protocol.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. #include "protocol.h"
  2. #include "stdint.h"
  3. #include "stdlib.h"
  4. #include "string.h"
  5. #include "node_message.h"
  6. #include "sys_mqtt.h"
  7. /*****************************protocol主要为主网关与子节点通讯的协议使用**********************************/
  8. /*****************************其主要作用主网关给子节点轮询发送数据的编码**********************************/
  9. /*****************************子节点解析该主网关发送的数据 **********************************/
  10. /*****************************子节点回应对应的响应 **********************************/
  11. /*****************************子节点回应对应的响应的解析 **********************************/
  12. static volatile int deviceNum = 0; // 记录轮询读取设备的结束位置
  13. static volatile int paramsNum = 0; // 记录轮询读取属性的结束位置
  14. static volatile int startDeviceNum = 0; // 记录轮询读取设备的开始位置
  15. static volatile int startParamsNum = 0; // 记录轮询读取设备属性的开始位置
  16. void insertHexData(uint8_t *String, const uint8_t *hexData, uint8_t insertIndex, uint8_t length);
  17. enum
  18. {
  19. protocol_dlt645_97 = 0x08,
  20. protocol_modbus_read,
  21. protocol_dlt645_07
  22. } PROTOCOL_LENGTH; // 每个协议的数据包长度用于最开始区分不同协议
  23. // 枚举采集数据的存储个数
  24. enum
  25. {
  26. typeInt = 1,
  27. typeFloat,
  28. typeDouble
  29. } DATAType;
  30. // 枚举MODBUS协议具体功能
  31. enum
  32. {
  33. READ_COIL = 0x01,
  34. WRITE_COIL = 0x05,
  35. WRITE_COILS = 0x0F,
  36. READ_REGISTER = 0x03,
  37. WRITE_REFISTER = 0x06,
  38. WRITE_REGISTERS = 0x10
  39. } MODBUS_COMMAND;
  40. // 大小端
  41. typedef enum
  42. {
  43. MModBus_16bitOrder_AB = 1, // 大端
  44. MModBus_16bitOrder_BA,
  45. } MModBus_16bitOrder_t;
  46. /*
  47. *********************************************************************************************************
  48. * 函 数 名: void masterSendNodeString(uint8_t nodeIndex)Index下标从0开始
  49. * 功能说明: 负责取出网关第nodeIndex下的数据组成下发格式的数据,注:此处没有对node是否为NULL进行判断,请确保有该节点的信息
  50. * 形 参:nodeIndex第几个节点数据、string所总成的传递的字符串、size组成的字符串大小
  51. * 返 回 值: 0:该节点下已经没有属性需要在去读出了,1:该节点下还拥有其他属性等待读出。
  52. 注:其一次性只能传输20条属性的值若超出其范围还有数据则要多次组成发送
  53. 逻辑:每次调用该函数都会总成一条string,属性足够的时候会组成一条具有20个属性的指令,并记录结束的设备链表位置,属性链表位置,下次再调用从结束位置再开始,到最后可能就组成不了20个属性的string了,此时将开始的设备num,属性都归位
  54. 且也要记录每次开始的设备位置和属性位置,方便接收应答信号的解析
  55. *********************************************************************************************************
  56. */
  57. int masterSendNodeString(uint8_t nodeIndex, uint8_t *string, uint16_t *size)
  58. {
  59. startDeviceNum = deviceNum; // 起始位置等于上次结束的位置
  60. startParamsNum = paramsNum; // 起始位置等于上次结束的位置
  61. int nowDeviceNum = deviceNum;
  62. int nowparamsNum = paramsNum;
  63. GATEWAY_PARAMS *gateway;
  64. gateway = get_gateway_config_params();
  65. // 将当前的节点指针指到需要读取的节点位置
  66. NODE_PARAMS *currentNode = gateway->node_params;
  67. while (nodeIndex)
  68. {
  69. currentNode = currentNode->nextNode;
  70. nodeIndex--;
  71. }
  72. memset(string, 0, 256); // 清除上一次数据
  73. // 将首字符用nodeAdress
  74. string[0] = currentNode->node_address[0];
  75. string[1] = currentNode->node_address[1];
  76. // 找到当前的设备结束位置
  77. DEVICE_PARAMS *currentDevice = currentNode->device_params;
  78. while (nowDeviceNum)
  79. {
  80. currentDevice = currentDevice->nextDevice;
  81. nowDeviceNum--;
  82. }
  83. // 移动位置到结束位置属性的下一位
  84. NODE_READ_MODBUS_COMMAND *currentModbusParams = currentDevice->params->node_read_modbus_command;
  85. NODE_READ_DLT645_COMMAND *currentDlt645Params = currentDevice->params->node_read_dlt645_command;
  86. switch (currentDevice->protocol)
  87. {
  88. case MODBUS:
  89. while (nowparamsNum)
  90. {
  91. currentModbusParams = currentModbusParams->nextParams;
  92. nowparamsNum--;
  93. }
  94. break;
  95. case DLT645_07:
  96. case DLT645_97:
  97. while (nowparamsNum)
  98. {
  99. currentDlt645Params = currentDlt645Params->nextParams;
  100. nowparamsNum--;
  101. }
  102. break;
  103. default:
  104. break;
  105. }
  106. // 最多进行20次循环组成下发数据
  107. int i = 0;
  108. int len;
  109. len = strlen(string);
  110. do
  111. {
  112. switch (currentDevice->protocol)
  113. {
  114. case MODBUS_READ:
  115. {
  116. uint8_t protocolHexData = protocol_modbus_read;
  117. insertHexData(string, &protocolHexData, len, 1); // 插入modbus长度
  118. len++;
  119. insertHexData(string, &currentModbusParams->functionCode, len, 1); // 插入读取功能码
  120. len++;
  121. insertHexData(string, &currentDevice->MDBdataType, len, 1); // 插入读取的数据格式
  122. len++;
  123. insertHexData(string, &currentModbusParams->slaveAddress, len, 1); // 插入modbus从站地址
  124. len++;
  125. insertHexData(string, (uint8_t *)&currentModbusParams->registerAddress, len, 2); // 插入modbus寄存器地址
  126. len += 2;
  127. insertHexData(string, &currentModbusParams->decimalPoint, len, 1); // 插入小数点位数
  128. len++;
  129. insertHexData(string, &currentDevice->MDBbigLittleFormat, len, 1); // 插入大小端
  130. len++;
  131. // 属性读取完毕,移位到下一个属性
  132. i++;
  133. currentModbusParams = currentModbusParams->nextParams;
  134. if (currentModbusParams == NULL)
  135. {
  136. currentDevice = currentDevice->nextDevice;
  137. if (currentModbusParams == NULL)
  138. {
  139. deviceNum = 0; // 将结束位置全部归0
  140. paramsNum = 0;
  141. *size = len;
  142. return 1;
  143. }
  144. currentModbusParams = currentDevice->params->node_read_modbus_command;
  145. nowDeviceNum++;
  146. nowparamsNum = 0;
  147. }
  148. break;
  149. }
  150. case DLT645_07:
  151. {
  152. uint8_t protocolHexData = protocol_dlt645_07;
  153. insertHexData(string, &protocolHexData, len, 1); // 插入dlt645_07数据长度
  154. len++;
  155. insertHexData(string, (uint8_t *)&currentDlt645Params->deviceID645, len, 6); // 插入dlt645地址域
  156. len += 6;
  157. insertHexData(string, (uint8_t *)&currentDlt645Params->Identification, len, 4);
  158. len += 4;
  159. // 属性读取完毕,移位到下一个属性
  160. i++;
  161. currentDlt645Params = currentDlt645Params->nextParams;
  162. if (currentDlt645Params == NULL)
  163. {
  164. currentDevice = currentDevice->nextDevice;
  165. if (currentDevice == NULL)
  166. {
  167. deviceNum = 0; // 将结束位置全部归0
  168. paramsNum = 0;
  169. *size = len;
  170. return 1;
  171. }
  172. currentDlt645Params = currentDevice->params->node_read_dlt645_command;
  173. nowDeviceNum++;
  174. nowparamsNum = 0;
  175. }
  176. break;
  177. }
  178. case DLT645_97:
  179. {
  180. uint8_t protocolHexData = protocol_dlt645_97;
  181. insertHexData(string, &protocolHexData, len, 1); // 插入dlt645_97数据长度
  182. len++;
  183. insertHexData(string, (uint8_t *)&currentDlt645Params->deviceID645, len, 6); // 插入dlt645_97地址域
  184. len += 6;
  185. insertHexData(string, (uint8_t *)&currentDlt645Params->Identification, len, 2); // 插入dlt645_97数据标识
  186. len += 2;
  187. // 属性读取完毕,移位到下一个属性
  188. i++;
  189. currentDlt645Params = currentDlt645Params->nextParams;
  190. if (currentDlt645Params == NULL)
  191. {
  192. currentDevice = currentDevice->nextDevice;
  193. if (currentDlt645Params == NULL)
  194. {
  195. deviceNum = 0; // 将结束位置全部归0
  196. paramsNum = 0;
  197. *size = len;
  198. return 1;
  199. }
  200. currentDlt645Params = currentDevice->params->node_read_dlt645_command; // 还有属性则更新位置
  201. nowDeviceNum++;
  202. nowparamsNum = 0;
  203. }
  204. break;
  205. }
  206. default:
  207. goto end_while;
  208. }
  209. nowparamsNum++;
  210. } while (i != 20);
  211. end_while:
  212. // 更新结束的位置分为两种情况,一种还在当前设备的属性中轮询此时nowDeviceNum没有改变过,另外一种情况设备内的属性
  213. if (nowDeviceNum == 0)
  214. {
  215. deviceNum = startDeviceNum;
  216. paramsNum = startParamsNum + nowparamsNum;
  217. }
  218. else
  219. {
  220. deviceNum = startDeviceNum + nowDeviceNum;
  221. paramsNum = nowparamsNum - 1;
  222. }
  223. *size = len;
  224. return 0;
  225. }
  226. /*
  227. *********************************************************************************************************
  228. * 函 数 名: void insertHexData(uint8_t *originalString,const uint8_t *hexData,int position)
  229. * 形 参:uint8_t *String需要插入的字符串,hexData插入的hex数据,insertIndex插入的下标位置,length插入的数据长度
  230. * 返 回 值: 无
  231. 注:插入的数据以被插入的字符串都可能包含0x00不要使用strlen
  232. *********************************************************************************************************
  233. */
  234. void insertHexData(uint8_t *String, const uint8_t *hexData, uint8_t insertIndex, uint8_t length)
  235. {
  236. memcpy(String + insertIndex, hexData, length);
  237. }
  238. /*
  239. *********************************************************************************************************
  240. * 函 数 名: uint8_t SlaveProtocolAnalysis(uint8_t *buff,uint16_t len)
  241. * 形 参:uint8_t *buff等待解析的字符串数据,
  242. * 返 回 值: 0:不是该节点的消息,数据没有进行任何处理。1:为该节点信息,接收到要进行的相应的切换工作
  243. 解析这段数据时要先判断是否为该节点的消息,stuct B *p=malloc(sizeof(struct B);
  244. *********************************************************************************************************
  245. */
  246. uint16_t LocalAddress=0x1F6E;
  247. uint8_t SlaveProtocolAnalysis(uint8_t *buff, uint16_t len)
  248. {
  249. NODE_DEVICE_PARAMS *node_receive_params;
  250. free_all_node_params();
  251. node_receive_params = get_node_receive_params();
  252. uint16_t slaveAdress = buff[0] << 8 | buff[1];
  253. int protocol_location = 2; // 起始的协议所处位置
  254. uint8_t i = 0;
  255. while (1)
  256. {
  257. if (slaveAdress == LocalAddress) // 判断此消息是否为该节点的消息,如果不是则跳出
  258. {
  259. switch (buff[protocol_location]) // 读取接收到的数据属于什么协议
  260. {
  261. case protocol_modbus_read:
  262. protocol_location++;
  263. node_receive_params->params[i].protcol = MODBUS_READ;
  264. node_receive_params->params[i].dlt645_params = NULL;
  265. node_receive_params->params[i].modbus_read = malloc(sizeof(NODE_MODBUS_READ));
  266. node_receive_params->params[i].modbus_write = NULL;
  267. node_receive_params->params[i].modbus_read->functionCode = buff[protocol_location + 1]; // 读出functionCode
  268. node_receive_params->params[i].modbus_read->dataType = buff[protocol_location + 2]; // 读出数据格式
  269. node_receive_params->params[i].modbus_read->slaveAddress = buff[protocol_location + 3]; // 读出从站地址
  270. node_receive_params->params[i].modbus_read->registerAddress = buff[protocol_location + 5] << 8 || buff[protocol_location + 4]; // 读出寄存器地址
  271. node_receive_params->params[i].modbus_read->registerLength = buff[protocol_location + 7] << 8 || buff[protocol_location + 6]; // 读出要读的寄存器长度
  272. node_receive_params->params[i].modbus_read->precision = buff[protocol_location + 8]; // 读出小数点精度
  273. node_receive_params->params[i].modbus_read->bigLittleFormat = buff[protocol_location + 9]; // 读出数据大小端格式
  274. protocol_location += protocol_modbus_read;
  275. break;
  276. case protocol_dlt645_07:
  277. protocol_location++;
  278. node_receive_params->params[i].protcol = DLT645_07;
  279. node_receive_params->params[i].dlt645_params = malloc(sizeof(NODE_DLT645_PARAMS));
  280. node_receive_params->params[i].modbus_read = NULL;
  281. node_receive_params->params[i].modbus_write = NULL;
  282. memcpy(node_receive_params->params[i].dlt645_params->deviceType645, buff + protocol_location, 6);
  283. memcpy((uint8_t *)&node_receive_params->params[i].dlt645_params->dataType645, buff + protocol_location + 6, 4);
  284. protocol_location += protocol_dlt645_07;
  285. break;
  286. case protocol_dlt645_97:
  287. protocol_location++;
  288. node_receive_params->params[i].protcol = DLT645_97;
  289. node_receive_params->params[i].dlt645_params = malloc(sizeof(NODE_DLT645_PARAMS));
  290. node_receive_params->params[i].modbus_read = NULL;
  291. node_receive_params->params[i].modbus_write = NULL;
  292. memcpy(node_receive_params->params[i].dlt645_params->deviceType645, buff + protocol_location, 6);
  293. memcpy((uint8_t *)&node_receive_params->params[i].dlt645_params->dataType645, buff + protocol_location + 6, 2);
  294. protocol_location += protocol_dlt645_97;
  295. break;
  296. default: // 解析没满20个属性
  297. return 1;
  298. }
  299. }
  300. else
  301. {
  302. node_receive_params->Index = i; // 记录本次有多少数据传输过来了
  303. return 0;
  304. }
  305. i++;
  306. if (protocol_location > len) // 判断数据解析是否越界了,越界则跳转出
  307. {
  308. return 1;
  309. }
  310. }
  311. }
  312. /*
  313. *********************************************************************************************************
  314. * 函 数 名: nodeSendReadValue(uint8_t *string)
  315. * 形 参:组成node回传数据,传输数据为
  316. * 返 回 值: 无
  317. *********************************************************************************************************
  318. */
  319. void nodeSendReaddValue(uint8_t *string,uint16_t *size)
  320. {
  321. NODE_DEVICE_PARAMS *node_receive_params;
  322. node_receive_params = get_node_receive_params();
  323. int i = 0;
  324. int len=0;
  325. //先加载node的地址node地址暂时本地写死后续加载
  326. string[len]= LocalAddress>>8;
  327. string[len+1]=LocalAddress;
  328. len+=2;
  329. while (i != 20)
  330. {
  331. switch (node_receive_params->params[i].protcol)
  332. {
  333. case DLT645_07:
  334. case DLT645_97:
  335. if (node_receive_params->params[i].dlt645_params->rxLen <= 4)
  336. {
  337. string[len] = 0x04;
  338. len++;
  339. memcpy(&string[len], node_receive_params->params[i].dlt645_params->value, 4);
  340. len += 4;
  341. }
  342. else if (node_receive_params->params[i].dlt645_params->rxLen == 5)
  343. {
  344. string[len] = 0x05;
  345. len++;
  346. memcpy(&string[len], node_receive_params->params[i].dlt645_params->value, 5);
  347. len += 5;
  348. }
  349. else if (node_receive_params->params[i].dlt645_params->rxLen == 9)
  350. {
  351. string[len] = 0x09;
  352. len++;
  353. memcpy(&string[len], node_receive_params->params[i].dlt645_params->value, 9);
  354. len += 9;
  355. }
  356. else
  357. {
  358. string[len] = 0x00;
  359. len++;
  360. }
  361. break;
  362. case MODBUS:
  363. if (node_receive_params->params[i].modbus_read->rxLen == 4)
  364. {
  365. string[len] = 0x04;
  366. len++;
  367. memcpy(&string[len], node_receive_params->params[i].dlt645_params->value, 4);
  368. len += 4;
  369. }
  370. else
  371. {
  372. string[len] = 0x00;
  373. len++;
  374. }
  375. break;
  376. default:
  377. *size=len;
  378. return;
  379. }
  380. i++;
  381. }
  382. *size=len;
  383. }
  384. /*
  385. *********************************************************************************************************
  386. * 函 数 名: GatewayProtocolAnalysis(uint8_t *string)
  387. * 形 参:将节点应答信息依次解析为json数据
  388. * 返 回 值: 0未读到json数据,1读到了json数据
  389. *********************************************************************************************************
  390. */
  391. int GatewayProtocolAnalysis(uint8_t *string, uint16_t len)
  392. {
  393. // 读取上次循环最终停止位置
  394. int nowDeviceNum = startDeviceNum;
  395. int nowparamsNum = startParamsNum;
  396. GATEWAY_PARAMS *gateway;
  397. gateway = get_gateway_config_params();
  398. uint16_t nodeId = string[0] << 8 | string[1];
  399. // 将当前的节点指针指到需要读取的节点位置
  400. NODE_PARAMS *currentNode = gateway->node_params;
  401. uint16_t currentNodeId = currentNode->node_address[0] << 8 | currentNode->node_address[1];
  402. while (currentNodeId != nodeId)
  403. {
  404. currentNode = currentNode->nextNode;
  405. if (currentNode == NULL)
  406. {
  407. // 没有找到对应该节点信息不是给本机
  408. return 0;
  409. }
  410. currentNodeId = currentNode->node_address[0] << 8 | currentNode->node_address[1];
  411. }
  412. // 找到该节点进行轮询
  413. DEVICE_PARAMS *currentDevice = currentNode->device_params;
  414. while (nowDeviceNum)
  415. {
  416. currentDevice = currentDevice->nextDevice;
  417. nowDeviceNum--;
  418. }
  419. // 移动位置到开始属性
  420. NODE_READ_MODBUS_COMMAND *currentModbusParams = currentDevice->params->node_read_modbus_command;
  421. NODE_READ_DLT645_COMMAND *currentDlt645Params = currentDevice->params->node_read_dlt645_command;
  422. switch (currentDevice->protocol)
  423. {
  424. case MODBUS:
  425. while (nowparamsNum)
  426. {
  427. currentModbusParams = currentModbusParams->nextParams;
  428. nowparamsNum--;
  429. }
  430. break;
  431. case DLT645_07:
  432. case DLT645_97:
  433. while (nowparamsNum)
  434. {
  435. currentDlt645Params = currentDlt645Params->nextParams;
  436. nowparamsNum--;
  437. }
  438. break;
  439. default:
  440. break;
  441. }
  442. memset(pubJsonString,0,jsonMaxSize);
  443. sprintf(pubJsonString, "{\"data\":[");
  444. int index = 2; // 子节点地址
  445. while (index <len)
  446. {
  447. switch (currentDevice->protocol)
  448. {
  449. case MODBUS:
  450. // modbus协议
  451. switch (*(string + index))
  452. {
  453. case 0x00:
  454. // 没有数据
  455. index++;
  456. break;
  457. case 0x04:
  458. if (currentDevice->MDBdataType == 0x01 && currentModbusParams->decimalPoint == 0x00) // modbus底层存储的数据类型 1INT 2float
  459. {
  460. uint32_t data;
  461. data = string[index + 1] + (string[index + 2] >> 8) + (string[index + 3] >> 16) + (string[index + 4] >> 24);
  462. sprintf(pubJsonString + strlen(pubJsonString), "{\"deviceId\":\"%s\",\"%s\":%d},", currentDevice->deviceID, currentModbusParams->keyword, data);
  463. }
  464. else // 如果是int且有小数点,或者底层就是float按照float来计算
  465. {
  466. float value;
  467. memcpy(&value,string+index+1,4);
  468. sprintf(pubJsonString + strlen(pubJsonString), "{\"deviceId\":\"%s\",\"%s\":%.2f},", currentDevice->deviceID,currentModbusParams->keyword,value);
  469. }
  470. index += 4;
  471. break;
  472. default:
  473. break;
  474. }
  475. currentModbusParams = currentModbusParams->nextParams;
  476. if (currentModbusParams == NULL)
  477. {
  478. currentDevice = currentDevice->nextDevice;
  479. if(currentDevice->protocol==MODBUS)
  480. {
  481. currentModbusParams=currentModbusParams->nextParams;
  482. }
  483. else
  484. {
  485. currentDlt645Params=currentDlt645Params->nextParams;
  486. }
  487. }
  488. break;
  489. case DLT645_07:
  490. case DLT645_97:
  491. switch (*(string + index))
  492. {
  493. case 0x00:
  494. index++;
  495. break;
  496. case 0x04:
  497. {
  498. index++;
  499. float value;
  500. memcpy(&value,string+index,sizeof(float));
  501. sprintf(pubJsonString + strlen(pubJsonString), "{\"deviceId\":\"%s\",\"%s\": %.2f},", currentDevice->deviceID, currentDlt645Params->keyword,value);
  502. index += 4;
  503. }
  504. break;
  505. case 0x05:
  506. {
  507. index++;
  508. //%02依次为年月日时分
  509. sprintf(pubJsonString + strlen(pubJsonString), "{\"deviceId\":\"%s\",\"%s\": \"%02X%02X%02X%02X%02X\"},",
  510. currentDevice->deviceID, currentDlt645Params->keyword, string[index + 4], string[index + 3], string[index + 2], string[index + 1], string[index]);
  511. index += 5;
  512. }
  513. break;
  514. case 9:
  515. {
  516. index++;
  517. float value;
  518. memcpy(&value, &string[index], 4);
  519. sprintf(pubJsonString + strlen(pubJsonString), "{\"deviceId\":\"%s\",\"%s\":\"%02X%02X%02X%02X%02X%.2f\"},",
  520. currentDevice->deviceID, currentDlt645Params->keyword, string[index + 8], string[index + 7], string[index + 6], string[index + 5], string[index + 4], value);
  521. index+=9;
  522. }
  523. break;
  524. default:
  525. break;
  526. }
  527. //移动到下个属性
  528. switch (currentDevice->protocol)
  529. {
  530. case DLT645_97:
  531. case DLT645_07:
  532. currentDlt645Params = currentDlt645Params->nextParams;
  533. if (currentDlt645Params == NULL)
  534. {
  535. currentDevice = currentDevice->nextDevice;
  536. currentDlt645Params=currentDevice->params->node_read_dlt645_command;
  537. }
  538. break;
  539. case MODBUS:
  540. currentModbusParams=currentModbusParams->nextParams;
  541. if(currentModbusParams==NULL)
  542. {
  543. currentDevice=currentDevice->nextDevice;
  544. currentDlt645Params=currentDevice->params->node_read_dlt645_command;
  545. }
  546. break;
  547. }
  548. break;
  549. default:
  550. break;
  551. }
  552. }
  553. if(strlen(pubJsonString)<10)
  554. {
  555. return 0;
  556. }
  557. sprintf(pubJsonString+strlen(pubJsonString)-1,"]}");
  558. //组装完成json数据开始向mqtt邮箱发送完成标识
  559. int msg = MBOX_USER_PUBLISHQOS2;
  560. if(mqtt_connectFlag==1) OSMboxPost(mqtt_sendMseeageMbox, &msg);
  561. return 1;
  562. }