Пример #1
0
        internal virtual bool ApplicationCommandHandler(byte[] rawMessage)
        {
            NodeEvent messageEvent  = null;
            int       messageLength = rawMessage.Length;

            if (messageLength > 8)
            {
                byte commandLength = rawMessage[6];
                byte commandClass  = rawMessage[7];
                // TODO: this should be moved inside the NodeCommandClass class
                // TODO: as "Instance" property
                var    cc      = CommandClassFactory.GetCommandClass(commandClass);
                byte[] message = new byte[commandLength];
                Array.Copy(rawMessage, 7, message, 0, commandLength);
                try
                {
                    messageEvent = cc.GetEvent(this, message);
                }
                catch (Exception ex)
                {
                    Utility.logger.Error(ex);
                }
            }

            if (messageEvent != null)
            {
                OnNodeUpdated(messageEvent);
            }
            else if (messageLength > 3 && rawMessage[3] != (byte)ZWaveFunction.SendData)
            {
                Utility.logger.Warn("Unhandled message type: {0}", BitConverter.ToString(rawMessage));
            }

            return(false);
        }
Пример #2
0
        //this is designed to be called during NodeAdd ONLY
        public bool HandleSecureCommandClasses(byte[] nodeInfo)
        {
            bool foundSecure = false;

            foreach (byte b in nodeInfo)
            {
                // if we are security then we need to initalize
                if (b == (byte)CommandClass.Security)
                {
                    security.adding_node = true;
                    var cc = CommandClassFactory.GetCommandClass(b);
                    cc.GetEvent(this, null);
                    foundSecure = true;
                }
            }

            return(foundSecure);
        }
Пример #3
0
        public virtual bool MessageRequestHandler(byte[] receivedMessage)
        {
            ZWaveEvent messageEvent  = null;
            int        messageLength = receivedMessage.Length;

            if (messageLength > 8)
            {
                byte   commandLength = receivedMessage[6];
                byte   commandClass  = receivedMessage[7];
                var    cc            = CommandClassFactory.GetCommandClass(commandClass);
                byte[] message       = new byte[commandLength];
                Array.Copy(receivedMessage, 7, message, 0, commandLength);
                try
                {
                    messageEvent = cc.GetEvent(this, message);
                }
                catch (Exception ex)
                {
                    Utility.DebugLog(DebugMessageType.Error, "Error in Command Class " + commandClass.ToString("X2") + " GetEvent: " + ex.Message + "\n" + ex.StackTrace);
                }
            }

            if (messageEvent != null)
            {
                if (messageEvent.Parameter == EventParameter.ManufacturerSpecific)
                {
                    var specs = (ManufacturerSpecificInfo)messageEvent.Value;
                    this.ManufacturerId = specs.ManufacturerId;
                    this.TypeId         = specs.TypeId;
                    this.ProductId      = specs.ProductId;
                    if (ManufacturerSpecificResponse != null)
                    {
                        try
                        {
                            ManufacturerSpecificResponse(this, new ManufacturerSpecificResponseEventArg()
                            {
                                NodeId = this.Id,
                                ManufacturerSpecific = specs
                            });
                        }
                        catch (Exception ex)
                        {
                            Utility.DebugLog(DebugMessageType.Error, "Exception occurred during ManufacturerSpecificResponse callback: " + ex.Message + "\n" + ex.StackTrace);
                        }
                    }
                }

                this.RaiseUpdateParameterEvent(messageEvent);
            }
            else if (messageLength > 3)
            {
                if (receivedMessage[3] != 0x13)
                {
                    bool log = true;
                    // do not log an error message for ManufacturerSpecific and Security CommandClass
                    if (messageLength > 7 && /* cmd_class */ (receivedMessage[7] == (byte)CommandClass.ManufacturerSpecific || receivedMessage[7] == (byte)CommandClass.Security))
                    {
                        log = false;
                    }
                    if (log)
                    {
                        Utility.DebugLog(DebugMessageType.Error, "Unhandled message: " + Utility.ByteArrayToString(receivedMessage));
                    }
                }
            }

            return(false);
        }
Пример #4
0
        public virtual bool MessageRequestHandler(byte[] receivedMessage)
        {
            //Console.WriteLine("\n   _z_ [" + this.NodeId + "]  " + (this.DeviceHandler != null ? this.DeviceHandler.ToString() : "!" + this.GenericClass.ToString()));
            //Console.WriteLine("   >>> " + zp.ByteArrayToString(receivedMessage) + "\n");

            ZWaveEvent messageEvent  = null;
            int        messageLength = receivedMessage.Length;

            if (messageLength > 8)
            {
                byte   commandLength = receivedMessage[6];
                byte   commandClass  = receivedMessage[7];
                var    cc            = CommandClassFactory.GetCommandClass(commandClass);
                byte[] message       = new byte[commandLength];
                Array.Copy(receivedMessage, 7, message, 0, commandLength);
                messageEvent = cc.GetEvent(this, message);
            }

            if (messageEvent != null)
            {
                if (messageEvent.Parameter == EventParameter.ManufacturerSpecific)
                {
                    var specs = (ManufacturerSpecificInfo)messageEvent.Value;
                    this.ManufacturerId = specs.ManufacturerId;
                    this.TypeId         = specs.TypeId;
                    this.ProductId      = specs.ProductId;
                    if (ManufacturerSpecificResponse != null)
                    {
                        try
                        {
                            ManufacturerSpecificResponse(this, new ManufacturerSpecificResponseEventArg()
                            {
                                NodeId = this.Id,
                                ManufacturerSpecific = specs
                            });
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("ZWaveLib: Error during ManufacturerSpecificResponse callback, " +
                                              ex.Message + "\n" + ex.StackTrace);
                        }
                    }
                }
                this.RaiseUpdateParameterEvent(messageEvent);
            }
            else if (messageLength > 3)
            {
                if (receivedMessage[3] != 0x13)
                {
                    bool log = true;
                    if (messageLength > 7 && /* cmd_class */ receivedMessage[7] == (byte)CommandClass.ManufacturerSpecific)
                    {
                        log = false;
                    }
                    if (log)
                    {
                        Console.WriteLine("ZWaveLib UNHANDLED message: " + Utility.ByteArrayToString(receivedMessage));
                    }
                }
            }

            return(false);
        }
