Exemplo n.º 1
0
 public static ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
 {
     ZWaveEvent nodeEvent = null;
     byte cmdType = message[8];
     if (message.Length > 12 && cmdType == (byte)Command.AssociationReport)
     {
         byte groupId = message[9];
         byte maxAssociations = message[10];
         byte numAssociations = message[11]; // it is always zero ?!?
         string assocNodes = "";
         if (message.Length > 13)
         {
             for (int a = 12; a < message.Length - 1; a++)
             {
                 assocNodes += message[a] + ",";
             }
         }
         assocNodes = assocNodes.TrimEnd(',');
         //
         var associationRespose = new AssociationResponse() {
             Max = maxAssociations,
             Count = numAssociations,
             NodeList = assocNodes,
             GroupId = groupId
         };
         nodeEvent = new ZWaveEvent(node, EventParameter.Association, associationRespose, 0);
     }
     return nodeEvent;
 }
Exemplo n.º 2
0
 public static ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
 {
     ZWaveEvent nodeEvent = null;
     byte cmdType = message[8];
     if (message.Length > 11 && cmdType == (byte)Command.ConfigurationReport)
     {
         byte paramId = message[9];
         byte paramLength = message[10];
         //
         var nodeConfigParamsLength = GetConfigParamsData(node);
         if (!nodeConfigParamsLength.ContainsKey(paramId))
         {
             nodeConfigParamsLength.Add(paramId, paramLength);
         }
         else
         {
             // this shouldn't change on read... but you never know! =)
             nodeConfigParamsLength[paramId] = paramLength;
         }
         //
         byte[] bval = new byte[4];
         // extract bytes value
         Array.Copy(message, 11, bval, 4 - (int)paramLength, (int)paramLength);
         uint paramval = bval[0];
         Array.Reverse(bval);
         // convert it to uint
         paramval = BitConverter.ToUInt32(bval, 0);
         nodeEvent = new ZWaveEvent(node, EventParameter.Configuration, paramval, paramId);
     }
     return nodeEvent;
 }
Exemplo n.º 3
0
 public static ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
 {
     ZWaveEvent nodeEvent = null;
     byte cmdType = message[8];
     switch (cmdType)
     {
     case (byte)Command.WakeUpIntervalReport:
         if (message.Length > 11)
         {
             uint interval = ((uint)message[9]) << 16;
             interval |= (((uint)message[10]) << 8);
             interval |= (uint)message[11];
             nodeEvent = new ZWaveEvent(node, EventParameter.WakeUpInterval, interval, 0);
         }
         break;
     case (byte)Command.WakeUpNotification:
             // Resend queued messages while node was asleep
         var wakeUpResendQueue = GetResendQueueData(node);
         for (int m = 0; m < wakeUpResendQueue.Count; m++)
         {
             node.SendMessage(wakeUpResendQueue[m]);
         }
         wakeUpResendQueue.Clear();
         nodeEvent = new ZWaveEvent(node, EventParameter.WakeUpNotify, 1, 0);
         break;
     }
     return nodeEvent;
 }
Exemplo n.º 4
0
 public static ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
 {
     ZWaveEvent nodeEvent = null;
     byte cmdType = message[8];
     if (cmdType == (byte)Command.SensorBinaryReport)
     {
         nodeEvent = new ZWaveEvent(node, EventParameter.Generic, message[9], 0);
     }
     return nodeEvent;
 }
Exemplo n.º 5
0
 public ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
 {
     ZWaveEvent nodeEvent = null;
     byte cmdType = message[1];
     if (cmdType == (byte)Command.SceneActivationSet)
     {
         nodeEvent = new ZWaveEvent(node, EventParameter.SensorGeneric, (double)message[2], 0);
     }
     return nodeEvent;
 }
Exemplo n.º 6
0
 public static ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
 {
     ZWaveEvent nodeEvent = null;
     byte cmdType = message[8];
     if (cmdType == (byte)Command.BasicReport || cmdType == (byte)Command.BasicSet)
     {
         int levelValue = (int)message[9];
         nodeEvent = new ZWaveEvent(node, EventParameter.Level, (double)levelValue, 0);
     }
     return nodeEvent;
 }
Exemplo n.º 7
0
 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;
 }
