Esempio n. 1
0
 public void AddSensorReadings(SensorData[] data)
 {
     if (data != null && data.Length > 0)
     {
         lock (this.sensorDataBuffer)
         {
             this.sensorDataBuffer.Add(data);
         }
     }
 }
Esempio n. 2
0
 public static string CreateCSVPacket(SensorData sensorData)
 {
     string packet = string.Empty;
     packet = packet.AddSeperatedValue(DateTime.Now.ToString(), ",");
     packet = packet.AddSeperatedValue(sensorData.AnalogLight.ToString(), ",");
     packet = packet.AddSeperatedValue(sensorData.EntityCount.ToString(), ",");
     packet = packet.AddSeperatedValue(sensorData.Humidity.ToString(), ",");
     packet = packet.AddSeperatedValue(sensorData.Pressure.ToString(), ",");
     packet = packet.AddSeperatedValue(sensorData.Temperature.ToString(), ",");
     return packet;
 }
 public override SensorData GetData()
 {
     var sensorData = new SensorData
                          {
                              SensorType = this,
                              ReadTime = DateTime.Now,
                              Humidity = this.GetHumidity(),
                              Pressure = this.GetPressure(),
                              Temperature = this.GetTemperature()
                          };
     return sensorData;
 }
Esempio n. 4
0
        private SensorData[] SampleSensorData()
        {
            ArrayList sample = this.hardwareController.GetAllSensors();
            SensorData[] result = null;
            if (sample != null)
            {
                result = new SensorData[sample.Count];
                for (int k = 0; k < sample.Count; k++)
                {
                    result[k] = ((Sensor)sample[k]).GetData();
                }
            }

            return result;
        }
Esempio n. 5
0
        public static string SerializeJSON(int nodeID, SensorData[] sensorData)
        {
            string jsonstring = "{";
            if (nodeID >= 0)
            {
                jsonstring = jsonstring + "\"" + nodeID + "\":{";
                if (sensorData != null)
                {
                    int objnum = 0;
                    SensorData dataobj = sensorData[objnum];
                    if (dataobj == null && sensorData.Length > 1)
                    {
                        objnum = 1;
                        while (dataobj == null && objnum < sensorData.Length)
                        {
                            dataobj = sensorData[objnum];
                            objnum++;
                        }
                    }

                    if (dataobj != null)
                    {
                        jsonstring = jsonstring + "\"" + sensorData[objnum].SensorType.ID + "\":{";
                        jsonstring = jsonstring + SerializeDataComponent(sensorData[objnum]) + "}";
                        objnum++;
                        if (objnum < sensorData.Length)
                        {
                            for (int k = objnum; k < sensorData.Length; k++)
                            {
                                jsonstring = jsonstring + ",\"" + sensorData[objnum].SensorType.ID + "\":{";
                                jsonstring = jsonstring + SerializeDataComponent(sensorData[k]) + "}";
                            }
                        }
                    }
                }

                jsonstring = jsonstring + "}";
            }

            return jsonstring + "}";
        }
 public override SensorData GetData()
 {
     var sensorData = new SensorData { AnalogLight = this.GetAnalogLightValue() };
     return sensorData;
 }
        public void PollSensorReadingsRemovesSensorData()
        {
            var hardwareController = new HardwareController();
            var random = new Random();

            SensorData[] sensorDatas = new SensorData[random.Next(1, 5)];
            for (int i = 0; i < sensorDatas.Length; i++)
            {
                var sensorData = new SensorData
                                     {
                                         Humidity = random.Next(0, 100) / 100,
                                         Pressure = random.Next(0, 100) / 100
                                     };

                sensorDatas[i] = sensorData;
            }

            hardwareController.AddSensorReadings(sensorDatas);
            hardwareController.PollSensorReadings(0);

            Assert.AreEqual(0, hardwareController.GetSensorDataBufferCount());
        }
        public void GetSensorDataBufferCount()
        {
            var hardwareController = new HardwareController();
            var random = new Random();

            int dataCount = random.Next(1, 5);
            for (int i = 0; i < dataCount; i++)
            {
                SensorData[] sensorDatas = new SensorData[random.Next(1, 5)];
                for (int j = 0; j < sensorDatas.Length; j++)
                {
                    var sensorData = new SensorData
                                         {
                                             Humidity = random.Next(0, 100) / 100,
                                             Pressure = random.Next(0, 100) / 100
                                         };

                    sensorDatas[j] = sensorData;
                }

                hardwareController.AddSensorReadings(sensorDatas);
            }

            Assert.AreEqual(dataCount, hardwareController.GetSensorDataBufferCount());
        }
