shellmatta_transport_layer.dox 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**
  2. @page shellmatta_transport_layer Shellmatta Transport Layer
  3. To be able to use the shellmatta directly on an unsecured interface like
  4. raw UART a simple connectionless transport layer has been implemented.
  5. The transport layer is optional and can be removed during compile time as
  6. well as deactivated during runtime.
  7. To enable it during compile time add the define ``SHELLMATTA_TRANSPORT``.
  8. The transport layer intends to be used in machine to machine interfaces.
  9. @warning As the transport layer is connectionless there is no way to
  10. determine wether a packet is received properly.
  11. To check if all packets have been received by the shellmatta
  12. the sequence counters included in any packet can be used.
  13. The packet counter will be incremented on every packet which
  14. is received with a valid CRC and address.
  15. Unknown packets or packets with wrong payload lengths are
  16. ignored - but the sequence counter will still be incremented.
  17. @section shellmatta_transport_layer_sequence Basic sequence
  18. @startuml
  19. loop until command is sent
  20. Host -> Shellmatta: send packet
  21. Shellmatta -> Shellmatta: validate packet
  22. end
  23. loop until response is sent
  24. Shellmatta -> Host: send return packet
  25. Host -> Host: validate packet
  26. end
  27. @enduml
  28. @section shellmatta_transport_layer_protocol Protocol
  29. | Offset | Length | Description |
  30. |--------|---------------|---------------------------------------------|
  31. | 0 | 1 | Start of header (\\SOH) |
  32. | 1 | 1 | Protocol version |
  33. | 2 | 1 | Packet type |
  34. | 3 | 1 | Payload Length |
  35. | 4 | 1 | Source |
  36. | 5 | 1 | Destination |
  37. | 6 | 1 | Sequence counter host to shellmatta |
  38. | 7 | 1 | Sequence counter shellmatta to host |
  39. | 8 | L1 = 0 .. 255 | Payload |
  40. |8 + L1 | 4 | CRC32 of header + payload without CRC32 |
  41. @subsection shellmatta_transport_layer_protocol_packet_Types Packet types
  42. The type codes are divided into request and respond codes using the MSB.
  43. The MSB indicates a response.
  44. | type | Description | Payload length | Payload |
  45. |------|--------------------------------|----------------|------------------------|
  46. | 0x00 | Plain Data | 0 .. 255 | User data |
  47. | 0x01 | Request Sequence counters | 0 | - |
  48. | 0x81 | Respond Sequence counters | 0 | - |
  49. | 0x02 | Request and set max buffersize | 1 | Hosts buffersize |
  50. | 0x82 | Respond max buffersize | 1 | Shellmattas buffersize |
  51. | 0x03 | Search device by unique ID | 32 | UUID Range 2x 16 byte |
  52. | 0x83 | Respond to search | 16 | UUID of Shellmatta |
  53. | 0x04 | Set address | 16 + 1 | UUID + new address |
  54. | 0x84 | Respond to set address | 16 | UUID of Shellmatta |
  55. @section shellmatta_transport_layer_sequence_counters Sequence counters
  56. The sequence counters are included in the header of every packet to enable
  57. the host to check for any dropped packets.
  58. This is a quite nasty workaround as the host has no chance to determine
  59. which packet has been dropped - but better than nothing.
  60. If no response is received from the shellmatta the sequence counters can be
  61. requested explicitly.
  62. The sequence counter host to shellmatta will increment on every successfully
  63. received packet.
  64. The sequence counter shellmatta to host will increment on every packet the
  65. shellmatta sends to the host.
  66. @section shellmatta_transport_layer_buffersize Buffer sizes
  67. The shellmatta always uses the maximum buffersize of
  68. #SHELLMATTA_TRANPORT_PAYLOAD_MAXLENGTH.
  69. If the host has a smaller receive buffer this can be set using the 0x02
  70. packet.
  71. A host should use this packet to request the shellmatta buffersize.
  72. This can be changed in the future.
  73. @section shellmatta_transport_layer_addressing Addressing and Search
  74. The shellmatta comes with a primitive multidrop implementation to address
  75. and find multiple shellmatta transport layer enabled devices on a bus.
  76. Every command comes with a source and destination address.
  77. 0 is the broadcast address an received everytime.
  78. 1 is reserved for the MASTER/HOST. The Shellmatta will always send responses
  79. to this address - no matter what the source of the telegram was.
  80. The packet response is sent to the source from the request packet.
  81. To assign a new address to a shellmatta transport layer enabled device
  82. there is a possibility to search for devices on the bus.
  83. Every shellmatta which enables this feature requires a 16 byte UUID to be
  84. specified which is unique on the bus.
  85. The Host can then search for shellmatta nodes using a range of UUIDs
  86. using command 0x03.
  87. Every shellmatta instance within this range will respond.
  88. If more than one shellmatta is in the specified range this will lead to
  89. collisions on the bus. When the host detects collisions it shall repeat
  90. the search requests with different ranges until only one shellmatta
  91. responds.
  92. Once the host has found a single shellmatta in one range it can assign a
  93. unique address using command 0x04.
  94. The shellmatta can now be accessed using this address.
  95. @section shellmatta_transport_layer_crc CRC calculation
  96. The shellmatta transport layer uses the CRC32 algorithm to secure the
  97. transmission (0x04c11db7).
  98. By default the shellmatta crc implementation uses a lookup table to
  99. calculate the crc in a performant way.
  100. This uses quite a lot of read only memory on the device. If the memory
  101. consumption is an Issue you can switch to a slower implementation without
  102. the lookup table. This will increase CPU load quite a bit, but saves nearly
  103. 1K of read only memory.
  104. To enable the lookup table less CRC just define
  105. ``SHELLMATTA_TRANSPORT_CRC_NO_LOOKUP`` during compilation.
  106. @section shellmatta_transport_layer_control Controlling the transport layer
  107. @todo Not implemented yet
  108. */