Exemplo n.º 8
0
 public static ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
 {
     ZWaveEvent nodeEvent = null;
     byte cmdType = message[8];
     if (cmdType == (byte)Command.AlarmReport)
     {
         var alarm = AlarmValue.Parse(message);
         nodeEvent = new ZWaveEvent(node, alarm.EventType, alarm.Value, 0);
     }
     return nodeEvent;
 }
Exemplo n.º 9
0
 public ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
 {
     ZWaveEvent nodeEvent = null;
     byte cmdType = message[1];
     if (message.Length > 0 && cmdType == (byte)Command.BatteryReport) // Battery Report
     {
         int batteryLevel = message[2];
         nodeEvent = new ZWaveEvent(node, EventParameter.Battery, batteryLevel, 0);
     }
     return nodeEvent;
 }
Exemplo n.º 10
0
 public static ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
 {
     ZWaveEvent nodeEvent = null;
     byte cmdType = message[8];
     if (cmdType == (byte)Command.SwitchBinaryReport || cmdType == (byte)Command.SwitchBinarySet) // some devices use this instead of report
     {
         int levelValue = (int)message[9];
         nodeEvent = new ZWaveEvent(node, EventParameter.Level, (double)levelValue, 0);
     }
     return nodeEvent;
 }
Exemplo n.º 11
0
 public ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
 {
     ZWaveEvent nodeEvent = null;
     byte cmdType = message[1];
     if (cmdType == (byte)Command.UserCodeReport)
     {
         var reportedUserCode = UserCodeValue.Parse(message);
         var userCode = GetUserCodeData(node);
         userCode.TagCode = reportedUserCode.TagCode;
         userCode.UserId = reportedUserCode.UserId;
         userCode.UserIdStatus = reportedUserCode.UserIdStatus;
         nodeEvent = new ZWaveEvent(node, EventParameter.UserCode, reportedUserCode, 0);
     }
     return nodeEvent;
 }
Exemplo n.º 12
0
 public static ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
 {
     ZWaveEvent nodeEvent = null;
     byte cmdType = message[8];
     if (cmdType == (byte)Command.SensorMultilevelReport)
     {
         var sensor = SensorValue.Parse(message);
         if (sensor.Parameter == ZWaveSensorParameter.Unknown)
         {
             byte key = message[9];
             nodeEvent = new ZWaveEvent(node, EventParameter.Generic, sensor.Value, 0);
             Console.WriteLine("\nUNHANDLED SENSOR PARAMETER TYPE => " + key + "\n");
         }
         else
         {
             nodeEvent = new ZWaveEvent(node, sensor.EventType, sensor.Value, 0);
         }
     }
     return nodeEvent;
 }
Exemplo n.º 13
0
 public ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
 {
     ZWaveEvent nodeEvent = null;
     byte cmdType = message[1];
     if (cmdType == (byte)Command.SensorMultilevelReport)
     {
         var sensor = SensorValue.Parse(message);
         if (sensor.Parameter == ZWaveSensorParameter.Unknown)
         {
             byte key = message[2];
             nodeEvent = new ZWaveEvent(node, EventParameter.SensorGeneric, sensor.Value, 0);
             Utility.DebugLog(DebugMessageType.Warning, "Unhandled sensor parameter type: " + key);
         }
         else
         {
             nodeEvent = new ZWaveEvent(node, sensor.EventType, sensor.Value, 0);
         }
     }
     return nodeEvent;
 }
Exemplo n.º 14
0
        public ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
        {
            ZWaveEvent nodeEvent = null;

            if (message.Length > 7)
            {
                byte[] manufacturerId = new byte[2] { message[2], message[3] };
                byte[] typeId = new byte[2] { message[4], message[5] };
                byte[] productId = new byte[2] { message[6], message[7] };

                var manufacturerSpecs = new ManufacturerSpecificInfo() {
                    TypeId = Utility.ByteArrayToString(typeId).Replace(" ", ""),
                    ProductId = Utility.ByteArrayToString(productId).Replace(" ", ""),
                    ManufacturerId = Utility.ByteArrayToString(manufacturerId).Replace(" ", "")
                };

                nodeEvent = new ZWaveEvent(node, EventParameter.ManufacturerSpecific, manufacturerSpecs, 0);
            }

            return nodeEvent;
        }
