agile_modbus_tcp.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * @file agile_modbus_tcp.h
  3. * @brief Agile Modbus package TCP header file
  4. * @author Ma Longwei (2544047213@qq.com)
  5. * @date 2021-12-02
  6. *
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2021 Ma Longwei.
  10. * All rights reserved.</center></h2>
  11. *
  12. */
  13. #ifndef __PKG_AGILE_MODBUS_TCP_H
  14. #define __PKG_AGILE_MODBUS_TCP_H
  15. #if AGILE_MODBUS_USING_TCP
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #include <stdint.h>
  20. /** @addtogroup TCP
  21. * @{
  22. */
  23. /** @defgroup TCP_Exported_Constants TCP Exported Constants
  24. * @{
  25. */
  26. #define AGILE_MODBUS_TCP_HEADER_LENGTH 7
  27. #define AGILE_MODBUS_TCP_PRESET_REQ_LENGTH 12
  28. #define AGILE_MODBUS_TCP_PRESET_RSP_LENGTH 8
  29. #define AGILE_MODBUS_TCP_CHECKSUM_LENGTH 0
  30. /**
  31. @verbatim
  32. Modbus_Application_Protocol_V1_1b.pdf Chapter 4 Section 1 Page 5
  33. TCP MODBUS ADU = 253 bytes + MBAP (7 bytes) = 260 bytes
  34. @endverbatim
  35. */
  36. #define AGILE_MODBUS_TCP_MAX_ADU_LENGTH 260
  37. /**
  38. * @}
  39. */
  40. /** @defgroup TCP_Exported_Types TCP Exported Types
  41. * @{
  42. */
  43. /**
  44. * @brief TCP structure
  45. */
  46. typedef struct agile_modbus_tcp {
  47. agile_modbus_t _ctx; /**< modbus handle */
  48. uint16_t t_id; /**< Extract from MODBUS Messaging on TCP/IP Implementation Guide V1.0b
  49. (page 23/46):
  50. The transaction identifier is used to associate the future response
  51. with the request. This identifier is unique on each TCP connection. */
  52. } agile_modbus_tcp_t;
  53. /**
  54. * @}
  55. */
  56. /** @addtogroup TCP_Exported_Functions
  57. * @{
  58. */
  59. int agile_modbus_tcp_init(agile_modbus_tcp_t *ctx, uint8_t *send_buf, int send_bufsz, uint8_t *read_buf, int read_bufsz);
  60. /**
  61. * @}
  62. */
  63. /**
  64. * @}
  65. */
  66. #ifdef __cplusplus
  67. }
  68. #endif
  69. #endif /* AGILE_MODBUS_USING_TCP */
  70. #endif /* __PKG_AGILE_MODBUS_TCP_H */