Esempio n. 1
0
 public Sender(ArrayList args, Prompt prompt) {
   this.prompt = prompt;
   if (!ParseArgs(args)) {
     prompt.WriteLine("send: wrong arguments", prompt.errorTextColor);
     return;
   }
   try{
     mote = new MoteIF(motecom);
   }
   catch(Exception e){
     prompt.WriteLine(e.Message, prompt.errorTextColor);
     return;
   }
 }
Esempio n. 2
0
    public Listener(MoteIF mote, Prompt prompt) {

      if (mote == null) {
        return;
      }

      motecom = mote.motecom;
      active = true;
      this.mote = mote;
      this.prompt = prompt;
      prompt.WriteLine("Listening on " +motecom+ " (^C or 'exit' returns to prompt)", prompt.successTextColor);
      //Console.CancelKeyPress += stop;
      mote.onMessageArrived += newMsgHandler;
      //evt = new AutoResetEvent(false);
      //evt.WaitOne();
      //Console.CancelKeyPress -= stop;
    }
Esempio n. 3
0
 public Listener(ArrayList args, Prompt prompt) {
   if (args.Count != 3) {
     prompt.WriteLine("listen: Wrong arguments", prompt.errorTextColor);
     return;
   }
   this.prompt = prompt;
   motecom = args[2].ToString();
   try {
     mote = new MoteIF(motecom);
   } catch (Exception e) {
     prompt.WriteLine(e.Message, prompt.errorTextColor);
     return;
   }
   active = true;
   prompt.WriteLine("Listening on " + motecom + " (^C or 'exit' returns to prompt)", prompt.successTextColor);
   //Console.TreatControlCAsInput = false;
   //Console.CancelKeyPress += stop;
   mote.onMessageArrived += newMsgHandler;
   //evt = new AutoResetEvent(false);
   //evt.WaitOne();
   //Console.TreatControlCAsInput = true;
   //Console.CancelKeyPress -= stop;
 }
Esempio n. 4
0
 static public void PrintHelp(Prompt prompt) {
   prompt.WriteLine("USAGE");
   prompt.WriteLine("  listen -comm <MOTECOM>", prompt.helpTextColor);
   prompt.WriteLine("");
   prompt.WriteLine("DESCRIPTION");
   prompt.WriteLine("  Listen for serial packets from the given MOTECOM");
   prompt.WriteLine("  Ctrl+C closes the listener for the local client. ");
   prompt.WriteLine("  The control client stops the listener with an 'exit' command.");
   prompt.WriteLine("");
   prompt.WriteLine("EXAMPLE");
   prompt.WriteLine("  listen -comm serial@COM25:115200");
   prompt.WriteLine("  listen -comm sf@localhost:9000");
 }
Esempio n. 5
0
    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);
    }
Esempio n. 6
0
 public static void PrintInfoHelp(Prompt prompt) {
   prompt.WriteLine("USAGE");
   prompt.WriteLine("  info <ID | PORT>", prompt.helpTextColor);
   prompt.WriteLine("");
   prompt.WriteLine("DESCRIPTION");
   prompt.WriteLine("  Prints out stats about the specified sf-server.");
 }
Esempio n. 7
0
 public static void PrintListHelp(Prompt prompt) {
   prompt.WriteLine("Lists all running sf-servers.");
 }
Esempio n. 8
0
    public static void PrintStopHelp(Prompt prompt) {

      prompt.WriteLine("USAGE");
      prompt.WriteLine("  stop <ID | PORT>", prompt.helpTextColor);
      prompt.WriteLine("");
      prompt.WriteLine("DESCRIPTION");
      prompt.WriteLine("  Stops the specified sf server.");
    }