Exemplo n.º 15
0
        public static ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
        {
            ZWaveEvent nodeEvent = null;
            byte cmdType = message[8];

            if (message.Length > 14)
            {
                byte[] manufacturerId = new byte[2] { message[9], message[10] };
                byte[] typeId = new byte[2] { message[11], message[12] };
                byte[] productId = new byte[2] { message[13], message[14] };

                var manufacturerSpecs = new ManufacturerSpecificInfo() {
                    TypeId = Utility.ByteArrayToString(typeId).Replace(" ", ""),
                    ProductId = Utility.ByteArrayToString(productId).Replace(" ", ""),
                    ManufacturerId = Utility.ByteArrayToString(manufacturerId).Replace(" ", "")
                };

                nodeEvent = new ZWaveEvent(node, EventParameter.ManufacturerSpecific, manufacturerSpecs, 0);
            }

            return nodeEvent;
        }
Exemplo n.º 16
0
        public ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
        {
            ZWaveEvent nodeEvent = null;
            byte cmdType = message[1];

            // we want to get in to that we can handle NO Associations
            if (message.Length > 4 && cmdType == (byte)Command.AssociationReport)
            {
                byte groupId = message[2];
                byte associationMax = message[3];
                byte associationCount = message[4]; // it is always zero ?!?
                string associationNodes = "";
                if (message.Length > 4)
                {
                    for (int a = 5; a < message.Length; a++)
                    {
                        associationNodes += message[a] + ",";
                    }
                }
                associationNodes = associationNodes.TrimEnd(',');

                // We don't want to send empty response since it will be handled as "timeout"
                // so setting it to "None"
                if (associationNodes.Length == 0)
                {
                    associationNodes = "None";
                }
                //
                var associationResponse = new AssociationResponse() {
                    Max = associationMax,
                    Count = associationCount,
                    NodeList = associationNodes,
                    GroupId = groupId
                };
                nodeEvent = new ZWaveEvent(node, EventParameter.Association, associationResponse, 0);
            }

            return nodeEvent;
        }
Exemplo n.º 17
0
        public byte[] GeneratePrivateNetworkKey()
        {
            privateNetworkKey = new byte[16];
            Random rnd = new Random();
            rnd.NextBytes(privateNetworkKey);

            // notify the controller that the privateNetworkKey was generated so that it can save it
            ZWaveEvent keyGenEvent = new ZWaveEvent(parentNode, EventParameter.SecurityGeneratedKey, 0, 0);
            parentNode.RaiseUpdateParameterEvent(keyGenEvent);

            return privateNetworkKey;
        }
Exemplo n.º 18
0
        public ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
        {
            ZWaveEvent nodeEvent = null;

            //byte cmdClass = message[0];
            byte cmdType = message[1];
            byte instanceCmdClass = message[2];

            switch (cmdType)
            {
            case (byte)Command.MultiInstanceEncapsulated:
                nodeEvent = HandleMultiInstanceEncapReport(node, message);
                break;

            //case (byte) Command.MultiInstanceReport:
            case (byte) Command.MultiChannelEncapsulated:
                nodeEvent = HandleMultiChannelEncapReport(node, message);
                //if (nodeEvent != null)
                //{
                //    nodeEvent.Instance = (int) message[2];
                //}
                break;

            case (byte) Command.MultiInstanceCountReport:
                byte instanceCount = message[3];
                switch (instanceCmdClass)
                {
                case (byte) CommandClass.SwitchBinary:
                    nodeEvent = new ZWaveEvent(node, EventParameter.MultiinstanceSwitchBinaryCount, instanceCount, 0);
                    break;
                case (byte) CommandClass.SwitchMultilevel:
                    nodeEvent = new ZWaveEvent(node, EventParameter.MultiinstanceSwitchMultilevelCount, instanceCount, 0);
                    break;
                case (byte) CommandClass.SensorBinary:
                    nodeEvent = new ZWaveEvent(node, EventParameter.MultiinstanceSensorBinaryCount, instanceCount, 0);
                    break;
                case (byte) CommandClass.SensorMultilevel:
                    nodeEvent = new ZWaveEvent(node, EventParameter.MultiinstanceSensorMultilevelCount, instanceCount, 0);
                    break;
                }
                break;

            }

            return nodeEvent;
        }
