diff --git a/applications/VK_Client.c b/applications/VK_Client.c index 0d4e88e..bcf863b 100644 --- a/applications/VK_Client.c +++ b/applications/VK_Client.c @@ -14,6 +14,8 @@ char cmd_cmd[100] = {0}; char cmd_str[100] = {0}; +no_carrier_match_t _no_carrier_t = {0}; + /*关闭TCP连接*/ void client_tcp_close(Cclient_t *client) { rt_sprintf(cmd_str, AT_QICLOSE, client->connect_ID); @@ -22,6 +24,105 @@ void client_tcp_close(Cclient_t *client) { // client->error_cnt = 0; } +static int no_carrier_char_parser(uint8_t ch){ + int ret = 0; + switch(_no_carrier_t.match_stage){ + case 0: + if(ch == 0x4E){ + _no_carrier_t.match_stage++; + }else { + _no_carrier_t.match_stage = 0; + ret = -1; + } + break; + case 1: + if(ch == 0x4F){ + _no_carrier_t.match_stage++; + }else{ + _no_carrier_t.match_stage = 0; + ret = -1; + } + break; + case 2: + if(ch == 0x20){ + _no_carrier_t.match_stage++; + }else{ + _no_carrier_t.match_stage = 0; + ret = -1; + } + break; + case 3: + if(ch == 0x43){ + _no_carrier_t.match_stage++; + }else{ + _no_carrier_t.match_stage = 0; + ret = -1; + } + break; + case 4: + if(ch == 0x41){ + _no_carrier_t.match_stage++; + }else{ + _no_carrier_t.match_stage = 0; + ret = -1; + } + break; + case 5: + if(ch == 0x52){ + _no_carrier_t.match_stage++; + }else{ + _no_carrier_t.match_stage = 0; + ret = -1; + } + break; + case 6: + if(ch == 0x52){ + _no_carrier_t.match_stage++; + }else{ + _no_carrier_t.match_stage = 0; + ret = -1; + } + break; + case 7: + if(ch == 0x49){ + _no_carrier_t.match_stage++; + }else{ + _no_carrier_t.match_stage = 0; + ret = -1; + } + break; + case 8: + if(ch == 0x45){ + _no_carrier_t.match_stage++; + }else{ + _no_carrier_t.match_stage = 0; + ret = -1; + } + break; + case 9: + if(ch == 0x52){ + ret = 1; + _no_carrier_t.match_stage = 0; + }else{ + _no_carrier_t.match_stage = 0; + ret = -1; + } + break; + } + return ret; +} + +static void no_carrier_match(uint8_t * at_buf,rt_size_t len){ + uint8_t buff[256] = {0}; + rt_memcpy(buff, at_buf, len); + for(int i = 0;i < len;i++){ + if(no_carrier_char_parser(buff[i]) == 1){ + _no_carrier_t.match_flag = COMPLETE_MATCH; + } + } +} + + /*将EC800K软件复位*/ int16_t EC800K_Reset(void) { int16_t rst = -1; @@ -212,7 +313,21 @@ int16_t client_yield(CLte_dev_t *pLte_dev) { rt_kprintf("disconnect!!!\n"); hw_printf("disconnect!!!\n"); pLte_dev->client1->connect_sta = false; + _no_carrier_t.match_flag = NO_MATCH; break; + } else if(strstr((const char *)lte_dev.at_buf, "\r\n")) { + _no_carrier_t.match_flag = HALF_MATCH; + } + + if (_no_carrier_t.match_flag == HALF_MATCH) { + no_carrier_match(pLte_dev->at_buf, len); + if (_no_carrier_t.match_flag == COMPLETE_MATCH) { + rt_kprintf("disconnect!!!\n"); + hw_printf("disconnect!!!\n"); + pLte_dev->client1->connect_sta = false; + _no_carrier_t.match_flag = NO_MATCH; + break; + } } rt_device_t fmu_com = fmu_com_get(); diff --git a/applications/VK_Client.h b/applications/VK_Client.h index 57117b3..33ad64a 100644 --- a/applications/VK_Client.h +++ b/applications/VK_Client.h @@ -8,6 +8,11 @@ #include #include "drv_ec800k.h" +typedef struct { + uint8_t match_stage; + uint8_t match_flag; +} no_carrier_match_t; + void client_task(void); diff --git a/applications/drv_ec800k.h b/applications/drv_ec800k.h index e4eac20..b770277 100644 --- a/applications/drv_ec800k.h +++ b/applications/drv_ec800k.h @@ -253,6 +253,13 @@ enum { DTU_CF_NEED_RESET = 1, }; + +enum { + NO_MATCH = 0, + HALF_MATCH = 1, + COMPLETE_MATCH = 2, +}; + ////////////////////////////////////////////////////////////////////////////////////////// bool isICCIDValid(char *str);