MBmsg.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef _MBMSG_H_
  2. #define _MBMSG_H_
  3. #include <stdint.h>
  4. // 下列 ifdef 块是创建使从 DLL 导出更简单的
  5. // 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 DUCP_EXPORTS
  6. // 符号编译的。在使用此 DLL 的
  7. // 任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将
  8. // DUCP_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的
  9. // 符号视为是被导出的。
  10. #ifdef DUCP_EXPORTS
  11. #define DUCP_API __declspec(dllexport)
  12. #else
  13. #define DUCP_API __declspec(dllimport)
  14. #endif
  15. #if defined(__cplusplus)
  16. extern "C" { /* Make sure we have C-declarations in C++ programs */
  17. #endif
  18. #define MB_STK_ADDR_DEF (0x00) /*默认的地址*/
  19. #define MB_STK_FC_DEF (100) /*默认的功能码*/
  20. #define MB_MSG_SIZE_MAX (255)
  21. /*
  22. 消息结构
  23. */
  24. typedef struct {
  25. uint8_t PN[2];
  26. uint8_t MsgId;
  27. uint8_t DLen;
  28. uint8_t Data[MB_MSG_SIZE_MAX];
  29. } MB_MSG_T;
  30. /*
  31. 消息接收完成回调函数类型
  32. */
  33. typedef int8_t (*cbMsgRdy_t)(MB_MSG_T *);
  34. typedef int8_t (*cbSTKOut_t)(uint8_t * p,uint32_t size);
  35. /*
  36. CRC16校验函数
  37. */
  38. EXTERN_C DUCP_API uint16_t MB_CRC16(uint8_t *pFrame, uint16_t count);
  39. /*
  40. 设置协议数据输出回调函数
  41. */
  42. EXTERN_C DUCP_API void MB_STK_SetOutCallback(cbSTKOut_t cb);
  43. /*
  44. 协议栈数据输入
  45. */
  46. EXTERN_C DUCP_API int8_t MB_STK_In(uint8_t * pBuff, uint16_t Size);
  47. /*
  48. 设置地址
  49. */
  50. EXTERN_C DUCP_API uint8_t MB_STK_SetAddr(uint8_t NewAddr);
  51. /*
  52. 设置消息就绪回调函数
  53. */
  54. EXTERN_C DUCP_API void MB_MSG_SetMsgRdyCallback(cbMsgRdy_t cb);
  55. /*
  56. 发送消息
  57. PN + MSGID + DLEN + DATA
  58. */
  59. EXTERN_C DUCP_API int8_t MB_MSG_Send(MB_MSG_T * pMsg, uint32_t Ovtime);
  60. /*
  61. 读消息
  62. PN + MSGID + DLEN + DATA
  63. */
  64. EXTERN_C DUCP_API int8_t MB_MSG_Read(MB_MSG_T * pMsg, uint32_t Ovtime);
  65. /*
  66. 读消息
  67. PN + MSGID + DLEN + DATA
  68. */
  69. EXTERN_C DUCP_API MB_MSG_T * MB_MSG_ReadEx(uint32_t Ovtime);
  70. #if defined(__cplusplus)
  71. }
  72. #endif
  73. #endif