Exemplo n.º 19
0
 public ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
 {
     ZWaveEvent nodeEvent = null;
     byte cmdType = message[1];
     if (cmdType == (byte)Command.DoorLockReport)
     {
         nodeEvent = new ZWaveEvent(node, EventParameter.DoorLockStatus, message[2], 0);
     }
     return nodeEvent;
 }
Exemplo n.º 20
0
        public ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
        {
            byte cmdType = message[1];

            byte[]     decryptedMessage;
            ZWaveEvent nodeEvent = null;

            int startOffset = 1;

            switch (cmdType)
            {
            case (byte)SecurityCommand.SupportedReport:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_SUPPORTED_REPORT for node: " + node.Id);

                /* this is a list of CommandClasses that should be Encrypted.
                 * and it might contain new command classes that were not present in the NodeInfoFrame
                 * so we have to run through, mark existing Command Classes as SetSecured (so SendMsg in the Driver
                 * class will route the unecrypted messages to our SendMsg) and for New Command
                 * Classes, create them, and of course, also do a SetSecured on them.
                 *
                 * This means we must do a SecurityCmd_SupportedGet request ASAP so we dont have
                 * Command Classes created after the Discovery Phase is completed!
                 */
                byte[] securedClasses = new byte[message.Length - 3];
                Array.Copy(message, 3, securedClasses, 0, message.Length - 3);
                nodeEvent = new ZWaveEvent(node, EventParameter.SecurityNodeInformationFrame, securedClasses, 0);
                break;

            case (byte)SecurityCommand.SchemeReport:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_SCHEME_REPORT for node: " + node.Id + ", " + (startOffset + 1));
                int          schemes          = message[startOffset + 1];
                SecurityData nodeSecurityData = GetSecurityData(node);
                if (nodeSecurityData.SchemeAgreed)
                {
                    break;
                }
                else if (schemes == (byte)SecurityScheme.SchemeZero)
                {
                    SetNetworkKey(node);
                    nodeSecurityData.SchemeAgreed = true;
                }
                else
                {
                    Utility.DebugLog(DebugMessageType.Information, "   No common security scheme.  The device will continue as an unsecured node.");
                }
                break;

            case (byte)SecurityCommand.NonceGet:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_NONCE_GET for node: " + node.Id);

                /* the Device wants to send us a Encrypted Packet, and thus requesting for our latest NONCE */
                SendNonceReport(node);
                break;

            case (byte)SecurityCommand.MessageEncap:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_MESSAGE_ENCAP for node: " + node.Id);

                /* We recieved a Encrypted single packet from the Device. Decrypt it. */
                decryptedMessage = DecryptMessage(node, message, startOffset);
                if (decryptedMessage != null)
                {
                    nodeEvent = new ZWaveEvent(node, EventParameter.SecurityDecriptedMessage, decryptedMessage, 0);
                }
                break;

            case (byte)SecurityCommand.NonceReport:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_NONCE_REPORT for node: " + node.Id);

                /* we recieved a NONCE from a device, so assume that there is something in a queue to send out */
                ProcessNonceReport(node, message, startOffset);
                break;

            case (byte)SecurityCommand.MessageEncapNonceGet:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_MESSAGE_ENCAP_NONCE_GET for node: " + node.Id);

                /* we recieved a encrypted packet from the device, and the device is also asking us to send a
                 * new NONCE to it, hence there must be multiple packets.*/
                decryptedMessage = DecryptMessage(node, message, startOffset);
                if (decryptedMessage != null)
                {
                    nodeEvent = new ZWaveEvent(node, EventParameter.SecurityDecriptedMessage, decryptedMessage, 0);
                }
                /* Regardless of the success/failure of Decrypting, send a new NONCE */
                SendNonceReport(node);
                break;

            case (byte)SecurityCommand.NetworkKeySet:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_NETWORK_KEY_SET for node: " + node.Id + ", " + (startOffset + 1));

                /* we shouldn't get a NetworkKeySet from a node if we are the controller
                 * as we send it out to the Devices
                 */
                break;

            case (byte)SecurityCommand.NetworkKeyVerify:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_NETWORK_KEY_VERIFY for node: " + node.Id + ", " + (startOffset + 1));

                /*
                 * if we can decrypt this packet, then we are assured that our NetworkKeySet is successfull
                 * and thus should set the Flag referenced in SecurityCmd_SchemeReport
                 */
                GetSupported(node);
                break;

            case (byte)SecurityCommand.SchemeInherit:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_SCHEME_INHERIT for node: " + node.Id);
                /* only used in a Controller Replication Type enviroment. */
                break;
            }

            return(nodeEvent);
        }
