Example #1
0
    public void OnSpawn(GameObject go)
    {
        Sensors component = go.GetComponent <Sensors>();

        component.Add(new PathProberSensor(component));
        component.Add(new SafeCellSensor(component));
        component.Add(new IdleCellSensor(component));
        component.Add(new PickupableSensor(component));
        component.Add(new ClosestEdibleSensor(component));
        component.Add(new BreathableAreaSensor(component));
        component.Add(new AssignableReachabilitySensor(component));
        component.Add(new ToiletSensor(component));
        component.Add(new MingleCellSensor(component));
        StateMachineController component2 = go.GetComponent <StateMachineController>();

        RationalAi.Instance instance = new RationalAi.Instance(component2);
        instance.StartSM();
        if (go.GetComponent <OxygenBreather>().GetGasProvider() == null)
        {
            go.GetComponent <OxygenBreather>().SetGasProvider(new GasBreatherFromWorldProvider());
        }
        Navigator component3 = go.GetComponent <Navigator>();

        component3.transitionDriver.overrideLayers.Add(new BipedTransitionLayer(component3, 3.325f, 2.5f));
        component3.transitionDriver.overrideLayers.Add(new DoorTransitionLayer(component3));
        component3.transitionDriver.overrideLayers.Add(new TubeTransitionLayer(component3));
        component3.transitionDriver.overrideLayers.Add(new LadderDiseaseTransitionLayer(component3));
        component3.transitionDriver.overrideLayers.Add(new ReactableTransitionLayer(component3));
        component3.transitionDriver.overrideLayers.Add(new SplashTransitionLayer(component3));
        ThreatMonitor.Instance sMI = go.GetSMI <ThreatMonitor.Instance>();
        if (sMI != null)
        {
            sMI.def.fleethresholdState = Health.HealthState.Critical;
        }
    }
        private void LoadCollection()
        {
            try
            {
                openFileDialog = new OpenFileDialog();
                // ------------------------------------
                openFileDialog.Filter      = "Json file (.json)|*.json|All Files(.*)|*.*";
                openFileDialog.FileName    = "Путь до файла";
                openFileDialog.Title       = "Загрузить данные с файла";
                openFileDialog.FilterIndex = 0;
                openFileDialog.DefaultExt  = FileManager.FilePath;
                // ------------------------------------

                bool?isOk = openFileDialog.ShowDialog() ?? false;
                if (isOk.Value)
                {
                    Sensors.Clear();
                    FileManager.FilePath = Path.GetDirectoryName(openFileDialog.FileName);
                    LogView = $"Load data from {FileManager.FilePath}";

                    List <Sensor> collection = FileManager.Read(FileManager.FilePath);
                    collection.ForEach(sensor => Sensors.Add(new SensorViewModel(sensor)));
                    UpdateCharts();
                }
            }
            catch (Exception ex)
            {
                var log = ExceptionHandler.Handler(ex);
                Log.WriteLog(log);
                MessageBox.Show(log, "Error! ", MessageBoxButton.OK, MessageBoxImage.Error);
                LogView = $"Error! {log}";
            }
        }
        protected override void DoStartAsync(object stoppingToken)
        {
            uart = new UART_Adapter(UARTSettings.COMPort);
            uart.Open();
            Logger.LogInformation($"UART is now listennig port {UARTSettings.COMPort}");
            OneWireSensor sensor = new DS18B20(uart);
            List <byte[]> ROMs   = sensor.GetConnectedROMs();

            Logger.LogInformation($"{ROMs.Count} connected sensor(s)");

            foreach (byte[] item in ROMs)
            {
                OneWireSensor physSensor = Utils.CreateSensor(item[0], uart, item);
                using (var scope = ScopeFactory.CreateScope())
                {
                    IUnitOfWork <Sensor> sensorsUnitOfWork = scope.ServiceProvider.GetRequiredService <IUnitOfWork <Sensor> >();
                    var dbSensor = sensorsUnitOfWork.GetRepository().Query().FirstOrDefault(sn => sn.ROM == physSensor.ROM);
                    if (dbSensor == null)
                    {
                        Sensors.Add(new UARTSensorDTO(physSensor)
                        {
                            SensorID = (Sensors.Count + 1) * -1, Name = "Not in DB", ROM = physSensor.ROM, DeviceName = physSensor.DeviceName(physSensor.FamilyCode)
                        });
                    }
                    else
                    {
                        Sensors.Add(new UARTSensorDTO(physSensor)
                        {
                            SensorID = dbSensor.snID, Name = dbSensor.Name, ROM = physSensor.ROM, DeviceName = physSensor.DeviceName(physSensor.FamilyCode)
                        });
                    }
                    Logger.LogInformation($"Added to list sensor with ROM: {physSensor.ROM}, Family Code = {physSensor.FamilyCode}");
                }
            }
        }
