123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- /*
- netWork.c
- 网络功能任务
- */
- #include "includes.h"
- /*
- isNetWork4G
- 更新4G/非4G状态后要处理的操作
- */
- void isNetWork4G(void){
- static nwy_nw_mode_type_t last_network_mode = NWY_NW_MODE_NONE;
- nwy_nw_mode_type_t network_mode;
- if (NWY_SUCCESS == nwy_nw_get_network_mode(&network_mode)){
- if(network_mode!=last_network_mode){
- last_network_mode=network_mode;
- if(network_mode==NWY_NW_MODE_GSM){
- wlog_info("Is none-4G netWork");
- talking.workIn_4G=FALSE;
- talking.maxValue_none_4G=DEFAULT_TCP_HEARTTICK - (DEFAULT_TCP_HEARTTICK % paras.udpHeartTick_none_4G);
- }else if(network_mode==NWY_NW_MODE_LTE){
- wlog_info("Is 4G netWork");
- talking.workIn_4G=TRUE;
- talking.maxValue_4G=DEFAULT_TCP_HEARTTICK - (DEFAULT_TCP_HEARTTICK % paras.udpHeartTick_4G);
- }
- talking.pocTupCnt=0;
- }
- }
- }
- void isNetWorkIdle(void){
- if(talking.netWork.pdp==0) ticketDeVote(TICKET_PT_NETWORK);
- else ticketVote(TICKET_PT_NETWORK);
- }
- static void nwy_data_cb_fun(int hndl, nwy_data_call_state_t ind_state){
- static nwy_data_call_state_t lastDataCall=NWY_DATA_CALL_INVALID;
- wlog_info("dataCallCb hndl=%d,ind_state=%d",hndl, ind_state);
- if(lastDataCall!=ind_state){
- lastDataCall=ind_state;
- if(ind_state==NWY_DATA_CALL_CONNECTED){
- wlog_warn("pdp on");
- talking.netWork.pdp=1;
- }else{
- wlog_warn("pdp off");
- talking.netWork.pdp=0;
- }
- }
- }
- /*
- MS5700_Networking
- MS5700平台网络任务入口
- */
- int myhndl=-1;
- void pdpRstHandler(void){
- static char rstStep=0;
- if(talking.netWork.resetPDP!=0){
- talking.netWork.resetPDP=0;
- rstStep=1;
- wlog_warn("Disable pdp!!!");
- }
- switch(rstStep){
- case 1:
- wlog_warn("stop call");
- if(myhndl>0) nwy_data_stop_call(myhndl);
- rstStep=2;
- break;
- case 2:
- wlog_warn("release srv");
- if(myhndl>0) nwy_data_relealse_srv_handle(myhndl);
- myhndl=-1;
- rstStep=0;
- break;
- }
- }
- static void MS5700_Networking(void){
- nwy_sim_result_type info={0};
- nwy_nw_regs_info_type_t reg_info = {0};
- static nwy_nw_service_type_t lastRegStatus=NWY_NW_SERVICE_NONE;
- static T_BOOL getIccidFlag=FALSE;
- static T_UINT16 cnt=0;
- static T_UINT16 regCnt=0;
- if(FALSE==getIccidFlag){
- if(NWY_SMS_SUCCESS==nwy_sim_get_iccid(&info)){
- wlog_info("ICCID:%s", info.iccid);
- strcpy(talking.CCID, info.iccid);
- getIccidFlag=TRUE;
- }
- }
- if(FALSE==talking.getImeiFlag){
- if(NWY_SMS_SUCCESS==nwy_sim_get_imei(&info)){
- wlog_info("IMEI:%s", info.nImei);
- strcpy(talking.imei, info.nImei);
- talking.getImeiFlag=TRUE;
- }
- }
- if(FALSE==getIccidFlag) return;//没卡
- //网络处理
- isNetWorkIdle();
- //检测是否要重置PDP
- pdpRstHandler();
- if(NWY_RES_OK != nwy_nw_get_register_info(®_info)){
- wlog_warn("Get REG status failed");
- return;
- }
-
- if(reg_info.data_regs.regs_state == NWY_NW_SERVICE_NONE){//注册不成功
- if(lastRegStatus != reg_info.data_regs.regs_state) {wlog_warn("reg off");}//注册状态发生变化
- talking.netWork.reg=0;
- talking.netWork.pdp=0;
- wlog_info("wait reg");
- if(regCnt==600){//注册10分钟还不成功
- wlog_warn("!!!CFUN=0");
- // LSAPI_NET_CFUN(0);
- }else if(regCnt>=601) {
- regCnt=0;
- wlog_warn("!!!CFUN=1");
- // LSAPI_NET_CFUN(1);
- }
- ++regCnt;
- }else{//注册成功
- if(lastRegStatus != reg_info.data_regs.regs_state) {wlog_warn("reg on");}//注册状态发生变化
- talking.netWork.reg=1;
- if(myhndl<0){
- myhndl = nwy_data_get_srv_handle(nwy_data_cb_fun);
- if(myhndl>0){
- nwy_data_start_call_v02_t param_t={1,1,10,5000};
- if(nwy_data_start_call(myhndl,¶m_t)==NWY_RES_OK) wlog_warn("nwy_data_start_call ok");
- else{
- wlog_warn("nwy_data_start_call failed,rst pdp");
- talking.netWork.resetPDP=1;
- }
- }
- }
- }
- lastRegStatus=reg_info.data_regs.regs_state;
- isNetWork4G();
- isNetWorkIdle();
- }
- //#include "lsapi_sock.h"
- //static bool pingStatus=FALSE;
- void pingcallback(uint8_t flag){
- #if 0
- switch(flag){
- case LSAPI_SOCK_ICMP_DATA_IND:
- wlog_info("ping success");
- msgToOutter("+IPING:SUCC\r\n");
- break;
- case LSAPI_SOCK_ICMP_TIME_OUT:
- wlog_info("ping timeout");
- msgToOutter("+IPING:TIMEOUT\r\n");
- break;
- default:
- msgToOutter("+IPING:UNKNWON\r\n");
- wlog_info("ping default event:%d",flag);
- break;
- }
- threadPostEvent(LSAPI_OSI_ThreadCurrent(),USER_EVENT_EXIT);
- return;
- #endif
- }
- char pinghost[IP_DOMAIN_SIZE+1]={0};
- static void wpingTask(void *param){
- #if 0
- wlog_info("start ping:%s",pinghost);
- if(LSAPI_RET_OK!=LSAPI_SOCK_Ping(pinghost, 6, 255, pingcallback)){
- wlog_info("ping api error");
- msgToOutter("+IPING:ERR\r\n");
- pingStatus=FALSE;
- nwy_exit_thread();
- return;
- }
- LSAPI_OSI_Event_t event={};
- for(;;){
- nwy_wait_thead_event(LSAPI_OSI_ThreadCurrent(), &event,0);
- if(USER_EVENT_EXIT==event.id){
- pingStatus=FALSE;
- userExitThread("wpingTask");
- break;
- }
- }
- #endif
- }
- void tryToPing(char *host){
- #if 0
- //host="www.baidu.com"
- int i,j;
- //return ;
- //计算'"'个数
- j=0;
- if(host[0] != '"') goto CMD_ERR;
- for(i=0;i<strlen(host);i++){
- if(host[i]=='"'){
- j++;
- if(j>2){
- goto CMD_ERR;
- }else if(j==2){
- if(host[i+1]!=0) goto CMD_ERR;
- host[i]=0;
- }
- }
- }
- if(TRUE==pingStatus){
- msgToOutter("+IPING:BUSY\r\n");
- wlog_warn("ping is busy");
- return;
- }
- //get host
- snprintf(pinghost, sizeof(pinghost),"%s",host+1);
- wlog_info("ping:%s",pinghost);
- if(NULL == LSAPI_OSI_ThreadCreate("wping", wpingTask, NULL, NWY_OSI_PRIORITY_NORMAL, PING_THREAD_STACK, 4)){
- msgToOutter("+IPING:ERR\r\n");
- wlog_warn("ping thread failed");
- return;
- }
- pingStatus=TRUE;
- msgToOutter("OK\r\n");
- return;
- CMD_ERR:
- msgToOutter("+IPING:ERR\r\n");
- wlog_warn("ping cmd err");
- #endif
- }
- /*
- ptNetWorkTask
- 网络任务入口操作
- */
- PT_THREAD (ptNetWorkTask(pt_timer_t *ptPool, struct pt *pt)){
- static pt_timer_t ptTimer;
- PT_BEGIN(pt);
- while(1){
- MS5700_Networking();
- PTTimerStart(ptPool, &ptTimer,100);//need set to 1 seconds
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- }
- PT_END(pt);
- }
|