wifiRil.lua 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. --- 模块功能:esp8266 wifi模块AT命令交互管理
  2. -- @module wifiRil
  3. -- @author openLuat
  4. -- @license MIT
  5. -- @copyright openLuat
  6. -- @release 2017.02.13
  7. -- require "uart"
  8. -- require "rtos"
  9. require "sys"
  10. require "log"
  11. module(..., package.seeall)
  12. local UART_ID = 1
  13. --加载常用的全局函数至本地
  14. local vwrite = uart.write
  15. local vread = uart.read
  16. --是否为透传模式,true为透传模式,false或者nil为非透传模式
  17. --默认非透传模式
  18. local transparentmode
  19. --透传模式下,虚拟串口数据接收的处理函数
  20. local rcvfunc
  21. local uartswitch
  22. --cipsend执行完毕的flag
  23. local cipsendflag
  24. --执行AT命令后1分钟无反馈,判定at命令执行失败,则重启软件
  25. local TIMEOUT,DATA_TIMEOUT = 120000,120000
  26. --AT命令的应答类型
  27. --NORESULT:收到的应答数据当做urc通知处理,如果发送的AT命令不处理应答或者没有设置类型,默认为此类型
  28. --NUMBERIC:纯数字类型;例如发送AT+CGSN命令,应答的内容为:862991527986589\r\nOK,此类型指的是862991527986589这一部分为纯数字类型
  29. --SLINE:有前缀的单行字符串类型;例如发送AT+CSQ命令,应答的内容为:+CSQ: 23,99\r\nOK,此类型指的是+CSQ: 23,99这一部分为单行字符串类型
  30. --MLINE:有前缀的多行字符串类型;例如发送AT+CMGR=5命令,应答的内容为:+CMGR: 0,,84\r\n0891683108200105F76409A001560889F800087120315123842342050003590404590D003A59\r\nOK,此类型指的是OK之前为多行字符串类型
  31. --STRING:无前缀的字符串类型,例如发送AT+ATWMFT=99命令,应答的内容为:SUCC\r\nOK,此类型指的是SUCC
  32. --SPECIAL:特殊类型,需要针对AT命令做特殊处理,例如CIPSEND、CIPCLOSE、CIFSR
  33. local NORESULT, NUMBERIC, SLINE, MLINE, STRING, SPECIAL = 0, 1, 2, 3, 4, 10
  34. --AT命令的应答类型表,预置了如下几项
  35. local RILCMD = {
  36. ["+CSQ"] = 2,
  37. ["+MUID"] = 2,
  38. ["+CGSN"] = 1,
  39. ["+WISN"] = 4,
  40. ["+CIMI"] = 1,
  41. ["+CCID"] = 1,
  42. ["+CGATT"] = 2,
  43. ["+CCLK"] = 2,
  44. ["+ATWMFT"] = 4,
  45. ["+CMGR"] = 3,
  46. ["+CMGS"] = 2,
  47. ["+CPBF"] = 3,
  48. ["+CPBR"] = 3,
  49. ['+CLCC'] = 3,
  50. ['+CNUM'] = 3,
  51. ["+CIPSEND"] = 10,
  52. ["+CIPCLOSE"] = 10,
  53. ["+SSLINIT"] = 10,
  54. ["+SSLCERT"] = 10,
  55. ["+SSLCREATE"] = 10,
  56. ["+SSLCONNECT"] = 10,
  57. ["+SSLSEND"] = 10,
  58. ["+SSLDESTROY"] = 10,
  59. ["+SSLTERM"] = 10,
  60. ["+CIFSR"] = 10,
  61. ["+CTFSGETID"] = 2,
  62. ["+CTFSDECRYPT"] = 2,
  63. ["+CTFSAUTH"] = 2,
  64. ["+ALIPAYOPEN"] = 2,
  65. ["+ALIPAYREP"] = 2,
  66. ["+ALIPAYPINFO"] = 2,
  67. ["+ALIPAYACT"] = 2,
  68. ["+ALIPAYDID"] = 2,
  69. ["+ALIPAYSIGN"] = 2
  70. }
  71. --radioready:AT命令通道是否准备就绪
  72. --delaying:执行完某些AT命令前,需要延时一段时间,才允许执行这些AT命令;此标志表示是否在延时状态
  73. local radioready, delaying = false
  74. --AT命令队列
  75. local cmdqueue = {
  76. "ATE0",
  77. -- "AT+SYSLOG=0",
  78. 'AT+CIPSNTPCFG=1,8,"cn.ntp.org.cn","ntp.sjtu.edu.cn"',
  79. }
  80. --当前正在执行的AT命令,参数,反馈回调,延迟执行时间,命令头,类型,反馈格式
  81. local currcmd, currarg, currsp, curdelay, cmdhead, cmdtype, rspformt, cmdRspParam
  82. --反馈结果,中间信息,结果信息
  83. local result, interdata, respdata
  84. local sslCreating
  85. --ril会出现三种情况:
  86. --发送AT命令,收到应答
  87. --发送AT命令,命令超时没有应答
  88. --底层软件主动上报的通知,下文我们简称为urc
  89. --[[
  90. 函数名:atimeout
  91. 功能 :发送AT命令,命令超时没有应答的处理
  92. 参数 :无
  93. 返回值:无
  94. ]]
  95. local function atimeout()
  96. --重启软件
  97. sys.restart("wifiRil.atimeout_" .. (currcmd or ""))
  98. end
  99. --[[
  100. 函数名:defrsp
  101. 功能 :AT命令的默认应答处理。如果没有定义某个AT的应答处理函数,则会走到本函数
  102. 参数 :
  103. cmd:此应答对应的AT命令
  104. success:AT命令执行结果,true或者false
  105. response:AT命令的应答中的执行结果字符串
  106. intermediate:AT命令的应答中的中间信息
  107. 返回值:无
  108. ]]
  109. local function defrsp(cmd, success, response, intermediate)
  110. log.info("wifiRil.defrsp", cmd, success, response, intermediate)
  111. end
  112. --AT命令的应答处理表
  113. local rsptable = {}
  114. setmetatable(rsptable, {
  115. __index = function()
  116. return defrsp
  117. end
  118. })
  119. --自定义的AT命令应答格式表,当AT命令应答为STRING格式时,用户可以进一步定义这里面的格式
  120. local formtab = {}
  121. ---注册某个AT命令应答的处理函数
  122. -- @param head 此应答对应的AT命令头,去掉了最前面的AT两个字符
  123. -- @param fnc AT命令应答的处理函数
  124. -- @param typ AT命令的应答类型,取值范围NORESULT,NUMBERIC,SLINE,MLINE,STRING,SPECIAL
  125. -- @param formt typ为STRING时,进一步定义STRING中的详细格式
  126. -- @return bool ,成功返回true,失败false
  127. -- @usage wifiRil.regRsp("+CSQ", rsp)
  128. function regRsp(head, fnc, typ, formt)
  129. --没有定义应答类型
  130. if typ == nil then
  131. rsptable[head] = fnc
  132. return true
  133. end
  134. --定义了合法应答类型
  135. if typ == 0 or typ == 1 or typ == 2 or typ == 3 or typ == 4 or typ == 10 then
  136. --如果AT命令的应答类型已存在,并且与新设置的不一致
  137. if RILCMD[head] and RILCMD[head] ~= typ then
  138. return false
  139. end
  140. --保存
  141. RILCMD[head] = typ
  142. rsptable[head] = fnc
  143. formtab[head] = formt
  144. return true
  145. else
  146. return false
  147. end
  148. end
  149. --[[
  150. 函数名:rsp
  151. 功能 :AT命令的应答处理
  152. 参数 :无
  153. 返回值:无
  154. ]]
  155. local function rsp()
  156. --停止应答超时定时器
  157. sys.timerStopAll(atimeout)
  158. --如果发送AT命令时已经同步指定了应答处理函数
  159. if currsp then
  160. currsp(currcmd, result, respdata, interdata)
  161. --用户注册的应答处理函数表中找到处理函数
  162. else
  163. rsptable[cmdhead](currcmd, result, respdata, interdata, cmdRspParam)
  164. end
  165. --重置全局变量
  166. if cmdhead == "+CIPSEND" and cipsendflag then
  167. return
  168. end
  169. currcmd, currarg, currsp, curdelay, cmdhead, cmdtype, rspformt = nil
  170. result, interdata, respdata = nil
  171. end
  172. --[[
  173. 函数名:defurc
  174. 功能 :urc的默认处理。如果没有定义某个urc的应答处理函数,则会走到本函数
  175. 参数 :
  176. data:urc内容
  177. 返回值:无
  178. ]]
  179. local function defurc(data)
  180. log.info("wifiRil.defurc", data)
  181. end
  182. --urc的处理表
  183. local urctable = {}
  184. setmetatable(urctable, {
  185. __index = function()
  186. return defurc
  187. end
  188. })
  189. --- 注册某个urc的处理函数
  190. -- @param prefix urc前缀,最前面的连续字符串,包含+、大写字符、数字的组合
  191. -- @param handler urc的处理函数
  192. -- @return 无
  193. -- @usage wifiRil.regUrc("+CREG", neturc)
  194. function regUrc(prefix, handler)
  195. urctable[prefix] = handler
  196. end
  197. --- 解注册某个urc的处理函数
  198. -- @param prefix urc前缀,最前面的连续字符串,包含+、大写字符、数字的组合
  199. -- @return 无
  200. -- @usage deRegUrc("+CREG")
  201. function deRegUrc(prefix)
  202. urctable[prefix] = nil
  203. end
  204. --“数据过滤器”,虚拟串口收到的数据时,首先需要调用此函数过滤处理一下
  205. local urcfilter
  206. --[[
  207. 函数名:urc
  208. 功能 :urc处理
  209. 参数 :
  210. data:urc数据
  211. 返回值:无
  212. ]]
  213. local function urc(data, cmd)
  214. --AT通道准备就绪
  215. if data == "ready" then
  216. radioready = true
  217. else
  218. local prefix = string.match(data, "([%+%*]*[%a%d& ]+)")
  219. -- 执行prefix的urc处理函数,返回数据过滤器
  220. urcfilter = urctable[prefix](data, prefix, cmd)
  221. end
  222. end
  223. --[[
  224. 函数名:procatc
  225. 功能 :处理虚拟串口收到的数据
  226. 参数 :
  227. data:收到的数据
  228. 返回值:无
  229. ]]
  230. local function procatc(data)
  231. log.info("wifiRil.proatc", data)
  232. --如果命令的应答是多行字符串格式
  233. if interdata and cmdtype == MLINE then
  234. --不出现OK\r\n,则认为应答还未结束
  235. if data ~= "OK\r\n" then
  236. --去掉最后的\r\n
  237. if string.find(data, "\r\n", -2) then
  238. data = string.sub(data, 1, -3)
  239. end
  240. --拼接到中间数据
  241. interdata = interdata .. "\r\n" .. data
  242. return
  243. end
  244. end
  245. --如果存在“数据过滤器”
  246. if urcfilter then
  247. data, urcfilter = urcfilter(data)
  248. end
  249. --去掉最后的\r\n
  250. if not data:find("+CIPRECVDATA") then
  251. if string.find(data, "\r\n", -2) then
  252. data = string.sub(data, 1, -3)
  253. end
  254. else
  255. local len, tmp = data:match("%+CIPRECVDATA:(%d+),(.+)")
  256. if len + 2 == #tmp and string.find(data, "\r\n", -2) then
  257. data = string.sub(data, 1, -3)
  258. end
  259. end
  260. --数据为空
  261. if data == "" then
  262. return
  263. end
  264. --当前无命令在执行则判定为urc
  265. if currcmd == nil then
  266. urc(data)
  267. return
  268. end
  269. local isurc = false
  270. --一些特殊的错误信息,转化为ERROR统一处理
  271. if string.find(data, "^%+CMS ERROR:") or string.find(data, "^%+CME ERROR:") or (data == "CONNECT FAIL" and currcmd and string.match(currcmd, "CIPSTART")) then
  272. data = "ERROR"
  273. end
  274. if sslCreating and data=="+PDP: DEACT" and tonumber(string.match(rtos.get_version(),"Luat_V(%d+)_"))<31 then
  275. sys.publish("SSL_DNS_PARSE_PDP_DEACT")
  276. end
  277. if cmdhead == "+CIPSEND" and data == "SEND OK" then
  278. result = true
  279. respdata = data
  280. cipsendflag = false
  281. elseif cmdhead == "+CIPSEND" and data == "OK" then
  282. result = true
  283. respdata = data
  284. cipsendflag = true
  285. --执行成功的应答
  286. elseif data == "OK" or data == "SHUT OK" then
  287. result = true
  288. respdata = data
  289. --执行失败的应答
  290. elseif data == "ERROR" or data == "NO ANSWER" or data == "NO DIALTONE" then
  291. result = false
  292. respdata = data
  293. --需要继续输入参数的AT命令应答
  294. elseif data == ">" then
  295. --发送短信
  296. if cmdhead == "+CMGS" then
  297. log.info("wifiRil.procatc.send", currarg)
  298. vwrite(UART_ID, currarg, "\026")
  299. --发送数据
  300. elseif cmdhead == "+CIPSEND" or cmdhead == "+SSLSEND" or cmdhead == "+SSLCERT" then
  301. log.info("wifiRil.procatc.send", "first 200 bytes", currarg:sub(1,200))
  302. vwrite(UART_ID, currarg)
  303. elseif cmdhead == "+SYSFLASH" then
  304. log.info("wifiRil.sysflash.send", "first 200 bytes", currarg:sub(1,200))
  305. vwrite(UART_ID, currarg)
  306. else
  307. log.error("error promot cmd:", currcmd)
  308. end
  309. else
  310. --无类型
  311. if cmdtype == NORESULT then
  312. isurc = true
  313. --全数字类型
  314. elseif cmdtype == NUMBERIC then
  315. local numstr = string.match(data, "(%x+)")
  316. if numstr == data then
  317. interdata = data
  318. else
  319. isurc = true
  320. end
  321. --字符串类型
  322. elseif cmdtype == STRING then
  323. --进一步检查格式
  324. if string.match(data, rspformt or "^.+$") then
  325. interdata = data
  326. else
  327. isurc = true
  328. end
  329. elseif cmdtype == SLINE or cmdtype == MLINE then
  330. if interdata == nil and string.find(data, cmdhead) == 1 then
  331. interdata = data
  332. else
  333. isurc = true
  334. end
  335. --特殊处理
  336. elseif cmdhead == "+CIFSR" then
  337. local s = string.match(data, "%d+%.%d+%.%d+%.%d+")
  338. if s ~= nil then
  339. interdata = s
  340. result = true
  341. else
  342. isurc = true
  343. end
  344. --特殊处理
  345. elseif cmdhead == "+CIPSEND" or cmdhead == "+CIPCLOSE" then
  346. local keystr = cmdhead == "+CIPSEND" and "SEND" or "CLOSE"
  347. local lid, res = string.match(data, "(%d), *([%u%d :]+)")
  348. if data:match("^%d, *CLOSED$") then
  349. isurc = true
  350. elseif lid and res then
  351. if (string.find(res, keystr) == 1 or string.find(res, "TCP ERROR") == 1 or string.find(res, "UDP ERROR") == 1 or string.find(data, "DATA ACCEPT")) and (lid == string.match(currcmd, "=(%d)")) then
  352. result = data:match("ERROR") == nil
  353. respdata = data
  354. else
  355. isurc = true
  356. end
  357. elseif data == "+PDP: DEACT" then
  358. result = true
  359. respdata = data
  360. elseif data:match("^Recv %d+ bytes$") then
  361. result = true
  362. respdata = data
  363. else
  364. isurc = true
  365. end
  366. elseif cmdhead == "+SSLINIT" or cmdhead == "+SSLCERT" or cmdhead == "+SSLCREATE" or cmdhead == "+SSLCONNECT" or cmdhead == "+SSLSEND" or cmdhead == "+SSLDESTROY" or cmdhead == "+SSLTERM" then
  367. if string.match(data, "^SSL&%d, *CLOSED") or string.match(data, "^SSL&%d, *ERROR") or string.match(data, "SSL&%d,CONNECT ERROR") then
  368. isurc = true
  369. elseif string.match(data, "^SSL&%d,") then
  370. respdata = data
  371. if string.match(data, "ERROR") then
  372. result = false
  373. else
  374. result = true
  375. end
  376. if cmdhead == "+SSLCREATE" then
  377. sslCreating = false
  378. end
  379. else
  380. isurc = true
  381. end
  382. else
  383. isurc = true
  384. end
  385. end
  386. -- urc处理
  387. if isurc then
  388. urc(data, currcmd)
  389. --应答处理
  390. elseif result ~= nil then
  391. rsp()
  392. end
  393. end
  394. --是否在读取虚拟串口数据
  395. local readat = false
  396. --[[
  397. 函数名:getcmd
  398. 功能 :解析一条AT命令
  399. 参数 :
  400. item:AT命令
  401. 返回值:当前AT命令的内容
  402. ]]
  403. local function getcmd(item)
  404. local cmd, arg, rsp, delay, rspParam
  405. --命令是string类型
  406. if type(item) == "string" then
  407. --命令内容
  408. cmd = item
  409. --命令是table类型
  410. elseif type(item) == "table" then
  411. --命令内容
  412. cmd = item.cmd
  413. --命令参数
  414. arg = item.arg
  415. --命令应答处理函数
  416. rsp = item.rsp
  417. --命令延时执行时间
  418. delay = item.delay
  419. --命令携带的参数,执行回调时传入此参数
  420. rspParam = item.rspParam
  421. else
  422. log.info("wifiRil.getcmd", "getpack unknown item")
  423. return
  424. end
  425. -- 命令前缀
  426. local head = string.match(cmd, "AT([%+%*]*%u+)")
  427. if head == nil then
  428. log.error("wifiRil.getcmd", "request error cmd:", cmd)
  429. return
  430. end
  431. --这两个命令必须有参数
  432. if head == "+CMGS" or head == "+CIPSEND" then -- 必须有参数
  433. if arg == nil or arg == "" then
  434. log.error("wifiRil.getcmd", "request error no arg", head)
  435. return
  436. end
  437. end
  438. --赋值全局变量
  439. currcmd = cmd
  440. currarg = arg
  441. currsp = rsp
  442. curdelay = delay
  443. cmdhead = head
  444. cmdRspParam = rspParam
  445. cmdtype = RILCMD[head] or NORESULT
  446. rspformt = formtab[head]
  447. return currcmd
  448. end
  449. --[[
  450. 函数名:sendat
  451. 功能 :发送AT命令
  452. 参数 :无
  453. 返回值:无
  454. ]]
  455. local function sendat()
  456. -- AT通道未准备就绪、正在读取虚拟串口数据、有AT命令在执行或者队列无命令、正延时发送某条AT
  457. if not radioready or readat or currcmd ~= nil or delaying then
  458. return
  459. end
  460. local item
  461. while true do
  462. --队列无AT命令
  463. if #cmdqueue == 0 then
  464. return
  465. end
  466. --读取第一条命令
  467. item = table.remove(cmdqueue, 1)
  468. --解析命令
  469. getcmd(item)
  470. --需要延迟发送
  471. if curdelay then
  472. --启动延迟发送定时器
  473. sys.timerStart(delayfunc, curdelay)
  474. --清除全局变量
  475. currcmd, currarg, currsp, curdelay, cmdhead, cmdtype, rspformt, cmdRspParam = nil
  476. item.delay = nil
  477. --设置延迟发送标志
  478. delaying = true
  479. --把命令重新插入命令队列的队首
  480. table.insert(cmdqueue, 1, item)
  481. return
  482. end
  483. if currcmd ~= nil then
  484. break
  485. end
  486. end
  487. --启动AT命令应答超时定时器
  488. if currcmd:match("^AT%+CIPSTART") or currcmd:match("^AT%+CIPSEND") or currcmd:match("^AT%+SSLCREATE") or currcmd:match("^AT%+SSLCONNECT") or currcmd:match("^AT%+SSLSEND") then
  489. sys.timerStart(atimeout,DATA_TIMEOUT)
  490. else
  491. sys.timerStart(atimeout, TIMEOUT)
  492. end
  493. if currcmd:match("^AT%+SSLCREATE") then
  494. sslCreating = true
  495. end
  496. log.info("wifiRil.sendat", currcmd)
  497. --向虚拟串口中发送AT命令
  498. vwrite(UART_ID, currcmd .. "\r\n")
  499. end
  500. -- 延时执行某条AT命令的定时器回调
  501. -- @return 无
  502. -- @usage wifiRil.delayfunc()
  503. function delayfunc()
  504. --清除延时标志
  505. delaying = nil
  506. --执行AT命令发送
  507. sendat()
  508. end
  509. --[[
  510. 函数名:atcreader
  511. 功能 :“AT命令的虚拟串口数据接收消息”的处理函数,当虚拟串口收到数据时,会走到此函数中
  512. 参数 :无
  513. 返回值:无
  514. ]]
  515. local function atcreader()
  516. local s
  517. if not transparentmode then
  518. readat = true
  519. end
  520. -- 循环读取虚拟串口收到的数据
  521. while true do
  522. --每次读取一行
  523. s = vread(UART_ID, "*l", 0)
  524. if string.len(s) ~= 0 then
  525. if transparentmode then
  526. --透传模式下直接转发数据
  527. rcvfunc(s)
  528. else
  529. --非透传模式下处理收到的数据
  530. procatc(s)
  531. end
  532. else
  533. break
  534. end
  535. end
  536. if not transparentmode then
  537. readat = false
  538. --数据处理完以后继续执行AT命令发送
  539. sendat()
  540. end
  541. end
  542. --- 发送AT命令到底层软件
  543. -- @param cmd AT命令内容
  544. -- @param arg AT命令参数,例如AT+CMGS=12命令执行后,接下来会发送此参数;AT+CIPSEND=14命令执行后,接下来会发送此参数
  545. -- @param onrsp AT命令应答的处理函数,只是当前发送的AT命令应答有效,处理之后就失效了
  546. -- @param delay 延时delay毫秒后,才发送此AT命令
  547. -- @return 无
  548. -- @usage wifiRil.request("AT+CENG=1,1")
  549. -- @usage wifiRil.request("AT+CRSM=214,28539,0,0,12,\"64f01064f03064f002fffff\"", nil, crsmResponse)
  550. function request(cmd, arg, onrsp, delay, param)
  551. if transparentmode then
  552. return
  553. end
  554. --插入缓冲队列
  555. if arg or onrsp or delay or formt or param then
  556. table.insert(cmdqueue, {
  557. cmd = cmd,
  558. arg = arg,
  559. rsp = onrsp,
  560. delay = delay,
  561. rspParam = param
  562. })
  563. else
  564. table.insert(cmdqueue, cmd)
  565. end
  566. --执行AT命令发送
  567. sendat()
  568. end
  569. --[[
  570. 函数名:setransparentmode
  571. 功能 :AT命令通道设置为透传模式
  572. 参数 :
  573. fnc:透传模式下,虚拟串口数据接收的处理函数
  574. 返回值:无
  575. 注意:透传模式和非透传模式,只支持开机的第一次设置,不支持中途切换
  576. ]]
  577. function setransparentmode(fnc)
  578. transparentmode, rcvfunc = true, fnc
  579. end
  580. --[[
  581. 函数名:sendtransparentdata
  582. 功能 :透传模式下发送数据
  583. 参数 :
  584. data:数据
  585. 返回值:成功返回true,失败返回nil
  586. ]]
  587. function sendtransparentdata(data)
  588. if not transparentmode then
  589. return
  590. end
  591. vwrite(UART_ID, data)
  592. return true
  593. end
  594. function setDataTimeout(tm)
  595. DATA_TIMEOUT = (tm<120000 and 120000 or tm)
  596. end
  597. uart.setup(UART_ID, 115200, 8, uart.PAR_NONE, uart.STOP_1)
  598. --注册“AT命令的虚拟串口数据接收消息”的处理函数
  599. uart.on(UART_ID, "receive", atcreader)