Esempio n. 1
0
        public CollectorsValues GetIndoorCollectors()
        {
            var collectorsValues = new CollectorsValues();

            var dashboard = _context.Dashboards.Include(t => t.OutdoorCollector.Sensors)
                            .First();

            if (dashboard != null)
            {
                // Vnitřní senzory
                var indoorCollectors = new List <CollectorValues>();
                foreach (var collector in _context.Collectors.Where(t => t.Id != dashboard.OutdoorCollector.Id).Include(t => t.Sensors))
                {
                    var collectorValues    = new CollectorValues();
                    var indoorSensorValues = new List <SensorValue>();
                    foreach (var sensor in collector.Sensors)
                    {
                        var sv = new SensorValue();
                        sv.Sensor = sensor;
                        sv.Value  = _context.SensorRecords.Where(t => t.SensorId == sensor.Id).LastOrDefault().Value;

                        indoorSensorValues.Add(sv);
                    }
                    collectorValues.Sensors  = indoorSensorValues;
                    collectorValues.Location = collector.Name;
                    indoorCollectors.Add(collectorValues);
                }
                collectorsValues.Collectors = indoorCollectors.ToArray();
            }

            return(collectorsValues);
        }
Esempio n. 2
0
        public override bool HandleBasicReport(byte[] message)
        {
            bool handled = false;
            //
            //byte cmdLength = message[6];
            byte cmdClass = message[7];
            byte cmdType  = message[8];

            //
            if (cmdClass == (byte)CommandClass.SensorMultilevel && cmdType == (byte)Command.SensorMultilevelReport)
            {
                SensorValue sensorval = SensorValue.Parse(message);
                if (sensorval.Parameter == ZWaveSensorParameter.LUMINANCE)
                {
                    sensorval.Value = BitConverter.ToUInt16(new byte[2] {
                        message[12], message[11]
                    }, 0);
                    nodeHost.RaiseUpdateParameterEvent(nodeHost, 0, sensorval.EventType, sensorval.Value);
                    handled = true;
                }
            }
            //
            // if not handled, fallback to Generic Sensor
            if (!handled)
            {
                handled = base.HandleBasicReport(message);
            }
            //
            return(handled);
        }
Esempio n. 3
0
        public override bool HandleBasicReport(byte[] message)
        {
            bool handled = false;
            //
            //byte cmdLength = message[6];
            byte cmdClass = message[7];
            byte cmdType  = message[8];

            //
            if (cmdClass == (byte)CommandClass.COMMAND_CLASS_SENSOR_MULTILEVEL && cmdType == 0x05)
            {
                SensorValue sensorval = Sensor.ParseSensorValue(message);
                if (sensorval.Parameter == ZWaveSensorParameter.LUMINANCE)
                {
                    // thanks to Zed for reporting this: http://www.homegenie.it/forum/index.php?topic=29.msg140
                    sensorval.Value = BitConverter.ToUInt16(new byte[2] {
                        message[12], message[11]
                    }, 0);
                    nodeHost.RaiseUpdateParameterEvent(nodeHost, 0, sensorval.EventType, sensorval.Value);
                    handled = true;
                }
            }
            //
            // if not handled, fallback to Generic Sensor
            if (!handled)
            {
                handled = base.HandleBasicReport(message);
            }
            //
            return(handled);
        }
Esempio n. 4
0
        public static IList <SensorValue> ExtractSensorValues(IList <byte> parcel)
        {
            if (parcel == null)
            {
                return(null);
            }
            int i = parcel.IndexOf(CommandByte);

            if (i == -1)
            {
                return(null);
            }

            i += ShiftIndexCmd;
            if (!parcel.IndexExist(i + 1))
            {
                return(null);
            }

            var lst = new List <SensorValue>();

            for (int k = i; k < (parcel.Count - 1); k += 2)
            {
                lst.Add(SensorValue.From2Bytes(parcel[k], parcel[k + 1]));
            }
            return(lst);
        }
 /// <summary>
 /// 복사 생성자
 /// </summary>
 /// <param name="other">복사할 다른 개체</param>
 public SensorValue(SensorValue other)
 {
     Acceleration    = new SensorPoint(other.Acceleration.x, other.Acceleration.y, other.Acceleration.z);
     AngularVelocity = new SensorPoint(other.AngularVelocity.x, other.AngularVelocity.y, other.AngularVelocity.z);
     Position        = new SensorPoint(other.Position.x, other.Position.y, other.Position.z);
     Status          = other.Status;
 }
