Exemplo n.º 1
0
        public async Task <SensorList> GetSensorsAsync()
        {
            HttpRequestMessage request      = new HttpRequestMessage(HttpMethod.Post, "/action/deviceListGet");
            SensorList         responseBody = await SendRequest <SensorList>(request);

            return(responseBody);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets all the data from a sensor type in the blob storage
        /// according to the date, device and sensor type that are
        /// entered as the parameters and packs the data in as a weather report.
        /// </summary>
        /// <param name="dateText"></param>
        /// <param name="deviceName"></param>
        /// <param name="sensorName"></param>
        /// <returns></returns>
        public WeatherReport GetWeatherReport(string dateText, string deviceName, string sensorName)
        {
            List <SensorType> data = GetDataFromFile(dateText, deviceName, sensorName);

            if (data == null)
            {
                return(null);
            }

            DateTime date   = DateTime.Parse(dateText);
            var      device = new Device
            {
                DeviceName = deviceName,
                Date       = date
            };

            List <SensorList> sensorTypes = new List <SensorList>();
            SensorList        sensorList  = new SensorList();

            sensorList.sensorName = sensorName;
            sensorList.sensorList = data;
            sensorTypes.Add(sensorList);

            WeatherReport report = new WeatherReport();

            report.Device      = device;
            report.SensorTypes = sensorTypes;

            return(report);
        }
Exemplo n.º 3
0
        public static List <Sensor> GetSensorList(int groupId)
        {
            //  List<Sensor> sensors = new List<Sensor>();

            RestClient client = new RestClient();

            client.BaseUrl = new Uri("https://api.samsara.com");


            var request = new RestRequest();
            // request.AddBody(new { groupId = "2401" });

            var jsonToSend = "{\"groupId\":2401}";

            request.AddParameter("application/json; charset=utf-8", jsonToSend, ParameterType.RequestBody);
            request.Method = Method.POST;

            request.Resource = "v1/sensors/list";
            request.AddQueryParameter("access_token", "qnxQMV1tOhLXSqZhF98E");


            var response = client.Execute(request);


            JavaScriptSerializer deserial = new JavaScriptSerializer();
            SensorList           sList    = deserial.Deserialize <SensorList>(response.Content);


            return(sList.sensors);
        }
Exemplo n.º 4
0
 /// <summary>
 /// 鼠标单击事件,3种情况
 /// 1:右键菜单取消
 /// 2:添加新传感器
 /// 3:打开右键菜单
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void PicMask_MouseClick(object sender, MouseEventArgs e)
 {
     if (IsEditing)
     {
         if (SelectSensor != null)
         {
             SelectSensor = null;
         }
         else if (e.Button == MouseButtons.Left && MostNearSensor == null)
         {
             DectectPointInfo new_sensor = new DectectPointInfo();
             new_sensor.Location = new Tuple <int, int>(e.X, e.Y);
             new_sensor.Position = new Tuple <double, double>((double)e.X / this.Width, (double)e.Y / this.Height);
             new_sensor.Weight   = 0;
             SensorList.Add(new_sensor);
             ReSet();
         }
         else if (e.Button == MouseButtons.Right)
         {
             if (MostNearSensor != null)
             {
                 RightClickcontextMenuStrip.Show(MousePosition.X, MousePosition.Y);
             }
         }
     }
 }
Exemplo n.º 5
0
 public void SetSensors(BitArray sensors)
 {
     try
     {
         SensorList?.ForEach(prop => prop.Active = sensors[prop.Offset]);
     }
     catch (Exception ex)
     {
         throw new ConveyorBasicException(String.Format("ConveyorBasicInfo.SetSensors failed. Reason:{0}", ex.Message));
     }
 }
Exemplo n.º 6
0
 public virtual void Initialize()
 {
     try
     {
         Sensor = SensorList?.ToDictionary(prop => prop.Reference);
     }
     catch (Exception ex)
     {
         throw new ConveyorBasicException(String.Format("ConveyorBasicInfo.Initialize failed. Reason:{0}", ex.Message));
     }
 }
Exemplo n.º 7
0
        public void SensorListSortByOrder()
        {
            SensorList <string, object> sensorList = new SensorList <string, object>
            {
                new ExecutableSensor <string, object>(5, 20)
            };

            Assert.AreEqual(20, sensorList[0].GetTickRate());

            sensorList.AddAndSort(new ExecutableSensor <string, object>(4, 30));
            Assert.AreEqual(30, sensorList[0].GetTickRate());
        }
Exemplo n.º 8
0
        private async Task ConfigureSensors()
        {
            SensorList response = await _lupusecService.GetSensorsAsync();

            foreach (var sensor in response.Sensors)
            {
                TryCall(sensor, ConfigureSensors);
            }

            AlarmBinarySensor alarmBinarySensorArea1 = new AlarmBinarySensor(_configuration, 1);
            AlarmBinarySensor alarmBinarySensorArea2 = new AlarmBinarySensor(_configuration, 2);

            PublishDeviceToMqtt(alarmBinarySensorArea1); PublishDeviceToMqtt(alarmBinarySensorArea2);
        }
Exemplo n.º 9
0
        public static void Initialize()
        {
            SocketServer.RegisterHandler(MessageType.SensorData, SensorDataHandler);
            SocketServer.RegisterHandler(MessageType.Image1, Image1Handler);
            SocketServer.RegisterHandler(MessageType.Image2, Image2Handler);

            sql = new SqliteConnection("Data Source=Db/sensorData.db");
            Directory.CreateDirectory("Images 1");
            Directory.CreateDirectory("Images 2");

            SensorList.Initialize();

            byte[] sensorIds = SensorList.Sensors.Select(c => c.SensorId).ToArray();
            CreateSensorTables(sensorIds);
        }
Exemplo n.º 10
0
 //Actors and Sensors
 private void LoadData()
 {
     simulator = new Simulator(modelItems); //modelItems-Liste wird an Simulator übergeben
     foreach (var item in simulator.Items)  //enthält die generierten Demo-Daten aus dem Simulator
     {
         if (item.ItemType.Equals(typeof(ISensor)))
         {
             SensorList.Add(item);
         }
         else if (item.ItemType.Equals(typeof(IActuator)))
         {
             ActorList.Add(item);
         }
     }
 }
Exemplo n.º 11
0
        private void LoadData()
        {
            Simulator sim = new Simulator(modelItems);

            foreach (var item in sim.Items)
            {
                if (item.ItemType.Equals(typeof(ISensor)))
                {
                    SensorList.Add(item);
                }
                else if (item.ItemType.Equals(typeof(IActuator)))
                {
                    ActorList.Add(item);
                }
            }
        }
Exemplo n.º 12
0
        public void GenerateData()
        {
            sim = new Simulator(ModelList);

            foreach (var item in sim.Items)
            {
                if (item.ItemType.Equals(typeof(ISensor)))
                {
                    SensorList.Add(item);
                }

                else if (item.ItemType.Equals(typeof(IActuator)))
                {
                    ActorList.Add(item);
                }
            }
        }
Exemplo n.º 13
0
 private void Form1_Shown(object sender, EventArgs e)
 {
     try
     {
         SensorList <Sensor> sl = SensorManager.GetAllSensors();
         SensorManager.RequestPermission(this.Handle, true, sl);
     }
     catch (SensorPlatformException spe)
     {
         TaskDialog dialog = new TaskDialog( );
         dialog.InstructionText = spe.Message;
         dialog.Text            = "This application will now exit.";
         dialog.StandardButtons = TaskDialogStandardButtons.Close;
         dialog.Show();
         Application.Exit( );
     }
 }
Exemplo n.º 14
0
        //DemoDaten laden
        private void LoadData()
        {
            Simulator sim = new Simulator(modelItems);

            //ueberpruefen ob Sensor oder Actor und zu Liste hinzufuegen
            foreach (var item in sim.Items)
            {
                if (item.ItemType.Equals(typeof(ISensor)))
                {
                    SensorList.Add(item);
                }
                else if (item.ItemType.Equals(typeof(IActuator)))
                {
                    ActorList.Add(item);
                }
            }
        }
Exemplo n.º 15
0
 public bool LoadSensorInfo(string logname)
 {
     logfilename = logname;
     SensorList.Clear();
     if (File.Exists(string.Format("{0}\\{1}.log", LogPath, logfilename)))
     {
         using (StreamReader sr = new StreamReader(string.Format("{0}\\{1}.log", LogPath, logfilename), Encoding.UTF8))
         {
             String line;
             double x;
             double y;
             Random ra = new Random();
             while ((line = sr.ReadLine()) != null)
             {
                 var onesensor = new DectectPointInfo();
                 x = double.Parse(line.Substring(1, 6));
                 y = double.Parse(line.Substring(8, 6));
                 onesensor.Position = new Tuple <double, double>(x, y);
                 onesensor.Location = new Tuple <int, int>(Convert.ToInt32(x * this.Width), Convert.ToInt32(y * this.Height));
                 //onesensor.Weight = ra.NextDouble();
                 onesensor.Weight = 0d;
                 //  查询该点是否绑定检测信号
                 if (line.Length > 16)
                 {
                     onesensor.SignalName = line.Substring(15, line.Length - 15);    //  获取之前绑定的信号名称
                     //  检测该信号名称是否已经加载,若无则清空该监测点绑定的信号名称
                     var onelistsignal = CardSettingManager.Settings.Find(onesetting => onesetting.SignalName == onesensor.SignalName);
                     if (onelistsignal == null)
                     {
                         onesensor.SignalName = null;
                     }
                 }
                 else
                 {
                     onesensor.SignalName = null;
                 }
                 SensorList.Add(onesensor);
             }
         }
         ReSet();
         return(true);
     }
     ReSet();
     return(false);
 }
Exemplo n.º 16
0
        /// <summary>
        /// Gets all the data from all sensor types in the blob storage
        /// according to the date and device that are
        /// entered as the parameters and packs the data in as a weather report.
        /// </summary>
        /// <param name="dateText"></param>
        /// <param name="deviceName"></param>
        /// <returns></returns>
        public WeatherReport GetWeatherReport(string dateText, string deviceName)
        {
            List <SensorType> dataTemperature = GetDataFromFile(dateText, deviceName, "temperature");
            List <SensorType> dataHumidity    = GetDataFromFile(dateText, deviceName, "humidity");
            List <SensorType> dataRainfall    = GetDataFromFile(dateText, deviceName, "rainfall");

            if (dataTemperature == null && dataHumidity == null && dataRainfall == null)
            {
                return(null);
            }

            DateTime date   = DateTime.Parse(dateText);
            var      device = new Device
            {
                DeviceName = deviceName,
                Date       = date
            };

            List <SensorList> sensorTypes           = new List <SensorList>();
            SensorList        sensorListTemperature = new SensorList();

            sensorListTemperature.sensorName = "temperature";
            sensorListTemperature.sensorList = dataTemperature;

            SensorList sensorListHumidity = new SensorList();

            sensorListHumidity.sensorName = "humidity";
            sensorListHumidity.sensorList = dataHumidity;

            SensorList sensorListRainfall = new SensorList();

            sensorListRainfall.sensorName = "rainfall";
            sensorListRainfall.sensorList = dataRainfall;

            sensorTypes.Add(sensorListTemperature);
            sensorTypes.Add(sensorListHumidity);
            sensorTypes.Add(sensorListRainfall);

            WeatherReport report = new WeatherReport();

            report.Device      = device;
            report.SensorTypes = sensorTypes;

            return(report);
        }
Exemplo n.º 17
0
        private void HookUpAccelerometer()
        {
            try
            {
                SensorList <Accelerometer3D> sl = SensorManager.GetSensorsByTypeId <Accelerometer3D>( );
                if (sl.Count > 0)
                {
                    Accelerometer3D accel = sl[0];
                    accel.AutoUpdateDataReport = true;
                    accel.DataReportChanged   += new DataReportChangedEventHandler(DataReport_Changed);
                }

                availabilityLabel.Text = "Accelerometers available = " + sl.Count;
            }
            catch (SensorPlatformException)
            {
                // This exception will also be hit in the Shown message handler.
            }
        }
Exemplo n.º 18
0
        public WocketsController(string name, string filename, string description)
        {
            this._Name        = name;
            this._Filename    = filename;
            this._Description = description;



            this.savingEvent     = new AutoResetEvent(false);
            this.waitToSaveEvent = new AutoResetEvent(false);

            this.pollingEvent     = new AutoResetEvent(false);
            this.waitToPollEvent  = new AutoResetEvent(false);
            this.classifyingEvent = new AutoResetEvent(false);
            this.trainingEvent    = new AutoResetEvent(false);

            this._Decoders  = new DecoderList();
            this._Receivers = new ReceiverList();
            this._Sensors   = new SensorList();
        }
Exemplo n.º 19
0
        public UasBase(LagoVista.IoT.DeviceManagement.Core.Models.Device device)
        {
            _device = device;

            Acc = new ObservableCollection <DOF3Sensor>();
            Acc.Add(new DOF3Sensor());
            Gyro = new ObservableCollection <DOF3Sensor>();
            Gyro.Add(new DOF3Sensor());
            Magnometer = new ObservableCollection <DOF3Sensor>();
            Magnometer.Add(new DOF3Sensor());
            EKFStatus = new EKF();
            GPSs      = new ObservableCollection <GPS>();
            GPSs.Add(new GPS());
            Batteries = new ObservableCollection <Battery>();
            Batteries.Add(new Battery());
            SystemStatus     = new SystemStatus();
            Attitude         = new Attitude();
            FlightController = new FlightController();
            PowerStatus      = new PowerStatus();
            RangeFinder      = new RangeFinder();
            Comms            = new Comms();
            Location         = new GeoLocation();

            Channels = new ObservableCollection <RCChannel>();
            for (var idx = 0; idx < 16; ++idx)
            {
                Channels.Add(new RCChannel());
            }

            ServoOutputs = new ObservableCollection <ServoOutput>();
            for (var idx = 0; idx < 16; ++idx)
            {
                ServoOutputs.Add(new ServoOutput());
            }

            ComponentId = 1;
            SystemId    = 1;

            Sensors = new SensorList();
        }
Exemplo n.º 20
0
    public void SetSensorsFromNode(int nodeId, int i)
    {
        if (api.LoginCredential == null)
        {
            return;
        }

        StartCoroutine(api.Request(api.ListSensor(nodeId), s =>
        {
            XmlSerializer d = new XmlSerializer(typeof(SensorList));
            using (var r = new System.IO.StringReader(s))
            {
                SensorList l     = (SensorList)d.Deserialize(r);
                nodes[i].sensors = l.Sensors;

                if (i == nodes.Count - 1)
                {
                    sensorsComplete = true;
                }
            }
        }));
    }
Exemplo n.º 21
0
        private async Task PublishSensors()
        {
            SensorList sensorList = await _lupusecService.GetSensorsAsync();

            _logger.LogDebug("Received {countSensors} sensors", sensorList.Sensors.Count);

            RecordList recordList = await _lupusecService.GetRecordsAsync();

            _logger.LogDebug("Received records");

            foreach (var sensor in sensorList.Sensors)
            {
                TryCall(sensor, item => PublishSensor(recordList, item));
            }

            AlarmBinarySensor alarmBinarySensorArea1 = new AlarmBinarySensor(_configuration, 1);
            AlarmBinarySensor alarmBinarySensorArea2 = new AlarmBinarySensor(_configuration, 2);

            alarmBinarySensorArea1.SetState(sensorList.Sensors);
            alarmBinarySensorArea2.SetState(sensorList.Sensors);
            PublishStateToMqtt(alarmBinarySensorArea1);
            PublishStateToMqtt(alarmBinarySensorArea2);
        }
Exemplo n.º 22
0
 /// <summary>
 /// 删除传感器标记
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void  除ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     SensorList.Remove(SelectSensor);
     SelectSensor = null;
     ReSet();
 }
