Пример #1
0
        public void Test_That_Reference_TriggerCommand_Can_Be_Parsed_Correctly()
        {
            // Taken from 'C-Bus Quick Start Guide.pdf' Page 7
            var referenceMessageData = "05CA0002250109\r";

            Output.WriteLine("Taken from 'C-Bus Quick Start Guide.pdf' Page 7: {0}", referenceMessageData);


            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 lighting command"
                );
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        public void Test_That_Reference_LightingCommand_Can_Be_Parsed_Correctly()
        {
            //Take from 'C-Bus Quick Start Guide.pdf' Page 7
            //var referenceMessageData = "0538007988C2\r";

            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);

            var _state = new Protocol.CBusProtcol.CBusStateMachine();
            //int rxDataPointer = 0;
            //int rxCommandLength;
            //byte[] CommandBytes;
            //Protocol.CBusProtcol.CBusMessageType rxMessageType;

            var data      = referenceMessageData.ToCharArray();
            int dataIndex = 0;

            Assert.True(
                cbusProtocol.TryProcessReceivedBytes(
                    data, data.Length,
                    ref dataIndex, _state
                    ),

                "Failed to parse reference lighting command"
                );
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        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);
            }
        }