porting.dox 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. @page mqtt_porting Porting Guide
  3. @brief Guide for porting MQTT to a new platform.
  4. A port to a new platform must provide the following components:
  5. 1. [Configuration Macros](@ref mqtt_porting_config)
  6. 2. [Transport Interface](@ref mqtt_porting_transport)
  7. 3. [Time Function](@ref mqtt_porting_time)
  8. @section mqtt_porting_config Configuration Macros
  9. @brief Settings that must be set as macros in the config header `core_mqtt_config.h`, or passed in as compiler options.
  10. @note If a custom configuration header `core_mqtt_config.h` is not provided, then the @ref MQTT_DO_NOT_USE_CUSTOM_CONFIG macro must be defined.
  11. @see [Configurations](@ref core_mqtt_config)
  12. The following macros can be configured for the managed MQTT library:
  13. - @ref MQTT_PINGRESP_TIMEOUT_MS <br>
  14. - @ref MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT
  15. In addition, the following logging macros are used throughout the library:
  16. - @ref LogError
  17. - @ref LogWarn
  18. - @ref LogInfo
  19. - @ref LogDebug
  20. @section mqtt_porting_transport Transport Interface
  21. @brief The MQTT library relies on an underlying transport interface API that must be implemented
  22. in order to send and receive packets on a network.
  23. @see [Transport Interface](@ref mqtt_transport_interface)
  24. The transport interface API used by MQTT is defined in @ref transport_interface.h.
  25. A port must implement functions corresponding to the following functions pointers:
  26. - [Transport Receive](@ref TransportRecv_t): A function to receive bytes from a network.
  27. @code
  28. int32_t (* TransportRecv_t )(
  29. NetworkContext_t * pNetworkContext, void * pBuffer, size_t bytesToRecv
  30. );
  31. @endcode
  32. - [Transport Send](@ref TransportSend_t): A function to send bytes over a network.
  33. @code
  34. int32_t (* TransportSend_t )(
  35. NetworkContext_t * pNetworkContext, const void * pBuffer, size_t bytesToSend
  36. );
  37. @endcode
  38. The above two functions take in a pointer to a @ref NetworkContext_t, the typename of a
  39. `struct NetworkContext`. The NetworkContext struct must also be defined by the port, and
  40. ought to contain any information necessary to send and receive data with the @ref TransportSend_t
  41. and @ref TransportRecv_t implementations, respectively:
  42. @code
  43. struct NetworkContext {
  44. // Fields necessary for the transport implementations, e.g. a TCP socket descriptor.
  45. };
  46. @endcode
  47. @section mqtt_porting_time Time Function
  48. @brief The MQTT library relies on a function to generate millisecond timestamps, for the
  49. purpose of calculating durations and timeouts, as well as maintaining the keep-alive mechanism
  50. of the MQTT protocol.
  51. @see @ref MQTTGetCurrentTimeFunc_t
  52. Platforms must supply a function capable of generating 32 bit timestamps of millisecond resolution.
  53. These timestamps need not correspond with any real world clock; the only requirement is that the
  54. difference between two timestamps must be an accurate representation of the duration between them,
  55. in milliseconds.
  56. @note Should the platform be incapable of providing millisecond timestamps, the port may instead
  57. provide a function that always returns 0, or a strictly non-decreasing sequence. In this case, the
  58. timeout values in all library calls to @ref MQTT_Connect, @ref MQTT_ProcessLoop, or @ref MQTT_ReceiveLoop
  59. MUST be set to 0, resulting in loop functions running for a single iteration, and @ref MQTT_Connect
  60. relying on @ref MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT to receive the CONNACK packet.
  61. */