main.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include "stm32f10x.h"
  5. #include "Timer.h"
  6. #include "OLED.h"
  7. #include "GPIOA.h"
  8. #include "Usart1.h"
  9. #include "Usart2.h"
  10. #include "Regist.h"
  11. #include "PumpBusiness.h"
  12. #include "CONFIG.h"
  13. #include "mbedtls_util.h"
  14. #include "Common_Util.h"
  15. #include "Timer_Module.h"
  16. #include "Log_Module.h"
  17. #include "Tuoreniot.h"
  18. #include "bc260y.h"
  19. #include "esp32.h"
  20. #include "At_Module.h"
  21. // 6365736869303036
  22. uint8_t mcu_id[8] = "ceshi007";
  23. // 计时器
  24. static struct TIMER_Struct timer;
  25. static uint8_t regist_flag = 0;
  26. char ch[30] = "11111111111111111111111111111";
  27. int main(void)
  28. {
  29. // uint8_t memmem_flag = 0;
  30. Timer_Init();//定时器
  31. Usart1_Init();//打印串口
  32. Usart2_Init();//4G模块通信
  33. GPIOA_Init();//4G模块DTR IO口
  34. OLED_Init();
  35. OLED_Clear();
  36. OLED_ShowString(1, 1, "MS:");
  37. Log_Printf_Debug("1234\r\n");
  38. bytesToHex(ch, mcu_id, sizeof(mcu_id));
  39. // 通讯流程初始化
  40. PUMPBUSINESS_Init();
  41. while(1)
  42. {
  43. // 循环执行udp客户端OLED_ShowNum
  44. OLED_ShowNum(1, 4, time_get_delay(&timer), 6);
  45. if(time_get_delay(&timer) > 60 * 1000)
  46. {
  47. time_clear(&timer);
  48. }
  49. // 注册接口使用方法
  50. if(regist_flag == 0)
  51. {
  52. if(TUORENIOT_GetCodeOfRegistResponse() != 200)
  53. {
  54. Log_Printf_Debug("开始注册\r\n");
  55. // 开始注册
  56. REGIST_Start();
  57. }
  58. else
  59. {
  60. Log_Printf_Debug("已注册\r\n");
  61. }
  62. regist_flag = 1;
  63. }
  64. //判断注册流程是否成功
  65. if(REGIST_GetStatus() == REGIST_Status_Done)
  66. {
  67. Log_Printf_Debug("注册结束\r\n");
  68. if(REGIST_GetResult() == REGIST_Result_Success)
  69. {
  70. Log_Printf_Debug("注册成功: %d\r\n", REGIST_GetResult());
  71. Network_Success_Flag = 1;
  72. }
  73. else if(REGIST_GetResult() == REGIST_Result_Failure)
  74. {
  75. Log_Printf_Debug("注册失败: %d\r\n", REGIST_GetResult());
  76. Network_Success_Flag = 0;
  77. }
  78. // 重置注册
  79. REGIST_Reset();
  80. }
  81. // 通讯流程处理
  82. PUMPBUSINESS_ProcessHandle();
  83. }
  84. }