Beispiel #1
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];
                switch (commandClass)
                {
                case (byte)CommandClass.Basic:
                    messageEvent = Basic.GetEvent(this, receivedMessage);
                    break;

                case (byte)CommandClass.Alarm:
                    messageEvent = Alarm.GetEvent(this, receivedMessage);
                    break;

                case (byte)CommandClass.SensorAlarm:
                    messageEvent = SensorAlarm.GetEvent(this, receivedMessage);
                    break;

                case (byte)CommandClass.SceneActivation:
                    messageEvent = SceneActivation.GetEvent(this, receivedMessage);
                    break;

                case (byte)CommandClass.SwitchBinary:
                    messageEvent = SwitchBinary.GetEvent(this, receivedMessage);
                    break;

                case (byte)CommandClass.SwitchMultilevel:
                    messageEvent = SwitchMultilevel.GetEvent(this, receivedMessage);
                    break;

                case (byte)CommandClass.SensorBinary:
                    messageEvent = SensorBinary.GetEvent(this, receivedMessage);
                    break;

                case (byte)CommandClass.SensorMultilevel:
                    messageEvent = SensorMultilevel.GetEvent(this, receivedMessage);
                    break;

                case (byte)CommandClass.Meter:
                    messageEvent = Meter.GetEvent(this, receivedMessage);
                    break;

                case (byte)CommandClass.ThermostatMode:
                case (byte)CommandClass.ThermostatFanMode:
                case (byte)CommandClass.ThermostatFanState:
                case (byte)CommandClass.ThermostatHeating:
                case (byte)CommandClass.ThermostatOperatingState:
                case (byte)CommandClass.ThermostatSetBack:
                case (byte)CommandClass.ThermostatSetPoint:
                    messageEvent = Thermostat.GetEvent(this, receivedMessage);
                    break;

                case (byte)CommandClass.UserCode:
                    messageEvent = UserCode.GetEvent(this, receivedMessage);
                    break;

                case (byte)CommandClass.Association:
                    messageEvent = Association.GetEvent(this, receivedMessage);
                    break;

                case (byte)CommandClass.Configuration:
                    messageEvent = Configuration.GetEvent(this, receivedMessage);
                    break;

                case (byte)CommandClass.WakeUp:
                    messageEvent = WakeUp.GetEvent(this, receivedMessage);
                    break;

                case (byte)CommandClass.Battery:
                    messageEvent = Battery.GetEvent(this, receivedMessage);
                    break;

                case (byte)CommandClass.Hail:
                    Basic.Get(this);
                    break;

                case (byte)CommandClass.MultiInstance:
                    messageEvent = MultiInstance.GetEvent(this, receivedMessage);
                    break;

                case (byte)CommandClass.ManufacturerSpecific:
                    messageEvent = ManufacturerSpecific.GetEvent(this, receivedMessage);
                    if (messageEvent != null)
                    {
                        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.NodeId,
                                    ManufacturerSpecific = specs
                                });
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("ZWaveLib: Error during ManufacturerSpecificResponse callback, " + ex.Message + "\n" + ex.StackTrace);
                            }
                        }
                    }

                    break;
                }
            }

            if (messageEvent != null)
            {
                this.RaiseUpdateParameterEvent(messageEvent.Instance, messageEvent.Event, messageEvent.Value);
            }
            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);
        }