UDP_CMD_GET_TIME = '6', // 获取Cat1 时间 ,YYYYMMDD HHmmss zone
UDP_CMD_GET_RECV_NETWORKSTAT = '7', //获取Cat1 信号信息,VOLTE信息,信号强度,SIM卡状态 // 内容同UDP_CMD_GET_NETWORKSTAT,CAT主动发给MCU
UDP_MSG_SMS = '8', // CAT1接收到的SMS信息给MCU,包含电话号及短信内容
- UDP_CMD_RESET_NETWORKSTAT = '9', // 重置网络
+ UDP_CMD_MSG_ATCMD = '9', // AT 指令
UDP_MSG_CALL_CONNECTED = 'A', // CAT1 电话接听消息
UDP_MSG_CALL_DISCONNECTED = 'B', // CAT1 电话挂断消息
UDP_MSG_COMMING_CALL = 'C' , // CAT1 来电消息,包含电话号
uapi_cat1_wakeup_cat1(0);
}
-#define BOOTMSG_HEADER_STR "BOOTUP,"
+#define BOOTMSG_HEADER_STR "BOOTUP"
#define BOOTMSG_HEADER_STR_LEN strlen(BOOTMSG_HEADER_STR)
#define NETSTAT_HEADER_STR "imei:"
#define NETSTAT_HEADER_STR_LEN strlen(NETSTAT_HEADER_STR)
-#define VERMSG_HEADER_STR "pyVer,"
+#define VERMSG_HEADER_STR "pyVer"
#define VERMSG_HEADER_STR_LEN strlen(VERMSG_HEADER_STR)
#define MSG_SPLIT_CHAR ","
+#define MSG_SPLIT_CHAR2 "@"
+// const char* msgboot = "BOOTUP:pyVer,PY_SRV_V4,modemVer,EG810MCNLAR06A01M08_VOLTE_OCPU_QPY_BETA0312";
+// const char* msgver ="pyVer,PY_SRV_V4,modemVer,EG810MCNLAR06A01M08_VOLTE_OCPU_QPY_BETA0312";
static int decodeVersion(char* msg)
{
+
+ int update = 0;
+ runtime_status_t * runtime = get_device_runtime_status();
+
if (strlen(msg) < 50)
{
PRINT("msg len is too short !\r\n");
char buf[200] = {0};
if (strncmp(msg,BOOTMSG_HEADER_STR,BOOTMSG_HEADER_STR_LEN) ==0)
{
- strcpy(buf,msg+BOOTMSG_HEADER_STR_LEN);
+ strcpy(buf,msg+BOOTMSG_HEADER_STR_LEN+1);
// PRINT("BOOTMSG =============\r\n");
+
}
else if (strncmp(msg,VERMSG_HEADER_STR,VERMSG_HEADER_STR_LEN) ==0)
{
strcpy(buf,msg);
// PRINT("version =============\r\n");
+
}else{
return -2;
}
- char* p = MSG_SPLIT_CHAR;
+
+ char* p = MSG_SPLIT_CHAR;
+ if (strstr(buf,MSG_SPLIT_CHAR2) != NULL)
+ {
+ p = MSG_SPLIT_CHAR2;
+ }
char* s = NULL;
- char *pbuf[4] = {0};
- int i = 0;
- int update = 0;
- runtime_status_t * runtime = get_device_runtime_status();
for (s = strtok(buf,p); s!=NULL;s=strtok(NULL,p))
{
- pbuf[i] = s;
- if(i==1)
+ if((strncmp(s,"pyVer",5) == 0) && (strlen(s)> 5))
{
- // PRINT("pyVer= %s\r\n",pbuf[i]);
- if (strncmp(pbuf[i],"PY_",3) == 0 || strcmp(runtime->cat1_runtime.pyVer,pbuf[i])==0 )
+ char* ptmp=s+6;
+ PRINT("pyVer= %s\r\n",ptmp);
+ if ( strcmp(runtime->cat1_runtime.pyVer,ptmp)!=0 )
{
update++;
+ memset(runtime->cat1_runtime.pyVer,0,sizeof(runtime->cat1_runtime.pyVer));
+ strcpy_s(runtime->cat1_runtime.pyVer,sizeof(runtime->cat1_runtime.pyVer),ptmp);
}
- memset(runtime->cat1_runtime.pyVer,0,sizeof(runtime->cat1_runtime.pyVer));
- strcpy_s(runtime->cat1_runtime.pyVer,sizeof(runtime->cat1_runtime.pyVer),pbuf[i]);
- }
- else if (i==3)
+
+ }else if ((strncmp(s,"modemVer",8) == 0) && (strlen(s)> 8))
+ {
+ char* ptmp=s+9;
+ PRINT("modemVer= %s\r\n",ptmp);
+ if (strcmp(runtime->cat1_runtime.modemVer,ptmp) != 0)
+ {
+ update++;
+ memset(runtime->cat1_runtime.modemVer,0,sizeof(runtime->cat1_runtime.modemVer));
+ strcpy_s(runtime->cat1_runtime.modemVer,sizeof(runtime->cat1_runtime.modemVer),ptmp);
+ }
+ } else if (strncmp(s,"PY_",3) == 0 )
+ {
+ PRINT("pyVer = %s\r\n",s);
+ if ( strcmp(runtime->cat1_runtime.pyVer,s)!=0 )
+ {
+ update++;
+ memset(runtime->cat1_runtime.pyVer,0,sizeof(runtime->cat1_runtime.pyVer));
+ strcpy_s(runtime->cat1_runtime.pyVer,sizeof(runtime->cat1_runtime.pyVer),s);
+ }
+
+ }else if (strncmp(s,"EG810M",6) == 0 )
{
- // PRINT("modemVer= %s\r\n",pbuf[i]);
- if (strncmp(pbuf[i],"EG810M",6) == 0 || strcmp(runtime->cat1_runtime.modemVer,pbuf[i]) == 0)
+ PRINT("modemVer = %s\r\n",s);
+ if (strcmp(runtime->cat1_runtime.modemVer,s) != 0)
{
update++;
+ memset(runtime->cat1_runtime.modemVer,0,sizeof(runtime->cat1_runtime.modemVer));
+ strcpy_s(runtime->cat1_runtime.modemVer,sizeof(runtime->cat1_runtime.modemVer),s);
}
- memset(runtime->cat1_runtime.modemVer,0,sizeof(runtime->cat1_runtime.modemVer));
- strcpy_s(runtime->cat1_runtime.modemVer,sizeof(runtime->cat1_runtime.modemVer),pbuf[i]);
}
- i++;
}
+
if (update > 0)
return 0;
else
return -3;
}
-
-
+// const char* msgnet ="imei:860132060352796,sim:0,oper:-1,signal:99,net:([99, 0, 0, 0], [0, 0, 0, 0, 0])";
+// const char* msgnetfull = "imei:864430010001091,sim:1,oper:('CHN-CT', 'CT', '460', '11'),signal:22,net:([99, 99, 255, 255], [-71, -103, -12, 255, 4])";
+// ([rssi, bitErrorRate, rscp, ecno], [rssi, rsrp, rsrq, cqi, sinr])
+// const char* msgnet ="imei:860132060352796@sim:0@oper:-1@signal:99@net:([99, 0, 0, 0], [0, 0, 0, 0, 0])";
+// const char* msgnetfull = "imei:864430010001091@sim:1@oper:('CHN-CT', 'CT', '460', '11')@signal:22@net:([99, 99, 255, 255], [-71, -103, -12, 255, 4])";
static int decodeNetStat(char* msg)
{
+ int update = 0;
+ runtime_status_t * runtime = get_device_runtime_status();
if (strlen(msg) < 50)
{
PRINT("msg len is too short !\r\n");
if (strncmp(msg,NETSTAT_HEADER_STR,NETSTAT_HEADER_STR_LEN) ==0)
{
strcpy(buf,msg);
- // PRINT("net stat =============\r\n");
}else{
return -2;
}
char* p = MSG_SPLIT_CHAR;
+ if (strstr(buf,MSG_SPLIT_CHAR2) != NULL)
+ {
+ p = MSG_SPLIT_CHAR2;
+ }
char* s = NULL;
- char *pbuf[6] = {0};
- char *ppbuf ;
- int i = 0;
- int update = 0;
- runtime_status_t * runtime = get_device_runtime_status();
+ char* ppbuf = NULL;
for (s = strtok(buf,p); s!=NULL;s=strtok(NULL,p))
{
- pbuf[i] = s;
- if(strncmp(pbuf[i],"imei:",5) == 0)
+ // PRINT("%s\r\n",s );
+ if(strncmp(s,"imei:",5) == 0)
{
- ppbuf=pbuf[i]+5;
+ ppbuf = s+5;
PRINT("=== imei = %s\r\n",ppbuf);
- if ( strcmp(runtime->cat1_runtime.imei,ppbuf)==0 )
+ if ( strcmp(runtime->cat1_runtime.imei,ppbuf)!=0 )
{
- update++;
+ update++;
+ memset(runtime->cat1_runtime.imei,0,sizeof(runtime->cat1_runtime.imei));
+ strcpy_s(runtime->cat1_runtime.imei,sizeof(runtime->cat1_runtime.imei),ppbuf);
}
- memset(runtime->cat1_runtime.imei,0,sizeof(runtime->cat1_runtime.imei));
- strcpy_s(runtime->cat1_runtime.imei,sizeof(runtime->cat1_runtime.imei),ppbuf);
- i++;
continue;
- }
- if(strncmp(pbuf[i],"sim:",4) == 0)
+ }else if(strncmp(s,"sim:",4) == 0)
{
- ppbuf=pbuf[i]+4;
+ ppbuf=s+4;
int simstat = atoi(ppbuf);
PRINT("=== sim = %d\r\n",simstat);
if ( runtime->cat1_runtime.sim != simstat)
{
update++;
+ runtime->cat1_runtime.sim = simstat;
}
- runtime->cat1_runtime.sim = simstat;
- i++;
continue;
- }
- if(strncmp(pbuf[i],"oper:",5) == 0)
+ }else if(strncmp(s,"oper:",5) == 0)
{
- if( *(pbuf[i]+5) == '(' )
- ppbuf=pbuf[i]+6;
+ if( *(s+5) == '(' && (p != MSG_SPLIT_CHAR2))
+ ppbuf=s+6;
else
- ppbuf=pbuf[i]+5;
+ ppbuf=s+5;
PRINT("=== opera = %s\r\n",ppbuf);
- if ( strcmp(runtime->cat1_runtime.opera,ppbuf)==0 )
+ if ( strcmp(runtime->cat1_runtime.opera,ppbuf)!=0 )
{
- update++;
+ update++;
+ memset(runtime->cat1_runtime.opera,0,sizeof(runtime->cat1_runtime.opera));
+ strcpy_s(runtime->cat1_runtime.opera,sizeof(runtime->cat1_runtime.opera),ppbuf);
}
- memset(runtime->cat1_runtime.opera,0,sizeof(runtime->cat1_runtime.opera));
- strcpy_s(runtime->cat1_runtime.opera,sizeof(runtime->cat1_runtime.opera),ppbuf);
- i++;
+
continue;
- }
- if(strncmp(pbuf[i],"signal:",7) == 0)
+ }else if(strncmp(s,"signal:",7) == 0)
{
- ppbuf=pbuf[i]+7;
+ ppbuf=s+7;
int signals = atoi(ppbuf);
PRINT("=== signal = %d\r\n",signals);
if ( runtime->cat1_runtime.signal != signals)
{
update++;
+ runtime->cat1_runtime.signal = signals;
}
- runtime->cat1_runtime.signal = signals;
- i++;
continue;
}
- if (i>=4) break;
+
}
if (update > 0)
return 0;
udp_send_msg_toCat1(UDP_CMD_DIAL_NUMB,phonenum);
}
-void cat1_reset_network(void)
+void cat1_at_cmd(char * cmd)
{
- udp_send_msg_toCat1(UDP_CMD_RESET_NETWORKSTAT,"0");
+ udp_send_msg_toCat1(UDP_CMD_MSG_ATCMD,cmd);
}
void cat1_getsignal(void)
WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 cat1_handle_timesync %s\n",timesync);
// ('24/03/01 07:15:36 8 0', 1709277336, 0)
+ // "4294938528@(2106, 2, 7, 6, 28, 48, 6, 38)@8"
//TODO:设置时间
// if (g_time_synced == 0)
{
}
break;
- case UDP_CMD_GET_CAT1VER:
+ case UDP_CMD_GET_CAT1VER:
index = cat1_handle_version_msg(msg);
+ break;
+ case UDP_CMD_MSG_ATCMD:
+ PRINT("ATCMD reply : %s\n", msg->buffer);
break;
default:
PRINT("error message: %s\n", rx_buffer);
import ql_fs
import pm
PROJECT_NAME = "Cat1SlipUDPService"
-PROJECT_VERSION = "PY_SRV_V4"
+PROJECT_VERSION = "PY_SRV_V5"
CONFIG_JSON="/usr/system_config.json"
CURRENT_APP_TYPE="pysrv"
UDP_CMD_GET_TIME = '6' #获取Cat1 时间 ,YYYYMMDD HHmmss zone
UDP_CMD_GET_RECV_NETWORKSTAT = '7' #获取Cat1 信号信息,VOLTE信息,信号强度,SIM卡状态 // 内容同UDP_CMD_GET_NETWORKSTAT,CAT主动发给MCU
UDP_MSG_SMS = '8' # CAT1接收到的SMS信息给MCU,包含电话号及短信内容
-UDP_CMD_RESET_NETWORKSTAT = '9' # 重置网络
+UDP_CMD_ATCMD = '9' # 执行AT指令
UDP_MSG_CALL_CONNECTED = 'A' # CAT1 电话接听消息
UDP_MSG_CALL_DISCONNECTED = 'B' # CAT1 电话挂断消息
UDP_MSG_COMMING_CALL = 'C' # CAT1 来电消息,包含电话号
def bootup_msg_to_bt(self):
modem_ver = modem.getDevFwVersion()
- self.reply_cmd('FF',"BOOTUP,pyVer,{},modemVer,{}".format(PROJECT_VERSION,modem_ver))
+ self.reply_cmd('FF',"BOOTUP@pyVer:{}@modemVer:{}".format(PROJECT_VERSION,modem_ver))
def btmcu_cmd_handler(self,cmd,parm):
print("btmcu_cmd_handler cmd {0} , args {1}".format(cmd,parm))
print(cmd)
# UDP_CMD_GET_CAT1VER
modem_ver = modem.getDevFwVersion()
- self.reply_cmd('F0',"pyVer,{},modemVer,{}".format(PROJECT_VERSION,modem_ver))
+ self.reply_cmd('F0',"pyVer:{}@modemVer:{}".format(PROJECT_VERSION,modem_ver))
elif cmd == "F1":
print("{}{}".format(cmd,parm))
# UDP_CMD_DIAL_NUMB
time=utime.localtime()
zone=utime.getTimeZone()
#(2024, 3, 2, 18, 31, 32, 5, 62),8
- self.reply_cmd('F6',"{0},{1}".format(time,zone))
+ # 返回当前时间戳,参数为元组
+ # timestamp = utime.mktime(time)
+ # cat1service_log.info(timestamp)
+ self.reply_cmd('F6',"{0}@{1}".format(time,zone))
elif cmd == "F7":
print(cmd)
# UDP_CMD_GET_RECV_NETWORKSTAT
operator = net.operatorName()
signal = net.csqQueryPoll()
print("imei:{0},sim:{1},oper:{2},signal:{3},net:{4}".format(imei,simstat,operator,signal,netstat))
- self.reply_cmd('F7',"imei:{0},sim:{1},oper:{2},signal:{3},net:{4}".format(imei,simstat,operator,signal,netstat))
+ self.reply_cmd('F7',"imei:{0}@sim:{1}@oper:{2}@signal:{3}@net:{4}".format(imei,simstat,operator,signal,netstat))
elif cmd == "F9":
- print(cmd)
- # UDP_CMD_RESET_NETWORKSTAT
- net.setModemFun(0)
- net.setModemFun(1)
- # resp=bytearray(50)
- # ret=atcmd.sendSync('AT+CFUN=1?\r\n',resp,'',20)
- # print("reply:{},ret:{}".format(resp,ret))
- # self.reply_cmd('F9',"ret:{}".format(ret))
+ print("{},{}".format(cmd,parm))
+ # UDP_CMD_ATCMD
+ # net.setModemFun(0)
+ # net.setModemFun(1)
+ resp=bytearray(50)
+ ret=atcmd.sendSync("{}\r\n".format(parm),resp,'',10)
+ if ret == 0:
+ print("reply:{},ret:{}".format(resp.decode(),ret))
+ self.reply_cmd('F9',"{}".format(resp.decode()))
+ else:
+ print("cmd error ret:{}".format(ret))
+ self.reply_cmd('F9',"{}".format("at error"))
# 来电提醒
#define TIME_YEAR_OFFSET 123
#define TIME_ZONE_OFF (8 * 60)
#define TIME_SECSPERMIN 60 /* second per minute */
-static uint32_t get_sec_time_from_cat1time(char* time , uint32_t *second , uint8_t *zone)
+static uint32_t get_sec_time_from_cat1time(char* time , uint32_t *second , int *zone)
{
struct tm _tm = { 0 };
// printf("%04d-%02d-%02d %02d:%02d:%02d %d\n",_tm.tm_year,_tm.tm_mon,_tm.tm_mday,_tm.tm_hour,_tm.tm_min,_tm.tm_sec,*zone);
return 0;
}
+
+static int decodeTime(char* time,uint32_t *timeseconds,int *zone)
+{
+
+ struct tm _tm = { 0 };
+ if (time==NULL || strlen(time) < 12)
+ {
+ printf("time==NULL || strlen(time) < 12 , format error, should like [(2024, 3, 2, 18, 40, 1, 5, 62),8] or [(2106, 2, 7, 6, 28, 48, 6, 38)@8] ");
+ return 2;
+ }
+ // const char* timestr="(2024, 3, 2, 18, 40, 1, 5, 62),8";
+
+ char buf[50] = {0};
+ if (strlen(time)>sizeof(buf))
+ {
+ strncpy(buf,time,sizeof(buf));
+
+ }else{
+ strncpy(buf,time,strlen(time));
+
+ }
+
+ char* p = ")";
+ char* s = NULL;
+ // PRINT("origin %s, %s \r\n",time,buf);
+ char tmp_time_buf[50]={0};
+ int tmp_zone=0;
+ uint32_t tmp_timestamp =0 ;
+
+ int index=0;
+ for (s = strtok(buf,p); s!=NULL;s=strtok(NULL,p))
+ {
+ if (index == 0 )
+ {
+ char* ptime = s+1;
+ strncpy(tmp_time_buf,ptime,strlen(ptime));
+ // PRINT("ptime= %s \r\n",ptime );
+
+ }else if (index == 1)
+ {
+ char* pzone = s+1;
+ // PRINT("pzone %s\r\n",pzone);
+ tmp_zone = strtol(pzone, NULL, DECIMAL);
+
+ }
+ index++;
+ }
+
+ int i = 0;
+ s = NULL;
+
+ // PRINT("time %s zone %d\r\n",tmp_time_buf,tmp_zone);
+
+ for (s = strtok(tmp_time_buf,","); s!=NULL;s=strtok(NULL,","))
+ {
+ // printf("[%d]%s\r\n",i,s);
+ switch(i)
+ {
+ case 0://year
+ // 年的计算需要减去1900
+ _tm.tm_year = strtol(s, NULL, DECIMAL) - 1900;
+ if (_tm.tm_year < TIME_YEAR_OFFSET) {
+ PRINT("ERR!year num must bigger than 2023!");
+ return 3;
+ }
+ break;
+ case 1://month
+ // 月的计算需要减1
+ if (s[0] == ' ')
+ _tm.tm_mon = strtol(s+1, NULL, DECIMAL) - 1;
+ else
+ _tm.tm_mon = strtol(s, NULL, DECIMAL) - 1;
+ break;
+ case 2://day
+ if (s[0] == ' ')
+ _tm.tm_mday = strtol(s+1, NULL, DECIMAL);
+ else
+ _tm.tm_mday = strtol(s, NULL, DECIMAL);
+ break;
+ case 3://hour
+ if (s[0] == ' ')
+ _tm.tm_hour = strtol(s+1, NULL, DECIMAL);
+ else
+ _tm.tm_hour = strtol(s, NULL, DECIMAL);
+ break;
+ case 4://minitue
+ if (s[0] == ' ')
+ _tm.tm_min = strtol(s+1, NULL, DECIMAL);
+ else
+ _tm.tm_min = strtol(s, NULL, DECIMAL);
+ break;
+ case 5://seconds
+ if (s[0] == ' ')
+ _tm.tm_sec = strtol(s+1, NULL, DECIMAL);
+ else
+ _tm.tm_sec = strtol(s, NULL, DECIMAL);
+ break;
+ default:
+ break;
+ }
+ i++;
+ }
+ tmp_timestamp = (uint32_t)mktime(&_tm);
+ // tmp_timestamp -= tmp_zone * 3600; //cat1获得的时间时当下时间,实际上要减去zone的时间
+ printf("time %04d-%02d-%02d %02d:%02d:%02d \r\nstamp %u \r\nzone %d\n",
+ _tm.tm_year,_tm.tm_mon,_tm.tm_mday,_tm.tm_hour,_tm.tm_min,_tm.tm_sec,
+ tmp_timestamp,
+ tmp_zone);
+
+
+ *zone = tmp_zone;
+ *timeseconds = tmp_timestamp;
+
+ return 0;
+
+}
errcode_t uapi_set_time_from_cat1(char* cat1time)
{
- uint8_t zone = 0;
+ int zone = 0;
uint32_t sec = 0;
- uint32_t ret = get_sec_time_from_cat1time(cat1time,&sec,&zone);
+ // uint32_t ret = get_sec_time_from_cat1time(cat1time,&sec,&zone);
+ uint32_t ret = decodeTime(cat1time,&sec,&zone);
if (ret == 0 )
{