public void Test_That_Command_Can_Be_Processed_When_Recieved_In_Multiple_Parts_From_The_Network() { //string referenceMessageData = "056438007922C4\r\n"; string referenceMessageData1 = "05643800"; string referenceMessageData2 = "7922C4\r\n"; var CBusAddressMap = new Protocol.CBusApplicationAddressMap(); CBusAddressMap.AddMapping(Protocol.CBusProtcol.ApplicationTypes.LIGHTING, 0x38); CBusAddressMap.AddMapping(Protocol.CBusProtcol.ApplicationTypes.TRIGGER, 0xCA); var cbusProtocol = new Protocol.CBusProtcol(128); var state = new Protocol.CBusProtcol.CBusStateMachine(); var data = referenceMessageData1.ToCharArray(); int dataIndex = 0; Assert.False( cbusProtocol.TryProcessReceivedBytes( data, data.Length, ref dataIndex, state ), "should not reuturn success when only partial command received" ); //Process another segment of data data = referenceMessageData2.ToCharArray(); dataIndex = 0; Assert.True( cbusProtocol.TryProcessReceivedBytes( data, data.Length, ref dataIndex, state ), "Failed to parse reference lighting command" ); var isMonitoredSAL = (state.MessageType == Protocol.CBusProtcol.CBusMessageType.MONITORED_SAL_MESSAGE_RECEIVED); Protocol.CBusSALCommand cmd; Assert.True( CBusAddressMap.TryParseCommand(state.CommandBytes, state.CommandLength, isMonitoredSAL, false, out cmd), "Failed to interpret reference lighting command" ); // Expected lighting Command Type Assert.Equal <Protocol.CBusProtcol.ApplicationTypes>( Protocol.CBusProtcol.ApplicationTypes.LIGHTING, cmd.ApplicationType); Console.WriteLine("Parsed Command:{0}", cmd); foreach (var c in ((Protocol.CBusLightingCommand)cmd).Commands()) { Console.WriteLine("Child Command: **{0}**", c); } }
public void Test_That_Reference_TriggerCommand_Can_Be_Parsed_And_The_Result_Interpreted_Correctly() { //Take from 'C-Bus Quick Start Guide.pdf' Page 7 var referenceMessageData = "05CA0002250109\r"; //var referenceMessageData = "0505CA00020000\r"; var CBusAddressMap = new Protocol.CBusApplicationAddressMap(); CBusAddressMap.AddMapping(Protocol.CBusProtcol.ApplicationTypes.LIGHTING, 0x38); CBusAddressMap.AddMapping(Protocol.CBusProtcol.ApplicationTypes.TRIGGER, 0xCA); var cbusProtocol = new Protocol.CBusProtcol(128); var state = new Protocol.CBusProtcol.CBusStateMachine(); var data = referenceMessageData.ToCharArray(); int dataIndex = 0; Assert.True( cbusProtocol.TryProcessReceivedBytes( data, data.Length, ref dataIndex, state ), "Failed to parse reference trigger command" ); var isMonitoredSAL = (state.MessageType == Protocol.CBusProtcol.CBusMessageType.MONITORED_SAL_MESSAGE_RECEIVED); Protocol.CBusSALCommand cmd; Assert.True( CBusAddressMap.TryParseCommand(state.CommandBytes, state.CommandLength, isMonitoredSAL, true, out cmd), "Failed to interpret reference trigger command" ); // Expected Trigger Command Type Assert.Equal( Protocol.CBusProtcol.ApplicationTypes.TRIGGER, cmd.ApplicationType); Console.WriteLine("Parsed Command:{0}", cmd); foreach (var c in ((Protocol.CBusTriggerCommand)cmd).Commands()) { Console.WriteLine("Child Command: **{0}**", c); } }
public void Test_That_Reference_LightingCommand_Can_Be_Interpreted_Correctly() { //Take from 'C-Bus Quick Start Guide.pdf' Page 7 byte[] referenceMessageData = { 0x05, 0x38, 0x00, 0x79, 0x88, 0xC2 }; var CBusAddressMap = new Protocol.CBusApplicationAddressMap(); CBusAddressMap.AddMapping(Protocol.CBusProtcol.ApplicationTypes.LIGHTING, 0x38); CBusAddressMap.AddMapping(Protocol.CBusProtcol.ApplicationTypes.TRIGGER, 0xCA); Protocol.CBusSALCommand cmd; Assert.True( CBusAddressMap.TryParseCommand(referenceMessageData, referenceMessageData.Length, false, false, out cmd), "Failed to interpret reference lighting command"); Assert.True( cmd.ApplicationType == Protocol.CBusProtcol.ApplicationTypes.LIGHTING, "Expected Lighting Command Type"); }
public void Test_That_Reference_TriggerCommand_Can_Be_Interpreted_Correctly() { Output.WriteLine("Taken from 'Trigger Control Application.pdf' Page 14"); // Taken from 'Trigger Control Application.pdf' Page 14 byte[] referenceMessageData = { 0x05, 0xCA, 0x00, 0x02, 0x25, 0x01, 0x09 }; var CBusAddressMap = new Protocol.CBusApplicationAddressMap(); CBusAddressMap.AddMapping(Protocol.CBusProtcol.ApplicationTypes.LIGHTING, 0x38); CBusAddressMap.AddMapping(Protocol.CBusProtcol.ApplicationTypes.TRIGGER, 0xCA); Protocol.CBusSALCommand cmd; Assert.True( CBusAddressMap.TryParseCommand(referenceMessageData, referenceMessageData.Length, false, false, out cmd), "Failed to interpret reference lighting command" ); Assert.True( cmd.ApplicationType == Protocol.CBusProtcol.ApplicationTypes.TRIGGER, "Expected Lighting Command Type" ); }
public void Test_That_Reference_LightingCommand_Can_Be_Parsed_And_The_Result_Interpreted_Correctly(string referenceMessageData) { //Take from 'C-Bus Quick Start Guide.pdf' Page 7 //var referenceMessageData = "0538007988C2\r"; //05 - Long Form Reply //03 - Unit/Bridge Address //38 - Application Address //00 - Network //SAL Data (02,47,3D,3D) //FD - Checksum //SAL Data //02 - Ramp Instant (Short Form) //47 - Group Address //3D - Level //var referenceMessageData = "0503380002473D3DFD\r"; var CBusAddressMap = new Protocol.CBusApplicationAddressMap(); CBusAddressMap.AddMapping(Protocol.CBusProtcol.ApplicationTypes.LIGHTING, 0x38); CBusAddressMap.AddMapping(Protocol.CBusProtcol.ApplicationTypes.TRIGGER, 0xCA); var cbusProtocol = new Protocol.CBusProtcol(128); //int rxDataPointer = 0; //int rxCommandLength; //byte[] CommandBytes; //Protocol.CBusProtcol.CBusMessageType rxMessageType; var state = new Protocol.CBusProtcol.CBusStateMachine(); var data = referenceMessageData.ToCharArray(); int dataIndex = 0; Assert.True( cbusProtocol.TryProcessReceivedBytes( data, data.Length, ref dataIndex, state ), "Failed to parse reference lighting command" ); var isMonitoredSAL = (state.MessageType == Protocol.CBusProtcol.CBusMessageType.MONITORED_SAL_MESSAGE_RECEIVED); Protocol.CBusSALCommand cmd; Assert.True( CBusAddressMap.TryParseCommand(state.CommandBytes, state.CommandLength, isMonitoredSAL, false, out cmd), "Failed to interpret reference lighting command" ); // Expected lighting Command Type Assert.Equal( Protocol.CBusProtcol.ApplicationTypes.LIGHTING, cmd.ApplicationType); Console.WriteLine("Parsed Command:{0}", cmd); foreach (var c in ((Protocol.CBusLightingCommand)cmd).Commands()) { Console.WriteLine("Child Command: **{0}**", c); } }