Exemplo n.º 21
0
        public static ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
        {
            ZWaveEvent nodeEvent = null;

            byte cmdClass         = message[7];
            byte cmdType          = message[8];
            byte instanceCmdClass = message[9];

            switch (cmdType)
            {
            case (byte)Command.MultiInstanceReport:
            case (byte)Command.MultiInstaceV2Encapsulated:

                byte[] instanceMessage;
                byte   instanceNumber = message[9];

                // if it's a COMMAND_MULTIINSTANCEV2_ENCAP we shift key and val +1 byte
                if (cmdType == (byte)Command.MultiInstaceV2Encapsulated)
                {
                    instanceCmdClass = message[11];
                    instanceMessage  = new byte[message.Length - 4];
                    System.Array.Copy(message, 4, instanceMessage, 0, message.Length - 4);
                }
                else
                {
                    instanceCmdClass = message[10];
                    instanceMessage  = new byte[message.Length - 3];
                    System.Array.Copy(message, 3, instanceMessage, 0, message.Length - 3);
                }

                switch (instanceCmdClass)
                {
                case (byte)CommandClass.Basic:
                    nodeEvent = Basic.GetEvent(node, instanceMessage);
                    break;

                case (byte)CommandClass.Alarm:
                    nodeEvent = Alarm.GetEvent(node, instanceMessage);
                    break;

                case (byte)CommandClass.SensorAlarm:
                    nodeEvent = SensorAlarm.GetEvent(node, instanceMessage);
                    break;

                case (byte)CommandClass.SceneActivation:
                    nodeEvent = SceneActivation.GetEvent(node, instanceMessage);
                    break;

                case (byte)CommandClass.SwitchBinary:
                    nodeEvent = SwitchBinary.GetEvent(node, instanceMessage);
                    if (nodeEvent != null)
                    {
                        node.RaiseUpdateParameterEvent(instanceNumber, EventParameter.MultiinstanceSwitchBinary, nodeEvent.Value);
                    }
                    break;

                case (byte)CommandClass.SwitchMultilevel:
                    nodeEvent = SwitchMultilevel.GetEvent(node, instanceMessage);
                    if (nodeEvent != null)
                    {
                        node.RaiseUpdateParameterEvent(instanceNumber, EventParameter.MultiinstanceSwitchMultilevel, nodeEvent.Value);
                    }
                    break;

                case (byte)CommandClass.SensorBinary:
                    nodeEvent = SensorBinary.GetEvent(node, instanceMessage);
                    if (nodeEvent != null)
                    {
                        node.RaiseUpdateParameterEvent(instanceNumber, EventParameter.MultiinstanceSensorBinary, nodeEvent.Value);
                    }
                    break;

                case (byte)CommandClass.SensorMultilevel:
                    nodeEvent = SensorMultilevel.GetEvent(node, instanceMessage);
                    if (nodeEvent != null)
                    {
                        node.RaiseUpdateParameterEvent(instanceNumber, EventParameter.MultiinstanceSensorMultilevel, nodeEvent.Value);
                    }
                    break;

                case (byte)CommandClass.Meter:
                    nodeEvent = Meter.GetEvent(node, instanceMessage);
                    break;
                }

                if (nodeEvent != null)
                {
                    nodeEvent.Instance = (int)message[9];
                }

                break;

            case (byte)Command.MultiInstanceCountReport:
                byte instanceCount = message[10];
                switch (instanceCmdClass)
                {
                case (byte)CommandClass.SwitchBinary:
                    nodeEvent = new ZWaveEvent(node, EventParameter.MultiinstanceSwitchBinaryCount, instanceCount, 0);
                    break;

                case (byte)CommandClass.SwitchMultilevel:
                    nodeEvent = new ZWaveEvent(node, EventParameter.MultiinstanceSwitchMultilevelCount, instanceCount, 0);
                    break;

                case (byte)CommandClass.SensorBinary:
                    nodeEvent = new ZWaveEvent(node, EventParameter.MultiinstanceSensorBinaryCount, instanceCount, 0);
                    break;

                case (byte)CommandClass.SensorMultilevel:
                    nodeEvent = new ZWaveEvent(node, EventParameter.MultiinstanceSensorMultilevelCount, instanceCount, 0);
                    break;
                }
                break;
            }

            return(nodeEvent);
        }
