ril_wifi.lua 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. --- 模块功能:虚拟串口AT命令交互管理
  2. -- @module ril
  3. -- @author openLuat
  4. -- @license MIT
  5. -- @copyright openLuat
  6. -- @release 2017.02.13
  7. local ril_wifi = {}
  8. local UART_ID = 1
  9. --加载常用的全局函数至本地
  10. local vwrite = uart.write
  11. local vread = uart.read
  12. --是否为透传模式,true为透传模式,false或者nil为非透传模式
  13. --默认非透传模式
  14. local transparentmode
  15. --透传模式下,虚拟串口数据接收的处理函数
  16. local rcvfunc
  17. local uartswitch
  18. --cipsend执行完毕的flag
  19. local cipsendflag
  20. --执行AT命令后1分钟无反馈,判定at命令执行失败,则重启软件
  21. local TIMEOUT,DATA_TIMEOUT = 120000,120000
  22. --AT命令的应答类型
  23. --NORESULT:收到的应答数据当做urc通知处理,如果发送的AT命令不处理应答或者没有设置类型,默认为此类型
  24. --NUMBERIC:纯数字类型;例如发送AT+CGSN命令,应答的内容为:862991527986589\r\nOK,此类型指的是862991527986589这一部分为纯数字类型
  25. --SLINE:有前缀的单行字符串类型;例如发送AT+CSQ命令,应答的内容为:+CSQ: 23,99\r\nOK,此类型指的是+CSQ: 23,99这一部分为单行字符串类型
  26. --MLINE:有前缀的多行字符串类型;例如发送AT+CMGR=5命令,应答的内容为:+CMGR: 0,,84\r\n0891683108200105F76409A001560889F800087120315123842342050003590404590D003A59\r\nOK,此类型指的是OK之前为多行字符串类型
  27. --STRING:无前缀的字符串类型,例如发送AT+ATWMFT=99命令,应答的内容为:SUCC\r\nOK,此类型指的是SUCC
  28. --SPECIAL:特殊类型,需要针对AT命令做特殊处理,例如CIPSEND、CIPCLOSE、CIFSR
  29. local NORESULT, NUMBERIC, SLINE, MLINE, STRING, SPECIAL = 0, 1, 2, 3, 4, 10
  30. --AT命令的应答类型表,预置了如下几项
  31. local RILCMD = {
  32. ["+CSQ"] = 2,
  33. ["+MUID"] = 2,
  34. ["+CGSN"] = 1,
  35. ["+WISN"] = 4,
  36. ["+CIMI"] = 1,
  37. ["+CCID"] = 1,
  38. ["+CGATT"] = 2,
  39. ["+CCLK"] = 2,
  40. ["+ATWMFT"] = 4,
  41. ["+CMGR"] = 3,
  42. ["+CMGS"] = 2,
  43. ["+CPBF"] = 3,
  44. ["+CPBR"] = 3,
  45. ['+CLCC'] = 3,
  46. ['+CNUM'] = 3,
  47. ["+CIPSEND"] = 10,
  48. ["+CIPCLOSE"] = 10,
  49. ["+SSLINIT"] = 10,
  50. ["+SSLCERT"] = 10,
  51. ["+SSLCREATE"] = 10,
  52. ["+SSLCONNECT"] = 10,
  53. ["+SSLSEND"] = 10,
  54. ["+SSLDESTROY"] = 10,
  55. ["+SSLTERM"] = 10,
  56. ["+CIFSR"] = 10,
  57. ["+CTFSGETID"] = 2,
  58. ["+CTFSDECRYPT"] = 2,
  59. ["+CTFSAUTH"] = 2,
  60. ["+ALIPAYOPEN"] = 2,
  61. ["+ALIPAYREP"] = 2,
  62. ["+ALIPAYPINFO"] = 2,
  63. ["+ALIPAYACT"] = 2,
  64. ["+ALIPAYDID"] = 2,
  65. ["+ALIPAYSIGN"] = 2
  66. }
  67. --radioready:AT命令通道是否准备就绪
  68. --delaying:执行完某些AT命令前,需要延时一段时间,才允许执行这些AT命令;此标志表示是否在延时状态
  69. local radioready, delaying = false
  70. --AT命令队列
  71. local cmdqueue = {
  72. "ATE0",
  73. -- "AT+SYSLOG=0",
  74. 'AT+CIPSNTPCFG=1,8,"cn.ntp.org.cn","ntp.sjtu.edu.cn"',
  75. }
  76. --当前正在执行的AT命令,参数,反馈回调,延迟执行时间,命令头,类型,反馈格式
  77. local currcmd, currarg, currsp, curdelay, cmdhead, cmdtype, rspformt, cmdRspParam
  78. --反馈结果,中间信息,结果信息
  79. local result, interdata, respdata
  80. local sslCreating
  81. --ril会出现三种情况:
  82. --发送AT命令,收到应答
  83. --发送AT命令,命令超时没有应答
  84. --底层软件主动上报的通知,下文我们简称为urc
  85. --[[
  86. 函数名:atimeout
  87. 功能 :发送AT命令,命令超时没有应答的处理
  88. 参数 :无
  89. 返回值:无
  90. ]]
  91. local function atimeout()
  92. --重启软件
  93. sys.restart("ril.atimeout_" .. (currcmd or ""))
  94. end
  95. --[[
  96. 函数名:defrsp
  97. 功能 :AT命令的默认应答处理。如果没有定义某个AT的应答处理函数,则会走到本函数
  98. 参数 :
  99. cmd:此应答对应的AT命令
  100. success:AT命令执行结果,true或者false
  101. response:AT命令的应答中的执行结果字符串
  102. intermediate:AT命令的应答中的中间信息
  103. 返回值:无
  104. ]]
  105. local function defrsp(cmd, success, response, intermediate)
  106. log.info("ril.defrsp", cmd, success, response, intermediate)
  107. end
  108. --AT命令的应答处理表
  109. local rsptable = {}
  110. setmetatable(rsptable, {
  111. __index = function()
  112. return defrsp
  113. end
  114. })
  115. --自定义的AT命令应答格式表,当AT命令应答为STRING格式时,用户可以进一步定义这里面的格式
  116. local formtab = {}
  117. ---注册某个AT命令应答的处理函数
  118. -- @param head 此应答对应的AT命令头,去掉了最前面的AT两个字符
  119. -- @param fnc AT命令应答的处理函数
  120. -- @param typ AT命令的应答类型,取值范围NORESULT,NUMBERIC,SLINE,MLINE,STRING,SPECIAL
  121. -- @param formt typ为STRING时,进一步定义STRING中的详细格式
  122. -- @return bool ,成功返回true,失败false
  123. -- @usage ril.regRsp("+CSQ", rsp)
  124. function ril_wifi.regRsp(head, fnc, typ, formt)
  125. --没有定义应答类型
  126. if typ == nil then
  127. rsptable[head] = fnc
  128. return true
  129. end
  130. --定义了合法应答类型
  131. if typ == 0 or typ == 1 or typ == 2 or typ == 3 or typ == 4 or typ == 10 then
  132. --如果AT命令的应答类型已存在,并且与新设置的不一致
  133. if RILCMD[head] and RILCMD[head] ~= typ then
  134. return false
  135. end
  136. --保存
  137. RILCMD[head] = typ
  138. rsptable[head] = fnc
  139. formtab[head] = formt
  140. return true
  141. else
  142. return false
  143. end
  144. end
  145. --[[
  146. 函数名:rsp
  147. 功能 :AT命令的应答处理
  148. 参数 :无
  149. 返回值:无
  150. ]]
  151. local function rsp()
  152. --停止应答超时定时器
  153. sys.timerStopAll(atimeout)
  154. --如果发送AT命令时已经同步指定了应答处理函数
  155. if currsp then
  156. currsp(currcmd, result, respdata, interdata)
  157. --用户注册的应答处理函数表中找到处理函数
  158. else
  159. rsptable[cmdhead](currcmd, result, respdata, interdata, cmdRspParam)
  160. end
  161. --重置全局变量
  162. --log.info("在rsp被清除了吗", currcmd, currarg, currsp, curdelay, cmdhead)
  163. if cmdhead == "+CIPSEND" and cipsendflag then
  164. return
  165. end
  166. currcmd, currarg, currsp, curdelay, cmdhead, cmdtype, rspformt = nil
  167. result, interdata, respdata = nil
  168. end
  169. --[[
  170. 函数名:defurc
  171. 功能 :urc的默认处理。如果没有定义某个urc的应答处理函数,则会走到本函数
  172. 参数 :
  173. data:urc内容
  174. 返回值:无
  175. ]]
  176. local function defurc(data)
  177. log.info("ril.defurc", data)
  178. end
  179. --urc的处理表
  180. local urctable = {}
  181. setmetatable(urctable, {
  182. __index = function()
  183. return defurc
  184. end
  185. })
  186. --- 注册某个urc的处理函数
  187. -- @param prefix urc前缀,最前面的连续字符串,包含+、大写字符、数字的组合
  188. -- @param handler urc的处理函数
  189. -- @return 无
  190. -- @usage ril.regUrc("+CREG", neturc)
  191. function ril_wifi.regUrc(prefix, handler)
  192. urctable[prefix] = handler
  193. end
  194. --- 解注册某个urc的处理函数
  195. -- @param prefix urc前缀,最前面的连续字符串,包含+、大写字符、数字的组合
  196. -- @return 无
  197. -- @usage deRegUrc("+CREG")
  198. function ril_wifi.deRegUrc(prefix)
  199. urctable[prefix] = nil
  200. end
  201. --“数据过滤器”,虚拟串口收到的数据时,首先需要调用此函数过滤处理一下
  202. local urcfilter
  203. --[[
  204. 函数名:urc
  205. 功能 :urc处理
  206. 参数 :
  207. data:urc数据
  208. 返回值:无
  209. ]]
  210. local function urc(data)
  211. --AT通道准备就绪
  212. point(#data, data)
  213. if string.find(data, "ready") then
  214. radioready = true
  215. else
  216. local prefix = string.match(data, "([%+%*]*[%a%d& ]+)")
  217. -- 执行prefix的urc处理函数,返回数据过滤器
  218. urcfilter = urctable[prefix](data, prefix)
  219. end
  220. end
  221. --[[
  222. 函数名:procatc
  223. 功能 :处理虚拟串口收到的数据
  224. 参数 :
  225. data:收到的数据
  226. 返回值:无
  227. ]]
  228. local function procatc(data)
  229. log.info("ril.proatc", data)
  230. --如果命令的应答是多行字符串格式
  231. if interdata and cmdtype == MLINE then
  232. --不出现OK\r\n,则认为应答还未结束
  233. if data ~= "OK\r\n" then
  234. --去掉最后的\r\n
  235. if string.find(data, "\r\n", -2) then
  236. data = string.sub(data, 1, -3)
  237. end
  238. --拼接到中间数据
  239. interdata = interdata .. "\r\n" .. data
  240. return
  241. end
  242. end
  243. --如果存在“数据过滤器”
  244. if urcfilter then
  245. data, urcfilter = urcfilter(data)
  246. end
  247. --去掉最后的\r\n
  248. if not data:find("+CIPRECVDATA") then
  249. if string.find(data, "\r\n", -2) then
  250. point(#data)
  251. data = string.sub(data, 1, -3)
  252. end
  253. else
  254. local len, tmp = data:match("%+CIPRECVDATA:(%d+),(.+)")
  255. if len + 2 == #tmp and string.find(data, "\r\n", -2) then
  256. data = string.sub(data, 1, -3)
  257. end
  258. end
  259. --数据为空
  260. if data == "" then
  261. return
  262. end
  263. --当前无命令在执行则判定为urc
  264. if currcmd == nil then
  265. --log.info("被判定成配网数据了", data, isurc, result)
  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.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("ril.procatc.send", currarg)
  298. vwrite(UART_ID, currarg, "\026")
  299. --发送数据
  300. elseif cmdhead == "+CIPSEND" or cmdhead == "+SSLSEND" or cmdhead == "+SSLCERT" then
  301. log.info("ril.procatc.send", "first 200 bytes", currarg:sub(1,200))
  302. vwrite(UART_ID, currarg)
  303. elseif cmdhead == "+SYSFLASH" then
  304. log.info("ril.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)
  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("ril.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("ril.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("ril.getcmd", "request error no arg", head)
  435. return
  436. end
  437. end
  438. --log.info("走到赋值全局变量了吗", cmd, arg, rsp, delay, head)
  439. --赋值全局变量
  440. currcmd = cmd
  441. currarg = arg
  442. currsp = rsp
  443. curdelay = delay
  444. cmdhead = head
  445. cmdRspParam = rspParam
  446. cmdtype = RILCMD[head] or NORESULT
  447. rspformt = formtab[head]
  448. return currcmd
  449. end
  450. --[[
  451. 函数名:sendat
  452. 功能 :发送AT命令
  453. 参数 :无
  454. 返回值:无
  455. ]]
  456. local function sendat()
  457. -- AT通道未准备就绪、正在读取虚拟串口数据、有AT命令在执行或者队列无命令、正延时发送某条AT
  458. if not radioready or readat or currcmd ~= nil or delaying then
  459. return
  460. end
  461. --log.info("已就绪")
  462. local item
  463. while true do
  464. --队列无AT命令
  465. if #cmdqueue == 0 then
  466. return
  467. end
  468. --读取第一条命令
  469. item = table.remove(cmdqueue, 1)
  470. --解析命令
  471. getcmd(item)
  472. --需要延迟发送
  473. if curdelay then
  474. --启动延迟发送定时器
  475. sys.timerStart(delayfunc, curdelay)
  476. --清除全局变量
  477. currcmd, currarg, currsp, curdelay, cmdhead, cmdtype, rspformt, cmdRspParam = nil
  478. item.delay = nil
  479. --设置延迟发送标志
  480. delaying = true
  481. --把命令重新插入命令队列的队首
  482. table.insert(cmdqueue, 1, item)
  483. return
  484. end
  485. if currcmd ~= nil then
  486. break
  487. end
  488. end
  489. --启动AT命令应答超时定时器
  490. 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
  491. sys.timerStart(atimeout,DATA_TIMEOUT)
  492. else
  493. sys.timerStart(atimeout, TIMEOUT)
  494. end
  495. if currcmd:match("^AT%+SSLCREATE") then
  496. sslCreating = true
  497. end
  498. log.info("ril.sendat", currcmd)
  499. --向虚拟串口中发送AT命令
  500. vwrite(UART_ID, currcmd .. "\r\n")
  501. end
  502. -- 延时执行某条AT命令的定时器回调
  503. -- @return 无
  504. -- @usage ril.delayfunc()
  505. function ril_wifi.delayfunc()
  506. --清除延时标志
  507. delaying = nil
  508. --执行AT命令发送
  509. sendat()
  510. end
  511. --[[
  512. 函数名:atcreader
  513. 功能 :“AT命令的虚拟串口数据接收消息”的处理函数,当虚拟串口收到数据时,会走到此函数中
  514. 参数 :无
  515. 返回值:无
  516. ]]
  517. local function atcreader(id,len)
  518. local alls = vread(UART_ID, len):split("\r\n")
  519. if not transparentmode then
  520. readat = true
  521. end
  522. -- 循环读取虚拟串口收到的数据
  523. for i=1,#alls do
  524. local s = alls[i]
  525. --每次读取一行
  526. --s = vread(UART_ID, len)
  527. log.debug("uart.log",s)
  528. if string.len(s) ~= 0 then
  529. if transparentmode then
  530. --透传模式下直接转发数据
  531. rcvfunc(s)
  532. else
  533. --非透传模式下处理收到的数据
  534. procatc(s)
  535. end
  536. else
  537. break
  538. end
  539. end
  540. if not transparentmode then
  541. readat = false
  542. --数据处理完以后继续执行AT命令发送
  543. sendat()
  544. end
  545. end
  546. --- 发送AT命令到底层软件
  547. -- @param cmd AT命令内容
  548. -- @param arg AT命令参数,例如AT+CMGS=12命令执行后,接下来会发送此参数;AT+CIPSEND=14命令执行后,接下来会发送此参数
  549. -- @param onrsp AT命令应答的处理函数,只是当前发送的AT命令应答有效,处理之后就失效了
  550. -- @param delay 延时delay毫秒后,才发送此AT命令
  551. -- @return 无
  552. -- @usage ril.request("AT+CENG=1,1")
  553. -- @usage ril.request("AT+CRSM=214,28539,0,0,12,\"64f01064f03064f002fffff\"", nil, crsmResponse)
  554. function ril_wifi.request(cmd, arg, onrsp, delay, param)
  555. if transparentmode then
  556. return
  557. end
  558. --插入缓冲队列
  559. if arg or onrsp or delay or formt or param then
  560. table.insert(cmdqueue, {
  561. cmd = cmd,
  562. arg = arg,
  563. rsp = onrsp,
  564. delay = delay,
  565. rspParam = param
  566. })
  567. else
  568. table.insert(cmdqueue, cmd)
  569. end
  570. --执行AT命令发送
  571. point(cmd)
  572. sendat()
  573. end
  574. --[[
  575. 函数名:setransparentmode
  576. 功能 :AT命令通道设置为透传模式
  577. 参数 :
  578. fnc:透传模式下,虚拟串口数据接收的处理函数
  579. 返回值:无
  580. 注意:透传模式和非透传模式,只支持开机的第一次设置,不支持中途切换
  581. ]]
  582. function ril_wifi.setransparentmode(fnc)
  583. transparentmode, rcvfunc = true, fnc
  584. end
  585. --[[
  586. 函数名:sendtransparentdata
  587. 功能 :透传模式下发送数据
  588. 参数 :
  589. data:数据
  590. 返回值:成功返回true,失败返回nil
  591. ]]
  592. function ril_wifi.sendtransparentdata(data)
  593. if not transparentmode then
  594. return
  595. end
  596. vwrite(UART_ID, data)
  597. return true
  598. end
  599. function ril_wifi.setDataTimeout(tm)
  600. DATA_TIMEOUT = (tm<120000 and 120000 or tm)
  601. end
  602. uart.setup(UART_ID, 115200)
  603. --注册“AT命令的虚拟串口数据接收消息”的处理函数
  604. uart.on(UART_ID, "receive", atcreader)
  605. uart.write(UART_ID,"AT+RST\r\n")
  606. return ril_wifi