From 8a9870e7a156e80c649489312407fbf17b961a8e Mon Sep 17 00:00:00 2001 From: zhutianhua Date: Sat, 13 Jun 2020 11:53:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E5=B8=83core(0035)=E5=92=8Cscript(2.2?= =?UTF-8?q?.8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/readme.txt | 5 +- core/release notes.txt | 30 +++++- script_LuaTask/demo/crypto/private.key | 27 +++++ script_LuaTask/demo/crypto/public.key | 9 ++ script_LuaTask/demo/crypto/testCrypto.lua | 36 ++++++- .../demo/gpio/gpioSingle/testGpioSingle.lua | 3 +- script_LuaTask/demo/mqtt/sync/readme.txt | 4 +- .../demo/mqtt/sync/sendWaitRecv/mqttInMsg.lua | 7 +- .../mqtt/sync/sendWaitRecv/mqttOutMsg.lua | 7 +- script_LuaTask/demo/socket/sync/readme.txt | 4 +- .../longConnection/socketInMsg.lua | 6 +- .../longConnection/socketOutMsg.lua | 7 +- .../longConnectionTransparent/socketInMsg.lua | 6 +- .../socketOutMsg.lua | 8 +- .../socketSsl/longConnection/socketInMsg.lua | 6 +- .../socketSsl/longConnection/socketOutMsg.lua | 8 +- script_LuaTask/demo/softdog/main.lua | 52 ++++++++++ script_LuaTask/demo/softdog/testSoftDog.lua | 43 ++++++++ script_LuaTask/doc/lib/index.html | 2 +- script_LuaTask/doc/lib/modules/aLiYun.html | 2 +- script_LuaTask/doc/lib/modules/aLiYunOta.html | 2 +- script_LuaTask/doc/lib/modules/agps.html | 2 +- script_LuaTask/doc/lib/modules/clib.html | 2 +- script_LuaTask/doc/lib/modules/common.html | 2 +- script_LuaTask/doc/lib/modules/console.html | 2 +- script_LuaTask/doc/lib/modules/errDump.html | 2 +- script_LuaTask/doc/lib/modules/gps.html | 2 +- script_LuaTask/doc/lib/modules/gpsv2.html | 2 +- script_LuaTask/doc/lib/modules/http.html | 2 +- script_LuaTask/doc/lib/modules/httpv2.html | 2 +- script_LuaTask/doc/lib/modules/lbsLoc.html | 2 +- script_LuaTask/doc/lib/modules/led.html | 2 +- script_LuaTask/doc/lib/modules/link.html | 2 +- script_LuaTask/doc/lib/modules/log.html | 2 +- script_LuaTask/doc/lib/modules/misc.html | 2 +- script_LuaTask/doc/lib/modules/mqtt.html | 25 ++--- script_LuaTask/doc/lib/modules/net.html | 2 +- script_LuaTask/doc/lib/modules/netLed.html | 2 +- script_LuaTask/doc/lib/modules/ntp.html | 2 +- script_LuaTask/doc/lib/modules/nvm.html | 2 +- script_LuaTask/doc/lib/modules/patch.html | 2 +- script_LuaTask/doc/lib/modules/pb.html | 2 +- script_LuaTask/doc/lib/modules/pins.html | 2 +- script_LuaTask/doc/lib/modules/pm.html | 2 +- script_LuaTask/doc/lib/modules/powerKey.html | 2 +- script_LuaTask/doc/lib/modules/ril.html | 2 +- script_LuaTask/doc/lib/modules/sim.html | 2 +- script_LuaTask/doc/lib/modules/sms.html | 4 +- script_LuaTask/doc/lib/modules/socket.html | 99 ++++++++++++++++++- script_LuaTask/doc/lib/modules/sys.html | 2 +- script_LuaTask/doc/lib/modules/update.html | 2 +- script_LuaTask/doc/lib/modules/utils.html | 2 +- script_LuaTask/lib/aLiYun.lua | 8 +- script_LuaTask/lib/errDump.lua | 4 + script_LuaTask/lib/http.lua | 40 ++++---- script_LuaTask/lib/link.lua | 28 ++++-- script_LuaTask/lib/misc.lua | 39 +++++--- script_LuaTask/lib/net.lua | 9 +- script_LuaTask/lib/pb.lua | 17 +++- script_LuaTask/lib/sms.lua | 72 +++++++------- script_LuaTask/lib/socket.lua | 64 +++++++++--- script_LuaTask/lib/sys.lua | 27 +++-- script_LuaTask/lib/update.lua | 4 +- script_LuaTask/release notes.txt | 9 ++ 64 files changed, 575 insertions(+), 204 deletions(-) create mode 100644 script_LuaTask/demo/crypto/private.key create mode 100644 script_LuaTask/demo/crypto/public.key create mode 100644 script_LuaTask/demo/softdog/main.lua create mode 100644 script_LuaTask/demo/softdog/testSoftDog.lua diff --git a/core/readme.txt b/core/readme.txt index 2674be0..9faeda9 100644 --- a/core/readme.txt +++ b/core/readme.txt @@ -5,7 +5,10 @@ Luat_VXXXX_ASR1802:不支持浮点数和math库 Luat_VXXXX_ASR1802_FLOAT:支持浮点数和math库 用户二次开发有两个分区可用,脚本区和文件系统区 -脚本区:通过Luatools烧写的所有文件,都存放在此区域,目前总空间为524KB,不同版本的core可能会有差异,以版本每次的更新记录为准 +脚本区:通过Luatools烧写的所有文件,都存放在此区域 + 0032版本之前的脚本总空间为524KB + 0032以及0032版本之后的脚本总空间为1MB + 文件系统区:程序运行过程中实时创建的文件都会存放在此区域,目前总空间为800多KB,不同版本的core可能会有差异,可通过rtos.get_fs_free_size()查询剩余的文件系统可用空间 diff --git a/core/release notes.txt b/core/release notes.txt index 70a8fcd..223c03b 100644 --- a/core/release notes.txt +++ b/core/release notes.txt @@ -1,4 +1,32 @@ -版本号:Luat_V0029_ASR1802_XXX.lod +版本号:Luat_V0035_ASR1802_XXX.lod +发布时间:2020/06/12 11:59 +修改记录: + (1)修正“socket连接服务器概率性无结果返回”的问题 + + +版本号:Luat_V0033_ASR1802_XXX.lod +发布时间:2020/04/21 10:30 +修改记录: + (1)修正“socket链接服务器失败”的问题 + (2)支持rtos.get_temperature获取芯片温度功能 + + +版本号:Luat_V0032_ASR1802_XXX.lod +发布时间:2020/04/21 10:30 +修改记录: + (1)修正“错误域名解析时,导致Lua被阻塞30秒”的问题 + (2)脚本区空间扩大为1M字节 + + +版本号:Luat_V0031_ASR1802_XXX.lod +发布时间:2020/03/19 22:37 +修改记录: + (1)优化“因为LTE协议版本低导致某些地方注册不上4G网络”的问题 + (2)支持usb at口在data和at功能之间的切换功能 + + + +版本号:Luat_V0029_ASR1802_XXX.lod 发布时间:2020/01/19 11:02 修改记录: (1)修正“aes des ecb 不填充加密可能导致死循环”重启的问题 diff --git a/script_LuaTask/demo/crypto/private.key b/script_LuaTask/demo/crypto/private.key new file mode 100644 index 0000000..ce62e87 --- /dev/null +++ b/script_LuaTask/demo/crypto/private.key @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAx0+zurC2NFWgULkhQ4rEAvPeNnuxBz/0kbjbhrGNlD0gLccO +ZdQHihJqwRdX2IuDDhienfNX+9qIeQgkf3owzp082k93I2ky/QLwNDvN9loDJ0Zv +eIk0kwwz9yJZqD1FIiFabO+DkSVx+e+26yIKQjnS0i0D3IulzOGulSt56OuIl0/a +/fgFWQqfMWoLL4cyBQBEFuQth0fTACTsY6XAQ3e2kshD0cMT3U55hJmCCbxFuJ+Q +WOgtUuLt1SqlqZoYo/rYNQj5yBc3fd9HKXzLvmoKUMxFIW6Ez/ddubPx6F4B0eyz +V3oZ8Fp6I4WsMDDoUxJIYQ1Z4Yg6l9lkwqdAzwIDAQABAoIBAQCdMAiJBfDM2XLz +9u16/SeVRItN4MM++nuBqY7IbaNA8+w67jA2sr+3bsruueA4Ed8r8NK3s0ECidjz +yy4ts0pmyK9DZUSKkt75l6WlLD1FOrwd73jeUSc7iXY6Q8b93kR1pGRSYZsbj7KR +8TILwu7gSAYyZ/oRp7j9Gke7sWwV+rdgQAwlI/0Pkv7pCFEfSLe0pdG60mt80s6O +tgW0m/xlCp+X20zmObh9DivBsera2hPUAVDM95pPaQLC2gxq2TD4BdglizcENLqA +Mp9djr/hT0DfLzBu5DxDtki3bwN+pDlH9yabU328iJn6e5Lx5sPUOKG/XZKQAmlq +ZTqIJl6hAoGBAOm7Tgfb0dZLAbycjPLW5SWagc/IYqlUHLs2RIMiGYWEFdTWEPNg +PSFHL8B5TX8h4TwCpm4nXimxouAwgxNCrKblpaEtZ5RSZ+cw1Dzf/jBoRFgOa842 +pmhWdZ2gIdnWcx1FNcig4csrnEtAg505zYPBpnVUJGFSdR+2woWVHRC3AoGBANpM +43YC6jtcNlxqNl3wCWH3k8ATAopGpuQSZ76VPCUHUwocjUoThbxtNwm4EY2xxjjc +41iqQFPGKcion3PeDwQ8o87fHkIgwx9DBcrMgB2CtWa+cFsICmVxOQTE/CSLFroh +oPtxLGWNWNewZAgFXhWm9uJ0SD812ML9TupJGoipAoGAQuxzqkJhsdcmNygoH3wy +fnLgCmuY/FzuIRinw1hnMFiim59zmQwMVNP6M0VIUEeWI0Wq+81f49ZOCZ06WrBz +mRIWO7ExgEGcKJFNo+SK9rdUIlZ2vcPeH+/pm2l3Z9VEfrQLc1fFbxQcm1tsk/8x +/jDbharDA+7FRIBi8DbC7L8CgYEAlxXL/6s4zeiePwvLoOw2sjUVb0Q459bKPuN2 +JfNHcyFEmaT1LKWiU60LAJECpRy64jQOrRj3+IMX/CaoZRr1LauCe/T0DjR6lzJd +2eP7b3E9d2SqgnZoK5lXKzPihrA1BJGtxxim74oKSQ1tzhdY7IdoK4brUcREx39l +lMUPtjECgYAnoVCSO2DWOIKg8L35rghUr3/LpNPqqoK8QwIh/iOK4LDOPXQzNgc2 +v3YzGQPKuk2cDXaRam+WtABFgZl2NTIGxct/AwQbu0LjGBsoQpJRcMjAIH46lEP+ +XuGVYywF+LxuRKfJCcdO0RudQ1BiB5sWuTH9jfoHZHyMSJKZ/re6lg== +-----END RSA PRIVATE KEY----- diff --git a/script_LuaTask/demo/crypto/public.key b/script_LuaTask/demo/crypto/public.key new file mode 100644 index 0000000..eec0e04 --- /dev/null +++ b/script_LuaTask/demo/crypto/public.key @@ -0,0 +1,9 @@ +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx0+zurC2NFWgULkhQ4rE +AvPeNnuxBz/0kbjbhrGNlD0gLccOZdQHihJqwRdX2IuDDhienfNX+9qIeQgkf3ow +zp082k93I2ky/QLwNDvN9loDJ0ZveIk0kwwz9yJZqD1FIiFabO+DkSVx+e+26yIK +QjnS0i0D3IulzOGulSt56OuIl0/a/fgFWQqfMWoLL4cyBQBEFuQth0fTACTsY6XA +Q3e2kshD0cMT3U55hJmCCbxFuJ+QWOgtUuLt1SqlqZoYo/rYNQj5yBc3fd9HKXzL +vmoKUMxFIW6Ez/ddubPx6F4B0eyzV3oZ8Fp6I4WsMDDoUxJIYQ1Z4Yg6l9lkwqdA +zwIDAQAB +-----END PUBLIC KEY----- diff --git a/script_LuaTask/demo/crypto/testCrypto.lua b/script_LuaTask/demo/crypto/testCrypto.lua index 712e005..00505c5 100644 --- a/script_LuaTask/demo/crypto/testCrypto.lua +++ b/script_LuaTask/demo/crypto/testCrypto.lua @@ -320,6 +320,39 @@ local function aesTest() log.info("testCrypto.decrypt",crypto.aes_decrypt("CTR","NONE",encodeStr,"12345678901234567890123456789012","1234567890666666")) end +--rsa算法测试 +local function rsaTest() + --local plainStr = "1234567890asdfghjklzxcvbnm" + local plainStr = "firmId=10015&model=zw-sp300&sn=W01201910300000108&version=1.0.0" + + --公钥加密(2048bit,这个bit与实际公钥的bit要保持一致) + local encryptStr = crypto.rsa_encrypt("PUBLIC_KEY",io.readFile("/lua/public.key"),2048,"PUBLIC_CRYPT",plainStr) + log.info("rsaTest.encrypt",encryptStr:toHex()) + --私钥解密(2048bit,这个bit与实际私钥的bit要保持一致) + local decryptStr = crypto.rsa_decrypt("PRIVATE_KEY",io.readFile("/lua/private.key"),2048,"PRIVATE_CRYPT",encryptStr) + log.info("rsaTest.decrypt",decryptStr) --此处的decryptStr应该与plainStr相同 + + + --私钥签名(2048bit,这个bit与实际私钥的bit要保持一致) + local signStr = crypto.rsa_sha256_sign("PRIVATE_KEY",io.readFile("/lua/private.key"),2048,"PRIVATE_CRYPT",plainStr) + log.info("rsaTest.signStr",signStr:toHex()) + --公钥验签(2048bit,这个bit与实际公钥的bit要保持一致) + local verifyResult = crypto.rsa_sha256_verify("PUBLIC_KEY",io.readFile("/lua/public.key"),2048,"PUBLIC_CRYPT",signStr,plainStr) + log.info("rsaTest.verify",verifyResult) + + + + --私钥解密某个客户的公钥加密密文 + encryptStr = string.fromHex("af750a8c95f9d973a033686488197cffacb8c1b2b5a15ea8779a48a72a1cdb2f9c948fe5ce0ac231a16de16b5fb609f62ec81c7646c1f018e333860627b5d4853cfe77f71ea7e4573323905faf0a759d59729d2afb80e46ff1f1b715227b599a14f3b9feb676f1feb1c2acd97f4d494124237a720ca781a16a2b600c17e348a5fdd3c374384276147b93ce93cc5a005a0aaf1581cdb7d58bfa84b4e4d7263efc02bf7ad80b15937ce8b37ced4e1ef8899be5c2a7d338cb5c4784c6b8a1cb31e7ecd1ec48597a02050b1190a3e13f2253a35e8cbc094c0af28b968f05a7f946a7a8cf3f9da2013d53ee51ca74279f8f36662e093b37db83caef5b18b666d405d4") + decryptStr = crypto.rsa_decrypt("PRIVATE_KEY",io.readFile("/lua/private.key"),2048,"PRIVATE_CRYPT",encryptStr) + log.info("rsaTest.decrypt",decryptStr) + + --公钥验签某个客户的私钥签名密文 + signStr = string.fromHex("7251fd625c01ac41e277d11b5b795962ba42d89a645eb9fe2241b2d8a9b6b5b6ea70e23e6933ef1324495749abde0e31eaf4fefe6d09f9270c0510790bd6075595717522539b7b70b798bdc216dae3873389644d73b04ecaeb01b25831904955a891d2459334a3f9f1e4558f7f99906c35f94c377f7f95cf0d3e062d8eb513fd723ad8b3981027b09126fbeb72d5fe4554a32b9c270f8f46032ede59387769b1fb090f0b4be15aaac2744a666dfbde7c04e02979f1c1b4e4c0f23c6bb9f60941312850caf41442d68ad7c9e939b7305ac6712ad31427f1c1d7b4f68001df9ce03367bd35e401a420f526aee3c96c2caaccb9a8db09b30930172b4c2847725d05") + verifyResult = crypto.rsa_sha256_verify("PUBLIC_KEY",io.readFile("/lua/public.key"),2048,"PUBLIC_CRYPT",signStr,"firmId=10015&model=zw-sp300&sn=W01201910300000108&version=1.0.0") + log.info("rsaTest.verifyResult customer",verifyResult) +end + --- 算法测试入口 -- @return local function cryptoTest() @@ -336,7 +369,8 @@ local function cryptoTest() hmacSha256Test() -- xxtea 需要lod打开支持 -- xxteaTest() + --pcall(rsaTest) print("test end") end -sys.timerStart(cryptoTest,2000) +sys.timerStart(cryptoTest,6000) diff --git a/script_LuaTask/demo/gpio/gpioSingle/testGpioSingle.lua b/script_LuaTask/demo/gpio/gpioSingle/testGpioSingle.lua index 8f098eb..3e7bc2f 100644 --- a/script_LuaTask/demo/gpio/gpioSingle/testGpioSingle.lua +++ b/script_LuaTask/demo/gpio/gpioSingle/testGpioSingle.lua @@ -45,7 +45,7 @@ getGpio54Fnc = pins.setup(pio.P1_22,gpio54IntFnc) pmd.ldoset(x,pmd.VLDO6) x=0时:关闭LDO x=1时:LDO输出1.8V -x=2时:LDO输出2.5V +x=2时:LDO输出1.9V x=3时:LDO输出2.5V x=4时:LDO输出2.8V x=5时:LDO输出2.9V @@ -53,3 +53,4 @@ x=6时:LDO输出3.1V x=7时:LDO输出3.3V x=8时:LDO输出1.7V ]] + diff --git a/script_LuaTask/demo/mqtt/sync/readme.txt b/script_LuaTask/demo/mqtt/sync/readme.txt index 9aa161a..bd27acd 100644 --- a/script_LuaTask/demo/mqtt/sync/readme.txt +++ b/script_LuaTask/demo/mqtt/sync/readme.txt @@ -1,2 +1,2 @@ -sendWaitRecvʱݣҪȵݳʱյݲŻݷͳȥ -sendInterruptRecvʱpublishϢжݽյ \ No newline at end of file +sendWaitRecvʾӦԷḻ +sendInterruptRecvʾӦԼ \ No newline at end of file diff --git a/script_LuaTask/demo/mqtt/sync/sendWaitRecv/mqttInMsg.lua b/script_LuaTask/demo/mqtt/sync/sendWaitRecv/mqttInMsg.lua index d480b3a..a99c0bb 100644 --- a/script_LuaTask/demo/mqtt/sync/sendWaitRecv/mqttInMsg.lua +++ b/script_LuaTask/demo/mqtt/sync/sendWaitRecv/mqttInMsg.lua @@ -14,19 +14,16 @@ module(...,package.seeall) function proc(mqttClient) local result,data while true do - result,data = mqttClient:receive(2000) + result,data = mqttClient:receive(60000,"APP_SOCKET_SEND_DATA") --接收到数据 if result then log.info("mqttInMsg.proc",data.topic,string.toHex(data.payload)) --TODO:根据需求自行处理data.payload - - --如果mqttOutMsg中有等待发送的数据,则立即退出本循环 - if mqttOutMsg.waitForSend() then return true end else break end end - return result or data=="timeout" + return result or data=="timeout" or data=="APP_SOCKET_SEND_DATA" end diff --git a/script_LuaTask/demo/mqtt/sync/sendWaitRecv/mqttOutMsg.lua b/script_LuaTask/demo/mqtt/sync/sendWaitRecv/mqttOutMsg.lua index ad4309a..d044956 100644 --- a/script_LuaTask/demo/mqtt/sync/sendWaitRecv/mqttOutMsg.lua +++ b/script_LuaTask/demo/mqtt/sync/sendWaitRecv/mqttOutMsg.lua @@ -13,6 +13,7 @@ local msgQueue = {} local function insertMsg(topic,payload,qos,user) table.insert(msgQueue,{t=topic,p=payload,q=qos,user=user}) + sys.publish("APP_SOCKET_SEND_DATA") end local function pubQos0TestCb(result) @@ -53,12 +54,6 @@ function unInit() end end ---- MQTT客户端是否有数据等待发送 --- @return 有数据等待发送返回true,否则返回false --- @usage mqttOutMsg.waitForSend() -function waitForSend() - return #msgQueue > 0 -end --- MQTT客户端数据发送处理 -- @param mqttClient,MQTT客户端对象 diff --git a/script_LuaTask/demo/socket/sync/readme.txt b/script_LuaTask/demo/socket/sync/readme.txt index 9aa161a..bd27acd 100644 --- a/script_LuaTask/demo/socket/sync/readme.txt +++ b/script_LuaTask/demo/socket/sync/readme.txt @@ -1,2 +1,2 @@ -sendWaitRecvʱݣҪȵݳʱյݲŻݷͳȥ -sendInterruptRecvʱpublishϢжݽյ \ No newline at end of file +sendWaitRecvʾӦԷḻ +sendInterruptRecvʾӦԼ \ No newline at end of file diff --git a/script_LuaTask/demo/socket/sync/sendWaitRecv/longConnection/socketInMsg.lua b/script_LuaTask/demo/socket/sync/sendWaitRecv/longConnection/socketInMsg.lua index e220f10..ae431d0 100644 --- a/script_LuaTask/demo/socket/sync/sendWaitRecv/longConnection/socketInMsg.lua +++ b/script_LuaTask/demo/socket/sync/sendWaitRecv/longConnection/socketInMsg.lua @@ -14,19 +14,17 @@ module(...,package.seeall) function proc(socketClient) local result,data while true do - result,data = socketClient:recv(2000) + result,data = socketClient:recv(60000,"APP_SOCKET_SEND_DATA") --接收到数据 if result then log.info("socketInMsg.proc",data) --TODO:根据需求自行处理data - --如果socketOutMsg中有等待发送的数据,则立即退出本循环 - if socketOutMsg.waitForSend() then return true end else break end end - return result or data=="timeout" + return result or data=="timeout" or data=="APP_SOCKET_SEND_DATA" end diff --git a/script_LuaTask/demo/socket/sync/sendWaitRecv/longConnection/socketOutMsg.lua b/script_LuaTask/demo/socket/sync/sendWaitRecv/longConnection/socketOutMsg.lua index 58827e8..175219c 100644 --- a/script_LuaTask/demo/socket/sync/sendWaitRecv/longConnection/socketOutMsg.lua +++ b/script_LuaTask/demo/socket/sync/sendWaitRecv/longConnection/socketOutMsg.lua @@ -13,6 +13,7 @@ local msgQueue = {} local function insertMsg(data,user) table.insert(msgQueue,{data=data,user=user}) + sys.publish("APP_SOCKET_SEND_DATA") end local function sndHeartCb(result) @@ -53,12 +54,6 @@ function unInit() end end ---- socket客户端是否有数据等待发送 --- @return 有数据等待发送返回true,否则返回false --- @usage socketOutMsg.waitForSend() -function waitForSend() - return #msgQueue > 0 -end --- socket客户端数据发送处理 -- @param socketClient,socket客户端对象 diff --git a/script_LuaTask/demo/socket/sync/sendWaitRecv/longConnectionTransparent/socketInMsg.lua b/script_LuaTask/demo/socket/sync/sendWaitRecv/longConnectionTransparent/socketInMsg.lua index bee1988..9388a06 100644 --- a/script_LuaTask/demo/socket/sync/sendWaitRecv/longConnectionTransparent/socketInMsg.lua +++ b/script_LuaTask/demo/socket/sync/sendWaitRecv/longConnectionTransparent/socketInMsg.lua @@ -14,19 +14,17 @@ module(...,package.seeall) function proc(socketClient) local result,data while true do - result,data = socketClient:recv(2000) + result,data = socketClient:recv(60000,"APP_SOCKET_SEND_DATA") --接收到数据 if result then log.info("socketInMsg.proc",data) sys.publish("SOCKET_RECV_DATA",data) - --如果socketOutMsg中有等待发送的数据,则立即退出本循环 - if socketOutMsg.waitForSend() then return true end else break end end - return result or data=="timeout" + return result or data=="timeout" or data=="APP_SOCKET_SEND_DATA" end diff --git a/script_LuaTask/demo/socket/sync/sendWaitRecv/longConnectionTransparent/socketOutMsg.lua b/script_LuaTask/demo/socket/sync/sendWaitRecv/longConnectionTransparent/socketOutMsg.lua index ad2411b..9f57831 100644 --- a/script_LuaTask/demo/socket/sync/sendWaitRecv/longConnectionTransparent/socketOutMsg.lua +++ b/script_LuaTask/demo/socket/sync/sendWaitRecv/longConnectionTransparent/socketOutMsg.lua @@ -13,6 +13,7 @@ local msgQueue = {} local function insertMsg(data,user) table.insert(msgQueue,{data=data,user=user}) + sys.publish("APP_SOCKET_SEND_DATA") end @@ -26,13 +27,6 @@ function unInit() end end ---- socket客户端是否有数据等待发送 --- @return 有数据等待发送返回true,否则返回false --- @usage socketOutMsg.waitForSend() -function waitForSend() - return #msgQueue > 0 -end - --- socket客户端数据发送处理 -- @param socketClient,socket客户端对象 -- @return 处理成功返回true,处理出错返回false diff --git a/script_LuaTask/demo/socketSsl/longConnection/socketInMsg.lua b/script_LuaTask/demo/socketSsl/longConnection/socketInMsg.lua index e220f10..ae431d0 100644 --- a/script_LuaTask/demo/socketSsl/longConnection/socketInMsg.lua +++ b/script_LuaTask/demo/socketSsl/longConnection/socketInMsg.lua @@ -14,19 +14,17 @@ module(...,package.seeall) function proc(socketClient) local result,data while true do - result,data = socketClient:recv(2000) + result,data = socketClient:recv(60000,"APP_SOCKET_SEND_DATA") --接收到数据 if result then log.info("socketInMsg.proc",data) --TODO:根据需求自行处理data - --如果socketOutMsg中有等待发送的数据,则立即退出本循环 - if socketOutMsg.waitForSend() then return true end else break end end - return result or data=="timeout" + return result or data=="timeout" or data=="APP_SOCKET_SEND_DATA" end diff --git a/script_LuaTask/demo/socketSsl/longConnection/socketOutMsg.lua b/script_LuaTask/demo/socketSsl/longConnection/socketOutMsg.lua index da0a1dc..ec4cb25 100644 --- a/script_LuaTask/demo/socketSsl/longConnection/socketOutMsg.lua +++ b/script_LuaTask/demo/socketSsl/longConnection/socketOutMsg.lua @@ -13,6 +13,7 @@ local msgQuene = {} local function insertMsg(data,user) table.insert(msgQuene,{data=data,user=user}) + sys.publish("APP_SOCKET_SEND_DATA") end local function sndGetCb(result) @@ -42,13 +43,6 @@ function unInit() end end ---- socket客户端是否有数据等待发送 --- @return 有数据等待发送返回true,否则返回false --- @usage socketOutMsg.waitForSend() -function waitForSend() - return #msgQuene > 0 -end - --- socket客户端数据发送处理 -- @param socketClient,socket客户端对象 -- @return 处理成功返回true,处理出错返回false diff --git a/script_LuaTask/demo/softdog/main.lua b/script_LuaTask/demo/softdog/main.lua new file mode 100644 index 0000000..297badd --- /dev/null +++ b/script_LuaTask/demo/softdog/main.lua @@ -0,0 +1,52 @@ +--必须在这个位置定义PROJECT和VERSION变量 +--PROJECT:ascii string类型,可以随便定义,只要不使用,就行 +--VERSION:ascii string类型,如果使用Luat物联云平台固件升级的功能,必须按照"X.X.X"定义,X表示1位数字;否则可随便定义 +PROJECT = "LUAT_SOFT_DOG" +VERSION = "1.0.0" + +--加载日志功能模块,并且设置日志输出等级 +--如果关闭调用log模块接口输出的日志,等级设置为log.LOG_SILENT即可 +require "log" +LOG_LEVEL = log.LOGLEVEL_TRACE +--[[ +如果使用UART输出日志,打开这行注释的代码"--log.openTrace(true,1,115200)"即可,根据自己的需求修改此接口的参数 +如果要彻底关闭脚本中的输出日志(包括调用log模块接口和Lua标准print接口输出的日志),执行log.openTrace(false,第二个参数跟调用openTrace接口打开日志的第二个参数相同),例如: +1、没有调用过sys.opntrace配置日志输出端口或者最后一次是调用log.openTrace(true,nil,921600)配置日志输出端口,此时要关闭输出日志,直接调用log.openTrace(false)即可 +2、最后一次是调用log.openTrace(true,1,115200)配置日志输出端口,此时要关闭输出日志,直接调用log.openTrace(false,1)即可 +]] +--log.openTrace(true,1,115200) + +require "sys" + +require "net" +--每1分钟查询一次GSM信号强度 +--每1分钟查询一次基站信息 +net.startQueryAll(60000, 60000) + +--加载控制台调试功能模块(此处代码配置的是uart2,波特率115200) +--此功能模块不是必须的,根据项目需求决定是否加载 +--使用时注意:控制台使用的uart不要和其他功能使用的uart冲突 +--使用说明参考demo/console下的《console功能使用说明.docx》 +--require "console" +--console.setup(2, 115200) + +--加载网络指示灯和LTE指示灯功能模块 +--根据自己的项目需求和硬件配置决定:1、是否加载此功能模块;2、配置指示灯引脚 +--合宙官方出售的Air720开发板上的网络指示灯引脚为pio.P2_0,LTE指示灯引脚为pio.P2_1 +require "netLed" +netLed.setup(true,pio.P2_0,pio.P2_1) +--网络指示灯功能模块中,默认配置了各种工作状态下指示灯的闪烁规律,参考netLed.lua中ledBlinkTime配置的默认值 +--如果默认值满足不了需求,此处调用netLed.updateBlinkTime去配置闪烁时长 +--LTE指示灯功能模块中,配置的是注册上4G网络,灯就常亮,其余任何状态灯都会熄灭 + +--加载错误日志管理功能模块【强烈建议打开此功能】 +--如下2行代码,只是简单的演示如何使用errDump功能,详情参考errDump的api +require "errDump" +errDump.request("udp://ota.airm2m.com:9072") + +--加载软狗功能测试模块 +require "testSoftDog" + +--启动系统框架 +sys.init(0, 0) +sys.run() diff --git a/script_LuaTask/demo/softdog/testSoftDog.lua b/script_LuaTask/demo/softdog/testSoftDog.lua new file mode 100644 index 0000000..c310e76 --- /dev/null +++ b/script_LuaTask/demo/softdog/testSoftDog.lua @@ -0,0 +1,43 @@ +--- 模块功能:软狗功能测试 +-- @author openLuat +-- @module testSoftDog +-- @license MIT +-- @copyright openLuat +-- @release 2019.11.26 + +module(...,package.seeall) + +--[[ +函数名:eatSoftDog +功能 :喂狗 +参数 :无 +返回值:无 +]] +function eatSoftDog() + print("eatSoftDog test") + rtos.eatSoftDog() +end + +--[[ +函数名:closeSoftDog +功能 :关闭软狗 +参数 :无 +返回值:无 +]] +function closeSoftDog() + print("closeSoftDog test") + sys.timerStop(eatSoftDog) + rtos.closeSoftDog() +end + +--打开并设置软狗超时时间单位MS,超过设置时间没去喂狗,重启模块 +rtos.openSoftDog(60*1000) + +--定时喂狗 +sys.timerLoopStart(eatSoftDog,50*1000) + +--关闭软狗 +sys.timerStart(closeSoftDog,180*1000) + +--打印版本号 +sys.timerLoopStart(log.info,2000,rtos.get_version(),_G.VERSION) diff --git a/script_LuaTask/doc/lib/index.html b/script_LuaTask/doc/lib/index.html index 32c2add..6ddf626 100644 --- a/script_LuaTask/doc/lib/index.html +++ b/script_LuaTask/doc/lib/index.html @@ -213,7 +213,7 @@

