Example #1
0
        private ZWaveEvent HandleMultiInstanceEncapReport(ZWaveNode node, byte[] message)
        {
            if (message.Length < 5)
            {
                Console.WriteLine("\nZWaveLib: MultiInstance encapsulated message ERROR: message is too short: {0}", Utility.ByteArrayToString(message));
                return(null);
            }

            byte instanceNumber   = message[2];
            var  instanceCmdClass = message[3];
            var  instanceMessage  = new byte[message.Length - 3]; //TODO:

            Array.Copy(message, 3, instanceMessage, 0, message.Length - 3);

            Console.WriteLine("\nZWaveLib: MultiInstance encapsulated message: CmdClass: {0}; message: {1}", instanceCmdClass, Utility.ByteArrayToString(instanceMessage));

            var cc = CommandClassFactory.GetCommandClass(instanceCmdClass);

            if (cc == null)
            {
                Console.WriteLine("\nZWaveLib: Can't find CommandClass handler for command class {0}", instanceCmdClass);
                return(null);
            }
            ZWaveEvent zevent = cc.GetEvent(node, instanceMessage);

            zevent.Instance    = instanceNumber;
            zevent.NestedEvent = GetNestedEvent(instanceCmdClass, zevent);
            return(zevent);
        }
Example #2
0
        private ZWaveEvent HandleMultiChannelEncapReport(ZWaveNode node, byte[] message)
        {
            if (message.Length < 6)
            {
                Utility.DebugLog(DebugMessageType.Warning, String.Format("MultiChannel encapsulated message ERROR: message is too short: {0}", Utility.ByteArrayToString(message)));
                return(null);
            }

            var instanceNumber   = message[2];
            var instanceCmdClass = message[4];
            var instanceMessage  = new byte[message.Length - 4]; //TODO

            Array.Copy(message, 4, instanceMessage, 0, message.Length - 4);

            Utility.DebugLog(DebugMessageType.Information, String.Format("MultiChannel encapsulated message: CmdClass: {0}; message: {1}", instanceCmdClass, Utility.ByteArrayToString(instanceMessage)));

            var cc = CommandClassFactory.GetCommandClass(instanceCmdClass);

            if (cc == null)
            {
                Utility.DebugLog(DebugMessageType.Warning, String.Format("Can't find CommandClass handler for command class {0}", instanceCmdClass));
                return(null);
            }
            ZWaveEvent zevent = cc.GetEvent(node, instanceMessage);

            zevent.Instance    = instanceNumber;
            zevent.NestedEvent = GetNestedEvent(instanceCmdClass, zevent);
            return(zevent);
        }
        private NodeEvent HandleMultiInstanceEncapReport(ZWaveNode node, byte[] message)
        {
            if (message.Length < 5)
            {
                Utility.logger.Error(String.Format("MultiInstance encapsulated message ERROR: message is too short: {0}", BitConverter.ToString(message)));
                return(null);
            }

            byte instanceNumber   = message[2];
            var  instanceCmdClass = message[3];
            var  instanceMessage  = new byte[message.Length - 3]; //TODO:

            Array.Copy(message, 3, instanceMessage, 0, message.Length - 3);

            Utility.logger.Debug(String.Format("MultiInstance encapsulated message: CmdClass: {0}; message: {1}", instanceCmdClass, BitConverter.ToString(instanceMessage)));

            var cc = CommandClassFactory.GetCommandClass(instanceCmdClass);

            if (cc == null)
            {
                Utility.logger.Error(String.Format("Can't find CommandClass handler for command class {0}", instanceCmdClass));
                return(null);
            }
            NodeEvent zevent = cc.GetEvent(node, instanceMessage);

            zevent.Instance    = instanceNumber;
            zevent.NestedEvent = GetNestedEvent(instanceCmdClass, zevent);
            return(zevent);
        }
        public NodeEvent GetEvent(ZWaveNode node, byte[] message)
        {
            byte i, offset = 3;

            NodeEvent parent = null, child = null;

            Utility.DebugLog(DebugMessageType.Information, String.Format("MultiCmd encapsulated message: {0}", BitConverter.ToString(message)));

            if (message[1] != (byte)1)
            {
                return(parent);
            }

            // Loop over each message and process it in turn.
            for (i = 0; i < message[2]; i++)
            {
                // Length and command classes of sub-command.
                byte length   = message[offset];
                byte cmdClass = message[offset + 1];

                // Copy message into new array.
                var instanceMessage = new byte[length];
                Array.Copy(message, offset + 1, instanceMessage, 0, length);
                Utility.DebugLog(DebugMessageType.Information, String.Format("Processing message chunk: {0}", BitConverter.ToString(instanceMessage)));

                // Move offset to the next encap message
                offset += (byte)(length + 1);

                // Grab command class from the factory. If we don't have one, print out a warning and continue.
                var cc = CommandClassFactory.GetCommandClass(cmdClass);
                if (cc == null)
                {
                    Utility.DebugLog(DebugMessageType.Information, String.Format("Can't find CommandClass handler for command class {0}", cmdClass));
                    continue;
                }

                // Chain this event onto previously seen events.
                NodeEvent tmp = cc.GetEvent(node, instanceMessage);
                if (tmp == null)
                {
                    continue;
                }

                if (parent == null)
                {
                    parent = child = tmp;
                }
                else
                {
                    child.NestedEvent = tmp;
                    child             = tmp;
                }
            }

            return(parent);
        }
Example #5
0
        private ZWaveEvent ProcessEncapsulatedMessage(ZWaveNode node, byte[] encapMessage)
        {
            Console.WriteLine("\nZWaveLib: CRC16 encapsulated message: {0}", Utility.ByteArrayToString(encapMessage));
            ZWaveEvent nodeEvent = null;
            byte       cmdClass  = encapMessage[0];
            var        cc        = CommandClassFactory.GetCommandClass(cmdClass);

            if (cc == null)
            {
                Console.WriteLine("\nZWaveLib: Can't find CommandClass handler for command class {0}", cmdClass);
            }
            else
            {
                nodeEvent = cc.GetEvent(node, encapMessage);
            }
            return(nodeEvent);
        }
Example #6
0
        private NodeEvent ProcessEncapsulatedMessage(ZWaveNode node, byte[] encapMessage)
        {
            Utility.logger.Debug(String.Format("CRC16 encapsulated message: {0}", BitConverter.ToString(encapMessage)));
            NodeEvent nodeEvent = null;
            byte      cmdClass  = encapMessage[0];
            var       cc        = CommandClassFactory.GetCommandClass(cmdClass);

            if (cc == null)
            {
                Utility.logger.Error(String.Format("Can't find CommandClass handler for command class {0}", cmdClass));
            }
            else
            {
                nodeEvent = cc.GetEvent(node, encapMessage);
            }
            return(nodeEvent);
        }
Example #7
0
        private ZWaveEvent ProcessEncapsulatedMessage(ZWaveNode node, byte[] encapMessage)
        {
            Utility.DebugLog(DebugMessageType.Information, String.Format("CRC16 encapsulated message: {0}", Utility.ByteArrayToString(encapMessage)));
            ZWaveEvent nodeEvent = null;
            byte       cmdClass  = encapMessage[0];
            var        cc        = CommandClassFactory.GetCommandClass(cmdClass);

            if (cc == null)
            {
                Utility.DebugLog(DebugMessageType.Error, String.Format("Can't find CommandClass handler for command class {0}", cmdClass));
            }
            else
            {
                nodeEvent = cc.GetEvent(node, encapMessage);
            }
            return(nodeEvent);
        }