Esempio n. 6
0
        // Get all sensorvalues from the web service
        static async Task <SensorValue[]> GetSensorValues()
        {
            SensorValue[] sensorValues = new SensorValue[0];
            using (HttpClient client = new HttpClient())
            {
                try
                {
                    client.BaseAddress = new Uri(apipath);
                    client.DefaultRequestHeaders.Accept.Clear();

                    var requestBody = JsonConvert.SerializeObject(sensorList.Select(obj => obj.SensorId).ToArray());
                    Console.WriteLine(requestBody);
                    var httpContent = new StringContent(requestBody, Encoding.UTF8, "application/json");
                    // Get sensor values
                    HttpResponseMessage response = await client.PostAsync(apipath + "api/values", httpContent);

                    if (response.IsSuccessStatusCode)
                    {
                        var stringResponse = await response.Content.ReadAsStringAsync();

                        sensorValues = JsonConvert.DeserializeObject <SensorValue[]>(stringResponse);
                        Console.WriteLine("{0} sensor values retreived", sensorValues.Length);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine($"ERROR - GetSensorValues {e.Message}");
                }
            }

            return(sensorValues);
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,SensorType,SensorID,Value,TimeStamp")] SensorValue sensorValue)
        {
            if (id != sensorValue.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(sensorValue);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SensorValueExists(sensorValue.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(sensorValue));
        }
Esempio n. 8
0
        void OnNewSensorValueHandler(SensorValue sensorBaseArg)
        {
            DataStore.DAL_PacientData.AddData(sensorBaseArg);

            sensorValueList.Insert(0, sensorBaseArg);
            this.BeginInvoke(new VoidFunctionDelegate(BindDataGridToListOfValues));
        }
Esempio n. 9
0
        public static ListValue PartList(this IShipconstruct vessel, string partType, SharedObjects sharedObj)
        {
            var list     = new ListValue();
            var partList = vessel.Parts.ToList();

            switch (partType.ToUpper())
            {
            case "RESOURCES":
                list = ResourceValue.PartsToList(partList);
                break;

            case "PARTS":
                list = PartValue.PartsToList(partList, sharedObj);
                break;

            case "ENGINES":
                list = EngineValue.PartsToList(partList, sharedObj);
                break;

            case "SENSORS":
                list = SensorValue.PartsToList(partList, sharedObj);
                break;

            case "ELEMENTS":
                list = ElementValue.PartsToList(partList);
                break;

            case "DOCKINGPORTS":
                list = DockingPortValue.PartsToList(partList, sharedObj);
                break;
            }
            return(list);
        }
    /// <summary>
    /// 현재 데이터를 모두 구간처리 함
    /// </summary>
    public void RefineAll()
    {
        if (Data_Refined == null)
        {
            Data_Refined = new List <SensorValue>();
        }
        Data_Refined.Clear();
        foreach (SensorValue S in Data)
        {
            SensorValue SR      = new SensorValue(S);
            float       acc_sum = GetAccPower(S);
            bool        AddData = false;
            switch (S.Status)
            {
            case SensorValue.SV_Status.PreSwing:
            case SensorValue.SV_Status.AfterSwing:
                if (acc_sum >= threshold_static)
                {
                    AddData = true;
                }
                break;

            case SensorValue.SV_Status.SwingHit:
                AddData = true;
                break;
            }
            if (AddData)
            {
                Data_Refined.Add(SR);
            }
        }
        ev_data_refined?.Invoke(Data_Refined);
    }
Esempio n. 11
0
        public FunctionSensor(CircuitState circuitState, CircuitSymbol symbol, int[] result) : base(circuitState, null, result)
        {
            this.CircuitSymbol = symbol;
            Tracer.Assert(this.BitWidth == result.Length);
            switch (this.Sensor.SensorType)
            {
            case SensorType.Series:
            case SensorType.Loop:
                this.sensorValue = new SeriesValue(this.Sensor.Data, this.Sensor.SensorType == SensorType.Loop, this.Sensor.BitWidth);
                break;

            case SensorType.Random:
                this.sensorValue = new RandomValue(this.Sensor.Data, this.Sensor.BitWidth, this.CircuitState.Random);
                break;

            case SensorType.Manual:
                this.sensorValue = new ManualValue(this.Sensor.Data, this.Sensor.BitWidth);
                break;

            default:
                Tracer.Fail();
                this.sensorValue = null;
                break;
            }
        }
Esempio n. 12
0
        private async Task SensorValueChanged(object sender, SensorValue sensorValue)
        {
            var payload = JsonConvert.SerializeObject(new SensorPayload
            {
                Value = sensorValue.Value,
                LastChangeDateTime = sensorValue.LastChangeDateTime
            });

            try
            {
                var message = new MqttApplicationMessageBuilder()
                              .WithTopic(sensorValue.SensorName)
                              .WithPayload(payload)
                              .WithExactlyOnceQoS()
                              .WithRetainFlag()
                              .Build();

                if (_mqttClient.IsConnected)
                {
                    await _mqttClient.PublishAsync(message);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
            }
        }
    private void CheckValue(IDictionary <string, SensorValue> values, string id, double?number, bool valid, string unit)
    {
        SensorValue value = values[id];

        Assert.AreEqual(number, value.Value);
        Assert.AreEqual(valid, value.Valid);
        Assert.AreEqual(unit, value.Unit);
    }
Esempio n. 14
0
 /// <summary>
 /// Calculate single sensor value with alarm option
 /// Non auto save changed to database, you must call entityConntext.SaveChanges() to save changed.
 /// </summary>
 /// <param name="sensorValue"></param>
 /// <param name="alarmLogger"></param>
 public void Calculating(SensorValue sensorValue, bool alarmLogger)
 {
     Calculating(sensorValue);
     if (alarmLogger)
     {
         AlarmBLL.Current.CheckAlarm(sensorValue);
     }
 }
Esempio n. 15
0
        private SensorValue SensorValueExchange(uint password, bool secured, uint sensorType, bool noSelection)
        {
            NurApi hCurApi = hApi != null ? hApi : hLocalApi;

            SensorValue     sv      = new SensorValue();
            List <BitEntry> entries = new List <BitEntry>();

            NurApi.CustomExchangeParams   xch;
            NurApi.CustomExchangeResponse resp;
            int  respLen;
            uint tmpVal;
            int  ticks;

            BitBuffer bb;

            if (hCurApi == null)
            {
                throw new NurApiException("SensorValueExchange(): cannot find NurApi.");
            }

            entries.Add(BuildEntry(ADD_PARAMETER, sensorType, SENSOR_TYPE_BITS));
            bb = BuildCommand(CMD_GETSENSORVAL, entries);

            /* 0 for possible error reception. */
            xch = BuildDefault(bb, 0, false, false);

            ticks = System.Environment.TickCount;
            if (noSelection)
            {
                resp = hCurApi.CustomExchange(password, secured, xch);
            }
            else
            {
                resp = hApi.CustomExchangeSingulated(password, secured, NurApi.BANK_EPC, 32, epc.Length * 8, epc, xch);
            }

            sv.time = System.Environment.TickCount - ticks;
            respLen = resp.tagBytes.Length;

            if (resp.error != NurApiErrors.NUR_NO_ERROR)
            {
                if (respLen >= MIN_ERROR_RESP_LENGTH)
                {
                    InterpretedException("Get sensor value", resp);
                }
                DoException("Get sensor value", resp);
            }

            tmpVal   = resp.tagBytes[0];
            tmpVal <<= 8;
            tmpVal  |= resp.tagBytes[1];

            sv.adError      = IsMaskBitSet(tmpVal, SENSOR_AD_ERR_BIT);
            sv.rangeOrLimit = ((tmpVal >> SENSOR_RANGE_LSH) & SENSOR_RANGE_MASK_VAL);
            sv.adValue      = (tmpVal & SENSOR_AD_VALMASK);

            return(sv);
        }
Esempio n. 16
0
 /// <summary>
 /// Add value in tab sensor list
 /// </summary>
 /// <param name="sv">Sensor value</param>
 /// <param name="sensorName">Sensor name</param>
 private void AddValueInSensorListTab(SensorValue sv, string sensorName)
 {
     for (int i = 0; i < this.SelectedTab.Sensors.Count; i++)
     {
         if (this.SelectedTab.Sensors[i].SensorName == sensorName)
         {
             this.SelectedTab.Sensors[i].Values.Add(sv);
         }
     }
 }
Esempio n. 17
0
        public static SensorValue ToCelsius(this SensorValue temp)
        {
            if (temp.Unit == SensorType.Celsius)
            {
                return(temp);
            }

            var celc = (temp.RawValue - 32) * 5.0 / 9.0;

            return(new SensorValue((float)celc, SensorType.Celsius));
        }
Esempio n. 18
0
        public static SensorValue ToFahrenheit(this SensorValue temp)
        {
            if (temp.Unit == SensorType.Fahrenheit)
            {
                return(temp);
            }

            var fahr = 9.0 / 5.0 * temp.RawValue + 32;

            return(new SensorValue((float)fahr, SensorType.Fahrenheit));
        }
        public async Task <IActionResult> Create([Bind("ID,SensorType,SensorID,Value,TimeStamp")] SensorValue sensorValue)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sensorValue);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(sensorValue));
        }
Esempio n. 20
0
        private void TestSensorValue(SensorValue sensorvalue)
        {
            Assert.NotNull(sensorvalue);

            Assert.InRange(sensorvalue.SensorID, 1, int.MaxValue);

            Assert.NotNull(sensorvalue.Value);

            Assert.True(sensorvalue.Type > 0);
            Assert.True(sensorvalue.Timestamp > DateTime.MinValue);
        }
Esempio n. 21
0
        private void SetCurrentValue <T>(SensorValue <T> sensorValue)
        {
            var changeType = Convert.ChangeType(sensorValue.Min, typeof(int));

            if (changeType != null)
            {
                int min = (int)changeType;
                // ReSharper disable once PossibleNullReferenceException
                int max = (int)Convert.ChangeType(sensorValue.Max, typeof(int));
                SetCurrentValue(sensorValue, min, max + 1);
            }
        }
Esempio n. 22
0
        public async Task <Sensor> Add(SensorValue value)
        {
            if (value == null)
            {
                return(null);
            }
            var sensor = new Sensor(Guid.NewGuid(), value);

            await _db.Sensors.AddAsync(_converter.ToSensorDataModel(sensor));

            await _db.SaveChangesAsync();

            return(await Get(sensor.Id));
        }
Esempio n. 23
0
        /// <summary>
        /// MQTT Client message received event handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Client_ApplicationMessageReceived(object sender, MqttApplicationMessageReceivedEventArgs e)
        {
            //Output is from MQTTNet examples
            Console.WriteLine("### RECEIVED APPLICATION MESSAGE ###");
            Console.WriteLine($"+ Topic = {e.ApplicationMessage.Topic}");
            Console.WriteLine($"+ Payload = {Encoding.UTF8.GetString(e.ApplicationMessage.Payload)}");
            Console.WriteLine($"+ QoS = {e.ApplicationMessage.QualityOfServiceLevel}");
            Console.WriteLine($"+ Retain = {e.ApplicationMessage.Retain}");
            Console.WriteLine();

            currentValue = JsonConvert.DeserializeObject <SensorValue>(Encoding.UTF8.GetString(e.ApplicationMessage.Payload), new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Utc
            });
            processThresholdExceededLogic();
        }
        public async Task <ActionResult <bool> > TelldusSensorUpdate(SensorUpdatesModel model)
        {
            lock (duplicationRequestLock)
            {
                if (IsDuplicateRequest($"{model.SensorID}|{model.Type}|{model.Value}"))
                {
                    return(Ok(false));
                }
            }

            await TelldusLogStream(new { Timestamp = model?.Timestamp, Message = $"DEVICE {model?.SensorID}: {model?.Type.ToString()} - {model?.Value}" });

            var sensor = jsonDatabaseService.Sensors.FirstOrDefault(s => s.Source == DeviceSource.Telldus && s.SourceID == model?.SensorID.ToString());

            if (sensor != null)
            {
                logger.LogInformation($"Received sensor update from sensor '{sensor}'.");
            }
            else
            {
                logger.LogInformation($"Received sensor update from telldus sensor with ID '{model?.SensorID}'.");
            }

            try
            {
                SensorValue sensorValue = new SensorValue();
                sensorValue.TellstickID = model.SensorID;
                sensorValue.Type        = model.Type;
                sensorValue.Value       = model.Value;
                sensorValue.Timestamp   = model.Timestamp;

                await context.SensorValues.AddAsync(sensorValue);

                await context.SaveChangesAsync();

                if (sensor != null)
                {
                    sensor.LatestValues[model.Type] = sensorValue;
                }

                return(Ok(true));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Failed to insert sensor value for sensor '{model?.SensorID}' into database.");
                return(StatusCode(500));
            }
        }
    public void AddData(SensorValue S)
    {
        Data.Add(S);
        float AccPower = GetAccPower(S);

        Power.Add(AccPower);
        Vector2 PowerData = new Vector2(PowerGraphData.Count, AccPower);

        PowerGraphData.Add(PowerData);

        ev_data_added?.Invoke(S);
        ev_pvdata_added?.Invoke(PowerData);

        ev_data_changed?.Invoke(Data);
        ev_pvdata_changed?.Invoke(PowerGraphData);
    }