Esempio n. 9
0
    public static void PrintStartHelp(Prompt prompt) {

      prompt.WriteLine("USAGE");
      prompt.WriteLine("  start -port <TCP_PORT> -comm <MOTECOM>", prompt.helpTextColor);
      prompt.WriteLine("");
      prompt.WriteLine("DESCRIPTION");
      prompt.WriteLine("  Starts a new sf-server listening for clients on the specified TCP Port,");
      prompt.WriteLine("  with the specified MOTECOM as packets source, which can be a serial");
      prompt.WriteLine("  device or a serial forwarder.");
      prompt.WriteLine("");
      /* TODO
      prompt.WriteLine("OPTIONS");
      prompt.WriteLine("  -c MAX_CLIENTS: Maximum number of clients allowed to connect to ");
      prompt.WriteLine("                  the created sf-server. No client limit if no specified.");
      prompt.WriteLine("  -e TIME: Time (in seconds) after which the created sf-server will be");
      prompt.WriteLine("           destroyed. No sf-expiration if no specified.");
      prompt.WriteLine("");
       * */
      prompt.WriteLine("EXAMPLE");
      prompt.WriteLine("  start -port 9000 -comm serial@COM9:115200");
      prompt.WriteLine("  start -port 9001 -comm sf@localhost:9000");
      prompt.WriteLine("  start -port 7777 -comm serial@/dev/ttyUSB0:115200");
      prompt.WriteLine("  start -port 7778 -comm [email protected]:9000");
    }
Esempio n. 10
0
 public void Init() {
   prompt = new Prompt("", ">> ", helloMsg, 25);
   SetDefVarValues();
   stdinClient = new Thread(new ThreadStart(StdinClient));
   stdinClient.Start();
 }
Esempio n. 11
0
 private void PrintHelpClose(Prompt prompt) {
   prompt.WriteLine("Closes the connection to the control client.");
 }
Esempio n. 12
0
 private void PrintHelpExit(Prompt prompt) {
   prompt.WriteLine("Stops all running sf-servers and exit.");
 }
Esempio n. 13
0
 private void PrintHelpPorts(Prompt prompt) {
   prompt.WriteLine("Displays a list of available serial ports.");
 }
Esempio n. 14
0
 private void PrintHelpClear(Prompt prompt) {
   prompt.WriteLine("Clears the local console.");
 }
Esempio n. 15
0
 private void PrintSetHelp(Prompt prompt) {
   prompt.WriteLine("USAGE");
   prompt.WriteLine("  set [<DEST | SRC | GROUP | AM> [0x]<VALUE>] ", prompt.helpTextColor);
   prompt.WriteLine("");
   prompt.WriteLine("DESCRIPTION");
   prompt.WriteLine("  Sets serial packet header fields values for packets sent");
   prompt.WriteLine("  with the SEND command. Invoke without arguments");
   prompt.WriteLine("  to print the current assigned values. See also 'help send'.");
   prompt.WriteLine("");
   prompt.WriteLine("EXAMPLE");
   prompt.WriteLine("  set am 137");
   prompt.WriteLine("  set am 0x89");
 }
Esempio n. 16
0
 static public void PrintHelp(Prompt prompt) {
   prompt.WriteLine("USAGE");
   prompt.WriteLine("  send -comm <MOTECOM> -m <MESSAGE> [-listen]", prompt.helpTextColor);
   prompt.WriteLine("");
   prompt.WriteLine("DESCRIPTION");
   prompt.WriteLine("  Sends a MESSAGE in hex format throught the");
   prompt.WriteLine("  specified MOTECOM. Optionally a listen connection");
   prompt.WriteLine("  can be opened right after the send command ends.");
   prompt.WriteLine("  MESSAGE is the payload of the serial packet. Use");
   prompt.WriteLine("  the SET command to specify AM, DEST, SRC and GROUP.");
   prompt.WriteLine("  See also 'help set'.");
   prompt.WriteLine("");
   prompt.WriteLine("EXAMPLE");
   prompt.WriteLine("  set am 137");
   prompt.WriteLine("  set dest 5");
   prompt.WriteLine("  send -comm serial@COM25:115200 -m B0047C04E1");
   prompt.WriteLine("  send -comm sf@localhost:9000 -m 0001 -listen");
 }