更新checkota.py到V7,支持多个python文件一起更新。 188/1 188/head 190/target/1
authorSnickerSun <snickersun@163.com>
Wed, 29 May 2024 08:19:54 +0000 (16:19 +0800)
committerSnickerSun <snickersun@163.com>
Wed, 29 May 2024 08:19:54 +0000 (16:19 +0800)
修复imei解析错误问题

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/checkota.pyV3 [new file with mode: 0644]
code/sdk/drivers/peripheral/slip/cat1Service/pyscript/update.json

index f4870d6..9ac12cb 100644 (file)
@@ -386,14 +386,14 @@ static int decodeNetStat(char* msg)
     }else{
         return -2;
     }
-    char* p = MSG_SPLIT_CHAR;
+    char* p = MSG_SPLIT_CHAR2;
     switch(g_py_ver)
     {
+        case 4:
+            p = MSG_SPLIT_CHAR;
+            break;
         case 5:
         case 6:
-            p = MSG_SPLIT_CHAR2;
-            break;
-        case 4:
         default:
             break;
     }
index c44606e..bf7f36a 100644 (file)
@@ -71,7 +71,7 @@ sms.setCallback(msg_cb)#sms注册回调
 CAT1_SERVICE_HEAD = 'FE' #固定head 
 
 PROJECT_NAME = "Cat1SlipUDPService"
-PROJECT_VERSION = "PY_SRV_V6"
+PROJECT_VERSION = "PY_SRV_V7"
 CONFIG_JSON="/usr/system_config.json"
 CURRENT_APP_TYPE="pysrv"
 
index 56bee95..e3abcdd 100644 (file)
@@ -14,7 +14,7 @@ import utime
 import log
 import uos
 
-PROJECT_VERSION="PY_OTA_V3"
+PROJECT_VERSION="PY_OTA_V7"
 CONFIG_JSON="/usr/system_config.json"
 CURRENT_APP_TYPE="pyota"
 # 设置日志输出级别
@@ -26,12 +26,9 @@ 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"
+    if (app_type == "pyota"):
+        return  "PY_OTA_V7"
+    
 
 #如果没有configfile则创建它
 if not ql_fs.path_exists(CONFIG_JSON):
@@ -89,23 +86,24 @@ def do_app_update_internal(app_type):
     print(url)
     data = response.json()
     if(data['UptoDate'] == False):
-        print("Need update python application")
-        srcurl = data['url']
-        fota_log.info("run start...")
-        targetpyname = data['OtaPackageName']
-        version = data['OtaPackageVersion']
-        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(targetfile_path, tmpfile_path)
-            set_version_to_json_config(app_type,version)
-            # fota.set_update_flag() # 设置升级标志
-            # Power.powerRestart() # 重启
+        print("Need update python application {}".format(data["appcount"]))        
+        for app_update in data["apps"]:
+            srcurl = app_update['url']
+            fota_log.info("run start...")
+            targetpyname = app_update['OtaPackageName']
+            version = app_update['OtaPackageVersion']
+            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(targetfile_path, tmpfile_path)
+                set_version_to_json_config(app_type,version)
+                # fota.set_update_flag() # 设置升级标志
+                Power.powerRestart() # 重启
         else:
             print("ota failed")
     else:
@@ -116,9 +114,7 @@ if __name__ == '__main__':
     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))
diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/checkota.pyV3 b/code/sdk/drivers/peripheral/slip/cat1Service/pyscript/checkota.pyV3
new file mode 100644 (file)
index 0000000..56bee95
--- /dev/null
@@ -0,0 +1,128 @@
+import app_fota
+from misc import Power
+import modem
+import ujson
+import request
+import ql_fs
+import checkNet
+import sys
+
+#远程升级
+
+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()
+    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:
+        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)
+    data = response.json()
+    if(data['UptoDate'] == False):
+        print("Need update python application")
+        srcurl = data['url']
+        fota_log.info("run start...")
+        targetpyname = data['OtaPackageName']
+        version = data['OtaPackageVersion']
+        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(targetfile_path, tmpfile_path)
+            set_version_to_json_config(app_type,version)
+            # fota.set_update_flag() # 设置升级标志
+            # Power.powerRestart() # 重启
+        else:
+            print("ota failed")
+    else:
+        print("No need update python application")
+
+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)
+# print('总ext空间:{} MB,剩余空间:{} MB'.format((((res[0] * res[2]) / 1024 / 1024)),((res[0] * res[3]) / 1024 / 1024)))
\ No newline at end of file
index fbb99c9..4b55ac2 100644 (file)
@@ -1,11 +1,42 @@
+{
+       "UptoDate": true ,
+       "url" : "http://icfota.snicker.com.cn:8089/FD230/PY_OTA_V3/checkota.py",
+       "OtaPackageLength" : 1809362,
+       "OtaPackageName" : "checkota.py",
+       "OtaPackageVersion" : "PY_OTA_V7",
+       "md5sum" : "7d8b35e58ad8ca5eb0ef031c101e375e",
+       "SystemVersion" : "PY_OTA_V4",
+       "description" : " update to checkota version 7 ",
+       "AutoUpdate" : true ,
+       "appcount": 5 ,
+       "apps":[
                {
-               "UptoDate": true,
-               "url" : "http://icfota.snicker.com.cn:8089/FD230/V1/cat1Service.py",
-               "OtaPackageLength" : 1809362,
-               "OtaPackageName" : "cat1Service.py",
-               "OtaPackageVersion" : "V2",
-               "SystemVersion" : "V1",
-               "description" : " update to new cat1 Service ",
-               "md5sum" : "7d8b35e58ad8ca5eb0ef031c101e375e",
-               "AutoUpdate" : true
+                       "url" : "http://icfota.snicker.com.cn:8089/FD230/PY_OTA_V3/cat1Service.py",
+                       "OtaPackageLength" : 1809362,
+                       "OtaPackageName" : "cat1Service.py",
+                       "OtaPackageVersion" : "PY_SRV_V7",
+                       "md5sum" : "7d8b35e58ad8ca5eb0ef031c101e375e"
+               },      
+               {
+                       "url" : "http://icfota.snicker.com.cn:8089/FD230/PY_OTA_V3/EventMesh.py",
+                       "OtaPackageLength" : 1809362,
+                       "OtaPackageName" : "EventMesh.py",
+                       "OtaPackageVersion" : "PY_EVENT_V7",
+                       "md5sum" : "7d8b35e58ad8ca5eb0ef031c101e375e"
+               },      
+               {
+                       "url" : "http://icfota.snicker.com.cn:8089/FD230/PY_OTA_V3/telecom_dmp.py",
+                       "OtaPackageLength" : 1809362,
+                       "OtaPackageName" : "telecom_dmp.py",
+                       "OtaPackageVersion" : "PY_TELECOM_V7",
+                       "md5sum" : "7d8b35e58ad8ca5eb0ef031c101e375e"
+               },      
+               {
+                       "url" : "http://icfota.snicker.com.cn:8089/FD230/PY_OTA_V3/checkota.py",
+                       "OtaPackageLength" : 1809362,
+                       "OtaPackageName" : "checkota.py",
+                       "OtaPackageVersion" : "PY_OTA_V7",
+                       "md5sum" : "7d8b35e58ad8ca5eb0ef031c101e375e"
                }
+       ]
+}