Esempio n. 26
0
        public virtual bool HandleBasicReport(byte[] message)
        {
            bool handled = false;
            //
            //byte cmdLength = message[6];
            byte cmdClass = message[7];
            byte cmdType  = message[8];

            //
            if (cmdClass == (byte)CommandClass.Basic && (cmdType == (byte)Command.BasicReport || cmdType == (byte)Command.BasicSet))
            {
                nodeHost.RaiseUpdateParameterEvent(nodeHost, 0, ParameterType.LEVEL, (double)message[9]);
                handled = true;
            }
            else if (cmdClass == (byte)CommandClass.SceneActivation && cmdType == (byte)Command.SceneActivationSet)
            {
                nodeHost.RaiseUpdateParameterEvent(nodeHost, 0, ParameterType.GENERIC, (double)message[9]);
                handled = true;
            }
            else if (cmdClass == (byte)CommandClass.SensorBinary && cmdType == (byte)Command.SensorBinaryReport)
            {
                nodeHost.RaiseUpdateParameterEvent(nodeHost, 0, ParameterType.GENERIC, message[9]);
                handled = true;
            }
            else if (cmdClass == (byte)CommandClass.SensorMultilevel && cmdType == (byte)Command.SensorMultilevelReport)
            {
                var sensor = SensorValue.Parse(message);
                if (sensor.Parameter == ZWaveSensorParameter.UNKNOWN)
                {
                    byte key = message[9];
                    nodeHost.RaiseUpdateParameterEvent(nodeHost, 0, ParameterType.GENERIC, sensor.Value);
                    Console.WriteLine("\nUNHANDLED SENSOR PARAMETER TYPE => " + key + "\n");
                }
                else
                {
                    nodeHost.RaiseUpdateParameterEvent(nodeHost, 0, sensor.EventType, sensor.Value);
                    handled = true;
                }
            }
            else if ((cmdClass == (byte)CommandClass.SensorAlarm && cmdType == (byte)Command.SensorAlarmReport) || (cmdClass == (byte)CommandClass.Alarm && cmdType == (byte)Command.AlarmReport))
            {
                var alarm = AlarmValue.Parse(message);
                nodeHost.RaiseUpdateParameterEvent(nodeHost, 0, alarm.EventType, alarm.Value);
                handled = true;
            }
            return(handled);
        }