Example #4
0
        protected override void DoStartAsync(object stoppingToken)
        {
            Logger.LogInformation($"{openWeatherMapOptions.Cities.Length} connected sensor(s)");
            client.BaseAddress = new Uri("http://api.openweathermap.org/data/2.5/");

            for (int i = 0; i < openWeatherMapOptions.Cities.Length; i++)
            {
                string rom = openWeatherMapOptions.Cities[i].ToString();
                using (var scope = ScopeFactory.CreateScope())
                {
                    IUnitOfWork <Sensor> sensorsUnitOfWork = scope.ServiceProvider.GetRequiredService <IUnitOfWork <Sensor> >();
                    var dbSensor = sensorsUnitOfWork.GetRepository().Query().FirstOrDefault(sn => sn.ROM == rom);

                    if (dbSensor == null)
                    {
                        Sensors.Add(new SensorDTO()
                        {
                            SensorID = -i - 1, ROM = rom, DeviceName = $"OpenWeather sensor for city id {rom}"
                        });
                    }
                    else
                    {
                        Sensors.Add(new SensorDTO()
                        {
                            SensorID = dbSensor.snID, ROM = rom, DeviceName = $"OpenWeather sensor for city id {rom}"
                        });
                    }
                    Logger.LogInformation($"Added to list sensor with ROM (CityID): {rom}");
                }
            }
        }
Example #5
0
        /// <summary>
        /// 处理温湿度数据
        /// </summary>
        /// <param name="num">在线数</param>
        /// <param name="index">索引</param>
        /// <param name="data">数据</param>
        /// <param name="type">传感器类型</param>
        /// <returns></returns>
        private int ProcessTemperatureAndHumidity(int num, int index, byte[] data, int type)
        {
            for (int i = 0; i < num; i++)
            {
                Digital digitalWd = new Digital();
                digitalWd.Id = Convert.ToString(data[index++], 16);
                double wd = Convert.ToDouble(data[index++] << 8 | data[index++]) / 10;
                digitalWd.Value        = wd + "℃";
                digitalWd.Name         = "温度";
                digitalWd.Type         = type;
                digitalWd.Online       = wd == 0 ? StateType.Offline : StateType.Online;
                digitalWd.State        = wd == 0 ? StateType.StateClose : StateType.StateOpen;
                digitalWd.Controllable = false;
                Sensors.Add(digitalWd);
                Digital digitalSd = new Digital();
                digitalSd.Id = digitalWd.Id;
                double sd = Convert.ToDouble(data[index++] << 8 | data[index++]) / 10;
                digitalSd.Value        = sd + "%";
                digitalSd.Name         = "湿度";
                digitalSd.Type         = type;
                digitalSd.Online       = sd == 0 ? StateType.Offline : StateType.Online;
                digitalSd.State        = sd == 0 ? StateType.StateClose : StateType.StateOpen;
                digitalSd.Controllable = false;
                Sensors.Add(digitalSd);
            }

            return(index);
        }
