RyanMqttTest.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef __RyanMqttTest__
  2. #define __RyanMqttTest__
  3. #ifdef __cplusplus
  4. extern "C"
  5. {
  6. #endif
  7. #include <stdio.h>
  8. #include <stdint.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <unistd.h>
  12. #include <semaphore.h>
  13. #include <pthread.h>
  14. #define rlogLevel (rlogLvlDebug) // 日志打印等级
  15. #include "RyanMqttLog.h"
  16. #include "RyanMqttClient.h"
  17. #define RyanMqttClientId ("RyanMqttTest888") // 填写mqtt客户端id,要求唯一
  18. // #define RyanMqttHost ("127.0.0.1") // 填写你的mqtt服务器ip
  19. #define RyanMqttHost ("localhost") // 填写你的mqtt服务器ip
  20. #define RyanMqttPort (1883) // mqtt服务器端口
  21. #define RyanMqttUserName ("test") // 填写你的用户名,没有填NULL
  22. #define RyanMqttPassword ("test") // 填写你的密码,没有填NULL
  23. #define delay(ms) usleep((ms) * 1000)
  24. #define getArraySize(arr) ((int32_t)(sizeof(arr) / sizeof((arr)[0])))
  25. #define checkMemory \
  26. do \
  27. { \
  28. int area = 0, use = 0; \
  29. v_mcheck(&area, &use); \
  30. if (area != 0 || use != 0) \
  31. { \
  32. rlog_e("内存泄漏"); \
  33. while (1) \
  34. { \
  35. int area = 0, use = 0; \
  36. v_mcheck(&area, &use); \
  37. rlog_w("|||----------->>> area = %d, size = %d", area, use); \
  38. delay(3000); \
  39. } \
  40. } \
  41. } while (0)
  42. // 定义枚举类型
  43. // 定义结构体类型
  44. /* extern variables-----------------------------------------------------------*/
  45. extern RyanMqttError_e RyanMqttInitSync(RyanMqttClient_t **client, RyanMqttBool_e syncFlag, RyanMqttEventHandle mqttEventCallback);
  46. extern RyanMqttError_e RyanMqttDestorySync(RyanMqttClient_t *client);
  47. extern void mqttEventBaseHandle(void *pclient, RyanMqttEventId_e event, const void *eventData);
  48. extern RyanMqttError_e checkAckList(RyanMqttClient_t *client);
  49. extern void printfArrStr(uint8_t *buf, uint32_t len, char *userData);
  50. extern RyanMqttError_e RyanMqttDestoryTest();
  51. extern RyanMqttError_e RyanMqttKeepAliveTest();
  52. extern RyanMqttError_e RyanMqttPubTest();
  53. extern RyanMqttError_e RyanMqttReconnectTest();
  54. extern RyanMqttError_e RyanMqttSubTest();
  55. #ifdef __cplusplus
  56. }
  57. #endif
  58. #endif