更新Cat1脚本,固件,验证通过Cat1各种升级功能。脚本可以自行升级,CAT1固件需要通过蓝牙发送指令升级。
authorSnickerSun <snickersun@163.com>
Thu, 14 Mar 2024 14:33:13 +0000 (22:33 +0800)
committerSnickerSun <snickersun@163.com>
Thu, 14 Mar 2024 14:33:13 +0000 (22:33 +0800)
code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.cpp
code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp
code/sdk/drivers/peripheral/slip/cat1Service/pyscript/cat1Service.py
code/sdk/drivers/peripheral/slip/cat1Service/pyscript/checkota.py
code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/EG810MCNLAR06A01M08_VOLTE_OCPU_QPY_BETA0312_20240314-2201.zip [moved from code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/EG810MCNLAR06A01M08_VOLTE_OCPU_QPY_BETA0312_20240314-1202.zip with 99% similarity]
code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/V2-V3-ota/customer_fs.bin [new file with mode: 0644]
code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/V2-V3-ota/dfota_1.bin [new file with mode: 0644]
code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/V2-V3-ota/dfota_2.bin [new file with mode: 0644]
code/sdk/drivers/peripheral/slip/cat1Service/pyscript/main.py

index b066fa3..5dc8529 100644 (file)
@@ -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_checkota(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    UNUSED(strCommonCmd);
+    printf("CAT1TEST ATCMD  cat1 checkota\n");
+    cat1_ota_update("0");
+    return ERRCODE_SUCC;
+}
 static uint32_t AT_cat1_reset_network(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
 {
     UNUSED(strCommonCmd);
@@ -246,6 +253,7 @@ static const at_cmd_table_t g_cat1_cmd[] = {
     { (char *)"AT^IFCONFIG",      cat1_ifconfig, (char *)"1" },
     { (char *)"AT^CAT1GETVER",      at_cat1_getver, (char *)"1" },
     { (char *)"AT^CAT1RESETNETWORK",      AT_cat1_reset_network, (char *)"1" },
+    { (char *)"AT^CAT1OTA",      AT_cat1_checkota, (char *)"1" },
        { (char *)"AT^CALL_1",      AT_CALL_ifconfig, (char *)"1" },
 
 };
index 8d5bc9e..a835113 100644 (file)
@@ -360,8 +360,12 @@ static int udp_packet_parse(char *rx_buffer, int len)
             case UDP_MSG_CALL_DISCONNECTED:
                            index = cat1_handle_call_disconnected(msg);
                 break;
+            case UDP_CMD_CAT1_OTA_UPDATE:
+                printf("CAT1_OTA_UPDATE reply %s",msg->buffer);
+                break;
             case UDP_MSG_REPLY:
-
+                printf("UDP_MSG_REPLY reply %s",msg->buffer);
+                
                 break;
                    default:
                            printf("error message: %s\n", rx_buffer);
index a0cacdc..c514dba 100644 (file)
@@ -45,14 +45,56 @@ import modem
 import utime
 import checkNet
 import atcmd
-
+import fota
+import request
+import ql_fs
 
 PROJECT_NAME = "Cat1SlipUDPService"
-PROJECT_VERSION = "V3"
+PROJECT_VERSION = "PY_SRV_V3"
+CONFIG_JSON="/usr/system_config.json"
+CURRENT_APP_TYPE="pysrv"
+
 
 # 设置日志输出级别
 log.basicConfig(level=log.INFO)
 cat1service_log = log.getLogger("cat1service")
+
+
+
+
+def get_versionkeyname_by_py(app_type):
+    return str("{}version".format(app_type))
+
+def get_default_versionvalue_by_py(app_type):
+    if (app_type == "pymain"):
+        return "PY_MAIN_V2"
+    elif (app_type == "pyota"):
+        return  "PY_OTA_V2"
+    elif (app_type == "pysrv"):
+        return  "PY_SRV_V2"
+
+#如果没有configfile则创建它
+if not ql_fs.path_exists(CONFIG_JSON):
+    data = {str(get_versionkeyname_by_py(CURRENT_APP_TYPE)):get_default_versionvalue_by_py(CURRENT_APP_TYPE)}
+    ql_fs.touch(CONFIG_JSON,data)
+
+def set_version_to_json_config(app_type,keyvalue):
+    config_data = ql_fs.read_json(CONFIG_JSON)
+    config_data.update( {str(get_versionkeyname_by_py(app_type)):keyvalue})
+    ql_fs.touch(CONFIG_JSON, config_data)
+    cat1service_log.info("{}={}".format(get_versionkeyname_by_py(app_type),keyvalue))
+    cat1service_log.info("{}".format(config_data))
+
+def get_version_from_json_config(app_type):
+    config_data = ql_fs.read_json(CONFIG_JSON)
+    keyvalue = config_data.get( get_versionkeyname_by_py(app_type),get_default_versionvalue_by_py(app_type))
+    cat1service_log.info("{}={}".format(get_versionkeyname_by_py(app_type),keyvalue))
+    return keyvalue
+
+set_version_to_json_config(CURRENT_APP_TYPE,PROJECT_VERSION)
+    
+
+
 timer = osTimer()
 audio.set_qdai_cfg(1,0,0,1,0,0,1,1)
 
@@ -85,6 +127,37 @@ UDP_MSG_CALL_DISCONNECTED = 'B'        #  CAT1 电话挂断消息
 UDP_MSG_COMMING_CALL = 'C'       #  CAT1 来电消息,包含电话号
 UDP_MSG_REPLY = 'F'         # 返回值 
 
+
+
+def result(args):
+    print('download status:',args[0],'download process:',args[1])
+def download_fota_img( srcurl ):
+    fota_obj = fota()  # 创建Fota对象
+    cat1service_log.info("httpDownload... {} , {}".format("{}/dfota_1.bin".format(srcurl),"{}/dfota_2.bin".format(srcurl)))
+    res = fota_obj.httpDownload(url1="{}/dfota_1.bin".format(srcurl),url2="{}/dfota_2.bin".format(srcurl),callback=result)    
+    #差分升级FTP方式  
+    #res = fota_obj.httpDownload(url1="ftp://user:password@ip:port/fota.bin",callback=result) #其中user,password,ip,port需要填写具体使用的FTP服务器信息
+    if res != 0:
+        cat1service_log.error("httpDownload error")
+        
+def check_fota():
+    modem_ver = modem.getDevFwVersion()    
+    imei = modem.getDevImei()
+    url =  "http://icfota.snicker.com.cn:8089/fd230ota.jsp?product=FD230&pkgver={0}&imei={1}".format(modem_ver,imei)
+    response = request.get(url)
+    cat1service_log.info(url)
+    data = response.json()
+    if(data['UptoDate'] == False):
+        cat1service_log.info("Need update python application")
+        srcurl = data['url']
+        #差分升级方式
+        # res = fota_obj.httpDownload(url1="http://www.example.com/fota.bin",callback=result)    
+        # mini fota方式
+        return srcurl
+    else:
+        cat1service_log.info("No need update python application")
+        return ""
+
 class Cat1Service:
     AP = 0  # SLIP_INNER
     STA = 1 # SLIP_OUTER
@@ -129,7 +202,8 @@ class Cat1Service:
         if cmd == "F0":
             print(cmd)
             # UDP_CMD_GET_CAT1VER
-            self.reply_cmd('F0',PROJECT_VERSION)
+            modem_ver = modem.getDevFwVersion() 
+            self.reply_cmd('F0',"pyVer,{},modemVer,{}".format(PROJECT_VERSION,modem_ver))
         elif cmd == "F1":
             print("{}{}".format(cmd,parm))
             # UDP_CMD_DIAL_NUMB
@@ -144,8 +218,12 @@ class Cat1Service:
             voiceCall.callAnswer()
         elif cmd == "F4":
             print(cmd)
-            # UDP_CMD_CAT1_OTA_UPDATE
-            example.exec("/usr/checkota.py")
+            result = check_fota()
+            if result == "":
+                self.reply_cmd('F4',"no need update!")
+            else:
+                self.reply_cmd('F4',"start ota {} please wait...".format(result))
+            download_fota_img(result)
         elif cmd == "F5":
             print(cmd)
             # UDP_CMD_SEND_SMS
index d703fd6..56bee95 100644 (file)
@@ -7,20 +7,83 @@ import ql_fs
 import checkNet
 import sys
 
+#远程升级
 
-def do_fota_update():
-    fota = app_fota.new()
+import fota
+import utime
+import log
+import uos
+
+PROJECT_VERSION="PY_OTA_V3"
+CONFIG_JSON="/usr/system_config.json"
+CURRENT_APP_TYPE="pyota"
+# 设置日志输出级别
+log.basicConfig(level=log.INFO)
+fota_log = log.getLogger("Fota")
+
+
+def get_versionkeyname_by_py(app_type):
+    return str("{}version".format(app_type))
+
+def get_default_versionvalue_by_py(app_type):
+    if (app_type == "pymain"):
+        return "PY_MAIN_V2"
+    elif (app_type == "pyota"):
+        return  "PY_OTA_V2"
+    elif (app_type == "pysrv"):
+        return  "PY_SRV_V2"
+
+#如果没有configfile则创建它
+if not ql_fs.path_exists(CONFIG_JSON):
+    data = {str(get_versionkeyname_by_py(CURRENT_APP_TYPE)):get_default_versionvalue_by_py(CURRENT_APP_TYPE)}
+    ql_fs.touch(CONFIG_JSON,data)
+
+def set_version_to_json_config(app_type,keyvalue):
+    config_data = ql_fs.read_json(CONFIG_JSON)
+    config_data.update( {str(get_versionkeyname_by_py(app_type)):keyvalue})
+    ql_fs.touch(CONFIG_JSON, config_data)
+    fota_log.info("{}={}".format(get_versionkeyname_by_py(app_type),keyvalue))
+    fota_log.info("{}".format(config_data))
+
+def get_version_from_json_config(app_type):
+    config_data = ql_fs.read_json(CONFIG_JSON)
+    keyvalue = config_data.get( get_versionkeyname_by_py(app_type),get_default_versionvalue_by_py(app_type))
+    fota_log.info("{}={}".format(get_versionkeyname_by_py(app_type),keyvalue))
+    return keyvalue
+
+def result(args):
+    fota_log.info('download status:',args[0],'download process:',args[1])
+
+def check_fota():
+    modem_ver = modem.getDevFwVersion()    
     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"
+    url =  "http://icfota.snicker.com.cn:8089/fd230ota.jsp?product=FD230&pkgver={0}&imei={1}".format(modem_ver,imei)
+    response = request.get(url)
+    fota_log.info(url)
+    data = response.json()
+    if(data['UptoDate'] == False):
+        fota_log.info("Need update python application")
+        fota_obj = fota()  # 创建Fota对象
+        fota_log.info("httpDownload...")
+        srcurl = data['url']
+        #差分升级方式
+        # res = fota_obj.httpDownload(url1="http://www.example.com/fota.bin",callback=result)    
+        # mini fota方式
+        fota_log.info("{},{}".format("{}/dfota_1.bin".format(srcurl),"{}/dfota_2.bin".format(srcurl)))
+        res = fota_obj.httpDownload(url1="{}/dfota_1.bin".format(srcurl),url2="{}/dfota_2.bin".format(srcurl),callback=result)    
+        #差分升级FTP方式  
+        #res = fota_obj.httpDownload(url1="ftp://user:password@ip:port/fota.bin",callback=result) #其中user,password,ip,port需要填写具体使用的FTP服务器信息
+        if res != 0:
+            fota_log.error("httpDownload error")
+            return
+        fota_log.info("wait httpDownload update...")
     else:
-        pythonversion = "V1"
-
+        print("No need update python application")
+    
+def do_app_update_internal(app_type):
+    fota = app_fota.new()
+    imei = modem.getDevImei()
+    pythonversion=get_version_from_json_config(app_type)
     url =  "http://icfota.snicker.com.cn:8089/fd230ota.jsp?product=FD230&pkgver={0}&imei={1}".format(pythonversion,imei)
     response = request.get(url)
     print(url)
@@ -28,16 +91,19 @@ def do_fota_update():
     if(data['UptoDate'] == False):
         print("Need update python application")
         srcurl = data['url']
+        fota_log.info("run start...")
         targetpyname = data['OtaPackageName']
         version = data['OtaPackageVersion']
-        print("download {0} to /usr/{1}".format(srcurl,targetpyname))
+        tmpfile_path = "/usr/.updater/{}".format(targetpyname)
+        targetfile_path = "/usr/{}".format(targetpyname)
+        print("download {0} to {1}".format(srcurl,targetfile_path))
+        if ql_fs.path_exists(tmpfile_path):
+            uos.remove(tmpfile_path)
         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)
+            ql_fs.file_copy(targetfile_path, tmpfile_path)
+            set_version_to_json_config(app_type,version)
             # fota.set_update_flag() # 设置升级标志
             # Power.powerRestart() # 重启
         else:
@@ -45,13 +111,17 @@ def do_fota_update():
     else:
         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))