Esempio n. 27
0
        //
        // 01 0D 00 04 00 1C 07 9C 02 00 05 FF 00 00 89
        //  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
        //  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14
        //
        // 01 0F 00 04 00 18 09 71 05 07 00 00 FF 07 02 00
        // 01 0F 00 04 00 18 09 71 05 07 FF 00 FF 07 02 00
        //
        public virtual bool HandleBasicReport(byte[] message)
        {
            bool handled = false;
            //
            byte cmd_length = message[6];
            byte cmd_class  = message[7];
            byte cmd_type   = message[8];

            //
            if (cmd_class == (byte)CommandClass.COMMAND_CLASS_BASIC && (cmd_type == 0x03 || cmd_type == 0x01))
            {
                _nodehost._raiseUpdateParameterEvent(_nodehost, 0, ParameterType.PARAMETER_BASIC, (double)message [9]);
                handled = true;
            }
            else if (cmd_class == (byte)CommandClass.COMMAND_CLASS_SCENE_ACTIVATION && cmd_type == 0x01)
            {
                _nodehost._raiseUpdateParameterEvent(_nodehost, 0, ParameterType.PARAMETER_GENERIC, (double)message[9]);
                handled = true;
            }
            else if (cmd_class == (byte)CommandClass.COMMAND_CLASS_SENSOR_BINARY && cmd_type == 0x03)
            {
                _nodehost._raiseUpdateParameterEvent(_nodehost, 0, ParameterType.PARAMETER_GENERIC, message[9]);
                handled = true;
            }
            else if (cmd_class == (byte)CommandClass.COMMAND_CLASS_SENSOR_MULTILEVEL && cmd_type == 0x05)
            {
                SensorValue sensorval = Sensor.ParseSensorValue(message);
                if (sensorval.Parameter == ZWaveSensorParameter.UNKNOWN)
                {
                    byte key = message[9];
                    _nodehost._raiseUpdateParameterEvent(_nodehost, 0, ParameterType.PARAMETER_GENERIC, sensorval.Value);
                    Console.WriteLine("\nUNHANDLED SENSOR PARAMETER TYPE => " + key + "\n");
                }
                else
                {
                    _nodehost._raiseUpdateParameterEvent(_nodehost, 0, sensorval.EventType, sensorval.Value);
                    handled = true;
                }
            }
            else if ((cmd_class == (byte)CommandClass.COMMAND_CLASS_SENSOR_ALARM && cmd_type == 0x02) || (cmd_class == (byte)CommandClass.COMMAND_CLASS_ALARM && cmd_type == 0x05))
            {
                SensorAlarmValue sensoralarmval = Sensor.ParseSensorAlarmValue(message);
                _nodehost._raiseUpdateParameterEvent(_nodehost, 0, sensoralarmval.EventType, sensoralarmval.Value);
                handled = true;
            }
            return(handled);
        }
Esempio n. 28
0
        public NodeEvent GetEvent(ZWaveNode node, byte[] message)
        {
            ZWaveValue zvalue   = ZWaveValue.ExtractValueFromBytes(message, 4);
            var        setPoint = GetSetPointData(node);

            setPoint.Precision = zvalue.Precision;
            setPoint.Scale     = zvalue.Scale;
            setPoint.Size      = zvalue.Size;
            setPoint.Value     = zvalue.Value;
            // convert from Fahrenheit to Celsius if needed
            var ptype = new {
                Type  = (Value)message[2],
                Value = (zvalue.Scale == (int)ZWaveTemperatureScaleType.Fahrenheit ? SensorValue.FahrenheitToCelsius(zvalue.Value) : zvalue.Value)
            };

            return(new NodeEvent(node, EventParameter.ThermostatSetPoint, ptype, 0));
        }
