|
|
|
@ -17,8 +17,8 @@ char cmd_str[100] = {0}; |
|
|
|
void client_tcp_close(Cclient_t *client) { |
|
|
|
sprintf(cmd_str, AT_QICLOSE, client->connect_ID); |
|
|
|
BSP_LTE_SendCmd(cmd_str, DEFAULT_EXPECT, DEFAULT_ERROR, LTE_CMD_WAIT_NORMAL); |
|
|
|
client->connect_sta = false; |
|
|
|
client->error_cnt = 0; |
|
|
|
// client->connect_sta = false;
|
|
|
|
// client->error_cnt = 0;
|
|
|
|
} |
|
|
|
|
|
|
|
/*将EC800K软件复位*/ |
|
|
|
@ -85,6 +85,7 @@ int16_t client_tcp_connect(Cclient_t *client) { |
|
|
|
if (lte_dev.config_sta == false) return rtn; |
|
|
|
if (client->connect_sta == true) return rtn; |
|
|
|
|
|
|
|
if (lte_dev.reset_flag == DTU_CF_NEED_RESET) { |
|
|
|
/*查询PDP场景*/ |
|
|
|
if (0 != BSP_LTE_SendCmd(AT_QIACT, "+QIACT: 1,1,1,", DEFAULT_ERROR, |
|
|
|
LTE_CMD_WAIT_LLONG)) { |
|
|
|
@ -93,7 +94,7 @@ int16_t client_tcp_connect(Cclient_t *client) { |
|
|
|
LTE_CMD_WAIT_LLONG)) { |
|
|
|
BSP_LTE_SendCmd(AT_QIDEACT, NETCLOSE_SUCCESS, NETCLOSE_FAILURE, |
|
|
|
LTE_CMD_WAIT_LLONG); |
|
|
|
client->error_cnt++; |
|
|
|
//client->error_cnt++;
|
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -104,33 +105,35 @@ int16_t client_tcp_connect(Cclient_t *client) { |
|
|
|
BSP_LTE_SendCmd(AT_CFG_TRANS_WAITTM, DEFAULT_EXPECT, DEFAULT_ERROR, |
|
|
|
LTE_CMD_WAIT_LLONG); |
|
|
|
//
|
|
|
|
} |
|
|
|
// 1. 检查网络信号
|
|
|
|
lte_dev.csq = BSP_LTE_GetCSQ(); |
|
|
|
|
|
|
|
// 2, 打开链接
|
|
|
|
memset(cmd_cmd, 0, sizeof(cmd_cmd)); |
|
|
|
memset(cmd_str, 0, sizeof(cmd_str)); |
|
|
|
|
|
|
|
sprintf(cmd_cmd, AT_QIOPEN_TRANS /*AT_QIOPEN_FORW*/, client->connect_ID, |
|
|
|
client->mode, client->ip, client->port); |
|
|
|
sprintf(cmd_str, "+QIOPEN: %d,0", client->connect_ID); |
|
|
|
|
|
|
|
/*打开socket, 这个模块他不返回+QIOPEN:字符串*/ |
|
|
|
if (0 != BSP_LTE_SendCmd(cmd_cmd, CONNECTE_OK, DEFAULT_ERROR, |
|
|
|
while (0 != BSP_LTE_SendCmd(cmd_cmd, CONNECTE_OK, DEFAULT_ERROR, |
|
|
|
LTE_CMD_WAIT_LLONG) && |
|
|
|
0 != BSP_LTE_SendCmd(cmd_cmd, cmd_str, DEFAULT_ERROR, |
|
|
|
LTE_CMD_WAIT_LLONG)) { |
|
|
|
if (strstr((char *)lte_dev.at_buf, |
|
|
|
"563")) // Socket标识被占用 **应该是已经建立连接了
|
|
|
|
client_tcp_close(client); |
|
|
|
client->connect_sta = false; |
|
|
|
client->error_cnt++; |
|
|
|
|
|
|
|
if (client->error_cnt > 5) { |
|
|
|
EC800K_Reset(); |
|
|
|
|
|
|
|
client->error_cnt = 0; |
|
|
|
lte_dev.reset_flag = DTU_CF_NEED_RESET; |
|
|
|
return 0; |
|
|
|
} else { |
|
|
|
} |
|
|
|
} |
|
|
|
client->connect_sta = true; |
|
|
|
client->error_cnt = 0; |
|
|
|
} |
|
|
|
lte_dev.reset_flag = DTU_CF_NO_NEED_RESET; |
|
|
|
|
|
|
|
rt_kprintf("%s\r", lte_dev.at_buf); |
|
|
|
|
|
|
|
#ifdef TRANSPARENT_MODE |
|
|
|
@ -139,14 +142,16 @@ int16_t client_tcp_connect(Cclient_t *client) { |
|
|
|
|
|
|
|
#ifdef LINK_4G |
|
|
|
char buf[128] = {0}; |
|
|
|
sprintf(buf, "{\"sn\":\"%s\",\"client_id\":\"%s\"}\r\n", lte_dev.iccid, |
|
|
|
lte_dev.imei); |
|
|
|
sprintf(buf, "{\"sn\":\"%s\",\"client_id\":\"%s\",\"csq\":\"%d\"}\r\n", lte_dev.iccid, |
|
|
|
lte_dev.imei,lte_dev.csq); |
|
|
|
|
|
|
|
rt_device_write(lte_dev.com_dev, 0, buf, sizeof(buf)); |
|
|
|
|
|
|
|
rt_device_write(lte_dev.com_dev, 0, buf, sizeof(buf)); |
|
|
|
|
|
|
|
rt_device_write(lte_dev.com_dev, 0, buf, sizeof(buf)); |
|
|
|
|
|
|
|
hw_printf(buf); |
|
|
|
#endif |
|
|
|
|
|
|
|
return rtn; |
|
|
|
@ -157,22 +162,22 @@ int16_t client_yield(CLte_dev_t *pLte_dev) { |
|
|
|
int16_t rtn = 0; |
|
|
|
|
|
|
|
while (1) { |
|
|
|
if (lte_dev.client1->connect_sta == true) { |
|
|
|
rt_err_t ret = rt_sem_take(lte_dev.com_dev_rx_sem, 1000); |
|
|
|
if (pLte_dev->client1->connect_sta == true) { |
|
|
|
rt_err_t ret = rt_sem_take(pLte_dev->com_dev_rx_sem, 1000); |
|
|
|
if (rt_tick_get() - last_rx_tick > RT_TICK_PER_SECOND * 10) { |
|
|
|
rt_kprintf("timeout!!! reconnect."); |
|
|
|
hw_printf("timeout!!! reconnect."); |
|
|
|
rt_kprintf("timeout!!! reconnect.\n"); |
|
|
|
hw_printf("timeout!!! reconnect.\n"); |
|
|
|
pLte_dev->client1->connect_sta = false; |
|
|
|
} |
|
|
|
if (RT_EOK == ret) { |
|
|
|
rt_ssize_t len = 0; |
|
|
|
while (1) { |
|
|
|
rt_memset(lte_dev.at_buf, 0, sizeof(lte_dev.at_buf)); |
|
|
|
len = rt_device_read(lte_dev.com_dev, 0, lte_dev.at_buf, |
|
|
|
sizeof(lte_dev.at_buf)); |
|
|
|
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)); |
|
|
|
if (len > 0) { |
|
|
|
/*收到TCP关闭的消息*/ |
|
|
|
if (strstr((const char *)lte_dev.at_buf, CLOSED)) { |
|
|
|
if (strstr((const char *)pLte_dev->at_buf, CLOSED)) { |
|
|
|
memset(cmd_str, 0, sizeof(cmd_str)); |
|
|
|
sprintf(cmd_str, "\"closed\",%d", pLte_dev->client1->connect_ID); |
|
|
|
if (NULL != strstr((char *)lte_dev.at_buf, cmd_str)) { |
|
|
|
@ -182,8 +187,8 @@ int16_t client_yield(CLte_dev_t *pLte_dev) { |
|
|
|
} |
|
|
|
break; |
|
|
|
} else if (strstr((const char *)lte_dev.at_buf, "NO CARRIER")) { |
|
|
|
rt_kprintf("disconnect!!!"); |
|
|
|
hw_printf("disconnect!!!"); |
|
|
|
rt_kprintf("disconnect!!!\n"); |
|
|
|
hw_printf("disconnect!!!\n"); |
|
|
|
pLte_dev->client1->connect_sta = false; |
|
|
|
break; |
|
|
|
} |
|
|
|
@ -200,8 +205,10 @@ int16_t client_yield(CLte_dev_t *pLte_dev) { |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
if(pLte_dev->reset_flag == DTU_CF_NEED_RESET){ |
|
|
|
BSP_LTE_Config(); |
|
|
|
client_tcp_connect(lte_dev.client1); |
|
|
|
} |
|
|
|
client_tcp_connect(pLte_dev->client1); |
|
|
|
last_rx_tick = rt_tick_get(); |
|
|
|
} |
|
|
|
} |
|
|
|
|