Example #1
0
        // ===== Methods =========================================

        //
        // Call back function when there is a message in serial port
        //      the raw message is deciphor here.
        //
        private void Connection_ReceivedData(object sender, Packet e)
        {
            object obj = new object();
            CommandHandlerDelegate CommandHandler = new CommandHandlerDelegate(ReturnToUIHandler);

            string[] ParameterDelimeter = { "[", "]" };

            string[] parameters = e.Message.Split(ParameterDelimeter, StringSplitOptions.RemoveEmptyEntries);
            switch (parameters[Commands.CommandOffset])
            {
                case Commands.ReceiveData:
                    {
                        SensorData data = new SensorData("Default",
                                                        DateTime.Now,
                                                        parameters[Commands.SensorDataOffset]);
                        SensorNodeComponentUpdate update = new SensorNodeComponentUpdate(Convert.ToInt16(parameters[Commands.NodeIdOffset]),
                                                                                         Convert.ToInt16(parameters[Commands.PortIdOffset]),
                                                                                         0,
                                                                                         data);
                        if (this.Nodes[update.Node].Ports[update.Port].Sensor.Id == (int)SensorType.SensorId.TiltSensorId)
                        {
                            if (update.Data.Measurement == 0)
                            {
                                update.Data.Unit = "Landscape";
                            }
                            else
                            {
                                update.Data.Unit = "Portait";
                            }
                        }
                        else if (this.Nodes[update.Node].Ports[update.Port].Sensor.Id == (int)SensorType.SensorId.TouchPadSensorId)
                        {
                            if (update.Data.Measurement < 0x10000)  // only one action
                            {
                                update.Data.Unit = update.Data.FindTouchPadKey();
                            }
                            else
                            {
                                int restore_measurement = update.Data.Measurement;
                                string unit = "";
                                update.Data.Measurement /= 0x10000;                     // first action
                                unit = update.Data.FindTouchPadKey();
                                update.Data.Measurement = restore_measurement & 0xFFFF; // second action
                                unit += update.Data.FindTouchPadKey();
                                update.Data.Measurement = restore_measurement;
                                update.Data.Unit = unit;
                            }
                        }
                        else
                        {
                        }

                        obj = update;
                        CommandHandler = ReceiveDataCmdHandler;
                        break;
                    }
                case Commands.FlushData:
                    {
                        break;
                    }
                case Commands.SetNodeSleep:
                    {
                        break;
                    }
                case Commands.SetSampleRate:
                    {
                        break;
                    }
                case Commands.SensorStart:
                    {
                        break;
                    }
                case Commands.SensorStop:
                    {
                        break;
                    }
                case Commands.NewNode:
                    {
                        obj = parameters[Commands.NodeIdOffset];
                        CommandHandler = NewNodeCmdHandler;
                        break;
                    }
                case Commands.DeadNode:
                    {
                        obj = parameters[Commands.NodeIdOffset];
                        CommandHandler = DeadNodeCmdHandler;
                        break;
                    }
                case Commands.UpdateSensor:
                    {
                        SensorNodeComponentUpdate update = new SensorNodeComponentUpdate(Convert.ToInt16(parameters[Commands.NodeIdOffset]),
                                                                                         Convert.ToInt16(parameters[Commands.PortIdOffset]),
                                                                                         Convert.ToInt16(parameters[Commands.SensorDataOffset]),
                                                                                         null);
                        obj = update;
                        CommandHandler = UpdateSensorCmdHandler;
                        break;
                    }
                default:
                    {

                        MessageBox.Show("ERROR: Undefined Command!");
                        break;
                    }
            }

            MyDispatch.Invoke(
            (Action)(() =>
            {
                CommandHandler(obj);
            })
            );
        }
Example #2
0
 public SensorNodeComponentUpdate(int node_id, int port_id, int sensor_id, SensorData data)
 {
     this.Node = node_id;
     this.Port = port_id;
     this.Sensor = sensor_id;
     this.Data = data;
 }