Exemplo n.º 23
0
        public void Dispose()
        {
#if (PocketPC)
            if (dataCollectionThread != null)
            {
                dataCollectionThread.Abort();
            }

            if (interfaceActivityThread != null)
            {
                interfaceActivityThread.Abort();
            }
#endif
            if (aPollingThread != null)
            {
                aPollingThread.Abort();
            }

            if (aSavingThread != null)
            {
                aSavingThread.Abort();
            }


            if (trainingTW != null)
            {
                trainingTW.Flush();
                trainingTW.Close();
                trainingTW = null;
            }
            if (structureTW != null)
            {
                structureTW.Flush();
                structureTW.Close();
                structureTW = null;
            }
            for (int i = 0; (i < this._Receivers.Count); i++)
            {
                //this._Receivers[i]._Status = ReceiverStatus.Disconnected;
                //Thread.Sleep(100);
                if (this._Sensors[i]._Loaded)
                {
                    this._Receivers[i].Dispose();
                    Thread.Sleep(1000);
                    this._Receivers[i] = null;
                }
            }

            this._Receivers = null;

            for (int i = 0; (i < this._Sensors.Count); i++)
            {
                if (this._Sensors[i]._Loaded)
                {
                    this._Sensors[i].Dispose();
                    this._Decoders[i].Dispose();
                    this._Sensors[i]  = null;
                    this._Decoders[i] = null;
                }
            }

            this._Sensors  = null;
            this._Decoders = null;

            //NetworkStacks._BluetoothStack.Dispose();
        }