Esempio n. 29
0
        /// <summary>
        /// Post treshold Exceeded
        /// </summary>
        /// <param name="sensorValue"></param>
        public async void PostTresholdValueExceeded(SensorValue sensorValue)
        {
            var postObject = new SensorValuePost(sensorValue,
                                                 messages[SensorValuePosterMessageTypes.ThresholdExceeded]);

            var json = JsonConvert.SerializeObject(postObject, new JsonSerializerSettings
            {
                DateFormatString = "yyyy-MM-ddTHH:mm:ss.ffffff", //have to use custom format because Newtonsoft.Json uses Z to denote UTC on end of datetime string when using ISO
                ContractResolver = new CamelCasePropertyNamesContractResolver(),
            });
            var content = new StringContent(json, Encoding.UTF8, "application/json");
            var result  = await client.PostAsync(Url, content);

            if (!result.IsSuccessStatusCode)
            {
                Console.WriteLine($"SensorValuePoster failed to post {SensorValuePosterMessageTypes.ThresholdExceeded}");
            }
        }
Esempio n. 30
0
        public async Task <Sensor> Update(Guid id, SensorValue value)
        {
            var toBeUpdated = await _db.Sensors
                              .Include(sensor => sensor.Readings)
                              .FirstOrDefaultAsync(sensor => sensor.Id == id);

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

            toBeUpdated.Position = value.Position;
            toBeUpdated.Type     = value.Type;

            await _db.SaveChangesAsync();

            return(_converter.ToSensorDomainModel(toBeUpdated));
        }