Example #6
0
        private void Sensor_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            try
            {
                var sensor = sender as SensorModel;
                if (sensor != null)
                {
                    var existing = Sensors.FirstOrDefault(s => s.Name == sensor.Name);
                    if (existing != null)
                    {
                        existing = sensor;
                    }
                    else
                    {
                        Sensors.Add(sensor);
                    }
                }

                if (Sensors.Count > 0 && waitIndicator.IsRunning && Sensors[0].LastSummary != null)
                {
                    DisplayBeginSession();
                }
            }catch (Exception x)
            {
                Debug.WriteLine(x);
            }
        }
Example #7
0
        /// <summary>
        /// This method reads as 'move sensor A to the spot occupied by sensor B'. It moves sensor A to the spot where sensor B was, and moves sensor B one spot below it.
        /// </summary>
        /// <param name="a">The sensor to be moved.</param>
        /// <param name="b">The sensor whose spot will become sensor A's new location.</param>
        public void MoveSensorTo(Sensor a, Sensor b)
        {
            if (a.Equals(b))
            {
                return;
            }

            var newIndex = 0;

            var goingDown = Sensors.IndexOf(a) < Sensors.IndexOf(b);

            if (goingDown)
            {
                newIndex = Sensors.IndexOf(b); // Going down - use current index in the list
            }
            Sensors.Remove(a);

            if (!goingDown)
            {
                newIndex = Sensors.IndexOf(b);
            }

            if (newIndex < Sensors.Count)
            {
                Sensors.Insert(newIndex, a);
            }
            else
            {
                Sensors.Add(a);
            }
        }
Example #8
0
        public MadBot()
        {
            FleetTargeting     = new FleetTargeting(this);
            AbandonedTargeting = new AbandonedTargeting(this);
            FishTargeting      = new FishTargeting(this);
            ContextBehaviors.Add(Navigation = new NavigateToPoint(this)
            {
                BehaviorWeight = 1.0f
            });
            // Behaviors.Add(Efficiency = new Efficiency(this) { BehaviorWeight = 0.0f });
            // Behaviors.Add(Dodge0 = new Dodge(this) { LookAheadMS = 100, BehaviorWeight = 2 });
            // Behaviors.Add(Dodge1 = new Dodge(this) { LookAheadMS = 200, BehaviorWeight = 2 });
            // Behaviors.Add(Dodge2 = new Dodge(this) { LookAheadMS = 300, BehaviorWeight = 2 });
            for (int m = 000; m < 2000; m += 50)
            {
                ContextBehaviors.Add(new DogeWow(this)
                {
                    LookAheadMS = m + 50, BehaviorWeight = 1
                });
            }
            ContextBehaviors.Add(Separation = new Separation(this)
            {
                LookAheadMS = 500, BehaviorWeight = 2.0f
            });
            ContextBehaviors.Add(StayInBounds = new StayInBounds(this)
            {
                LookAheadMS = 1000, BehaviorWeight = 10f
            });

            Sensors.Add(SensorCTF = new SensorCTF(this));

            Navigation.TargetPoint = new Vector2(0, 0);
            Steps = 16;
        }
        protected override void DoStartAsync(object stoppingToken)
        {
            Logger.LogInformation($"{sensorsCount} connected sensor(s)");

            for (int i = 0; i < sensorsCount; i++)
            {
                int rndROM = 111111111 + i;
                using (var scope = ScopeFactory.CreateScope())
                {
                    IUnitOfWork <Sensor> sensorsUnitOfWork = scope.ServiceProvider.GetRequiredService <IUnitOfWork <Sensor> >();
                    var dbSensor = sensorsUnitOfWork.GetRepository().Query().FirstOrDefault(sn => sn.ROM == rndROM.ToString());

                    if (dbSensor == null)
                    {
                        Sensors.Add(new SensorDTO()
                        {
                            SensorID = rndROM, Name = $"Dummy sensor {i}", ROM = rndROM.ToString(), DeviceName = $"Sensor {rndROM}"
                        });
                    }
                    else
                    {
                        Sensors.Add(new SensorDTO()
                        {
                            SensorID = dbSensor.snID, Name = dbSensor.Name, ROM = dbSensor.ROM, DeviceName = $"Sensor {rndROM}"
                        });
                    }
                    Logger.LogInformation($"Added to list sensor with ROM: {rndROM}");
                }
            }
        }
