Browse Source

added addressing

stefan 9 months ago
parent
commit
35c24d6b3c

+ 3 - 1
doc/shellmatta_transport_layer.dox

@@ -64,7 +64,7 @@
     | 0x82 | Respond max buffersize         | 1              | Shellmattas buffersize |
     | 0x82 | Respond max buffersize         | 1              | Shellmattas buffersize |
     | 0x03 | Search device by unique ID     | 32             | UUID Range 2x 16 byte  |
     | 0x03 | Search device by unique ID     | 32             | UUID Range 2x 16 byte  |
     | 0x83 | Respond to search              | 16             | UUID of Shellmatta     |
     | 0x83 | Respond to search              | 16             | UUID of Shellmatta     |
-    | 0x04 | Set address                    | 16             | UUID of Shellmatta     |
+    | 0x04 | Set address                    | 16 + 1         | UUID + new address     |
     | 0x84 | Respond to set address         | 16             | UUID of Shellmatta     |
     | 0x84 | Respond to set address         | 16             | UUID of Shellmatta     |
 
 
 
 
@@ -103,6 +103,8 @@
 
 
     Every command comes with a source and destination address.
     Every command comes with a source and destination address.
     0 is the broadcast address an received everytime.
     0 is the broadcast address an received everytime.
+    1 is reserved for the MASTER/HOST. The Shellmatta will always send responses
+    to this address - no matter what the source of the telegram was.
 
 
     The packet response is sent to the source from the request packet.
     The packet response is sent to the source from the request packet.
 
 

+ 36 - 7
src/shellmatta_transport.c