Esempio n. 31
0
 public SensorValue getValue(int iSubPID)
 {
     SensorValue sensorValue = new SensorValue();
     switch (m_iPID)
     {
         case 1:
             switch (iSubPID)
             {
                 case 0:
                     sensorValue.EnglishValue = DataA < 128 ? (double)DataA : (double)(DataA - 128);
                     double num1 = sensorValue.EnglishValue;
                     sensorValue.EnglishDisplay = num1.ToString();
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 1:
                     sensorValue.EnglishValue = (double)(DataA & 128);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue == 0.0 ? "OFF" : "ON";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 2:
                     sensorValue.EnglishValue = (double)(DataB & 1);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue == 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 3:
                     sensorValue.EnglishValue = (double)(DataB & 2);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue == 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 4:
                     sensorValue.EnglishValue = (double)(DataB & 4);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue == 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 5:
                     sensorValue.EnglishValue = (double)(DataB & 16);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue != 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 6:
                     sensorValue.EnglishValue = (double)(DataB & 32);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue != 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 7:
                     sensorValue.EnglishValue = (double)(DataB & 64);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue != 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 8:
                     sensorValue.EnglishValue = (double)(DataC & 1);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue == 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 9:
                     sensorValue.EnglishValue = (double)(DataC & 2);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue == 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 10:
                     sensorValue.EnglishValue = (double)(DataC & 4);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue == 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 11:
                     sensorValue.EnglishValue = (double)(DataC & 8);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue == 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 12:
                     sensorValue.EnglishValue = (double)(DataC & 16);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue == 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 13:
                     sensorValue.EnglishValue = (double)(DataC & 32);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue == 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 14:
                     sensorValue.EnglishValue = (double)(DataC & 64);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue == 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 15:
                     sensorValue.EnglishValue = (double)(DataC & 128);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue == 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 16:
                     sensorValue.EnglishValue = (double)(DataD & 1);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue != 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 17:
                     sensorValue.EnglishValue = (double)(DataD & 2);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue != 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 18:
                     sensorValue.EnglishValue = (double)(DataD & 4);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue != 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 19:
                     sensorValue.EnglishValue = (double)(DataD & 8);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue != 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 20:
                     sensorValue.EnglishValue = (double)(DataD & 16);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue != 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 21:
                     sensorValue.EnglishValue = (double)(DataD & 32);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue != 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 22:
                     sensorValue.EnglishValue = (double)(DataD & 64);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue != 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
                 case 23:
                     sensorValue.EnglishValue = (double)(DataD & 128);
                     sensorValue.EnglishDisplay = sensorValue.EnglishValue != 0.0 ? "NO" : "YES";
                     sensorValue.MetricValue = sensorValue.EnglishValue;
                     sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
                     break;
             }
             break;
         case 2:
             sensorValue.EnglishValue = (double)(DataA * 256 + DataB);
             sensorValue.EnglishDisplay = OBD2.getDTCName(Response.Substring(4, 4));
             sensorValue.MetricValue = sensorValue.EnglishValue;
             sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
             break;
         case 3:
             int num2 = iSubPID != 0 ? DataB : DataA;
             sensorValue.EnglishValue = (double)num2;
             sensorValue.MetricValue = sensorValue.EnglishValue;
             if ((num2 & 1) != 0)
             {
                 sensorValue.EnglishDisplay = "Open Loop: Has not yet satisfied conditions to go closed loop.";
                 sensorValue.MetricDisplay = "OL";
             }
             else if ((num2 & 2) != 0)
             {
                 sensorValue.EnglishDisplay = "Closed Loop: Using oxygen sensor(s) as feedback for fuel control.";
                 sensorValue.MetricDisplay = "CL";
             }
             else if ((num2 & 4) != 0)
             {
                 sensorValue.EnglishDisplay = "OL-Drive: Open loop due to driving conditions. (e.g., power enrichment, deceleration enleanment)";
                 sensorValue.MetricDisplay = "OL-Drive";
             }
             else if ((num2 & 8) != 0)
             {
                 sensorValue.EnglishDisplay = "OL-Fault: Open loop due to detected system fault.";
                 sensorValue.MetricDisplay = "OL-Fault";
             }
             else if ((num2 & 16) != 0)
             {
                 sensorValue.EnglishDisplay = "CL-Fault: Closed loop, but fault with at least one oxygen sensor. May be using single oxygen sensor for fuel control.";
                 sensorValue.MetricDisplay = "CL-Fault";
             }
             else
             {
                 sensorValue.EnglishDisplay = "";
                 sensorValue.MetricDisplay = "";
             }
             break;
         case 4:
             sensorValue.EnglishValue = (double)DataA * (20.0 / 51.0);
             sensorValue.EnglishDisplay = sensorValue.EnglishValue.ToString("##0.##");
             sensorValue.MetricValue = sensorValue.EnglishValue;
             sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
             break;
         case 5:
             sensorValue.EnglishValue = ((double)DataA - 40.0) * 1.8 + 32.0;
             double num4 = sensorValue.EnglishValue;
             sensorValue.EnglishDisplay = num4.ToString();
             sensorValue.MetricValue = (double)DataA - 40.0;
             double num5 = sensorValue.MetricValue;
             sensorValue.MetricDisplay = num5.ToString();
             break;
         case 6:
         case 7:
         case 8:
         case 9:
             double num6 = iSubPID != 0 ? (double)DataB : (double)DataA;
             sensorValue.EnglishValue = num6 * (25.0 / 32.0) - 100.0;
             double num7 = sensorValue.EnglishValue;
             sensorValue.EnglishDisplay = num7.ToString();
             sensorValue.MetricValue = sensorValue.EnglishValue;
             sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
             break;
         case 10:
             double num8 = (double)DataA;
             sensorValue.EnglishValue = num8 * 30.0 * (1.0 / 69.0);
             double num9 = sensorValue.EnglishValue;
             sensorValue.EnglishDisplay = num9.ToString();
             sensorValue.MetricValue = num8 * 3.0;
             double num10 = sensorValue.MetricValue;
             sensorValue.MetricDisplay = num10.ToString();
             break;
         case 11:
             double num11 = (double)DataA;
             sensorValue.EnglishValue = num11 * 10.0 * (1.0 / 69.0);
             double num12 = sensorValue.EnglishValue;
             sensorValue.EnglishDisplay = num12.ToString();
             sensorValue.MetricValue = num11;
             double num13 = sensorValue.MetricValue;
             sensorValue.MetricDisplay = num13.ToString();
             break;
         case 12:
             double num14 = (double)(DataA * 256 + DataB);
             sensorValue.EnglishValue = num14 * 0.25;
             double num15 = sensorValue.EnglishValue;
             sensorValue.EnglishDisplay = num15.ToString();
             sensorValue.MetricValue = sensorValue.EnglishValue;
             sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
             break;
         case 13:
             double num16 = (double)DataA;
             sensorValue.EnglishValue = num16 * 0.625;
             double num17 = sensorValue.EnglishValue;
             sensorValue.EnglishDisplay = num17.ToString();
             sensorValue.MetricValue = num16;
             double num18 = sensorValue.MetricValue;
             sensorValue.MetricDisplay = num18.ToString();
             break;
         case 14:
             double num19 = (double)DataA;
             sensorValue.EnglishValue = num19 * 0.5 - 64.0;
             double num20 = sensorValue.EnglishValue;
             sensorValue.EnglishDisplay = num20.ToString();
             sensorValue.MetricValue = sensorValue.EnglishValue;
             sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
             break;
         case 15:
             double num21 = (double)DataA - 40.0;
             sensorValue.EnglishValue = num21 * 1.8 + 32.0;
             double num22 = sensorValue.EnglishValue;
             sensorValue.EnglishDisplay = num22.ToString();
             sensorValue.MetricValue = num21;
             double num23 = sensorValue.MetricValue;
             sensorValue.MetricDisplay = num23.ToString();
             break;
         case 16:
             double num24 = (double)(DataA * 256 + DataB);
             sensorValue.EnglishValue = num24 * 0.00132278048457858;
             double num25 = sensorValue.EnglishValue;
             sensorValue.EnglishDisplay = num25.ToString();
             sensorValue.MetricValue = num24 * 0.01;
             double num26 = sensorValue.MetricValue;
             sensorValue.MetricDisplay = num26.ToString();
             break;
         case 17:
             double num27 = (double)DataA;
             sensorValue.EnglishValue = num27 * (20.0 / 51.0);
             double num28 = sensorValue.EnglishValue;
             sensorValue.EnglishDisplay = num28.ToString();
             sensorValue.MetricValue = sensorValue.EnglishValue;
             sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
             break;
         case 18:
             sensorValue.EnglishValue = (double)DataA;
             if ((DataA & 1) != 0)
                 sensorValue.EnglishDisplay = "UPS: Upstream of first catalytic converter.";
             else if ((DataA & 2) != 0)
                 sensorValue.EnglishDisplay = "DNS: Downstream of first catalytic converter inlet.";
             else if ((DataA & 4) != 0)
                 sensorValue.EnglishDisplay = "OFF: Atmosphere / Off";
             sensorValue.MetricValue = sensorValue.EnglishValue;
             sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
             break;
         case 19:
             double num29 = (double)DataA;
             sensorValue.EnglishValue = num29;
             if ((DataA & 1) != 0)
                 sensorValue.EnglishDisplay = sensorValue.EnglishDisplay + "(O2S11) Bank 1 Sensor 1\r\n";
             if ((DataA & 2) != 0)
                 sensorValue.EnglishDisplay = sensorValue.EnglishDisplay + "(O2S12) Bank 1 Sensor 2\r\n";
             if ((DataA & 4) != 0)
                 sensorValue.EnglishDisplay = sensorValue.EnglishDisplay + "(O2S13) Bank 1 Sensor 3\r\n";
             if ((DataA & 8) != 0)
                 sensorValue.EnglishDisplay = sensorValue.EnglishDisplay + "(O2S14) Bank 1 Sensor 4\r\n";
             if ((DataA & 16) != 0)
                 sensorValue.EnglishDisplay = sensorValue.EnglishDisplay + "(O2S21) Bank 2 Sensor 1\r\n";
             if ((DataA & 32) != 0)
                 sensorValue.EnglishDisplay = sensorValue.EnglishDisplay + "(O2S22) Bank 2 Sensor 2\r\n";
             if ((DataA & 64) != 0)
                 sensorValue.EnglishDisplay = sensorValue.EnglishDisplay + "(O2S23) Bank 2 Sensor 3\r\n";
             if ((DataA & 128) != 0)
                 sensorValue.EnglishDisplay = sensorValue.EnglishDisplay + "(O2S24) Bank 2 Sensor 4\r\n";
             sensorValue.MetricValue = sensorValue.EnglishValue;
             sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
             break;
         case 20:
         case 21:
         case 22:
         case 23:
         case 24:
         case 25:
         case 26:
         case 27:
             double num30 = (double)DataA;
             double num31 = (double)DataB;
             if (iSubPID == 0)
             {
                 sensorValue.EnglishValue = num30 * 0.005;
                 double num32 = sensorValue.EnglishValue;
                 sensorValue.EnglishDisplay = num32.ToString();
             }
             else if (num31 == (double)byte.MaxValue)
             {
                 sensorValue.EnglishValue = -1.0;
                 sensorValue.EnglishDisplay = "NOT USED";
             }
             else
             {
                 sensorValue.EnglishValue = num31 * (25.0 / 32.0) - 100.0;
                 double num32 = sensorValue.EnglishValue;
                 sensorValue.EnglishDisplay = num32.ToString();
             }
             sensorValue.MetricValue = sensorValue.EnglishValue;
             sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
             break;
         case 28:
             double num33 = (double)DataA;
             sensorValue.EnglishValue = num33;
             if (num33 == 1.0)
                 sensorValue.EnglishDisplay = "OBD II (California ARB)";
             else if (num33 == 2.0)
                 sensorValue.EnglishDisplay = "OBD (Federal EPA)";
             else if (num33 == 3.0)
                 sensorValue.EnglishDisplay = "OBD and OBD II";
             else if (num33 == 4.0)
                 sensorValue.EnglishDisplay = "OBD I";
             else if (num33 == 5.0)
                 sensorValue.EnglishDisplay = "Not OBD Compliant";
             else if (num33 == 6.0)
                 sensorValue.EnglishDisplay = "EOBD";
             else if (num33 == 7.0)
                 sensorValue.EnglishDisplay = "EOBD and OBD II";
             else if (num33 == 8.0)
                 sensorValue.EnglishDisplay = "EOBD and OBD";
             else if (num33 == 9.0)
                 sensorValue.EnglishDisplay = "EOBD, OBD and OBD II";
             else if (num33 == 10.0)
                 sensorValue.EnglishDisplay = "JOBD";
             else if (num33 == 11.0)
                 sensorValue.EnglishDisplay = "JOBD and OBD II";
             else if (num33 == 12.0)
                 sensorValue.EnglishDisplay = "JOBD and EOBD";
             else if (num33 == 13.0)
                 sensorValue.EnglishDisplay = "JOBD, EOBD, and OBD II";
             sensorValue.MetricValue = sensorValue.EnglishValue;
             sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
             break;
         case 29:
             double num34 = (double)DataA;
             sensorValue.EnglishValue = num34;
             if ((DataA & 1) != 0)
                 sensorValue.EnglishDisplay = sensorValue.EnglishDisplay + "(O2S11) Bank 1 Sensor 1\r\n";
             if ((DataA & 2) != 0)
                 sensorValue.EnglishDisplay = sensorValue.EnglishDisplay + "(O2S12) Bank 1 Sensor 2\r\n";
             if ((DataA & 4) != 0)
                 sensorValue.EnglishDisplay = sensorValue.EnglishDisplay + "(O2S21) Bank 2 Sensor 1\r\n";
             if ((DataA & 8) != 0)
                 sensorValue.EnglishDisplay = sensorValue.EnglishDisplay + "(O2S22) Bank 2 Sensor 2\r\n";
             if ((DataA & 16) != 0)
                 sensorValue.EnglishDisplay = sensorValue.EnglishDisplay + "(O2S31) Bank 3 Sensor 1\r\n";
             if ((DataA & 32) != 0)
                 sensorValue.EnglishDisplay = sensorValue.EnglishDisplay + "(O2S32) Bank 3 Sensor 2\r\n";
             if ((DataA & 64) != 0)
                 sensorValue.EnglishDisplay = sensorValue.EnglishDisplay + "(O2S41) Bank 4 Sensor 1\r\n";
             if ((DataA & 128) != 0)
                 sensorValue.EnglishDisplay = sensorValue.EnglishDisplay + "(O2S42) Bank 4 Sensor 2\r\n";
             sensorValue.MetricValue = sensorValue.EnglishValue;
             sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
             break;
         case 30:
             double num35 = (double)DataA;
             sensorValue.EnglishValue = num35;
             sensorValue.EnglishDisplay = num35 != 0.0 ? "ON" : "OFF";
             sensorValue.MetricValue = sensorValue.EnglishValue;
             sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
             break;
         case 31:
             double num36 = (double)(DataA * 256 + DataB);
             sensorValue.EnglishValue = num36;
             double num37 = sensorValue.EnglishValue;
             sensorValue.EnglishDisplay = num37.ToString();
             sensorValue.MetricValue = sensorValue.EnglishValue;
             sensorValue.MetricDisplay = sensorValue.EnglishDisplay;
             break;
     }
     return sensorValue;
 }