Modules

generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
diff --git a/script_LuaTask/doc/lib/modules/aLiYun.html b/script_LuaTask/doc/lib/modules/aLiYun.html index 9f53423..e62ee3e 100644 --- a/script_LuaTask/doc/lib/modules/aLiYun.html +++ b/script_LuaTask/doc/lib/modules/aLiYun.html @@ -410,7 +410,7 @@

Usage:

generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
diff --git a/script_LuaTask/doc/lib/modules/aLiYunOta.html b/script_LuaTask/doc/lib/modules/aLiYunOta.html index 0dcb66c..94aa1dd 100644 --- a/script_LuaTask/doc/lib/modules/aLiYunOta.html +++ b/script_LuaTask/doc/lib/modules/aLiYunOta.html @@ -225,7 +225,7 @@

Usage:

generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
diff --git a/script_LuaTask/doc/lib/modules/agps.html b/script_LuaTask/doc/lib/modules/agps.html index f9b3db2..8a84f9d 100644 --- a/script_LuaTask/doc/lib/modules/agps.html +++ b/script_LuaTask/doc/lib/modules/agps.html @@ -106,7 +106,7 @@

Info:

generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
diff --git a/script_LuaTask/doc/lib/modules/clib.html b/script_LuaTask/doc/lib/modules/clib.html index 2fc059c..a75ae21 100644 --- a/script_LuaTask/doc/lib/modules/clib.html +++ b/script_LuaTask/doc/lib/modules/clib.html @@ -157,7 +157,7 @@