-
+if __name__ == '__main__':
+    set_version_to_json_config(CURRENT_APP_TYPE,PROJECT_VERSION)
+    stage, state = checkNet.waitNetworkReady(1)
+    if stage == 3 and state == 1:
+        print('Network connection successful.')
+        do_app_update_internal("pymain")
+        do_app_update_internal("pyota")
+        do_app_update_internal("pysrv")
+        # check_fota()
+    else:
+        print('Network connection failed, stage={}, state={}'.format(stage, state))
 
 # res = uos.statvfs("/usr")
 # res = list(res)
similarity index 99%
rename from code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/EG810MCNLAR06A01M08_VOLTE_OCPU_QPY_BETA0312_20240314-1202.zip
rename to code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/EG810MCNLAR06A01M08_VOLTE_OCPU_QPY_BETA0312_20240314-2201.zip
index 6dd34ff..6ffa782 100644 (file)
Binary files a/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/EG810MCNLAR06A01M08_VOLTE_OCPU_QPY_BETA0312_20240314-1202.zip and b/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/EG810MCNLAR06A01M08_VOLTE_OCPU_QPY_BETA0312_20240314-2201.zip differ
diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/V2-V3-ota/customer_fs.bin b/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/V2-V3-ota/customer_fs.bin
new file mode 100644 (file)
index 0000000..11e4540
Binary files /dev/null and b/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/V2-V3-ota/customer_fs.bin differ
diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/V2-V3-ota/dfota_1.bin b/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/V2-V3-ota/dfota_1.bin
new file mode 100644 (file)
index 0000000..4901ef7
Binary files /dev/null and b/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/V2-V3-ota/dfota_1.bin differ
diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/V2-V3-ota/dfota_2.bin b/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/V2-V3-ota/dfota_2.bin
new file mode 100644 (file)
index 0000000..df2d5ec
Binary files /dev/null and b/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/current_img/V2-V3-ota/dfota_2.bin differ
index dc557aa..5cbf4cb 100644 (file)
@@ -1,6 +1,43 @@
 import example
 import osTimer
