add : USB CDC虚拟串口通讯
This commit is contained in:
65
4G/tools/_temp/script/temp_script/main.lua
Normal file
65
4G/tools/_temp/script/temp_script/main.lua
Normal file
@@ -0,0 +1,65 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
PROJECT = "4G_NETWORK"
|
||||
VERSION = "1.0.0"
|
||||
|
||||
require "sys"
|
||||
require "net"
|
||||
require "log"
|
||||
require "cmd"
|
||||
require "uart"
|
||||
require "linksocket"
|
||||
|
||||
|
||||
uart.setup(1, 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)
|
||||
|
||||
local uartID = 1
|
||||
|
||||
|
||||
local function toHexcode(str)
|
||||
local hexcode = ""
|
||||
for i = 1, #str do
|
||||
hexcode = hexcode .. string.format("%02X", str:byte(i))
|
||||
end
|
||||
return hexcode
|
||||
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")
|
||||
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