From: SnickerSun Date: Mon, 4 Mar 2024 19:44:18 +0000 (+0800) Subject: 优化cat1和蓝牙通讯,实现http下载update.fwpkg, 但是目前超过1MB 的文件下载过程中cat1会重启。 X-Git-Tag: release_V1.2.70_20241020_135402~1274^2~31^2 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=7a9f0e38b1c94fed6685a7896b1d5267251a632f;p=mirrors%2FFD230.git 优化cat1和蓝牙通讯,实现http下载update.fwpkg, 但是目前超过1MB 的文件下载过程中cat1会重启。 --- diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.cpp index cffab3922..6d905b5cf 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.cpp +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.cpp @@ -227,6 +227,13 @@ static uint32_t AT_CALL_ifconfig(uint8_t *para, uint32_t paraLen, char *strCommo return ERRCODE_SUCC; } +static uint32_t AT_cat1_reset_network(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + printf("CAT1TEST ATCMD cat1 reset\n"); + cat1_reset_network(); + return ERRCODE_SUCC; +} static const at_cmd_table_t g_cat1_cmd[] = { { (char *)"AT^CAT1POWER", cat1_power, (char *)"1" }, { (char *)"AT^CAT1DIAL", at_cat1_dial, (char *)"1" }, @@ -238,7 +245,8 @@ static const at_cmd_table_t g_cat1_cmd[] = { { (char *)"AT^PING", cat1_ping, (char *)"1" }, { (char *)"AT^IFCONFIG", cat1_ifconfig, (char *)"1" }, { (char *)"AT^CAT1GETVER", at_cat1_getver, (char *)"1" }, - { (char *)"AT^CALL_1", AT_CALL_ifconfig, (char *)"1" }, + { (char *)"AT^CAT1RESETNETWORK", AT_cat1_reset_network, (char *)"1" }, + { (char *)"AT^CALL_1", AT_CALL_ifconfig, (char *)"1" }, }; diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp index 520d49c1b..96cbfd820 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp @@ -64,15 +64,15 @@ enum UDP_COMMAND_HEAD { UDP_CMD_CAT1_OTA_UPDATE = '4', // 触发Cat1 OTA升级,mcu提供url UDP_CMD_SEND_SMS = '5', // 发送SMS短信,mcu提供电话号及短信内容 UDP_CMD_GET_TIME = '6', // 获取Cat1 时间 ,YYYYMMDD HHmmss zone - UDP_CMD_GET_NETWORKSTAT = '7', //获取Cat1 信号信息,VOLTE信息,信号强度,SIM卡状态 + UDP_CMD_GET_RECV_NETWORKSTAT = '7', //获取Cat1 信号信息,VOLTE信息,信号强度,SIM卡状态 // 内容同UDP_CMD_GET_NETWORKSTAT,CAT主动发给MCU UDP_MSG_SMS = '8', // CAT1接收到的SMS信息给MCU,包含电话号及短信内容 - UDP_MSG_NETWORKSTAT = '9', // 内容同UDP_CMD_GET_NETWORKSTAT,CAT主动发给MCU + UDP_CMD_RESET_NETWORKSTAT = '9', // 重置网络 UDP_MSG_CALL_CONNECTED = 'A', // CAT1 电话接听消息 UDP_MSG_CALL_DISCONNECTED = 'B', // CAT1 电话挂断消息 UDP_MSG_COMMING_CALL = 'C' , // CAT1 来电消息,包含电话号 - UDP_MSG_TIMESYNC = 'D' , // CAT1 来电消息,包含电话号 - UDP_MSG_VERSION = 'E', - UDP_MSG_MAX = 'F' // + // UDP_MSG_TIMESYNC = 'D' , // CAT1 来电消息,包含电话号 + // UDP_MSG_VERSION = 'E', + UDP_MSG_REPLY = 'F' // 返回值 }; // static char *msg_wifi_resp[] = @@ -184,9 +184,14 @@ void cat1_call_dial(char* phonenum) udp_send_msg_toCat1(UDP_CMD_DIAL_NUMB,phonenum); } +void cat1_reset_network(void) +{ + udp_send_msg_toCat1(UDP_CMD_RESET_NETWORKSTAT,"0"); +} + void cat1_getsignal(void) { - udp_send_msg_toCat1(UDP_CMD_GET_NETWORKSTAT,"0"); + udp_send_msg_toCat1(UDP_CMD_GET_RECV_NETWORKSTAT,"0"); } void cat1_gettime(void) { @@ -339,13 +344,13 @@ static int udp_packet_parse(char *rx_buffer, int len) case UDP_MSG_COMMING_CALL: index = cat1_handle_call_incomming(msg); break; - case UDP_MSG_NETWORKSTAT: + case UDP_CMD_GET_RECV_NETWORKSTAT: index = cat1_handle_networ_msg(msg); break; case UDP_MSG_SMS: index = cat1_handle_sms(msg); break; - case UDP_MSG_TIMESYNC: + case UDP_CMD_GET_TIME: index = cat1_handle_timesync(msg); break; case UDP_MSG_CALL_CONNECTED: @@ -353,14 +358,17 @@ static int udp_packet_parse(char *rx_buffer, int len) break; case UDP_MSG_CALL_DISCONNECTED: index = cat1_handle_call_disconnected(msg); + break; + case UDP_MSG_REPLY: + break; default: printf("error message: %s\n", rx_buffer); index = 1; break; } - if (index > 0) //需要反馈的指令才返回OK - udp_send_msg_toCat1( msg->head[1], "OK"); + // if (index > 0) //需要反馈的指令才返回OK + // udp_send_msg_toCat1( msg->head[1], "OK"); } else { printf("wrong format msg and exit\n"); index = 1; diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.h b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.h index 69bfd278d..3032a0b32 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.h +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.h @@ -26,6 +26,7 @@ void cat1_call_sms_send(char* phonenum,char* sms_txt); void cat1_gettime(void); void cat1_getver(void); void restart_time_sync(void); +void cat1_reset_network(void); errcode_t cat1_server_init(void); diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/EG810MCNLAR06A01M08_VOLTE_OCPU_QPY_BETA0228_20240305-0342.zip b/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/EG810MCNLAR06A01M08_VOLTE_OCPU_QPY_BETA0228_20240305-0342.zip new file mode 100644 index 000000000..05a8a22e8 Binary files /dev/null and b/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/EG810MCNLAR06A01M08_VOLTE_OCPU_QPY_BETA0228_20240305-0342.zip differ diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/cat1Service.py b/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/cat1Service.py index 0582fd241..79b6dbf50 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/cat1Service.py +++ b/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/cat1Service.py @@ -12,21 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -# UDP_CMD_GET_CAT1VER = '0', // 获取 Cat1 版本号 -# UDP_CMD_DIAL_NUMB = '1', // 拨打电话 -# UDP_CMD_HUNGUP = '2', // 挂断电话 -# UDP_CMD_ANSWER = '3', // 接听电话 -# UDP_CMD_CAT1_OTA_UPDATE = '4', // 触发Cat1 OTA升级,mcu提供url -# UDP_CMD_SEND_SMS = '5', // 发送SMS短信,mcu提供电话号及短信内容 -# UDP_CMD_GET_TIME = '6', // 获取Cat1 时间 ,YYYYMMDD HHmmss zone -# UDP_CMD_GET_NETWORKSTAT = '7', //获取Cat1 信号信息,VOLTE信息,信号强度,SIM卡状态 -# UDP_MSG_SMS = '8', // CAT1接收到的SMS信息给MCU,包含电话号及短信内容 -# UDP_MSG_NETWORKSTAT = '9', // 内容同UDP_CMD_GET_NETWORKSTAT,CAT主动发给MCU -# UDP_MSG_CALL_CONNECTED = 'A', // CAT1 电话接听消息 -# UDP_MSG_CALL_DISCONNECTED = 'B', // CAT1 电话挂断消息 -# UDP_MSG_COMMING_CALL = 'C' , // CAT1 来电消息,包含电话号 -# UDP_MSG_TIMESYNC = 'D' , // CAT1 来电消息,包含电话号 -# UDP_MSG_MAX = 'F' // + # net.getNetMode() # (0, '460', '11', 7) @@ -57,7 +43,10 @@ import osTimer import sim import modem import utime - +import checkNet +import atcmd + + PROJECT_NAME = "Cat1SlipUDPService" PROJECT_VERSION = "V2" @@ -81,16 +70,31 @@ gpioWakeBT.set_dir(Pin.OUT) # 设置引脚电平 # gpioWakeBT.write(1) +UDP_CMD_GET_CAT1VER = '0' #获取 Cat1 版本号 +UDP_CMD_DIAL_NUMB = '1' #拨打电话 +UDP_CMD_HUNGUP = '2' #挂断电话 +UDP_CMD_ANSWER = '3' #接听电话 +UDP_CMD_CAT1_OTA_UPDATE = '4' #触发Cat1 OTA升级,mcu提供url +UDP_CMD_SEND_SMS = '5' #发送SMS短信,mcu提供电话号及短信内容 +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_MSG_CALL_CONNECTED = 'A' # CAT1 电话接听消息 +UDP_MSG_CALL_DISCONNECTED = 'B' # CAT1 电话挂断消息 +UDP_MSG_COMMING_CALL = 'C' # CAT1 来电消息,包含电话号 +UDP_MSG_REPLY = 'F' # 返回值 + class Cat1Service: AP = 0 # SLIP_INNER STA = 1 # SLIP_OUTER - def __init__(self, uart=UART.UART4, mode=AP, callback=None): + def __init__(self, uart=UART.UART4, mode=AP): self.__uart = uart self.__mode = mode self.__message = '' self.__err = 0 - self.__callback = callback + self.__net_connected = 0 self.__value = None self.__wait_resp = 0 slip.destroy() @@ -125,7 +129,7 @@ class Cat1Service: if cmd == "F0": print(cmd) # UDP_CMD_GET_CAT1VER - self.reply_cmd('FE',PROJECT_VERSION) + self.reply_cmd('F0',PROJECT_VERSION) elif cmd == "F1": print("{}{}".format(cmd,parm)) # UDP_CMD_DIAL_NUMB @@ -151,16 +155,28 @@ class Cat1Service: time=utime.localtime() zone=utime.getTimeZone() #(2024, 3, 2, 18, 31, 32, 5, 62),8 - self.reply_cmd('FD',"{0},{1}".format(time,zone)) + self.reply_cmd('F6',"{0},{1}".format(time,zone)) elif cmd == "F7": print(cmd) - # UDP_CMD_GET_NETWORKSTAT + # UDP_CMD_GET_RECV_NETWORKSTAT simstat = sim.getStatus() imei = modem.getDevImei() netstat = net.getSignal(1) operator = net.operatorName() - print("imei:{0},sim:{1},oper:{2},net:{3}".format(imei,simstat,operator,netstat)) - self.reply_cmd('F9',"imei:{0},sim:{1},oper:{2},net:{3}".format(imei,simstat,operator,netstat)) + 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)) + 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)) + + # 来电提醒 def notifyIncomingcall(self, incomming_numb): self.clear_remain() @@ -190,8 +206,19 @@ class Cat1Service: # if self.__err == 1 or self.__value[2] != 'OK': # return -1 return 0 - + def wait_network_ready(self): + stage, state = checkNet.waitNetworkReady(1) + if stage == 3 and state == 1: + print('Network connection successful.') + self.set_network_config() + self.__net_connected = 1 + return 0 + else: + print('Network connection failed, stage={}, state={}'.format(stage, state)) + self.reset_network_config() + self.__net_connected = 0 + return -1 # 查询网卡状态 def timesync(self,_timesync): @@ -246,6 +273,50 @@ class Cat1Service: self.ip_str = ip_str return slip.set_default_netif(self.ip_str) + def reset_network_config(self): + if (self.__net_connected == 0): + print("skip reset_network_config") + return 0 + Info = dataCall.getInfo(1,0) + print("Info{}".format(Info)) + default_NIC_ip = Info[2][2] # 假设默认网卡ip地址为10.10.1.1,请根据实际情况更改 + segment_ip = '172.16.4.0' # 假设ap模式网段范围是[192.168.4.0 ~ 192.168.4.255],请根据实际情况更改 + mask = '255.255.255.0' # 假设子网掩码为255.255.255.0,请根据实际情况更改 + # 配置默认网卡,通过默认网卡进行网络转发 + cat1service.set_default_NIC(default_NIC_ip) + print("default_NIC_ip {0} segment_ip {1}".format(default_NIC_ip,segment_ip)) + #添加路由规则,只有该网段IP才进行转发 + cat1service.router_add(segment_ip, mask) + + pri_dns = '8.8.8.8' # 假设DNS首选地址为8.8.8.8,请根据实际情况更改 + sec_dns = '114.114.114.114' # 假设DNS备选地址为114.114.114.114,请根据实际情况更改 + # 配置网卡DNS服务器 + cat1service.set_dns(pri_dns, sec_dns) + # 网卡IP信息查询 + cat1service.ipconfig() + + def set_network_config(self): + if (self.__net_connected == 1) : + print("skip set_network_config") + return 0 + Info = dataCall.getInfo(1,0) + print("Info{}".format(Info)) + default_NIC_ip = Info[2][2] # 假设默认网卡ip地址为10.10.1.1,请根据实际情况更改 + segment_ip = '172.16.1.0' # 假设ap模式网段范围是[192.168.4.0 ~ 192.168.4.255],请根据实际情况更改 + mask = '255.255.255.0' # 假设子网掩码为255.255.255.0,请根据实际情况更改 + # 配置默认网卡,通过默认网卡进行网络转发 + cat1service.set_default_NIC(default_NIC_ip) + print("default_NIC_ip {0} segment_ip {1}".format(default_NIC_ip,segment_ip)) + #添加路由规则,只有该网段IP才进行转发 + cat1service.router_add(segment_ip, mask) + + pri_dns = '8.8.8.8' # 假设DNS首选地址为8.8.8.8,请根据实际情况更改 + sec_dns = '114.114.114.114' # 假设DNS备选地址为114.114.114.114,请根据实际情况更改 + # 配置网卡DNS服务器 + cat1service.set_dns(pri_dns, sec_dns) + # 网卡IP信息查询 + cat1service.ipconfig() + # 释放slip网卡 def stop(self): slip.destroy() @@ -357,23 +428,7 @@ class Cat1Service: print("Cat1Service start") cat1service = Cat1Service() -Info = dataCall.getInfo(1,0) -print("Info{}".format(Info)) -default_NIC_ip = Info[2][2] # 假设默认网卡ip地址为10.10.1.1,请根据实际情况更改 -segment_ip = '172.16.1.0' # 假设ap模式网段范围是[192.168.4.0 ~ 192.168.4.255],请根据实际情况更改 -mask = '255.255.255.0' # 假设子网掩码为255.255.255.0,请根据实际情况更改 -# 配置默认网卡,通过默认网卡进行网络转发 -cat1service.set_default_NIC(default_NIC_ip) -print("default_NIC_ip {0} segment_ip {1}".format(default_NIC_ip,segment_ip)) -#添加路由规则,只有该网段IP才进行转发 -cat1service.router_add(segment_ip, mask) - -pri_dns = '8.8.8.8' # 假设DNS首选地址为8.8.8.8,请根据实际情况更改 -sec_dns = '114.114.114.114' # 假设DNS备选地址为114.114.114.114,请根据实际情况更改 -# 配置网卡DNS服务器 -cat1service.set_dns(pri_dns, sec_dns) -# 网卡IP信息查询 -cat1service.ipconfig() + #voice call callback function @@ -410,12 +465,13 @@ voiceCall.setCallback(voice_callback) def checknet_cb(arg): print("start checktime!!") - time=utime.localtime() - zone=utime.getTimeZone() + cat1service.wait_network_ready() + # time=utime.localtime() + # zone=utime.getTimeZone() #(2024, 3, 2, 18, 31, 32, 5, 62),8 - cat1service.timesync("{0},{1}".format(time,zone)) + # cat1service.timesync("{0},{1}".format(time,zone)) -timer.start(200000,1,checknet_cb) +timer.start(10000,1,checknet_cb) # while True: diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/checkota.py b/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/checkota.py index 247e1ca57..d703fd613 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/checkota.py +++ b/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/checkota.py @@ -4,44 +4,53 @@ import modem import ujson import request import ql_fs +import checkNet +import sys -fota = app_fota.new() -imei = modem.getDevImei() -if ql_fs.path_exists("/usr/system_config.json") == True: - config = ql_fs.read_json("/usr/system_config.json") - haskey = str("pythonVersion") in config.keys() - if haskey == True: - pythonversion = config['pythonVersion'] +def do_fota_update(): + fota = app_fota.new() + imei = modem.getDevImei() + if ql_fs.path_exists("/usr/system_config.json") == True: + config = ql_fs.read_json("/usr/system_config.json") + haskey = str("pythonVersion") in config.keys() + if haskey == True: + pythonversion = config['pythonVersion'] + else: + pythonversion = "V1" else: pythonversion = "V1" -else: - pythonversion = "V1" -url = "http://icfota.snicker.com.cn:8089/fd230ota.jsp?product=FD230&pkgver={0}&imei={1}".format(pythonversion,imei) -response = request.get(url) -print(url) -data = response.json() -if(data['UptoDate'] == False): - print("Need update python application") - srcurl = data['url'] - targetpyname = data['OtaPackageName'] - version = data['OtaPackageVersion'] - print("download {0} to /usr/{1}".format(srcurl,targetpyname)) - ret = fota.download(srcurl,targetpyname) - if ret == 0 : - print("ota success") - ql_fs.file_copy("/usr/{}".format(targetpyname), "/usr/.updater/{}".format(targetpyname)) - data = {"pythonVersion":version} - print(data) - ql_fs.touch("/usr/system_config.json", data) - # fota.set_update_flag() # 设置升级标志 - # Power.powerRestart() # 重启 + url = "http://icfota.snicker.com.cn:8089/fd230ota.jsp?product=FD230&pkgver={0}&imei={1}".format(pythonversion,imei) + response = request.get(url) + print(url) + data = response.json() + if(data['UptoDate'] == False): + print("Need update python application") + srcurl = data['url'] + targetpyname = data['OtaPackageName'] + version = data['OtaPackageVersion'] + print("download {0} to /usr/{1}".format(srcurl,targetpyname)) + ret = fota.download(srcurl,targetpyname) + if ret == 0 : + print("ota success") + ql_fs.file_copy("/usr/{}".format(targetpyname), "/usr/.updater/{}".format(targetpyname)) + data = {"pythonVersion":version} + print(data) + ql_fs.touch("/usr/system_config.json", data) + # fota.set_update_flag() # 设置升级标志 + # Power.powerRestart() # 重启 + else: + print("ota failed") else: - print("ota failed") -else: - print("No need update python application") + print("No need update python application") +stage, state = checkNet.waitNetworkReady(1) +if stage == 3 and state == 1: + print('Network connection successful.') + do_fota_update() +else: + print('Network connection failed, stage={}, state={}'.format(stage, state)) # res = uos.statvfs("/usr") diff --git a/code/sdk/drivers/peripheral/slip/uart_slip.c b/code/sdk/drivers/peripheral/slip/uart_slip.c index 041c89d5d..c478f64a0 100644 --- a/code/sdk/drivers/peripheral/slip/uart_slip.c +++ b/code/sdk/drivers/peripheral/slip/uart_slip.c @@ -37,7 +37,7 @@ struct netif sl_netif; #define UART_SLIP_CMD_MSG_READ_DATA 0x01 #define UART_SLIP_CMD_MSG_FLUSH_DATA 0x02 static unsigned long g_slip_cmd_queue; -#define MAX_BUFFER_SIZE (64) +#define MAX_BUFFER_SIZE (128) typedef struct { uint8_t cmd; uint32_t size; @@ -58,6 +58,8 @@ void do_uart_slip_cmd(int cmd,uint8_t *buffer,uint32_t size) memcpy_s(mail.buffer,MAX_BUFFER_SIZE,buffer,size); mail.cmd = cmd; mail.size = size; + // unsigned int quesize=osal_msg_queue_get_msg_num(g_slip_cmd_queue); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"do_uart_slip_cmd quesize %d\n",quesize); ret = osal_msg_queue_write_copy(g_slip_cmd_queue, (void *)&mail, sizeof(slip_uart_cmd_t), 0); if (ret != OSAL_SUCCESS) { @@ -147,9 +149,9 @@ void slip_receive_handler(uint8_t *buffer, int32_t size) do_uart_slip_cmd(UART_SLIP_CMD_MSG_READ_DATA,buffer,size); } -#define SLIP_CMD_TASK_MSG_COUNT 16 -#define SLIP_CMD_TASK_SIZE 0x100 -#define SLIP_CMD_TASK_PRIO 5 +#define SLIP_CMD_TASK_MSG_COUNT 512 +#define SLIP_CMD_TASK_SIZE (0x800*2) +#define SLIP_CMD_TASK_PRIO 4 int slip_uart_init(void) { diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index aaffb266c..e6f4b320f 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -261,18 +261,7 @@ errcode_t uapi_set_time_from_cat1(char* cat1time) settimeofday(&tv, &tz); - time_t rawtime; - struct tm* timeinfo; - time(&rawtime); - timeinfo = localtime(&rawtime); - - printf("set time success %04d-%02d-%02d %02d:%02d:%02d %d\n", - timeinfo->tm_year + 1900, - timeinfo->tm_mon + 1, - timeinfo->tm_mday, - timeinfo->tm_hour, - timeinfo->tm_min, - timeinfo->tm_sec,zone); + }else{ printf("convert to time failed ret %d!\n",ret); @@ -280,6 +269,21 @@ errcode_t uapi_set_time_from_cat1(char* cat1time) } + time_t rawtime; + struct tm* timeinfo; + time(&rawtime); + timeinfo = localtime(&rawtime); + + printf("set time success %04d-%02d-%02d %02d:%02d:%02d %d\n", + timeinfo->tm_year + 1900, + timeinfo->tm_mon + 1, + timeinfo->tm_mday, + timeinfo->tm_hour, + timeinfo->tm_min, + timeinfo->tm_sec,zone); + + if (timeinfo->tm_year+1900 < 2024) + return ERRCODE_FAIL; return ERRCODE_SUCC; } diff --git a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c index ea9416ce2..cbc6aeef4 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c @@ -87,9 +87,66 @@ static uint32_t custom_utils_getsn(uint8_t *para, uint32_t paraLen, char *strCom PRINT("get sn len %d , %s , ret = 0x%X\r\n",len,sn_buf,ret); return 0; } + + +#include "lwip/apps/http_client.h" +void httpc_download_result(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, u32_t srv_res, err_t err) +{ + PRINT("httpc_download_result , httpc_result_t %d, rx_content_len %d , srv_res %d, err %d\n", + httpc_result,rx_content_len,srv_res,err); + return ; +} + +err_t httpc_download_headers_done(httpc_state_t *connection, void *arg, struct pbuf *hdr, u16_t hdr_len, u32_t content_len) +{ + PRINT("httpc_download_headers_done , hdr_len %d ,content_len %d\n",hdr_len,content_len); + return 0; +} + +static uint32_t custom_start_ota_download(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + + uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != CUSTOM_UTILS_SUCCESS) { + PRINT("CUSTOM_UTILSTEST ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + + if (argc != 2) { + PRINT("CUSTOM_UTILSTEST ATCMD Set Parameter Failed argc %d\n",argc); + return ERRCODE_FAIL; + } + + + uint8_t *uri = (uint8_t*)argv[0]; + uint8_t *otadatapath = (uint8_t*)argv[1]; + PRINT("custom_start_ota_download %s to %s\r\n",uri,otadatapath); + httpc_connection_t settings = {0}; + settings.result_fn=httpc_download_result; + settings.headers_done_fn=httpc_download_headers_done; + httpc_state_t* connection=NULL; + err_t rett = httpc_get_file_dns_to_disk( + (const char*) "icfota.snicker.com.cn", + 8089, + (const char*) uri, + (const httpc_connection_t *)&settings, + NULL, + (const char*) otadatapath, + &connection); + + PRINT("custom_start_ota_download %d \r\n",rett); + return ERRCODE_SUCC; +} + + static const at_cmd_table_t g_custom_utils_cmd[] = { { (char *)"AT^CUSTOM_SN", custom_utils_setsn, (char *)"123456789ABCDEF2345678" }, { (char *)"AT^CUSTOM_SN_REQ", custom_utils_getsn, (char *)" " }, + { (char *)"AT^DOWNLOADOTA", custom_start_ota_download, (char *)" " }, { (char *)"AT^STARTOTA", custom_start_ota, (char *)" " }, }; diff --git a/code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt b/code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt index ab65c2afe..86f127385 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt +++ b/code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt @@ -71,7 +71,6 @@ set(SOURCES ${lwipcore6_SRCS} ${lwipsntp_SRCS} ${lwipmbedtls_SRCS} - # ${lwiphttp_SRCS} ${lwiphttp_SRCS} ${lwipport_SRCS} ${lwiptest_SRCS} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/lwipopts.h b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/lwipopts.h index 650447d02..f542bbff5 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/lwipopts.h +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/lwipopts.h @@ -250,4 +250,6 @@ #define LWIP_SOCKET_IOCTL 0 #define LWIP_SOCKET_FCNTL 0 +#define LWIP_HTTPC_HAVE_FILE_IO 1 + #endif /* _LWIP_PORTING_LWIPOPTS_H_ */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/src/apps/http/http_client.c b/code/sdk/open_source/openharmony/third_party/lwip/src/apps/http/http_client.c index 82da60d73..ae2f4e5c0 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/src/apps/http/http_client.c +++ b/code/sdk/open_source/openharmony/third_party/lwip/src/apps/http/http_client.c @@ -85,7 +85,7 @@ #define HTTPC_DEBUG_SERIOUS (HTTPC_DEBUG | LWIP_DBG_LEVEL_SERIOUS) #define HTTPC_POLL_INTERVAL 1 -#define HTTPC_POLL_TIMEOUT 30 /* 15 seconds */ +#define HTTPC_POLL_TIMEOUT 60 /* 15 seconds */ #define HTTPC_CONTENT_LEN_INVALID 0xFFFFFFFF