+import ql_fs
+import log
 
+PROJECT_VERSION = "PY_MAIN_V3"
+CONFIG_JSON="/usr/system_config.json"
+CURRENT_APP_TYPE="pymain"
+
+
+# 设置日志输出级别
+log.basicConfig(level=log.INFO)
+cat1service_log = log.getLogger("pymain")
+
+
+def get_versionkeyname_by_py(app_type):
+    return str("{}version".format(app_type))
+
+def get_default_versionvalue_by_py(app_type):
+    if (app_type == "pymain"):
+        return "PY_MAIN_V2"
+    elif (app_type == "pyota"):
+        return  "PY_OTA_V2"
+    elif (app_type == "pysrv"):
+        return  "PY_SRV_V2"
+
+#如果没有configfile则创建它
+if not ql_fs.path_exists(CONFIG_JSON):
+    data = {str(get_versionkeyname_by_py(CURRENT_APP_TYPE)):get_default_versionvalue_by_py(CURRENT_APP_TYPE)}
+    ql_fs.touch(CONFIG_JSON,data)
+
+def set_version_to_json_config(app_type,keyvalue):
+    config_data = ql_fs.read_json(CONFIG_JSON)
+    config_data.update( {str(get_versionkeyname_by_py(app_type)):keyvalue})
+    ql_fs.touch(CONFIG_JSON, config_data)
+    cat1service_log.info("{}={}".format(get_versionkeyname_by_py(app_type),keyvalue))
+    cat1service_log.info("{}".format(config_data))
+
+set_version_to_json_config(CURRENT_APP_TYPE,PROJECT_VERSION)
+    
 def checkota_cb(arg):
     print("start checkota!!")
     example.exec('/usr/checkota.py')