Exemplo n.º 1
0
        public static EnergyValue Parse(byte[] message)
        {
            int         scale  = 0;
            EnergyValue energy = new EnergyValue();

            //energy.Value = ((double)int.Parse(
            //                       message[12].ToString("X2") + message[13].ToString("X2") + message[14].ToString("X2"),
            //                       System.Globalization.NumberStyles.HexNumber
            //                   )) / 1000D;
            energy.Value = Utility.ExtractValueFromBytes(message, 11, out scale);
            if (Enum.IsDefined(typeof(ZWaveEnergyParameter), scale))
            {
                energy.Parameter = (ZWaveEnergyParameter)scale;
            }
            switch (energy.Parameter)
            {
            // Accumulated power consumption kW/h
            case ZWaveEnergyParameter.kWh:
                energy.EventType = ParameterType.METER_KW_HOUR;
                break;

            // Accumulated power consumption kilo Volt Ampere / hours (kVA/h)
            case ZWaveEnergyParameter.kVAh:
                energy.EventType = ParameterType.METER_KVA_HOUR;
                break;

            // Instant power consumption Watt
            case ZWaveEnergyParameter.Watt:
                energy.EventType = ParameterType.METER_WATT;
                break;

            // Pulses count
            case ZWaveEnergyParameter.Pulses:
                energy.EventType = ParameterType.METER_PULSES;
                break;

            // AC load Voltage
            case ZWaveEnergyParameter.ACVolt:
                energy.EventType = ParameterType.METER_AC_VOLT;
                break;

            // AC load Current
            case ZWaveEnergyParameter.ACCurrent:
                energy.EventType = ParameterType.METER_AC_CURRENT;
                break;

            // Power Factor
            case ZWaveEnergyParameter.PowerFactor:
                energy.EventType = ParameterType.METER_POWER;
                break;

            default:
                energy.EventType = ParameterType.METER_WATT;
                break;
            }
            return(energy);
        }
Exemplo n.º 2
0
        public static SensorValue Parse(byte[] message)
        {
            SensorValue sensor = new SensorValue();
            //
            int    scale = 0;
            double val   = Utility.ExtractValueFromBytes(message, 11, out scale);
            //
            byte key = message[9];

            if (key == (byte)ZWaveSensorParameter.TEMPERATURE)
            {
                sensor.Parameter = ZWaveSensorParameter.TEMPERATURE;
                sensor.Value     = Utility.ExtractTemperatureFromBytes(message);
                sensor.EventType = ParameterType.SENSOR_TEMPERATURE;
            }
            else if (key == (byte)ZWaveSensorParameter.GENERAL_PURPOSE_VALUE)
            {
                sensor.Parameter = ZWaveSensorParameter.GENERAL_PURPOSE_VALUE;
                sensor.Value     = val;
                sensor.EventType = ParameterType.GENERIC;
            }
            else if (key == (byte)ZWaveSensorParameter.LUMINANCE)
            {
                sensor.Parameter = ZWaveSensorParameter.LUMINANCE;
                sensor.Value     = val;
                sensor.EventType = ParameterType.SENSOR_LUMINANCE;
            }
            else if (key == (byte)ZWaveSensorParameter.RELATIVE_HUMIDITY)
            {
                sensor.Parameter = ZWaveSensorParameter.RELATIVE_HUMIDITY;
                sensor.Value     = val;
                sensor.EventType = ParameterType.SENSOR_HUMIDITY;
            }
            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 = ParameterType.METER_POWER;
            }
            else
            {
                sensor.Value = val;
            }
            //
            return(sensor);
        }