Пример #5
0
        public bool BuildSupportedList(byte[] nodesInfo, bool secured)
        {
            bool afterMark   = false;
            bool foundSecure = false;

            if (nodesInfo == null)
            {
                return(false);
            }

            foreach (byte nodeInfo in nodesInfo)
            {
                if (nodeInfo == (byte)0xEF)
                {
                    // COMMAND_CLASS_MARK.
                    // Marks the end of the list of supported command classes.  The remaining classes
                    // are those that can be controlled by the device.  These classes are created
                    // without values.  Messages received cause notification events instead.
                    afterMark = true;
                    continue;
                }

                var cc = CommandClassFactory.GetCommandClass((byte)nodeInfo);

                if (cc == null)
                {
                    Console.WriteLine(nodeInfo.ToString("X2") + " - We don't NOT supporte this CommandClass");
                }
                else
                {
                    SupportedCommandClasses scc = supportedClasses.Find(x => x.cclass == (byte)nodeInfo);

                    if (scc == null)
                    {
                        scc = new SupportedCommandClasses {
                            cclass = (byte)nodeInfo, secure = secured, afterMark = afterMark
                        };
                        supportedClasses.Add(scc);
                        Console.WriteLine("Added " + scc);
                    }
                    else
                    {
                        scc.secure = true;
                        Console.WriteLine("Updated " + scc);
                    }
                }

                if (nodeInfo == (byte)CommandClass.Security)
                {
                    foundSecure = true;
                }

                this.NodeInformationFrame = addElementToArray(this.NodeInformationFrame, nodeInfo);

                if (secured)
                {
                    this.SecuredNodeInformationFrame = addElementToArray(this.SecuredNodeInformationFrame, nodeInfo);
                }
            }

            return(foundSecure);
        }
Пример #6
0
        public virtual bool MessageRequestHandler(Controller ctrl, byte[] receivedMessage)
        {
            //Console.WriteLine("\n   _z_ [" + this.NodeId + "]  " + (this.DeviceHandler != null ? this.DeviceHandler.ToString() : "!" + this.GenericClass.ToString()));
            //Console.WriteLine("   >>> " + zp.ByteArrayToString(receivedMessage) + "\n");

            // saving a reference to the controller
            pController = ctrl;

            ZWaveEvent messageEvent  = null;
            int        messageLength = receivedMessage.Length;

            if (messageLength > 8)
            {
                byte   commandLength = receivedMessage[6];
                byte   commandClass  = receivedMessage[7];
                var    cc            = CommandClassFactory.GetCommandClass(commandClass);
                byte[] message       = new byte[commandLength];
                Array.Copy(receivedMessage, 7, message, 0, commandLength);
                messageEvent = cc.GetEvent(this, message);
            }

            if (messageEvent != null)
            {
                if (messageEvent.Parameter == EventParameter.ManufacturerSpecific)
                {
                    var specs = (ManufacturerSpecificInfo)messageEvent.Value;
                    this.ManufacturerId = specs.ManufacturerId;
                    this.TypeId         = specs.TypeId;
                    this.ProductId      = specs.ProductId;
                    if (ManufacturerSpecificResponse != null)
                    {
                        try
                        {
                            ManufacturerSpecificResponse(this, new ManufacturerSpecificResponseEventArg()
                            {
                                NodeId = this.Id,
                                ManufacturerSpecific = specs
                            });
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("ZWaveLib: Error during ManufacturerSpecificResponse callback, " +
                                              ex.Message + "\n" + ex.StackTrace);
                        }
                    }
                }
                else if (messageEvent.Node.GenericClass == (byte)GenericType.EntryControl)
                {
                    // this is an event for DoorLock and needs special handling
                    if (messageEvent.Parameter == EventParameter.AlarmGeneric)
                    {
                        int value = System.Convert.ToInt16(messageEvent.Value);
                        messageEvent.Parameter = EventParameter.DoorLockStatus;
                        if (value == 1)
                        {
                            messageEvent.Value = "Locked";
                        }
                        else if (value == 2)
                        {
                            messageEvent.Value = "Unlocked";
                        }
                        else if (value == 5)
                        {
                            messageEvent.Value = "Locked from outside";
                        }
                        else if (value == 6)
                        {
                            messageEvent.Value = "Unlocked by user " + System.Convert.ToInt32(receivedMessage[16].ToString("X2"), 16);
                        }
                        else if (value == 16)
                        {
                            messageEvent.Value = "Unatuthorized unlock attempted";
                        }
                    }
                }

                this.RaiseUpdateParameterEvent(messageEvent);
            }
            else if (messageLength > 3)
            {
                if (receivedMessage[3] != 0x13)
                {
                    bool log = true;
                    // do not log an error message for ManufacturerSpecific and Security CommandClass
                    if (messageLength > 7 && /* cmd_class */ (receivedMessage[7] == (byte)CommandClass.ManufacturerSpecific || receivedMessage[7] == (byte)CommandClass.Security))
                    {
                        log = false;
                    }
                    if (log)
                    {
                        Console.WriteLine("ZWaveLib UNHANDLED message: " + Utility.ByteArrayToString(receivedMessage));
                    }
                }
            }

            return(false);
        }