fix:删除4G模组tools目录
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
--- testSocket
|
||||
-- @module asyncSocket
|
||||
-- @author AIRM2M
|
||||
-- @license MIT
|
||||
-- @copyright openLuat.com
|
||||
-- @release 2018.10.27
|
||||
-- main.lua
|
||||
-- 功能:初始化硬件、网络、串口,注册回调,启动系统
|
||||
|
||||
PROJECT = "4G_NETWORK"
|
||||
VERSION = "1.0.0"
|
||||
@@ -11,55 +7,42 @@ VERSION = "1.0.0"
|
||||
require "sys"
|
||||
require "net"
|
||||
require "log"
|
||||
require "cmd"
|
||||
require "uart"
|
||||
require "linksocket"
|
||||
require "netLed"
|
||||
require "pmd"
|
||||
|
||||
-- 初始化 UART1
|
||||
uart.setup(1, 115200, 8, uart.PAR_NONE, uart.STOP_1)
|
||||
-- 初始化UART1
|
||||
local uartID = 1
|
||||
uart.setup(uartID, 115200, 8, uart.PAR_NONE, uart.STOP_1)
|
||||
|
||||
-- 启动网络指示灯功能模块
|
||||
require "netLed"
|
||||
pmd.ldoset(2,pmd.LDO_VLCD)
|
||||
netLed.setup(true,pio.P0_1,pio.P0_4)
|
||||
pmd.ldoset(2, pmd.LDO_VLCD)
|
||||
netLed.setup(true, pio.P0_1, pio.P0_4)
|
||||
|
||||
local uartID = 1
|
||||
-- 初始化网络
|
||||
net.startQueryAll(8 * 1000, 60 * 1000)
|
||||
ril.request("AT+RNDISCALL=0,1")
|
||||
|
||||
-- 加载自定义模块(必须放在网络初始化之后)
|
||||
local cmd = require "cmd"
|
||||
local linksocket = require "linksocket"
|
||||
|
||||
local function toHexcode(str)
|
||||
local hexcode = ""
|
||||
for i = 1, #str do
|
||||
hexcode = hexcode .. string.format("%02X", str:byte(i))
|
||||
end
|
||||
return hexcode
|
||||
end
|
||||
-- 注册Socket数据接收回调
|
||||
linksocket.setRecvCallback(function(socketId, data)
|
||||
-- 打包帧格式:55 AA 01 id len data AA 55
|
||||
local frame = string.char(0x55, 0xAA, 0x01, socketId, #data) .. data .. string.char(0xAA, 0x55)
|
||||
uart.write(uartID, frame)
|
||||
log.info("Forward data from socket", socketId, "len=", #data)
|
||||
end)
|
||||
|
||||
-- 串口数据接收处理
|
||||
uart.on(uartID, "receive", function()
|
||||
local data = uart.read(uartID, 300)
|
||||
if data and type(data) == "string" and #data > 0 then
|
||||
log.info("UART received:", toHexcode(data))
|
||||
if data:byte(1) == 0x55 and data:byte(2) == 0xAA and data:byte(-2) == 0xAA and data:byte(-1) == 0x55 then
|
||||
local Main_Cmd = data:byte(3)
|
||||
local Sub_Cmd = data:byte(4)
|
||||
local payload = data:sub(5, -3)
|
||||
|
||||
if Main_Cmd ==0x01 then
|
||||
handleCmd01(Sub_Cmd, payload)
|
||||
end
|
||||
if Main_Cmd == 0x02 then
|
||||
handleCmd02(Sub_Cmd, payload)
|
||||
end
|
||||
end
|
||||
else
|
||||
log.warn("UART receive callback triggered but no valid data")
|
||||
if data and #data > 0 then
|
||||
cmd.process(data)
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
net.startQueryAll(8 * 1000, 60 * 1000)
|
||||
|
||||
ril.request("AT+RNDISCALL=0,1")
|
||||
|
||||
|
||||
-- 启动系统
|
||||
sys.init(0, 0)
|
||||
sys.run()
|
||||
Reference in New Issue
Block a user