Esempio n. 32
0
        public static SensorValue ParseSensorValue(byte[] message)
        {
            // ...
            /*
             * 
    SPI > 01 0C 00 04 00 16 06 31 05 03 0A 00 43 99
    SPO < 06
    ZWaveLib UNHANDLED message: 01 0C 00 04 00 16 06 31 05 03 0A 00 43 99
    SPI > 01 0C 00 04 00 16 06 31 05 05 01 27 00 F0
    SPO < 06
    ZWaveLib UNHANDLED message: 01 0C 00 04 00 16 06 31 05 05 01 27 00 F0
    SPI > 01 0C 00 04 00 16 06 31 05 01 2A 03 3B C0
    SPO < 06
    ZWaveLib UNHANDLED message: 01 0C 00 04 00 16 06 31 05 01 2A 03 3B C0					 
             * 
            */

            SensorValue sensorValue = new SensorValue();
            //
            byte key = message[9];
            byte precisionScaleSize = message[10]; // type of the field to read
            byte val = message[11];
            //
            //double val = (double)int.Parse(message[14].ToString("X2"), System.Globalization.NumberStyles.HexNumber) / 1000D;
            //
            if (key == (byte)ZWaveSensorParameter.TEMPERATURE)
            {
                sensorValue.Parameter = ZWaveSensorParameter.TEMPERATURE;
                sensorValue.Value = ExtractTemperatureFromBytes(message);
                sensorValue.EventType = ParameterType.PARAMETER_TEMPERATURE;
            }
            else if (key == (byte)ZWaveSensorParameter.GENERAL_PURPOSE_VALUE)
            {
                sensorValue.Parameter = ZWaveSensorParameter.GENERAL_PURPOSE_VALUE;
                sensorValue.Value = val;
                sensorValue.EventType = ParameterType.PARAMETER_GENERIC;
            }
            else if (key == (byte)ZWaveSensorParameter.LUMINANCE)
            {
                sensorValue.Parameter = ZWaveSensorParameter.LUMINANCE;
                if (precisionScaleSize == 0x0A) // 0x0A = LUX ? (0-1000)
                {
                    sensorValue.Value = BitConverter.ToUInt16(new byte[2] { message[12], message[11] }, 0);
                }
                else // 0x01 = % percentage ? (0 - 100)
                {
                    sensorValue.Value = val;
                }
                sensorValue.EventType = ParameterType.PARAMETER_LUMINANCE;
            }
            else if (key == (byte)ZWaveSensorParameter.RELATIVE_HUMIDITY)
            {
                sensorValue.Parameter = ZWaveSensorParameter.RELATIVE_HUMIDITY;
                sensorValue.Value = val;
                sensorValue.EventType = ParameterType.PARAMETER_HUMIDITY;
            }
            else if (key == (byte)ZWaveSensorParameter.POWER)
            {
                // TODO: this might be very buggy.... to be completed
                sensorValue.Parameter = ZWaveSensorParameter.POWER;
                //sensorValue.Value = BitConverter.ToUInt16(new byte[2] { message[12], message[11] }, 0) / 10D;
                sensorValue.Value = ((double)int.Parse(
                    message[12].ToString("X2") + message[13].ToString("X2") + message[14].ToString("X2"),
                    System.Globalization.NumberStyles.HexNumber
                    )) / 1000D;
                sensorValue.EventType = ParameterType.PARAMETER_POWER;
            }
            else
            {
                sensorValue.Value = val;
            }
            //
            return sensorValue;
        }