Esempio n. 9
0
        private static string SerializeDataComponent(SensorData dataobj)
        {
            string jsonfragment = string.Empty;
            Type sensortype;
            try
            {
                sensortype = dataobj.SensorType.GetType();
            }
            catch (NullReferenceException e)
            {
                throw new ArgumentNullException("SensorData Sensor object not specified");
            }

            if (sensortype.IsClass)
            {
                int k = 0;
                if (dataobj.ReadTime != DateTime.MinValue)
                {
                    jsonfragment = jsonfragment + "\"" + READTIME_ID + "\":\""
                                                + dataobj.ReadTime.ToString("dd'/'MM'/'yyyy hh':'mm':'ss") + "\"";
                }

                if (dataobj.PollTime != DateTime.MinValue)
                {
                    if (jsonfragment != string.Empty)
                    {
                        jsonfragment = jsonfragment + ",";
                    }
                    jsonfragment = jsonfragment + "\"" + POLLTIME_ID + "\":\""
                                            + dataobj.PollTime.ToString("dd'/'MM'/'yyyy hh':'mm':'ss") + "\"";
                }
                string[] artefacts = new string[sensortype.GetInterfaces().Length];
                foreach (Type iface in sensortype.GetInterfaces())
                {
                    artefacts[k] = SerializeInterface(iface.Name, dataobj);
                    k++;
                }

                for (int l = 0; l < artefacts.Length; l++)
                {
                    if (l < artefacts.Length - 1)
                    {
                        if (jsonfragment != string.Empty && artefacts[l] != string.Empty)
                        {
                            jsonfragment = jsonfragment + ",";
                        }
                    }

                    jsonfragment = jsonfragment + artefacts[l];
                }
            }

            return jsonfragment;
        }
Esempio n. 10
0
        private static string SerializeInterface(string ifaceName, SensorData dataobj)
        {
            string jsonfragment = string.Empty;
            switch (ifaceName)
            {
                case "IEntityCountSensor":
                    jsonfragment = jsonfragment + "\"" + ENTITYCOUNT_ID + "\":" + dataobj.EntityCount;
                    break;
                case "IEntityPositionSensor":
                    if (dataobj.EntityPositions != null)
                    {
                        int count = 0;
                        bool prevEntry = false;
                        foreach (Position pos in dataobj.EntityPositions)
                        {
                            if (pos.Depth != 0 || pos.X != 0 || pos.Depth != 0)
                            {
                                if (prevEntry == true)
                                {
                                    jsonfragment = jsonfragment + ",";
                                }

                                jsonfragment = jsonfragment + "\"" + ENTITYPOS_ID + "." + count + "\":{\"";
                                jsonfragment = jsonfragment + XPOS_ID + "\":" + pos.X + ",\"";
                                jsonfragment = jsonfragment + YPOS_ID + "\":" + pos.Y + ",\"";
                                jsonfragment = jsonfragment + DEPTHPOS_ID + "\":" + pos.Depth + "}";
                                count++;
                                prevEntry = true;
                            }
                        }
                    }

                    break;
                case "IHumiditySensor":
                    jsonfragment = jsonfragment + "\"" + HUMIDITY_ID + "\":" + dataobj.Humidity;
                    break;
                case "ILightSensor":
                    jsonfragment = jsonfragment + "\"" + LIGHT_ID + "\":" + dataobj.AnalogLight;
                    break;
                case "IPowerSensor":
                    jsonfragment = jsonfragment + "\"" + POWER_ID + "\":" + dataobj.PowerWatt;
                    break;
                case "IPressureSensor":
                    jsonfragment = jsonfragment + "\"" + PRESSURE_ID + "\":" + dataobj.Pressure;
                    break;
                case "ISound":
                    jsonfragment = jsonfragment + "\"" + SOUND_ID + "\":" + dataobj.SoundDb;
                    break;
                case "ITemperatureSensor":
                    jsonfragment = jsonfragment + "\"" + TEMPERATURE_ID + "\":" + dataobj.Temperature;
                    break;
                case "IVibrationSensor":
                    jsonfragment = jsonfragment + "\"" + VIBRATION_ID + "\":" + dataobj.VibrationHz;
                    break;
                case "IWindSpeedSensor":
                    jsonfragment = jsonfragment + "\"" + WINDSPEED_ID + "\":" + dataobj.Windspeed;
                    break;
                default:
                    break;
            }

            return jsonfragment;
        }
Esempio n. 11
0
 public override SensorData GetData()
 {
     var sensorData = new SensorData
                          {
                              SensorType = this,
                              ReadTime = DateTime.Now,
                              EntityCount = this.GetEntityCount(),
                              EntityPositions = this.GetEntityPositions()
                          };
     return sensorData;
 }