internal void sendStandardLengthMessage(DeviceId toAddress, byte flags, byte command1, byte command2) { sendCommandWithEchoAndAck(0x02, 0x62, toAddress.IdHi, toAddress.IdMiddle, toAddress.IdLo, flags, command1, command2); }
internal AllLinkingCompletedArgs(byte linkCode, byte group, DeviceId peerId, byte deviceCategory, byte deviceSubcategory) { if (peerId == null) { throw new ArgumentNullException("peerId"); } this.AllLinkGroup = group; switch (linkCode) { case 0x00: this.AllLinkingAction = AllLinkingAction.LinkedWithPlmAsSlave; break; case 0x01: this.AllLinkingAction = AllLinkingAction.LinkedWithPlmAsMaster; break; case 0xFF: this.AllLinkingAction = AllLinkingAction.LinkDeleted; break; default: throw new ArgumentOutOfRangeException("linkCode"); } this.PeerId = peerId; this.DeviceCategoryCode = deviceCategory; this.DeviceSubcategoryCode = deviceSubcategory; }
/// <summary> /// Sends a message to the device with the given /// DeviceId in order to try to identify it, and /// if successful, returns a DeviceBase object. /// The derived type of the returned object varies /// depending on the Device category discovered /// during the identification process. /// </summary> /// <returns>null if unsuccessful - check plm.Exception</returns> public bool TryConnectToDevice(DeviceId deviceId, out DeviceBase device) { if (deviceId == null) { throw new ArgumentNullException("deviceId"); } DeviceBase result = null; if (this.deviceCache.ContainsKey(deviceId)) { result = this.deviceCache[deviceId]; } else { this.plm.exceptionHandler(() => { byte[] responseAck = this.plm.sendStandardLengthMessageAndWait4Response( deviceId, Constants.MSG_FLAGS_DIRECT, 0x10, 0x00); byte[] responseIdRequest = this.plm.waitForStandardMessageFrom(deviceId); result = DeviceFactory.BuildDevice(this.plm, responseIdRequest); }); if (result != null) { this.deviceCache.Add(deviceId, result); } } device = result; return(result != null); }
internal void sendExtendedMessage(DeviceId toAddress, byte flags, byte command1, byte command2) { sendCommandWithEchoAndAck(0x02, 0x62, toAddress.IdHi, toAddress.IdMiddle, toAddress.IdLo, flags, command1, command2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); }
public bool Equals(DeviceId otherId) { if ((object)otherId == null) { return(false); } return(otherId.ToString() == this.ToString()); }
protected override void processIncomingMessage(byte[] message) { if (message.Length < 2) { return; } switch (message[1]) { case 0x52: if (message.Length != 4) { return; } this.network.X10.x10MessageReceived(message[2], message[3]); break; case 0x53: if (message.Length != 10) { return; } byte linkCode = message[2]; byte group = message[3]; var peerId = new DeviceId(message[4], message[5], message[6]); byte deviceCategory = message[7]; byte deviceSubcategory = message[8]; this.network.allLinkingCompleted(linkCode, group, peerId, deviceCategory, deviceSubcategory); break; case 0x54: if (message.Length != 3) { return; } if (message[2] == 0x02) // set button pressed { this.setButton.setButtonTapped(); } else if (message[2] == 0x03) // set button pressed and held { this.setButton.setButtonPressedAndHeld(); } else if (message[2] == 0x04) // set button released after being held { this.setButton.setButtonReleasedAfterHolding(); } break; case 0x55: this.setButton.setButtonHeldDuringPowerUp(); break; } }
private void fireAllLinkingCompletedEvent(byte linkCode, byte group, DeviceId peerId, byte deviceCategory, byte deviceSubcategory) { var evt = AllLinkingCompleted; if (evt != null) { evt(this, new AllLinkingCompletedArgs(linkCode, group, peerId, deviceCategory, deviceSubcategory)); } }
private void fireStandardMessageReceivedEvent(DeviceId peerId, byte group, byte flags, byte command1, byte command2) { var evt = StandardMessageReceived; if (evt != null) { evt(this, new StandardMessageReceivedArgs(peerId, group, flags, command1, command2)); } }
/// <summary> /// Sends the given standard command to the given address /// and returns true if the peer responded with an ACK. /// </summary> /// <param name="toAddress">Example: new DeviceId("12.34.56")</param> public bool SendStandardCommandToAddress(DeviceId toAddress, byte command1, byte command2) { bool result = false; this.plm.exceptionHandler(() => { byte[] responseAck = this.plm.sendStandardLengthMessageAndWait4Response( toAddress, Constants.MSG_FLAGS_DIRECT, command1, command2); byte flags = DeviceMessage.MessageFlags(responseAck); result = (flags & Constants.MSG_FLAGS_DIRECT_ACK) > 0; }); return(result); }
/// <summary> /// Sends the given standard command to the given address /// and returns true if the peer responded with an ACK, also returns the data from the message. /// </summary> /// <param name="toAddress">Example: new DeviceId("12.34.56")</param> public bool GetByteFromAddress(DeviceId toAddress, byte command1, byte command2, out byte data) { bool result = false; byte[] responseAck = null; this.plm.exceptionHandler(() => { responseAck = this.plm.sendStandardLengthMessageAndWait4Response( toAddress, Constants.MSG_FLAGS_DIRECT, command1, command2); byte flags = DeviceMessage.MessageFlags(responseAck); result = (flags & Constants.MSG_FLAGS_DIRECT_ACK) > 0; }); if (result) { data = DeviceMessage.Command2(responseAck); } else { data = 0; } return result; }
/// <summary> /// Sends the given standard command to the given address /// and returns true if the peer responded with an ACK, also returns the data from the message. /// </summary> /// <param name="toAddress">Example: new DeviceId("12.34.56")</param> public bool GetByteFromAddress(DeviceId toAddress, byte command1, byte command2, out byte data) { bool result = false; byte[] responseAck = null; this.plm.exceptionHandler(() => { responseAck = this.plm.sendStandardLengthMessageAndWait4Response( toAddress, Constants.MSG_FLAGS_DIRECT, command1, command2); byte flags = DeviceMessage.MessageFlags(responseAck); result = (flags & Constants.MSG_FLAGS_DIRECT_ACK) > 0; }); if (result) { data = DeviceMessage.Command2(responseAck); } else { data = 0; } return(result); }
internal byte[] waitForStandardMessageFrom(DeviceId peerAddress) { byte[] result = null; int tryCounter = 0; DeviceId originator; do { result = this.serialPortController.GetIncomingMessageOfType(MSG_TYPE_RECV_STANDARD); originator = DeviceMessage.DeviceMessageOriginator(result); if (originator != peerAddress) { queueReceivedMessage(result); result = null; tryCounter++; if (tryCounter > 3) { throw new TimeoutException("Timed out waiting for response from " + peerAddress.ToString()); } } } while (result == null); return(result); }
internal AllLinkingCompletedArgs(byte linkCode, byte group, DeviceId peerId, byte deviceCategory, byte deviceSubcategory) { if (peerId == null) throw new ArgumentNullException("peerId"); this.AllLinkGroup = group; switch (linkCode) { case 0x00: this.AllLinkingAction = AllLinkingAction.LinkedWithPlmAsSlave; break; case 0x01: this.AllLinkingAction = AllLinkingAction.LinkedWithPlmAsMaster; break; case 0xFF: this.AllLinkingAction = AllLinkingAction.LinkDeleted; break; default: throw new ArgumentOutOfRangeException("linkCode"); } this.PeerId = peerId; this.DeviceCategoryCode = deviceCategory; this.DeviceSubcategoryCode = deviceSubcategory; }
internal byte[] sendExtendedMessageAndWait4Response(DeviceId toAddress, byte flags, byte command1, byte command2) { sendExtendedMessage(toAddress, (byte)(flags | Constants.MSG_FLAGS_MAX_HOPS | Constants.MSG_FLAGS_EXTENDED), command1, command2); return(waitForSpecificMessageFrom(toAddress, MSG_TYPE_RECV_EXTENDED)); }
/// <summary> /// Sends the given standard command to the given address /// and returns true if the peer responded with an ACK. /// </summary> /// <param name="dottedHexId">Example: "12.34.56"</param> public bool SendStandardCommandToAddress(string dottedHexId, byte command1, byte command2) { var deviceId = new DeviceId(dottedHexId); return SendStandardCommandToAddress(deviceId, command1, command2); }
internal byte[] waitForStandardMessageFrom(DeviceId peerAddress) { return waitForSpecificMessageFrom(peerAddress, MSG_TYPE_RECV_STANDARD); }
internal StandardMessageReceivedArgs(DeviceId peerId, byte group, byte flags, byte command1, byte command2) { if (peerId == null) throw new ArgumentNullException("peerId"); this.PeerId = peerId; this.RawFlags = flags; this.Flags = new StandardMessageFlags(flags); this.MessageType = (StandardMessageType)(flags & 0xE0); this.Command1 = command1; this.Command2 = command2; switch (this.MessageType) { case StandardMessageType.GroupBroadcast: this.Group = group; break; case StandardMessageType.GroupCleanupDirect: this.Group = command2; break; default: this.Group = 0; break; } this.Description = string.Empty; String command2Description; switch (this.Command1) { case 0x10: this.Description = "Ping"; break; case 0x11: command2Description = string.Empty; if (this.MessageType != StandardMessageType.GroupCleanupDirect && command2 > 0) { command2Description = string.Format(" to level {0}", command2); } this.Description = "Turn On" + command2Description; break; case 0x12: command2Description = string.Empty; if (this.MessageType != StandardMessageType.GroupCleanupDirect && command2 > 0) { command2Description = string.Format(" to level {0}", command2); } this.Description = "Fast On" + command2Description; break; case 0x13: command2Description = string.Empty; if (this.MessageType != StandardMessageType.GroupCleanupDirect) { command2Description = string.Format(" to level {0}", command2); } this.Description = "Turn Off" + command2Description; break; case 0x14: command2Description = string.Empty; if (this.MessageType != StandardMessageType.GroupCleanupDirect) { command2Description = string.Format(" to level {0}", command2); } this.Description = "Fast Off" + command2Description; break; case 0x15: this.Description = "Brighten 1 Step"; break; case 0x16: this.Description = "Dim 1 Step"; break; case 0x17: if (command2 == 1) { this.Description = "Begin Manual Brightening"; } else { this.Description = "Begin Manual Dimming"; } break; case 0x18: this.Description = "End Manual Brightening/Dimming"; break; case 0x19: this.Description = "Status Request"; break; } }
internal byte[] sendExtendedMessageAndWait4Response(DeviceId toAddress, byte flags, byte command1, byte command2) { sendExtendedMessage(toAddress, (byte)(flags | Constants.MSG_FLAGS_MAX_HOPS | Constants.MSG_FLAGS_EXTENDED), command1, command2); return waitForSpecificMessageFrom(toAddress, MSG_TYPE_RECV_EXTENDED); }
internal byte[] waitForStandardMessageFrom(DeviceId peerAddress) { return(waitForSpecificMessageFrom(peerAddress, MSG_TYPE_RECV_STANDARD)); }
/// <summary> /// Sends the given standard command to the given address /// and returns true if the peer responded with an ACK. /// </summary> /// <param name="toAddress">Example: new DeviceId("12.34.56")</param> public bool SendStandardCommandToAddress(DeviceId toAddress, byte command1, byte command2) { byte[] rawResponse; return(SendStandardCommandToAddress(toAddress, command1, command2, out rawResponse)); }
/// <summary> /// Sends the given standard command to the given address /// and returns true if the peer responded with an ACK. /// </summary> /// <param name="dottedHexId">Example: "12.34.56"</param> public bool SendStandardCommandToAddress(string dottedHexId, byte command1, byte command2) { var deviceId = new DeviceId(dottedHexId); return(SendStandardCommandToAddress(deviceId, command1, command2)); }
/// <summary> /// Sends a message to the device with the given /// DeviceId in order to try to identify it, and /// if successful, returns a DeviceBase object. /// The derived type of the returned object varies /// depending on the Device category discovered /// during the identification process. /// </summary> /// <param name="dottedHexId">Example: "12.34.56"</param> /// <returns>null if unsuccessful - check plm.Exception</returns> public bool TryConnectToDevice(string dottedHexId, out DeviceBase device) { var peerId = new DeviceId(dottedHexId); return(TryConnectToDevice(peerId, out device)); }
internal void allLinkingCompleted(byte linkCode, byte group, DeviceId peerId, byte deviceCategory, byte deviceSubcategory) { fireAllLinkingCompletedEvent(linkCode, group, peerId, deviceCategory, deviceSubcategory); }
internal StandardMessageReceivedArgs(DeviceId peerId, byte group, byte flags, byte command1, byte command2) { if (peerId == null) { throw new ArgumentNullException("peerId"); } this.PeerId = peerId; this.RawFlags = flags; this.Flags = new StandardMessageFlags(flags); this.MessageType = (StandardMessageType)(flags & 0xE0); this.Command1 = command1; this.Command2 = command2; switch (this.MessageType) { case StandardMessageType.GroupBroadcast: this.Group = group; break; case StandardMessageType.GroupCleanupDirect: this.Group = command2; break; default: this.Group = 0; break; } this.Description = string.Empty; String command2Description; switch (this.Command1) { case 0x10: this.Description = "Ping"; break; case 0x11: command2Description = string.Empty; if (this.MessageType != StandardMessageType.GroupCleanupDirect && command2 > 0) { command2Description = string.Format(" to level {0}", command2); } this.Description = "Turn On" + command2Description; break; case 0x12: command2Description = string.Empty; if (this.MessageType != StandardMessageType.GroupCleanupDirect && command2 > 0) { command2Description = string.Format(" to level {0}", command2); } this.Description = "Fast On" + command2Description; break; case 0x13: command2Description = string.Empty; if (this.MessageType != StandardMessageType.GroupCleanupDirect) { command2Description = string.Format(" to level {0}", command2); } this.Description = "Turn Off" + command2Description; break; case 0x14: command2Description = string.Empty; if (this.MessageType != StandardMessageType.GroupCleanupDirect) { command2Description = string.Format(" to level {0}", command2); } this.Description = "Fast Off" + command2Description; break; case 0x15: this.Description = "Brighten 1 Step"; break; case 0x16: this.Description = "Dim 1 Step"; break; case 0x17: if (command2 == 1) { this.Description = "Begin Manual Brightening"; } else { this.Description = "Begin Manual Dimming"; } break; case 0x18: this.Description = "End Manual Brightening/Dimming"; break; case 0x19: this.Description = "Status Request"; break; } }
/// <summary> /// Sends the given standard command to the given address /// and returns true if the peer responded with an ACK. /// This overload returns the raw response data in case you need it. /// </summary> /// <param name="dottedHexId">Example: "12.34.56"</param> public bool SendStandardCommandToAddress(string dottedHexId, byte command1, byte command2, out byte[] rawResponse) { var deviceId = new DeviceId(dottedHexId); return(SendStandardCommandToAddress(deviceId, command1, command2, out rawResponse)); }
internal void standardMessageReceived(DeviceId peerId, byte group, byte flags, byte command1, byte command2) { fireStandardMessageReceivedEvent(peerId, group, flags, command1, command2); }
protected override void processIncomingMessage(byte[] message) { DeviceId peerId; byte group; if (message.Length < 2) return; switch (message[1]) { case 0x50: if (message.Length != 11) return; peerId = new DeviceId(message[2], message[3], message[4]); group = message[7]; byte flags = message[8]; byte command1 = message[9]; byte command2 = message[10]; this.network.standardMessageReceived(peerId, group, flags, command1, command2); break; case 0x52: if (message.Length != 4) return; this.network.X10.x10MessageReceived(message[2], message[3]); break; case 0x53: if (message.Length != 10) return; byte linkCode = message[2]; group = message[3]; peerId = new DeviceId(message[4], message[5], message[6]); byte deviceCategory = message[7]; byte deviceSubcategory = message[8]; this.network.allLinkingCompleted(linkCode, group, peerId, deviceCategory, deviceSubcategory); break; case 0x54: if (message.Length != 3) return; if (message[2] == 0x02) // set button pressed { this.setButton.setButtonTapped(); } else if (message[2] == 0x03) // set button pressed and held { this.setButton.setButtonPressedAndHeld(); } else if (message[2] == 0x04) // set button released after being held { this.setButton.setButtonReleasedAfterHolding(); } break; case 0x55: this.setButton.setButtonHeldDuringPowerUp(); break; } }
/// <summary> /// Sends the given standard command to the given address /// and returns true if the peer responded with an ACK. /// </summary> /// <param name="toAddress">Example: new DeviceId("12.34.56")</param> public bool SendStandardCommandToAddress(DeviceId toAddress, byte command1, byte command2) { bool result = false; this.plm.exceptionHandler(() => { byte[] responseAck = this.plm.sendStandardLengthMessageAndWait4Response( toAddress, Constants.MSG_FLAGS_DIRECT, command1, command2); byte flags = DeviceMessage.MessageFlags(responseAck); result = (flags & Constants.MSG_FLAGS_DIRECT_ACK) > 0; }); return result; }
internal byte[] sendStandardLengthMessageAndWait4Response(DeviceId toAddress, byte flags, byte command1, byte command2) { sendStandardLengthMessage(toAddress, (byte)(flags | Constants.MSG_FLAGS_MAX_HOPS), command1, command2); return(waitForStandardMessageFrom(toAddress)); }
/// <summary> /// Sends a message to the device with the given /// DeviceId in order to try to identify it, and /// if successful, returns a DeviceBase object. /// The derived type of the returned object varies /// depending on the Device category discovered /// during the identification process. /// </summary> /// <param name="dottedHexId">Example: "12.34.56"</param> /// <returns>null if unsuccessful - check plm.Exception</returns> public bool TryConnectToDevice(string dottedHexId, out DeviceBase device) { var peerId = new DeviceId(dottedHexId); return TryConnectToDevice(peerId, out device); }
internal byte[] waitForStandardMessageFrom(DeviceId peerAddress) { byte[] result = null; int tryCounter = 0; DeviceId originator; do { result = this.serialPortController.GetIncomingMessageOfType(MSG_TYPE_RECV_STANDARD); originator = DeviceMessage.DeviceMessageOriginator(result); if (originator != peerAddress) { queueReceivedMessage(result); result = null; tryCounter++; if (tryCounter > 3) { throw new TimeoutException("Timed out waiting for response from " + peerAddress.ToString()); } } } while (result == null); return result; }
internal byte[] sendStandardLengthMessageAndWait4Response(DeviceId toAddress, byte flags, byte command1, byte command2) { sendStandardLengthMessage(toAddress, (byte)(flags | Constants.MSG_FLAGS_MAX_HOPS), command1, command2); return waitForStandardMessageFrom(toAddress); }
/// <summary> /// Sends a message to the device with the given /// DeviceId in order to try to identify it, and /// if successful, returns a DeviceBase object. /// The derived type of the returned object varies /// depending on the Device category discovered /// during the identification process. /// </summary> /// <param name="dottedHexId">Example: new DeviceId("12.34.56")</param> /// <returns>null if unsuccessful - check plm.Exception</returns> public bool TryConnectToDevice(DeviceId deviceId, out DeviceBase device) { if(deviceId == null) throw new ArgumentNullException("deviceId"); DeviceBase result = null; if (this.deviceCache.ContainsKey(deviceId)) { result = this.deviceCache[deviceId]; } else { this.plm.exceptionHandler(() => { byte[] responseAck = this.plm.sendStandardLengthMessageAndWait4Response( deviceId, Constants.MSG_FLAGS_DIRECT, 0x10, 0x00); byte[] responseIdRequest = this.plm.waitForStandardMessageFrom(deviceId); result = DeviceFactory.BuildDevice(this.plm, responseIdRequest); }); if (result != null) { this.deviceCache.Add(deviceId, result); } } device = result; return result != null; }
public bool Equals(DeviceId otherId) { if ((object)otherId == null) return false; return otherId.ToString() == this.ToString(); }