public static ZWaveEvent GetEvent(ZWaveNode node, byte[] message) { ZWaveEvent nodeEvent = null; byte cmdType = message[8]; if (cmdType == (byte)Command.MeterReport) { EnergyValue energy = EnergyValue.Parse(message); nodeEvent = new ZWaveEvent(node, energy.EventType, energy.Value, 0); } return(nodeEvent); }
public virtual bool HandleMultiInstanceReport(byte[] message) { //UNHANDLED: 01 14 00 04 08 04 0E 32 02 21 74 00 00 1E BB 00 00 00 00 00 00 2D // ^^ | | // +--|------> 0x31 Command Class Meter // +------> 0x02 Meter Report bool processed = false; // byte commandClass = message[7]; byte commandType = message[8]; // if (commandClass == (byte)CommandClass.Meter && commandType == (byte)Command.MeterReport) { // TODO: should check meter report type (Electric, Gas, Water) and value precision scale // TODO: the code below parse always as Electric type EnergyValue energy = EnergyValue.Parse(message); nodeHost.RaiseUpdateParameterEvent(nodeHost, 0, energy.EventType, energy.Value); processed = true; } return(processed); }
public virtual bool HandleMultiInstanceReport(byte[] message) { if (message.Length <= 14) { return(false); // we need at least 15 bytes long message for further processing } // bool processed = false; // //byte cmdLength = message[6]; byte cmdClass = message[7]; byte cmdType = message[8]; // if (cmdClass == (byte)CommandClass.Meter && cmdType == (byte)Command.MeterReport) { // TODO: should check meter report type (Electric, Gas, Water) and value precision / scale // TODO: the code below parse always as Electric type EnergyValue energy = EnergyValue.Parse(message); nodeHost.RaiseUpdateParameterEvent(nodeHost, 0, energy.EventType, energy.Value); processed = true; } else if (cmdClass == (byte)CommandClass.MultiInstance) { //01 0D 00 04 00 2F 07 60 0D 01 00 25 03 FF 6B // mi ? in sb rp vl byte instance = message[9]; byte reportType = message[10]; // //SPI > 01 0F 00 04 00 32 09 60 06 03 31 05 01 2A 02 E4 53 if (true) // TODO: check against proper command classes SENSOR_BINARY, SENSOR_MULTILEVEL, ... { var paramType = ParameterType.MULTIINSTANCE_SENSOR_BINARY; if (reportType == (byte)CommandClass.SensorMultilevel) { paramType = ParameterType.MULTIINSTANCE_SENSOR_MULTILEVEL; } // we assume its a COMMAND_MULTIINSTANCE_REPORT int scale = 0; byte key = message[12]; double val = Utility.ExtractValueFromBytes(message, 14, out scale); // if it's a COMMAND_MULTIINSTANCEV2_ENCAP we shift key and val +1 byte if (cmdType == (byte)Command.MultiInstaceV2Encapsulated) { key = message[13]; val = Utility.ExtractValueFromBytes(message, 15, out scale); } // if (key == (byte)ZWaveSensorParameter.TEMPERATURE && message.Length > 16) { if (cmdType == (byte)Command.MultiInstaceV2Encapsulated && message.Length > 18) { val = BitConverter.ToUInt16(new byte[2] { message[18], message[17] }, 0) / 100D; } else { val = Utility.ExtractTemperatureFromBytes(message); } // nodeHost.RaiseUpdateParameterEvent(nodeHost, instance, paramType, val); nodeHost.RaiseUpdateParameterEvent( nodeHost, key, ParameterType.SENSOR_TEMPERATURE, val ); processed = true; } else if (key == (byte)ZWaveSensorParameter.GENERAL_PURPOSE_VALUE) { nodeHost.RaiseUpdateParameterEvent(nodeHost, instance, paramType, (double)val); nodeHost.RaiseUpdateParameterEvent(nodeHost, key, ParameterType.GENERIC, val); processed = true; } else if (key == (byte)ZWaveSensorParameter.LUMINANCE) { nodeHost.RaiseUpdateParameterEvent(nodeHost, instance, paramType, (double)val); nodeHost.RaiseUpdateParameterEvent(nodeHost, key, ParameterType.SENSOR_LUMINANCE, val); processed = true; } else if (key == (byte)ZWaveSensorParameter.RELATIVE_HUMIDITY) { nodeHost.RaiseUpdateParameterEvent(nodeHost, instance, paramType, (double)val); nodeHost.RaiseUpdateParameterEvent(nodeHost, key, ParameterType.SENSOR_HUMIDITY, val); processed = true; } else if (key == (byte)ZWaveSensorParameter.POWER) { // TODO: verify if it's possible to use EnergyValue class double energy = 0; if (cmdType == (byte)Command.MultiInstaceV2Encapsulated && message.Length > 18) { var e = ((UInt32)message[15]) * 256 * 256 * 256 + ((UInt32)message[16]) * 256 * 256 + ((UInt32)message[17]) * 256 + ((UInt32)message[18]); energy = ((double)e) / 1000.0; } else if (cmdType == (byte)Command.MultiInstanceReport) { var e = ((UInt32)message[14]) * 256 * 256 * 256 + ((UInt32)message[15]) * 256 * 256 + ((UInt32)message[16]) * 256 + ((UInt32)message[17]); energy = ((double)e) / 1000.0; } nodeHost.RaiseUpdateParameterEvent( nodeHost, instance, ParameterType.MULTIINSTANCE_SENSOR_MULTILEVEL, (double)energy ); processed = true; } else { nodeHost.RaiseUpdateParameterEvent(nodeHost, instance, paramType, (double)val); nodeHost.RaiseUpdateParameterEvent(nodeHost, key, ParameterType.GENERIC, val); Console.WriteLine("\nUNHANDLED SENSOR PARAMETER TYPE => " + key + "\n"); } } } return(processed); }