Exemplo n.º 1
0
        private bool GetLinkIdentity(InsteonAddress address, out InsteonIdentity?identity)
        {
            Dictionary <PropertyKey, int> properties;

            logger.DebugFormat("Device {0} GetLinkIdentity", Address.ToString());
            byte[] message = { (byte)InsteonModemSerialCommand.StandardOrExtendedMessage, address[2],                            address[1], address[0],
                               (byte)MessageFlagsStandard.ThreeHopsThreeRemaining,        (byte)InsteonDirectCommands.IdRequest, Byte.MinValue };

            var status = network.Messenger.TrySendReceive(message, false, (byte)InsteonModemSerialCommand.StandardMessage, InsteonMessageType.SetButtonPressed, out properties);

            if (status == EchoStatus.NAK)
            {
                logger.ErrorFormat("received NAK trying to get idendity information");
                identity = null;
                return(false);
            }
            if (status == EchoStatus.ACK)
            {
                if (properties == null)
                {
                    logger.ErrorFormat("Device Id {0} has null properties object", Address.ToString());
                    identity = null;
                    return(false);
                }
                identity = new InsteonIdentity((byte)properties[PropertyKey.DevCat], (byte)properties[PropertyKey.SubCat], (byte)properties[PropertyKey.FirmwareVersion]);
                return(true);
            }

            logger.ErrorFormat("received unknown status trying to get idendity information");
            identity = null;
            return(false); // echo was not ACK or NAK
        }
 internal void OnMessage(InsteonMessage message)
 {
     if (message.MessageType == InsteonMessageType.DeviceLink)
     {
         InsteonAddress  address  = new InsteonAddress(message.Properties[PropertyKey.Address]);
         InsteonIdentity identity = new InsteonIdentity((byte)message.Properties[PropertyKey.DevCat], (byte)message.Properties[PropertyKey.SubCat], (byte)message.Properties[PropertyKey.FirmwareVersion]);
         InsteonDevice   device   = network.Devices.Add(address, identity);
         timer.Stop();
         IsInLinkingMode = false;
         if (linkingMode.HasValue)
         {
             if (linkingMode != InsteonLinkMode.Delete)
             {
                 OnDeviceLinked(device);
             }
             else
             {
                 OnDeviceUnlinked(device);
             }
         }
         else
         {
             OnDeviceLinked(device);
         }
     }
 }
Exemplo n.º 3
0
        private bool GetProductData(InsteonDeviceLinkRecord link, out InsteonIdentity?identity)
        {
            Dictionary <PropertyKey, int> properties;

            logger.DebugFormat("Controller {0} GetLinkProductData", Address.ToString());
            byte[] message = { (byte)InsteonModemSerialCommand.StandardOrExtendedMessage, link.Address[2],                                link.Address[1], link.Address[0],
                               (byte)MessageFlagsStandard.ThreeHopsThreeRemaining,        (byte)InsteonDirectCommands.ProductDataRequest, Byte.MinValue };

            var status = network.Messenger.TrySendReceive(message, false, (byte)InsteonModemSerialCommand.ExtendedMessage, InsteonMessageType.ProductDataResponse, out properties);

            if (status == EchoStatus.NAK)
            {
                logger.ErrorFormat("received NAK trying to get ProductData information");
                identity = null;
                return(false);
            }
            if (status == EchoStatus.ACK)
            {
                if (properties == null)
                {
                    logger.ErrorFormat("Device Id {0} has null properties object", Address.ToString());
                    identity = null;
                    return(false);
                }
                var pk = new InsteonProductKey((byte)properties[PropertyKey.ProductKeyHigh], (byte)properties[PropertyKey.ProductKeyMid], (byte)properties[PropertyKey.ProductKeyLow]);
                identity = new InsteonIdentity((byte)properties[PropertyKey.DevCat], (byte)properties[PropertyKey.SubCat], (byte)properties[PropertyKey.FirmwareVersion], pk);
                return(true);
            }

            logger.ErrorFormat("received unknown status trying to get productdata information");
            identity = null;
            return(false); // echo was not ACK or NAK
        }
Exemplo n.º 4
0
 internal InsteonDevice(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity)
 {
     this.network = network;
     this.Address = address;
     this.Identity = identity;
     this.ackTimer = new Timer(new TimerCallback(this.PendingCommandTimerCallback), null, Timeout.Infinite, Constants.deviceAckTimeout);
 }
 internal InsteonDevice(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity)
 {
     this.network  = network;
     this.Address  = address;
     this.Identity = identity;
     this.ackTimer = new Timer(new TimerCallback(PendingCommandTimerCallback), null, Timeout.Infinite, Constants.deviceAckTimeout);
 }
Exemplo n.º 6
0
 private InsteonController(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity)
 {
     this.network = network;
     this.Address = address;
     this.Identity = identity;
     
     this.timer.Interval = 4 * 60* 1000; // 4 minutes
     this.timer.AutoReset = false;
     this.timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
 }
        private InsteonController(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity)
        {
            this.network  = network;
            this.Address  = address;
            this.Identity = identity;

            this.timer.Interval  = 4 * 60 * 1000; // 4 minutes
            this.timer.AutoReset = false;
            this.timer.Elapsed  += new System.Timers.ElapsedEventHandler(timer_Elapsed);
        }
 private void OnSetButtonPressed(InsteonMessage message)
 {
     if (this.Identity.IsEmpty)
     {
         byte devCat          = (byte)message.Properties[PropertyKey.DevCat];
         byte subCat          = (byte)message.Properties[PropertyKey.DevCat];
         byte firmwareVersion = (byte)message.Properties[PropertyKey.DevCat];
         this.Identity = new InsteonIdentity(devCat, subCat, firmwareVersion);
     }
     OnDeviceIdentified();
 }