Usage:

generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
diff --git a/script_LuaTask/doc/lib/modules/common.html b/script_LuaTask/doc/lib/modules/common.html index 8390825..0151af5 100644 --- a/script_LuaTask/doc/lib/modules/common.html +++ b/script_LuaTask/doc/lib/modules/common.html @@ -715,7 +715,7 @@

Usage:

generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
diff --git a/script_LuaTask/doc/lib/modules/console.html b/script_LuaTask/doc/lib/modules/console.html index c6cb6a4..8e6fd19 100644 --- a/script_LuaTask/doc/lib/modules/console.html +++ b/script_LuaTask/doc/lib/modules/console.html @@ -154,7 +154,7 @@

Usage:

generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
diff --git a/script_LuaTask/doc/lib/modules/errDump.html b/script_LuaTask/doc/lib/modules/errDump.html index 00e91ef..1fca989 100644 --- a/script_LuaTask/doc/lib/modules/errDump.html +++ b/script_LuaTask/doc/lib/modules/errDump.html @@ -267,7 +267,7 @@

Usage:

generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
diff --git a/script_LuaTask/doc/lib/modules/gps.html b/script_LuaTask/doc/lib/modules/gps.html index e19d014..96f02b1 100644 --- a/script_LuaTask/doc/lib/modules/gps.html +++ b/script_LuaTask/doc/lib/modules/gps.html @@ -1279,7 +1279,7 @@

