8 Star 26 Fork 14

wibim / luat-jt808

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
factory.lua 3.66 KB
一键复制 编辑 原始数据 按行查看 历史
wibim 提交于 2020-02-15 14:44 . 第一次上代码
--[[
模块名称:factory
模块功能:功能测试
模块最后修改时间:2017.08.25
]]
module(...,package.seeall)
local ftrlt,fttimes,shkflag = 0,0
local smatch,slen = string.match,string.len
local waitrst
--[[
函数名:rsp
功能 :向串口写数据
参数 :写入字符串
返回值:无
]]
local function rsp(s)
print("factory rsp",s)
uart.write(3,s)
end
local function timeout()
local s1
fttimes = fttimes + 1
print("factory timeout",fttimes)
if fttimes > 20 then
s1 = "\r\n" .. "+FT9352:" .. "\r\n" .. ftrlt .. "\r\n" .. "OK" .. "\r\n"
rsp(s1)
rsp("\r\nOK\r\n")
return
end
checkft()
end
function getpwflag()
return pincfg.CHARGER()==1 and true or false
end
function getchgflag()
return pincfg.CHG_STATUS()==1 and true or false
end
function checkft()
print("factory checkft",net.getState(),net.getRssi(),gps.getgpssn(),shkflag,acc.getflag(),getpwflag(),chg.getstate())
local s1
if net.getState()=="REGISTERED" and net.getRssi() > 10 and (ftrlt % 2) == 0 then
ftrlt = ftrlt + 1
end
if gps.getgpssn() > 30 then
if (ftrlt % 4) < 2 then
ftrlt = ftrlt + 2
end
end
if shkflag then
if (ftrlt % 8) < 4 then
ftrlt = ftrlt + 4
end
end
if acc.getflag() then
if (ftrlt % 16) < 8 then
ftrlt = ftrlt + 8
end
end
if getpwflag() then
if (ftrlt % 32) < 16 then
ftrlt = ftrlt + 16
end
end
if getchgflag() then
if ftrlt < 32 then
ftrlt = ftrlt + 32
end
end
if ftrlt < 63 then
print("factory timeout",fttimes)
sys.timerStart(timeout,1000)
else
gps.close(gps.DEFAULT,{tag="FAC"})
s1 = "\r\n" .. "+FT9352:" .. "\r\n" .. ftrlt .. "\r\n" .. "OK" .. "\r\n"
rsp(s1)
rsp("\r\nOK\r\n")
end
end
local function cb(cmd,success,response,intermediate)
if (smatch(cmd,"WIMEI=") or smatch(cmd,"WISN=") or smatch(cmd,"AMFAC=")) and success then
rsp("\r\nOK\r\n")
end
end
local function cbwsin(success)
if success then
rsp("\r\nOK\r\n")
end
end
local function cbwimei(success)
if success then
rsp("\r\nOK\r\n")
end
end
--[[
函数名:proc
功能 :串口命令解析
参数 :要解析字符串
返回值:无
]]
local function proc(s)
s = string.upper(s)
if smatch(s,"WIMEI=") then
misc.setImei(smatch(s,"=\"(.+)\""),cbwimei)
elseif smatch(s,"CGSN") then
if waitrst then
rsp("\r\nAT+CGSN\r\nWAIT RST\r\nOK\r\n")
else
local imei = misc.getImei()
if imei and slen(imei) > 0 then
rsp("\r\nAT+CGSN\r\n" .. imei .. "\r\nOK\r\n")
end
end
elseif smatch(s,"WISN=") then
misc.setSn(smatch(s,"=(.+)\r"),cbwsin)
rsp("\r\nOK\r\n")
elseif smatch(s,"WISN%?") then
if waitrst then
rsp("\r\nAT+WISN?\r\nWAIT RST\r\nOK\r\n")
else
local sn = misc.getSn()
if sn and slen(sn) > 0 then
rsp("\r\nAT+WISN?\r\n" .. sn .. "\r\nOK\r\n")
end
end
elseif smatch(s,"VER") then
rsp("\r\nAT+VER\r\n" .. _G.PROJECT .. "_" .. _G.VERSION .."\r\nOK\r\n")
elseif smatch(s,"AMFAC=") then
rsp("\r\nOK\r\n")
elseif smatch(s,"CFUN=") then
rsp("\r\nOK\r\n")
waitrst = true
uart.close(3)
rtos.restart()
elseif smatch(s,"WDTEST") then
rsp("\r\nOK\r\n")
waitrst = true
uart.close(3)
wdt1.test()
elseif smatch(s,"LIGHT") then
light.factest(1)
rsp("\r\nAT+LIGHT\r\nOK\r\n")
elseif smatch(s,"AT%+FT9352") then
gps.open(gps.DEFAULT,{tag="FAC"})
checkft()
end
end
local function read()
local t1
local s1 = ""
local rd = true
while rd == true do
t1 = uart.read(3,"*l",0)
if string.len(t1) == 0 then
rd = false
continue
end
s1 = s1 .. t1
end
if s1 ~= "" then
print("factory proc:",s1)
end
proc(s1)
end
local function ind(id,data)
shkflag = true
return true
end
uart.setup(3,921600,8,uart.PAR_NONE,uart.STOP_1,2)
uart.on(3, "receive", read)
sys.subscribe("DEV_SHK_IND",ind)
Lua
1
https://gitee.com/wibim/luat-jt808.git
git@gitee.com:wibim/luat-jt808.git
wibim
luat-jt808
luat-jt808
master

搜索帮助