Ejemplo n.º 1
0
        public static SensorValue Parse(byte[] message)
        {
            SensorValue sensor = new SensorValue();
            //
            ZWaveValue zvalue = ZWaveValue.ExtractValueFromBytes(message, 11);
            //
            byte key = message[9];

            if (key == (byte)ZWaveSensorParameter.Temperature)
            {
                sensor.Parameter = ZWaveSensorParameter.Temperature;
                // convert from Fahrenheit to Celsius if needed
                sensor.Value     = (zvalue.Scale == (int)ZWaveTemperatureScaleType.Fahrenheit ? SensorValue.FahrenheitToCelsius(zvalue.Value) : zvalue.Value);
                sensor.EventType = EventParameter.SensorTemperature;
            }
            else if (key == (byte)ZWaveSensorParameter.GeneralPurposeValue)
            {
                sensor.Parameter = ZWaveSensorParameter.GeneralPurposeValue;
                sensor.Value     = zvalue.Value;
                sensor.EventType = EventParameter.Generic;
            }
            else if (key == (byte)ZWaveSensorParameter.Luminance)
            {
                sensor.Parameter = ZWaveSensorParameter.Luminance;
                sensor.Value     = zvalue.Value;
                sensor.EventType = EventParameter.SensorLuminance;
            }
            else if (key == (byte)ZWaveSensorParameter.RelativeHumidity)
            {
                sensor.Parameter = ZWaveSensorParameter.RelativeHumidity;
                sensor.Value     = zvalue.Value;
                sensor.EventType = EventParameter.SensorHumidity;
            }
            else if (key == (byte)ZWaveSensorParameter.Power)
            {
                //sensor.Value = BitConverter.ToUInt16(new byte[2] { message[12], message[11] }, 0) / 10D;
                //sensor.Value = ((double)int.Parse(
                //    message[12].ToString("X2") + message[13].ToString("X2") + message[14].ToString("X2"),
                //    System.Globalization.NumberStyles.HexNumber
                //    )) / 1000D;
                // TODO: this might be very buggy.... to be tested
                EnergyValue energy = EnergyValue.Parse(message);
                sensor.Parameter = ZWaveSensorParameter.Power;
                sensor.Value     = energy.Value;
                sensor.EventType = EventParameter.MeterPower;
            }
            else
            {
                sensor.Value = zvalue.Value;
            }
            //
            return(sensor);
        }
Ejemplo n.º 2
0
 public static SensorValue Parse(byte[] message)
 {
     SensorValue sensor = new SensorValue();
     //
     ZWaveValue zvalue = ZWaveValue.ExtractValueFromBytes(message, 4);
     //
     byte key = message[2];
     if (key == (byte)ZWaveSensorParameter.Temperature)
     {
         sensor.Parameter = ZWaveSensorParameter.Temperature;
         // convert from Fahrenheit to Celsius if needed
         sensor.Value = (zvalue.Scale == (int)ZWaveTemperatureScaleType.Fahrenheit ? SensorValue.FahrenheitToCelsius(zvalue.Value) : zvalue.Value);
         sensor.EventType = EventParameter.SensorTemperature;
     }
     else if (key == (byte)ZWaveSensorParameter.GeneralPurposeValue)
     {
         sensor.Parameter = ZWaveSensorParameter.GeneralPurposeValue;
         sensor.Value = zvalue.Value;
         sensor.EventType = EventParameter.SensorGeneric;
     }
     else if (key == (byte)ZWaveSensorParameter.Luminance)
     {
         sensor.Parameter = ZWaveSensorParameter.Luminance;
         sensor.Value = zvalue.Value;
         sensor.EventType = EventParameter.SensorLuminance;
     }
     else if (key == (byte)ZWaveSensorParameter.RelativeHumidity)
     {
         sensor.Parameter = ZWaveSensorParameter.RelativeHumidity;
         sensor.Value = zvalue.Value;
         sensor.EventType = EventParameter.SensorHumidity;
     }
     else if (key == (byte)ZWaveSensorParameter.Power)
     {
         //sensor.Value = BitConverter.ToUInt16(new byte[2] { message[12], message[11] }, 0) / 10D;
         //sensor.Value = ((double)int.Parse(
         //    message[12].ToString("X2") + message[13].ToString("X2") + message[14].ToString("X2"),
         //    System.Globalization.NumberStyles.HexNumber
         //    )) / 1000D;
         // TODO: this might be very buggy.... to be tested
         EnergyValue energy = EnergyValue.Parse(message);
         sensor.Parameter = ZWaveSensorParameter.Power;
         sensor.Value = energy.Value;
         sensor.EventType = EventParameter.MeterPower;
     }
     else
     {
         sensor.Value = zvalue.Value;
     }
     //
     return sensor;
 }
Ejemplo n.º 3
0
        public static SensorValue Parse(byte[] message)
        {
            var zvalue     = ZWaveValue.ExtractValueFromBytes(message, 4);
            var sensorType = ZWaveSensorParameter.Unknown;

            if (Enum.IsDefined(typeof(ZWaveSensorParameter), (int)message[2]))
            {
                sensorType = (ZWaveSensorParameter)message[2];
            }

            var sensorValue = new SensorValue
            {
                Parameter = sensorType,
                Value     = zvalue.Value
            };

            switch (sensorType)
            {
            case ZWaveSensorParameter.Temperature:
                // convert from Fahrenheit to Celsius if needed
                sensorValue.Value = zvalue.Scale == (int)ZWaveTemperatureScaleType.Fahrenheit
                        ? FahrenheitToCelsius(zvalue.Value)
                        : zvalue.Value;
                sensorValue.EventType = EventParameter.SensorTemperature;
                break;

            case ZWaveSensorParameter.GeneralPurposeValue:
                sensorValue.EventType = EventParameter.SensorGeneric;
                break;

            case ZWaveSensorParameter.Luminance:
                sensorValue.EventType = EventParameter.SensorLuminance;
                break;

            case ZWaveSensorParameter.RelativeHumidity:
                sensorValue.EventType = EventParameter.SensorHumidity;
                break;

            case ZWaveSensorParameter.Power:
                //sensor.Value = BitConverter.ToUInt16(new byte[2] { message[12], message[11] }, 0) / 10D;
                //sensor.Value = ((double)int.Parse(
                //    message[12].ToString("X2") + message[13].ToString("X2") + message[14].ToString("X2"),
                //    System.Globalization.NumberStyles.HexNumber
                //    )) / 1000D;
                // TODO: this might be very buggy.... to be tested
                EnergyValue energy = EnergyValue.Parse(message);
                sensorValue.Value     = energy.Value;
                sensorValue.EventType = EventParameter.MeterPower;
                break;

            case ZWaveSensorParameter.WaterFlow:
                sensorValue.EventType = EventParameter.WaterFlow;
                break;

            case ZWaveSensorParameter.WaterPressure:
                sensorValue.EventType = EventParameter.WaterPressure;
                break;

            case ZWaveSensorParameter.Ultraviolet:
                sensorValue.EventType = EventParameter.Ultraviolet;
                break;

                // TODO: implement other Sensor Types
            }

            return(sensorValue);
        }