Fields

generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
diff --git a/script_LuaTask/doc/lib/modules/gpsv2.html b/script_LuaTask/doc/lib/modules/gpsv2.html index ad5337e..37981c0 100644 --- a/script_LuaTask/doc/lib/modules/gpsv2.html +++ b/script_LuaTask/doc/lib/modules/gpsv2.html @@ -951,7 +951,7 @@

Parameters:

generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
diff --git a/script_LuaTask/doc/lib/modules/http.html b/script_LuaTask/doc/lib/modules/http.html index ce3a962..a0e46d7 100644 --- a/script_LuaTask/doc/lib/modules/http.html +++ b/script_LuaTask/doc/lib/modules/http.html @@ -228,7 +228,7 @@

Usage:

generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
diff --git a/script_LuaTask/doc/lib/modules/httpv2.html b/script_LuaTask/doc/lib/modules/httpv2.html index ba213ed..fca55d8 100644 --- a/script_LuaTask/doc/lib/modules/httpv2.html +++ b/script_LuaTask/doc/lib/modules/httpv2.html @@ -181,7 +181,7 @@

Usage:

generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
diff --git a/script_LuaTask/doc/lib/modules/lbsLoc.html b/script_LuaTask/doc/lib/modules/lbsLoc.html index 599e10b..0ae92af 100644 --- a/script_LuaTask/doc/lib/modules/lbsLoc.html +++ b/script_LuaTask/doc/lib/modules/lbsLoc.html @@ -199,7 +199,7 @@

Usage:

generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
diff --git a/script_LuaTask/doc/lib/modules/led.html b/script_LuaTask/doc/lib/modules/led.html index 7622019..47da77c 100644 --- a/script_LuaTask/doc/lib/modules/led.html +++ b/script_LuaTask/doc/lib/modules/led.html @@ -248,7 +248,7 @@

Usage:

generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
diff --git a/script_LuaTask/doc/lib/modules/link.html b/script_LuaTask/doc/lib/modules/link.html index 3157797..7a2bf14 100644 --- a/script_LuaTask/doc/lib/modules/link.html +++ b/script_LuaTask/doc/lib/modules/link.html @@ -165,7 +165,7 @@

Usage:

generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
diff --git a/script_LuaTask/doc/lib/modules/log.html b/script_LuaTask/doc/lib/modules/log.html index 4c72dc3..1361649 100644 --- a/script_LuaTask/doc/lib/modules/log.html +++ b/script_LuaTask/doc/lib/modules/log.html @@ -393,7 +393,7 @@

Usage:

generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
diff --git a/script_LuaTask/doc/lib/modules/misc.html b/script_LuaTask/doc/lib/modules/misc.html index cf2b70d..0162ac7 100644 --- a/script_LuaTask/doc/lib/modules/misc.html +++ b/script_LuaTask/doc/lib/modules/misc.html @@ -547,7 +547,7 @@

Returns:

generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
diff --git a/script_LuaTask/doc/lib/modules/mqtt.html b/script_LuaTask/doc/lib/modules/mqtt.html index 86452a9..acb78f0 100644 --- a/script_LuaTask/doc/lib/modules/mqtt.html +++ b/script_LuaTask/doc/lib/modules/mqtt.html @@ -99,7 +99,7 @@

Functions

- mqttc:connect (host, port[, transport="tcp"][, cert=nil]) + mqttc:connect (host, port[, transport="tcp"][, cert=nil], timeout) 连接mqtt服务器 @@ -123,7 +123,7 @@

Functions

