/// <summary>
 /// Called when a message comes in from the modem.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 void port_ReceivedMessage(object sender, RecievedMessageEventArgs args)
 {
     switch (args.Message.MessageType)
     {
         case PowerLineModemMessage.Message.AllLinkRecordResponse:
             // If we get this, then query the device for more details.
             AllLinkRecordResponse response = (AllLinkRecordResponse)args.Message;
             this.linkedDevices[response.Record.Address] = response.Record;
             this.linkingEvent.Set();
             break;
         case PowerLineModemMessage.Message.StandardMessageReceived:
             StandardMessage standardMessage = (StandardMessage)args.Message;
             if (standardMessage.Packet.FromAddress.Equals(this.sendingPacket.FromAddress))
             {
                 if (standardMessage.Packet.Flags.MessageType == InsteonPacket.InsteonFlags.MessageTypeEnum.AckDirect ||
                     standardMessage.Packet.Flags.MessageType == InsteonPacket.InsteonFlags.MessageTypeEnum.NackDirect)
                 {
                     this.receivedPacket = standardMessage.Packet;
                     this.linkingEvent.Set();
                     break;
                 }
             }
             // Find the device and send the packet there.
             if (this.devices.ContainsKey(standardMessage.Packet.FromAddress))
             {
                 DeviceBase device = this.devices[standardMessage.Packet.FromAddress];
                 if (device.handleInsteonPacket(standardMessage.Packet)) {
                     if (DeviceChanged != null){
                         DeviceChanged(this, new DeviceChangedEventArgs(device));
                     }
                     }
             }
             else
             {
                 // If this is a broadcast set button pressed, add into the device list.
                 if (standardMessage.Packet.Flags.MessageType == InsteonPacket.InsteonFlags.MessageTypeEnum.Broadcast &&
                     standardMessage.Packet.Command1 == (byte)InsteonPacket.BroadcastCommand.SetButtonPressed)
                 {
                     byte category = standardMessage.Packet.ToAddress.Address[0];
                     byte subCategory = standardMessage.Packet.ToAddress.Address[1];
                     AddDevice(standardMessage.Packet.FromAddress, category, subCategory);
                 }
             }
             break;
         case PowerLineModemMessage.Message.ExtendedMessageReceived:
             ExtendedMessage extendedMessage = (ExtendedMessage)args.Message;
             if (extendedMessage.Packet.FromAddress.Equals(this.sendingPacket.FromAddress))
             {
                 if (extendedMessage.Packet.Flags.MessageType == InsteonPacket.InsteonFlags.MessageTypeEnum.AckDirect ||
                     extendedMessage.Packet.Flags.MessageType == InsteonPacket.InsteonFlags.MessageTypeEnum.NackDirect)
                 {
                     this.receivedPacket = extendedMessage.Packet;
                     this.linkingEvent.Set();
                     break;
                 }
             }
             // Find the device and send the packet there.
             if (this.devices.ContainsKey(extendedMessage.Packet.FromAddress))
             {
                 DeviceBase device = this.devices[extendedMessage.Packet.FromAddress];
                 if (device.handleInsteonPacket(extendedMessage.Packet))
                 {
                     if (DeviceChanged != null)
                     {
                         DeviceChanged(this, new DeviceChangedEventArgs(device));
                     }
                 }
             }
             break;
     }
 }
Exemple #2
0
        /// <summary>
        /// Called when a message comes in from the modem.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        void port_ReceivedMessage(object sender, RecievedMessageEventArgs args)
        {
            switch (args.Message.MessageType)
            {
            case PowerLineModemMessage.Message.AllLinkRecordResponse:
                // If we get this, then query the device for more details.
                AllLinkRecordResponse response = (AllLinkRecordResponse)args.Message;
                this.linkedDevices[response.Record.Address] = response.Record;
                this.linkingEvent.Set();
                break;

            case PowerLineModemMessage.Message.StandardMessageReceived:
                StandardMessage standardMessage = (StandardMessage)args.Message;
                if (standardMessage.Packet.FromAddress.Equals(this.sendingPacket.FromAddress))
                {
                    if (standardMessage.Packet.Flags.MessageType == InsteonPacket.InsteonFlags.MessageTypeEnum.AckDirect ||
                        standardMessage.Packet.Flags.MessageType == InsteonPacket.InsteonFlags.MessageTypeEnum.NackDirect)
                    {
                        this.receivedPacket = standardMessage.Packet;
                        this.linkingEvent.Set();
                        break;
                    }
                }
                // Find the device and send the packet there.
                if (this.devices.ContainsKey(standardMessage.Packet.FromAddress))
                {
                    DeviceBase device = this.devices[standardMessage.Packet.FromAddress];
                    if (device.handleInsteonPacket(standardMessage.Packet))
                    {
                        if (DeviceChanged != null)
                        {
                            DeviceChanged(this, new DeviceChangedEventArgs(device));
                        }
                    }
                }
                else
                {
                    // If this is a broadcast set button pressed, add into the device list.
                    if (standardMessage.Packet.Flags.MessageType == InsteonPacket.InsteonFlags.MessageTypeEnum.Broadcast &&
                        standardMessage.Packet.Command1 == (byte)InsteonPacket.BroadcastCommand.SetButtonPressed)
                    {
                        byte category    = standardMessage.Packet.ToAddress.Address[0];
                        byte subCategory = standardMessage.Packet.ToAddress.Address[1];
                        AddDevice(standardMessage.Packet.FromAddress, category, subCategory);
                    }
                }
                break;

            case PowerLineModemMessage.Message.ExtendedMessageReceived:
                ExtendedMessage extendedMessage = (ExtendedMessage)args.Message;
                if (extendedMessage.Packet.FromAddress.Equals(this.sendingPacket.FromAddress))
                {
                    if (extendedMessage.Packet.Flags.MessageType == InsteonPacket.InsteonFlags.MessageTypeEnum.AckDirect ||
                        extendedMessage.Packet.Flags.MessageType == InsteonPacket.InsteonFlags.MessageTypeEnum.NackDirect)
                    {
                        this.receivedPacket = extendedMessage.Packet;
                        this.linkingEvent.Set();
                        break;
                    }
                }
                // Find the device and send the packet there.
                if (this.devices.ContainsKey(extendedMessage.Packet.FromAddress))
                {
                    DeviceBase device = this.devices[extendedMessage.Packet.FromAddress];
                    if (device.handleInsteonPacket(extendedMessage.Packet))
                    {
                        if (DeviceChanged != null)
                        {
                            DeviceChanged(this, new DeviceChangedEventArgs(device));
                        }
                    }
                }
                break;
            }
        }