Ejemplo n.º 1
0
 /// <summary>
 /// Accepts a command from an external thread. 
 /// </summary>
 /// <param name="aCmd"></param>
 public void AcceptCmd(object aCmd)
 {
     lock (this.cmdInput)
     {       // Possibly add to a Que structure for higher performance/less bottle neck
         this.currentCmd = (Command)aCmd;
         iCmdToService = true;
     }
 }
Ejemplo n.º 2
0
 // Sets the command
 private void cmd(object obj)
 {
     Command newCmd = (Command)obj;
     if ( newCmd.Device == "LED" )
     {
     lock (this)
     {
         this.iCmd = newCmd;
     }
     return;
     }
 }
        public CommandEventArgs(Command command)
        {
            Command = command;

            this.ReturnString = "Returning this string";
        }
Ejemplo n.º 4
0
 private bool RGO_LED_ACTION(Devices.RGO_LED rgoled, Command cmd )
 {
     // Need ability for controlled flashing of LED via a format found in cmd.Arguments
     switch (cmd.Action.ToLower())
     {
         case "red":
             rgoled.Red();
             return true;
         case "green":
             rgoled.Green();
             return true;
         case "amber":
             rgoled.Amber();
             return true;
         case "off":
             rgoled.Off();
             return true;
         default:
             rgoled.Off();
             return false;
     }
 }
Ejemplo n.º 5
0
 private bool OUTPUT_RELAY_ACTION(Devices.OutputRelay outputrelay, Command cmd)
 {
     switch (cmd.Action.ToLower())
     {
         case "on":
             outputrelay.On();
             return true;
         case "off":
             outputrelay.Off();
             return true;
         default:
             return false;
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Starts the server.
        /// </summary>
        private void StartServer()
        {
            using (var server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
            {
                server.Bind(new IPEndPoint(IPAddress.Any, this.Port));
                server.Listen(1);

                while (!cancel)
                {
                    using (Socket connection = server.Accept())
                    {
                        if (connection.Poll(-1, SelectMode.SelectRead))
                        {
                            // Create buffer and receive raw bytes.
                            byte[] bytes = new byte[connection.Available];
                            int count = connection.Receive(bytes);
                            Byte[] bytesToSend;
                            // Convert to string, will include HTTP headers.
                            string rawData = new string(Encoding.UTF8.GetChars(bytes));
                            Command aCmd = new Command(rawData);
                            bytesToSend = Encoding.UTF8.GetBytes("ACK");
                            this.serverDel(aCmd);
                            connection.Send(bytesToSend, bytesToSend.Length, 0);
                        }
                    }
                }
            }
        }