Example #10
0
        /// <summary>
        /// 数字量数据处理
        /// </summary>
        /// <param name="num">在线数</param>
        /// <param name="index">下标</param>
        /// <param name="data">数据</param>
        /// <param name="type">类型编码</param>
        private void ProcessActuatorData(int num, ref int index, byte[] data, int type)
        {
            string name = Digital[type];

            type += 1;
            if (name == "照明灯")
            {
                for (int i = 0; i < num; i++)
                {
                    index = ProcessLamp(index, data, type, name);
                }
            }
            else  //其他数字量传感器逻辑
            {
                for (int i = 0; i < num; i++)
                {
                    Actuator actuator = new Actuator();
                    actuator.Id   = Convert.ToString(data[index++], 16);
                    actuator.Name = name;
                    actuator.Type = type;
                    int state = data[index++];
                    actuator.State        = GetState(state);
                    actuator.IsOpen       = state == 1 ? false : true;
                    actuator.Online       = state == 0 ? StateType.Offline : StateType.Online;
                    actuator.Controllable = name != "人体" && name != "气体";
                    Sensors.Add(actuator);
                }
            }
        }
Example #11
0
        public Task AddSensor(ISensor sensor)
        {
            _logger.LogInformation("Adding new sensor to parking location");
            Sensors.Add(sensor);

            return(Task.CompletedTask);
        }
Example #12
0
 public BoontonPiStatusViewModel(IBackgroundHandler backgroundHandler, IBoontonPi device) : base(backgroundHandler, device)
 {
     foreach (var sensor in Device.Sensors)
     {
         Sensors.Add(new SensorInfoViewModel(sensor));
     }
 }
 public void Init()
 {
     Sensors.Add(CreateSensorItem("Accelerometer", sensorManager.Accelerometer));
     Sensors.Add(CreateSensorItem("Contact", sensorManager.Contact));
     Sensors.Add(CreateSensorItem("Distance", sensorManager.Distance));
     Sensors.Add(CreateSensorItem("Gyroscope", sensorManager.Gyroscope));
     Sensors.Add(CreateSensorItem("Heart Rate", sensorManager.HeartRate));
     Sensors.Add(CreateSensorItem("Pedometer", sensorManager.Pedometer));
     Sensors.Add(CreateSensorItem("Skin Temperature", sensorManager.SkinTemperature));
     Sensors.Add(CreateSensorItem("Ultraviolet Light", sensorManager.UltravioletLight));
 }
Example #14
0
        private void FillListOfSensors(IList <IMovement> movements)
        {
            int count = movements[0].Sensors.Count;

            for (int i = 0; i < count; i++)
            {
                var allSensorsOfCertainIndex = GetAllSensors(movements, indexOfSensors: i);

                Sensors.Add(new MeanSensor(allSensorsOfCertainIndex));
            }
        }
Example #15
0
        /// <summary>
        /// 处理空调数据
        /// </summary>
        /// <param name="num">在线数</param>
        /// <param name="index">索引</param>
        /// <param name="data">数据</param>
        /// <param name="type">传感器类型</param>
        /// <returns></returns>
        private int ProcessAir(int num, int index, byte[] data, int type)
        {
            for (int i = 0; i < num; i++)
            {
                AirConditioning airConditioning = new AirConditioning();
                airConditioning.Id = Convert.ToString(data[index++], 16);
                byte height = data[index++];
                airConditioning.State  = ((height >> 7) & 0x01) == 1 ? StateType.StateOpen : StateType.StateClose;
                airConditioning.IsOpen = airConditioning.State == StateType.StateOpen;
                byte low = data[index++];
                if (height == 0 && low == 0)
                {
                    airConditioning.Online = StateType.Offline;
                }
                else
                {
                    airConditioning.Online = StateType.Online;
                }
                airConditioning.IsOpen = height >> 7 == 1;
                int model = height >> 4;
                switch (model)
                {
                case 0:
                    airConditioning.Model = "自动";
                    break;

                case 1:
                    airConditioning.Model = "制冷";
                    break;

                case 2:
                    airConditioning.Model = "除湿";
                    break;

                case 3:
                    airConditioning.Model = "送风";
                    break;

                case 4:
                    airConditioning.Model = "制热";
                    break;
                }
                airConditioning.Speed     = (height >> 2) & 3;
                airConditioning.SweepWind = height >> 1 == 1 ? "扫风" : "不扫风";
                float val = (0x0f & low);
                airConditioning.Value        = val + 16 + "℃";
                airConditioning.Name         = "空调";
                airConditioning.Controllable = true;
                airConditioning.Type         = type;
                Sensors.Add(airConditioning);
            }
            return(index);
        }
