代码拉取完成,页面将自动刷新
--[[
模块名称: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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。