2024-08-05 09:18:38 +00:00
|
|
|
|
#include "EC801E.h"
|
|
|
|
|
#include "stdio.h"
|
|
|
|
|
#include "usart.h"
|
|
|
|
|
#include "string.h"
|
|
|
|
|
#include "cJSON.h"
|
2024-08-06 07:33:33 +00:00
|
|
|
|
#include "uart_dev.h"
|
2024-08-06 09:07:23 +00:00
|
|
|
|
#include "anemometer_dev.h"
|
2024-08-05 09:18:38 +00:00
|
|
|
|
|
2024-08-07 09:26:49 +00:00
|
|
|
|
#define USE_UTC 1
|
|
|
|
|
|
2024-08-29 02:40:16 +00:00
|
|
|
|
// ID
|
|
|
|
|
uint8_t g_devic_id[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77};
|
2024-08-30 06:46:25 +00:00
|
|
|
|
// <20>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-09-07 02:14:42 +00:00
|
|
|
|
char g_cilent_name[] = "Test_cilent";
|
2024-08-30 06:46:25 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>
|
|
|
|
|
char g_cilent_user_name[] = "12345";
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
char g_cilent_paaword[] = "12345";
|
2024-08-29 09:52:48 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP
|
|
|
|
|
char g_server_ip[] = "199.7.140.10,1883";
|
2024-08-30 06:46:25 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-09-07 02:14:42 +00:00
|
|
|
|
char g_topic_name[] = "Test_Topic_1";
|
2024-08-29 09:52:48 +00:00
|
|
|
|
|
2024-08-20 08:43:35 +00:00
|
|
|
|
// ʱ<><CAB1><EFBFBD><EFBFBD>
|
2024-08-07 09:26:49 +00:00
|
|
|
|
uint32_t g_time_stamp;
|
2024-08-21 07:13:25 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
|
|
|
|
uint32_t trans_time_stamp;
|
2024-08-07 09:26:49 +00:00
|
|
|
|
|
2024-08-20 08:43:35 +00:00
|
|
|
|
// <20>ͻ<F2BFAABF><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
|
|
|
|
int flag_open_net = 0;
|
|
|
|
|
// <20><><EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
|
|
|
|
int flag_connect = 0;
|
|
|
|
|
// <20><><EFBFBD>ijɹ<C4B3><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
|
|
|
|
int flag_sub = 0;
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>־
|
|
|
|
|
int flag_pubex = 0;
|
|
|
|
|
|
2024-08-16 02:45:39 +00:00
|
|
|
|
void parse_json(uint8_t *json_buff);
|
|
|
|
|
|
|
|
|
|
|
2024-08-05 09:18:38 +00:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ϵ粢<CFB5><E7B2A2><EFBFBD><EFBFBD>
|
|
|
|
|
void EC801E_Power_ON()
|
|
|
|
|
{
|
|
|
|
|
// PWR_KEY_4G_Pin<69>͵<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>ϵ<EFBFBD><CFB5>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
HAL_GPIO_WritePin(GPIO_4G_PWR_KEY_GPIO_Port, GPIO_4G_PWR_KEY_Pin, GPIO_PIN_SET);
|
|
|
|
|
//<2F>ϵ<EFBFBD>
|
2024-08-21 03:31:27 +00:00
|
|
|
|
HAL_GPIO_WritePin(GPIO_4G_PWR_CTRL_GPIO_Port, GPIO_4G_PWR_CTRL_Pin, GPIO_PIN_RESET);
|
|
|
|
|
HAL_Delay(1000);
|
2024-08-05 09:18:38 +00:00
|
|
|
|
HAL_GPIO_WritePin(GPIO_4G_PWR_CTRL_GPIO_Port, GPIO_4G_PWR_CTRL_Pin, GPIO_PIN_SET);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
|
|
|
|
|
//HAL_OK:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
uint8_t Read_Status()
|
|
|
|
|
{
|
|
|
|
|
uint8_t temp_status = HAL_ERROR;
|
|
|
|
|
temp_status = HAL_GPIO_ReadPin(GPIO_4G_STATUS_GPIO_Port, GPIO_4G_STATUS_Pin) == GPIO_PIN_SET ? HAL_OK : HAL_ERROR;
|
|
|
|
|
return temp_status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD>ӡ
|
|
|
|
|
size_t __write(int handle, const unsigned char * buffer, size_t size)
|
|
|
|
|
{
|
|
|
|
|
if(HAL_OK == HAL_UART_Transmit(&huart1,(uint8_t *)buffer,size,100000))
|
|
|
|
|
{
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MQTT<54>ͻ<F2BFAABF><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.<2E><><EFBFBD><EFBFBD>MQTT<54><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.<2E><><EFBFBD><EFBFBD>
|
2024-08-19 02:05:25 +00:00
|
|
|
|
// ip,<2C>˿ڣ<CBBF><DAA3>ͻ<EFBFBD><CDBB><EFBFBD>ID(0-5)<29><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><C6A3>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룬<EFBFBD><EBA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-08-05 09:18:38 +00:00
|
|
|
|
void MQTT_Config()
|
|
|
|
|
{
|
|
|
|
|
// ȷ<><C8B7>4Gģ<47><C4A3><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>
|
2024-08-06 07:33:33 +00:00
|
|
|
|
osDelay(5000);
|
2024-08-19 02:05:25 +00:00
|
|
|
|
|
2024-08-05 09:18:38 +00:00
|
|
|
|
// <20>ͻ<F2BFAABF><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-08-20 08:43:35 +00:00
|
|
|
|
while(!flag_open_net)
|
|
|
|
|
{
|
2024-08-29 09:52:48 +00:00
|
|
|
|
// uart_sendstr(g_ec801_uart_handle, "AT+QMTOPEN=0,199.7.140.10,1883\r\n");
|
|
|
|
|
uart_sendstr(g_ec801_uart_handle, "AT+QMTOPEN=0,");
|
|
|
|
|
uart_sendstr(g_ec801_uart_handle, g_server_ip);
|
|
|
|
|
uart_sendstr(g_ec801_uart_handle, "\r\n");
|
2024-08-06 07:33:33 +00:00
|
|
|
|
osDelay(5000);
|
2024-08-20 08:43:35 +00:00
|
|
|
|
}flag_open_net = 0;
|
2024-08-19 02:05:25 +00:00
|
|
|
|
|
2024-08-05 09:18:38 +00:00
|
|
|
|
// <20><><EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD><EFBFBD><EFBFBD>
|
2024-08-20 08:43:35 +00:00
|
|
|
|
while(!flag_connect)
|
|
|
|
|
{
|
2024-08-30 06:46:25 +00:00
|
|
|
|
uart_sendstr(g_ec801_uart_handle, "AT+QMTCONN=0,");
|
|
|
|
|
uart_sendstr(g_ec801_uart_handle, g_cilent_name);
|
|
|
|
|
uart_sendstr(g_ec801_uart_handle, ",");
|
|
|
|
|
uart_sendstr(g_ec801_uart_handle, g_cilent_user_name);
|
|
|
|
|
uart_sendstr(g_ec801_uart_handle, ",");
|
|
|
|
|
uart_sendstr(g_ec801_uart_handle, g_cilent_paaword);
|
|
|
|
|
uart_sendstr(g_ec801_uart_handle, "\r\n");
|
2024-08-06 07:33:33 +00:00
|
|
|
|
osDelay(5000);
|
2024-08-20 08:43:35 +00:00
|
|
|
|
}flag_connect = 0;
|
2024-08-19 02:05:25 +00:00
|
|
|
|
|
2024-08-05 09:18:38 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-08-20 08:43:35 +00:00
|
|
|
|
while(!flag_sub)
|
|
|
|
|
{
|
2024-08-30 06:46:25 +00:00
|
|
|
|
uart_sendstr(g_ec801_uart_handle, "AT+QMTSUB=0,0,");
|
|
|
|
|
uart_sendstr(g_ec801_uart_handle, g_topic_name);
|
|
|
|
|
uart_sendstr(g_ec801_uart_handle, ",0\r\n");
|
2024-08-20 08:43:35 +00:00
|
|
|
|
osDelay(5000);
|
|
|
|
|
}flag_sub = 0;
|
2024-08-05 09:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-21 03:31:27 +00:00
|
|
|
|
void EC801_start()
|
|
|
|
|
{
|
|
|
|
|
EC801E_Power_ON();
|
|
|
|
|
osDelay(5000);
|
|
|
|
|
while(!EC801_GET_Time());
|
|
|
|
|
MQTT_Config();
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-07 09:26:49 +00:00
|
|
|
|
// MQTT<54><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-08-19 02:05:25 +00:00
|
|
|
|
void MQTT_Trans_Data()
|
2024-08-05 09:18:38 +00:00
|
|
|
|
{
|
2024-08-07 09:26:49 +00:00
|
|
|
|
//<2F>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
uint8_t str_len = 0;
|
|
|
|
|
char str_len_str[32];
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
2024-08-06 09:07:23 +00:00
|
|
|
|
float32_t *ptr = (float32_t *)&g_stMcs_Para;
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>JSON<4F><4E><EFBFBD>鼰<EFBFBD><E9BCB0><EFBFBD><EFBFBD>
|
2024-08-05 09:18:38 +00:00
|
|
|
|
char *cjson_str = NULL;
|
|
|
|
|
cJSON * JsonRoot = cJSON_CreateObject();
|
2024-08-06 09:07:23 +00:00
|
|
|
|
cJSON * DataArray = cJSON_CreateArray();
|
2024-08-05 09:18:38 +00:00
|
|
|
|
|
2024-08-29 02:40:16 +00:00
|
|
|
|
//<2F><>uint8<74><38>ID<49>浽<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
char deviId_str[15];
|
|
|
|
|
snprintf(deviId_str, sizeof(deviId_str), "%X%X%X%X%X%X%X", g_devic_id[0], \
|
|
|
|
|
g_devic_id[1], \
|
|
|
|
|
g_devic_id[2], \
|
|
|
|
|
g_devic_id[3], \
|
|
|
|
|
g_devic_id[4], \
|
|
|
|
|
g_devic_id[5], \
|
|
|
|
|
g_devic_id[6]);
|
|
|
|
|
|
2024-08-21 07:13:25 +00:00
|
|
|
|
trans_time_stamp = g_time_stamp;// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱʱ<CAB1><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>ʱ<EFBFBD><CAB1>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
2024-08-29 02:40:16 +00:00
|
|
|
|
|
|
|
|
|
cJSON_AddStringToObject(JsonRoot, "deviId", deviId_str);
|
2024-08-07 09:26:49 +00:00
|
|
|
|
cJSON_AddStringToObject(JsonRoot, "frameType", "item_type");
|
|
|
|
|
cJSON_AddNumberToObject(JsonRoot, "timeStamp", g_time_stamp);
|
2024-08-15 01:06:11 +00:00
|
|
|
|
cJSON_AddNumberToObject(JsonRoot, "version", 10);
|
2024-08-05 09:18:38 +00:00
|
|
|
|
|
2024-08-06 09:07:23 +00:00
|
|
|
|
cJSON_AddItemToObject(JsonRoot, "data", DataArray);//<2F><><EFBFBD><EFBFBD>data<74><61><EFBFBD><EFBFBD>
|
|
|
|
|
|
2024-08-08 02:59:28 +00:00
|
|
|
|
for(int i = 0; i < sizeof(mcs_para)/sizeof(float32_t) - 2; i++)// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>仹<EFBFBD>ǿ<EFBFBD><C7BF><EFBFBD>
|
2024-08-06 09:07:23 +00:00
|
|
|
|
{
|
2024-08-08 02:59:28 +00:00
|
|
|
|
cJSON_AddItemToArray(DataArray, cJSON_CreateNumber(((float)((int )(ptr[i] * 100 + 0.5)))/100.0));// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λС<CEBB><D0A1>
|
2024-08-06 09:07:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-07 09:26:49 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>ת<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
2024-08-05 09:18:38 +00:00
|
|
|
|
cjson_str = cJSON_Print(JsonRoot);
|
2024-08-07 09:26:49 +00:00
|
|
|
|
|
2024-08-08 02:59:28 +00:00
|
|
|
|
str_len = strlen(cjson_str) + 2 + 4;
|
2024-08-07 09:26:49 +00:00
|
|
|
|
sprintf(str_len_str, "%d", str_len);
|
|
|
|
|
|
2024-08-21 03:31:27 +00:00
|
|
|
|
while(!flag_pubex)
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD>
|
2024-08-30 06:46:25 +00:00
|
|
|
|
uart_sendstr(g_ec801_uart_handle, "AT+QMTPUBEX=0,0,0,0,");
|
|
|
|
|
uart_sendstr(g_ec801_uart_handle, g_topic_name);
|
|
|
|
|
uart_sendstr(g_ec801_uart_handle, ",");
|
2024-08-21 03:31:27 +00:00
|
|
|
|
uart_sendstr(g_ec801_uart_handle, str_len_str);
|
|
|
|
|
uart_sendstr(g_ec801_uart_handle, "\r\n");
|
2024-08-07 09:26:49 +00:00
|
|
|
|
|
2024-08-21 03:31:27 +00:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>
|
|
|
|
|
osDelay(2000);
|
|
|
|
|
uart_sendstr(g_ec801_uart_handle, cjson_str);
|
|
|
|
|
HAL_Delay(3000);
|
|
|
|
|
}flag_pubex = 0;
|
2024-09-07 02:14:42 +00:00
|
|
|
|
|
2024-08-07 09:26:49 +00:00
|
|
|
|
//<2F>ͷ<EFBFBD>
|
|
|
|
|
vPortFree(cjson_str);
|
2024-08-05 09:18:38 +00:00
|
|
|
|
cJSON_Delete(JsonRoot);
|
2024-08-06 09:07:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-07 09:26:49 +00:00
|
|
|
|
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>꣬1<EAA3AC><31>0ƽ
|
|
|
|
|
uint16_t fml_leap_year(uint16_t year)
|
2024-08-06 09:07:23 +00:00
|
|
|
|
{
|
2024-08-07 09:26:49 +00:00
|
|
|
|
return (((year % 4 == 0)&&(year % 100 != 0)) || (year % 400 == 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>תʱ<D7AA><CAB1><EFBFBD><EFBFBD>
|
|
|
|
|
uint32_t fml_time_to_stamp(int year, int month, int day, int hour, int minute, int second)
|
|
|
|
|
{
|
|
|
|
|
static uint32_t dax = 0;
|
|
|
|
|
static uint32_t day_count = 0;
|
|
|
|
|
uint16_t leap_year_count = 0;
|
|
|
|
|
uint16_t i;
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
for (i = 1970; i < year; i++)
|
|
|
|
|
{
|
|
|
|
|
if (fml_leap_year(i))
|
|
|
|
|
{
|
|
|
|
|
leap_year_count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
day_count = leap_year_count * 366 + (year - 1970 - leap_year_count) * 365;
|
|
|
|
|
|
|
|
|
|
uint8_t mouthday[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
|
|
|
|
// <20><><EFBFBD>㵱<EFBFBD>굽<EFBFBD><EAB5BD>ǰ<EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
for (i = 1; i < month; i++)
|
|
|
|
|
{
|
|
|
|
|
day_count += mouthday[i];
|
|
|
|
|
}
|
|
|
|
|
if(fml_leap_year(year))
|
|
|
|
|
{
|
|
|
|
|
day_count += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20>ۼӼ<DBBC><D3BC>㵱<EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
day_count += (day - 1);
|
|
|
|
|
|
|
|
|
|
dax = (uint32_t)(day_count * 86400) + (uint32_t)((uint32_t)hour * 3600) + (uint32_t)((uint32_t)minute * 60) + (uint32_t)second;
|
|
|
|
|
|
|
|
|
|
return dax;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-08-15 08:35:33 +00:00
|
|
|
|
//ʱ<><CAB1><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ɱ<EFBFBD><C9B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ʼMQTT<54><54>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
|
|
|
|
uint8_t time_get_ok = 0;
|
2024-08-07 09:26:49 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
2024-08-15 08:35:33 +00:00
|
|
|
|
int EC801_GET_Time()
|
2024-08-07 09:26:49 +00:00
|
|
|
|
{
|
|
|
|
|
int year, month, day, hour, minute, second;
|
|
|
|
|
if(USE_UTC)
|
|
|
|
|
{
|
|
|
|
|
uart_sendstr(g_ec801_uart_handle, "AT+QLTS=0\r\n");
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
uart_sendstr(g_ec801_uart_handle, "AT+QLTS=2\r\n");
|
|
|
|
|
}
|
|
|
|
|
osDelay(1000);
|
|
|
|
|
char time[100] = {0};int index = 0;
|
|
|
|
|
|
|
|
|
|
// <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>䣬ǰ<E4A3AC>治Ҫ
|
|
|
|
|
do{
|
|
|
|
|
time[index] = uart_dev_in_char(g_ec801_uart_handle);
|
2024-08-15 08:35:33 +00:00
|
|
|
|
}while(time[index++] != '"' && uart_dev_char_present(g_ec801_uart_handle));
|
2024-08-07 09:26:49 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
|
|
|
|
memcpy(time, time + index - 1, index);
|
|
|
|
|
index = 1;
|
|
|
|
|
|
|
|
|
|
// "ǰ<><C7B0><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
|
|
do{
|
|
|
|
|
time[index] = uart_dev_in_char(g_ec801_uart_handle);
|
2024-08-15 08:35:33 +00:00
|
|
|
|
}while(time[index++] != '"' && uart_dev_char_present(g_ec801_uart_handle));
|
2024-08-07 09:26:49 +00:00
|
|
|
|
|
|
|
|
|
// <20>ַ<EFBFBD><D6B7><EFBFBD>ȡ<EFBFBD><C8A1>int
|
2024-08-15 08:35:33 +00:00
|
|
|
|
sscanf(time, "\"%d/%d/%d,%d:%d:%d\"", &year, &month, &day, &hour, &minute, &second);
|
2024-08-06 09:07:23 +00:00
|
|
|
|
|
2024-08-15 08:35:33 +00:00
|
|
|
|
if(year)
|
|
|
|
|
{
|
|
|
|
|
time_get_ok = 1;
|
|
|
|
|
}
|
2024-08-07 09:26:49 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
|
|
|
|
g_time_stamp = fml_time_to_stamp(year, month, day, hour, minute, second);
|
2024-08-15 08:35:33 +00:00
|
|
|
|
return year;
|
2024-08-08 02:59:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 08:43:35 +00:00
|
|
|
|
|
|
|
|
|
|
2024-08-15 08:35:33 +00:00
|
|
|
|
#define JSON_BUFFER_SIZE 200
|
2024-08-15 01:06:11 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>4gģ<67><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void parse_4g_receive_data()
|
2024-08-19 09:06:56 +00:00
|
|
|
|
{
|
2024-08-15 01:06:11 +00:00
|
|
|
|
if(uart_dev_char_present(g_ec801_uart_handle)){
|
2024-08-30 06:46:25 +00:00
|
|
|
|
int temp_5_index = 0;
|
|
|
|
|
char temp_5_char[5] = {0};
|
|
|
|
|
|
|
|
|
|
int AT_Command_flag = 0;
|
|
|
|
|
int Command_index = 0;
|
|
|
|
|
char AT_Command[10] = {0};
|
|
|
|
|
|
|
|
|
|
int AT_Command_ok_flag = 0;
|
|
|
|
|
|
|
|
|
|
int AT_data_ok_flag = 0;
|
|
|
|
|
uint8_t temp_buff[JSON_BUFFER_SIZE];
|
|
|
|
|
int temp_buff_index = 0; // <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
char c = 0;
|
|
|
|
|
int inJson = 0;
|
|
|
|
|
|
|
|
|
|
|
2024-08-15 09:42:15 +00:00
|
|
|
|
memset(temp_buff, '\0', sizeof(temp_buff));//ÿ<>ν<EFBFBD><CEBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>BUFF
|
2024-08-19 09:06:56 +00:00
|
|
|
|
for(; uart_dev_char_present(g_ec801_uart_handle);)
|
2024-08-15 01:06:11 +00:00
|
|
|
|
{
|
2024-08-19 09:06:56 +00:00
|
|
|
|
// ˼·<CBBC><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD>ν<EFBFBD><CEBD><EFBFBD>3<EFBFBD><33><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>BUFFER<45><52><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD>+<2B><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>AT<41><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>AT<41><54><EFBFBD><EFBFBD>+<2B><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>BUFF
|
|
|
|
|
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>BUFF <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-08-15 01:06:11 +00:00
|
|
|
|
c = uart_dev_in_char(g_ec801_uart_handle);
|
2024-08-20 08:43:35 +00:00
|
|
|
|
temp_5_char[temp_5_index] = c;
|
2024-08-19 09:06:56 +00:00
|
|
|
|
if(c == '+')
|
|
|
|
|
{
|
2024-08-20 08:43:35 +00:00
|
|
|
|
if(temp_5_char[(temp_5_index + 4)%5] == 'T' && temp_5_char[(temp_5_index + 3)%5] == 'A')// <20>ж<EFBFBD> + ǰ<>Dz<EFBFBD><C7B2><EFBFBD>AT
|
2024-08-19 09:06:56 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AT_Command_flag = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-20 08:43:35 +00:00
|
|
|
|
temp_5_index = (temp_5_index + 1)%5;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-08-19 09:06:56 +00:00
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(AT_Command_flag){
|
|
|
|
|
AT_Command[Command_index] = c;// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Buff
|
|
|
|
|
if(AT_Command[Command_index] == ':')// :<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
|
|
|
|
{
|
|
|
|
|
AT_Command_flag = 0;// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
AT_Command_ok_flag = 1;
|
2024-08-15 08:35:33 +00:00
|
|
|
|
}
|
2024-08-19 09:06:56 +00:00
|
|
|
|
Command_index ++;
|
2024-08-15 01:06:11 +00:00
|
|
|
|
}
|
2024-08-19 09:06:56 +00:00
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>꣬<EFBFBD><EAA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD>䷴<EFBFBD><E4B7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(AT_Command_ok_flag)
|
|
|
|
|
{
|
2024-08-19 09:16:58 +00:00
|
|
|
|
// term_printf(AT_Command);
|
2024-08-20 06:40:39 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>QMTT<54>ͻ<EFBFBD><CDBB>˷<EFBFBD><CBB7><EFBFBD>
|
2024-08-19 09:06:56 +00:00
|
|
|
|
if(strstr(AT_Command, "QMTOPEN"))
|
|
|
|
|
{
|
2024-08-20 06:40:39 +00:00
|
|
|
|
temp_buff[temp_buff_index] = c;
|
|
|
|
|
if(temp_buff[temp_buff_index] == '\r'||temp_buff[temp_buff_index] == '\n')
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
AT_Command_ok_flag = 0;
|
|
|
|
|
memset(AT_Command, 0, 10);
|
|
|
|
|
|
2024-08-20 08:43:35 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int client_idx, result;
|
|
|
|
|
sscanf(temp_buff, ": %d,%d", &client_idx, &result);
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(result == 0)
|
|
|
|
|
{
|
|
|
|
|
flag_open_net = 1;
|
|
|
|
|
}
|
2024-08-20 06:40:39 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
temp_buff_index ++;
|
2024-08-19 09:06:56 +00:00
|
|
|
|
}
|
2024-08-20 06:40:39 +00:00
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-08-19 09:06:56 +00:00
|
|
|
|
if(strstr(AT_Command, "QMTCONN"))
|
|
|
|
|
{
|
2024-08-20 06:40:39 +00:00
|
|
|
|
temp_buff[temp_buff_index] = c;
|
|
|
|
|
if(temp_buff[temp_buff_index] == '\r'||temp_buff[temp_buff_index] == '\n')
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
AT_Command_ok_flag = 0;
|
|
|
|
|
memset(AT_Command, 0, 10);
|
|
|
|
|
|
2024-08-20 08:43:35 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int client_idx, result, ret_code;
|
|
|
|
|
sscanf(temp_buff, ": %d,%d,%d", &client_idx, &result, &ret_code);
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(result == 0 && ret_code == 0)
|
|
|
|
|
{
|
|
|
|
|
flag_connect = 1;
|
|
|
|
|
}
|
2024-08-20 06:40:39 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
temp_buff_index ++;
|
2024-08-19 09:06:56 +00:00
|
|
|
|
}
|
2024-08-20 06:40:39 +00:00
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⷴ<EFBFBD><E2B7B4>
|
2024-08-19 09:06:56 +00:00
|
|
|
|
if(strstr(AT_Command, "QMTSUB"))
|
|
|
|
|
{
|
2024-08-20 06:40:39 +00:00
|
|
|
|
temp_buff[temp_buff_index] = c;
|
|
|
|
|
if(temp_buff[temp_buff_index] == '\r'||temp_buff[temp_buff_index] == '\n')
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
AT_Command_ok_flag = 0;
|
|
|
|
|
memset(AT_Command, 0, 10);
|
|
|
|
|
|
2024-08-20 08:43:35 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int client_idx, msgID, result, value;
|
|
|
|
|
sscanf(temp_buff, ": %d,%d,%d,%d", &client_idx, &msgID, &result, &value);
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(result == 0)
|
|
|
|
|
{
|
|
|
|
|
flag_sub = 1;
|
|
|
|
|
}
|
2024-08-20 06:40:39 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
temp_buff_index ++;
|
2024-08-19 09:06:56 +00:00
|
|
|
|
}
|
2024-08-20 06:40:39 +00:00
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
2024-08-19 09:06:56 +00:00
|
|
|
|
if(strstr(AT_Command, "QMTPUBEX"))
|
|
|
|
|
{
|
2024-08-20 06:40:39 +00:00
|
|
|
|
temp_buff[temp_buff_index] = c;
|
|
|
|
|
if(temp_buff[temp_buff_index] == '\r'||temp_buff[temp_buff_index] == '\n')
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
AT_Command_ok_flag = 0;
|
|
|
|
|
memset(AT_Command, 0, 10);
|
|
|
|
|
|
2024-08-20 08:43:35 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int client_idx, msgID, result, value;
|
|
|
|
|
sscanf(temp_buff, ": %d,%d,%d,%d", &client_idx, &msgID, &result, &value);
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(result == 0 || result == 1)
|
|
|
|
|
{
|
|
|
|
|
flag_pubex = 1;
|
|
|
|
|
}
|
2024-08-20 06:40:39 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
temp_buff_index ++;
|
2024-08-19 09:06:56 +00:00
|
|
|
|
}
|
2024-08-20 06:40:39 +00:00
|
|
|
|
|
|
|
|
|
// <20>յ<EFBFBD><D5B5><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>+++++<2B>յ<EFBFBD>json
|
2024-08-19 09:06:56 +00:00
|
|
|
|
if(strstr(AT_Command, "QMTRECV"))
|
|
|
|
|
{
|
2024-08-30 06:46:25 +00:00
|
|
|
|
if (c == '{')
|
2024-08-20 06:40:39 +00:00
|
|
|
|
{
|
|
|
|
|
AT_data_ok_flag = 1;
|
|
|
|
|
}
|
|
|
|
|
if (AT_data_ok_flag == 1)
|
|
|
|
|
{
|
|
|
|
|
temp_buff[temp_buff_index] = c;
|
|
|
|
|
if (temp_buff[temp_buff_index] == '}')
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
AT_data_ok_flag = 0;
|
|
|
|
|
memset(AT_Command, 0, 10);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-08-20 08:43:35 +00:00
|
|
|
|
if(temp_buff[0] != '\0')
|
|
|
|
|
{
|
|
|
|
|
parse_json(temp_buff);
|
|
|
|
|
}
|
2024-09-07 02:14:42 +00:00
|
|
|
|
// term_printf(temp_buff);
|
2024-08-20 06:40:39 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
temp_buff_index ++;
|
|
|
|
|
}
|
2024-08-19 09:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-15 01:06:11 +00:00
|
|
|
|
}
|
2024-08-16 02:45:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-07 02:14:42 +00:00
|
|
|
|
extern int trans_4g_flag;
|
2024-08-20 08:43:35 +00:00
|
|
|
|
// <20>յ<EFBFBD>json<6F><6E><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
|
2024-08-16 02:45:39 +00:00
|
|
|
|
void parse_json(uint8_t *json_buff)
|
|
|
|
|
{
|
|
|
|
|
cJSON* cjson_root = cJSON_Parse(json_buff);
|
|
|
|
|
|
|
|
|
|
if(cjson_root == NULL)
|
|
|
|
|
{
|
|
|
|
|
term_printf("parse fail.\n");
|
|
|
|
|
return;
|
2024-08-15 01:06:11 +00:00
|
|
|
|
}
|
2024-08-16 02:45:39 +00:00
|
|
|
|
|
|
|
|
|
cJSON* cjson_id = cJSON_GetObjectItem(cjson_root, "deviId");
|
|
|
|
|
cJSON* cjson_type = cJSON_GetObjectItem(cjson_root, "frameType");
|
|
|
|
|
cJSON* cjson_version = cJSON_GetObjectItem(cjson_root, "version");
|
|
|
|
|
cJSON* cjson_response = cJSON_GetObjectItem(cjson_root, "response");
|
|
|
|
|
cJSON* cjson_time = cJSON_GetObjectItem(cjson_root, "timeStamp");
|
|
|
|
|
|
2024-09-07 02:14:42 +00:00
|
|
|
|
cJSON* cjson_cmd = cJSON_GetObjectItem(cjson_root, "cmd");
|
|
|
|
|
|
2024-08-16 07:16:41 +00:00
|
|
|
|
// ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
char *temp_id = cjson_id -> valuestring;
|
|
|
|
|
char *temp_type = cjson_type -> valuestring;
|
|
|
|
|
int temp_version = cjson_version -> valueint;
|
|
|
|
|
int temp_response = cjson_response -> valueint;
|
|
|
|
|
int temp_time = cjson_time -> valueint;
|
2024-09-11 06:35:06 +00:00
|
|
|
|
int temp_cmd = cjson_cmd -> valueint;
|
2024-08-16 02:45:39 +00:00
|
|
|
|
|
2024-09-11 06:35:06 +00:00
|
|
|
|
term_printf("deviId=%s\n frameType=%s\n version=%d\n response=%d\n timeStamp=%d\n cmd=%d", temp_id, temp_type, temp_version, temp_response, temp_time, temp_cmd);
|
2024-08-16 02:45:39 +00:00
|
|
|
|
|
|
|
|
|
cJSON_Delete(cjson_root);
|
2024-08-16 07:16:41 +00:00
|
|
|
|
|
2024-08-21 07:13:25 +00:00
|
|
|
|
// <20>뷢<EFBFBD><EBB7A2>ʱ<EFBFBD>䲻һ<E4B2BB><D2BB><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD>
|
|
|
|
|
if(temp_time != trans_time_stamp)
|
2024-08-16 07:35:22 +00:00
|
|
|
|
{
|
2024-08-21 07:13:25 +00:00
|
|
|
|
term_printf("1111");
|
2024-09-07 02:14:42 +00:00
|
|
|
|
if(temp_cmd == 1)
|
|
|
|
|
{
|
|
|
|
|
trans_4g_flag = 1;
|
|
|
|
|
}
|
2024-08-16 07:35:22 +00:00
|
|
|
|
}
|
2024-08-21 07:13:25 +00:00
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
|
|
|
|
|
// if(abs(temp_time - g_time_stamp) >= 120)
|
|
|
|
|
// {
|
|
|
|
|
// g_time_stamp = temp_time;
|
|
|
|
|
// }
|
2024-08-15 01:06:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-08-16 02:45:39 +00:00
|
|
|
|
|
2024-08-16 07:16:41 +00:00
|
|
|
|
|
2024-08-19 02:05:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|