Exemplo n.º 22
0
        public static ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
        {
            ZWaveEvent nodeEvent = null;

            byte cmdClass = message[7];
            byte cmdType = message[8];
            byte instanceCmdClass = message[9];

            switch (cmdType)
            {
            case (byte)Command.MultiInstanceReport:
            case (byte)Command.MultiInstaceV2Encapsulated:

                byte[] instanceMessage;
                byte instanceNumber = message[9];

                // if it's a COMMAND_MULTIINSTANCEV2_ENCAP we shift key and val +1 byte
                if (cmdType == (byte)Command.MultiInstaceV2Encapsulated)
                {
                    instanceCmdClass = message[11];
                    instanceMessage = new byte[message.Length - 4];
                    System.Array.Copy(message, 4, instanceMessage, 0, message.Length - 4);
                }
                else
                {
                    instanceCmdClass = message[10];
                    instanceMessage = new byte[message.Length - 3];
                    System.Array.Copy(message, 3, instanceMessage, 0, message.Length - 3);
                }

                switch (instanceCmdClass)
                {
                case (byte)CommandClass.Basic:
                    nodeEvent = Basic.GetEvent(node, instanceMessage);
                    break;
                case (byte)CommandClass.Alarm:
                    nodeEvent = Alarm.GetEvent(node, instanceMessage);
                    break;
                case (byte)CommandClass.SensorAlarm:
                    nodeEvent = SensorAlarm.GetEvent(node, instanceMessage);
                    break;
                case (byte)CommandClass.SceneActivation:
                    nodeEvent = SceneActivation.GetEvent(node, instanceMessage);
                    break;
                case (byte)CommandClass.SwitchBinary:
                    nodeEvent = SwitchBinary.GetEvent(node, instanceMessage);
                    if (nodeEvent != null)
                    {
                        node.RaiseUpdateParameterEvent(instanceNumber, EventParameter.MultiinstanceSwitchBinary, nodeEvent.Value);
                    }
                    break;
                case (byte)CommandClass.SwitchMultilevel:
                    nodeEvent = SwitchMultilevel.GetEvent(node, instanceMessage);
                    if (nodeEvent != null)
                    {
                        node.RaiseUpdateParameterEvent(instanceNumber, EventParameter.MultiinstanceSwitchMultilevel, nodeEvent.Value);
                    }
                    break;
                case (byte)CommandClass.SensorBinary:
                    nodeEvent = SensorBinary.GetEvent(node, instanceMessage);
                    if (nodeEvent != null)
                    {
                        node.RaiseUpdateParameterEvent(instanceNumber, EventParameter.MultiinstanceSensorBinary, nodeEvent.Value);
                    }
                    break;
                case (byte)CommandClass.SensorMultilevel:
                    nodeEvent = SensorMultilevel.GetEvent(node, instanceMessage);
                    if (nodeEvent != null)
                    {
                        node.RaiseUpdateParameterEvent(instanceNumber, EventParameter.MultiinstanceSensorMultilevel, nodeEvent.Value);
                    }
                    break;
                case (byte)CommandClass.Meter:
                    nodeEvent = Meter.GetEvent(node, instanceMessage);
                    break;
                }

                if (nodeEvent != null)
                {
                    nodeEvent.Instance = (int)message[9];
                }

                break;

            case (byte)Command.MultiInstanceCountReport:
                byte instanceCount = message[10];
                switch (instanceCmdClass)
                {
                case (byte)CommandClass.SwitchBinary:
                    nodeEvent = new ZWaveEvent(node, EventParameter.MultiinstanceSwitchBinaryCount, instanceCount, 0);
                    break;
                case (byte)CommandClass.SwitchMultilevel:
                    nodeEvent = new ZWaveEvent(node, EventParameter.MultiinstanceSwitchMultilevelCount, instanceCount, 0);
                    break;
                case (byte)CommandClass.SensorBinary:
                    nodeEvent = new ZWaveEvent(node, EventParameter.MultiinstanceSensorBinaryCount, instanceCount, 0);
                    break;
                case (byte)CommandClass.SensorMultilevel:
                    nodeEvent = new ZWaveEvent(node, EventParameter.MultiinstanceSensorMultilevelCount, instanceCount, 0);
                    break;
                }
                break;

            }

            return nodeEvent;
        }
