コード例 #1
0
ファイル: WsnBase.cs プロジェクト: yguo89/RTOS
        // ===== 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);
            })
            );
        }
コード例 #2
0
ファイル: WsnBase.cs プロジェクト: yguo89/RTOS
        //
        // Update available sensor list and its places
        //
        private void AddSensorList(SensorNodeComponentUpdate packet)
        {
            List<AvailableSensors> sensors = this.Sensors[packet.Sensor];

            if (sensors == null)
                sensors = new List<AvailableSensors>();

            if (!sensors.Contains(new AvailableSensors(packet.Node, packet.Port)))
                sensors.Add(new AvailableSensors(packet.Node, packet.Port));
        }