shellmatta_transport_layer.dox 6.4 KB

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