@@ -38,8 +38,8 @@ static shellmatta_retCode_t shellmatta_transport_send(shellmatta_transport_layer
     /** -# fill header */
     /** -# fill header */
     header->startOfHeader   = SHELLMATTA_TRANSPORT_START_OF_HEADER;
     header->startOfHeader   = SHELLMATTA_TRANSPORT_START_OF_HEADER;
     header->protocolVersion = SHELLMATTA_TRANSPORT_PROTOCOL_VERSION;
     header->protocolVersion = SHELLMATTA_TRANSPORT_PROTOCOL_VERSION;
-    header->source          = 0;
-    header->destination     = 0;
+    header->source          = transportLayer->address;
+    header->destination     = SHELLMATTA_TRANSPORT_MASTER_ADDRESS;
     header->sequenceH2S     = transportLayer->sequenceH2S;
     header->sequenceH2S     = transportLayer->sequenceH2S;
     header->sequenceS2H     = ++transportLayer->sequenceS2H;
     header->sequenceS2H     = ++transportLayer->sequenceS2H;
 
 
@@ -221,7 +221,7 @@ shellmatta_retCode_t shellmatta_transport_process(shellmatta_transport_layer_t
     /** -# look for start of header */
     /** -# look for start of header */
     case SHELLMATTA_TRANSPORT_STATE_WAIT:
     case SHELLMATTA_TRANSPORT_STATE_WAIT:
         /** -# if start of header is found, continue transport layer fsm */
         /** -# if start of header is found, continue transport layer fsm */
-        if (SHELLMATTA_TRANSPORT_START_OF_HEADER == byte)
+        if(SHELLMATTA_TRANSPORT_START_OF_HEADER == byte)
         {
         {
             memset(&transportLayer->inPacket, 0, sizeof(transportLayer->inPacket));
             memset(&transportLayer->inPacket, 0, sizeof(transportLayer->inPacket));
             transportLayer->headerIndex = 1u;
             transportLayer->headerIndex = 1u;
@@ -254,10 +254,16 @@ shellmatta_retCode_t shellmatta_transport_process(shellmatta_transport_layer_t
         rawPacket[transportLayer->headerIndex] = byte;
         rawPacket[transportLayer->headerIndex] = byte;
         transportLayer->headerIndex ++;
         transportLayer->headerIndex ++;
 
 
-        if (transportLayer->headerIndex == SHELLMATTA_TRANSPORT_LENGTH_HEADER)
+        if(transportLayer->headerIndex == SHELLMATTA_TRANSPORT_LENGTH_HEADER)
         {
         {
-            //TODO check for errors in header data
-            if (0u != header->payloadLength)
+            /** -# check protocol version and addressing*/
+            if((SHELLMATTA_TRANSPORT_PROTOCOL_VERSION != header->protocolVersion) ||
+              ((SHELLMATTA_TRANSPORT_BROADCAST_ADDRESS != header->destination) &&
+              (transportLayer->address != header->destination)))
+            {
+                transportLayer->state = SHELLMATTA_TRANSPORT_STATE_WAIT;
+            }
+            else if(0u != header->payloadLength)
             {
             {
                 transportLayer->state = SHELLMATTA_TRANSPORT_STATE_GET_PAYLOAD;
                 transportLayer->state = SHELLMATTA_TRANSPORT_STATE_GET_PAYLOAD;
             }
             }
@@ -352,7 +358,30 @@ shellmatta_retCode_t shellmatta_transport_process(shellmatta_transport_layer_t
                     break;
                     break;
 
 
                 case SHELLMATTA_TRANSPORT_PACKET_SET_ADDRESS_REQUEST:
                 case SHELLMATTA_TRANSPORT_PACKET_SET_ADDRESS_REQUEST:
-                    /** @todo implement */
+
+                    /** -# use the passed address if the passed UUID matches our own */
+                    if((transportLayer->inPacket.header.payloadLength == SHELLMATTA_TRANPORT_UUID_LENGTH + 1u) &&
+                        0 == memcmp(transportLayer->uuid,
+                                   transportLayer->inPacket.payload,
+                                   SHELLMATTA_TRANPORT_UUID_LENGTH))
+                    {
+                        transportLayer->address = transportLayer->inPacket.payload[SHELLMATTA_TRANPORT_UUID_LENGTH];
+                        if(SHELLMATTA_TRANSPORT_MASTER_ADDRESS == transportLayer->address)
+                        {
+                            transportLayer->address = 0u;
+                        }
+                        else
+                        {
+                            /** -# respond to the address set command */
+                            intPacket.header.packetType = SHELLMATTA_TRANSPORT_PACKET_SET_ADDRESS_RESPOND;
+                            intPacket.header.payloadLength = SHELLMATTA_TRANPORT_UUID_LENGTH;
+                            (void)memcpy(intPacket.payload, transportLayer->uuid, SHELLMATTA_TRANPORT_UUID_LENGTH);
+                            (void)shellmatta_transport_send(transportLayer,
+                                                            (shellmatta_transport_packet_t *)&intPacket);
+                        }
+
+                    }
+                    
                     break;
                     break;
 
 
                 case SHELLMATTA_TRANSPORT_PACKET_SET_ADDRESS_RESPOND:
                 case SHELLMATTA_TRANSPORT_PACKET_SET_ADDRESS_RESPOND:

+ 4 - 0
src/shellmatta_transport.h

@@ -21,6 +21,10 @@
 #define SHELLMATTA_TRANSPORT_START_OF_HEADER    0x01u
 #define SHELLMATTA_TRANSPORT_START_OF_HEADER    0x01u
 /** @brief currently supported protocol version */
 /** @brief currently supported protocol version */
 #define SHELLMATTA_TRANSPORT_PROTOCOL_VERSION   0x01u
 #define SHELLMATTA_TRANSPORT_PROTOCOL_VERSION   0x01u
+/** @brief broadcast address */
+#define SHELLMATTA_TRANSPORT_BROADCAST_ADDRESS  0u
+/** @brief master address */
+#define SHELLMATTA_TRANSPORT_MASTER_ADDRESS     1u
 
 
 /* header field length defines */
 /* header field length defines */
 /** @brief length of header */
 /** @brief length of header */

+ 20 - 20
test/integrationtest_transport/test_integration_transport.cpp

@@ -161,11 +161,11 @@ SCENARIO("Integration test of Transport layer", "[integration, transport]")
                                                 "\x7b\x49\xfa\x72", 34u);
                                                 "\x7b\x49\xfa\x72", 34u);
             THEN("The shellmatta responds to the command")
             THEN("The shellmatta responds to the command")
             {
             {
-                char *dummyData =   (char*)"\x01\x01\x00\x2f\x00\x00\x01\x01"
+                char *dummyData =   (char*)"\x01\x01\x00\x2f\x00\x01\x01\x01"
                                            "doSomething argument - length: 20"
                                            "doSomething argument - length: 20"
                                            "\r\n"
                                            "\r\n"
                                            "shellmatta->"
                                            "shellmatta->"
-                                           "\xc8\xae\xc0\x56";
+                                           "\x4c\x9f\xd9\xa7";
 
 
                 CHECK(write_length == 59u);
                 CHECK(write_length == 59u);
                 REQUIRE(memcmp(write_data, dummyData, 59) == 0);
                 REQUIRE(memcmp(write_data, dummyData, 59) == 0);
@@ -184,21 +184,21 @@ SCENARIO("Integration test of Transport layer", "[integration, transport]")
                                                 "\xad\x33\x31\xcc", 26u);
                                                 "\xad\x33\x31\xcc", 26u);
             THEN("The shellmatta responds multiple telegrams")
             THEN("The shellmatta responds multiple telegrams")
             {
             {
-                char *dummyData =   (char*)"\x01\x01\x00\xff\x00\x00\x01\x01"
+                char *dummyData =   (char*)"\x01\x01\x00\xff\x00\x01\x01\x01"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very"
                                            "This is my very very very"
-                                           "\x0f\x90\xc0\xfd"
-                                           "\x01\x01\x00\x7f\x00\x00\x01\x02"
+                                           "\x00\x9c\x41\xe1"
+                                           "\x01\x01\x00\x7f\x00\x01\x01\x02"
                                            " very large payload\r\n"
                                            " very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "\r\n"
                                            "\r\n"
                                            "shellmatta->"
                                            "shellmatta->"
-                                           "\x00\xc9\x5d\x37";
+                                           "\x39\x75\x0d\x6b";
 
 
                 CHECK(write_length == 406u);
                 CHECK(write_length == 406u);
                 REQUIRE(memcmp(write_data, dummyData, 406u) == 0);
                 REQUIRE(memcmp(write_data, dummyData, 406u) == 0);
@@ -217,21 +217,21 @@ SCENARIO("Integration test of Transport layer", "[integration, transport]")
                                                 "\xad\x33\x31\xcc", 26u);
                                                 "\xad\x33\x31\xcc", 26u);
             THEN("The shellmatta responds multiple telegrams")
             THEN("The shellmatta responds multiple telegrams")
             {
             {
-                char *dummyData =   (char*)"\x01\x01\x00\xff\x00\x00\x01\x01"
+                char *dummyData =   (char*)"\x01\x01\x00\xff\x00\x01\x01\x01"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very"
                                            "This is my very very very"
-                                           "\x0f\x90\xc0\xfd"
-                                           "\x01\x01\x00\x7f\x00\x00\x01\x02"
+                                           "\x00\x9c\x41\xe1"
+                                           "\x01\x01\x00\x7f\x00\x01\x01\x02"
                                            " very large payload\r\n"
                                            " very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "This is my very very very very large payload\r\n"
                                            "\r\n"
                                            "\r\n"
                                            "shellmatta->"
                                            "shellmatta->"
-                                           "\x00\xc9\x5d\x37";
+                                           "\x39\x75\x0d\x6b";
 
 
                 CHECK(write_length == 406u);
                 CHECK(write_length == 406u);
                 REQUIRE(memcmp(write_data, dummyData, 406u) == 0);
                 REQUIRE(memcmp(write_data, dummyData, 406u) == 0);
@@ -248,11 +248,11 @@ SCENARIO("Integration test of Transport layer", "[integration, transport]")
             shellmatta_processData(handle, (char*)"doSomething argument\r\n", 22u);
             shellmatta_processData(handle, (char*)"doSomething argument\r\n", 22u);
             THEN("The shellmatta responds to the command")
             THEN("The shellmatta responds to the command")
             {
             {
-                char *dummyData =   (char*)"\x01\x01\x00\x2f\x00\x00\x01\x01"
+                char *dummyData =   (char*)"\x01\x01\x00\x2f\x00\x01\x01\x01"
                                            "doSomething argument - length: 20"
                                            "doSomething argument - length: 20"
                                            "\r\n"
                                            "\r\n"
                                            "shellmatta->"
                                            "shellmatta->"
-                                           "\xc8\xae\xc0\x56"
+                                           "\x4c\x9f\xd9\xa7"
                                            "doSomething argument - length: 20\r\n"
                                            "doSomething argument - length: 20\r\n"
                                            "shellmatta->";
                                            "shellmatta->";
 
 
@@ -280,11 +280,11 @@ SCENARIO("Integration test of Transport layer", "[integration, transport]")
                     THEN("The shellmatta returns the data")
                     THEN("The shellmatta returns the data")
                     {
                     {
 
 
-                        char *dummyData =   (char*)"\x01\x01\x00\x2f\x00\x00\x01\x01"
+                        char *dummyData =   (char*)"\x01\x01\x00\x2f\x00\x01\x01\x01"
                                                 "doSomething argument - length: 20"
                                                 "doSomething argument - length: 20"
                                                 "\r\n"
                                                 "\r\n"
                                                 "shellmatta->"
                                                 "shellmatta->"
-                                                "\xc8\xae\xc0\x56";
+                                                "\x4c\x9f\xd9\xa7";
 
 
                         CHECK(write_length == 59u);
                         CHECK(write_length == 59u);
                         REQUIRE(memcmp(write_data, dummyData, 59) == 0);
                         REQUIRE(memcmp(write_data, dummyData, 59) == 0);
@@ -300,8 +300,8 @@ SCENARIO("Integration test of Transport layer", "[integration, transport]")
                                                   "\xc4\xa3\x07\xe6", 12u);
                                                   "\xc4\xa3\x07\xe6", 12u);
             THEN("The valid Sequence counter is returned")
             THEN("The valid Sequence counter is returned")
             {
             {
-                char *dummyData =   (char*)"\x01\x01\x81\x00\x00\x00\x01\x01"
-                                           "\xb4\x0f\x12\xe9";
+                char *dummyData =   (char*)"\x01\x01\x81\x00\x00\x01\x01\x01"
+                                           "\xb5\xcd\x78\xde";
 
 
                 CHECK(write_length == 12);
                 CHECK(write_length == 12);
                 REQUIRE(memcmp(write_data, dummyData, 12) == 0);
                 REQUIRE(memcmp(write_data, dummyData, 12) == 0);
@@ -316,8 +316,8 @@ SCENARIO("Integration test of Transport layer", "[integration, transport]")
                                                       "\xc4\xa3\x07\xe6", 12u);
                                                       "\xc4\xa3\x07\xe6", 12u);
                 THEN("The next Sequence counter is returned")
                 THEN("The next Sequence counter is returned")
                 {
                 {
-                    char *dummyData =   (char*)"\x01\x01\x81\x00\x00\x00\x02\x02"
-                                               "\x06\x2b\x10\x90";
+                    char *dummyData =   (char*)"\x01\x01\x81\x00\x00\x01\x02\x02"
+                                               "\x07\xe9\x7a\xa7";
 
 
                     CHECK(write_length == 12);
                     CHECK(write_length == 12);
                     REQUIRE(memcmp(write_data, dummyData, 12) == 0);
                     REQUIRE(memcmp(write_data, dummyData, 12) == 0);
@@ -366,11 +366,11 @@ SCENARIO("Integration test of Transport layer with mandatory transport layer", "
                 shellmatta_processData(handle, (char*)"doSomething argument\r\n", 22u);
                 shellmatta_processData(handle, (char*)"doSomething argument\r\n", 22u);
                 THEN("The shellmatta responds only to the first command - and waits for a new telegram to start")
                 THEN("The shellmatta responds only to the first command - and waits for a new telegram to start")
                 {
                 {
-                    char *dummyData =   (char*)"\x01\x01\x00\x2f\x00\x00\x01\x01"
+                    char *dummyData =   (char*)"\x01\x01\x00\x2f\x00\x01\x01\x01"
                                             "doSomething argument - length: 20"
                                             "doSomething argument - length: 20"
                                             "\r\n"
                                             "\r\n"
                                             "shellmatta->"
                                             "shellmatta->"
-                                            "\xc8\xae\xc0\x56";
+                                            "\x4c\x9f\xd9\xa7";
 
 
                     CHECK(write_length == 59);
                     CHECK(write_length == 59);
                     CHECK(memcmp(write_data, dummyData, write_length) == 0);
                     CHECK(memcmp(write_data, dummyData, write_length) == 0);