Jelajahi Sumber

Merge branch 'master' of https://gitee.com/openLuat/LuatOS

alienwalker 1 tahun lalu
induk
melakukan
41eb021eb5

+ 12 - 0
demo/modbus_rtu/main.lua

@@ -4,6 +4,18 @@ VERSION = "1.0.0"
 
 sys = require("sys")
 
+
+local uartid = 1 -- 根据实际设备选取不同的uartid
+
+--初始化
+local result = uart.setup(
+    uartid,--串口id
+    9600,--波特率
+    8,--数据位
+    1,--停止位
+    uart.None
+)
+
 sys.taskInit(function()
     uart.on(1, "recv", function(id, len)
         local data = uart.read(1, len)

+ 205 - 0
demo/mqtt_emqx/main.lua

@@ -0,0 +1,205 @@
+
+-- LuaTools需要PROJECT和VERSION这两个信息
+PROJECT = "mqtt_emqx_demo"
+VERSION = "1.0.0"
+
+--[[
+本demo需要mqtt库, 大部分能联网的设备都具有这个库
+mqtt也是内置库, 无需require
+]]
+
+-- sys库是标配
+_G.sys = require("sys")
+--[[特别注意, 使用mqtt库需要下列语句]]
+_G.sysplus = require("sysplus")
+
+
+-- Air780E的AT固件默认会为开机键防抖, 导致部分用户刷机很麻烦
+if rtos.bsp() == "EC618" and pm and pm.PWK_MODE then
+    pm.power(pm.PWK_MODE, false)
+end
+
+-- 自动低功耗, 轻休眠模式
+-- Air780E支持uart唤醒和网络数据下发唤醒, 但需要断开USB,或者pm.power(pm.USB, false) 但这样也看不到日志了
+-- pm.request(pm.LIGHT)
+
+--根据自己的服务器修改以下参数
+local mqtt_host  = "xxxxxxxx" -- 连接地址
+local mqtt_port  = 8883                                 -- MQTT over TLS/SSL 端口
+local mqtt_isssl = true                                 -- ssl 选择 
+local client_id  = "luat_001"                           -- 设备id 
+local user_name  = "xxx"                -- 账号
+local password   = "xxx"                        -- 密码
+
+
+local pub_topic = "/luatos/pub/" .. (mcu.unique_id():toHex())
+local sub_topic = "/luatos/sub/" .. (mcu.unique_id():toHex())
+-- local topic2 = "/luatos/2"
+-- local topic3 = "/luatos/3"
+
+local mqttc = nil
+
+-- 统一联网函数
+sys.taskInit(function()
+    local device_id = mcu.unique_id():toHex()
+    -----------------------------
+    -- 统一联网函数, 可自行删减
+    ----------------------------
+    if wlan and wlan.connect then
+        -- wifi 联网, ESP32系列均支持
+        local ssid = "luatos1234"
+        local password = "12341234"
+        log.info("wifi", ssid, password)
+        -- TODO 改成自动配网
+        -- LED = gpio.setup(12, 0, gpio.PULLUP)
+        wlan.init()
+        wlan.setMode(wlan.STATION) -- 默认也是这个模式,不调用也可以
+        device_id = wlan.getMac()
+        wlan.connect(ssid, password, 1)
+    elseif mobile then
+        -- Air780E/Air600E系列
+        --mobile.simid(2) -- 自动切换SIM卡
+        -- LED = gpio.setup(27, 0, gpio.PULLUP)
+        device_id = mobile.imei()
+    elseif w5500 then
+        -- w5500 以太网, 当前仅Air105支持
+        w5500.init(spi.HSPI_0, 24000000, pin.PC14, pin.PC01, pin.PC00)
+        w5500.config() --默认是DHCP模式
+        w5500.bind(socket.ETH0)
+        -- LED = gpio.setup(62, 0, gpio.PULLUP)
+    elseif socket or mqtt then
+        -- 适配的socket库也OK
+        -- 没有其他操作, 单纯给个注释说明
+    else
+        -- 其他不认识的bsp, 循环提示一下吧
+        while 1 do
+            sys.wait(1000)
+            log.info("bsp", "本bsp可能未适配网络层, 请查证")
+        end
+    end
+    -- 默认都等到联网成功
+    sys.waitUntil("IP_READY")
+    sys.publish("net_ready", device_id)
+end)
+
+sys.taskInit(function()
+    -- 等待联网
+    local ret, device_id = sys.waitUntil("net_ready")
+    -- 下面的是mqtt的参数均可自行修改
+    client_id = device_id
+    pub_topic = "/luatos/pub/" .. device_id
+    sub_topic = "/luatos/sub/" .. device_id
+
+    -- 打印一下上报(pub)和下发(sub)的topic名称
+    -- 上报: 设备 ---> 服务器
+    -- 下发: 设备 <--- 服务器
+    -- 可使用mqtt.x等客户端进行调试
+    log.info("mqtt", "pub", pub_topic)
+    log.info("mqtt", "sub", sub_topic)
+
+    -- 打印一下支持的加密套件, 通常来说, 固件已包含常见的99%的加密套件
+    -- if crypto.cipher_suites then
+    --     log.info("cipher", "suites", json.encode(crypto.cipher_suites()))
+    -- end
+    if mqtt == nil then
+        while 1 do
+            sys.wait(1000)
+            log.info("bsp", "本bsp未适配mqtt库, 请查证")
+        end
+    end
+
+    -------------------------------------
+    -------- MQTT 演示代码 --------------
+    -------------------------------------
+
+    mqttc = mqtt.create(nil, mqtt_host, mqtt_port, mqtt_isssl, ca_file)
+
+    mqttc:auth(client_id,user_name,password) -- client_id必填,其余选填
+    -- mqttc:keepalive(240) -- 默认值240s
+    mqttc:autoreconn(true, 3000) -- 自动重连机制
+
+    mqttc:on(function(mqtt_client, event, data, payload)
+        -- 用户自定义代码
+        log.info("mqtt", "event", event, mqtt_client, data, payload)
+        if event == "conack" then
+            -- 联上了
+            sys.publish("mqtt_conack")
+            mqtt_client:subscribe(sub_topic)--单主题订阅
+            -- mqtt_client:subscribe({[topic1]=1,[topic2]=1,[topic3]=1})--多主题订阅
+        elseif event == "recv" then
+            log.info("mqtt", "downlink", "topic", data, "payload", payload)
+            sys.publish("mqtt_payload", data, payload)
+        elseif event == "sent" then
+            -- log.info("mqtt", "sent", "pkgid", data)
+        -- elseif event == "disconnect" then
+            -- 非自动重连时,按需重启mqttc
+            -- mqtt_client:connect()
+        end
+    end)
+
+    -- mqttc自动处理重连, 除非自行关闭
+    mqttc:connect()
+	sys.waitUntil("mqtt_conack")
+    while true do
+        -- 演示等待其他task发送过来的上报信息
+        local ret, topic, data, qos = sys.waitUntil("mqtt_pub", 300000)
+        if ret then
+            -- 提供关闭本while循环的途径, 不需要可以注释掉
+            if topic == "close" then break end
+            mqttc:publish(topic, data, qos)
+        end
+        -- 如果没有其他task上报, 可以写个空等待
+        --sys.wait(60000000)
+    end
+    mqttc:close()
+    mqttc = nil
+end)
+
+-- 这里演示在另一个task里上报数据, 会定时上报数据,不需要就注释掉
+sys.taskInit(function()
+    sys.wait(3000)
+	local data = "123,"
+	local qos = 1 -- QOS0不带puback, QOS1是带puback的
+    while true do
+        sys.wait(3000)
+        if mqttc and mqttc:ready() then
+            local pkgid = mqttc:publish(pub_topic, data .. os.date(), qos)
+            -- local pkgid = mqttc:publish(topic2, data, qos)
+            -- local pkgid = mqttc:publish(topic3, data, qos)
+        end
+    end
+end)
+
+-- 以下是演示与uart结合, 简单的mqtt-uart透传实现,不需要就注释掉
+local uart_id = 1
+uart.setup(uart_id, 9600)
+uart.on(uart_id, "receive", function(id, len)
+    local data = ""
+    while 1 do
+        local tmp = uart.read(uart_id)
+        if not tmp or #tmp == 0 then
+            break
+        end
+        data = data .. tmp
+    end
+    log.info("uart", "uart收到数据长度", #data)
+    sys.publish("mqtt_pub", pub_topic, data)
+end)
+sys.subscribe("mqtt_payload", function(topic, payload)
+    log.info("uart", "uart发送数据长度", #payload)
+    uart.write(1, payload)
+end)
+
+sys.taskInit(function ()
+    while true do
+        sys.wait(3000)
+        log.info("lua", rtos.meminfo())
+        log.info("sys", rtos.meminfo("sys"))
+    end
+end)
+
+
+-- 用户代码已结束---------------------------------------------
+-- 结尾总是这一句
+sys.run()
+-- sys.run()之后后面不要加任何语句!!!!!

TEMPAT SAMPAH
script/turnkey/hz201p/10.amr


TEMPAT SAMPAH
script/turnkey/hz201p/10.pcm


+ 0 - 298
script/turnkey/hz201p/ThingsCloud.lua

@@ -1,298 +0,0 @@
--- 合宙模组 LUATOS 接入 ThingsCloud 物联网平台
--- 接入协议参考:ThingsCloud MQTT 接入文档 https://docs.thingscloud.xyz/guide/connect-device/mqtt.html
-local ThingsCloud = {}
-
-local projectKey = "" -- project_key
-local accessToken = "" -- access_token
-local typeKey = "" -- type_key
-local host = ""
-local port = 1883
-local apiEndpoint = "" -- api endpoint
-local mqttc = nil
-local connected = false
-local deviceInfo = {}
-
-local certFetchRetryMax = 5
-local certFetchRetryCnt = 0
-
-local SUBSCRIBE_PREFIX = {
-    ATTRIBUTES_GET_REPONSE = "attributes/get/response/",
-    ATTRIBUTES_PUSH = "attributes/push",
-    COMMAND_SEND = "command/send/",
-    COMMAND_REPLY_RESPONSE = "command/reply/response/",
-    DATA_SET = "data/",
-    GW_ATTRIBUTES_PUSH = "gateway/attributes/push",
-    GW_COMMAND_SEND = "gateway/command/send"
-}
-local EVENT_TYPES = {
-    fetch_cert = true,
-    connect = true,
-    attributes_report_response = true,
-    attributes_get_response = true,
-    attributes_push = true,
-    command_send = true,
-    command_reply_response = true,
-    data_set = true,
-    gw_attributes_push = true,
-    gw_command_send = true
-}
-local CALLBACK = {}
-local QUEUE = {
-    PUBLISH = {}
-}
-local logger = {}
-function logger.info(...)
-    log.info("ThingsCloud", ...)
-end
-
-function ThingsCloud.on(eType, cb)
-    if not eType or not EVENT_TYPES[eType] or type(cb) ~= "function" then
-        return
-    end
-    CALLBACK[eType] = cb
-    logger.info("on", eType)
-end
-
-local function cb(eType, ...)
-    if not eType or not EVENT_TYPES[eType] or not CALLBACK[eType] then
-        return
-    end
-    CALLBACK[eType](...)
-    logger.info("event", eType, ...)
-end
-
-local function mqttConnect()
-    local retryCount = 0
-    logger.info("ThingsCloud connecting...")
-
-    mqttc = mqtt.create(nil, host, port, false, {rxSize = 4096})
-    mqttc:auth(mobile.imei(), accessToken, projectKey)
-    mqttc:keepalive(300)
-    mqttc:autoreconn(true, 10000)
-    mqttc:connect()
-
-    mqttc:on(function(mqtt_client, event, data, payload)
-
-        if event == "conack" then
-            connected = true
-            logger.info("ThingsCloud connected")
-            cb("connect", true)
-            sys.publish("mqtt_conack")
-            ThingsCloud.subscribe("attributes/push")
-            ThingsCloud.subscribe("attributes/get/response/+")
-            ThingsCloud.subscribe("command/send/+")
-            ThingsCloud.subscribe("command/reply/response/+")
-
-        elseif event == "recv" then
-            logger.info("receive from cloud", data or nil, payload or "nil")
-            if (data:sub(1, SUBSCRIBE_PREFIX.ATTRIBUTES_GET_REPONSE:len()) == SUBSCRIBE_PREFIX.ATTRIBUTES_GET_REPONSE) then
-                local response = json.decode(payload)
-                local responseId = tonumber(data:sub(SUBSCRIBE_PREFIX.ATTRIBUTES_GET_REPONSE:len() + 1))
-                cb("attributes_get_response", response, responseId)
-            elseif (data == SUBSCRIBE_PREFIX.ATTRIBUTES_PUSH) then
-                local response = json.decode(payload)
-                cb("attributes_push", response)
-            elseif (data:sub(1, SUBSCRIBE_PREFIX.COMMAND_SEND:len()) == SUBSCRIBE_PREFIX.COMMAND_SEND) then
-                local response = json.decode(payload)
-                if response.method and response.params then
-                    cb("command_send", response)
-                end
-            elseif (data:sub(1, SUBSCRIBE_PREFIX.COMMAND_REPLY_RESPONSE:len()) ==
-                SUBSCRIBE_PREFIX.COMMAND_REPLY_RESPONSE) then
-                local response = json.decode(payload)
-                local replyId = tonumber(data:sub(SUBSCRIBE_PREFIX.COMMAND_REPLY_RESPONSE:len() + 1))
-                cb("command_reply_response", response, replyId)
-            elseif (data:sub(1, SUBSCRIBE_PREFIX.DATA_SET:len()) == SUBSCRIBE_PREFIX.DATA_SET) then
-                local tmp = split(data, "/")
-                if #tmp == 3 and tmp[3] == "set" then
-                    local identifier = tmp[2]
-                    cb("data_set", payload)
-                end
-            elseif (data == SUBSCRIBE_PREFIX.GW_ATTRIBUTES_PUSH) then
-                local response = json.decode(payload)
-                cb("gw_attributes_push", response)
-            elseif (data == SUBSCRIBE_PREFIX.GW_COMMAND_SEND) then
-                local response = json.decode(payload)
-                cb("gw_command_send", response)
-            end
-
-        elseif event == "sent" then
-            log.info("mqtt", "sent", data)
-        end
-    end)
-
-end
-
-function ThingsCloud.disconnect()
-    if not connected then
-        return
-    end
-    mqttc:close()
-    mqttc = nil
-end
-
-function ThingsCloud.connect(param)
-    if not param.host or not param.projectKey then
-        logger.info("host or projectKey not found")
-        return
-    end
-    host = param.host
-    projectKey = param.projectKey
-
-    if param.accessToken then
-        accessToken = param.accessToken
-        sys.waitUntil("IP_READY", 30000)
-        sys.taskInit(function()
-            sys.taskInit(procConnect)
-        end)
-
-    else
-        if not param.apiEndpoint then
-            logger.info("apiEndpoint not found")
-            return
-        end
-        apiEndpoint = param.apiEndpoint
-        if param.typeKey ~= "" or param.typeKey ~= nil then
-            typeKey = param.typeKey
-        end
-        sys.waitUntil("IP_READY", 30000)
-        sys.taskInit(function()
-            sys.taskInit(fetchDeviceCert)
-        end)
-
-    end
-end
-
--- 一型一密,使用IMEI作为DeviceKey,领取设备证书AccessToken
-function fetchDeviceCert()
-    local headers = {}
-    headers["Project-Key"] = projectKey
-    headers["Content-Type"] = "application/json"
-    local url = apiEndpoint .. "/device/v1/certificate"
-    local deviceKey = mobile.imei()
-    local code, headers, body = http.request("POST", url, headers, json.encode({
-        device_key = deviceKey,
-        type_key = typeKey
-    }), {
-        timeout = 5000
-    }).wait()
-    log.info("http fetch cert:", deviceKey, code, headers, body)
-    if code == 200 then
-        local data = json.decode(body)
-        if data.result == 1 then
-            sys.taskInit(function()
-                cb("fetch_cert", true)
-            end)
-            deviceInfo = data.device
-            accessToken = deviceInfo.access_token
-            procConnect()
-            return
-        end
-    end
-    if certFetchRetryCnt < certFetchRetryMax then
-        -- 重试
-        certFetchRetryCnt = certFetchRetryCnt + 1
-        sys.wait(1000 * 10)
-        fetchDeviceCert()
-    else
-        cb("fetch_cert", false)
-    end
-end
-
-function procConnect()
-    mqttConnect()
-    sys.waitUntil("mqtt_conack")
-    sys.taskInit(function()
-        while true do
-            if #QUEUE.PUBLISH > 0 then
-                local item = table.remove(QUEUE.PUBLISH, 1)
-                logger.info("publish", item.topic, item.data)
-                if mqttc:publish(item.topic, item.data) then
-                    -- 
-                end
-            end
-            sys.wait(100)
-        end
-    end)
-end
-
-function ThingsCloud.isConnected()
-    return connected
-end
-
-local function insertPublishQueue(topic, data)
-    if not connected then
-        return
-    end
-    table.insert(QUEUE.PUBLISH, {
-        topic = topic,
-        data = data
-    })
-end
-
-function ThingsCloud.subscribe(topic)
-    if not connected then
-        return
-    end
-    logger.info("subscribe", topic)
-    mqttc:subscribe(topic)
-end
-
-function ThingsCloud.publish(topic, data)
-    insertPublishQueue(topic, data)
-end
-
-function ThingsCloud.reportAttributes(tableData)
-    insertPublishQueue("attributes", json.encode(tableData))
-    sys.publish("QUEUE_PUBLISH", "ATTRIBUTES")
-end
-
-function ThingsCloud.getAttributes(attrsList, options)
-    options = options or {}
-    options.getId = options.getId or 1000
-    local data = {
-        keys = attrsList
-    }
-    if #attrsList == 0 then
-        data = {}
-    end
-    insertPublishQueue("attributes/get/" .. tostring(options.getId), json.encode(data))
-end
-
-function ThingsCloud.reportEvent(event, options)
-    options = options or {}
-    options.eventId = options.eventId or 1000
-    insertPublishQueue("event/report/" .. tostring(options.eventId), json.encode(event))
-end
-
-function ThingsCloud.replyCommand(commandReply, options)
-    options = options or {}
-    options.replyId = options.replyId or 1000
-    insertPublishQueue("command/reply/" .. tostring(options.replyId), json.encode(commandReply))
-end
-
-function ThingsCloud.publishCustomTopic(topic, payload, options)
-    insertPublishQueue(topic, payload)
-end
-
-function getAccessToken()
-    return accessToken
-end
-
-function isGateway()
-    if deviceInfo.conn_type == "3" then
-        return true
-    end
-    return false
-end
-
-function split(str, sep)
-    local sep, fields = sep or ":", {}
-    local pattern = string.format("([^%s]+)", sep)
-    str:gsub(pattern, function(c)
-        fields[#fields + 1] = c
-    end)
-    return fields
-end
-
-return ThingsCloud

+ 0 - 116
script/turnkey/hz201p/attributes.lua

@@ -1,116 +0,0 @@
-local t = {}
-
-local attributes = {
-    location = {
-        lat = 0,
-        lng = 0,
-    },
-    isCharging = false,
-    battery = 0,
-    step = 0,
-    ledControl = false,
-    redLed = true,
-    blueLed = true,
-    isFixed = "获取中",
-    lat = "无数据",
-    lng = "无数据",
-    rsrp = 0,
-    rsrq = 0,
-    vbat = 0,
-    audioStatus = "空闲",
-    callStatus = "不支持",
-    isGPSOn = true,
-    sleepMode = false,
-}
-
---已修改的数据,缓存在这里,等待上报
-local reportTemp = {}
-
---初始化
-function t.initial()
-    sys.taskInit(function()
-        sys.waitUntil("CLOUD_CONNECTED") -- 连接成功
-        for k,v in pairs(reportTemp) do
-            attributes[k] = v
-        end
-        --上报数据初始化一下
-        --ThingsCloud.reportAttributes(attributes)
-        while true do
-            local hasData = false
-            for _,_ in pairs(reportTemp) do
-                hasData = true
-                break
-            end
-            if not hasData then
-                --没数据,等待
-                sys.waitUntil("ATTRIBUTES_UPDATED")
-            end
-            sys.wait(100)
-            --有数据,复制数据
-            local temp = {}
-            for k,v in pairs(reportTemp) do
-                temp[k] = v
-            end
-            reportTemp = {}
-            --上报数据
-            ThingsCloud.reportAttributes(temp)
-
-            sys.wait(5500)--防止上报太频繁,最快5秒一次
-        end
-    end)
-end
-
---修改数据
-function t.set(k,v,fromCloud)
-    --值没改变,不用处理
-    if attributes[k] == v then
-        return
-    end
-    --休眠模式下,只有sleepMode属性可以修改
-    if attributes.sleepMode then
-        log.info("attributes.set", "sleepMode",k,v)
-        if fromCloud then--云端下发的数据只能修改sleepMode属性
-            if k ~= "sleepMode" then
-                return
-            end
-        else
-            return
-        end
-    end
-    if type(v) == "table" then
-        local hasChange = false
-        for k1,v1 in pairs(v) do
-            if attributes[k][k1] ~= v1 then
-                hasChange = true
-                break
-            end
-        end
-        if not hasChange then
-            return
-        end
-    end
-    attributes[k] = v
-    --来自云端的数据不用缓存
-    if not fromCloud then
-        --缓存数据,等待上报
-        reportTemp[k] = v
-        sys.publish("ATTRIBUTES_UPDATED")
-    end
-end
-
---获取数据
-function t.get(k)
-    return attributes[k]
-end
-
---获取所有数据
-function t.all()
-    return attributes
-end
-
---刷新所有数据
-function t.setAll()
-    reportTemp = attributes
-end
-
-return t

+ 0 - 64
script/turnkey/hz201p/battery.lua

@@ -1,64 +0,0 @@
-function voltage_to_percentage(voltage)
-    local min_voltage = 3600
-    local max_voltage = 4190
-
-    if voltage <= min_voltage then
-        return 0
-    elseif voltage >= max_voltage then
-        return 100
-    else
-        local percentage = (voltage - min_voltage) / (max_voltage - min_voltage) * 100
-        return math.floor(percentage + 0.5) -- 四舍五入
-    end
-end
-
-
-adc.open(adc.CH_VBAT)
-sys.taskInit(function ()
-    repeat
-        local voltage = adc.get(adc.CH_VBAT)
-        local percentage = voltage_to_percentage(voltage)
-        log.info("battery", "voltage:", voltage, "percentage:", percentage)
-        --低于3.3V时,关机
-        if voltage < 3300 then
-            pm.shutdown()
-        end
-        attributes.set("battery", percentage)
-        attributes.set("vbat", voltage)
-        sys.wait(60000)
-    until nil
-end)
-
---充电状态检测
-local function chargeCheck()
-    log.info("chargeCheck", gpio.get(42))
-    attributes.set("isCharging", gpio.get(42) == 0)
-end
-gpio.setup(42, chargeCheck, 0, gpio.BOTH)
-attributes.set("isCharging", gpio.get(42) == 0)
-
-local function exitSleepMode()
-    pm.power(pm.WORK_MODE, 0)--退出休眠模式
-    --上报所有参数
-    sys.timerStart(attributes.setAll, 6000)
-    --重启一下
-    --pm.reboot()
-end
-
-sys.subscribe("SLEEP_CMD_RECEIVED", function(on)
-    if on then
-        log.info("battery","enter sleepMode wait")
-        pm.power(pm.WORK_MODE, 1)--进入休眠模式
-    else
-        log.info("battery","exit sleepMode wait")
-        exitSleepMode()
-    end
-end)
-
-sys.subscribe("POWERKEY_PRESSED", function()
-    log.info("battery","POWERKEY_PRESSED")
-    if attributes.get("sleepMode") then
-        attributes.set("sleepMode", false, true)
-        sys.publish("SLEEP_CMD_RECEIVED", false)
-    end
-end)

+ 0 - 115
script/turnkey/hz201p/bf30a2.lua

@@ -1,115 +0,0 @@
-
-local reg_table = {
-	{0xf2,0x01},
-	{0xcf,0xb0},
-	{0x12,0x20},
-	{0x15,0x80},
-	{0x6b,0x71},
-	{0x00,0x40},
-	{0x04,0x00},
-	{0x06,0x26},
-	{0x08,0x07},
-	{0x1c,0x12},
-	{0x20,0x20},
-	{0x21,0x20},
-	{0x34,0x02},
-	{0x35,0x02},
-	{0x36,0x21},
-	{0x37,0x13},
-	{0xca,0x23},
-	{0xcb,0x22},
-	{0xcc,0x89},
-	{0xcd,0x4c},
-	{0xce,0x6b},
-	{0xa0,0x8e},
-	{0x01,0x1b},
-	{0x02,0x1d},
-	{0x13,0x08},
-	{0x87,0x13},
-	{0x8b,0x08},
-	{0x70,0x17},
-	{0x71,0x43},
-	{0x72,0x0a},
-	{0x73,0x62},
-	{0x74,0xa2},
-	{0x75,0xbf},
-	{0x76,0x00},
-	{0x77,0xcc},
-	{0x40,0x32},
-	{0x41,0x28},
-	{0x42,0x26},
-	{0x43,0x1d},
-	{0x44,0x1a},
-	{0x45,0x14},
-	{0x46,0x11},
-	{0x47,0x0f},
-	{0x48,0x0e},
-	{0x49,0x0d},
-	{0x4B,0x0c},
-	{0x4C,0x0b},
-	{0x4E,0x0a},
-	{0x4F,0x09},
-	{0x50,0x09},
-	{0x24,0x30},
-	{0x25,0x36},
-	{0x80,0x00},
-	{0x81,0x20},
-	{0x82,0x40},
-	{0x83,0x30},
-	{0x84,0x50},
-	{0x85,0x30},
-	{0x86,0xd8},
-	{0x89,0x45},
-	{0x8a,0x33},
-	{0x8f,0x81},
-	{0x91,0xff},
-	{0x92,0x08},
-	{0x94,0x82},
-	{0x95,0xfd},
-	{0x9a,0x20},
-	{0x9e,0xbc},
-	{0xf0,0x87},
-	{0x51,0x06},
-	{0x52,0x25},
-	{0x53,0x2b},
-	{0x54,0x0f},
-	{0x57,0x2a},
-	{0x58,0x22},
-	{0x59,0x2c},
-	{0x23,0x33},
-	{0xa1,0x93},
-	{0xa2,0x0f},
-	{0xa3,0x2a},
-	{0xa4,0x08},
-	{0xa5,0x26},
-	{0xa7,0x80},
-	{0xa8,0x80},
-	{0xa9,0x1e},
-	{0xaa,0x19},
-	{0xab,0x18},
-	{0xae,0x50},
-	{0xaf,0x04},
-	{0xc8,0x10},
-	{0xc9,0x15},
-	{0xd3,0x0c},
-	{0xd4,0x16},
-	{0xee,0x06},
-	{0xef,0x04},
-	{0x55,0x34},
-	{0x56,0x9c},
-	{0xb1,0x98},
-	{0xb2,0x98},
-	{0xb3,0xc4},
-	{0xb4,0x0c},
-	{0xa0,0x8f},
-	{0x13,0x07},
-}
-
-function bf30a2Init(cspiId,i2cId,speed,scanMode,onlyY)
-	local id = camera.init(cspiId,speed,0,0,1,0,0,onlyY,scanMode,240,320)
-	for i=1,#reg_table do
-		i2c.send(i2cId,0x6e,reg_table[i],1)
-	end
-	camera.start(id)
-	return id
-end

+ 0 - 59
script/turnkey/hz201p/camCapture.lua

@@ -1,59 +0,0 @@
-require "bf30a2"
-
-camera.on(0, "scanned", function(id, str)
-    if type(str) == 'string' then
-        log.info("扫码结果", str)
-    elseif str == false then
-        log.error("摄像头没有数据")
-    else
-        log.info("摄像头数据", str)
-        sys.publish("capture done", true)
-    end
-end)
-
-local function press_key()
-    log.info("boot press")
-    sys.publish("PRESS", true)
-end
-
-gpio.setup(0, press_key, gpio.PULLDOWN, gpio.RISING)
-
-gpio.debounce(0, 100, 1)
-
-local rawbuff, err = zbuff.create(60 * 1024, 0, zbuff.HEAP_AUTO)
-
-if rawbuff == nil then
-    log.info(err)
-end
-
-
-
-sys.taskInit(function()
-    log.info("摄像头启动")
-    local cspiId, i2cId = 1, 0
-    local camera_id
-    i2c.setup(i2cId, i2c.FAST)
-    gpio.setup(5, 0) -- PD拉低
-    log.info("按下boot开始测试")
-    log.info(rtos.meminfo("sys"))
-    log.info(rtos.meminfo("psram"))
-    while 1 do
-        local result, data = sys.waitUntil("PRESS")
-        if result == true and data == true then
-            log.debug("摄像头拍照")
-            camera_id = bf30a2Init(cspiId, i2cId, 25500000)
-            camera.capture(camera_id, rawbuff, 1) -- 2和3需要非常多非常多的psram,尽量不要用
-            result, data = sys.waitUntil("capture done", 30000)
-            if result then
-                log.info(rawbuff:used())
-            end
-            camera.close(camera_id) -- 完全关闭摄像头才用这个
-            rawbuff:resize(60 * 1024)
-            log.info(rtos.meminfo("sys"))
-            log.info(rtos.meminfo("psram"))
-        end
-    end
-end)
-
-sys.publish("PRESS", true)
-sys.timerLoopStart(sys.publish, 60000, "PRESS", true)

+ 0 - 158
script/turnkey/hz201p/ccVolte.lua

@@ -1,158 +0,0 @@
-local pcmFile = "/luadb/10.pcm"
-local amrFile = "/luadb/10.amr"
-
-local ringTimer
-local hangUpCb = function()
-    cc.hangUp(0)
-end
-local acceptCb = function()
-    if ringTimer then
-        sys.timerStop(ringTimer)
-        ringTimer = nil
-    end
-    if not audio.isEnd(0) then
-        log.info("手动关闭")
-        audio.playStop(0)
-    end
-    local result = cc.accept(0)
-    log.info("cc accept", result)
-    sys.subscribe("POWERKEY_PRESSED", hangUpCb)
-end
-
-local cnt = 0
-sys.subscribe("CC_IND", function(state)
-    log.info("CC_IND", state)
-    if state == "READY" then
-        sys.publish("CC_READY")
-    elseif state == "INCOMINGCALL" then
-        cnt = cnt + 1
-        if cnt > 1 then
-            if ringTimer then return end
-            sys.subscribe("POWERKEY_PRESSED", acceptCb)
-            attributes.set("callStatus", "通话中")
-            attributes.set("audioStatus", "通话中")
-            if ringTimer then
-                sys.timerStop(ringTimer)
-                ringTimer = nil
-            end
-            if not audio.isEnd(0) then
-                log.info("手动关闭")
-                audio.playStop(0)
-            end
-            local buff = io.readFile(pcmFile)
-            audio.start(0, audio.PCM, 1, 8000, 16)
-            audio.write(0, buff)
-            ringTimer = sys.timerLoopStart(function()
-                if not audio.isEnd(0) then
-                    log.info("手动关闭")
-                    audio.playStop(0)
-                end
-                audio.write(0, buff)
-            end, 400)
-        end
-    elseif state == "HANGUP_CALL_DONE" or state == "MAKE_CALL_FAILED" or state == "DISCONNECTED" then
-        pcall(sys.unsubscribe, "POWERKEY_PRESSED", acceptCb)
-        pcall(sys.unsubscribe, "POWERKEY_PRESSED", hangUpCb)
-        if ringTimer then
-            sys.timerStop(ringTimer)
-            ringTimer = nil
-        end
-        attributes.set("callStatus", "已就绪")
-        attributes.set("audioStatus", "空闲")
-        sys.publish("CC_DONE")
-        audio.pm(0, audio.STANDBY)
-        -- audio.pm(0,audio.SHUTDOWN)	--低功耗可以选择SHUTDOWN或者POWEROFF,如果codec无法断电用SHUTDOWN
-    end
-end)
-
-local ccReady = false
-local es8311Power = gpio.setup(25, 1)
-sys.taskInit(function()
-    local multimedia_id = 0
-    local i2c_id = 0
-    local i2s_id = 0
-    local i2s_mode = 0
-    local i2s_sample_rate = 16000
-    local i2s_bits_per_sample = 16
-    local i2s_channel_format = i2s.MONO_R
-    local i2s_communication_format = i2s.MODE_LSB
-    local i2s_channel_bits = 16
-    local pa_pin = 23
-    local pa_on_level = 1
-    local pa_delay = 100
-    local power_pin = 255
-    local power_on_level = 1
-    local power_delay = 3
-    local power_time_delay = 100
-    local voice_vol = 70
-    local mic_vol = 90
-    local find_es8311 = false
-    mcu.altfun(mcu.I2C, i2c_id, 13, 2, 0)
-    mcu.altfun(mcu.I2C, i2c_id, 14, 2, 0)
-    i2c.setup(i2c_id, i2c.FAST)
-    sys.wait(10)
-    if i2c.send(i2c_id, 0x18, 0xfd) == true then
-        find_es8311 = true
-    end
-    if not find_es8311 then
-        while true do
-            log.info("not find es8311")
-            sys.wait(1000)
-        end
-    end
-    i2s.setup(i2s_id, i2s_mode, i2s_sample_rate, i2s_bits_per_sample, i2s_channel_format, i2s_communication_format, i2s_channel_bits)
-    audio.config(multimedia_id, pa_pin, pa_on_level, power_delay, pa_delay, power_pin, power_on_level, power_time_delay)
-    audio.setBus(multimedia_id, audio.BUS_I2S, {
-        chip = "es8311",
-        i2cid = i2c_id,
-        i2sid = i2s_id,
-        voltage = audio.VOLTAGE_1800
-    }) -- 通道0的硬件输出通道设置为I2S
-    audio.vol(multimedia_id, voice_vol)
-    audio.micVol(multimedia_id, mic_vol)
-    cc.init(multimedia_id)
-    audio.pm(0, audio.STANDBY)
-    sys.publish("AUDIO_SETUP_DONE")--音频初始化完毕了
-    sys.waitUntil("CC_READY")
-    ccReady = true
-    attributes.set("callStatus", "已就绪")
-    sys.wait(100)
-end)
-
-sys.taskInit(function()
-    sys.waitUntil("AUDIO_SETUP_DONE")
-    log.info("audio", "ready")
-    while true do
-        local _,cmd,param = sys.waitUntil("AUDIO_CMD_RECEIVED")
-        log.info("audio", cmd, param)
-        --低功耗模式就别放了
-        if attributes.get("sleepMode") then
-            log.info("audio", "sleepMode cancel play")
-        elseif cmd == "call" then
-            if ccReady then
-                cc.dial(0,param) --拨打电话
-                attributes.set("callStatus", "通话中")
-                attributes.set("audioStatus", "通话中")
-                sys.subscribe("POWERKEY_PRESSED", hangUpCb)
-                sys.waitUntil("CC_DONE")
-            else
-                log.info("audio", "cc not ready")
-            end
-        elseif cmd == "music" then
-            local result = audio.play(0, amrFile)
-            attributes.set("audioStatus", "播放中")
-            log.info("audio", "play music",result)
-            sys.wait(1000)
-            if not audio.isEnd(0) then
-                log.info("手动关闭")
-                audio.playStop(0)
-            end
-            audio.pm(0, audio.STANDBY)
-            attributes.set("audioStatus", "空闲")
-        end
-    end
-end)
-
-audio.on(0, function(audio_id, msg)
-    log.info("msg", audio_id, msg)
-end)

+ 0 - 80
script/turnkey/hz201p/cloud.lua

@@ -1,80 +0,0 @@
--- 引入 ThingsCloud 接入库
--- 接入协议参考:ThingsCloud MQTT 接入文档 https://docs.thingscloud.xyz/guide/connect-device/mqtt.html
-_G.ThingsCloud = require "ThingsCloud"
-
--- 进入 ThingsCloud 控制台:https://www.thingscloud.xyz
--- 创建设备,进入设备详情页的【连接】页面,复制设备证书和MQTT接入点地址。请勿泄露你的设备证书。
--- projectKey
-local projectKey = "PyvS86eR0D"
--- typeKey
-local typeKey = "b0c0eqsmta"
--- MQTT 接入点,只需主机名部分
-local host = "sh-1-mqtt.iot-api.com"
--- apiEndpoint
-local apiEndpoint = "http://sh-1-api.iot-api.com"
-
-
-
--- 设备成功连接云平台后,触发该函数
-local function onConnect(result)
-    log.info("cloud","onConnect", result)
-    if result then
-        sys.publish("CLOUD_CONNECTED")
-        _G_CONNECTED = true
-        -- 当设备连接成功后
-        -- 例如:切换设备的LED闪烁模式,提示用户设备已正常连接。
-
-        --上报所有参数
-        attributes.setAll()
-    end
-end
-
--- 设备接收到云平台下发的属性时,触发该函数
-local function onReceive(response)
-    for k, v in pairs(response) do
-        log.info("onReceive", k, v)
-        if k == "phone" then
-            -- 设备接收到云端下发的电话号码,开始拨打电话。
-            sys.publish("AUDIO_CMD_RECEIVED","call",v)
-        elseif k == "sleepMode" then
-            -- 设备收到低功耗要求,更改低功耗模式
-            attributes.set("isGPSOn", false)
-            attributes.set("isFixed", "定位功能已关闭")
-            attributes.set("lat", "无数据")
-            attributes.set("lng", "无数据")
-            --最后再更改变量
-            attributes.set(k, v, true)
-            sys.timerStart(sys.publish, 6000, "SLEEP_CMD_RECEIVED", v)
-        else
-            attributes.set(k, v, true)
-        end
-    end
-end
-
--- 设备接收到云平台下发的命令时,触发该函数
-local function onCommand(cmd)
-    if cmd.method == "play" then
-        -- 设备接收到云端下发的播放命令,开始播放音乐。
-        log.info("play music")
-        sys.publish("AUDIO_CMD_RECEIVED","music")
-    end
-end
-
--- 设备接入云平台的初始化逻辑,在独立协程中完成
-sys.taskInit(function()
-    -- 连接云平台,内部支持判断网络可用性、MQTT自动重连
-    -- 这里采用了设备一机一密方式,需要为每个设备固件单独写入证书。另外也支持一型一密,相同设备类型下的所有设备使用相同固件。
-    ThingsCloud.connect({
-        host = host,
-        projectKey = projectKey,
-        typeKey = typeKey,
-        apiEndpoint = apiEndpoint,
-    })
-
-    -- 注册各类事件的回调函数,在回调函数中编写所需的硬件端操作逻辑
-    ThingsCloud.on("connect", onConnect)
-    ThingsCloud.on("attributes_push", onReceive)
-    ThingsCloud.on("command_send", onCommand)
-
-    sys.waitUntil("CLOUD_CONNECTED") -- 连接成功
-end)

+ 0 - 266
script/turnkey/hz201p/core/luat_conf_bsp.h

@@ -1,266 +0,0 @@
-
-#ifndef LUAT_CONF_BSP
-#define LUAT_CONF_BSP
-
-//------------------------------------------------------
-// 以下custom --> 到  <-- custom 之间的内容,是供用户配置的
-// 同时也是云编译可配置的部分. 提交代码时切勿删除会修改标识
-
-#define LUAT_USE_GPIO 1
-#define LUAT_USE_UART 1
-#define LUAT_USE_I2C 1
-#define LUAT_USE_ADC 1
-#define LUAT_USE_PWM 1
-#define LUAT_USE_WDT 1
-#define LUAT_USE_SPI 1
-#define LUAT_USE_MCU 1
-#define LUAT_USE_RTC 1
-#define LUAT_USE_PM 1
-#define LUAT_USE_MEDIA 1
-#define LUAT_USE_RECORD 1
-#define LUAT_USE_WLAN 1
-#define LUAT_USE_MQTT 1
-#define LUAT_USE_CJSON 1
-#define LUAT_USE_FS 1
-#define LUAT_USE_PACK 1
-#define LUAT_USE_ZBUFF 1
-#define LUAT_USE_LIBGNSS 1
-#define LUAT_USE_FSKV 1
-
-#define LUAT_SCRIPT_SIZE 96
-#define LUAT_SCRIPT_OTA_SIZE 72
-
-
-//------------------------------------------------------------------------------
-
-// 以下选项仅开发人员可修改, 一般用户切勿自行修改
-//-----------------------------
-// 内存配置, 默认200k, 128 ~ 324k 可调. 324k属于极限值, 不可使用音频, 并限制TLS连接的数量不超过2个
-// #ifdef LUAT_HEAP_SIZE_324K
-// #define LUAT_HEAP_SIZE (324*1024)
-// #endif
-#ifdef LUAT_HEAP_SIZE_300K
-#define LUAT_HEAP_SIZE (300*1024)
-#endif
-#ifdef LUAT_HEAP_SIZE_200K
-#define LUAT_HEAP_SIZE (200*1024)
-#endif
-// // 一般无需修改. 若不需要使用SSL/TLS/TTS,可适当增加,但不应该超过256k
-#ifndef LUAT_HEAP_SIZE
-#define LUAT_HEAP_SIZE (250*1024)
-#endif
-
-#if defined TYPE_EC718P && defined (FEATURE_IMS_ENABLE)
-#if LUAT_HEAP_SIZE > (160*1024)
-#undef LUAT_HEAP_SIZE
-#define LUAT_HEAP_SIZE (160*1024)
-#endif
-
-#if LUAT_SCRIPT_SIZE > 128
-#undef LUAT_SCRIPT_SIZE
-#undef LUAT_SCRIPT_OTA_SIZE
-#define LUAT_SCRIPT_SIZE 128
-#define LUAT_SCRIPT_OTA_SIZE 96
-#endif
-#endif
-
-//-----------------------------
-
-// 将UART0切换到用户模式, 默认是UNILOG模式
-// 使用UART0, 日志将完全依赖USB输出, 若USB未引出或失效, 将无法获取底层日志
-// 本功能仅限完全了解风险的用户使用
-// #define LUAT_UART0_FORCE_USER     1
-// #define LUAT_UART0_FORCE_ALT1     1
-// #define LUAT_UART0_LOG_BR_12M     1
-#if defined CHIP_EC716
-#define LUAT_GPIO_PIN_MAX 29
-#else
-#define LUAT_GPIO_PIN_MAX 47
-#endif
-// #define LUAT__UART_TX_NEED_WAIT_DONE
-// // 内存优化: 减少内存消耗, 会稍微减低性能
-#define LUAT_USE_MEMORY_OPTIMIZATION_CODE_MMAP 1
-
-//----------------------------------
-// 使用VFS(虚拟文件系统)和内置库文件, 必须启用
-#define LUAT_USE_VFS_INLINE_LIB 1
-#define LUA_USE_VFS_FILENAME_OFFSET 1
-// //----------------------------------
-
-#define LUAT_WS2812B_MAX_CNT	(8)
-
-#define LV_DISP_DEF_REFR_PERIOD 30
-#define LUAT_LV_DEBUG 0
-
-#define LV_MEM_CUSTOM 1
-
-#define LUAT_USE_LVGL_INDEV 1 // 输入设备
-
-#define LV_HOR_RES_MAX          (160)
-#define LV_VER_RES_MAX          (80)
-#define LV_COLOR_DEPTH          16
-
-#define LV_COLOR_16_SWAP   1
-#define __LVGL_SLEEP_ENABLE__
-
-#undef LV_DISP_DEF_REFR_PERIOD
-#define LV_DISP_DEF_REFR_PERIOD g_lvgl_flash_time
-
-#define LV_TICK_CUSTOM 1
-#define LV_TICK_CUSTOM_INCLUDE  "common_api.h"         /*Header for the system time function*/
-#define LV_TICK_CUSTOM_SYS_TIME_EXPR ((uint32_t)GetSysTickMS())     /*Expression evaluating to current system time in ms*/
-
-// #define LUAT_USE_LCD_CUSTOM_DRAW
-
-#define __LUATOS_TICK_64BIT__
-
-#define LUAT_RET int
-#define LUAT_RT_RET_TYPE	void
-#define LUAT_RT_CB_PARAM void *param
-
-#define LUAT_USE_NETWORK 1
-// LUAT_USE_TLS 通过xmake判断打开
-// #define LUAT_USE_TLS 1
-#define LUAT_USE_LWIP 1
-#define LUAT_USE_DNS 1
-#define LUAT_USE_ERR_DUMP 1
-#define LUAT_USE_DHCP  1
-#define LUAT_USE_ERRDUMP 1
-#define LUAT_USE_FOTA 1
-#define LUAT_USE_MOBILE 1
-#define LUAT_USE_SNTP 1
-#define LUAT_USE_WLAN_SCANONLY 1
-//目前没用到的宏,但是得写在这里
-#define LUAT_USE_I2S
-#ifdef LUAT_USE_MEDIA
-#define LUAT_SUPPORT_AMR  1
-#endif
-#ifndef LUAT_USE_HMETA
-#define LUAT_USE_HMETA 1
-#endif
-
-// MCU引脚复用
-#define LUAT_MCU_IOMUX_CTRL 1
-
-#if defined TYPE_EC718P && defined (FEATURE_IMS_ENABLE)
-#define LUAT_USE_VOLTE
-
-#ifndef LUAT_USE_MEDIA
-#define LUAT_USE_MEDIA 1
-#endif
-
-#endif
-
-// // TTS 相关
-#ifdef LUAT_USE_TTS
-
-#ifndef LUAT_USE_TTS_8K
-#define LUAT_USE_TTS_16K 1
-#endif // LUAT_USE_TTS_8K
-
-#ifndef LUAT_USE_MEDIA
-#define LUAT_USE_MEDIA 1
-#endif
-
-// #ifdef LUAT_USE_TTS_ONCHIP
-// #undef LUAT_USE_SFUD
-// #else
-// #ifndef LUAT_USE_SFUD
-// #define LUAT_USE_SFUD  1
-// #endif // LUAT_USE_SFUD
-// #endif // LUAT_USE_TTS_ONCHIP
-
-#endif // LUAT_USE_TTS
-
-// 当前不支持软件UART, 自动禁用之
-#ifdef LUAT_USE_SOFT_UART
-#undef LUAT_USE_SOFT_UART
-#endif
-
-// #ifdef LUAT_USE_TTS_ONCHIP
-// #undef LUAT_SCRIPT_SIZE
-// #undef LUAT_SCRIPT_OTA_SIZE
-// #define LUAT_SCRIPT_SIZE 64
-// #define LUAT_SCRIPT_OTA_SIZE 48
-// #endif
-
-#define LUA_SCRIPT_ADDR (FLASH_FOTA_REGION_START - (LUAT_SCRIPT_SIZE + LUAT_SCRIPT_OTA_SIZE) * 1024)
-#define LUA_SCRIPT_OTA_ADDR FLASH_FOTA_REGION_START - (LUAT_SCRIPT_OTA_SIZE * 1024)
-
-#define __LUAT_C_CODE_IN_RAM__ __attribute__((__section__(".platFMRamcode")))
-
-#ifdef LUAT_USE_TLS_DISABLE
-#undef LUAT_USE_TLS
-#endif
-
-// 关闭加密版本的UDP, 类似于TCP的TLS/SSL, 极少使用
-#ifdef LUAT_CONF_TLS_DTLS_DISABLE
-#undef MBEDTLS_SSL_PROTO_DTLS
-#undef MBEDTLS_SSL_DTLS_ANTI_REPLAY
-#undef MBEDTLS_SSL_DTLS_HELLO_VERIFY
-#undef MBEDTLS_SSL_DTLS_BADMAC_LIMIT
-#endif
-
-// 关闭几个不常用的东西
-#ifdef LUAT_CONF_TLS_DISABLE_NC
-#undef MBEDTLS_X509_RSASSA_PSS_SUPPORT
-#undef MBEDTLS_DES_C
-#undef MBEDTLS_DHM_C
-#undef MBEDTLS_GCM_C
-#undef MBEDTLS_PSA_CRYPTO_C
-#undef MBEDTLS_PKCS1_V21
-#endif
-
-// 关闭几个不常用的东西
-#ifdef LUAT_CONF_TLS_DISABLE_ECP_ECDHE
-#undef MBEDTLS_ECP_DP_SECP192R1_ENABLED
-#undef MBEDTLS_ECP_DP_SECP224R1_ENABLED
-#undef MBEDTLS_ECP_DP_SECP256R1_ENABLED
-#undef MBEDTLS_ECP_DP_SECP384R1_ENABLED
-#undef MBEDTLS_ECP_DP_SECP521R1_ENABLED
-#undef MBEDTLS_ECP_DP_SECP192K1_ENABLED
-#undef MBEDTLS_ECP_DP_SECP224K1_ENABLED
-#undef MBEDTLS_ECP_DP_SECP256K1_ENABLED
-#undef MBEDTLS_ECP_DP_BP256R1_ENABLED
-#undef MBEDTLS_ECP_DP_BP384R1_ENABLED
-#undef MBEDTLS_ECP_DP_BP512R1_ENABLED
-/* Montgomery curves (supporting ECP) */
-#undef MBEDTLS_ECP_DP_CURVE25519_ENABLED
-#undef MBEDTLS_ECP_DP_CURVE448_ENABLED
-
-#undef MBEDTLS_ECP_NIST_OPTIM
-// #undef MBEDTLS_ECDH_LEGACY_CONTEXT
-
-#undef MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
-#undef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
-#undef MBEDTLS_ECDH_C
-#undef MBEDTLS_ECP_C
-#undef MBEDTLS_ECDSA_C
-
-#endif
-
-
-#ifndef PSRAM_FEATURE_ENABLE
-#undef LUAT_USE_CAMERA
-#endif
-
-#ifdef TYPE_EC716E
-#undef LUAT_HEAP_SIZE
-#define LUAT_HEAP_SIZE (200*1024)
-#endif
-
-#ifdef LUAT_USE_CAMERA
-#define LUAT_USE_LCD_SERVICE 1
-#endif
-
-#ifdef LUAT_SUPPORT_AMR
-#if defined (FEATURE_AMR_CP_ENABLE) || defined (FEATURE_VEM_CP_ENABLE)
-#define LUAT_USE_INTER_AMR	1
-#endif
-#endif
-
-#if defined (PSRAM_FEATURE_ENABLE) && (PSRAM_EXIST==1)
-#define LUAT_USE_PSRAM
-#endif
-
-#endif

+ 0 - 76
script/turnkey/hz201p/da267.lua

@@ -1,76 +0,0 @@
-local i2cId = 1
-local da267Addr = 0x26
-local intPin = 39
-local function ind()
-    log.info("int", gpio.get(intPin))
-    if gpio.get(intPin) == 1 then
-        log.info("da267", "interrupt")
-        i2c.send(i2cId, da267Addr, 0x02, 1)
-        local data = i2c.recv(i2cId, da267Addr, 6)
-        if data and #data == 6 then
-            local xl, xm, yl, ym, zl, zm = string.byte(data, 1, 1), string.byte(data, 2, 2), string.byte(data, 3, 3), string.byte(data, 4, 4), string.byte(data, 5, 5), string.byte(data, 6, 6)
-            local x, y, z = (xm << 8 | xl ) >> 4, (ym << 8 | yl) >> 4, (zm << 8 | zl ) >> 4
-            log.info("da267", "x:", x, "y:", y, "z:", z)
-        else
-            sys.publish("RESTORE_GSENSOR")
-        end
-        i2c.send(i2cId, da267Addr, 0x0D, 1)
-        local data = i2c.recv(i2cId, da267Addr, 2)
-        if data and #data == 2 then
-            local xl, xm = string.byte(data, 1, 1), string.byte(data, 2, 2)
-            local step = ((xl << 8) + xm) // 2
-            log.info("da267", "step:", step)
-            sys.publish("STEP_COUNTER", step)
-        else
-            sys.publish("RESTORE_GSENSOR")
-        end
-    end
-end
-gpio.setup(intPin, ind)
-
-local function init()
-    i2c.close(i2cId)
-    i2c.setup(i2cId, i2c.SLOW)
-    i2c.send(i2cId, da267Addr, {0x00, 0x24}, 1)
-    sys.wait(20)
-    i2c.send(i2cId, da267Addr, {0x0F, 0x00}, 1)
-    i2c.send(i2cId, da267Addr, {0x11, 0x34}, 1)
-    i2c.send(i2cId, da267Addr, {0x10, 0x07}, 1)
-
-    sys.wait(50)
-
-    -- int set1
-    i2c.send(i2cId, da267Addr, {0x16, 0x87}, 1)
-
-    -- init active interrupt
-    i2c.send(i2cId, da267Addr, {0x38, 0x03}, 1)
-    i2c.send(i2cId, da267Addr, {0x39, 0x05}, 1)
-    i2c.send(i2cId, da267Addr, {0x3A, 0x05}, 1)
-    i2c.send(i2cId, da267Addr, {0x3B, 0x05}, 1)
-    i2c.send(i2cId, da267Addr, {0x19, 0x04}, 1)
-
-    -- enable active
-    i2c.send(i2cId, da267Addr, {0x11, 0x30}, 1)
-
-    -- init step counter
-    i2c.send(i2cId, da267Addr, {0x33, 0x80}, 1)
-end
-
-sys.taskInit(function()
-    mcu.altfun(mcu.I2C, i2cId, 23, 2, 0)
-    mcu.altfun(mcu.I2C, i2cId, 24, 2, 0)
-    while true do
-        init()
-        while true do
-            local result = sys.waitUntil("RESTORE_GSENSOR", 60 * 1000)
-            if result then
-                break
-            end
-            i2c.send(i2cId, da267Addr, 0x01, 1)
-            local data = i2c.recv(i2cId, da267Addr, 1)
-            if not data or data == "" or string.byte(data) ~= 0x13 then
-                break
-            end
-        end
-    end
-end)

+ 0 - 328
script/turnkey/hz201p/gc0310.lua

@@ -1,328 +0,0 @@
-local reg_table = {
-    {0xfe, 0xf0},
-    {0xfe, 0xf0},
-    {0xfe, 0x00},
-    {0xfc, 0x16}, 
-    {0xfc, 0x16}, 
-    {0xf2, 0x07}, 
-    {0xf3, 0x83}, 
-    {0xf5, 0x07}, 
-    {0xf7, 0x88}, 
-    {0xf8, 0x00}, 
-    {0xf9, 0x4f}, 
-    {0xfa, 0x11}, 
-    {0xfc, 0xce},
-    {0xfd, 0x00},
-
-    {0x00, 0x2f},
-    {0x01, 0x0f},
-    {0x02, 0x04},
-    {0x03, 0x02},
-    {0x04, 0x12},
-    {0x09, 0x00},
-    {0x0a, 0x00},
-    {0x0b, 0x00},
-    {0x0c, 0x04},
-    {0x0d, 0x01},
-    {0x0e, 0xe8},
-    {0x0f, 0x02},
-    {0x10, 0x88},
-    {0x16, 0x00},
-    {0x17, 0x14},
-    {0x18, 0x1a},
-    {0x19, 0x14},
-    {0x1b, 0x48},
-    {0x1c, 0x6c},
-    {0x1e, 0x6b},
-    {0x1f, 0x28},
-    {0x20, 0x8b},
-    {0x21, 0x49},
-    {0x22, 0xd0},
-    {0x23, 0x04},
-    {0x24, 0xff},
-    {0x34, 0x20},
-
-    {0x26, 0x23}, 
-    {0x28, 0xff}, 
-    {0x29, 0x00}, 
-    {0x32, 0x04},
-    {0x33, 0x10}, 
-    {0x37, 0x20}, 
-    {0x38, 0x10},
-    {0x47, 0x80}, 
-    {0x4e, 0x66}, 
-    {0xa8, 0x02}, 
-    {0xa9, 0x80},
-
-    {0x40, 0xff},
-    {0x41, 0x21}, 
-    {0x42, 0xcf}, 
-    {0x44, 0x00},
-    {0x45, 0xa0},
-    {0x46, 0x02}, 
-    {0x4a, 0x11},
-    {0x4b, 0x01},
-    {0x4c, 0x20}, 
-    {0x4d, 0x05}, 
-    {0x4f, 0x01},
-    {0x50, 0x01}, 
-    {0x55, 0x01}, 
-    {0x56, 0xe0},
-    {0x57, 0x02}, 
-    {0x58, 0x80},
-
-    {0x70, 0x70},
-    {0x5a, 0x84},
-    {0x5b, 0xc9},
-    {0x5c, 0xed},
-    {0x77, 0x74},
-    {0x78, 0x40},
-    {0x79, 0x5f},
-
-    {0x82, 0x14},
-    {0x83, 0x0b},
-    {0x89, 0xf0},
-
-    {0x8f, 0xaa},
-    {0x90, 0x8c},
-    {0x91, 0x90},
-    {0x92, 0x03},
-    {0x93, 0x03},
-    {0x94, 0x05},
-    {0x95, 0x65},
-    {0x96, 0xf0},
-
-    {0xfe, 0x00},
-    {0x9a, 0x20},
-    {0x9b, 0x80},
-    {0x9c, 0x40},
-    {0x9d, 0x80},
-    {0xa1, 0x30},
-    {0xa2, 0x32},
-    {0xa4, 0x30}, 
-    {0xa5, 0x30}, 
-    {0xaa, 0x10}, 
-    {0xac, 0x22},
-
-    {0xfe, 0x00},
-    {0xbf, 0x08},
-    {0xc0, 0x16},
-    {0xc1, 0x28},
-    {0xc2, 0x41},
-    {0xc3, 0x5a},
-    {0xc4, 0x6c},
-    {0xc5, 0x7a},
-    {0xc6, 0x96},
-    {0xc7, 0xac},
-    {0xc8, 0xbc},
-    {0xc9, 0xc9},
-    {0xca, 0xd3},
-    {0xcb, 0xdd},
-    {0xcc, 0xe5},
-    {0xcd, 0xf1},
-    {0xce, 0xfa},
-    {0xcf, 0xff},
-
-    {0xd0, 0x40},
-    {0xd1, 0x34},
-    {0xd2, 0x34},
-    {0xd3, 0x40},
-    {0xd6, 0xf2},
-    {0xd7, 0x1b},
-    {0xd8, 0x18},
-    {0xdd, 0x03},
-
-    {0xfe, 0x01},
-    {0x05, 0x30},
-    {0x06, 0x75},
-    {0x07, 0x40},
-    {0x08, 0xb0},
-    {0x0a, 0xc5},
-    {0x0b, 0x11},
-    {0x0c, 0x00},
-    {0x12, 0x52},
-    {0x13, 0x38},
-    {0x18, 0x95},
-    {0x19, 0x96},
-    {0x1f, 0x20},
-    {0x20, 0xc0},
-    {0x3e, 0x40},
-    {0x3f, 0x57},
-    {0x40, 0x7d},
-    {0x03, 0x60},
-    {0x44, 0x00},
-
-    {0xfe, 0x01},
-    {0x1c, 0x91},
-    {0x21, 0x15},
-    {0x50, 0x80},
-    {0x56, 0x04},
-    {0x59, 0x08},
-    {0x5b, 0x02},
-    {0x61, 0x8d},
-    {0x62, 0xa7},
-    {0x63, 0xd0},
-    {0x65, 0x06},
-    {0x66, 0x06},
-    {0x67, 0x84},
-    {0x69, 0x08},
-    {0x6a, 0x25},
-    {0x6b, 0x01},
-    {0x6c, 0x00},
-    {0x6d, 0x02},
-    {0x6e, 0xf0},
-    {0x6f, 0x80},
-    {0x76, 0x80},
-    {0x78, 0xaf},
-    {0x79, 0x75},
-    {0x7a, 0x40},
-    {0x7b, 0x50},
-    {0x7c, 0x0c},
-    {0x90, 0xc9}, 
-    {0x91, 0xbe},
-    {0x92, 0xe2},
-    {0x93, 0xc9},
-    {0x95, 0x1b},
-    {0x96, 0xe2},
-    {0x97, 0x49},
-    {0x98, 0x1b},
-    {0x9a, 0x49},
-    {0x9b, 0x1b},
-    {0x9c, 0xc3},
-    {0x9d, 0x49},
-    {0x9f, 0xc7},
-    {0xa0, 0xc8},
-    {0xa1, 0x00},
-    {0xa2, 0x00},
-    {0x86, 0x00},
-    {0x87, 0x00},
-    {0x88, 0x00},
-    {0x89, 0x00},
-    {0xa4, 0xb9},
-    {0xa5, 0xa0},
-    {0xa6, 0xba},
-    {0xa7, 0x92},
-    {0xa9, 0xba},
-    {0xaa, 0x80},
-    {0xab, 0x9d},
-    {0xac, 0x7f},
-    {0xae, 0xbb},
-    {0xaf, 0x9d},
-    {0xb0, 0xc8},
-    {0xb1, 0x97},
-    {0xb3, 0xb7},
-    {0xb4, 0x7f},
-    {0xb5, 0x00},
-    {0xb6, 0x00},
-    {0x8b, 0x00},
-    {0x8c, 0x00},
-    {0x8d, 0x00},
-    {0x8e, 0x00},
-    {0x94, 0x55},
-    {0x99, 0xa6},
-    {0x9e, 0xaa},
-    {0xa3, 0x0a},
-    {0x8a, 0x00},
-    {0xa8, 0x55},
-    {0xad, 0x55},
-    {0xb2, 0x55},
-    {0xb7, 0x05},
-    {0x8f, 0x00},
-    {0xb8, 0xcb},
-    {0xb9, 0x9b},
-
-    {0xfe, 0x01},
-    {0xd0, 0x38}, 
-    {0xd1, 0x00},
-    {0xd2, 0x02},
-    {0xd3, 0x04},
-    {0xd4, 0x38},
-    {0xd5, 0x12},
-    {0xd6, 0x30},
-    {0xd7, 0x00},
-    {0xd8, 0x0a},
-    {0xd9, 0x16},
-    {0xda, 0x39},
-    {0xdb, 0xf8},
-
-    {0xfe, 0x01},
-    {0xc1, 0x3c},
-    {0xc2, 0x50},
-    {0xc3, 0x00},
-    {0xc4, 0x40},
-    {0xc5, 0x30},
-    {0xc6, 0x30},
-    {0xc7, 0x10},
-    {0xc8, 0x00},
-    {0xc9, 0x00},
-    {0xdc, 0x20},
-    {0xdd, 0x10},
-    {0xdf, 0x00},
-    {0xde, 0x00},
-
-    {0x01, 0x10},
-    {0x0b, 0x31}, 
-    {0x0e, 0x50},
-    {0x0f, 0x0f},
-    {0x10, 0x6e},
-    {0x12, 0xa0},
-    {0x15, 0x60},
-    {0x16, 0x60},
-    {0x17, 0xe0},
-
-    {0xcc, 0x0c}, 
-    {0xcd, 0x10},
-    {0xce, 0xa0},
-    {0xcf, 0xe6},
-
-
-    {0x45, 0xf7},
-    {0x46, 0xff}, 
-    {0x47, 0x15},
-    {0x48, 0x03}, 
-    {0x4f, 0x60}, 
-
-    {0xfe, 0x00},
-    {0x05, 0x01},
-    {0x06, 0x32}, 
-    {0x07, 0x00},
-    {0x08, 0x0c}, 
-    {0xfe, 0x01},
-    {0x25, 0x00}, 
-    {0x26, 0x3c},
-    {0x27, 0x01}, 
-    {0x28, 0xdc},
-    {0x29, 0x01}, 
-    {0x2a, 0xe0},
-    {0x2b, 0x01}, 
-    {0x2c, 0xe0},
-    {0x2d, 0x01}, 
-    {0x2e, 0xe0},
-    {0x3c, 0x20},
-
-    --SPI配置
-    {0xfe, 0x03},
-    {0x52, 0xa2},
-    {0x53, 0x24}, 
-    {0x54, 0x20},
-    {0x55, 0x00},
-    {0x59, 0x1f}, 
-    {0x5a, 0x00},
-    {0x5b, 0x80},
-    {0x5c, 0x02},
-    {0x5d, 0xe0},
-    {0x5e, 0x01},
-    {0x51, 0x03},
-    {0x64, 0x04},
-    {0xfe, 0x00},
-    {0x44, 0x02},
-}
-
-function gc0310Init(cspiId, i2cId, speed, scanMode, onlyY)
-    local id = camera.init(cspiId, speed, 1, 1, 2, 1, 0x00010101, onlyY, scanMode, 640, 480)
-    for i = 1, #reg_table do
-        i2c.send(i2cId, 0x21, reg_table[i], 1)
-    end
-    camera.start(id)
-    return id
-end

+ 0 - 361
script/turnkey/hz201p/gc032a.lua

@@ -1,361 +0,0 @@
-local reg_table = {
-    {0xf3, 0x83}, 
-    {0xf5, 0x08},
-    {0xf7, 0x01},
-    {0xf8, 0x01}, 
-    {0xf9, 0x4e},
-    {0xfa, 0x00},
-    {0xfc, 0x02},
-    {0xfe, 0x02},
-    {0x81, 0x03},
- 
-    {0xfe, 0x00},
-    {0x77, 0x64},
-    {0x78, 0x40},
-    {0x79, 0x60},
- 
-    {0xfe, 0x00},
-    {0x03, 0x01},
-    {0x04, 0xcb},
-    {0x05, 0x01},
-    {0x06, 0xb2},
-    {0x07, 0x00},
-    {0x08, 0x10},
- 
-    {0x0a, 0x00},
-    {0x0c, 0x00},
-    {0x0d, 0x01},
-    {0x0e, 0xe8},
-    {0x0f, 0x02},
-    {0x10, 0x88},
-
-    {0x17, 0x54},
-    {0x19, 0x08},
-    {0x1a, 0x0a},
-    {0x1f, 0x40},
-    {0x20, 0x30},
-    {0x2e, 0x80},
-    {0x2f, 0x2b},
-    {0x30, 0x1a},
-    {0xfe, 0x02},
-    {0x03, 0x02},
-    {0x05, 0xd7},
-    {0x06, 0x60},
-    {0x08, 0x80},
-    {0x12, 0x89},
- 
- 
-    {0xfe, 0x03},
-    {0x52, 0xba}, 
-    {0x53, 0x24},
-    {0x54, 0x20},
-    {0x55, 0x00},
-    {0x59, 0x1f}, 
-    {0x5a, 0x00}, 
-    {0x5b, 0x80},
-    {0x5c, 0x02},
-    {0x5d, 0xe0},
-    {0x5e, 0x01},
-    {0x51, 0x03},
-    {0x64, 0x04},
-    {0xfe, 0x00},
- 
- 
-    {0xfe, 0x00},
-    {0x18, 0x02},
-    {0xfe, 0x02},
-    {0x40, 0x22},
-    {0x45, 0x00},
-    {0x46, 0x00},
-    {0x49, 0x20},
-    {0x4b, 0x3c},
-    {0x50, 0x20},
-    {0x42, 0x10},
- 
- 
-    {0xfe, 0x01},
-    {0x0a, 0xc5},
-    {0x45, 0x00},
-    {0xfe, 0x00},
-    {0x40, 0xff},
-    {0x41, 0x25},
-    {0x42, 0xef},
-    {0x43, 0x10},
-    {0x44, 0x83}, 
-    {0x46, 0x22},
-    {0x49, 0x03},
-    {0x52, 0x02},
-    {0x54, 0x00},
-    {0xfe, 0x02},
-    {0x22, 0xf6},
- 
- 
-    {0xfe, 0x01},
-    {0xc1, 0x38},
-    {0xc2, 0x4c},
-    {0xc3, 0x00},
-    {0xc4, 0x2c},
-    {0xc5, 0x24},
-    {0xc6, 0x18},
-    {0xc7, 0x28},
-    {0xc8, 0x11},
-    {0xc9, 0x15},
-    {0xca, 0x20},
-    {0xdc, 0x7a},
-    {0xdd, 0xa0},
-    {0xde, 0x80},
-    {0xdf, 0x88},
- 
- 
-    {0xfe, 0x01},
-    {0x50, 0xc1},
-    {0x56, 0x34},
-    {0x58, 0x04},
-    {0x65, 0x06},
-    {0x66, 0x0f},
-    {0x67, 0x04},
-    {0x69, 0x20},
-    {0x6a, 0x40},
-    {0x6b, 0x81},
-    {0x6d, 0x12},
-    {0x6e, 0xc0},
-    {0x7b, 0x2a},
-    {0x7c, 0x0c},
-    {0xfe, 0x01},
-    {0x90, 0xe3},
-    {0x91, 0xc2},
-    {0x92, 0xff},
-    {0x93, 0xe3},
-    {0x95, 0x1c},
-    {0x96, 0xff},
-    {0x97, 0x44},
-    {0x98, 0x1c},
-    {0x9a, 0x44},
-    {0x9b, 0x1c},
-    {0x9c, 0x64},
-    {0x9d, 0x44},
-    {0x9f, 0x71},
-    {0xa0, 0x64},
-    {0xa1, 0x00},
-    {0xa2, 0x00},
-    {0x86, 0x00},
-    {0x87, 0x00},
-    {0x88, 0x00},
-    {0x89, 0x00},
-    {0xa4, 0xc2},
-    {0xa5, 0x9b},
-    {0xa6, 0xc8},
-    {0xa7, 0x92},
-    {0xa9, 0xc9},
-    {0xaa, 0x96},
-    {0xab, 0xa9},
-    {0xac, 0x99},
-    {0xae, 0xce},
-    {0xaf, 0xa9},
-    {0xb0, 0xcf},
-    {0xb1, 0x9d},
-    {0xb3, 0xcf},
-    {0xb4, 0xac},
-    {0xb5, 0x00},
-    {0xb6, 0x00},
-    {0x8b, 0x00},
-    {0x8c, 0x00},
-    {0x8d, 0x00},
-    {0x8e, 0x00},
-    {0x94, 0x55},
-    {0x99, 0xa6},
-    {0x9e, 0xaa},
-    {0xa3, 0x0a},
-    {0x8a, 0x00},
-    {0xa8, 0x55},
-    {0xad, 0x55},
-    {0xb2, 0x55},
-    {0xb7, 0x05},
-    {0x8f, 0x00},
-    {0xb8, 0xc7},
-    {0xb9, 0xa0},
- 
-    {0xfe, 0x01},
-    {0xd0, 0x40},
-    {0xd1, 0x00},
-    {0xd2, 0x00},
-    {0xd3, 0xfa},
-    {0xd4, 0x4a},
-    {0xd5, 0x02},
- 
-    {0xd6, 0x44},
-    {0xd7, 0xfa},
-    {0xd8, 0x04},
-    {0xd9, 0x08},
-    {0xda, 0x5c},
-    {0xdb, 0x02},
-    {0xfe, 0x00},
- 
- 
-    {0xfe, 0x00},
-    {0xba, 0x00},
-    {0xbb, 0x04},
-    {0xbc, 0x0a},
-    {0xbd, 0x0e},
-    {0xbe, 0x22},
-    {0xbf, 0x30},
-    {0xc0, 0x3d},
-    {0xc1, 0x4a},
-    {0xc2, 0x5d},
-    {0xc3, 0x6b},
-    {0xc4, 0x7a},
-    {0xc5, 0x85},
-    {0xc6, 0x90},
-    {0xc7, 0xa5},
-    {0xc8, 0xb5},
-    {0xc9, 0xc2},
-    {0xca, 0xcc},
-    {0xcb, 0xd5},
-    {0xcc, 0xde},
-    {0xcd, 0xea},
-    {0xce, 0xf5},
-    {0xcf, 0xff},
- 
- 
-    {0xfe, 0x00},
-    {0x5a, 0x08},
-    {0x5b, 0x0f},
-    {0x5c, 0x15},
-    {0x5d, 0x1c},
-    {0x5e, 0x28},
-    {0x5f, 0x36},
-    {0x60, 0x45},
-    {0x61, 0x51},
-    {0x62, 0x6a},
-    {0x63, 0x7d},
-    {0x64, 0x8d},
-    {0x65, 0x98},
-    {0x66, 0xa2},
-    {0x67, 0xb5},
-    {0x68, 0xc3},
-    {0x69, 0xcd},
-    {0x6a, 0xd4},
-    {0x6b, 0xdc},
-    {0x6c, 0xe3},
-    {0x6d, 0xf0},
-    {0x6e, 0xf9},
-    {0x6f, 0xff},
- 
- 
-    {0xfe, 0x00},
-    {0x70, 0x50},
- 
- 
-    {0xfe, 0x00},
-    {0x4f, 0x01},
-    {0xfe, 0x01},
-    {0x0c, 0x01},
-    {0x0d, 0x00}, 
-    {0x12, 0xa0},
-    {0x13, 0x38},
-    {0x1f, 0x40},
-    {0x20, 0x40},
-    {0x23, 0x0a},
-    {0x26, 0x9a},
-    {0x3e, 0x20},
-    {0x3f, 0x2d},
-    {0x40, 0x40},
-    {0x41, 0x5b},
-    {0x42, 0x82},
-    {0x43, 0xb7},
-    {0x04, 0x0a},
-    {0x02, 0x79},
-    {0x03, 0xc0},
- 
-   
-    {0xfe, 0x01},
-    {0xcc, 0x08},
-    {0xcd, 0x08},
-    {0xce, 0xa4},
-    {0xcf, 0xec},
- 
-  
-    {0xfe, 0x00},
-    {0x81, 0xb8},
-    {0x82, 0x04},
-    {0x83, 0x10},
-    {0x84, 0x01},
-    {0x86, 0x50},
-    {0x87, 0x18},
-    {0x88, 0x10},
-    {0x89, 0x70},
-    {0x8a, 0x20},
-    {0x8b, 0x10},
-    {0x8c, 0x08},
-    {0x8d, 0x0a},
- 
- 
-    {0xfe, 0x00},
-    {0x8f, 0xaa},
-    {0x90, 0x1c},
-    {0x91, 0x52},
-    {0x92, 0x03},
-    {0x93, 0x03},
-    {0x94, 0x08},
-    {0x95, 0x6a},
-    {0x97, 0x00},
-    {0x98, 0x00},
- 
-  
-    {0xfe, 0x00},
-    {0x9a, 0x30},
-    {0x9b, 0x50},
-    {0xa1, 0x30},
-    {0xa2, 0x66},
-    {0xa4, 0x28},
-    {0xa5, 0x30},
-    {0xaa, 0x28},
-    {0xac, 0x32},
- 
-   
-    {0xfe, 0x00},
-    {0xd1, 0x3f},
-    {0xd2, 0x3f},
-    {0xd3, 0x38},
-    {0xd6, 0xf4},
-    {0xd7, 0x1d},
-    {0xdd, 0x72},
-    {0xde, 0x84},
- 
-    {0xfe, 0x00},
-    {0x05, 0x01},
-    {0x06, 0xad},
-    {0x07, 0x00},
-    {0x08, 0x10},
- 
-    {0xfe, 0x01},
-    {0x25, 0x00},
-    {0x26, 0x4d},
- 
-    {0x27, 0x01},
-    {0x28, 0xce}, 
-    {0x29, 0x01},
-    {0x2a, 0xce}, 
-    {0x2b, 0x01},
-    {0x2c, 0xce}, 
-    {0x2d, 0x01},
-    {0x2e, 0xce}, 
-    {0x2f, 0x01},
-    {0x30, 0xce}, 
-    {0x31, 0x01},
-    {0x32, 0xce}, 
-    {0x33, 0x01},
-    {0x34, 0xce}, 
-    {0x3c, 0x10}, 
-    {0xfe, 0x00},
-    {0x44, 0x03},
- }
- 
- function gc032aInit(cspiId,i2cId,speed,scanMode,onlyY)
-     local id = camera.init(cspiId,speed,1,1,2,1,0x00010101,onlyY,scanMode,640,480)
-     for i=1,#reg_table do
-         i2c.send(i2cId,0x21,reg_table[i],1)
-     end
-     camera.start(id)
-     return id
- end

+ 0 - 134
script/turnkey/hz201p/gnss.lua

@@ -1,134 +0,0 @@
--- gnss的供电
-local gnssEnvPower = gpio.setup(26, 1)
-local gpsPower = gpio.setup(2, 1)
--- gnss的复位
-local gpsRst = gpio.setup(27, 1)
-local isOn = true
-
-local function power(on)
-    if on ~= isOn then
-        if on then--开机后要清空一下
-            libgnss.clear()
-        end
-        gnssEnvPower(on and 1 or 0)
-        gpsPower(on and 1 or 0)
-        if on then--开机后要清空一下
-            gpsRst(0)
-            sys.timerStart(gpsRst, 500, 1)
-            libgnss.clear()
-        end
-        isOn = on
-    end
-end
-
-
-sys.taskInit(function()
-    log.info("GPS", "start")
-
-    local uartId = 2
-    libgnss.clear() -- 清空数据,兼初始化
-    uart.setup(uartId, 115200)
-
-    sys.wait(200) -- GPNSS芯片启动需要时间
-    -- 调试日志,可选
-    --libgnss.debug(true)
-    libgnss.bind(2)
-end)
-
--- 订阅GNSS状态编码
-sys.subscribe("GNSS_STATE", function(event, ticks)
-    -- event取值有 
-    -- FIXED 定位成功
-    -- LOSE  定位丢失
-    -- ticks是事件发生的时间,一般可以忽略
-    log.info("gnss", "state", event, ticks)
-    if event == "FIXED" then
-        local locStr = libgnss.locStr()
-        log.info("gnss", "locStr", locStr)
-    elseif event == "LOSE" then
-        log.info("gnss", "no fix")
-    end
-end)
-
---基站定位数据
-local latLbs, lngLbs, typeLbs
-
-sys.timerLoopStart(function ()
-    if attributes.get("isGPSOn") then
-        if attributes.get("sleepMode") then--休眠模式,关闭GPS
-            attributes.set("isGPSOn", false)
-        else
-            local isFixed = libgnss.isFix()
-            if isFixed then--优先使用gps数据
-                local loc = libgnss.getRmc(2)
-                attributes.set("isFixed", "已定位")
-                attributes.set("lat", tostring(loc.lat))
-                attributes.set("lng", tostring(loc.lng))
-                attributes.set("location", {
-                    lat = loc.lat,
-                    lng = loc.lng,
-                })
-            elseif latLbs and lngLbs then
-                attributes.set("isFixed", typeLbs)
-                attributes.set("lat", tostring(latLbs))
-                attributes.set("lng", tostring(lngLbs))
-                attributes.set("location", {
-                    lat = tonumber(latLbs),
-                    lng = tonumber(lngLbs),
-                })
-            else
-                attributes.set("isFixed", "获取中")
-                attributes.set("lat", "无数据")
-                attributes.set("lng", "无数据")
-            end
-            power(true)
-        end
-    else
-        power(false)
-    end
-end,3000)
-
-
-local lbsLoc = require("lbsLoc")
-
-local function getLocCb(result, lat, lng, addr, time, locType)
-    log.info("testLbsLoc.getLocCb", result, lat, lng)
-    -- 基站定位获取经纬度成功
-    if result == 0 and attributes.get("isGPSOn") and not attributes.get("sleepMode") then
-        latLbs, lngLbs = lat, lng
-        typeLbs = locType == 0 and "基站定位" or "WIFI定位"
-    end
-end
-
-sys.taskInit(function()
-    sys.waitUntil("IP_READY", 30000)
-    while mobile do -- 没有mobile库就没有基站定位
-        if attributes.get("isGPSOn") and not attributes.get("sleepMode") then--开启定位功能后再定位
-            --基站定位信息
-            mobile.reqCellInfo(15)
-            sys.waitUntil("CELL_INFO_UPDATE", 3000)
-            --wifi定位信息
-            wlan.scan()
-            local reqWifi
-            local r = sys.waitUntil("WLAN_SCAN_DONE", 60000)
-            if r then
-                local results = wlan.scanResult()
-                log.info("wifi scan", "count", #results)
-                if #results > 0 then
-                    local reqWifi = {}
-                    for k,v in pairs(results) do
-                        log.info("scan", v["ssid"], v["rssi"], v["bssid"]:toHex())
-                        local bssid = v["bssid"]:toHex()
-                        bssid = string.format ("%s:%s:%s:%s:%s:%s", bssid:sub(1,2), bssid:sub(3,4), bssid:sub(5,6), bssid:sub(7,8), bssid:sub(9,10), bssid:sub(11,12))
-                        reqWifi[bssid]=v["rssi"]
-                    end
-                end
-            end
-            if not libgnss.isFix() then--没定位成功再去获取
-                lbsLoc.request(getLocCb,nil,nil,nil,nil,nil,nil,reqWifi)
-            end
-        end
-        sys.wait(60000)
-    end
-end)
-

+ 0 - 277
script/turnkey/hz201p/lbsLoc.lua

@@ -1,277 +0,0 @@
---[[
-@module lbsLoc
-@summary lbsLoc 发送基站定位请求
-@version 1.0
-@date    2022.12.16
-@author  luatos
-@usage
---注意:因使用了sys.wait()所有api需要在协程中使用
---用法实例
---注意:此处的PRODUCT_KEY仅供演示使用,不能用于生产环境
---量产项目中一定要使用自己在iot.openluat.com中创建的项目productKey,项目详情里可以查看
---基站定位的坐标系是 WSG84
-PRODUCT_KEY = "v32xEAKsGTIEQxtqgwCldp5aPlcnPs3K"
-local lbsLoc = require("lbsLoc")
--- 功能:获取基站对应的经纬度后的回调函数
--- 参数:-- result:number类型,0表示成功,1表示网络环境尚未就绪,2表示连接服务器失败,3表示发送数据失败,4表示接收服务器应答超时,5表示服务器返回查询失败;为0时,后面的5个参数才有意义
-		-- lat:string类型,纬度,整数部分3位,小数部分7位,例如031.2425864
-		-- lng:string类型,经度,整数部分3位,小数部分7位,例如121.4736522
-        -- addr:目前无意义
-        -- time:string类型或者nil,服务器返回的时间,6个字节,年月日时分秒,需要转为十六进制读取
-            -- 第一个字节:年减去2000,例如2017年,则为0x11
-            -- 第二个字节:月,例如7月则为0x07,12月则为0x0C
-            -- 第三个字节:日,例如11日则为0x0B
-            -- 第四个字节:时,例如18时则为0x12
-            -- 第五个字节:分,例如59分则为0x3B
-            -- 第六个字节:秒,例如48秒则为0x30
-        -- locType:numble类型或者nil,定位类型,0表示基站定位成功,255表示WIFI定位成功
-function getLocCb(result, lat, lng, addr, time, locType)
-    log.info("testLbsLoc.getLocCb", result, lat, lng)
-    -- 获取经纬度成功, 坐标系WGS84
-    if result == 0 then
-        log.info("服务器返回的时间", time:toHex())
-        log.info("定位类型,基站定位成功返回0", locType)
-    end
-end
-
-sys.taskInit(function()
-    sys.waitUntil("IP_READY", 30000)
-    while 1 do
-        mobile.reqCellInfo(15)
-        sys.waitUntil("CELL_INFO_UPDATE", 3000)
-        lbsLoc.request(getLocCb)
-        sys.wait(60000)
-    end
-end)
-]]
-
-local sys = require "sys"
-local sysplus = require("sysplus")
-local libnet = require("libnet")
-
-local lbsLoc = {}
-local d1Name = "lbsLoc"
-
---- ASCII字符串 转化为 BCD编码格式字符串(仅支持数字)
--- @string inStr 待转换字符串
--- @number destLen 转换后的字符串期望长度,如果实际不足,则填充F
--- @return string data,转换后的字符串
--- @usage
-local function numToBcdNum(inStr,destLen)
-    local l,t,num = string.len(inStr or ""),{}
-    destLen = destLen or (inStr:len()+1)/2
-    for i=1,l,2 do
-        num = tonumber(inStr:sub(i,i+1),16)
-        if i==l then
-            num = 0xf0+num
-        else
-            num = (num%0x10)*0x10 + (num-(num%0x10))/0x10
-        end
-        table.insert(t,num)
-    end
-
-    local s = string.char(unpack(t))
-
-    l = string.len(s)
-    if l < destLen then
-        s = s .. string.rep("\255",destLen-l)
-    elseif l > destLen then
-        s = string.sub(s,1,destLen)
-    end
-
-    return s
-end
-
---- BCD编码格式字符串 转化为 号码ASCII字符串(仅支持数字)
--- @string num 待转换字符串
--- @return string data,转换后的字符串
--- @usage
-local function bcdNumToNum(num)
-	local byte,v1,v2
-	local t = {}
-
-	for i=1,num:len() do
-		byte = num:byte(i)
-		v1,v2 = bit.band(byte,0x0f),bit.band(bit.rshift(byte,4),0x0f)
-
-		if v1 == 0x0f then break end
-		table.insert(t,v1)
-
-		if v2 == 0x0f then break end
-		table.insert(t,v2)
-	end
-
-	return table.concat(t)
-end
-
-
-local function netCB(msg)
-	--log.info("未处理消息", msg[1], msg[2], msg[3], msg[4])
-end
-
-
-local function enCellInfo(s)
-    local ret,t,mcc,mnc,lac,ci,rssi,k,v,m,n,cntrssi = "",{}
-        for k,v in pairs(s) do
-            mcc,mnc,lac,ci,rssi = v.mcc,v.mnc,v.tac,v.cid,((v.rsrq + 144) >31) and 31 or (v.rsrq + 144)
-            local handle = nil
-            for k,v in pairs(t) do
-                if v.lac == lac and v.mcc == mcc and v.mnc == mnc then
-                    if #v.rssici < 8 then
-                        table.insert(v.rssici,{rssi=rssi,ci=ci})
-                    end
-                    handle = true
-                break
-                end
-            end
-            if not handle then
-                table.insert(t,{mcc=mcc,mnc=mnc,lac=lac,rssici={{rssi=rssi,ci=ci}}})
-            end
-            log.debug("rssi,mcc,mnc,lac,ci", rssi,mcc,mnc,lac,ci)
-        end
-        for k,v in pairs(t) do
-            ret = ret .. pack.pack(">HHb",v.lac,v.mcc,v.mnc)
-            for m,n in pairs(v.rssici) do
-                cntrssi = bit.bor(bit.lshift(((m == 1) and (#v.rssici-1) or 0),5),n.rssi)
-                ret = ret .. pack.pack(">bi",cntrssi,n.ci)
-            end
-        end
-        return string.char(#t)..ret
-end
-
-local function enWifiInfo(tWifi)
-    local ret,cnt = "", 0
-    if tWifi then
-        for k,v in pairs(tWifi) do
-            -- log.info("lbsLoc.enWifiInfo",k,v)
-            ret = ret..pack.pack("Ab",(k:gsub(":","")):fromHex(),(v<0) and (v+255) or v)
-            cnt = cnt+1
-        end
-    end
-    return string.char(cnt)..ret
-end
-
-local function enMuid()   --获取模块MUID
-    local muid = mobile.muid()
-    return string.char(muid:len())..muid
-end
-
-local function trans(str)
-    local s = str
-    if str:len()<10 then
-        s = str..string.rep("0",10-str:len())
-    end
-
-    return s:sub(1,3).."."..s:sub(4,10)
-end
-
-
-local function taskClient(cbFnc, reqAddr, timeout, productKey, host, port,reqTime, reqWifi)
-    if mobile.status() == 0 then
-        if not sys.waitUntil("IP_READY", timeout) then return cbFnc(1) end
-        sys.wait(500)
-    end
-    if productKey == nil then
-        productKey = ""
-    end
-    local retryCnt  = 0
-    local reqStr = pack.pack("bAbAAAAA", productKey:len(), productKey,
-                             (reqAddr and 2 or 0) + (reqTime and 4 or 0) + 8 +(reqWifi and 16 or 0) + 32, "",
-                             numToBcdNum(mobile.imei()), enMuid(),
-                             enCellInfo(mobile.getCellInfo()),
-                             enWifiInfo(reqWifi))
-    log.debug("reqStr", reqStr:toHex())
-    local rx_buff = zbuff.create(17)
-    -- sys.wait(5000)
-    while true do
-        local result,succ,param
-        local netc = socket.create(nil, d1Name) -- 创建socket对象
-        if not netc then cbFnc(6) return end -- 创建socket失败
-        socket.debug(netc, false)
-        socket.config(netc, nil, true, nil)
-        --result = libnet.waitLink(d1Name, 0, netc)
-        result = libnet.connect(d1Name, 5000, netc, host, port)
-        if result then
-            while true do
-                -- log.info(" lbsloc socket_service connect true")
-                result = libnet.tx(d1Name, 0, netc, reqStr) ---发送数据
-                if result then
-                    result, param = libnet.wait(d1Name, 15000 + retryCnt * 5, netc)
-                    if not result then
-                        socket.close(netc)
-                        socket.release(netc)
-                        retryCnt = retryCnt+1
-                        if retryCnt>=3 then return cbFnc(4) end
-                        break
-                    end
-                    succ, param = socket.rx(netc, rx_buff) -- 接收数据
-                    -- log.info("是否接收和数据长度", succ, param)
-                    if param ~= 0 then -- 如果接收成功
-                        socket.close(netc) -- 关闭连接
-                        socket.release(netc)
-                        local read_buff = rx_buff:toStr(0, param)
-                        rx_buff:clear()
-                        log.debug("lbsLoc receive", read_buff:toHex())
-                        if read_buff:len() >= 11 and(read_buff:byte(1) == 0 or read_buff:byte(1) == 0xFF) then
-                            local locType = read_buff:byte(1)
-                            cbFnc(0, trans(bcdNumToNum(read_buff:sub(2, 6))),
-                                trans(bcdNumToNum(read_buff:sub(7, 11))), reqAddr and
-                                read_buff:sub(13, 12 + read_buff:byte(12)) or nil,
-                                reqTime and read_buff:sub(reqAddr and (13 + read_buff:byte(12)) or 12, -1) or "",
-                                locType)
-                        else
-                            log.warn("lbsLoc.query", "根据基站查询经纬度失败")
-                            if read_buff:byte(1) == 2 then
-                                log.warn("lbsLoc.query","main.lua中的PRODUCT_KEY和此设备在iot.openluat.com中所属项目的ProductKey必须一致,请去检查")
-                            else
-                                log.warn("lbsLoc.query","基站数据库查询不到所有小区的位置信息")
-                                -- log.warn("lbsLoc.query","在trace中向上搜索encellinfo,然后在电脑浏览器中打开http://bs.openluat.com/,手动查找encellinfo后的所有小区位置")
-                                -- log.warn("lbsLoc.query","如果手动可以查到位置,则服务器存在BUG,直接向技术人员反映问题")
-                                -- log.warn("lbsLoc.query","如果手动无法查到位置,则基站数据库还没有收录当前设备的小区位置信息,向技术人员反馈,我们会尽快收录")
-                            end
-                            cbFnc(5)
-                        end
-                        return
-                    else
-                        socket.close(netc)
-                        socket.release(netc)
-                        retryCnt = retryCnt+1
-                        if retryCnt>=3 then return cbFnc(4) end
-                        break
-                    end
-                else
-                    socket.close(netc)
-                    socket.release(netc)
-                    retryCnt = retryCnt+1
-                    if retryCnt>=3 then return cbFnc(3) end
-                    break
-                end
-            end
-        else
-            socket.close(netc)
-            socket.release(netc)
-            retryCnt = retryCnt + 1
-            if retryCnt >= 3 then return cbFnc(2) end
-        end
-    end
-end
-
-
---[[
-发送基站定位请求
-@api lbsLoc.request(cbFnc,reqAddr,timeout,productKey,host,port,reqTime,reqWifi)
-@function cbFnc 用户回调函数,回调函数的调用形式为:cbFnc(result,lat,lng,addr,time,locType)
-@bool reqAddr 是否请求服务器返回具体的位置字符串信息,已经不支持,填false或者nil
-@number timeout 请求超时时间,单位毫秒,默认20000毫秒
-@string productKey IOT网站上的产品KEY,如果在main.lua中定义了PRODUCT_KEY变量,则此参数可以传nil
-@string host 服务器域名, 默认 "bs.openluat.com" ,可选备用服务器(不保证可用) "bs.air32.cn"
-@string port 服务器端口,默认"12411",一般不需要设置
-@return nil
-@usage
--- 提醒: 返回的坐标值, 是WGS84坐标系
-]]
-function lbsLoc.request(cbFnc,reqAddr,timeout,productKey,host,port,reqTime,reqWifi)
-    sysplus.taskInitEx(taskClient, d1Name, netCB, cbFnc, reqAddr,timeout or 20000,productKey or _G.PRODUCT_KEY,host or "bs.openluat.com",port or "12411", reqTime == nil and true or reqTime,reqWifi)
-end
-
-return lbsLoc

+ 0 - 139
script/turnkey/hz201p/libfota.lua

@@ -1,139 +0,0 @@
---[[
-@module libfota
-@summary libfota fota升级
-@version 1.0
-@date    2023.02.01
-@author  Dozingfiretruck
-@demo    fota
-@usage
---注意:因使用了sys.wait()所有api需要在协程中使用
---用法实例
-local libfota = require("libfota")
-
--- 功能:获取fota的回调函数
--- 参数:
--- result:number类型
---   0表示成功
---   1表示连接失败
---   2表示url错误
---   3表示服务器断开
---   4表示接收报文错误
---   5表示使用iot平台VERSION需要使用 xxx.yyy.zzz形式
-function libfota_cb(result)
-    log.info("fota", "result", result)
-    -- fota成功
-    if result == 0 then
-        rtos.reboot()   --如果还有其他事情要做,就不要立刻reboot
-    end
-end
-
---注意!!!:使用合宙iot平台,必须用luatools量产生成的.bin文件!!! 自建服务器可使用.ota文件!!!
---注意!!!:使用合宙iot平台,必须用luatools量产生成的.bin文件!!! 自建服务器可使用.ota文件!!!
---注意!!!:使用合宙iot平台,必须用luatools量产生成的.bin文件!!! 自建服务器可使用.ota文件!!!
-
---下方示例为合宙iot平台,地址:http://iot.openluat.com 
-libfota.request(libfota_cb)
-
---如使用自建服务器,自行更换url
--- 对自定义服务器的要求是:
--- 若需要升级, 响应http 200, body为升级文件的内容
--- 若不需要升级, 响应300或以上的代码,务必注意
-libfota.request(libfota_cb,"http://xxxxxx.com/xxx/upgrade?version=" .. _G.VERSION)
-
--- 若需要定时升级
--- 合宙iot平台
-sys.timerLoopStart(libfota.request, 4*3600*1000, libfota_cb)
--- 自建平台
-sys.timerLoopStart(libfota.request, 4*3600*1000, libfota_cb, "http://xxxxxx.com/xxx/upgrade?version=" .. _G.VERSION)
-]]
-
-local sys = require "sys"
-local sysplus = require "sysplus"
-
-local libfota = {}
-
-
-local function fota_task(cbFnc,storge_location, len, param1,ota_url,ota_port,libfota_timeout,server_cert, client_cert, client_key, client_password, show_otaurl)
-    if cbFnc == nil then
-        cbFnc = function() end
-    end
-    -- 若ota_url没有传,那就是用合宙iot平台
-    if ota_url == nil then
-        if _G.PRODUCT_KEY == nil then
-            -- 必须在main.lua定义 PRODUCT_KEY = "xxx"
-            -- iot平台新建项目后, 项目详情中可以查到
-            log.error("fota", "iot.openluat.com need PRODUCT_KEY!!!")
-            cbFnc(5)
-            return
-        else
-            local x,y,z = string.match(_G.VERSION,"(%d+).(%d+).(%d+)")
-            if x and y and z then
-                version = x.."."..z
-                local imei = ""
-                if mobile then
-                    imei = mobile.imei()
-                elseif wlan and wlan.getMac then
-                    imei = wlan.getMac()
-                else
-                    imei = mcu.unique_id():toHex()
-                end
-                ota_url = "http://iot.openluat.com/api/site/firmware_upgrade?project_key=" .. _G.PRODUCT_KEY .. "&imei=".. imei .. "&device_key=&firmware_name=" .. _G.PROJECT.. "_LuatOS-SoC_" .. rtos.bsp() .. "&version=" .. rtos.version():sub(2) .. "." .. version
-            else
-                log.error("fota", "_G.VERSION must be xxx.yyy.zzz!!!")
-                cbFnc(5)
-                return
-            end
-        end
-    end
-    local ret
-    local opts = {timeout = libfota_timeout}
-    if fota then
-        opts.fota = true
-    else
-        os.remove("/update.bin")
-        opts.dst = "/update.bin"
-    end
-    if show_otaurl == nil or show_otaurl == true then
-        log.info("fota.url", ota_url)
-    end
-    local code, headers, body = http.request("GET", ota_url, nil, nil, opts, server_cert, client_cert, client_key, client_password).wait()
-    log.info("http fota", code, headers, body)
-    if code == 200 or code == 206 then
-        if body == 0 then
-            ret = 4
-        else
-            ret = 0
-        end
-    elseif code == -4 then
-        ret = 1
-    elseif code == -5 then
-        ret = 3
-    else
-        ret = 4
-    end
-    cbFnc(ret)
-end
-
---[[
-fota升级
-@api libfota.request(cbFnc,ota_url,storge_location, len, param1,ota_port,libfota_timeout,server_cert, client_cert, client_key, client_password)
-@function cbFnc 用户回调函数,回调函数的调用形式为:cbFnc(result) , 必须传
-@string ota_url 升级URL, 若不填则自动使用合宙iot平台
-@number/string storge_location 可选,fota数据存储的起始位置<br>如果是int,则是由芯片平台具体判断<br>如果是string,则存储在文件系统中<br>如果为nil,则由底层决定存储位置
-@number len 可选,数据存储的最大空间
-@userdata param1,可选,如果数据存储在spiflash时,为spi_device
-@number ota_port 可选,请求端口,默认80
-@number libfota_timeout 可选,请求超时时间,单位毫秒,默认30000毫秒
-@string server_cert 可选,服务器ca证书数据
-@string client_cert 可选,客户端ca证书数据
-@string client_key 可选,客户端私钥加密数据
-@string client_password 可选,客户端私钥口令数据
-@boolean show_otaurl 可选,是否从日志中输出打印OTA升级包的URL路径,默认会打印
-@return nil 无返回值
-]]
-function libfota.request(cbFnc,ota_url,storge_location, len, param1,ota_port,libfota_timeout,server_cert, client_cert, client_key, client_password, show_otaurl)
-    sys.taskInit(fota_task, cbFnc,storge_location, len, param1,ota_url, ota_port,libfota_timeout or 30000,server_cert, client_cert, client_key, client_password, show_otaurl)
-end
-
-return libfota
-

+ 0 - 168
script/turnkey/hz201p/libnet.lua

@@ -1,168 +0,0 @@
---[[
-@module libnet
-@summary libnet 在socket库基础上的同步阻塞api,socket库本身是异步非阻塞api
-@version 1.0
-@date    2023.03.16
-@author  lisiqi
-]]
-
-local libnet = {}
-
---[[
-阻塞等待网卡的网络连接上,只能用于sysplus.taskInitEx创建的任务函数中
-@api libnet.waitLink(taskName,timeout,...)
-@string 任务标志
-@int 超时时间,如果==0或者空,则没有超时一致等待
-@... 其他参数和socket.linkup一致
-@return boolean 失败或者超时返回false 成功返回true
-]]
-function libnet.waitLink(taskName, timeout, ...)
-	local succ, result = socket.linkup(...)
-	if not succ then
-		return false
-	end
-	if not result then
-		result = sys_wait(taskName, socket.LINK, timeout)
-	else
-		return true
-	end
-	if type(result) == 'table' and result[2] == 0 then
-		return true
-	else
-		return false
-	end
-end
-
-
---[[
-阻塞等待IP或者域名连接上,如果加密连接还要等握手完成,只能用于sysplus.taskInitEx创建的任务函数中
-@api libnet.connect(taskName,timeout,...)
-@string 任务标志
-@int 超时时间,如果==0或者空,则没有超时一致等待
-@... 其他参数和socket.connect一致
-@return boolean 失败或者超时返回false 成功返回true
-]]
-function libnet.connect(taskName,timeout, ... )
-	local succ, result = socket.connect(...)
-	if not succ then
-		return false
-	end
-	if not result then
-		result = sys_wait(taskName, socket.ON_LINE, timeout)
-	else
-		return true
-	end
-	if type(result) == 'table' and result[2] == 0 then
-		return true
-	else
-		return false
-	end
-end
-
---[[
-阻塞等待客户端连接上,只能用于sysplus.taskInitEx创建的任务函数中
-@api libnet.listen(taskName,timeout,...)
-@string 任务标志
-@int 超时时间,如果==0或者空,则没有超时一致等待
-@... 其他参数和socket.listen一致
-@return boolean 失败或者超时返回false 成功返回true
-]]
-function libnet.listen(taskName,timeout, ... )
-	local succ, result = socket.listen(...)
-	if not succ then
-		return false
-	end
-	if not result then
-		result = sys_wait(taskName, socket.ON_LINE, timeout)
-	else
-		return true
-	end
-	if type(result) == 'table' and result[2] == 0 then
-		return true
-	else
-		return false
-	end
-end
-
---[[
-阻塞等待数据发送完成,只能用于sysplus.taskInitEx创建的任务函数中
-@api libnet.tx(taskName,timeout,...)
-@string 任务标志
-@int 超时时间,如果==0或者空,则没有超时一直等待
-@... 其他参数和socket.tx一致
-@return boolean 失败或者超时返回false,缓冲区满了或者成功返回true
-@return boolean 缓存区是否满了
-]]
-function libnet.tx(taskName,timeout, ...)
-	local succ, is_full, result = socket.tx(...)
-	if not succ then
-		return false, is_full
-	end
-	if is_full then
-		return true, true
-	end
-	if not result then
-		result = sys_wait(taskName, socket.TX_OK, timeout)
-	else
-		return true, is_full
-	end
-	if type(result) == 'table' and result[2] == 0 then
-		return true, false
-	else
-		return false, is_full
-	end
-end
-
---[[
-阻塞等待新的网络事件,只能用于sysplus.taskInitEx创建的任务函数中,可以通过sysplus.sendMsg(taskName,socket.EVENT,0)或者sys_send(taskName,socket.EVENT,0)强制退出
-@api libnet.wait(taskName,timeout, netc)
-@string 任务标志
-@int 超时时间,如果==0或者空,则没有超时一致等待
-@userdata socket.create返回的netc
-@return boolean 网络异常返回false,其他返回true
-@return boolean 超时返回false,有新的网络事件到返回true
-]]
-function libnet.wait(taskName,timeout, netc)
-	local succ, result = socket.wait(netc)
-	if not succ then
-		return false,false
-	end
-	if not result then
-		result = sys_wait(taskName, socket.EVENT, timeout)
-	else
-		return true,true
-	end
-	if type(result) == 'table' then
-		if result[2] == 0 then
-			return true, true
-		else
-			return false, false
-		end
-	else
-		return true, false
-	end
-end
-
---[[
-阻塞等待网络断开连接,只能用于sysplus.taskInitEx创建的任务函数中
-@api libnet.close(taskName,timeout, netc)
-@string 任务标志
-@int 超时时间,如果==0或者空,则没有超时一致等待
-@userdata socket.create返回的netc
-]]
-function libnet.close(taskName,timeout, netc)
-	local succ, result = socket.discon(netc)
-	if not succ then
-		socket.close(netc)
-		return
-	end
-	if not result then
-		result = sys_wait(taskName, socket.CLOSED, timeout)
-	else
-		socket.close(netc)
-		return
-	end
-	socket.close(netc)
-end
-
-return libnet

+ 0 - 145
script/turnkey/hz201p/main.lua

@@ -1,145 +0,0 @@
--- LuaTools需要PROJECT和VERSION这两个信息
-PROJECT = "HZ201P"
-VERSION = "1.0.8"
-log.info("main", PROJECT, VERSION)
--- 引入必要的库文件(lua编写), 内部库不需要require
-sys = require "sys"
-sysplus = require("sysplus")
-pm.ioVol(pm.IOVOL_ALL_GPIO, 1800)
--- mcu.hardfault(0)
-
-local function fskvInit()
-    fskv.init()
-    local init = fskv.get("isInit")
-    if init then
-        return
-    end
-    fskv.set("allDone", false)
-    fskv.set("pcbaDone", false)
-    fskv.set("isInit", true)
-end
-
-fskvInit()
-
-local allDone = fskv.get("allDone")
-
-if allDone then
-
-    -- 运营商给的dns经常抽风,手动指定
-    socket.setDNS(nil, 1, "223.5.5.5")
-    socket.setDNS(nil, 2, "119.29.29.29")
-
-
-    -- gnss的备电和gsensor的供电
-    local vbackup = gpio.setup(24, 1)
-    -- 使用合宙iot平台时需要这个参数
-    PRODUCT_KEY = "YXdzIDo5QawWCIRywShMAKjmJsInXtsb" -- 到 iot.openluat.com 创建项目,获取正确的项目id
-    libfota = require "libfota"
-    function fota_cb(ret)
-        log.info("fota", ret)
-        if ret == 0 then
-            rtos.reboot()
-        end
-    end
-    -- 使用合宙iot平台进行升级
-    sys.subscribe("IP_READY", function()
-        libfota.request(fota_cb)
-        sys.timerLoopStart(libfota.request, 3600000, fota_cb)
-    end)
-
-    -- 云平台逻辑
-    require "cloud"
-
-    -- 获取所有参数
-    attributes = require "attributes"
-    attributes.initial() -- 初始化
-
-    -- gnss
-    require "gnss"
-
-    -- Gsensor
-    require "da267"
-    sys.subscribe("STEP_COUNTER", function(step)
-        log.info("STEP_COUNTER", step)
-        if step > 0 then
-            attributes.set("step", step)
-        end
-    end)
-
-    -- LED
-    -- 全局状态变量
-    _G_CONNECTED = false
-    local blueLed = gpio.setup(1, 0)
-    local redLed = gpio.setup(16, 0, nil, nil, 4)
-    sys.taskInit(function()
-        while true do
-            if attributes.get("sleepMode") then
-                blueLed(0)
-                redLed(0)
-                --直接死等到休眠状态变化后再跑
-                sys.waitUntil("SLEEP_CMD_RECEIVED")
-            elseif attributes.get("ledControl") then
-                blueLed(attributes.get("blueLed") and 1 or 0)
-                redLed(attributes.get("redLed") and 1 or 0)
-                sys.wait(500)
-            else
-                redLed(attributes.get("isCharging") and 1 or 0)
-                blueLed(1)
-                sys.wait(_G_CONNECTED and 100 or 1000)
-                blueLed(0)
-                sys.wait(_G_CONNECTED and 100 or 1000)
-            end
-        end
-    end)
-
-    -- 关机键
-    local powerTimer
-    local powerKey = gpio.setup(46, function()
-        log.info("powerKey", gpio.get(46))
-        if gpio.get(46) == 0 then
-            sys.publish("POWERKEY_PRESSED")
-            powerTimer = sys.timerStart(function()
-                log.info("powerKey", "long press")
-                -- 把灯关都掉,让用户以为已经关机了
-                blueLed(0)
-                redLed(0)
-                blueLed = function()
-                end
-                redLed = blueLed
-                -- 两秒后真正关机
-                sys.timerStart(pm.shutdown, 2000)
-            end, 3000)
-        else
-            if powerTimer then
-                sys.timerStop(powerTimer)
-                log.info("powerKey", "stop press")
-            end
-        end
-    end, gpio.PULLUP)
-
-    -- 电量检测与上报
-    require "battery"
-
-    -- 信号值检测与上报
-    sys.taskInit(function()
-        while true do
-            attributes.set("rsrp", mobile.rsrp())
-            attributes.set("rsrq", mobile.rsrq())
-            sys.wait(60000)
-        end
-    end)
-
-    -- 拨打电话与音频
-    require "ccVolte"
-
-    -- SIM DETECT
-    local simCheck = gpio.setup(41, function()
-        log.info("sim status", gpio.get(41))
-    end)
-
-else
-    require "test"
-end
--- 用户代码已结束---------------------------------------------
--- 结尾总是这一句
-sys.run()

+ 0 - 327
script/turnkey/hz201p/test.lua

@@ -1,327 +0,0 @@
-local cacheTable = {}
-local rxCache = ""
-
-local vbackup = gpio.setup(24, 1)
-local gnssReset = gpio.setup(27, 1)
-local gnssEnvPower = gpio.setup(26, 1)
-local es8311Power = gpio.setup(25, 1)
-local gnssPower = gpio.setup(2, 1)
-local blueLed = gpio.setup(1, 0)
-local redLed = gpio.setup(16, 0, nil, nil, 4)
-
-local powerKeyTest = false
-pm.request(pm.IDLE)
-
-local transUartId = 1
-if not fskv.get("pcbaDone") then
-    transUartId = 1
-else
-    transUartId = uart.VUART_0
-end
-local gnssUartId = 2
-local gnssIsDownload = false
-local gnssIsTrans = false
-local gnssTransFlag = false
-uart.setup(transUartId, 115200)
-
-local Gsensori2cId = 1
-local da267Addr = 0x26
-local intPin = 39
-
-local ES8311i2cId = 0
-
-local function NMEA2UART1(id, len)
-    local result
-    while 1 do
-        local data = uart.read(gnssUartId, len)
-        if not data or #data == 0 then
-            break
-        end
-        if gnssTransFlag then
-            table.insert(cacheTable, data)
-            sys.publish("UART1_SEND")
-        end
-    end
-end
-
--- amr数据存放buffer,尽可能地给大一些
-local amr_buff = zbuff.create(20 * 1024)
--- 创建一个amr的encoder
-local encoder = nil
-
-audio.on(0, function(id, event, buff)
-    log.info("audio.on", id, event)
-    -- 使用play来播放文件时只有播放完成回调
-    if event == audio.RECORD_DATA then -- 录音数据
-        codec.encode(encoder, buff, amr_buff)
-    elseif event == audio.RECORD_DONE then -- 录音完成
-        sys.publish("AUDIO_RECORD_DONE")
-    else
-        local succ, stop, file_cnt = audio.getError(0)
-        if not succ then
-            if stop then
-                log.info("用户停止播放")
-            else
-                log.info("第", file_cnt, "个文件解码失败")
-            end
-        end
-        log.info("播放完成一个音频")
-        sys.publish("AUDIO_PLAY_DONE")
-    end
-end)
-
-local recordPath = "/record.amr"
-sys.taskInit(function()
-    mcu.altfun(mcu.I2C, Gsensori2cId, 23, 2, 0)
-    mcu.altfun(mcu.I2C, Gsensori2cId, 24, 2, 0)
-    mcu.altfun(mcu.I2C, ES8311i2cId, 13, 2, 0)
-    mcu.altfun(mcu.I2C, ES8311i2cId, 14, 2, 0)
-    local multimedia_id = 0
-    local i2s_id = 0
-    local i2s_mode = 0
-    local i2s_sample_rate = 16000
-    local i2s_bits_per_sample = 16
-    local i2s_channel_format = i2s.MONO_R
-    local i2s_communication_format = i2s.MODE_LSB
-    local i2s_channel_bits = 16
-    local pa_pin = 23
-    local pa_on_level = 1
-    local pa_delay = 100
-    local power_pin = 255
-    local power_on_level = 1
-    local power_delay = 3
-    local power_time_delay = 100
-    local voice_vol = 100
-    local mic_vol = 80
-    local find_es8311 = false
-    i2c.setup(Gsensori2cId, i2c.SLOW)
-    i2c.setup(ES8311i2cId, i2c.FAST)
-    if i2c.send(ES8311i2cId, 0x18, 0xfd) == true then
-        find_es8311 = true
-    end
-    log.info("find_es8311?", find_es8311)
-    i2s.setup(i2s_id, i2s_mode, i2s_sample_rate, i2s_bits_per_sample, i2s_channel_format, i2s_communication_format, i2s_channel_bits)
-    audio.config(multimedia_id, pa_pin, pa_on_level, power_delay, pa_delay, power_pin, power_on_level, power_time_delay)
-    audio.setBus(multimedia_id, audio.BUS_I2S, {
-        chip = "es8311",
-        i2cid = ES8311i2cId,
-        i2sid = i2s_id,
-        voltage = audio.VOLTAGE_1800
-    }) -- 通道0的硬件输出通道设置为I2S
-    audio.vol(multimedia_id, 80)
-    audio.micVol(multimedia_id, 80)
-    while true do
-        local result, param1, param2, param3 = sys.waitUntil("CONTROL")
-        log.info("CONTROL", param1, param2, param3)
-        if param1 == "GNSS" then
-            gnssReset(0)
-            sys.wait(10)
-            gnssReset(1)
-        elseif param1 == "GSENSOR" then
-            i2c.send(Gsensori2cId, da267Addr, 0x01, 1)
-            local data = i2c.recv(Gsensori2cId, da267Addr, 1)
-            if not data or data == "" or string.byte(data) ~= 0x13 then
-                table.insert(cacheTable, "ERROR#")
-            else
-                table.insert(cacheTable, "OK#")
-            end
-            sys.publish("UART1_SEND")
-        elseif param1 == "RECORD" then
-            local err = audio.record(0, audio.AMR, 5, 7, recordPath)
-            result = sys.waitUntil("AUDIO_RECORD_DONE", 10000)
-            if result then
-                table.insert(cacheTable, "OK#")
-            else
-                table.insert(cacheTable, "ERROR#")
-            end
-            sys.publish("UART1_SEND")
-        elseif param1 == "PLAY" then
-            local err = audio.play(0, recordPath)
-            result = sys.waitUntil("AUDIO_PLAY_DONE", 10000)
-            if result then
-                table.insert(cacheTable, "OK#")
-            else
-                table.insert(cacheTable, "ERROR#")
-            end
-            sys.publish("UART1_SEND")
-        end
-    end
-end)
-
-local function powerOff()
-    pm.shutdown()
-end
-
-local function powerKeyCb()
-    if gpio.get(46) == 1 then
-        if powerKeyTest then
-            table.insert(cacheTable, "POWERKEY_RELEASE#")
-        end
-        if sys.timerIsActive(powerOff) then
-            sys.timerStop(powerOff)
-        end
-    else
-        if powerKeyTest then
-            table.insert(cacheTable, "POWERKEY_PRESS#")
-        end
-        sys.timerStart(powerOff, 3000)
-    end
-    if powerKeyTest then
-        sys.publish("UART1_SEND")
-    end
-end
-gpio.debounce(46, 100)
-gpio.setup(46, powerKeyCb, gpio.PULLUP, gpio.BOTH)
-local function proc(data)
-    local item = nil
-    local find = true
-    local needNowReply = true
-    local h = string.find(data, "#")
-    if h then
-        local cmd = string.sub(data, 1, h - 1)
-        if string.find(cmd, "VERSION") then
-            item = PROJECT .. "_" .. VERSION
-        elseif string.find(cmd, "LED") then
-            local onoff = string.match(cmd, "LED,(%d)")
-            item = "OK"
-            if onoff == "0" then
-                blueLed(0)
-                redLed(0)
-            elseif onoff == "1" then
-                blueLed(1)
-                redLed(1)
-            else
-                item = "ERROR"
-            end
-        elseif string.find(cmd, "IMEI") then
-            item = mobile.imei()
-        elseif string.find(cmd, "IMSI") then
-            item = mobile.imsi()
-        elseif string.find(cmd, "ICCID") then
-            item = mobile.iccid()
-        elseif string.find(cmd, "CSQ") then
-            item = mobile.csq()
-        elseif string.find(cmd, "MUID") then
-            item = mobile.muid()
-        elseif string.find(cmd, "GPSTEST") then
-            local onoff = string.match(cmd, "GPSTEST,(%d)")
-            log.info("flag", onoff)
-            item = "OK"
-            if onoff == "0" then
-                gnssTransFlag = false
-                uart.close(gnssUartId)
-            elseif onoff == "1" then
-                gnssTransFlag = true
-                uart.on(gnssUartId, "receive", NMEA2UART1)
-                uart.setup(gnssUartId, 115200)
-            else
-                item = "ERROR"
-            end
-        elseif string.find(cmd, "GPSDOWNLOAD") then
-            local onoff = string.match(cmd, "GPSDOWNLOAD,(%d)")
-            item = "OK"
-            if onoff == "0" then
-                gpio.close(12)
-                gpio.close(13)
-            elseif onoff == "1" then
-                gpio.setup(12)
-                gpio.setup(13)
-                sys.publish("CONTROL", "GNSS")
-            else
-                item = "ERROR"
-            end
-        elseif string.find(cmd, "GS_STATE") then
-            sys.publish("CONTROL", "GSENSOR")
-            needNowReply = false
-        elseif string.find(cmd, "RECORD") then
-            sys.publish("CONTROL", "RECORD")
-            needNowReply = false
-        elseif string.find(cmd, "PLAY") then
-            sys.publish("CONTROL", "PLAY")
-            needNowReply = false
-        elseif string.find(cmd, "POWERKEY") then
-            local onoff = string.match(cmd, "POWERKEY,(%d)")
-            item = "OK"
-            if onoff == "0" then
-                powerKeyTest = false
-            elseif onoff == "1" then
-                powerKeyTest = true
-            else
-                item = "ERROR"
-            end
-        elseif string.find(cmd, "ECNPICFG") then
-            mobile.nstOnOff(true, transUartId)
-            mobile.nstInput("AT+ECNPICFG?\r\n")
-            mobile.nstInput(nil)
-            mobile.nstOnOff(false, transUartId)
-            needNowReply = false
-        elseif string.find(cmd, "VBAT") then
-            adc.open(adc.CH_VBAT)
-            local vbat = adc.get(adc.CH_VBAT)
-            adc.close(adc.CH_VBAT)
-            item = tostring(vbat)
-        elseif string.find(cmd, "PCBA_TEST_DONE") then
-            item = "OK"
-            fskv.set("pcbaDone", true)
-        elseif string.find(cmd, "TEST_DONE") then
-            item = "OK"
-            fskv.set("allDone", true)
-            sys.timerStart(pm.reboot, 3000)
-        else
-            find = false
-            item = "ERROR"
-        end
-        if find then
-            if not item then
-                item = " "
-            end
-        end
-        if needNowReply then
-            item = item .. "#"
-            table.insert(cacheTable, item)
-            sys.publish("UART1_SEND")
-        end
-        return true, data:sub(h + 1)
-    else
-        return false, data
-    end
-end
-
-uart.on(transUartId, "receive", function(id, len)
-    local result
-    while 1 do
-        local data = uart.read(transUartId, 512)
-        if not data or #data == 0 then
-            break
-        end
-        rxCache = rxCache .. data
-        while true do
-            result, rxCache = proc(rxCache)
-            if not result then
-                break
-            end
-        end
-    end
-end)
-uart.on(transUartId, "sent", function()
-    sys.publish("SEND_DOWN")
-end)
-
-sys.taskInit(function()
-    while true do
-        while #cacheTable > 0 do
-            uart.write(transUartId, table.remove(cacheTable, 1))
-            sys.waitUntil("SEND_DOWN")
-        end
-        sys.waitUntil("UART1_SEND", 1000)
-    end
-end)
-
-sys.taskInit(function()
-    sys.wait(1000)
-    while true do
-        mobile.reqCellInfo(15)
-        sys.waitUntil("CELL_INFO_UPDATE", 15000)
-        sys.wait(1000)
-    end
-end)