Example #16
0
        public BiUniversalMovement(IMovement primary, IMovement secondary, GraphProviderDelegate graphProvider)
        {
            if (primary.Sensors.Count != secondary.Sensors.Count)
            {
                throw new DifferentCountOfSensorsException();
            }

            for (int i = 0; i < primary.Sensors.Count; i++)
            {
                Sensors.Add(new BiUniversalSensor(primary.Sensors[i], secondary.Sensors[i], graphProvider));
            }
        }
Example #17
0
        private void setupFakeData()
        {
            Random r = new Random();

            foreach (string s in sensorNameLocations.Keys)
            {
                var temp = Math.Round(r.Next(30, 104) + r.NextDouble(), 2);
                Sensors.Add(new Sensor()
                {
                    Sensor_ID = 0, Name = s + " Sensor", Temperature = temp, AvgTemperature = temp + r.Next(-5, 5), imageSrc = sensorNameLocations[s]
                });
            }
        }
Example #18
0
 public bool AddSensor(Sensor sensor)
 {
     if (_sensorDictionary.TryGetValue(sensor.Name, out int i))
     {
         return(false);
     }
     else
     {
         Sensors.Add(sensor);
         _sensorDictionary.Add(sensor.Name, Sensors.Count - 1);
         return(true);
     }
 }
Example #19
0
        public BoontonPiControlViewModel(IBackgroundHandler backgroundHandler, IBoontonPi device, IPiControlPublisher commandPublisher) : base(backgroundHandler, device)
        {
            _commandPublisher = commandPublisher;
            foreach (var sensor in Device.Sensors)
            {
                Sensors.Add(new SensorControlViewModel(sensor, _commandPublisher));
            }

            StartPollingCommand        = new MvxAsyncCommand(OnStartPi);
            StopPollingCommand         = new MvxAsyncCommand(OnStopPi);
            BoontonStartupCommand      = new MvxAsyncCommand(OnBoontonStartup);
            BoontonCloseSensorsCommand = new MvxAsyncCommand(OnBoontonCloseSensors);
            BoontonResetSensorsCommand = new MvxAsyncCommand(OnBoontonResetSensors);
        }
Example #20
0
        // Todo add error handling
        public async Task <bool> AddSensorAsync(Sensor sensor)
        {
            try
            {
                Sensors.Add(sensor);
                await SaveChangesAsync().ConfigureAwait(false);

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine("Add Sensor error: " + e);
                return(false);
            }
        }
Example #21
0
        private void SetupSimulator()
        {
            Simulator simulator = new Simulator(itemsList);

            simulator.Items.ForEach(item => {
                if (item.ItemType.Equals(typeof(ISensor)))
                {
                    Sensors.Add(item);
                }
                else if (item.ItemType.Equals(typeof(IActuator)))
                {
                    Actuators.Add(item);
                }
            });
        }
Example #22
0
        private void DrawData(SensorData data)
        {
            var existingData = Sensors.FirstOrDefault(s => s.SensorName == data.SensorName);

            App.Current.Dispatcher.Invoke((Action) delegate
            {
                if (existingData != null)
                {
                    existingData.SoundLevel = data.SoundLevel;
                }
                else
                {
                    Sensors.Add(data);
                }
            });
        }