Exemplo n.º 9
0
        /// <summary>
        /// Adds an INSTEON device to the list of known devices.
        /// </summary>
        /// <param name="address">The INSTEON address of the device to add.</param>
        /// <param name="identity">The INSTEON identity of the device to add.</param>
        /// <returns>Returns an object representing the specified device.</returns>
        /// <remarks>This method does not perform any INSTEON messaging, it only adds the specified device to a list of known devices.</remarks>
        public InsteonDevice Add(InsteonAddress address, InsteonIdentity identity)
        {
            if (devices.ContainsKey(address.Value))
            {
                return(devices[address.Value]);
            }

            InsteonDevice device = new InsteonDevice(network, address, identity);

            devices.Add(address.Value, device);
            OnDeviceAdded(device);
            return(device);
        }
Exemplo n.º 10
0
        private InsteonController(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity)
        {
            this.network = network;
            Address      = address;
            Identity     = identity;

            timer.Interval  = 4 * 60 * 1000; // 4 minutes
            timer.AutoReset = false;
            timer.Elapsed  += (sender, args) =>
            {
                IsInLinkingMode = false;
                OnDeviceLinkTimeout();
            };
        }
Exemplo n.º 11
0
 internal void OnMessage(InsteonMessage message)
 {
     if (message.MessageType == InsteonMessageType.DeviceLink)
     {
         InsteonAddress address = new InsteonAddress(message.Properties[PropertyKey.Address]);
         InsteonIdentity identity = new InsteonIdentity((byte)message.Properties[PropertyKey.DevCat], (byte)message.Properties[PropertyKey.SubCat], (byte)message.Properties[PropertyKey.FirmwareVersion]);
         InsteonDevice device = network.Devices.Add(address, identity);
         timer.Stop();
         IsInLinkingMode = false;
         if (linkingMode.HasValue)
         {
             if (linkingMode != InsteonLinkMode.Delete)
                 OnDeviceLinked(device);
             else
                 OnDeviceUnlinked(device);
         }
         else
         {
             OnDeviceLinked(device);
         }
     }
 }
 /// <summary>
 /// Determines the type of INSTEON device by querying the device.
 /// </summary>
 /// <remarks>
 /// This method does not throw an exception.
 /// This is a non-blocking method that sends an INSTEON message to the target device and returns immediately (as long as another command is not already pending for the device). Only one command can be pending to an INSTEON device at a time. This method will block if a second command is sent while a first command is still pending.
 /// The <see cref="DeviceIdentified">DeviceIdentified</see> event will be invoked if the command is successful.
 /// The <see cref="DeviceCommandTimeout">DeviceCommandTimeout</see> event will be invoked if the device does not respond within the expected timeout period.
 /// </remarks>
 public bool TryIdentify()
 {
     this.Identity = new InsteonIdentity();
     return(TryCommand(InsteonDeviceCommands.IDRequest));
 }
 /// <summary>
 /// Determines the type of INSTEON device by querying the device.
 /// </summary>
 /// <remarks>
 /// This is a non-blocking method that sends an INSTEON message to the target device and returns immediately (as long as another command is not already pending for the device). Only one command can be pending to an INSTEON device at a time. This method will block if a second command is sent while a first command is still pending.
 /// The <see cref="DeviceIdentified">DeviceIdentified</see> event will be invoked if the command is successful.
 /// The <see cref="DeviceCommandTimeout">DeviceCommandTimeout</see> event will be invoked if the device does not respond within the expected timeout period.
 /// </remarks>
 public void Identify()
 {
     this.Identity = new InsteonIdentity();
     Command(InsteonDeviceCommands.IDRequest);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Determines the type of INSTEON device by querying the device.
 /// </summary>
 /// <remarks>
 /// This method does not throw an exception.
 /// This is a non-blocking method that sends an INSTEON message to the target device and returns immediately (as long as another command is not already pending for the device). Only one command can be pending to an INSTEON device at a time. This method will block if a second command is sent while a first command is still pending.
 /// The <see cref="DeviceIdentified">DeviceIdentified</see> event will be invoked if the command is successful.
 /// The <see cref="DeviceCommandTimeout">DeviceCommandTimeout</see> event will be invoked if the device does not respond within the expected timeout period.
 /// </remarks>
 public bool TryIdentify()
 {
     this.Identity = new InsteonIdentity();
     return this.TryCommand(InsteonDeviceCommands.IDRequest);
 }
Exemplo n.º 15
0
 private void OnSetButtonPressed(InsteonMessage message)
 {
     if (this.Identity.IsEmpty)
     {
         var devCat = (byte)message.Properties[PropertyKey.DevCat];
         var subCat = (byte)message.Properties[PropertyKey.DevCat];
         var firmwareVersion = (byte)message.Properties[PropertyKey.DevCat];
         this.Identity = new InsteonIdentity(devCat, subCat, firmwareVersion);
     }
     this.OnDeviceIdentified();
 }
Exemplo n.º 16
0
 /// <summary>
 /// Determines the type of INSTEON device by querying the device.
 /// </summary>
 /// <remarks>
 /// This is a non-blocking method that sends an INSTEON message to the target device and returns immediately (as long as another command is not already pending for the device). Only one command can be pending to an INSTEON device at a time. This method will block if a second command is sent while a first command is still pending.
 /// The <see cref="DeviceIdentified">DeviceIdentified</see> event will be invoked if the command is successful.
 /// The <see cref="DeviceCommandTimeout">DeviceCommandTimeout</see> event will be invoked if the device does not respond within the expected timeout period.
 /// </remarks>
 public void Identify()
 {
     this.Identity = new InsteonIdentity();
     this.Command(InsteonDeviceCommands.IDRequest);
 }