Mod aaa-12 修改lte模块

RCA:
SOL:
修改人:tongyebin
检视人:
This commit is contained in:
tongyebin 2019-10-17 15:33:55 +08:00
parent 747eb82bff
commit fcbddb6343
3 changed files with 94 additions and 50 deletions

View File

@ -66,7 +66,7 @@ typedef unsigned int ret_code;
#define RET_NO_LTE_MODULE_ERR (unsigned int)((unsigned int)LTE_CONFIG_MODULE<<16|4) #define RET_NO_LTE_MODULE_ERR (unsigned int)((unsigned int)LTE_CONFIG_MODULE<<16|4)
#define RET_ALREADY_START_ERR (unsigned int)((unsigned int)LTE_CONFIG_MODULE<<16|5) #define RET_ALREADY_START_ERR (unsigned int)((unsigned int)LTE_CONFIG_MODULE<<16|5)
#define RET_ALREADY_STOP_ERR (unsigned int)((unsigned int)LTE_CONFIG_MODULE<<16|6) #define RET_ALREADY_STOP_ERR (unsigned int)((unsigned int)LTE_CONFIG_MODULE<<16|6)
#define RET_ANOTHER_IN_PROCESS (unsigned int)((unsigned int)LTE_CONFIG_MODULE<<16|7)
@ -125,7 +125,8 @@ typedef unsigned int ret_code;
{ RET_LTE_NO_MATCH_ERR, "LTENoMatch"},\ { RET_LTE_NO_MATCH_ERR, "LTENoMatch"},\
{ RET_NO_LTE_MODULE_ERR, "NoLTEModule"},\ { RET_NO_LTE_MODULE_ERR, "NoLTEModule"},\
{ RET_ALREADY_START_ERR, "AlreadyStart"},\ { RET_ALREADY_START_ERR, "AlreadyStart"},\
{ RET_ALREADY_STOP_ERR, "AlreadyStop"}\ { RET_ALREADY_STOP_ERR, "AlreadyStop"},\
{ RET_ANOTHER_IN_PROCESS, "AnotherThreadIsRunning"}\
} }
struct err_disc { struct err_disc {

View File

@ -5,6 +5,9 @@
int g_action = 0; int g_action = 0;
int g_status = STOPPED;
pthread_t lte;
ret_code compare(char *result) ret_code compare(char *result)
{ {
@ -132,18 +135,18 @@ ret_code LTE_json_parse(pointer input, uint *conf_type, int action)
{ {
g_action = START; g_action = START;
} }
else if(strcmp(action_type->valuestring,"restart") == 0) /*else if(strcmp(action_type->valuestring,"restart") == 0)
{ {
g_action = RESTART; g_action = RESTART;
} }*/
else if(strcmp(action_type->valuestring,"stop") == 0) else if(strcmp(action_type->valuestring,"stop") == 0)
{ {
g_action = STOP; g_action = STOP;
} }
else if(strcmp(action_type->valuestring,"init") == 0) /*else if(strcmp(action_type->valuestring,"init") == 0)
{ {
g_action = INIT; g_action = INIT;
} }*/
else else
{ {
cJSON_Delete(json_obj); cJSON_Delete(json_obj);
@ -156,7 +159,7 @@ ret_code LTE_json_parse(pointer input, uint *conf_type, int action)
return ret; return ret;
} }
/*void killpid() void killpid()
{ {
char pid[10] = {0}; char pid[10] = {0};
char cmd[20] = {0}; char cmd[20] = {0};
@ -170,13 +173,44 @@ ret_code LTE_json_parse(pointer input, uint *conf_type, int action)
} }
fgets(pid,sizeof(pid),fp); fgets(pid,sizeof(pid),fp);
sscanf(pid,"%d",&pid_int); sscanf(pid,"%d",&pid_int);
rpc_log_info("pid is %d\n",pid_int);
sprintf(cmd,"kill %d",pid_int); sprintf(cmd,"kill %d",pid_int);
system(cmd); system(cmd);
pclose(fp); pclose(fp);
}*/ }
void _start_lte(void)
{
int wait_time = 0;
g_status = STARTING;
while(wait_time < 60)
{
if(access(file_path,0) != -1)
{
sleep(1000);
wait_time ++;
}
else
{
g_status = CONNECTED;
return;
}
}
system("/etc/ppp/ppp-4g init");
restart_lte();
pthread_join(lte,NULL);
return;
}
ret_code start_lte() ret_code start_lte()
{ {
if(g_status == STARTING)
{
return RET_ANOTHER_IN_PROCESS;
}
char result[RESULT_LENGTH] = {0}; char result[RESULT_LENGTH] = {0};
int i = 0; int i = 0;
@ -186,6 +220,7 @@ ret_code start_lte()
if (NULL == f) if (NULL == f)
{ {
g_status = START_FAIL;
rpc_log_info("execuate cmd fail\n"); rpc_log_info("execuate cmd fail\n");
return RET_EXEC_SHELL_ERR; return RET_EXEC_SHELL_ERR;
} }
@ -198,38 +233,23 @@ ret_code start_lte()
if(strstr(result,"not install lte") != NULL ) if(strstr(result,"not install lte") != NULL )
{ {
g_status = START_FAIL;
pclose(f); pclose(f);
return RET_NO_LTE_MODULE_ERR; return RET_NO_LTE_MODULE_ERR;
} }
else if(strstr(result,"pppd apparently already active") != NULL) else if(strstr(result,"pppd apparently already active") != NULL)
{ {
g_status = START_FAIL;
pclose(f); pclose(f);
return RET_ALREADY_START_ERR; return RET_ALREADY_START_ERR;
} }
else if(strstr(result,"start pppd ppp0") != NULL) else if(strstr(result,"start pppd ppp0") != NULL)
{ {
pthread_create(&lte,NULL,(void *)&_start_lte,NULL);
g_status = STARTING;
pclose(f); pclose(f);
return RET_OK; return RET_OK;
/* while(i < 120)
{
if(access(file_path,0) != -1)
{
sleep(1000);
i ++;
}
else
{
pclose(f);
return RET_OK;
}
}
pclose(f);
//ɱËÀ½ø³Ì
killpid();
rpc_log_info("please check the sim card\n");
return RET_EXEC_SHELL_ERR;*/
} }
else else
{ {
@ -259,12 +279,14 @@ ret_code stop_lte()
if(strstr(result,"pppd may be sotped already") != NULL) if(strstr(result,"pppd may be sotped already") != NULL)
{ {
g_status = STOPPED;
pclose(f); pclose(f);
return RET_ALREADY_STOP_ERR; return RET_ALREADY_STOP_ERR;
} }
else if((strstr(result,"stop pppd ppp0") != NULL) && access(file_path,0) != -1) else if((strstr(result,"stop pppd ppp0") != NULL) && access(file_path,0) != -1)
{ {
g_status = STOPPED;
pclose(f); pclose(f);
return RET_OK; return RET_OK;
} }
@ -276,10 +298,10 @@ ret_code stop_lte()
} }
ret_code restart_lte() void restart_lte(void)
{ {
char result[RESULT_LENGTH] = {0}; char result[RESULT_LENGTH] = {0};
int i = 0; int wait_time = 0;
FILE *f = NULL; FILE *f = NULL;
f = popen("/etc/ppp/ppp-4g restart","r"); f = popen("/etc/ppp/ppp-4g restart","r");
@ -287,7 +309,8 @@ ret_code restart_lte()
if (NULL == f) if (NULL == f)
{ {
rpc_log_info("execuate cmd fail\n"); rpc_log_info("execuate cmd fail\n");
return RET_EXEC_SHELL_ERR; g_status = START_FAIL;
return;
} }
fseek(f,0,SEEK_SET); fseek(f,0,SEEK_SET);
@ -300,41 +323,43 @@ ret_code restart_lte()
if(strstr(result,"not install lte! ") != NULL) if(strstr(result,"not install lte! ") != NULL)
{ {
g_status = START_FAIL;
pclose(f); pclose(f);
return RET_NO_LTE_MODULE_ERR; return;
} }
else if(strstr(result,"pppd apparently already active") != NULL) else if(strstr(result,"pppd apparently already active") != NULL)
{ {
g_status = START_FAIL;
pclose(f); pclose(f);
return RET_ALREADY_START_ERR; return;
} }
else if(strstr(result,"start pppd ppp0") != NULL) else if(strstr(result,"start pppd ppp0") != NULL)
{ {
pclose(f); while(wait_time < 60)
return RET_OK;
/* while(i < 120)
{ {
if(access(file_path,0) != -1) if(access(file_path,0) != -1)
{ {
sleep(1000); sleep(1000);
i ++; wait_time ++;
} }
else else
{ {
g_status = CONNECTED;
pclose(f); pclose(f);
return RET_OK; return;
} }
} }
pclose(f); pclose(f);
//ɱËÀ½ø³Ì //ɱËÀ½ø³Ì
killpid(); killpid();
rpc_log_info("please check the sim card\n"); g_status = START_FAIL;
return RET_EXEC_SHELL_ERR;*/ return;
} }
else else
{ {
g_status = START_FAIL;
pclose(f); pclose(f);
return RET_EXEC_SHELL_ERR; return RET_EXEC_SHELL_ERR;
} }
@ -399,7 +424,22 @@ ret_code status_lte(pointer output, int *output_len)
rpc_log_info("%s\n",result); rpc_log_info("%s\n",result);
if(strstr(result,"off") != NULL) if(strstr(result,"off") != NULL)
{ {
strcpy(status,"off"); if(g_status == STARTING)
{
strcpy(status,"starting...");
}
else if(g_status == STOPPED)
{
strcpy(status,"stopped");
}
else if(g_status == START_FAIL)
{
strcpy(status,"start fail");
}
else
{
return RET_ERR;
}
//·â×°json //·â×°json
ret = lte_to_json(status,connect_time,output,output_len); ret = lte_to_json(status,connect_time,output,output_len);
pclose(f); pclose(f);
@ -407,7 +447,7 @@ ret_code status_lte(pointer output, int *output_len)
} }
else if(strstr(result,"on") != NULL) else if(strstr(result,"on") != NULL)
{ {
strcpy(status,"on"); strcpy(status,"started");
memset(result,0,sizeof(result)); memset(result,0,sizeof(result));
fgets(result,sizeof(result),f); fgets(result,sizeof(result),f);
rpc_log_info("%s\n",result); rpc_log_info("%s\n",result);
@ -452,15 +492,15 @@ ret_code LTE_config_proc(uint source, uint config_type,
case START: case START:
ret = start_lte(); ret = start_lte();
break; break;
case RESTART: /* case RESTART:
ret = restart_lte(); ret = restart_lte();
break; break;*/
case STOP: case STOP:
ret = stop_lte(); ret = stop_lte();
break; break;
case INIT: /* case INIT:
ret = LTE_config_init(); ret = LTE_config_init();
break; break;*/
default: default:
ret = RET_INPUTERR; ret = RET_INPUTERR;
break; break;

View File

@ -11,6 +11,7 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <net/if.h> #include <net/if.h>
#include <pthread.h>
#define INIT_CMD "/etc/ppp/ppp-4G init" #define INIT_CMD "/etc/ppp/ppp-4G init"
@ -21,13 +22,15 @@
#define file_path "/var/run/ppp0.pid" #define file_path "/var/run/ppp0.pid"
#define GETPID "pgrep ppp-4g" #define GETPID "pgrep ppp-4g"
#define START 1 #define START 1
#define RESTART 2 #define STOP 2
#define STOP 3 #define STATUS 3
#define STATUS 4
#define INIT 5
#define RESULT_LENGTH 60 #define RESULT_LENGTH 60
#define ACTION_LENGTH 10 #define ACTION_LENGTH 10
#define STATUS_LENGTH 5 #define STATUS_LENGTH 10
#define STARTING 1
#define STOPPED 2
#define CONNECTED 3
#define START_FAIL 4
//ret_code LTE_config_init(void); //ret_code LTE_config_init(void);