mcb_test.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // +build ignore
  2. #include "mcu_ctrl_board.h"
  3. #include "../swapi/subjects/serial/serial.h"
  4. // 检查核心内存分配情况
  5. static char coreBuf[200*1024*1024] = { 0 };
  6. static void coreMemCheck(const char *filename, int line, const char *ptr, int size, void *lpParameter)
  7. {
  8. sw_log_info("filename:%s line:%d addr:%#p size:%dbytes", filename, line, ptr, size);
  9. }
  10. int RTU_IsInetAvailable()
  11. {
  12. return 0;
  13. }
  14. int RTU_IsSyncedNtpTime()
  15. {
  16. return 0;
  17. }
  18. int RTU_IsLoginMqServer()
  19. {
  20. return 0;
  21. }
  22. int RTU_SendGrpEnvData(SensorEnvData *pGroupData, int cnt)
  23. {
  24. return 0;
  25. }
  26. int RTU_SendOneEnvData(SensorEnvData *pOneData)
  27. {
  28. return 0;
  29. }
  30. int RTU_RequestTakePhoto()
  31. {
  32. return 0;
  33. }
  34. int RTU_LoadMCUParamsCfg()
  35. {
  36. return 0;
  37. }
  38. int RTU_NotifyPwrWillOff()
  39. {
  40. return 0;
  41. }
  42. // 主函数入口, 测试拍照
  43. int main(int argc,char *argv[])
  44. {
  45. if(!sw_heap_init(coreBuf, sizeof(coreBuf), 4)) goto end_p;
  46. int ret = MCBComInit();
  47. if(ret < 0)
  48. {
  49. sw_log_error("an error occurred while calling the MCBComInit() function(%d)!!", ret);
  50. goto end_p;
  51. }
  52. // 测试-查询状态位图
  53. uint8_t req1[] = { 0x7D, 0x01, 0x01, 0x01, 0xE0, 0x50, 0x7E };
  54. serial_write_recv_buffer(MCBGetSerialHandle(), req1, sizeof(req1));
  55. // 测试-发送环境数据
  56. uint8_t req2[] = { 0x7D, 0x01, 0x02, \
  57. 0x68, 0x78, 0x7B, 0x6D, 0x02, 0x0A, 0x01, 0x97, 0x00, 0x00, 0x00, 0x5A, 0x00, 0x27, \
  58. 0x68, 0x78, 0x7B, 0x77, 0x01, 0xC9, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x30, 0x00, 0x27, \
  59. 0x68, 0x78, 0x7B, 0x81, 0x02, 0xC4, 0x01, 0x1B, 0x00, 0x00, 0x00, 0x3A, 0x00, 0x27, \
  60. 0x68, 0x78, 0x7B, 0x8B, 0x02, 0xDB, 0x00, 0xA0, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x27, \
  61. 0x68, 0x78, 0x7B, 0x95, 0x01, 0x14, 0x02, 0xA6, 0x00, 0x00, 0x00, 0x03, 0x00, 0x22, \
  62. 0x68, 0x78, 0x7B, 0x9F, 0x01, 0x8C, 0x00, 0x1D, 0x00, 0x00, 0x00, 0x5A, 0x00, 0x22, \
  63. 0x68, 0x78, 0x7B, 0xA9, 0x00, 0xE5, 0x01, 0x3A, 0x00, 0x00, 0x00, 0x09, 0x00, 0x22, \
  64. 0x68, 0x78, 0x7B, 0xB3, 0x00, 0x88, 0x02, 0x9A, 0x00, 0x00, 0x00, 0x36, 0x00, 0x22, \
  65. 0x68, 0x78, 0x7B, 0xB6, 0x00, 0x88, 0x02, 0x9A, 0x00, 0x00, 0x00, 0x36, 0x00, 0x27, \
  66. 0x68, 0x78, 0x7C, 0x71, 0x00, 0x84, 0x01, 0xA6, 0x00, 0x00, 0x00, 0x01, 0x00, 0x27, \
  67. 0x68, 0x78, 0x7C, 0x7B, 0x01, 0x51, 0x01, 0xAB, 0x00, 0x00, 0x00, 0x11, 0x00, 0x22, \
  68. 0x68, 0x78, 0x7C, 0x80, 0x01, 0xC5, 0x01, 0x94, 0x00, 0x00, 0x00, 0x51, 0x00, 0x22, \
  69. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  70. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  71. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  72. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  73. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  74. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  75. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  76. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  77. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  78. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  79. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  80. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  81. 0x65, 0x1F, 0x7E };
  82. serial_write_recv_buffer(MCBGetSerialHandle(), req2, sizeof(req2));
  83. // 测试-查询主机对时
  84. uint8_t req3[] = { 0x7D, 0x01, 0x03, 0x68, 0x78, 0x7C, 0xA3, 0xB9, 0x0A, 0x7E };
  85. serial_write_recv_buffer(MCBGetSerialHandle(), req3, sizeof(req3));
  86. // 测试-同步运行参数
  87. uint8_t req4[] = { 0x7D, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x0A, 0x7E };
  88. serial_write_recv_buffer(MCBGetSerialHandle(), req4, sizeof(req4));
  89. getchar(); // 输入任意键退出
  90. end_p:
  91. MCBComExit();
  92. sw_log_info("Memory leak check:");
  93. sw_heap_check(coreMemCheck, NULL); // 内存泄露检查
  94. sw_heap_exit();
  95. return 0;
  96. }