12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #include "usart.h"
- #include "string.h"
- #include "ring_buffer.h"
- #include "mqttRecv.h"
- #include "main.h"
- #include "parseDeviceMessage.h"
- void Receive_MQTT_DataPack(void)
- {
- if (strstr((const char *)UART0_RX_BUF, "QMTRECV") != NULL)
- {
- UART0_RX_MQTT_SUB_STAT = 1;
- int i = 0;
- while (UART0_RX_BUF[i] != '{')
- {
- i++;
- }
- for (; i < strlen(UART0_RX_BUF); i++)
- {
- ring_buffer_write(UART0_RX_BUF[i], &mqttRecv);
- if (UART0_RX_BUF[i] == '}')
- {
- break;
- }
- }
- Clear_DMA_Buffer();
- }
- else if(strstr((const char *)UART0_RX_BUF, "QMTSTAT:")!=NULL)
- {
- NVIC_SystemReset();
- }
- }
- bool MQTT_BUFFER_READ(uint8_t *json)
- {
- static uint8_t json_len = 0;
- static uint8_t json_buf[128];
- uint8_t recv_data;
- bool found_json_end = false;
- bool json_start = false;
- while (ring_buffer_read(&recv_data, &mqttRecv) != -1)
- {
- if (recv_data == '{')
- {
- json_start = true;
- json_len = 0;
- }
-
- if (json_start)
- {
- json_buf[json_len++] = recv_data;
-
- if (recv_data == '}')
- {
- found_json_end = true;
-
- json_buf[json_len] = '\0';
- strcpy(json, (char *)json_buf);
-
- memset(json_buf, 0, sizeof(json_buf));
- json_len = 0;
- json_start = false;
- }
- }
- if (found_json_end)
- {
- break;
- }
- }
- return found_json_end;
- }
|