globalDef.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #include "globalDef.h"
  2. CurTick g_curTick; // 时间信息
  3. RunData g_runData; //运行数据
  4. FirmwareMsg g_firmwareMsg; // 网关 采集器固件信息存储
  5. ReadCollcmd g_readCmd83; // 上电第一次读取0x83指令时的状态
  6. ReadCollcmd g_readCmd58; // 读取58指令
  7. ReadCollcmd g_readCmd56; // 读取56指令
  8. dacommQueue g_commQueue;
  9. FirmwareExpl g_firmwareExpl; //固件信息版本格式
  10. Da4G g_data4G; // 4G模块连接情况
  11. LedStatus g_ledStatus; // led灯的情况
  12. char g_upLinkTopic[64] = {0};
  13. char g_logupLinkTopic[64] = {0};
  14. GunStatus g_checkGun[16];
  15. LoraCollMsg g_loraCollMsg;
  16. key_func_t key_info;
  17. timeout_t g_taxSendTime;
  18. timeout_t g_taxDataTime; // 报税器读取57指令时,86 89 中间要有的延时
  19. cmdInfo83 g_cmdInfo83;
  20. updateProg g_updateProg;
  21. EncodeOptDa g_encoderDa;
  22. MqttRunDa g_mqttRunDa;
  23. uint8_t g_bPrintfDebug = 0; // 0:不打印即不执行data_dump函数,1:执行
  24. LogCfigDa g_logCfigDa;
  25. uint8_t g_curSendCmd = 0;
  26. Sm4Key g_sm4Key; // 密钥
  27. /*时间信息初始化*/
  28. /*系统信息*/
  29. /*运行数据*/
  30. #define QUEUE_MAX 16
  31. void init_queue(cmdInfo83 *da)
  32. {
  33. da->front = 0;
  34. da->rear = 0;
  35. da->bread83 = 0;
  36. }
  37. uint8_t en_queue_cmd83(cmdInfo83 *da, uint32_t sn, uint8_t para,uint8_t taxNo, uint8_t flag)
  38. {
  39. if((da->rear+1)&QUEUE_MAX == da->front){
  40. printf("queue have no size\r\n");
  41. return 0;
  42. }
  43. da->da[da->rear%QUEUE_MAX].sn = sn;
  44. da->da[da->rear%QUEUE_MAX].para = para;
  45. da->da[da->rear&QUEUE_MAX].taxNo = taxNo;
  46. da->rear++;
  47. da->bread83 = 1;
  48. printf("queue size , = %d\r\n",da->rear);
  49. return 1;
  50. }
  51. uint8_t de_queue_cmd83(cmdInfo83 *inda,da83 *outda)
  52. {
  53. if(inda->front == (inda->rear%QUEUE_MAX)) return 0; // 队列为空
  54. outda->sn = inda->da[inda->front].sn;
  55. outda->para = inda->da[inda->front].para;
  56. outda->taxNo = inda->da[inda->front].taxNo;
  57. inda->front = (inda->front+1)%QUEUE_MAX;
  58. return 1;
  59. }
  60. /*-------------------------------------------------------------
  61. * 日志上报info 初始化
  62. * ------------------------------------------------------------*/
  63. void init_log_info(void)
  64. {
  65. g_logCfigDa.bEnable = 0;
  66. g_logCfigDa.settimer = 0;
  67. timeout_setValue(&g_logCfigDa.time,0);
  68. timeout_stop(&g_logCfigDa.time);
  69. timeout_setValue(&g_logCfigDa.time2,0);
  70. timeout_stop(&g_logCfigDa.time2);
  71. }
  72. /*-------------------------------------------------------------
  73. * sm4密钥
  74. * ------------------------------------------------------------*/
  75. void get_sm4_key(void)
  76. {
  77. g_sm4Key.keyda.flag[0] = 'W';
  78. g_sm4Key.keyda.flag[1] = 'B';
  79. g_sm4Key.keyda.flag[2] = 'J';
  80. g_sm4Key.keyda.flag[3] = 'W';
  81. g_sm4Key.keyda.flag[4] = 'Z';
  82. g_sm4Key.keyda.flag[5] = 'Z';
  83. g_sm4Key.keyda.flag[6] = '7';
  84. g_sm4Key.keyda.flag[7] = '6';
  85. g_sm4Key.keyda.flag[8] = '2';
  86. g_sm4Key.keyda.flag[9] = '9';
  87. g_sm4Key.keyda.flag[10] = '3';
  88. g_sm4Key.keyda.flag[11] = '7';
  89. g_sm4Key.keyda.sn = downlink_config.gateway_id;
  90. }
  91. void init_comm_queue(void)
  92. {
  93. uint8_t i = 0;
  94. g_commQueue.front = 0;
  95. g_commQueue.rear = 0;
  96. for(i = 0; i<COMM_QUEUE_SZIE;i++){
  97. memset(g_commQueue.data[i].da,0,64);
  98. g_commQueue.data[i].size = 0;
  99. }
  100. }
  101. uint8_t save_comme_queue(uint8_t type1, uint16_t type2,uint8_t *data,uint8_t size)
  102. {
  103. volatile uint8_t index = 0;
  104. if((g_commQueue.rear+1)&COMM_QUEUE_SZIE == g_commQueue.front){
  105. printf("queue have no size\r\n");
  106. return 0;
  107. }
  108. index = g_commQueue.rear%COMM_QUEUE_SZIE;
  109. memcpy((char*)g_commQueue.data[index].da,(char*)data,size);
  110. g_commQueue.data[index].type01 = type1;
  111. g_commQueue.data[index].type02 = type2;
  112. g_commQueue.data[index].size = size;
  113. g_commQueue.rear++;
  114. //data_dump("send111 0x01-0x1052:",data,size);
  115. printf("queue size = %d, save index = %d\r\n",g_commQueue.rear,index);
  116. return 1;
  117. }
  118. uint16_t read_comm_queue(uint8_t *type1, uint16_t *type2,uint8_t *outda)
  119. {
  120. volatile uint8_t index = 0;
  121. if(g_commQueue.front == (g_commQueue.rear%COMM_QUEUE_SZIE)) {
  122. g_commQueue.front = 0;
  123. g_commQueue.rear = 0;
  124. return 0; // 队列为空
  125. }
  126. index = g_commQueue.front;
  127. *type1 = g_commQueue.data[index].type01;
  128. *type2 = g_commQueue.data[index].type02;
  129. //printf("aaaaaaaaa data size = %d\r\n",g_commQueue.data[index].size);
  130. memcpy(outda,g_commQueue.data[index].da,g_commQueue.data[index].size);
  131. g_commQueue.front = (g_commQueue.front+1)%COMM_QUEUE_SZIE;
  132. return g_commQueue.data[index].size;
  133. }