Exemplo n.º 24
0
        public void Dispose()
        {
            #if (PocketPC)
            if (dataCollectionThread != null)
                dataCollectionThread.Abort();

            if (interfaceActivityThread != null)
                interfaceActivityThread.Abort();
            #endif
            if (aPollingThread != null)
                aPollingThread.Abort();

            if (aSavingThread != null)
                aSavingThread.Abort();

            if (trainingTW != null)
            {
                trainingTW.Flush();
                trainingTW.Close();
                trainingTW = null;
            }
            if (structureTW != null)
            {
                structureTW.Flush();
                structureTW.Close();
                structureTW = null;
            }
            for (int i = 0; (i < this._Receivers.Count); i++)
            {
                //this._Receivers[i]._Status = ReceiverStatus.Disconnected;
                //Thread.Sleep(100);
                if (this._Sensors[i]._Loaded)
                {
                    this._Receivers[i].Dispose();
                    Thread.Sleep(1000);
                    this._Receivers[i] = null;
                }
            }

            this._Receivers = null;

            for (int i = 0; (i < this._Sensors.Count); i++)
                if (this._Sensors[i]._Loaded)
                {
                    this._Sensors[i].Dispose();
                    this._Decoders[i].Dispose();
                    this._Sensors[i] = null;
                    this._Decoders[i] = null;
                }

            this._Sensors = null;
            this._Decoders = null;

            //NetworkStacks._BluetoothStack.Dispose();
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            socketClient = new SocketClient(ServerIPAddress);
            Console.WriteLine("Hello");
            socketClient.Connect();
            Console.WriteLine("Yes");

            SensorList.Initialize();
            try { Sak.InitalizeSaker(); } catch (Exception e) { Console.WriteLine(e); }

            Thread photoThread = new Thread(PhotoLoop);

            photoThread.Start();

            Dictionary <byte, Dictionary <byte, List <Sensor> > > sensorsByBusByAddr = new Dictionary <byte, Dictionary <byte, List <Sensor> > >();

            foreach (var sensor in SensorList.Sensors)
            {
                if (sensor is I2cSensor i2cSensor)
                {
                    if (i2cSensor.Device == null)
                    {
                        continue;
                    }
                    sensorsByBusByAddr.GetValueCreateNew((byte)i2cSensor.Device.ConnectionSettings.BusId)
                    .GetValueCreateNew((byte)i2cSensor.Device.ConnectionSettings.DeviceAddress).Add(i2cSensor);
                }
                else
                {
                    sensorsByBusByAddr.GetValueCreateNew((byte)1).GetValueCreateNew((byte)1).Add(sensor);
                }
            }

            while (true)
            {
                DateTime now = DateTime.Now;

                Dictionary <byte, byte> errorCounts = new Dictionary <byte, byte>();

                List <Task> tasks = new List <Task>();
                foreach (var sensorsByAddr in sensorsByBusByAddr.Values)
                {
                    tasks.Add(new Task(() => {
                        try {
                            foreach (var sensors in sensorsByAddr.Values)
                            {
                                bool skipRest = false;
                                foreach (var sensor in sensors)
                                {
                                    sensor.UpdateValues();
                                    if (skipRest)
                                    {
                                        foreach (SensorValue sensorValue in sensor.GetSensorValues())
                                        {
                                            sensorValue.online = false;
                                        }
                                    }
                                    else if (!sensor.GetSensorValues()[0].online)
                                    {
                                        if (errorCounts.ChangeValueCreateDefault(sensor.SensorId, c => ++ c) == 5)
                                        {
                                            Console.WriteLine("Startar om usb-hubben...");
                                            Bash("sudo uhubctl -l 1-1 -p 2 -a 0");
                                            Thread.Sleep(100);
                                            Bash("sudo uhubctl -l 1-1 -p 2 -a 1");
                                        }
                                        skipRest = true;
                                        continue;
                                    }
                                    errorCounts[sensor.SensorId] = 0;
                                }
                            }
                        } catch (Exception e) { Console.WriteLine(e); }
                    }));
                }
                tasks.ForEach(t => t.Start());
                tasks.ForEach(t => t.Wait());

                if (socketClient.sender.Connected)
                {
                    SendSensorData(SensorList.Sensors, socketClient, now);
                    Console.WriteLine("Connected");
                }
                else
                {
                    socketClient.Connect();
                    Console.WriteLine("Not connected");
                }

                while (DateTime.Now.Second == now.Second)
                {
                    Thread.Sleep(1);
                }
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="gattService">Gatt Service found for this sensor</param>
        /// <param name="sensorIndex">SensorIndex</param>
        public CC2650SensorTag(GattDeviceService gattService, SensorIndexes sensorIndex, SensorDataDelegate callMeBack)
        {
            Debug.WriteLine("Begin sensor constructor: " + sensorIndex.ToString());
            try
            {
                NotificationState = NotificationStates.off;
                SensorList.Add(this);
                GattService     = gattService;
                HasSetCallBacks = false;
                SensorIndex     = sensorIndex;
                Guid guidNull         = Guid.Empty;
                Guid guidData         = guidNull;
                Guid guidNotification = guidNull;
                Guid guidConfiguraton = guidNull;
                Guid guidPeriod       = guidNull;
                Guid guidAddress      = guidNull;
                Guid guidDevId        = guidNull;

                CallMeBack = callMeBack;

                IO_IsOn = false;

                switch (SensorIndex)
                {
                case SensorIndexes.KEYS:
                    guidNotification = BUTTONS_NOTIFICATION_GUID;
                    break;

                case SensorIndexes.IO_SENSOR:
                    guidData         = IO_SENSOR_DATA_GUID;
                    guidConfiguraton = IO_SENSOR_CONFIGURATION_GUID;
                    break;

                case SensorIndexes.REGISTERS:
                    guidData    = REGISTERS_DATA_GUID;
                    guidAddress = REGISTERS_ADDRESS_GUID;
                    guidDevId   = REGISTERS_DEVICE_ID_GUID;
                    break;

                default:
                    guidData         = new Guid(UUIDBase[(int)SensorIndex] + SENSOR_GUID_SUFFFIX);
                    guidNotification = new Guid(UUIDBase[(int)SensorIndex] + SENSOR_NOTIFICATION_GUID_SUFFFIX);
                    guidConfiguraton = new Guid(UUIDBase[(int)SensorIndex] + SENSOR_ENABLE_GUID_SUFFFIX);
                    guidPeriod       = new Guid(UUIDBase[(int)SensorIndex] + SENSOR_PERIOD_GUID_SUFFFIX);
                    break;
                }

                IReadOnlyList <GattCharacteristic> characteristicList_Data          = null;
                IReadOnlyList <GattCharacteristic> characteristicList_Notification  = null;
                IReadOnlyList <GattCharacteristic> characteristicList_Configuration = null;
                IReadOnlyList <GattCharacteristic> characteristicList_Period        = null;

                IReadOnlyList <GattCharacteristic> characteristicList_Address   = null;
                IReadOnlyList <GattCharacteristic> characteristicList_Device_Id = null;

                if (guidData != guidNull)
                {
                    characteristicList_Data = gattService.GetCharacteristics(guidData);
                }
                if (guidNotification != guidNull)
                {
                    characteristicList_Notification = gattService.GetCharacteristics(guidNotification);
                }
                if (guidConfiguraton != guidNull)
                {
                    characteristicList_Configuration = gattService.GetCharacteristics(guidConfiguraton);
                }
                if (guidPeriod != guidNull)
                {
                    characteristicList_Period = gattService.GetCharacteristics(guidPeriod);
                }

                if (guidAddress != guidNull)
                {
                    characteristicList_Address = gattService.GetCharacteristics(guidAddress);
                }
                if (guidDevId != guidNull)
                {
                    characteristicList_Device_Id = gattService.GetCharacteristics(guidDevId);
                }

                if (characteristicList_Data != null)
                {
                    if (characteristicList_Data.Count > 0)
                    {
                        Data = characteristicList_Data[0];
                    }
                }
                if (characteristicList_Notification != null)
                {
                    if (characteristicList_Notification.Count > 0)
                    {
                        Notification = characteristicList_Notification[0];
                    }
                }
                if (characteristicList_Configuration != null)
                {
                    if (characteristicList_Configuration.Count > 0)
                    {
                        Configuration = characteristicList_Configuration[0];
                    }
                }
                if (characteristicList_Period != null)
                {
                    if (characteristicList_Period.Count > 0)
                    {
                        Data = characteristicList_Period[0];
                    }
                }

                if (characteristicList_Address != null)
                {
                    if (characteristicList_Address.Count > 0)
                    {
                        Address = characteristicList_Address[0];
                    }
                }
                if (characteristicList_Device_Id != null)
                {
                    if (characteristicList_Device_Id.Count > 0)
                    {
                        Device_Id = characteristicList_Device_Id[0];
                    }
                }

                SensorsCharacteristicsList[(int)sensorIndex] = this;

                if (SensorIndex >= 0 && SensorIndex != SensorIndexes.IO_SENSOR && SensorIndex != SensorIndexes.REGISTERS)
                {
                    ActiveCharacteristicNotifications[(int)SensorIndex] = Notification;
                    Task.Run(() => this.SetChangedNotifactionHandler()).Wait(); //Could leave out Wait but potentially could action this instance too soon

                    Task.Run(() => this.TurnOnSensor()).Wait();                 //This launches a new thread for this action but stalls the constructor thread.
                }
            } catch (Exception ex)
            {
                Debug.WriteLine("Error: CC2650SensorTag() Constructor: " + SensorIndex.ToString() + " " + ex.Message);
            }
            IncProgressCounter();
            Debug.WriteLine("End sensor constructor: " + SensorIndex.ToString());
        }
Exemplo n.º 27
0
        private void PopulatePanel()
        {
            try
            {
                SensorList <AmbientLightSensor> alsList = SensorManager.GetSensorsByTypeId <AmbientLightSensor>();

                panel.Controls.Clear();

                int ambientLightSensors = 0;

                foreach (AmbientLightSensor sensor in alsList)
                {
                    // Create a new progress bar to monitor light level.
                    var pb = new ProgressBar
                    {
                        Width   = 300,
                        Height  = 20,
                        Top     = 10 + (40 * ambientLightSensors),
                        Left    = 10,
                        Maximum = maxIntensity
                    };

                    // Identify the control the bar represents.
                    var label = new Label
                    {
                        Text   = "SensorId = " + sensor.SensorId.ToString(),
                        Top    = pb.Top,
                        Left   = pb.Right + 20,
                        Height = pb.Height,
                        Width  = 300
                    };

                    // Add controls to panel.
                    panel.Controls.AddRange(new Control[] { pb, label });

                    // Map sensor id to progress bar for lookup in data report handler.
                    sensorMap[sensor.SensorId.Value] = pb;

                    // set intial progress bar value
                    _ = sensor.TryUpdateData();
                    float current = sensor.CurrentLuminousIntensity.Intensity;
                    pb.Value = Math.Min((int)current, maxIntensity);

                    // Set up automatc data report handling.
                    sensor.AutoUpdateDataReport = true;
                    sensor.DataReportChanged   += DataReportChanged;

                    ambientLightSensors++;
                }

                if (ambientLightSensors == 0)
                {
                    var label = new Label
                    {
                        Text   = "No Sensors Found",
                        Top    = 10,
                        Left   = 10,
                        Height = 20,
                        Width  = 300
                    };
                    panel.Controls.Add(label);
                }
            }
            catch (SensorPlatformException)
            {
                // This exception will also be hit in the Shown message handler.
            }
        }
Exemplo n.º 28
0
        public WocketsController(string name, string filename, string description)
        {
            this._Name = name;
            this._Filename = filename;
            this._Description = description;

            this.savingEvent = new AutoResetEvent(false);
            this.waitToSaveEvent = new AutoResetEvent(false);

            this.pollingEvent = new AutoResetEvent(false);
            this.waitToPollEvent = new AutoResetEvent(false);
            this.classifyingEvent = new AutoResetEvent(false);
            this.trainingEvent = new AutoResetEvent(false);

            this._Decoders = new DecoderList();
            this._Receivers = new ReceiverList();
            this._Sensors = new SensorList();
        }