Exemple #1
0
 public MoteIF(string motecom) {
   try {
     messageSource = SourceMaker.make(motecom);
     this.motecom = motecom;
     messageSource.messageArrivedEvent += onReceive;
   } catch (Exception e) { throw e; }
 }
Exemple #2
0
        public static MessageSource make(string motecom)
        {
            //string errsrc = "\nUnable to create or connect to {0}\n";
            MessageSource messageSource = null;

            string[] words = motecom.Split('@');
            string[] args;
            if (words.Length != 2)
            {
                throw new Exception("Could not make MessageSource");
            }

            if (words[0].Equals("serial"))
            {
                args = words[1].Split(':');
                try {
                    messageSource = new SerialSource(args[0], Convert.ToInt32(args[1]));
                } catch (Exception e) {
                    Debug.WriteLine(e.Message);
                    throw new Exception("Could not make serial source (bad port?)");
                }
            }
            else if (words[0].Equals("sf"))
            {
                args = words[1].Split(':');
                try {
                    messageSource = new SFSource();
                    ((SFSource)messageSource).Connect(args[0], Convert.ToInt32(args[1]));
                } catch (Exception e) {
                    Debug.WriteLine(e.Message);
                    throw new Exception("Could not make sf source (bad ip/port?)");
                }
            }
            return(messageSource);
        }
Exemple #3
0
 public MoteIF(string motecom)
 {
     try {
         messageSource = SourceMaker.make(motecom);
         this.motecom  = motecom;
         messageSource.messageArrivedEvent += onReceive;
     } catch (Exception e) { throw e; }
 }
 public SFClientHandler(TcpClient tcpClient, MessageSource msgSrc, uint id) {
   this.id = id;
   this.mote = msgSrc;
   msgSrc.messageArrivedEvent += OnMoteMessageArrived;
   this.messageArrivedEvent += OnTCPMessageArrived;
   this.tcpClient = tcpClient;
   this.stream = this.tcpClient.GetStream();
   try {
     Handshake();
     Start();
   } catch (Exception e) { Console.Write(e.Message); }
 }
Exemple #5
0
 public MoteIF(MessageSource src) {
   messageSource = src;
   messageSource.messageArrivedEvent += onReceive;
 }
    public SerialForwarder(ArrayList args, Prompt prompt, uint id) {
      this.id = id;
      this.prompt = prompt;
      for (int i = 1, l = args.Count; i < l; i++) {
        switch (args[i].ToString()) {
          case "-c":
            if (++i == l) {
              WriteLine("start: wrong arguments", prompt.errorTextColor);
              return;
            }
            else
              // TODO
              //maxClients = Convert.ToInt32(args[i].ToString());
            break;

          case "-e":
            if (++i == l) {
              WriteLine("start: wrong arguments", prompt.errorTextColor);
              return;
            }
            else
              //TODO
              //expirationTimeout = Convert.ToInt32(args[i].ToString());
            break;

          case "-comm":
            if (++i == l) {
              prompt.WriteLine("start: wrong arguments", prompt.errorTextColor);
              return;
            }
            else motecom = args[i].ToString();
            break;

          case "-port":
            if (++i == l) {
              WriteLine("start: wrong arguments", prompt.errorTextColor);
              return;
            }
            else
              try {
                port = Convert.ToUInt16(args[i].ToString());
              } catch (Exception) {
                port = 0;
              }
              
            break;

          default:
            WriteLine("start: wrong arguments", prompt.errorTextColor);
            return;
        }
      }
      try {
        mote = SourceMaker.make(motecom);
      } catch (Exception e) {
        Debug.WriteLine(e.Message);
        WriteLine("start: unable to open " + motecom, prompt.errorTextColor);
        return;
      }

      if (mote == null || port == 0) {
        WriteLine("start: wrong arguments", prompt.errorTextColor);
        return;
      }
      mote.RxPacket += mote_RxPacket;
      mote.TxPacket += mote_TxPacket;
      mote.ToutPacket += mote_ToutPacket;
      tcpListener = new TcpListener(IPAddress.Any, port);

      try {
        tcpListener.Start();
      } catch (SocketException se) {
        Debug.WriteLine(se.Message);
        WriteLine("Unable to open socket on port " + port + "( port in use?)", prompt.errorTextColor);
        mote.Close();
        return;
      }

      connectionReceiver = new Thread(new ThreadStart(ListenForClients));
      connectionReceiver.Start();
      running = true;
      WriteLine("Serial forwarder started (id = " + id.ToString() + "). Waiting for clients on port " 
        + port.ToString(), prompt.successTextColor);
    }
Exemple #7
0
 public MoteIF(MessageSource src)
 {
     messageSource = src;
     messageSource.messageArrivedEvent += onReceive;
 }