Esempio n. 33
0
        public static SensorValue ParseSensorValue(byte[] message)
        {
            // ...
            /*
             * 
    SPI > 01 0C 00 04 00 16 06 31 05 03 0A 00 43 99
    SPO < 06
    ZWaveLib UNHANDLED message: 01 0C 00 04 00 16 06 31 05 03 0A 00 43 99
    SPI > 01 0C 00 04 00 16 06 31 05 05 01 27 00 F0
    SPO < 06
    ZWaveLib UNHANDLED message: 01 0C 00 04 00 16 06 31 05 05 01 27 00 F0
    SPI > 01 0C 00 04 00 16 06 31 05 01 2A 03 3B C0
    SPO < 06
    ZWaveLib UNHANDLED message: 01 0C 00 04 00 16 06 31 05 01 2A 03 3B C0					 
             * 
            */

            SensorValue sensorValue = new SensorValue();
            //
            byte key = message[9];
            byte val = message[11];
            //
            //double val = (double)int.Parse(message[14].ToString("X2"), System.Globalization.NumberStyles.HexNumber) / 1000D;
            //
            if (key == (byte)ZWaveSensorParameter.TEMPERATURE)
            {
                sensorValue.Parameter = ZWaveSensorParameter.TEMPERATURE;
                sensorValue.Value = ExtractTemperatureFromBytes(message);
                sensorValue.EventType = ParameterType.PARAMETER_TEMPERATURE;



            }
            else if (key == (byte)ZWaveSensorParameter.GENERAL_PURPOSE_VALUE)
            {
                sensorValue.Parameter = ZWaveSensorParameter.GENERAL_PURPOSE_VALUE;
                sensorValue.Value = val;
                sensorValue.EventType = ParameterType.PARAMETER_GENERIC;
            }
            else if (key == (byte)ZWaveSensorParameter.LUMINANCE)
            {
                sensorValue.Parameter = ZWaveSensorParameter.LUMINANCE;
                sensorValue.Value = val;
                sensorValue.EventType = ParameterType.PARAMETER_LUMINANCE;
            }
            else if (key == (byte)ZWaveSensorParameter.RELATIVE_HUMIDITY)
            {
                sensorValue.Parameter = ZWaveSensorParameter.RELATIVE_HUMIDITY;
                sensorValue.Value = val;
                sensorValue.EventType = ParameterType.PARAMETER_HUMIDITY;
            }
            else if (key == (byte)ZWaveSensorParameter.POWER)
            {
                sensorValue.Parameter = ZWaveSensorParameter.POWER;
                sensorValue.Value = BitConverter.ToUInt16(new byte[2] { message[12], message[11] }, 0) / 10D;
                sensorValue.EventType = ParameterType.PARAMETER_WATTS;
            }
            else
            {
                sensorValue.Value = val;
            }
            //
            return sensorValue;
        }