Exemplo n.º 23
0
 private ZWaveEvent GetNestedEvent(byte commandClass, ZWaveEvent nodeEvent)
 {
     ZWaveEvent nestedEvent = null;
     switch (commandClass)
     {
     case (byte) CommandClass.SwitchBinary:
         nestedEvent = new ZWaveEvent(nodeEvent.Node, EventParameter.MultiinstanceSwitchBinary, nodeEvent.Value, nodeEvent.Instance);
         break;
     case (byte) CommandClass.SwitchMultilevel:
         nestedEvent = new ZWaveEvent(nodeEvent.Node, EventParameter.MultiinstanceSwitchMultilevel, nodeEvent.Value, nodeEvent.Instance);
         break;
     case (byte) CommandClass.SensorBinary:
         nestedEvent = new ZWaveEvent(nodeEvent.Node, EventParameter.MultiinstanceSensorBinary, nodeEvent.Value, nodeEvent.Instance);
         break;
     case (byte) CommandClass.SensorMultilevel:
         nestedEvent = new ZWaveEvent(nodeEvent.Node, EventParameter.MultiinstanceSensorMultilevel, nodeEvent.Value, nodeEvent.Instance);
         break;
     }
     return nestedEvent;
 }
Exemplo n.º 24
0
 // all Thermostat command classes use
 //    0x01 for the "set" command (same as Command.BasicSet)
 //    0x02 for the "get" command (same as Command.BasicGet)
 //    0x03 value for the "report" command (that is the same as Command.BasicReport)
 public static ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
 {
     ZWaveEvent nodeEvent = null;
     byte cmdClass = message[7];
     byte cmdType = message[8];
     if (cmdType == (byte)Command.BasicReport)
     {
         switch (cmdClass)
         {
         case (byte)CommandClass.ThermostatMode:
             nodeEvent = new ZWaveEvent(node, EventParameter.ThermostatMode, (Thermostat.Mode)message[9], 0);
             break;
         case (byte)CommandClass.ThermostatOperatingState:
             nodeEvent = new ZWaveEvent(node, EventParameter.ThermostatOperatingState, message[9], 0);
             break;
         case (byte)CommandClass.ThermostatFanMode:
             nodeEvent = new ZWaveEvent(node, EventParameter.ThermostatFanMode, message[9], 0);
             break;
         case (byte)CommandClass.ThermostatFanState:
             nodeEvent = new ZWaveEvent(node, EventParameter.ThermostatFanState, message[9], 0);
             break;
         case (byte)CommandClass.ThermostatHeating:
             nodeEvent = new ZWaveEvent(node, EventParameter.ThermostatHeating, message[9], 0);
             break;
         case (byte)CommandClass.ThermostatSetBack:
             nodeEvent = new ZWaveEvent(node, EventParameter.ThermostatSetBack, message[9], 0);
             break;
         case (byte)CommandClass.ThermostatSetPoint:
             ZWaveValue zvalue = ZWaveValue.ExtractValueFromBytes(message, 11);
             var setPoint = GetSetPointData(node);
             setPoint.Precision = zvalue.Precision;
             setPoint.Scale = zvalue.Scale;
             setPoint.Size = zvalue.Size;
             setPoint.Value = zvalue.Value;
             dynamic ptype = new ExpandoObject();
             ptype.Type = (SetPointType)message[9];
             // convert from Fahrenheit to Celsius if needed
             ptype.Value = (zvalue.Scale == (int)ZWaveTemperatureScaleType.Fahrenheit ? SensorValue.FahrenheitToCelsius(zvalue.Value) : zvalue.Value);
             nodeEvent = new ZWaveEvent(node, EventParameter.ThermostatSetPoint, ptype, 0);
             break;
         }
     }
     return nodeEvent;
 }