- mqttc:receive ([timeout=0][, msg=nil]) + mqttc:receive (timeout[, msg=nil]) 接收消息 @@ -210,7 +210,7 @@

Usage:

- mqttc:connect (host, port[, transport="tcp"][, cert=nil]) + mqttc:connect (host, port[, transport="tcp"][, cert=nil], timeout)
@@ -242,6 +242,10 @@

Parameters:

clientPassword = "123456", --客户端证书文件密码[可选] } +
  • timeout + number +
     链接服务器最长超时时间
    +
  • Returns:

    @@ -254,7 +258,7 @@

    Returns:

    Usage:

    @@ -377,7 +381,7 @@

    Usage:

    - mqttc:receive ([timeout=0][, msg=nil]) + mqttc:receive (timeout[, msg=nil])
    @@ -388,8 +392,7 @@

    Parameters:

    @@ -453,7 +456,7 @@

    Usage:

    generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
    diff --git a/script_LuaTask/doc/lib/modules/net.html b/script_LuaTask/doc/lib/modules/net.html index d6e0924..c577fbc 100644 --- a/script_LuaTask/doc/lib/modules/net.html +++ b/script_LuaTask/doc/lib/modules/net.html @@ -689,7 +689,7 @@

    Usage:

    generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
    diff --git a/script_LuaTask/doc/lib/modules/netLed.html b/script_LuaTask/doc/lib/modules/netLed.html index ed9a84b..350b5a7 100644 --- a/script_LuaTask/doc/lib/modules/netLed.html +++ b/script_LuaTask/doc/lib/modules/netLed.html @@ -202,7 +202,7 @@

    Usage:

    generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
    diff --git a/script_LuaTask/doc/lib/modules/ntp.html b/script_LuaTask/doc/lib/modules/ntp.html index 081eea8..6a65c22 100644 --- a/script_LuaTask/doc/lib/modules/ntp.html +++ b/script_LuaTask/doc/lib/modules/ntp.html @@ -311,7 +311,7 @@

    Usage:

    generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
    diff --git a/script_LuaTask/doc/lib/modules/nvm.html b/script_LuaTask/doc/lib/modules/nvm.html index 9069b5f..3a989dd 100644 --- a/script_LuaTask/doc/lib/modules/nvm.html +++ b/script_LuaTask/doc/lib/modules/nvm.html @@ -418,7 +418,7 @@

    Usage:

    generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
    diff --git a/script_LuaTask/doc/lib/modules/patch.html b/script_LuaTask/doc/lib/modules/patch.html index aad4151..0106d0f 100644 --- a/script_LuaTask/doc/lib/modules/patch.html +++ b/script_LuaTask/doc/lib/modules/patch.html @@ -96,7 +96,7 @@

    Info:

    generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
    diff --git a/script_LuaTask/doc/lib/modules/pb.html b/script_LuaTask/doc/lib/modules/pb.html index 768b313..405f902 100644 --- a/script_LuaTask/doc/lib/modules/pb.html +++ b/script_LuaTask/doc/lib/modules/pb.html @@ -281,7 +281,7 @@

    Usage:

    generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
    diff --git a/script_LuaTask/doc/lib/modules/pins.html b/script_LuaTask/doc/lib/modules/pins.html index 150179e..15e672d 100644 --- a/script_LuaTask/doc/lib/modules/pins.html +++ b/script_LuaTask/doc/lib/modules/pins.html @@ -201,7 +201,7 @@

    Usage:

    generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
    diff --git a/script_LuaTask/doc/lib/modules/pm.html b/script_LuaTask/doc/lib/modules/pm.html index ec6de39..a211db1 100644 --- a/script_LuaTask/doc/lib/modules/pm.html +++ b/script_LuaTask/doc/lib/modules/pm.html @@ -219,7 +219,7 @@

    Usage:

    generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
    diff --git a/script_LuaTask/doc/lib/modules/powerKey.html b/script_LuaTask/doc/lib/modules/powerKey.html index 5ceac4a..3c85f5d 100644 --- a/script_LuaTask/doc/lib/modules/powerKey.html +++ b/script_LuaTask/doc/lib/modules/powerKey.html @@ -161,7 +161,7 @@

    Usage:

    generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
    diff --git a/script_LuaTask/doc/lib/modules/ril.html b/script_LuaTask/doc/lib/modules/ril.html index 888b532..b5b3278 100644 --- a/script_LuaTask/doc/lib/modules/ril.html +++ b/script_LuaTask/doc/lib/modules/ril.html @@ -277,7 +277,7 @@

    Usage:

    generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
    diff --git a/script_LuaTask/doc/lib/modules/sim.html b/script_LuaTask/doc/lib/modules/sim.html index ddc23ee..4b36e34 100644 --- a/script_LuaTask/doc/lib/modules/sim.html +++ b/script_LuaTask/doc/lib/modules/sim.html @@ -267,7 +267,7 @@

    Usage:

    generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
    diff --git a/script_LuaTask/doc/lib/modules/sms.html b/script_LuaTask/doc/lib/modules/sms.html index 06953de..076ff9c 100644 --- a/script_LuaTask/doc/lib/modules/sms.html +++ b/script_LuaTask/doc/lib/modules/sms.html @@ -138,7 +138,7 @@

    Parameters:

    短信发送结果异步返回时的用户回调函数,回调函数的调用形式为:
                   cbFnc(result,num,data)
                   num:短信接收方的号码,ASCII码字符串格式
    -              data:短信内容,GB2312编码的字符串
    + data:短信内容,unicode大端编码的HEX字符串
  • idx number @@ -200,7 +200,7 @@

    Usage:

    generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
    diff --git a/script_LuaTask/doc/lib/modules/socket.html b/script_LuaTask/doc/lib/modules/socket.html index 7a9d2ee..13cc621 100644 --- a/script_LuaTask/doc/lib/modules/socket.html +++ b/script_LuaTask/doc/lib/modules/socket.html @@ -136,7 +136,7 @@

    Functions

    - mt:recv ([timeout=0][, msg=nil]) + mt:recv ([timeout=0][, msg=nil][, msgNoResume=nil]) 接收数据 @@ -152,6 +152,19 @@

    Functions

    设置TCP层自动重传的参数 + + + setDnsParsePara ([retryCnt=4][, retryTimeoutMulti=4]) + + 设置域名解析参数 + 注意:0027以及之后的core版本才支持此功能 + + + + printStatus () + + 打印所有socket的状态 +

    Fields

    @@ -422,7 +435,7 @@

    Usage:

    - mt:recv ([timeout=0][, msg=nil]) + mt:recv ([timeout=0][, msg=nil][, msgNoResume=nil])
    @@ -441,6 +454,11 @@

    Parameters:

    [此参数可选,默认值为: nil]
     可选参数,控制socket所在的线程退出recv阻塞状态
    +
  • msgNoResume + bool + [此参数可选,默认值为: nil] +
     可选参数,控制socket所在的线程退出recv阻塞状态,false或者nil表示“在recv阻塞状态,收到msg消息,可以退出阻塞状态”,true表示不退出
    +
  • Returns:

    @@ -448,7 +466,9 @@

    Returns:

  • result 数据接收结果,true表示成功,false表示失败
  • -
    data 如果成功的话,返回接收到的数据;超时时返回错误为"timeout";msg控制退出时返回msg
  • +
    data 如果成功的话,返回接收到的数据;超时时返回错误为"timeout";msg控制退出时返回msg的字符串
    +
  • +
    param 如果是msg返回的false,则data的值是msg,param的值是msg的参数
  • @@ -524,6 +544,77 @@

    Usage:

    setTcpResendPara(4,16) +
    +
    + + + setDnsParsePara ([retryCnt=4][, retryTimeoutMulti=4]) + +
    +
    +
    设置域名解析参数
    + 注意:0027以及之后的core版本才支持此功能
    + + +

    Parameters:

    +
      +
    • retryCnt + number + [此参数可选,默认值为: 4] +
      重传次数;取值范围1到8
      +
    • +
    • retryTimeoutMulti + number + [此参数可选,默认值为: 4] +
      重传超时时间倍数,取值范围1到5
      +                第n次重传超时时间的计算方式为:第n次的重传超时基数*retryTimeoutMulti,单位为秒
      +                重传超时基数表为{1, 1, 2, 4, 4, 4, 4, 4}
      +                第1次重传超时时间为:1*retryTimeoutMulti 秒
      +                第2次重传超时时间为:1*retryTimeoutMulti 秒
      +                第3次重传超时时间为:2*retryTimeoutMulti 秒
      +                ...........................................
      +                第8次重传超时时间为:8*retryTimeoutMulti 秒
      +
    • +
    + +

    Returns:

    +
      +
    • +
      nil
      +
    + + + +

    Usage:

    +
      +
    • socket.setDnsParsePara(8,5)
      +
    + +
    +
    + + + printStatus () + +
    +
    +
    打印所有socket的状态
    + + + +

    Returns:

    +
      +
    • +
      +
    + + + +

    Usage:

    +
      +
    • socket.printStatus()
      +
    +

    Fields

    @@ -552,7 +643,7 @@

    Fields

    generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
    diff --git a/script_LuaTask/doc/lib/modules/sys.html b/script_LuaTask/doc/lib/modules/sys.html index 8d8db2a..ffb4385 100644 --- a/script_LuaTask/doc/lib/modules/sys.html +++ b/script_LuaTask/doc/lib/modules/sys.html @@ -692,7 +692,7 @@

    Usage:

    generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
    diff --git a/script_LuaTask/doc/lib/modules/update.html b/script_LuaTask/doc/lib/modules/update.html index 7758f4b..6f43ea4 100644 --- a/script_LuaTask/doc/lib/modules/update.html +++ b/script_LuaTask/doc/lib/modules/update.html @@ -179,7 +179,7 @@

    Usage:

    generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
    diff --git a/script_LuaTask/doc/lib/modules/utils.html b/script_LuaTask/doc/lib/modules/utils.html index 7c60b86..1aa81c6 100644 --- a/script_LuaTask/doc/lib/modules/utils.html +++ b/script_LuaTask/doc/lib/modules/utils.html @@ -749,7 +749,7 @@

    Returns:

    generated by LDoc 1.4.6 -Last updated 2019-10-22 16:00:46 +Last updated 2020-06-13 11:38:12
    diff --git a/script_LuaTask/lib/aLiYun.lua b/script_LuaTask/lib/aLiYun.lua index 552173f..13b2a5b 100644 --- a/script_LuaTask/lib/aLiYun.lua +++ b/script_LuaTask/lib/aLiYun.lua @@ -179,6 +179,7 @@ function clientAuthTask() local _,result,statusCode,body = sys.waitUntil("ALIYUN_AUTH_IND") --log.info("aLiYun.clientAuthTask1",result and statusCode=="200",body) + local invalidSign if result and statusCode=="200" then local tJsonDecode,result = json.decode(body) --log.info("aLiYun.clientAuthTask2",result,tJsonDecode["message"],tJsonDecode["data"]) @@ -198,9 +199,12 @@ function clientAuthTask() return end end + if body and body:match("invalid sign") then + invalidSign = true + end end - - if sProductSecret then + + if sProductSecret and invalidSign then http.request("POST","https://iot-auth.cn-shanghai.aliyuncs.com/auth/register/device",nil, {['Content-Type']="application/x-www-form-urlencoded"}, getBody("register"),30000,getDeviceSecretCb) diff --git a/script_LuaTask/lib/errDump.lua b/script_LuaTask/lib/errDump.lua index 30aeedb..b041278 100644 --- a/script_LuaTask/lib/errDump.lua +++ b/script_LuaTask/lib/errDump.lua @@ -215,6 +215,10 @@ function setNetworkLog(flag) stNetworkLog[(ssl and "ssl" or prot).."://"..addr..":"..port] = getTimeStr()..":send fail" updateNetworkLog() end) + procer("LIB_SOCKET_CLOSE_IND",function(ssl,prot,addr,port) + stNetworkLog[(ssl and "ssl" or prot).."://"..addr..":"..port.." closed"] = getTimeStr() + updateNetworkLog() + end) procer("PDP_DEACT_IND",function() stNetworkLog["PDP_DEACT_IND"] = getTimeStr() updateNetworkLog() diff --git a/script_LuaTask/lib/http.lua b/script_LuaTask/lib/http.lua index c636a6c..2010cb4 100644 --- a/script_LuaTask/lib/http.lua +++ b/script_LuaTask/lib/http.lua @@ -27,10 +27,11 @@ local function getFileBase64Len(s) end local function taskClient(method,protocal,auth,host,port,path,cert,head,body,timeout,cbFnc,rcvFilePath) + log.info("http path",path) while not socket.isReady() do if not sys.waitUntil("IP_READY_IND",timeout) then return response(nil,cbFnc,false,"network not ready") end end - + --计算body长度 local bodyLen = 0 if body then @@ -42,7 +43,7 @@ local function taskClient(method,protocal,auth,host,port,path,cert,head,body,tim end end end - + --重构head local heads = head or {} if not heads.Host then heads["Host"] = host end @@ -54,18 +55,18 @@ local function taskClient(method,protocal,auth,host,port,path,cert,head,body,tim headStr = headStr..k..": "..v.."\r\n" end headStr = headStr.."\r\n" - + local client = socket.tcp(protocal=="https",cert) if not client then return response(nil,cbFnc,false,"create socket error") end if not client:connect(host,port) then return response(client,cbFnc,false,"connect fail") end - + --发送请求行+请求头+string类型的body if not client:send(method.." "..path.." HTTP/1.1".."\r\n"..headStr..(type(body)=="string" and body or "")) then return response(client,cbFnc,false,"send head fail") end - + --发送table类型的body if type(body)=="table" then for i=1,#body do @@ -77,7 +78,7 @@ local function taskClient(method,protocal,auth,host,port,path,cert,head,body,tim local file = io.open(body[i].file or body[i].file_base64,"rb") if file then while true do - local dat = file:read(body[i].file and 1460 or 1095) + local dat = file:read(body[i].file and 11200 or 8400) if not dat then io.close(file) break @@ -94,7 +95,7 @@ local function taskClient(method,protocal,auth,host,port,path,cert,head,body,tim end end end - + local rcvCache,rspHead,rspBody,d1,d2,result,data,statusCode,rcvChunked,contentLen = "",{},{} --接收数据,解析状态行和头 while true do @@ -111,8 +112,7 @@ local function taskClient(method,protocal,auth,host,port,path,cert,head,body,tim --应答头 for k,v in string.gmatch(rcvCache:sub(d1+1,d2-2),"(.-):%s*(.-)\r\n") do rspHead[k] = v - if (k=="Transfer-Encoding") and (v=="chunked") then rcvChunked = true end - + if (string.upper(k)==string.upper("Transfer-Encoding")) and (string.upper(v)==string.upper("chunked")) then rcvChunked = true end end if not rcvChunked then contentLen = tonumber(rspHead["Content-Length"] or "2147483647") @@ -122,7 +122,7 @@ local function taskClient(method,protocal,auth,host,port,path,cert,head,body,tim break end end - + --解析body if rcvChunked then local chunkSize @@ -133,16 +133,16 @@ local function taskClient(method,protocal,auth,host,port,path,cert,head,body,tim d1,d2,chunkSize = rcvCache:find("(%x+)\r\n") if chunkSize then chunkSize = tonumber(chunkSize,16) - rcvCache = rcvCache:sub(d2+1,-1) + rcvCache = rcvCache:sub(d2+1,-1) else result,data = receive(client,timeout,cbFnc,false,nil,rspHead,rcvFilePath or table.concat(rspBody)) if not result then return end rcvCache = rcvCache..data end end - + --log.info("http.taskClient chunkSize",chunkSize) - + --解析chunk data if chunkSize then if rcvCache:len()=27 then + request("AT+AUTOAPN=0") + --0:保存并重启生效 + --1:不保存立即生效 + --2:保存并立即生效 + --3:删除保存的文件 + request('AT+CPNETAPN=2,"'..apn..'","'..user..'","'..pwd..'",'..prot) + else]] + authProt,authApn,authUser,authPassword = prot or 0,apn or "",user or "",pwd or "" + request("AT*CGDFLT?") + ril.regUrc("*CGDFLT", function(data) + local dftApn = data:match("CGDFLT:%s*\"%w*\",\"(.-)\"") + if dftApn~=authApn then + setCgdf() + end + end) + --end end local function Pdp_Act() diff --git a/script_LuaTask/lib/misc.lua b/script_LuaTask/lib/misc.lua index 5840fd2..7ff04f6 100644 --- a/script_LuaTask/lib/misc.lua +++ b/script_LuaTask/lib/misc.lua @@ -12,6 +12,7 @@ module(..., package.seeall) -- calib 校准标志 local sn, imei, calib, ver, muid local setSnCbFnc,setImeiCbFnc,setClkCbFnc +local sPpType,sPpVoltage local function timeReport() sys.publish("TIME_CLK_IND") @@ -49,14 +50,6 @@ local function rsp(cmd, success, response, intermediate) sys.publish('IMEI_READY_IND') elseif cmd == 'AT+VER' then ver = intermediate - --查询是否校准 - elseif cmd == "AT+ATWMFT=99" then - log.info('misc.ATWMFT', intermediate) - if intermediate == "SUCC" then - calib = true - else - calib = false - end elseif prefix == '+CCLK' then if success then sys.publish('TIME_UPDATE_IND') @@ -77,6 +70,25 @@ local function rsp(cmd, success, response, intermediate) end elseif cmd:match("AT%+MUID?") then if intermediate then muid = intermediate:match("+MUID:%s*\"(.+)\"") end + elseif cmd:match("AT%*LTECFG%?") then + log.info("misc.rsp","LTECFG?",intermediate) + if intermediate then + local typ,vol = intermediate:match("PP_TYPE=(%d+),PP_VOLTAGE=(%d+)") + if typ then + if tonumber(typ)~=sPpType or tonumber(vol)~=sPpVoltage then + req("AT*LTECFG="..sPpType..","..sPpVoltage) + end + else + sys.timerStart(sys.restart,300000,"LTECFG query fail") + end + end + elseif cmd:match("AT%*LTECFG=") then + log.info("misc.rsp","LTECFG=",success) + if success then + sys.timerStart(sys.restart,3000,cmd.." success") + else + sys.timerStart(sys.restart,300000,"LTECFG set fail") + end end end @@ -208,18 +220,21 @@ function closePwm(id) req("AT+SPWM=" .. id .. ",0,0") end + +function setPpVoltage(ppType,ppVoltage) + sPpType,sPpVoltage = ppType,ppVoltage + req("AT*LTECFG?") +end + --注册以下AT命令的应答处理函数 -ril.regRsp("+ATWMFT", rsp) ril.regRsp("+WISN", rsp) ril.regRsp("+CGSN", rsp) ril.regRsp("+MUID", rsp) ril.regRsp("+WIMEI", rsp) ril.regRsp("+AMFAC", rsp) -ril.regRsp("+CFUN", rsp) ril.regRsp('+VER', rsp, 4, '^[%w_]+$') +ril.regRsp('*LTECFG', rsp, 4, '^.+$') req('AT+VER') ---查询是否校准 -req("AT+ATWMFT=99") --查询序列号 req("AT+WISN?") --查询IMEI diff --git a/script_LuaTask/lib/net.lua b/script_LuaTask/lib/net.lua index 9c394d6..667c09d 100644 --- a/script_LuaTask/lib/net.lua +++ b/script_LuaTask/lib/net.lua @@ -438,14 +438,14 @@ end -- @return string mcc,当前小区的mcc,如果还没有注册GSM网络,则返回sim卡的mcc -- @usage net.getMcc() function getMcc() - return cellinfo[1].mcc or sim.getMcc() + return cellinfo[1].mcc and string.format("%x",cellinfo[1].mcc) or sim.getMcc() end --- 获取当前小区的mnc -- @return string mcn,当前小区的mnc,如果还没有注册GSM网络,则返回sim卡的mnc -- @usage net.getMnc() function getMnc() - return cellinfo[1].mnc or sim.getMnc() + return cellinfo[1].mnc and string.format("%x",cellinfo[1].mnc) or sim.getMnc() end --- 获取当前位置区ID @@ -524,10 +524,11 @@ local function rsp(cmd, success, response, intermediate) --产生一个内部消息GSM_SIGNAL_REPORT_IND,表示读取到了信号强度 publish("GSM_SIGNAL_REPORT_IND", success, rssi) end - elseif prefix == "+CFUN" then - if success then publish("FLYMODE", flyMode) end elseif prefix == "+CENG" then end end + if prefix == "+CFUN" then + if success then publish("FLYMODE", flyMode) end + end end --- 实时读取“当前和临近小区信息” diff --git a/script_LuaTask/lib/pb.lua b/script_LuaTask/lib/pb.lua index a6380cd..acb60fd 100644 --- a/script_LuaTask/lib/pb.lua +++ b/script_LuaTask/lib/pb.lua @@ -109,8 +109,23 @@ local function pbrsp(cmd,success,response,intermediate) end end +--[[ +函数名:urc +功能 :主动上报消息处理函数 +参数 :data,prefix +返回值:无 +]] +local function urc(data, prefix) + local pbready = string.match(data, "(%d+)", string.len(prefix) + 1) + pbready = tonumber(pbready) + if pbready == 1 then + req("AT+CPBS=\"SM\"") + end +end + ril.regRsp("+CPBR",pbrsp) ril.regRsp("+CPBW",pbrsp) ril.regRsp("+CPBS",pbrsp) ril.regRsp("+CPBS?",pbrsp) -req("AT+CPBS=\"SM\"") +ril.regUrc("+MPBK", urc) + diff --git a/script_LuaTask/lib/sms.lua b/script_LuaTask/lib/sms.lua index f88122a..39ccb5e 100644 --- a/script_LuaTask/lib/sms.lua +++ b/script_LuaTask/lib/sms.lua @@ -27,13 +27,13 @@ num:待转换字符串 ]] local function numtobcdnum(num) local len, numfix, convnum = slen(num), "81", "" - + if ssub(num, 1, 1) == "+" then numfix = "91" len = len - 1 num = ssub(num, 2, -1) end - + if len % 2 ~= 0 then --奇数位 for i = 1, (len - (len % 2)) / 2 do convnum = convnum .. ssub(num, i * 2, i * 2) .. ssub(num, i * 2 - 1, i * 2 - 1) @@ -44,7 +44,7 @@ local function numtobcdnum(num) convnum = convnum .. ssub(num, i * 2, i * 2) .. ssub(num, i * 2 - 1, i * 2 - 1) end end - + return numfix .. convnum end @@ -57,26 +57,26 @@ num:待转换字符串 ]] local function bcdnumtonum(num) local len, numfix, convnum = slen(num), "", "" - + if len % 2 ~= 0 then print("your bcdnum is err " .. num) return end - + if ssub(num, 1, 2) == "91" then numfix = "+" end - + len, num = len - 2, ssub(num, 3, -1) - + for i = 1, (len - (len % 2)) / 2 do convnum = convnum .. ssub(num, i * 2, i * 2) .. ssub(num, i * 2 - 1, i * 2 - 1) end - + if ssub(convnum, len, len) == "f" or ssub(convnum, len, len) == "F" then convnum = ssub(convnum, 1, -2) end - + return numfix .. convnum end @@ -91,7 +91,7 @@ data:短信内容 local function _send(num, data) local numlen, datalen, pducnt, pdu, pdulen, udhi = sformat("%02X", slen(num)), slen(data) / 2, 1, "", "", "" if not smsReady or not netReady then return false end - + --如果发送的数据大于140字节则为长短信 if datalen > 140 then --计算出长短信拆分后的总条数,长短信的每包的数据实际只有134个实际要发送的短信内容,数据的前6字节为协议头 @@ -100,13 +100,13 @@ local function _send(num, data) --分配一个序列号,范围为0-255 isn = isn == 255 and 0 or isn + 1 end - + table.insert(tsend, {sval = pducnt, rval = 0, flg = true})--sval发送的包数,rval收到的包数 - + if ssub(num, 1, 1) == "+" then numlen = sformat("%02X", slen(num) - 1) end - + for i = 1, pducnt do --如果是长短信 if pducnt > 1 then @@ -135,7 +135,7 @@ end ]] function read(pos) if not smsReady or pos == nil or pos == 0 then return false end - + req("AT+CMGR=" .. pos) return true end @@ -173,7 +173,7 @@ longsms ]] function gsm7bitdecode(data, longsms) local ucsdata, lpcnt, tmpdata, resdata, nbyte, nleft, ucslen, olddat = "", slen(data) / 2, 0, 0, 0, 0, 0 - + if longsms then tmpdata = tonumber("0x" .. ssub(data, 1, 2)) resdata = bit.rshift(tmpdata, 1) @@ -202,12 +202,12 @@ function gsm7bitdecode(data, longsms) olddat, resdata = resdata, Charmap[resdata] end ucsdata = ucsdata .. sformat("%04X", resdata) - + nleft = bit.rshift(tmpdata, 7 - nbyte) nbyte = nbyte + 1 ucslen = ucslen + 1 end - + for i = 2, lpcnt do tmpdata = tonumber("0x" .. ssub(data, (i - 1) * 2 + 1, i * 2)) if tmpdata == nil then break end @@ -223,11 +223,11 @@ function gsm7bitdecode(data, longsms) olddat, resdata = resdata, Charmap[resdata] end ucsdata = ucsdata .. sformat("%04X", resdata) - + nleft = bit.rshift(tmpdata, 7 - nbyte) nbyte = nbyte + 1 ucslen = ucslen + 1 - + if nbyte == 7 then if olddat == 27 then if Charmapctl[nleft] then --特殊字符 @@ -244,7 +244,7 @@ function gsm7bitdecode(data, longsms) ucslen = ucslen + 1 end end - + return ucsdata, ucslen end @@ -257,11 +257,11 @@ longsms ]] function gsm8bitdecode(data) local ucsdata, lpcnt = "", slen(data) / 2 - + for i = 1, lpcnt do ucsdata = ucsdata .. "00" .. ssub(data, (i - 1) * 2 + 1, i * 2) end - + return ucsdata, lpcnt end @@ -274,7 +274,7 @@ end local function rsp(cmd, success, response, intermediate) local prefix = smatch(cmd, "AT(%+%u+)") log.info("lib_sms rsp", prefix, cmd, success, response, intermediate) - + --读短信成功 if prefix == "+CMGR" then if not success then publish("SMS_READ_CNF") return end @@ -283,7 +283,7 @@ local function rsp(cmd, success, response, intermediate) stat, alpha, len, pdu = smatch(intermediate, "+CMGR:%s*(%d),(.*),%s*(%d+)\r\n(%x+)") len = tonumber(len)--PDU数据长度,不包括短信息中心号码 end - + --收到的PDU包不为空则解析PDU包 if pdu and pdu ~= "" then local offset, addlen, addnum, flag, dcs, tz, txtlen, fo = 5 @@ -293,14 +293,14 @@ local function rsp(cmd, success, response, intermediate) longsms = true end addlen = tonumber(sformat("%d", "0x" .. ssub(pdu, 3, 4)))--回复地址数字个数 - + addlen = addlen % 2 == 0 and addlen + 2 or addlen + 3 --加上号码类型2位(5,6)or 加上号码类型2位(5,6)和1位F - + offset = offset + addlen - + addnum = ssub(pdu, 5, 5 + addlen - 1) convnum = bcdnumtonum(addnum) - + flag = tonumber(sformat("%d", "0x" .. ssub(pdu, offset, offset + 1)))--协议标识 (TP-PID) offset = offset + 2 dcs = tonumber(sformat("%d", "0x" .. ssub(pdu, offset, offset + 1)))--用户信息编码方式 Dcs=8,表示短信存放的格式为UCS2编码 @@ -319,9 +319,9 @@ local function rsp(cmd, success, response, intermediate) data = ssub(data, 15, -1)--去掉报头7个字节 end end - + log.info("TP-PID : ", flag, "dcs: ", dcs, "tz: ", tz, "data: ", data, "txtlen", txtlen) - + if dcs == 0x00 then --7bit encode local newlen data, newlen = gsm7bitdecode(data, longsms) @@ -333,10 +333,10 @@ local function rsp(cmd, success, response, intermediate) data, txtlen = gsm8bitdecode(data) log.info("8bit to ucs2 data: ", data, "txtlen", txtlen) end - + for i = 1, 7 do t = t .. ssub(tz, i * 2, i * 2) .. ssub(tz, i * 2 - 1, i * 2 - 1) - + if i <= 3 then t = i < 3 and (t .. "/") or (t .. ",") elseif i <= 6 then @@ -344,7 +344,7 @@ local function rsp(cmd, success, response, intermediate) end end end - + local pos = smatch(cmd, "AT%+CMGR=(%d+)") data = data or "" alpha = alpha or "" @@ -443,7 +443,7 @@ end ]] local function longsmsind(num, data, datetime, name, total, idx, isn) log.info("longsmsind", "isn", isn, "total:", total, "idx:", idx, "data", data) - + if tlongsms[isn .. total] then if not tlongsms[isn .. total]["dat"] then tlongsms[isn .. total]["dat"] = {} end tlongsms[isn .. total]["dat"][idx] = data @@ -453,7 +453,7 @@ local function longsmsind(num, data, datetime, name, total, idx, isn) tlongsms[isn .. total]["dat"] = {} tlongsms[isn .. total]["dat"][idx] = data end - + local totalrcv = 0 for i = 1, tlongsms[isn .. total]["total"] do if tlongsms[isn .. total]["dat"][i] then totalrcv = totalrcv + 1 end @@ -523,7 +523,7 @@ end -- @function[opt=nil] cbFnc,短信发送结果异步返回时的用户回调函数,回调函数的调用形式为: -- cbFnc(result,num,data) -- num:短信接收方的号码,ASCII码字符串格式 --- data:短信内容,GB2312编码的字符串 +-- data:短信内容,unicode大端编码的HEX字符串 -- @number[opt=nil] idx,插入短信发送缓冲表的位置,默认是插入末尾 -- @return result,true表示调用接口成功(并不是短信发送成功,短信发送结果,通过sendcnf返回,如果有cbFnc,会通知cbFnc函数);返回false,表示调用接口失败 -- @usage sms.send("10086","test",cbFnc) diff --git a/script_LuaTask/lib/socket.lua b/script_LuaTask/lib/socket.lua index 4ce80f9..45ce087 100644 --- a/script_LuaTask/lib/socket.lua +++ b/script_LuaTask/lib/socket.lua @@ -14,7 +14,7 @@ local SENDSIZE = 11200 -- 缓冲区最大下标 local INDEX_MAX = 256 -- 是否有socket正处在链接 -local socketsConnected = false +local socketsConnected = 0 --- SOCKET 是否有可用 -- @return 可用true,不可用false socket.isReady = link.isReady @@ -177,9 +177,13 @@ function mt:connect(address, port, timeout) return false end log.info("socket:connect: connect ok") - self.connected = true - socketsConnected = self.connected or socketsConnected - sys.publish("SOCKET_ACTIVE", socketsConnected) + + if not self.connected then + self.connected = true + socketsConnected = socketsConnected+1 + sys.publish("SOCKET_ACTIVE", socketsConnected>0) + end + return true, self.id end @@ -312,8 +316,11 @@ function mt:recv(timeout, msg, msgNoResume) if msg and not self.iSubscribe then self.iSubscribe = msg self.subMessage = function(data) - if data then table.insert(self.output, data) end - if self.wait == "+RECEIVE" and not self.msgNoResume then coroutine.resume(self.co, 0xAA) end + --if data then table.insert(self.output, data) end + if self.wait == "+RECEIVE" and not self.msgNoResume then + if data then table.insert(self.output, data) end + coroutine.resume(self.co, 0xAA) + end end sys.subscribe(msg, self.subMessage) end @@ -367,7 +374,7 @@ function mt:close() --if self.connected then log.info("socket:sock_close", self.id) local result, reason - self.connected = false + if self.id then socketcore.sock_close(self.id) self.wait = "SOCKET_CLOSE" @@ -376,8 +383,13 @@ function mt:close() if reason == "RESPONSE" then break end end end - socketsConnected = self.connected or socketsConnected - sys.publish("SOCKET_ACTIVE", socketsConnected) + if self.connected then + self.connected = false + if socketsConnected>0 then + socketsConnected = socketsConnected-1 + end + sys.publish("SOCKET_ACTIVE", socketsConnected>0) + end --end if self.id ~= nil then sockets[self.id] = nil @@ -416,14 +428,20 @@ rtos.on(rtos.MSG_SOCK_CLOSE_IND, function(msg) log.warn('close ind on nil socket', msg.socket_index, msg.id) return end - sockets[msg.socket_index].connected = false + if sockets[msg.socket_index].connected then + sockets[msg.socket_index].connected = false + if socketsConnected>0 then + socketsConnected = socketsConnected-1 + end + sys.publish("SOCKET_ACTIVE", socketsConnected>0) + end sockets[msg.socket_index].error = 'CLOSED' - socketsConnected = sockets[msg.socket_index].connected or socketsConnected - sys.publish("SOCKET_ACTIVE", socketsConnected) + --[[ if type(socketcore.sock_destroy) == "function" then socketcore.sock_destroy(msg.socket_index) end]] + sys.publish("LIB_SOCKET_CLOSE_IND", sockets[msg.socket_index].ssl, sockets[msg.socket_index].protocol, sockets[msg.socket_index].address, sockets[msg.socket_index].port) coroutine.resume(sockets[msg.socket_index].co, false, "CLOSED") end) rtos.on(rtos.MSG_SOCK_RECV_IND, function(msg) @@ -461,7 +479,24 @@ function setTcpResendPara(retryCnt, retryMaxTimeout) ril.request("AT+TCPUSERPARAM=6," .. (retryCnt or 4) .. ",7200," .. (retryMaxTimeout or 16)) end --- setTcpResendPara(1, 16) +--- 设置域名解析参数 +-- 注意:0027以及之后的core版本才支持此功能 +-- @number[opt=4] retryCnt,重传次数;取值范围1到8 +-- @number[opt=4] retryTimeoutMulti,重传超时时间倍数,取值范围1到5 +-- 第n次重传超时时间的计算方式为:第n次的重传超时基数*retryTimeoutMulti,单位为秒 +-- 重传超时基数表为{1, 1, 2, 4, 4, 4, 4, 4} +-- 第1次重传超时时间为:1*retryTimeoutMulti 秒 +-- 第2次重传超时时间为:1*retryTimeoutMulti 秒 +-- 第3次重传超时时间为:2*retryTimeoutMulti 秒 +-- ........................................... +-- 第8次重传超时时间为:8*retryTimeoutMulti 秒 +-- @return nil +-- @usage +-- socket.setDnsParsePara(8,5) +function setDnsParsePara(retryCnt, retryTimeoutMulti) + ril.request("AT*DNSTMOUT="..(retryCnt or 4)..","..(retryTimeoutMulti or 4)) +end + --- 打印所有socket的状态 -- @return 无 -- @usage socket.printStatus() @@ -472,3 +507,6 @@ function printStatus() end end end + +--setDnsParsePara(4,4) +--setTcpResendPara(1,16) diff --git a/script_LuaTask/lib/sys.lua b/script_LuaTask/lib/sys.lua index 681a6a1..1ea7c54 100644 --- a/script_LuaTask/lib/sys.lua +++ b/script_LuaTask/lib/sys.lua @@ -10,7 +10,7 @@ require "patch" module(..., package.seeall) -- lib脚本版本号,只要lib中的任何一个脚本做了修改,都需要更新此版本号 -SCRIPT_LIB_VER = "2.2.7" +SCRIPT_LIB_VER = "2.2.8" -- TaskID最大值 local TASK_TIMER_ID_MAX = 0x1FFFFFFF @@ -291,7 +291,7 @@ function unsubscribe(id, callback) log.warn("warning: sys.unsubscribe invalid parameter", id, callback) return end - if subscribers[id] then subscribers[id][callback] = nil end + if subscribers[id] then subscribers[id][callback] = false end end --- 发布内部消息,存储在内部消息队列中 @@ -309,12 +309,20 @@ local function dispatch() break end local message = table.remove(messageQueue, 1) + --log.info("sys.dispatch message",message[1],subscribers[message[1]]) if subscribers[message[1]] then - for callback, _ in pairs(subscribers[message[1]]) do - if type(callback) == "function" then - callback(unpack(message, 2, #message)) - elseif type(callback) == "thread" then - coroutine.resume(callback, unpack(message)) + for callback, flag in pairs(subscribers[message[1]]) do + if flag then + if type(callback) == "function" then + callback(unpack(message, 2, #message)) + elseif type(callback) == "thread" then + coroutine.resume(callback, unpack(message)) + end + end + end + for callback, flag in pairs(subscribers[message[1]]) do + if not flag then + subscribers[message[1]][callback] = nil end end end @@ -376,3 +384,8 @@ function run() end require "clib" + +if type(rtos.openSoftDog)=="function" then + rtos.openSoftDog(60000) + sys.timerLoopStart(rtos.eatSoftDog,20000) +end diff --git a/script_LuaTask/lib/update.lua b/script_LuaTask/lib/update.lua index c1db1e1..0decfe4 100644 --- a/script_LuaTask/lib/update.lua +++ b/script_LuaTask/lib/update.lua @@ -26,11 +26,11 @@ local function processOta(stepData,totalLen,statusCode) if stepData and totalLen then if statusCode=="200" or statusCode=="206" then if rtos.fota_process((sProcessedLen+stepData:len()>totalLen) and stepData:sub(1,totalLen-sProcessedLen) or stepData,totalLen)~=0 then - log.error("updata.processOta","fail") + log.error("update.processOta","fail") return false else sProcessedLen = sProcessedLen + stepData:len() - log.info("updata.processOta",totalLen,sProcessedLen,(sProcessedLen*100/totalLen).."%") + log.info("update.processOta",totalLen,sProcessedLen,(sProcessedLen*100/totalLen).."%") --if sProcessedLen*100/totalLen==sBraekTest then return false end if sProcessedLen*100/totalLen>=100 then return true end end diff --git a/script_LuaTask/release notes.txt b/script_LuaTask/release notes.txt index 7b9d029..71c995a 100644 --- a/script_LuaTask/release notes.txt +++ b/script_LuaTask/release notes.txt @@ -1,3 +1,12 @@ +ʱ䣺2020/06/13 11:41 +޸ļ¼ + һlibű޸ + libű汾ţ2.2.8 + (1)socketrecvȴʱϢ˳״̬ʱֵԳ + (2)httptransfer-encodingִСдµchunk޷ + + + ʱ䣺2019/11/17 08:16 ޸ļ¼ һlibű޸