Example #23
0
        private void Port_SensorIDRecivedEventHandler(object sender, SerialDataIDEventArgs e)
        {
            bool flag = true;

            foreach (TemperatureSensor sens in Sensors)
            {
                if (sens.SensorID == e.message)
                {
                    flag = false;
                }
            }
            if (flag)
            {
                Sensors.Add(new TemperatureSensor(e.message));
            }
        }
Example #24
0
        protected override void ReconcileSensors()
        {
            var deviceSerialNumbers = from sensor in Device.Sensors select sensor.SerialNumber;
            var ocSerialNumbers     = from sensor in Sensors select sensor.SerialNumber;

            var deviceMissing = ocSerialNumbers.Where(x => !deviceSerialNumbers.Any(x.Contains));
            var ocMissing     = deviceSerialNumbers.Where(x => !ocSerialNumbers.Any(x.Contains));

            try
            {
                //Add new viewmodels previously not found in device info
                foreach (var serialNumber in ocMissing)
                {
                    var newSensor = Device.Sensors.Where(x => string.Equals(x.SerialNumber, serialNumber, StringComparison.OrdinalIgnoreCase)).Single();
                    Sensors.Add(new SensorControlViewModel(newSensor, _commandPublisher));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Boonton Pi Status Add New Sensors Error {ex.Message}");
            }

            //Remove old viewmodels no longer found in device manager
            var tmp = new List <ISensorInfoViewModel>();

            foreach (var vm in Sensors)
            {
                if (!deviceSerialNumbers.Contains(vm.SerialNumber))
                {
                    tmp.Add(vm);
                }
            }
            try
            {
                foreach (var item in tmp)
                {
                    var index = Sensors.IndexOf(item);
                    var vm    = Sensors[index];
                    Sensors.RemoveAt(index);
                    vm = null;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Boonton Pi Status Remove Old Sensors Error {ex.Message}");
            }
        }
Example #25
0
 public void Init()
 {
     Sensors.Add(CreateSensorItem("Accelerometer", sensorManager.Accelerometer, 3));
     Sensors.Add(CreateSensorItem("Altimeter", sensorManager.Altimeter, 9));
     Sensors.Add(CreateSensorItem("Ambient Light", sensorManager.AmbientLight, 1));
     Sensors.Add(CreateSensorItem("Barometer", sensorManager.Barometer, 2));
     Sensors.Add(CreateSensorItem("Calories", sensorManager.Calories, 1));
     Sensors.Add(CreateSensorItem("Contact", sensorManager.Contact, 1));
     Sensors.Add(CreateSensorItem("Distance", sensorManager.Distance, 4));
     Sensors.Add(CreateSensorItem("Gyroscope", sensorManager.Gyroscope, 3));
     Sensors.Add(CreateSensorItem("Gsr", sensorManager.Gsr, 1));
     Sensors.Add(CreateSensorItem("Heart Rate", sensorManager.HeartRate, 2));
     Sensors.Add(CreateSensorItem("Pedometer", sensorManager.Pedometer, 1));
     Sensors.Add(CreateSensorItem("RR Interval", sensorManager.RRInterval, 1));
     Sensors.Add(CreateSensorItem("Skin Temperature", sensorManager.SkinTemperature, 1));
     Sensors.Add(CreateSensorItem("Ultraviolet Light", sensorManager.UltravioletLight, 1));
 }
 private void GenerateCollection()
 {
     try
     {
         LogView = $"Generate new Charts";
         Sensors.Clear();
         Generator.GetSensors().ForEach(item => Sensors.Add(new SensorViewModel(item)));
         UpdateCharts();                 //Строим графики
     }
     catch (Exception ex)
     {
         var log = ExceptionHandler.Handler(ex);
         Log.WriteLog(log);
         MessageBox.Show(log, "Error! ", MessageBoxButton.OK, MessageBoxImage.Error);
         LogView = $"Error! {log}";
     }
 }
Example #27
0
        /// <summary>
        /// 处理光照传感器数据
        /// </summary>
        /// <param name="num">在线数</param>
        /// <param name="index">索引</param>
        /// <param name="data">数据</param>
        /// <param name="type">传感器类型</param>
        /// <returns></returns>
        private int ProcessIllumination(int num, int index, byte[] data, int type)
        {
            for (int i = 0; i < num; i++)
            {
                Digital digital = new Digital();
                digital.Id = Convert.ToString(data[index++], 16);
                double value = data[index++] << 8 | data[index++];
                digital.Value        = value + " lx";
                digital.Name         = "光照";
                digital.Type         = type;
                digital.Online       = value == 0 ? StateType.Offline : StateType.Online;
                digital.State        = value != 0 ? StateType.StateOpen : StateType.StateClose;
                digital.Controllable = false;
                Sensors.Add(digital);
            }

            return(index);
        }
Example #28
0
        /// <summary>
        /// 处理照明灯的逻辑
        /// </summary>
        /// <param name="index">模块数量</param>
        /// <param name="data">数据</param>
        /// <param name="type">类型编码</param>
        /// <param name="name">模块名称</param>
        /// <returns></returns>
        private int ProcessLamp(int index, byte[] data, int type, string name)
        {
            Actuator Lamp1    = new Actuator();
            string   moduleId = Convert.ToString(data[index++], 16);

            Lamp1.Name = name;
            Lamp1.Type = type;
            int state     = data[index++];
            int moduleNum = state >> 7;

            if (moduleNum == 1)   //一个节点控制两盏灯
            {
                //将单个节点控制多个灯的状态值保存起来
                Cache.AddCache(classRoomId, state);
                int moduleState = state & 0x1;
                Lamp1.Id     = moduleId + "_0";
                Lamp1.State  = moduleState != 0 ? StateType.StateOpen : StateType.StateClose;
                Lamp1.IsOpen = moduleState == 1;
                //数据位第4位表示在线状态
                Lamp1.Online       = OnLineState(state);
                Lamp1.Controllable = true;
                Sensors.Add(Lamp1);
                Actuator Lamp2 = new Actuator();
                Lamp2.Name = name;
                Lamp2.Type = type;
                Lamp2.Id   = moduleId + "_1";
                int module1State = (state >> 1) & 0x1;
                Lamp2.State        = module1State != 0 ? StateType.StateOpen : StateType.StateClose;
                Lamp2.IsOpen       = module1State == 1;
                Lamp2.Online       = OnLineState(state);
                Lamp2.Controllable = true;
                Sensors.Add(Lamp2);
            }
            else
            {
                Lamp1.Id           = moduleId;
                Lamp1.State        = (state & 1) != 0 ? StateType.StateOpen : StateType.StateClose;
                Lamp1.IsOpen       = (state & 1) == 1;
                Lamp1.Online       = OnLineState(state);
                Lamp1.Controllable = true;
                Sensors.Add(Lamp1);
            }
            return(index);
        }
 private void HandleSensorMessage(Sensor sensor)
 {
     if (sensor != null)
     {
         Sensor lastSensor         = service.All().LastOrDefault();
         Sensor lastSensorFromList = Sensors.LastOrDefault();
         if (lastSensorFromList != null)
         {
             if (lastSensorFromList.Sensor_id != lastSensor.Sensor_id)
             {
                 Sensors.Add(lastSensor);
             }
         }
         else
         {
             Sensors.Add(lastSensor);
         }
     }
 }
        private void AddSensors()
        {
            irSensor = new PassiveInfraRedSensor()
            {
                Name = "Motion Sensor", Port = "D2"
            };
            Sensors.Add(irSensor);

            blinky = new Led()
            {
                Name = "Blinky", Port = "D5"
            };
            Sensors.Add(blinky);

            buzzer = new VibrationMotor()
            {
                Name = "Vibration Motor", Port = "D6"
            };
            Sensors.Add(buzzer);
        }