Exemplo n.º 25
0
        public ZWaveEvent GetEvent(ZWaveNode node, byte[] message)
        {
            byte cmdType = message[1];
            byte[] decryptedMessage;
            ZWaveEvent nodeEvent = null;

            int startOffset = 1;
            switch (cmdType)
            {
            case (byte)SecurityCommand.SupportedReport:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_SUPPORTED_REPORT for node: " + node.Id);
                /* this is a list of CommandClasses that should be Encrypted.
                 * and it might contain new command classes that were not present in the NodeInfoFrame
                 * so we have to run through, mark existing Command Classes as SetSecured (so SendMsg in the Driver
                 * class will route the unecrypted messages to our SendMsg) and for New Command
                 * Classes, create them, and of course, also do a SetSecured on them.
                 *
                 * This means we must do a SecurityCmd_SupportedGet request ASAP so we dont have
                 * Command Classes created after the Discovery Phase is completed!
                 */
                byte[] securedClasses = new byte[message.Length - 3];
                Array.Copy(message, 3, securedClasses, 0, message.Length - 3);
                nodeEvent = new ZWaveEvent(node, EventParameter.SecurityNodeInformationFrame, securedClasses, 0);
                break;

            case (byte)SecurityCommand.SchemeReport:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_SCHEME_REPORT for node: " + node.Id + ", " + (startOffset + 1));
                int schemes = message[startOffset + 1];
                SecurityData nodeSecurityData = GetSecurityData(node);
                if (nodeSecurityData.SchemeAgreed)
                {
                    break;
                }
                else if (schemes == (byte)SecurityScheme.SchemeZero)
                {
                    SetNetworkKey(node);
                    nodeSecurityData.SchemeAgreed = true;
                }
                else
                {
                    Utility.DebugLog(DebugMessageType.Information, "   No common security scheme.  The device will continue as an unsecured node.");
                }
                break;

            case (byte)SecurityCommand.NonceGet:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_NONCE_GET for node: " + node.Id);

                /* the Device wants to send us a Encrypted Packet, and thus requesting for our latest NONCE */
                SendNonceReport(node);
                break;

            case (byte)SecurityCommand.MessageEncap:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_MESSAGE_ENCAP for node: " + node.Id);

                /* We recieved a Encrypted single packet from the Device. Decrypt it. */
                decryptedMessage = DecryptMessage(node, message, startOffset);
                if (decryptedMessage != null)
                    nodeEvent = new ZWaveEvent(node, EventParameter.SecurityDecriptedMessage, decryptedMessage, 0);
                break;

            case (byte)SecurityCommand.NonceReport:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_NONCE_REPORT for node: " + node.Id);

                /* we recieved a NONCE from a device, so assume that there is something in a queue to send out */
                ProcessNonceReport(node, message, startOffset);
                break;

            case (byte)SecurityCommand.MessageEncapNonceGet:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_MESSAGE_ENCAP_NONCE_GET for node: " + node.Id);

                /* we recieved a encrypted packet from the device, and the device is also asking us to send a
                     * new NONCE to it, hence there must be multiple packets.*/
                decryptedMessage = DecryptMessage(node, message, startOffset);
                if (decryptedMessage != null)
                    nodeEvent = new ZWaveEvent(node, EventParameter.SecurityDecriptedMessage, decryptedMessage, 0);
                /* Regardless of the success/failure of Decrypting, send a new NONCE */
                SendNonceReport(node);
                break;

            case (byte)SecurityCommand.NetworkKeySet:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_NETWORK_KEY_SET for node: " + node.Id + ", " + (startOffset + 1));

                /* we shouldn't get a NetworkKeySet from a node if we are the controller
                     * as we send it out to the Devices
                    */
                break;

            case (byte)SecurityCommand.NetworkKeyVerify:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_NETWORK_KEY_VERIFY for node: " + node.Id + ", " + (startOffset + 1));

                /*
                     * if we can decrypt this packet, then we are assured that our NetworkKeySet is successfull
                     * and thus should set the Flag referenced in SecurityCmd_SchemeReport
                    */
                GetSupported(node);
                break;

            case (byte)SecurityCommand.SchemeInherit:
                Utility.DebugLog(DebugMessageType.Information, "Received COMMAND_SCHEME_INHERIT for node: " + node.Id);
                /* only used in a Controller Replication Type enviroment. */
                break;

            }

            return nodeEvent;
        }