|
|
@ -31,6 +31,10 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static char cmd_cmd[128] = {0}; |
|
|
static char cmd_cmd[128] = {0}; |
|
|
|
|
|
static uint8_t socket_tx_buffer[LTE_SOCKET_TX_CHUNK_SIZE]; |
|
|
|
|
|
static uint8_t socket_rx_buffer[LTE_SOCKET_RX_CHUNK_SIZE]; |
|
|
|
|
|
static rt_size_t socket_tx_pending = 0; |
|
|
|
|
|
static rt_tick_t last_ack_query_tick = 0; |
|
|
|
|
|
|
|
|
no_carrier_match_t _no_carrier_t = {0}; |
|
|
no_carrier_match_t _no_carrier_t = {0}; |
|
|
|
|
|
|
|
|
@ -39,6 +43,10 @@ void client_tcp_close(Cclient_t *client) { |
|
|
char close_cmd[24]; |
|
|
char close_cmd[24]; |
|
|
|
|
|
|
|
|
client->connect_sta = false; |
|
|
client->connect_sta = false; |
|
|
|
|
|
BSP_LTE_SetDataTxPaused(true); |
|
|
|
|
|
BSP_LTE_ClearSocketEvents(); |
|
|
|
|
|
fmu_net_queue_reset(); |
|
|
|
|
|
socket_tx_pending = 0; |
|
|
rt_snprintf(close_cmd, sizeof(close_cmd), AT_QICLOSE, client->connect_ID); |
|
|
rt_snprintf(close_cmd, sizeof(close_cmd), AT_QICLOSE, client->connect_ID); |
|
|
BSP_LTE_SendCmd(close_cmd, DEFAULT_EXPECT, DEFAULT_ERROR, |
|
|
BSP_LTE_SendCmd(close_cmd, DEFAULT_EXPECT, DEFAULT_ERROR, |
|
|
LTE_CMD_WAIT_QICLOSE); |
|
|
LTE_CMD_WAIT_QICLOSE); |
|
|
@ -149,6 +157,8 @@ static const char *disconnect_reason_name(lte_disconnect_reason_t reason) { |
|
|
case LTE_DISC_AT_TIMEOUT: return "AT_TIMEOUT"; |
|
|
case LTE_DISC_AT_TIMEOUT: return "AT_TIMEOUT"; |
|
|
case LTE_DISC_QIOPEN_FAILED: return "QIOPEN_FAILED"; |
|
|
case LTE_DISC_QIOPEN_FAILED: return "QIOPEN_FAILED"; |
|
|
case LTE_DISC_MODULE_RESET: return "MODULE_RESET"; |
|
|
case LTE_DISC_MODULE_RESET: return "MODULE_RESET"; |
|
|
|
|
|
case LTE_DISC_SERVER_SILENCE: return "SERVER_SILENCE"; |
|
|
|
|
|
case LTE_DISC_SOCKET_SEND: return "SOCKET_SEND"; |
|
|
default: return "UNKNOWN"; |
|
|
default: return "UNKNOWN"; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -180,6 +190,15 @@ void lte_diag_disconnect(lte_disconnect_reason_t reason) { |
|
|
lte_diag.fmu_rx_bytes, lte_diag.fmu_tx_bytes, |
|
|
lte_diag.fmu_rx_bytes, lte_diag.fmu_tx_bytes, |
|
|
lte_diag.server_rx_bytes, lte_diag.server_rx_read_events, |
|
|
lte_diag.server_rx_bytes, lte_diag.server_rx_read_events, |
|
|
lte_diag.server_silence_timeout_count); |
|
|
lte_diag.server_silence_timeout_count); |
|
|
|
|
|
LOG_I("[DISC] socket_tx=%u send_ok=%u send_fail=%u prompt_timeout=%u read_errors=%u", |
|
|
|
|
|
lte_diag.socket_tx_bytes, lte_diag.socket_send_ok, |
|
|
|
|
|
lte_diag.socket_send_fail, lte_diag.socket_prompt_timeouts, |
|
|
|
|
|
lte_diag.socket_read_errors); |
|
|
|
|
|
LOG_I("[DISC] acked=%u unacked=%u ack_queries=%u ack_errors=%u", |
|
|
|
|
|
lte_diag.socket_acked_bytes, lte_diag.socket_unacked_bytes, |
|
|
|
|
|
lte_diag.socket_ack_queries, lte_diag.socket_ack_errors); |
|
|
|
|
|
LOG_I("[DISC] tx_queue_high=%u drops=%u", |
|
|
|
|
|
lte_diag.tx_queue_high_water, lte_diag.tx_queue_drops); |
|
|
LOG_I("[DISC] age_uart2_rx=%u age_uart2_tx=%u age_fmu_rx=%u age_server_rx=%u", |
|
|
LOG_I("[DISC] age_uart2_rx=%u age_uart2_tx=%u age_fmu_rx=%u age_server_rx=%u", |
|
|
diag_age(now, lte_diag.last_uart2_rx_tick), |
|
|
diag_age(now, lte_diag.last_uart2_rx_tick), |
|
|
diag_age(now, lte_diag.last_uart2_tx_tick), |
|
|
diag_age(now, lte_diag.last_uart2_tx_tick), |
|
|
@ -211,11 +230,7 @@ int16_t EC800K_Reset(void) { |
|
|
lte_dev.client1->connect_sta = false; |
|
|
lte_dev.client1->connect_sta = false; |
|
|
//lte_dev.client2->connect_sta = false;
|
|
|
//lte_dev.client2->connect_sta = false;
|
|
|
|
|
|
|
|
|
rt_thread_mdelay(3000); |
|
|
|
|
|
BSP_LTE_SendData((uint8_t *)"+++", 3); |
|
|
|
|
|
rt_thread_mdelay(2000); |
|
|
|
|
|
BSP_LTE_SendData((uint8_t *)"+++", 3); |
|
|
|
|
|
rt_thread_mdelay(2000); |
|
|
|
|
|
|
|
|
rt_thread_mdelay(1000); |
|
|
|
|
|
|
|
|
uint8_t try_count = 5; |
|
|
uint8_t try_count = 5; |
|
|
|
|
|
|
|
|
@ -261,9 +276,9 @@ int16_t client_tcp_connect(Cclient_t *client) { |
|
|
BSP_LTE_InitLogClock(); |
|
|
BSP_LTE_InitLogClock(); |
|
|
|
|
|
|
|
|
//
|
|
|
//
|
|
|
BSP_LTE_SendCmd(AT_CFG_TRANS_SIZE, DEFAULT_EXPECT, DEFAULT_ERROR, |
|
|
|
|
|
|
|
|
BSP_LTE_SendCmd(AT_CFG_RECV_IND, DEFAULT_EXPECT, DEFAULT_ERROR, |
|
|
LTE_CMD_WAIT_NORMAL); |
|
|
LTE_CMD_WAIT_NORMAL); |
|
|
BSP_LTE_SendCmd(AT_CFG_TRANS_WAITTM, DEFAULT_EXPECT, DEFAULT_ERROR, |
|
|
|
|
|
|
|
|
BSP_LTE_SendCmd(AT_QISDE0, DEFAULT_EXPECT, DEFAULT_ERROR, |
|
|
LTE_CMD_WAIT_NORMAL); |
|
|
LTE_CMD_WAIT_NORMAL); |
|
|
BSP_LTE_SendCmd(AT_CFG_PASSIVE_CLOSED, DEFAULT_EXPECT, DEFAULT_ERROR, |
|
|
BSP_LTE_SendCmd(AT_CFG_PASSIVE_CLOSED, DEFAULT_EXPECT, DEFAULT_ERROR, |
|
|
LTE_CMD_WAIT_NORMAL); |
|
|
LTE_CMD_WAIT_NORMAL); |
|
|
@ -276,7 +291,7 @@ int16_t client_tcp_connect(Cclient_t *client) { |
|
|
|
|
|
|
|
|
// 2, 打开链接
|
|
|
// 2, 打开链接
|
|
|
memset(cmd_cmd, 0, sizeof(cmd_cmd)); |
|
|
memset(cmd_cmd, 0, sizeof(cmd_cmd)); |
|
|
cmd_len = rt_snprintf(cmd_cmd, sizeof(cmd_cmd), AT_QIOPEN_TRANS, |
|
|
|
|
|
|
|
|
cmd_len = rt_snprintf(cmd_cmd, sizeof(cmd_cmd), AT_QIOPEN_BUFFER, |
|
|
client->connect_ID, client->mode, client->ip, |
|
|
client->connect_ID, client->mode, client->ip, |
|
|
client->port); |
|
|
client->port); |
|
|
if (cmd_len < 0 || cmd_len >= (int)sizeof(cmd_cmd)) { |
|
|
if (cmd_len < 0 || cmd_len >= (int)sizeof(cmd_cmd)) { |
|
|
@ -285,8 +300,7 @@ int16_t client_tcp_connect(Cclient_t *client) { |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
|
/* 透传模式成功返回 CONNECT;一次尝试只发送一次 QIOPEN。 */ |
|
|
/* 透传模式成功返回 CONNECT;一次尝试只发送一次 QIOPEN。 */ |
|
|
while (0 != BSP_LTE_SendCmd(cmd_cmd, CONNECTE_OK, DEFAULT_ERROR, |
|
|
|
|
|
LTE_CMD_WAIT_QIOPEN)) { |
|
|
|
|
|
|
|
|
while (0 != BSP_LTE_OpenSocket(cmd_cmd, client->connect_ID)) { |
|
|
lte_diag.qioopen_failures++; |
|
|
lte_diag.qioopen_failures++; |
|
|
client_tcp_close(client); |
|
|
client_tcp_close(client); |
|
|
#ifdef debug_mode |
|
|
#ifdef debug_mode |
|
|
@ -305,8 +319,12 @@ int16_t client_tcp_connect(Cclient_t *client) { |
|
|
#endif |
|
|
#endif |
|
|
} |
|
|
} |
|
|
client->connect_sta = true; |
|
|
client->connect_sta = true; |
|
|
|
|
|
BSP_LTE_ClearSocketEvents(); |
|
|
|
|
|
fmu_net_queue_reset(); |
|
|
|
|
|
socket_tx_pending = 0; |
|
|
BSP_LTE_SetDataTxPaused(false); |
|
|
BSP_LTE_SetDataTxPaused(false); |
|
|
lte_diag_connect_success(); |
|
|
lte_diag_connect_success(); |
|
|
|
|
|
last_ack_query_tick = lte_diag.connect_tick; |
|
|
client->error_cnt = 0; |
|
|
client->error_cnt = 0; |
|
|
lte_dev.reset_flag = DTU_CF_NO_NEED_RESET; |
|
|
lte_dev.reset_flag = DTU_CF_NO_NEED_RESET; |
|
|
|
|
|
|
|
|
@ -323,7 +341,7 @@ int16_t client_tcp_connect(Cclient_t *client) { |
|
|
mav_len = mavlink_msg_to_send_buffer(mav_buf, &msg); |
|
|
mav_len = mavlink_msg_to_send_buffer(mav_buf, &msg); |
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) { |
|
|
for (int i = 0; i < 3; i++) { |
|
|
BSP_LTE_SendData(mav_buf, mav_len); |
|
|
|
|
|
|
|
|
BSP_LTE_SendSocketData(client->connect_ID, mav_buf, mav_len); |
|
|
} |
|
|
} |
|
|
rt_device_t fmu_com = fmu_com_get(); |
|
|
rt_device_t fmu_com = fmu_com_get(); |
|
|
if (fmu_com != RT_NULL) { |
|
|
if (fmu_com != RT_NULL) { |
|
|
@ -334,11 +352,11 @@ int16_t client_tcp_connect(Cclient_t *client) { |
|
|
rt_sprintf(buf, "{\"sn\":\"%s\",\"client_id\":\"%s\",\"csq\":\"%d\"}\r\n", |
|
|
rt_sprintf(buf, "{\"sn\":\"%s\",\"client_id\":\"%s\",\"csq\":\"%d\"}\r\n", |
|
|
lte_dev.iccid, lte_dev.imei, lte_dev.csq); |
|
|
lte_dev.iccid, lte_dev.imei, lte_dev.csq); |
|
|
|
|
|
|
|
|
BSP_LTE_SendData((uint8_t *)buf, sizeof(buf)); |
|
|
|
|
|
|
|
|
BSP_LTE_SendSocketData(client->connect_ID, (uint8_t *)buf, sizeof(buf)); |
|
|
|
|
|
|
|
|
BSP_LTE_SendData((uint8_t *)buf, sizeof(buf)); |
|
|
|
|
|
|
|
|
BSP_LTE_SendSocketData(client->connect_ID, (uint8_t *)buf, sizeof(buf)); |
|
|
|
|
|
|
|
|
BSP_LTE_SendData((uint8_t *)buf, sizeof(buf)); |
|
|
|
|
|
|
|
|
BSP_LTE_SendSocketData(client->connect_ID, (uint8_t *)buf, sizeof(buf)); |
|
|
|
|
|
|
|
|
//hw_printf(buf);
|
|
|
//hw_printf(buf);
|
|
|
#endif |
|
|
#endif |
|
|
@ -350,37 +368,7 @@ int16_t client_tcp_connect(Cclient_t *client) { |
|
|
static rt_tick_t last_rx_tick = 0; |
|
|
static rt_tick_t last_rx_tick = 0; |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
/* Leave transparent mode only after the UART has been quiet for the
|
|
|
|
|
|
* required guard time. The caller keeps data_tx_paused asserted until the |
|
|
|
|
|
* next successful QIOPEN. */ |
|
|
|
|
|
static bool client_exit_transparent_mode(CLte_dev_t *pLte_dev) { |
|
|
|
|
|
rt_tick_t deadline; |
|
|
|
|
|
rt_ssize_t len; |
|
|
|
|
|
|
|
|
|
|
|
BSP_LTE_SetDataTxPaused(true); |
|
|
|
|
|
rt_thread_mdelay(1000); |
|
|
|
|
|
BSP_LTE_SendData((uint8_t *)"+++", 3); |
|
|
|
|
|
rt_thread_mdelay(1000); |
|
|
|
|
|
|
|
|
|
|
|
deadline = rt_tick_get() + 2000; |
|
|
|
|
|
while ((rt_int32_t)(rt_tick_get() - deadline) < 0) { |
|
|
|
|
|
if (pLte_dev->com_dev_rx_sem != RT_NULL) { |
|
|
|
|
|
rt_sem_take(pLte_dev->com_dev_rx_sem, 100); |
|
|
|
|
|
} |
|
|
|
|
|
rt_memset(pLte_dev->at_buf, 0, sizeof(pLte_dev->at_buf)); |
|
|
|
|
|
len = rt_device_read(pLte_dev->com_dev, 0, pLte_dev->at_buf, |
|
|
|
|
|
sizeof(pLte_dev->at_buf) - 1); |
|
|
|
|
|
if (len > 0) { |
|
|
|
|
|
lte_diag_uart2_rx((rt_size_t)len); |
|
|
|
|
|
pLte_dev->at_buf[len] = '\0'; |
|
|
|
|
|
if (rt_strstr((const char *)pLte_dev->at_buf, DEFAULT_EXPECT) != RT_NULL) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
void client_yield(CLte_dev_t *pLte_dev) { |
|
|
void client_yield(CLte_dev_t *pLte_dev) { |
|
|
while (1) { |
|
|
while (1) { |
|
|
if (pLte_dev->client1->connect_sta == true) { |
|
|
if (pLte_dev->client1->connect_sta == true) { |
|
|
@ -468,6 +456,96 @@ void client_yield(CLte_dev_t *pLte_dev) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
void client_yield(CLte_dev_t *pLte_dev) { |
|
|
|
|
|
while (1) { |
|
|
|
|
|
if (pLte_dev->client1->connect_sta == true) { |
|
|
|
|
|
int16_t socket_result; |
|
|
|
|
|
|
|
|
|
|
|
BSP_LTE_PollSocketUrc(20); |
|
|
|
|
|
if (pLte_dev->socket_closed_pending) { |
|
|
|
|
|
LOG_W("[URC] socket closed received"); |
|
|
|
|
|
lte_diag_disconnect(LTE_DISC_CLOSED); |
|
|
|
|
|
client_tcp_close(pLte_dev->client1); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
while (pLte_dev->socket_recv_pending && |
|
|
|
|
|
pLte_dev->client1->connect_sta) { |
|
|
|
|
|
rt_device_t fmu_com; |
|
|
|
|
|
int16_t read_length = BSP_LTE_ReadSocketData( |
|
|
|
|
|
pLte_dev->client1->connect_ID, socket_rx_buffer, |
|
|
|
|
|
sizeof(socket_rx_buffer)); |
|
|
|
|
|
if (read_length < 0) { |
|
|
|
|
|
lte_diag_disconnect(pLte_dev->socket_closed_pending |
|
|
|
|
|
? LTE_DISC_CLOSED |
|
|
|
|
|
: LTE_DISC_AT_TIMEOUT); |
|
|
|
|
|
client_tcp_close(pLte_dev->client1); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
if (read_length == 0) break; |
|
|
|
|
|
|
|
|
|
|
|
lte_diag.server_rx_bytes += read_length; |
|
|
|
|
|
lte_diag.server_rx_read_events++; |
|
|
|
|
|
lte_diag.last_server_rx_tick = rt_tick_get(); |
|
|
|
|
|
#if LTE_SERVER_SILENCE_TIMEOUT_SEC > 0 |
|
|
|
|
|
last_rx_tick = lte_diag.last_server_rx_tick; |
|
|
|
|
|
#endif |
|
|
|
|
|
fmu_com = fmu_com_get(); |
|
|
|
|
|
if (fmu_com != RT_NULL) { |
|
|
|
|
|
rt_ssize_t written = rt_device_write(fmu_com, 0, socket_rx_buffer, |
|
|
|
|
|
read_length); |
|
|
|
|
|
if (written > 0) lte_diag_fmu_tx((rt_size_t)written); |
|
|
|
|
|
} |
|
|
|
|
|
if (read_length == sizeof(socket_rx_buffer)) |
|
|
|
|
|
pLte_dev->socket_recv_pending = true; |
|
|
|
|
|
} |
|
|
|
|
|
if (!pLte_dev->client1->connect_sta) continue; |
|
|
|
|
|
|
|
|
|
|
|
if (socket_tx_pending == 0) { |
|
|
|
|
|
socket_tx_pending = fmu_net_queue_get(socket_tx_buffer, |
|
|
|
|
|
sizeof(socket_tx_buffer)); |
|
|
|
|
|
} |
|
|
|
|
|
if (socket_tx_pending > 0) { |
|
|
|
|
|
socket_result = BSP_LTE_SendSocketData( |
|
|
|
|
|
pLte_dev->client1->connect_ID, socket_tx_buffer, |
|
|
|
|
|
(uint16_t)socket_tx_pending); |
|
|
|
|
|
if (socket_result == 0) { |
|
|
|
|
|
socket_tx_pending = 0; |
|
|
|
|
|
} else if (socket_result < 0) { |
|
|
|
|
|
lte_diag_disconnect(LTE_DISC_SOCKET_SEND); |
|
|
|
|
|
client_tcp_close(pLte_dev->client1); |
|
|
|
|
|
continue; |
|
|
|
|
|
} else { |
|
|
|
|
|
rt_thread_mdelay(50); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (rt_tick_get() - last_ack_query_tick >= RT_TICK_PER_SECOND * 5) { |
|
|
|
|
|
last_ack_query_tick = rt_tick_get(); |
|
|
|
|
|
BSP_LTE_QuerySocketSendStatus(pLte_dev->client1->connect_ID); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if LTE_SERVER_SILENCE_TIMEOUT_SEC > 0 |
|
|
|
|
|
if (rt_tick_get() - last_rx_tick > |
|
|
|
|
|
RT_TICK_PER_SECOND * LTE_SERVER_SILENCE_TIMEOUT_SEC) { |
|
|
|
|
|
lte_diag.server_silence_timeout_count++; |
|
|
|
|
|
LOG_W("server silence timeout, reconnect\n"); |
|
|
|
|
|
lte_diag_disconnect(LTE_DISC_SERVER_SILENCE); |
|
|
|
|
|
client_tcp_close(pLte_dev->client1); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
#endif |
|
|
|
|
|
} else { |
|
|
|
|
|
if (pLte_dev->reset_flag == DTU_CF_NEED_RESET) BSP_LTE_Config(); |
|
|
|
|
|
client_tcp_connect(pLte_dev->client1); |
|
|
|
|
|
#if LTE_SERVER_SILENCE_TIMEOUT_SEC > 0 |
|
|
|
|
|
last_rx_tick = rt_tick_get(); |
|
|
|
|
|
#endif |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void client_task(void) { |
|
|
void client_task(void) { |
|
|
client_yield(<e_dev); |
|
|
client_yield(<e_dev); |
|
|
|