luat_lib_mobile.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591
  1. /*
  2. @module mobile
  3. @summary 蜂窝网络
  4. @version 1.0
  5. @date 2022.8.9
  6. @demo mobile
  7. @tag LUAT_USE_MOBILE
  8. @usage
  9. -- 简单演示
  10. log.info("imei", mobile.imei())
  11. log.info("imsi", mobile.imsi())
  12. local sn = mobile.sn()
  13. if sn then
  14. log.info("sn", sn:toHex())
  15. end
  16. log.info("muid", mobile.muid())
  17. log.info("iccid", mobile.iccid())
  18. log.info("csq", mobile.csq())
  19. log.info("rssi", mobile.rssi())
  20. log.info("rsrq", mobile.rsrq())
  21. log.info("rsrp", mobile.rsrp())
  22. log.info("snr", mobile.snr())
  23. log.info("simid", mobile.simid())
  24. */
  25. #include "luat_base.h"
  26. #include "luat_mem.h"
  27. #include "luat_rtos.h"
  28. #include "luat_msgbus.h"
  29. #include "luat_mobile.h"
  30. #include "luat_network_adapter.h"
  31. #define LUAT_LOG_TAG "mobile"
  32. #include "luat_log.h"
  33. extern void luat_cc_start_speech(uint32_t param);
  34. extern void luat_cc_play_tone(uint32_t param);
  35. /**
  36. 获取IMEI
  37. @api mobile.imei(index)
  38. @int 编号,默认0. 在支持双卡的模块上才会出现0或1的情况
  39. @return string 当前的IMEI值,若失败返回nil
  40. @usgae
  41. -- 注意, 当前所有模块只支持单待,所以IMEI总是同一个
  42. */
  43. static int l_mobile_imei(lua_State* L) {
  44. char buff[24] = {0};
  45. // size_t len = 0;
  46. // size_t wlen = 0;
  47. int ret = 0;
  48. int index = luaL_optinteger(L, 1, 0);
  49. ret = luat_mobile_get_imei(index, buff, 24);
  50. // if (lua_isstring(L, 2)) {
  51. // const char* wbuff = luaL_checklstring(L, 2, &wlen);
  52. // if (wlen >= 15) {
  53. // ret = luat_mobile_set_imei(index, wbuff, wlen);
  54. // LLOGI("IMEI write %d %s ret %d", index, wbuff, ret);
  55. // }
  56. // }
  57. if (ret > 0) {
  58. buff[23] = 0x00; // 确保能结束
  59. lua_pushlstring(L, buff, strlen(buff));
  60. }
  61. else
  62. lua_pushnil(L);
  63. return 1;
  64. }
  65. /**
  66. 获取IMSI
  67. @api mobile.imsi(index)
  68. @int 编号,默认0. 在支持双卡的模块上才会出现0或1的情况
  69. @return string 当前的IMSI值,若失败返回nil
  70. @usgae
  71. -- 注意, 当前所有模块只支持单待,所以IMSI总是同一个
  72. */
  73. static int l_mobile_imsi(lua_State* L) {
  74. char buff[24] = {0};
  75. // size_t len = 0;
  76. // size_t wlen = 0;
  77. int ret = 0;
  78. int index = luaL_optinteger(L, 1, 0);
  79. ret = luat_mobile_get_imsi(index, buff, 24);
  80. // if (lua_isstring(L, 2)) {
  81. // const char* wbuff = luaL_checklstring(L, 2, &wlen);
  82. // if (wlen >= 1) {
  83. // ret = luat_mobile_set_imsi(index, wbuff, wlen);
  84. // LLOGI("IMSI write %d %s ret %d", index, wbuff, ret);
  85. // }
  86. // }
  87. if (ret > 0){
  88. buff[23] = 0x00; // 确保能结束
  89. lua_pushlstring(L, buff, strlen(buff));
  90. }
  91. else
  92. lua_pushnil(L);
  93. return 1;
  94. }
  95. /**
  96. 获取SN
  97. @api mobile.sn()
  98. @return string 当前的SN值,若失败返回nil. 注意, SN可能包含不可见字符
  99. @usage
  100. -- 注意, 出厂未必有写SN
  101. -- 一般用途的唯一id, 可以用mobile.imei()代替
  102. -- 如需要真正的唯一ID, 使用 mcu.unique_id()
  103. */
  104. static int l_mobile_sn(lua_State* L) {
  105. char buff[32] = {0};
  106. // size_t len = 0;
  107. // size_t wlen = 0;
  108. int ret = 0;
  109. ret = luat_mobile_get_sn(buff, 32);
  110. // if (lua_isstring(L, 1)) {
  111. // const char* wbuff = luaL_checklstring(L, 1, &wlen);
  112. // if (wlen >= 1) {
  113. // ret = luat_mobile_set_sn(wbuff, wlen);
  114. // LLOGI("SN write %d %s ret %d", index, wbuff, ret);
  115. // }
  116. // }
  117. if (ret > 0) {
  118. //buff[63] = 0x00; // 确保能结束
  119. lua_pushlstring(L, buff, ret);
  120. }
  121. else
  122. lua_pushnil(L);
  123. return 1;
  124. }
  125. /**
  126. 获取MUID
  127. @api mobile.muid()
  128. @return string 当前的MUID值,若失败返回nil
  129. */
  130. static int l_mobile_muid(lua_State* L) {
  131. char buff[33] = {0};
  132. // size_t len = 0;
  133. // size_t wlen = 0;
  134. int ret = 0;
  135. ret = luat_mobile_get_muid(buff, 32);
  136. if (lua_isstring(L, 1)) {
  137. // const char* wbuff = luaL_checklstring(L, 1, &wlen);
  138. // if (wlen >= 15) {
  139. // ret = luat_mobile_set_muid(index, wbuff, wlen);
  140. // LLOGI("SN write %d %s ret %d", index, wbuff, ret);
  141. // }
  142. }
  143. if (ret > 0) {
  144. lua_pushlstring(L, buff, strlen(buff));
  145. }
  146. else
  147. lua_pushnil(L);
  148. return 1;
  149. }
  150. /**
  151. 获取或设置ICCID
  152. @api mobile.iccid(id)
  153. @int SIM卡的编号, 例如0, 1, 默认0
  154. @return string ICCID值,若失败返回nil
  155. */
  156. static int l_mobile_iccid(lua_State* L) {
  157. char buff[24] = {0};
  158. // size_t len = 0;
  159. // size_t wlen = 0;
  160. int ret = 0;
  161. int index = luaL_optinteger(L, 1, 0);
  162. ret = luat_mobile_get_iccid(index, buff, 24);
  163. if (ret > 0) {
  164. buff[23] = 0x00; // 确保能结束
  165. lua_pushlstring(L, buff, strlen(buff));
  166. }
  167. else
  168. lua_pushnil(L);
  169. return 1;
  170. }
  171. /**
  172. 获取手机卡号,注意,只有写入了手机号才能读出,因此有可能读出来是空的
  173. @api mobile.number(id)
  174. @int SIM卡的编号, 例如0, 1, 默认0
  175. @return string number值,若失败返回nil
  176. */
  177. static int l_mobile_number(lua_State* L) {
  178. char buff[24] = {0};
  179. // size_t len = 0;
  180. // size_t wlen = 0;
  181. int ret = 0;
  182. int index = luaL_optinteger(L, 1, 0);
  183. ret = luat_mobile_get_sim_number(index, buff, 24);
  184. if (ret > 0) {
  185. buff[23] = 0x00; // 确保能结束
  186. lua_pushlstring(L, buff, strlen(buff));
  187. }
  188. else
  189. lua_pushnil(L);
  190. return 1;
  191. }
  192. /**
  193. 获取当前SIM卡槽,或者切换卡槽
  194. @api mobile.simid(id)
  195. @int SIM卡的编号, 例如0, 1, 如果支持双卡,例如Air780EXXX,可以填2来自适应,但是会占用掉4个IO(gpio4/5/6/23)。如果不填就直接读取当前卡槽
  196. @boolean 是否优先用SIM0,只有SIM卡编号写2自适应才有用!!!。true优先用SIM0,false则由具体平台决定,支持双卡双待SIM0优先,不支持的是上一次检测到的优先,默认是false,必须在开机就配置,否则就无效了
  197. @return int 当前sim卡槽编号,若失败返回-1
  198. @usage
  199. mobile.simid(0) -- 固定使用SIM0
  200. mobile.simid(1) -- 固件使用SIM1
  201. mobile.simid(2) -- 自动识别SIM0, SIM1, 优先级看具体平台
  202. mobile.simid(2, true) -- -- 自动识别SIM0, SIM1, 且SIM0优先
  203. -- 提醒, 自动识别是会增加时间的
  204. */
  205. static int l_mobile_simid(lua_State* L) {
  206. // char buff[24] = {0};
  207. int ret = 0;
  208. int id = 0;
  209. if (lua_isinteger(L, 1)) {
  210. id = luaL_checkinteger(L, 1);
  211. ret = luat_mobile_set_sim_id(id);
  212. LLOGI("sim set to %d , ret %d", id, ret);
  213. }
  214. if (LUA_TBOOLEAN == lua_type(L, 2)) {
  215. if (lua_toboolean(L, 2)) {
  216. luat_mobile_set_sim_detect_sim0_first();
  217. }
  218. }
  219. ret = luat_mobile_get_sim_id(&id);
  220. if (ret == 0) {
  221. lua_pushinteger(L, id);
  222. }
  223. else {
  224. lua_pushinteger(L, -1);
  225. }
  226. return 1;
  227. }
  228. /**
  229. 检测当前SIM卡是否准备好,对SIM卡的PIN码做相关操作
  230. @api mobile.simPin(id,operation,pin1,pin2)
  231. @int SIM卡的编号, 例如0, 1, 支持双卡双待的才需要选择
  232. @int PIN码操作类型,只能是mobile.PIN_XXXX,不操作就留空
  233. @string 更换pin时操作的pin码,或者验证操作的pin码,或者解锁pin码时的PUK,4~8字节
  234. @string 更换pin码操作时的新的pin码,解锁pin码时的新PIN,4~8字节
  235. @return boolean 当无PIN操作时,返回SIM卡是否准备好,有PIN操作时,返回是否成功
  236. @usage
  237. local cpin_is_ready = mobile.simPin() -- 当前sim卡是否准备好,一般返回false就是没卡
  238. local succ = mobile.simPin(0, mobile.PIN_VERIFY, "1234") -- 输入pin码验证
  239. */
  240. static int l_mobile_sim_pin(lua_State* L) {
  241. char old[9] = {0};
  242. char new[9] = {0};
  243. int id = luaL_optinteger(L, 1, 0);
  244. int operation = luaL_optinteger(L, 2, -1);
  245. size_t old_len, new_len;
  246. if (lua_isstring(L, 3))
  247. {
  248. const char *old_pin = lua_tolstring(L, 3, &old_len);
  249. memcpy(old, old_pin, (old_len > 8)?8:old_len);
  250. }
  251. if (lua_isstring(L, 4))
  252. {
  253. const char *new_pin = lua_tolstring(L, 4, &new_len);
  254. memcpy(new, new_pin, (new_len > 8)?8:new_len);
  255. }
  256. if (operation != -1)
  257. {
  258. lua_pushboolean(L, (luat_mobile_set_sim_pin(id, operation, old, new) == 0));
  259. }
  260. else
  261. {
  262. lua_pushboolean(L, (luat_mobile_get_sim_ready(id) == 1));
  263. }
  264. return 1;
  265. }
  266. /**
  267. 设置RRC自动释放时间间隔,当开启时后,遇到极弱信号+频繁数据操作可能会引起网络严重故障,因此需要额外设置自动重启协议栈
  268. @api mobile.rtime(time, auto_reset_stack, data_first)
  269. @int RRC自动释放时间,等同于Air724的AT+RTIME,单位秒,写0或者不写则是停用,不要超过20秒,没有意义
  270. @boolean 网络遇到严重故障时尝试自动恢复,和飞行模式/SIM卡切换冲突,true开启,false关闭,留空时,如果设置了时间则自动开启。本参数于2023年9月14日已废弃
  271. @boolean 是否启用数据传输优化,true启用,false关闭,留空为false,开启后必须等到TCP数据ACK或者超时失败,或者socket CONNECT完成(无论成功或者失败)才允许RRC提前释放,可能会增加功耗。本参数于2024年8月12日启用
  272. @return nil 无返回值
  273. @usage
  274. mobile.rtime(3) --与基站无数据交互3秒后提前释放RRC
  275. mobile.rtime(3,nil,true) --启用数据传输优化,与基站无数据交互3秒后,提前释放RRC
  276. */
  277. extern void net_lwip_check_switch(uint8_t onoff);
  278. static int l_mobile_set_rrc_auto_release_time(lua_State* L) {
  279. uint8_t release_time = luaL_optinteger(L, 1, 0);
  280. if (LUA_TBOOLEAN == lua_type(L, 3)) {
  281. net_lwip_check_switch(lua_toboolean(L, 3));
  282. }
  283. uint32_t idle_time = luaL_optinteger(L, 4, 0);
  284. if (idle_time >= 10)
  285. {
  286. luat_mobile_set_auto_rrc(release_time, idle_time);
  287. }
  288. else
  289. {
  290. luat_mobile_set_rrc_auto_release_time(release_time);
  291. }
  292. return 0;
  293. }
  294. /**
  295. 设置一些辅助周期性或者自动功能,目前支持SIM卡暂时脱离后恢复,周期性获取小区信息,网络遇到严重故障时尝试自动恢复
  296. @api mobile.setAuto(check_sim_period, get_cell_period, search_cell_time, auto_reset_stack, network_check_period)
  297. @int SIM卡自动恢复时间,单位毫秒,建议5000~10000,和飞行模式/SIM卡切换冲突,不能再同一时间使用,必须错开执行。写0或者不写则是关闭功能
  298. @int 周期性获取小区信息的时间间隔,单位毫秒。获取小区信息会增加部分功耗。写0或者不写则是关闭功能
  299. @int 每次搜索小区时最大搜索时间,单位秒。不要超过8秒
  300. @boolean 网络遇到严重故障时尝试自动恢复,和飞行模式/SIM卡切换冲突,true开启,false关闭,开始状态是false,留空则不做改变
  301. @int 设置定时检测网络是否正常并且在检测到长时间无网时通过重启协议栈来恢复,无网恢复时长,单位ms,建议60000以上,为网络搜索网络保留足够的时间,留空则不做更改
  302. @return nil 无返回值
  303. */
  304. static int l_mobile_set_auto_work(lua_State* L) {
  305. luat_mobile_set_period_work(luaL_optinteger(L, 2, 0), luaL_optinteger(L, 1, 0), luaL_optinteger(L, 3, 0));
  306. if (LUA_TBOOLEAN == lua_type(L, 4)) {
  307. luat_mobile_fatal_error_auto_reset_stack(lua_toboolean(L, 4));
  308. }
  309. if (lua_isinteger(L, 5)) {
  310. luat_mobile_set_check_network_period(luaL_optinteger(L, 5, 0));
  311. }
  312. return 0;
  313. }
  314. /**
  315. 获取或设置APN,设置APN必须在入网前就设置好,比如在SIM卡识别完成前就设置好
  316. @api mobile.apn(index, cid, new_apn_name, user_name, password, ip_type, protocol, is_del)
  317. @int 编号,默认0. 在支持双卡的模块上才会出现0或1的情况
  318. @int cid, 默认0,如果要用非默认APN来激活,必须>0
  319. @string 新的APN,不填就是获取APN, 填了就是设置APN, 是否支持设置取决于底层实现
  320. @string 新的APN的username,如果APN不是空,那必须填写,如果没有留个空字符串""。如果APN是空的,那可以nil
  321. @string 新的APN的password,如果APN不是空,那必须填写,如果没有留个空字符串""。如果APN是空的,那可以nil
  322. @int 激活APN时的IP TYPE,1=IPV4 2=IPV6 3=IPV4V6,默认是1
  323. @int 激活APN时,如果需要username和password,就要写鉴权协议类型,1~3,默认3,代表1和2都尝试一下。不需要鉴权的写0
  324. @boolean 是否删除APN,true是,其他都否,只有参数3新的APN不是string的时候才有效果
  325. @return string 如果网络注册成功,返回注册用的APN值,反之是nil。设置好不会立刻有返回值,需要等网络注册成功
  326. @usage
  327. -- 注意, 在国内, 公网卡基本上都不需要设置APN, 专网卡才需要设置
  328. mobile.apn(0,1,"cmiot","","",nil,0)
  329. -- 专网卡设置的demo,name,user,password联系卡商获取
  330. -- 设置后, 再次立即获取, 并不会返回设置的值, 要等联网成功 - 设置好不会立刻有返回值,需要等网络注册成功
  331. mobile.apn(0,1,"name","user","password",nil,3)
  332. */
  333. static int l_mobile_apn(lua_State* L) {
  334. char buff[64] = {0};
  335. size_t len = 0;
  336. size_t wlen = 0;
  337. int ret = 0;
  338. int index = luaL_optinteger(L, 1, 0);
  339. int cid = luaL_optinteger(L, 2, 0);
  340. ret = luat_mobile_get_apn(index, cid, buff, sizeof(buff) - 1);
  341. if (lua_isstring(L, 3)) {
  342. const char* wbuff = luaL_checklstring(L, 3, &wlen);
  343. size_t user_name_len = 0;
  344. size_t password_len = 0;
  345. const char* user_name = luaL_checklstring(L, 4, &user_name_len);
  346. const char* password = luaL_checklstring(L, 5, &password_len);
  347. uint8_t ip_type = luaL_optinteger(L, 6, 1);
  348. uint8_t protocol = luaL_optinteger(L, 7, 3);
  349. if (!user_name_len && !password_len)
  350. {
  351. protocol = 0;
  352. }
  353. if (wlen) {
  354. luat_mobile_user_apn_auto_active(index, cid, ip_type, protocol, wbuff, wlen, user_name, user_name_len, password, password_len);
  355. }
  356. else
  357. {
  358. luat_mobile_user_apn_auto_active(index, cid, ip_type, 0xff, NULL, 0, NULL, 0, NULL, 0);
  359. }
  360. }
  361. else
  362. {
  363. if (lua_isboolean(L, 8) && lua_toboolean(L, 8))
  364. {
  365. luat_mobile_del_apn(index, cid, 0);
  366. }
  367. }
  368. if (ret > 0) {
  369. lua_pushlstring(L, buff, strlen(buff));
  370. }
  371. else
  372. lua_pushnil(L);
  373. return 1;
  374. }
  375. /**
  376. 是否默认开启IPV6功能,必须在LTE网络连接前就设置好
  377. @api mobile.ipv6(onff)
  378. @boolean 开关 true开启 false 关闭
  379. @return boolean true 当前是开启的,false 当前是关闭的
  380. @usage
  381. -- 注意, 开启ipv6后, 开机联网会慢2~3秒
  382. */
  383. static int l_mobile_ipv6(lua_State* L) {
  384. // char buff[24] = {0};
  385. // uint8_t onoff;
  386. if (LUA_TBOOLEAN == lua_type(L, 1)) {
  387. luat_mobile_set_default_pdn_ipv6(lua_toboolean(L, 1));
  388. }
  389. lua_pushboolean(L, luat_mobile_get_default_pdn_ipv6());
  390. return 1;
  391. }
  392. /**
  393. 获取csq
  394. @api mobile.csq()
  395. @return int 当前CSQ值, 若失败返回0. 范围 0 - 31, 越大越好
  396. @usage
  397. -- 注意, 4G模块的CSQ值仅供参考, rsrp/rsrq才是真正的信号强度指标
  398. */
  399. static int l_mobile_csq(lua_State* L) {
  400. // luat_mobile_signal_strength_info_t info = {0};
  401. uint8_t csq = 0;
  402. if (luat_mobile_get_signal_strength(&csq) == 0) {
  403. lua_pushinteger(L, (int)csq);
  404. }
  405. else {
  406. lua_pushinteger(L, 0);
  407. }
  408. return 1;
  409. }
  410. /**
  411. 获取rssi
  412. @api mobile.rssi()
  413. @return int 当前rssi值,若失败返回0. 范围 0 到 -114, 越小越好
  414. */
  415. static int l_mobile_rssi(lua_State* L) {
  416. luat_mobile_signal_strength_info_t info = {0};
  417. if (luat_mobile_get_signal_strength_info(&info) == 0) {
  418. lua_pushinteger(L, info.lte_signal_strength.rssi);
  419. }
  420. else {
  421. lua_pushinteger(L, 0);
  422. }
  423. return 1;
  424. }
  425. /**
  426. 获取rsrp,参考信号接收功率
  427. @api mobile.rsrp()
  428. @return int 当前rsrp值,若失败返回0. 取值范围: -44 ~ -140 ,值越大越好
  429. */
  430. static int l_mobile_rsrp(lua_State* L) {
  431. luat_mobile_signal_strength_info_t info = {0};
  432. if (luat_mobile_get_signal_strength_info(&info) == 0) {
  433. lua_pushinteger(L, info.lte_signal_strength.rsrp);
  434. }
  435. else {
  436. lua_pushinteger(L, 0);
  437. }
  438. return 1;
  439. }
  440. /**
  441. 获取rsrq,参考信号发送功率
  442. @api mobile.rsrq()
  443. @return int 当前rsrq值,若失败返回0. 取值范围: -3 ~ -19.5 ,值越大越好
  444. */
  445. static int l_mobile_rsrq(lua_State* L) {
  446. luat_mobile_signal_strength_info_t info = {0};
  447. if (luat_mobile_get_signal_strength_info(&info) == 0) {
  448. lua_pushinteger(L, info.lte_signal_strength.rsrq);
  449. }
  450. else {
  451. lua_pushinteger(L, 0);
  452. }
  453. return 1;
  454. }
  455. /**
  456. 获取snr,信噪比
  457. @api mobile.snr()
  458. @return int 当前snq值,若失败返回0.范围 0 - 30, 越大越好
  459. */
  460. static int l_mobile_snr(lua_State* L) {
  461. luat_mobile_signal_strength_info_t info = {0};
  462. if (luat_mobile_get_signal_strength_info(&info) == 0) {
  463. lua_pushinteger(L, info.lte_signal_strength.snr);
  464. }
  465. else {
  466. lua_pushinteger(L, 0);
  467. }
  468. return 1;
  469. }
  470. /**
  471. 获取当前服务小区的ECI(E-UTRAN Cell Identifier)
  472. @api mobile.eci()
  473. @return int 当前eci值,若失败返回-1
  474. */
  475. static int l_mobile_eci(lua_State* L) {
  476. uint32_t eci;
  477. if (luat_mobile_get_service_cell_identifier(&eci) == 0) {
  478. lua_pushinteger(L, eci);
  479. }
  480. else {
  481. lua_pushinteger(L, -1);
  482. }
  483. return 1;
  484. }
  485. /**
  486. 获取当前服务小区的TAC或者LAC
  487. @api mobile.tac()
  488. @return int 当前eci值,若失败返回-1. 如果尚未注册到网络,会返回0
  489. @usage
  490. -- 本API于 2023.7.9 新增
  491. */
  492. static int l_mobile_tac(lua_State* L) {
  493. uint32_t tac;
  494. if (luat_mobile_get_service_tac_or_lac(&tac) == 0) {
  495. lua_pushinteger(L, tac);
  496. }
  497. else {
  498. lua_pushinteger(L, -1);
  499. }
  500. return 1;
  501. }
  502. /**
  503. 获取当前服务小区的eNBID(eNodeB Identifier)
  504. @api mobile.enbid()
  505. @return int 当前enbid值,若失败返回-1
  506. */
  507. static int l_mobile_enbid(lua_State* L) {
  508. uint32_t eci;
  509. if (luat_mobile_get_service_cell_identifier(&eci) == 0) {
  510. lua_pushinteger(L, eci>>8);
  511. }
  512. else {
  513. lua_pushinteger(L, -1);
  514. }
  515. return 1;
  516. }
  517. static inline uint16_t u162bcd(uint16_t src) {
  518. uint8_t high = (src >> 8) & 0xFF;
  519. uint8_t low = src & 0xFF;
  520. uint16_t dst = 0;
  521. dst += (low & 0x0F) + (low >> 4) * 10;
  522. dst += ((high & 0x0F) + (high >> 4) * 10) * 100;
  523. //LLOGD("src %04X dst %d", src, dst);
  524. return dst;
  525. }
  526. /**
  527. 获取当前服务小区更详细的信息
  528. @api mobile.scell()
  529. @return table 服务小区的信息
  530. @usage
  531. -- 本API于 2024.9.12 新增
  532. log.info("cell", json.encode(mobile.scell()))
  533. -- 返回值示例
  534. {
  535. "mnc": 11,
  536. "mcc": 460,
  537. "rssi": -78,
  538. "pci": 115,
  539. "rsrp": -107,
  540. "tac": 30005,
  541. "eci": 124045360,
  542. "cid": 124045360,
  543. "rsrq": -9,
  544. "snr": 15,
  545. "earfcn": 1850
  546. }
  547. */
  548. static int l_mobile_scell_extern_info(lua_State* L) {
  549. luat_mobile_scell_extern_info_t info = {0};
  550. int ret = 0;
  551. ret = luat_mobile_get_extern_service_cell_info(&info);
  552. if (ret) {
  553. return 0;
  554. }
  555. lua_newtable(L);
  556. // 驻网信息相关
  557. lua_pushinteger(L, u162bcd(info.mcc));
  558. lua_setfield(L, -2, "mcc");
  559. lua_pushinteger(L, u162bcd(info.mnc));
  560. lua_setfield(L, -2, "mnc");
  561. lua_pushinteger(L, info.earfcn);
  562. lua_setfield(L, -2, "earfcn");
  563. lua_pushinteger(L, info.pci);
  564. lua_setfield(L, -2, "pci");
  565. // 基站相关
  566. uint32_t eci = 0;
  567. uint32_t tac = 0;
  568. luat_mobile_get_service_cell_identifier(&eci);
  569. lua_pushinteger(L, eci);
  570. lua_setfield(L, -2, "eci");
  571. lua_pushinteger(L, eci);
  572. lua_setfield(L, -2, "cid");
  573. luat_mobile_get_service_tac_or_lac(&tac);
  574. lua_pushinteger(L, tac);
  575. lua_setfield(L, -2, "tac");
  576. // 信号强度相关的值
  577. luat_mobile_signal_strength_info_t sinfo = {0};
  578. luat_mobile_get_signal_strength_info(&sinfo);
  579. lua_pushinteger(L, sinfo.lte_signal_strength.snr);
  580. lua_setfield(L, -2, "snr");
  581. lua_pushinteger(L, sinfo.lte_signal_strength.rsrp);
  582. lua_setfield(L, -2, "rsrp");
  583. lua_pushinteger(L, sinfo.lte_signal_strength.rsrq);
  584. lua_setfield(L, -2, "rsrq");
  585. lua_pushinteger(L, sinfo.lte_signal_strength.rssi);
  586. lua_setfield(L, -2, "rssi");
  587. return 1;
  588. }
  589. /**
  590. 进出飞行模式
  591. @api mobile.flymode(index, enable)
  592. @int 编号,默认0. 在支持双卡的模块上才会出现0或1的情况
  593. @bool 是否设置为飞行模式,true为设置, false为退出,可选
  594. @return bool 原飞行模式的状态
  595. */
  596. static int l_mobile_flymode(lua_State* L) {
  597. int index = luaL_optinteger(L, 1, 0);
  598. int flymode = luat_mobile_get_flymode(index);
  599. if (lua_isboolean(L, 2)) {
  600. luat_mobile_set_flymode(index, lua_toboolean(L, 2));
  601. }
  602. lua_pushboolean(L, flymode == 0 ? 0 : 1);
  603. return 1;
  604. }
  605. /**
  606. 配置基站同步时间开关,默认开启
  607. @api mobile.syncTime(enable)
  608. @bool 开启,true开启, false关闭, nil不设置
  609. @return bool 当前开关状态
  610. @usage
  611. mobile.syncTime() --获取当前开关状态
  612. mobile.syncTime(false) --关闭基站同步时间
  613. */
  614. static int l_mobile_sync_time(lua_State* L) {
  615. if (lua_isboolean(L, 1)) {
  616. luat_mobile_set_sync_time(lua_toboolean(L, 1));
  617. }
  618. lua_pushboolean(L, luat_mobile_get_sync_time());
  619. return 1;
  620. }
  621. /**
  622. 获取网络状态
  623. @api mobile.status()
  624. @return int 当前网络状态
  625. @usage
  626. -- 状态描述
  627. -- 0:网络未注册
  628. -- 1:网络已注册
  629. -- 2:正在搜网中
  630. -- 3:网络注册被拒绝
  631. -- 4:网络状态未知
  632. -- 5:漫游,且已注册
  633. -- 6:仅SMS可用
  634. -- 7:仅SMS可用,且漫游状态
  635. -- 8:仅紧急呼叫. 注意, 国内不支持此状态,模块也不支持紧急呼叫
  636. -- 不推荐使用本API判断联网状态, 建议使用socket.localIP()来判断
  637. */
  638. static int l_mobile_status(lua_State* L) {
  639. int LUAT_MOBILE_REGISTER_STATUS_E = luat_mobile_get_register_status();
  640. lua_pushinteger(L, LUAT_MOBILE_REGISTER_STATUS_E);
  641. return 1;
  642. }
  643. /**
  644. 获取基站信息
  645. @api mobile.getCellInfo()
  646. @return table 包含基站数据的数组
  647. @usage
  648. -- 注意: 从2023.06.20开始, 需要主动请求一次reqCellInfo才会有基站数据.
  649. --示例输出(原始数据是table, 下面是json格式化后的内容)
  650. --[[
  651. [
  652. {"rsrq":-10,"rssi":-55,"cid":124045360,"mnc":17,"pci":115,"earfcn":1850,"snr":15,"rsrp":-85,"mcc":1120,"tdd":0},
  653. {"pci":388,"rsrq":-11,"mnc":17,"earfcn":2452,"snr":5,"rsrp":-67,"mcc":1120,"cid":124045331},
  654. {"pci":100,"rsrq":-9,"mnc":17,"earfcn":75,"snr":17,"rsrp":-109,"mcc":1120,"cid":227096712}
  655. ]
  656. ]]
  657. mobile.reqCellInfo(60)
  658. -- 订阅
  659. sys.subscribe("CELL_INFO_UPDATE", function()
  660. log.info("cell", json.encode(mobile.getCellInfo()))
  661. end)
  662. -- 定期轮训式
  663. sys.taskInit(function()
  664. sys.wait(3000)
  665. while 1 do
  666. mobile.reqCellInfo(15)
  667. sys.waitUntil("CELL_INFO_UPDATE", 15000)
  668. log.info("cell", json.encode(mobile.getCellInfo()))
  669. end
  670. end)
  671. */
  672. static int l_mobile_get_cell_info(lua_State* L) {
  673. lua_newtable(L);
  674. luat_mobile_cell_info_t* info = luat_heap_malloc(sizeof(luat_mobile_cell_info_t));
  675. if (info == NULL) {
  676. LLOGE("out of memory when malloc cell_info");
  677. return 1;
  678. }
  679. int ret = luat_mobile_get_last_notify_cell_info(info);
  680. if (ret != 0) {
  681. LLOGI("none cell info found %d", ret);
  682. goto exit;
  683. }
  684. //LLOGD("cid %d neighbor %d", info->lte_service_info.cid, info->lte_neighbor_info_num);
  685. // 当前仅返回lte信息
  686. if (info->lte_info_valid == 0 || info->lte_service_info.cid == 0) {
  687. if (0 == luat_mobile_get_service_cell_identifier(&info->lte_service_info.cid) && info->lte_service_info.cid) {
  688. LLOGW("请先调用 mobile.reqCellInfo()!!");
  689. }
  690. else {
  691. LLOGI("lte cell info not found");
  692. }
  693. goto exit;
  694. }
  695. lua_newtable(L);
  696. lua_pushinteger(L, info->lte_service_info.pci);
  697. lua_setfield(L, -2, "pci");
  698. lua_pushinteger(L, info->lte_service_info.cid);
  699. lua_setfield(L, -2, "cid");
  700. lua_pushinteger(L, info->lte_service_info.earfcn);
  701. lua_setfield(L, -2, "earfcn");
  702. lua_pushinteger(L, info->lte_service_info.rsrp);
  703. lua_setfield(L, -2, "rsrp");
  704. lua_pushinteger(L, info->lte_service_info.rsrq);
  705. lua_setfield(L, -2, "rsrq");
  706. lua_pushinteger(L, info->lte_service_info.rssi);
  707. lua_setfield(L, -2, "rssi");
  708. lua_pushinteger(L, info->lte_service_info.is_tdd);
  709. lua_setfield(L, -2, "tdd");
  710. lua_pushinteger(L, info->lte_service_info.snr);
  711. lua_setfield(L, -2, "snr");
  712. lua_pushinteger(L, u162bcd(info->lte_service_info.mcc));
  713. lua_setfield(L, -2, "mcc");
  714. lua_pushinteger(L, u162bcd(info->lte_service_info.mnc));
  715. lua_setfield(L, -2, "mnc");
  716. lua_pushinteger(L, info->lte_service_info.tac);
  717. lua_setfield(L, -2, "tac");
  718. lua_pushinteger(L, info->lte_service_info.band);
  719. lua_setfield(L, -2, "band");
  720. lua_pushinteger(L, info->lte_service_info.ulbandwidth);
  721. lua_setfield(L, -2, "ulbandwidth");
  722. lua_pushinteger(L, info->lte_service_info.dlbandwidth);
  723. lua_setfield(L, -2, "dlbandwidth");
  724. lua_seti(L, -2, 1);
  725. if (info->lte_neighbor_info_num > 0) {
  726. for (size_t i = 0; i < info->lte_neighbor_info_num; i++)
  727. {
  728. lua_settop(L, 1);
  729. //LLOGD("add neighbor %d", i);
  730. lua_newtable(L);
  731. lua_pushinteger(L, info->lte_info[i].pci);
  732. lua_setfield(L, -2, "pci");
  733. lua_pushinteger(L, info->lte_info[i].cid);
  734. lua_setfield(L, -2, "cid");
  735. if (0x8850 == info->version)
  736. {
  737. lua_pushinteger(L, info->lte_info[i].rssi);
  738. lua_setfield(L, -2, "rssi");
  739. lua_pushinteger(L, info->lte_info[i].celltype);
  740. lua_setfield(L, -2, "celltype");
  741. lua_pushinteger(L, info->lte_info[i].bandwidth);
  742. lua_setfield(L, -2, "bandwidth");
  743. }
  744. lua_pushinteger(L, info->lte_info[i].earfcn);
  745. lua_setfield(L, -2, "earfcn");
  746. lua_pushinteger(L, info->lte_info[i].rsrp);
  747. lua_setfield(L, -2, "rsrp");
  748. lua_pushinteger(L, info->lte_info[i].rsrq);
  749. lua_setfield(L, -2, "rsrq");
  750. lua_pushinteger(L, u162bcd(info->lte_info[i].mcc));
  751. lua_setfield(L, -2, "mcc");
  752. lua_pushinteger(L, u162bcd(info->lte_info[i].mnc));
  753. lua_setfield(L, -2, "mnc");
  754. lua_pushinteger(L, info->lte_info[i].snr);
  755. lua_setfield(L, -2, "snr");
  756. lua_pushinteger(L, info->lte_info[i].tac);
  757. lua_setfield(L, -2, "tac");
  758. lua_seti(L, -2, i + 2);
  759. }
  760. }
  761. lua_settop(L, 1);
  762. exit:
  763. luat_heap_free(info);
  764. return 1;
  765. }
  766. /**
  767. 发起基站信息查询,含临近小区
  768. @api mobile.reqCellInfo(timeout)
  769. @int 超时时长,单位秒,默认15. 最少5, 最高60
  770. @return nil 无返回值
  771. @usage
  772. -- 参考 mobile.getCellInfo 函数
  773. */
  774. static int l_mobile_request_cell_info(lua_State* L) {
  775. int timeout = luaL_optinteger(L, 1, 15);
  776. if (timeout > 60)
  777. timeout = 60;
  778. else if (timeout < 5)
  779. timeout = 5;
  780. luat_mobile_get_cell_info_async(timeout);
  781. return 0;
  782. }
  783. /**
  784. 锁定/解锁小区,仅用于外场测试,没接触过的,或者生产环境中请勿使用
  785. @api mobile.lockCell(mode, earfcn, pci)
  786. @int 操作码 0删除优先的频点,1设置优先频点,2锁定小区,3解锁小区
  787. @int 下行频点
  788. @int phycellid
  789. @return bool 成功true 失败false
  790. @usage
  791. mobile.lockCell(2,1860,32) --锁定小区
  792. mobile.lockCell(3) --解锁小区
  793. */
  794. static int l_mobile_lock_cell(lua_State* L) {
  795. lua_pushboolean(L, !luat_mobile_lock_cell(luaL_optinteger(L, 1, 4), luaL_optinteger(L, 2, 0), luaL_optinteger(L, 3, 0)));
  796. return 1;
  797. }
  798. /**
  799. 重启协议栈
  800. @api mobile.reset()
  801. @return nil 无返回值
  802. @usage
  803. -- 重启LTE协议栈
  804. mobile.reset()
  805. */
  806. static int l_mobile_reset(lua_State* L) {
  807. luat_mobile_reset_stack();
  808. return 0;
  809. }
  810. /**
  811. 数据量流量处理
  812. @api mobile.dataTraffic(clearUplink, clearDownlink)
  813. @boolean 清空上行流量累计值,true清空,其他忽略
  814. @boolean 清空下行流量累计值,true清空,其他忽略
  815. @return int 上行流量GB
  816. @return int 上行流量B
  817. @return int 下行流量GB
  818. @return int 下行流量B
  819. @usage
  820. -- 获取上下行流量累计值
  821. -- 上行流量值Byte = uplinkGB * 1024 * 1024 * 1024 + uplinkB
  822. -- 下行流量值Byte = downlinkGB * 1024 * 1024 * 1024 + downlinkB
  823. local uplinkGB, uplinkB, downlinkGB, downlinkB = mobile.dataTraffic()
  824. -- 清空上下行流量累计值
  825. mobile.dataTraffic(true, true)
  826. -- 仅记录开机后的流量,复位/重启会归零
  827. */
  828. static int l_mobile_data_traffic(lua_State* L) {
  829. uint64_t uplink;
  830. uint64_t downlink;
  831. uint8_t clear_uplink = 0;
  832. uint8_t clear_downlink = 0;
  833. volatile uint32_t temp;
  834. if (LUA_TBOOLEAN == lua_type(L, 1)) {
  835. clear_uplink = lua_toboolean(L, 1);
  836. }
  837. if (LUA_TBOOLEAN == lua_type(L, 2)) {
  838. clear_downlink = lua_toboolean(L, 2);
  839. }
  840. luat_mobile_get_ip_data_traffic(&uplink, &downlink);
  841. if (clear_uplink || clear_downlink) {
  842. luat_mobile_clear_ip_data_traffic(clear_uplink, clear_downlink);
  843. }
  844. temp = (uint32_t)(uplink >> 30);
  845. lua_pushinteger(L, temp);
  846. temp = (((uint32_t)uplink) & 0x3FFFFFFF);
  847. lua_pushinteger(L, temp);
  848. temp = (uint32_t)(downlink >> 30);
  849. lua_pushinteger(L, temp);
  850. temp = (((uint32_t)downlink) & 0x3FFFFFFF);
  851. lua_pushinteger(L, temp);
  852. return 4;
  853. }
  854. /**
  855. 网络特殊配置
  856. @api mobile.config(item, value)
  857. @int 配置项目,看mobile.CONF_XXX
  858. @int 配置值,根据具体配置的item决定
  859. @return boolean 是否成功
  860. @usage
  861. --针对不同平台有不同的配置,谨慎使用,目前只有Air780EXXX系列支持
  862. -- Air780EXXX配置小区重选信号差值门限,不能大于15dbm,必须在飞行模式下才能用
  863. mobile.flymode(0,true)
  864. mobile.config(mobile.CONF_RESELTOWEAKNCELL, 15)
  865. mobile.config(mobile.CONF_STATICCONFIG, 1) --开启网络静态优化
  866. mobile.flymode(0,false)
  867. -- Air780EXXX设置SIM写入次数的统计
  868. -- 关闭统计
  869. mobile.config(mobile.CONF_SIM_WC_MODE, 0)
  870. -- 开启统计, 默认也是开启的.
  871. mobile.config(mobile.CONF_SIM_WC_MODE, 1)
  872. -- 读取统计值,异步, 需要通过系统消息SIM_IND获取
  873. sys.subscribe("SIM_IND", function(stats, value)
  874. log.info("SIM_IND", stats)
  875. if stats == "SIM_WC" then
  876. log.info("sim", "write counter", value)
  877. end
  878. end)
  879. mobile.config(mobile.CONF_SIM_WC_MODE, 2)
  880. -- 清空统计值
  881. mobile.config(mobile.CONF_SIM_WC_MODE, 3)
  882. */
  883. static int l_mobile_config(lua_State* L) {
  884. uint8_t item = luaL_optinteger(L, 1, 0);
  885. uint32_t value = luaL_optinteger(L, 2, 0);
  886. if (!item)
  887. {
  888. lua_pushboolean(L, 0);
  889. }
  890. else
  891. {
  892. lua_pushboolean(L, !luat_mobile_config(item, value));
  893. }
  894. return 1;
  895. }
  896. #include "luat_uart.h"
  897. #include "luat_zbuff.h"
  898. /**
  899. 获取当前使用/支持的band
  900. @api mobile.getBand(band, is_default)
  901. @zbuff 输出band
  902. @boolean true默认支持,false当前支持的,默认是false,当前是预留功能,不要写true
  903. @return boolean 成功返回true,失败放回false
  904. @usage
  905. local buff = zbuff.create(40)
  906. mobile.getBand(buff) --输出当前使用的band,band号放在buff内,buff[0],buff[1],buff[2] .. buff[buff:used() - 1]
  907. */
  908. static int l_mobile_get_band(lua_State* L) {
  909. luat_zbuff_t *buff = ((luat_zbuff_t *)luaL_checkudata(L, 1, LUAT_ZBUFF_TYPE));
  910. uint8_t total_num;
  911. int re;
  912. if (buff->len < 40)
  913. {
  914. __zbuff_resize(buff, 40);
  915. }
  916. if (lua_isboolean(L, 2) && lua_toboolean(L, 2))
  917. {
  918. re = luat_mobile_get_support_band(buff->addr, &total_num);
  919. }
  920. else
  921. {
  922. re = luat_mobile_get_band(buff->addr, &total_num);
  923. }
  924. buff->used = total_num;
  925. lua_pushboolean(L, !re);
  926. return 1;
  927. }
  928. /**
  929. 设置使用的band
  930. @api mobile.setBand(band, num)
  931. @zbuff 输入使用的band
  932. @int band数量
  933. @return boolean 成功返回true,失败放回false
  934. @usage
  935. local buff = zbuff.create(40)
  936. buff[0] = 3
  937. buff[1] = 5
  938. buff[2] = 8
  939. buff[3] = 40
  940. mobile.setBand(buff, 4) --设置使用的band一共4个,为3,5,8,40
  941. */
  942. static int l_mobile_set_band(lua_State* L) {
  943. luat_zbuff_t *buff = ((luat_zbuff_t *)luaL_checkudata(L, 1, LUAT_ZBUFF_TYPE));
  944. int num = luaL_optinteger(L, 2, 1);
  945. lua_pushboolean(L, !luat_mobile_set_band(buff->addr, num));
  946. return 1;
  947. }
  948. /**
  949. RF测试开关和配置
  950. @api mobile.nstOnOff(onoff, uart_id)
  951. @boolean true开启测试模式,false关闭
  952. @int 串口号
  953. @return nil 无返回值
  954. @usage
  955. mobile.nstOnOff(true, uart.VUART_0) --打开测试模式,并且用虚拟串口发送结果
  956. mobile.nstOnOff(false) --关闭测试模式
  957. */
  958. static int l_mobile_nst_test_onoff(lua_State* L) {
  959. luat_mobile_rf_test_mode(luaL_optinteger(L, 2, LUAT_VUART_ID_0), lua_toboolean(L, 1));
  960. return 0;
  961. }
  962. /**
  963. RF测试数据输入
  964. @api mobile.nstInput(data)
  965. @string or zbuff 用户从串口获取的数据,注意,当获取完所有数据后,需要再传一个nil来作为传输结束
  966. @return nil 无返回值
  967. @usage
  968. mobile.nstInput(uart_data)
  969. mobile.nstInput(nil)
  970. */
  971. static int l_mobile_nst_data_input(lua_State* L) {
  972. size_t len = 0;
  973. const char *buf = NULL;
  974. if(lua_isuserdata(L, 1))
  975. {
  976. luat_zbuff_t *buff = ((luat_zbuff_t *)luaL_checkudata(L, 1, LUAT_ZBUFF_TYPE));
  977. len = buff->used;
  978. buf = buff->addr;
  979. }
  980. else if (lua_isstring(L, 1))
  981. {
  982. buf = lua_tolstring(L, 1, &len);//取出字符串数据
  983. }
  984. luat_mobile_rf_test_input(buf, len);
  985. return 0;
  986. }
  987. /**
  988. 初始化内置默认虚拟卡功能(不可用)
  989. @api mobile.vsimInit()
  990. @return nil 无返回值
  991. @usage
  992. mobile.vsimInit()
  993. */
  994. static int l_mobile_init_vsim(lua_State* L) {
  995. luat_mobile_softsim_init_default();
  996. return 0;
  997. }
  998. /**
  999. 切换内置虚拟卡和外置实体卡,2024年8月13日启用,虚拟卡需要固件支持,否则切换后无网络,需要在飞行模式下切换,或者切换后重启协议栈
  1000. @api mobile.vsimOnOff(enable)
  1001. @bool 开启,true开启, false关闭
  1002. @return nil 无返回值
  1003. @usage
  1004. mobile.vsimOnOff(true) --使用内置虚拟卡
  1005. mobile.vsimOnOff(false) --使用外置实体卡
  1006. */
  1007. static int l_mobile_vsim_onoff(lua_State* L) {
  1008. if (lua_isboolean(L, 1)) {
  1009. luat_mobile_softsim_onoff(lua_toboolean(L, 1));
  1010. }
  1011. return 0;
  1012. }
  1013. /**
  1014. 初始化自定义APN列表,主要用于海外SIM卡
  1015. @api mobile.apnTableInit()
  1016. @return nil 无返回值
  1017. @usage
  1018. mobile.apnTableInit()
  1019. */
  1020. static int l_mobile_init_apn_table(lua_State* L) {
  1021. luat_mobile_init_auto_apn_by_plmn();
  1022. return 0;
  1023. }
  1024. /**
  1025. 往自定义APN列表添加一条APN信息,主要用于海外SIM卡
  1026. @api mobile.apnTableAdd(mcc, mnc, ip_type, protocol, apn_name, user_name, password)
  1027. @int MCC码,16进制BCD码
  1028. @int MNC码,16进制BCD码
  1029. @int 激活APN时的IP TYPE,1=IPV4 2=IPV6 3=IPV4V6,默认是1
  1030. @int 激活APN时,如果需要username和password,就要写鉴权协议类型,1~3,默认3,代表1和2都尝试一下。不需要鉴权的写0
  1031. @string APN name,不能为空
  1032. @string APN的username
  1033. @string APN的password
  1034. @return nil 无返回值
  1035. @usage
  1036. mobile.apnTableInit() -- 先初始化,必须放在SIM卡识别完成前加入,最好就是写在开头
  1037. mobile.apnTableAdd(0x460,0x00,3,0,"cmiot","","") -- 单独添加一条APN信息,必须放在SIM卡识别完成前加入,最好就是写在开头,移动公网卡设置APN为cmiot(一般不用设置,这里只是举个例子)
  1038. */
  1039. static int l_mobile_add_apn_table(lua_State* L) {
  1040. size_t name_len = 0;
  1041. size_t user_len = 0;
  1042. size_t password_len = 0;
  1043. uint16_t mcc = luaL_optinteger(L, 1, 0x460);
  1044. uint16_t mnc = luaL_optinteger(L, 2, 0);
  1045. uint8_t ip_type = luaL_optinteger(L, 3, 3);
  1046. uint8_t protocol = luaL_optinteger(L, 4, 3);
  1047. const char* name = luaL_checklstring(L, 5, &name_len);
  1048. const char* user = luaL_optlstring(L, 6, "", &user_len);
  1049. const char* password = luaL_optlstring(L, 7, "", &password_len);
  1050. luat_mobile_add_auto_apn_item(mcc, mnc, ip_type, protocol, name, name_len, user, user_len, password, password_len, 1);
  1051. return 0;
  1052. }
  1053. /**
  1054. 打印自定义APN列表里的一条信息,在没有拿到卡的情况下,测试一下对应的APN信息是否和运营商提供的匹配
  1055. @api mobile.apnTablePrint(mcc, mnc)
  1056. @int MCC码,16进制BCD码
  1057. @int MNC码,16进制BCD码
  1058. @return nil 无返回值
  1059. @usage
  1060. mobile.apnTableInit()
  1061. mobile.apnTablePrint(0x202, 0x01)
  1062. */
  1063. static int l_mobile_print_apn_table(lua_State* L) {
  1064. uint16_t mcc = luaL_optinteger(L, 1, 0x460);
  1065. uint16_t mnc = luaL_optinteger(L, 2, 0);
  1066. luat_mobile_print_apn_by_mcc_mnc(mcc, mnc);
  1067. return 0;
  1068. }
  1069. #include "rotable2.h"
  1070. static const rotable_Reg_t reg_mobile[] = {
  1071. {"status", ROREG_FUNC(l_mobile_status)},
  1072. {"imei", ROREG_FUNC(l_mobile_imei)},
  1073. {"imsi", ROREG_FUNC(l_mobile_imsi)},
  1074. {"sn", ROREG_FUNC(l_mobile_sn)},
  1075. {"iccid", ROREG_FUNC(l_mobile_iccid)},
  1076. {"number", ROREG_FUNC(l_mobile_number)},
  1077. {"muid", ROREG_FUNC(l_mobile_muid)},
  1078. {"apn", ROREG_FUNC(l_mobile_apn)},
  1079. {"ipv6", ROREG_FUNC(l_mobile_ipv6)},
  1080. {"csq", ROREG_FUNC(l_mobile_csq)},
  1081. {"rssi", ROREG_FUNC(l_mobile_rssi)},
  1082. {"rsrq", ROREG_FUNC(l_mobile_rsrq)},
  1083. {"rsrp", ROREG_FUNC(l_mobile_rsrp)},
  1084. {"snr", ROREG_FUNC(l_mobile_snr)},
  1085. {"eci", ROREG_FUNC(l_mobile_eci)},
  1086. {"tac", ROREG_FUNC(l_mobile_tac)},
  1087. {"scell", ROREG_FUNC(l_mobile_scell_extern_info)},
  1088. {"enbid", ROREG_FUNC(l_mobile_enbid)},
  1089. {"flymode", ROREG_FUNC(l_mobile_flymode)},
  1090. {"simid", ROREG_FUNC(l_mobile_simid)},
  1091. {"simPin", ROREG_FUNC(l_mobile_sim_pin)},
  1092. {"rtime", ROREG_FUNC(l_mobile_set_rrc_auto_release_time)},
  1093. {"setAuto", ROREG_FUNC(l_mobile_set_auto_work)},
  1094. {"getCellInfo", ROREG_FUNC(l_mobile_get_cell_info)},
  1095. {"reqCellInfo", ROREG_FUNC(l_mobile_request_cell_info)},
  1096. {"lockCell", ROREG_FUNC(l_mobile_lock_cell)},
  1097. {"reset", ROREG_FUNC(l_mobile_reset)},
  1098. {"dataTraffic", ROREG_FUNC(l_mobile_data_traffic)},
  1099. {"config", ROREG_FUNC(l_mobile_config)},
  1100. {"getBand", ROREG_FUNC(l_mobile_get_band)},
  1101. {"setBand", ROREG_FUNC(l_mobile_set_band)},
  1102. {"nstOnOff", ROREG_FUNC(l_mobile_nst_test_onoff)},
  1103. {"nstInput", ROREG_FUNC(l_mobile_nst_data_input)},
  1104. {"syncTime", ROREG_FUNC(l_mobile_sync_time)},
  1105. {"vsimInit", ROREG_FUNC(l_mobile_init_vsim)},
  1106. {"vsimOnOff", ROREG_FUNC(l_mobile_vsim_onoff)},
  1107. {"apnTableInit", ROREG_FUNC(l_mobile_init_apn_table)},
  1108. {"apnTableAdd", ROREG_FUNC(l_mobile_add_apn_table)},
  1109. {"apnTablePrint", ROREG_FUNC(l_mobile_print_apn_table)},
  1110. //@const UNREGISTER number 未注册
  1111. {"UNREGISTER", ROREG_INT(LUAT_MOBILE_STATUS_UNREGISTER)},
  1112. //@const REGISTERED number 已注册
  1113. {"REGISTERED", ROREG_INT(LUAT_MOBILE_STATUS_REGISTERED)},
  1114. //@const SEARCH number 正在搜索中
  1115. {"SEARCH", ROREG_INT(LUAT_MOBILE_STATUS_SEARCHING)},
  1116. //@const DENIED number 注册被拒绝
  1117. {"DENIED", ROREG_INT(LUAT_MOBILE_STATUS_DENIED)},
  1118. //@const UNKNOW number 未知
  1119. {"UNKNOW", ROREG_INT(LUAT_MOBILE_STATUS_UNKNOW)},
  1120. //@const REGISTERED_ROAMING number 已注册,漫游
  1121. {"REGISTERED_ROAMING", ROREG_INT(LUAT_MOBILE_STATUS_REGISTERED_ROAMING)},
  1122. //@const SMS_ONLY_REGISTERED number 已注册,仅SMS
  1123. {"SMS_ONLY_REGISTERED", ROREG_INT(LUAT_MOBILE_STATUS_SMS_ONLY_REGISTERED)},
  1124. //@const SMS_ONLY_REGISTERED_ROAMING number 已注册,漫游,仅SMS
  1125. {"SMS_ONLY_REGISTERED_ROAMING", ROREG_INT(LUAT_MOBILE_STATUS_SMS_ONLY_REGISTERED_ROAMING)},
  1126. //@const EMERGENCY_REGISTERED number 已注册,紧急服务
  1127. {"EMERGENCY_REGISTERED", ROREG_INT(LUAT_MOBILE_STATUS_EMERGENCY_REGISTERED)},
  1128. //@const CSFB_NOT_PREFERRED_REGISTERED number 已注册,非主要服务
  1129. {"CSFB_NOT_PREFERRED_REGISTERED", ROREG_INT(LUAT_MOBILE_STATUS_CSFB_NOT_PREFERRED_REGISTERED)},
  1130. //@const CSFB_NOT_PREFERRED_REGISTERED_ROAMING number 已注册,非主要服务,漫游
  1131. {"CSFB_NOT_PREFERRED_REGISTERED_ROAMING", ROREG_INT(LUAT_MOBILE_STATUS_CSFB_NOT_PREFERRED_REGISTERED_ROAMING)},
  1132. //@const CONF_RESELTOWEAKNCELL number 小区重选信号差值门限,需要飞行模式设置
  1133. {"CONF_RESELTOWEAKNCELL", ROREG_INT(MOBILE_CONF_RESELTOWEAKNCELL)},
  1134. //@const CONF_STATICCONFIG number 网络静态模式优化,需要飞行模式设置
  1135. {"CONF_STATICCONFIG", ROREG_INT(MOBILE_CONF_STATICCONFIG)},
  1136. //@const CONF_QUALITYFIRST number 网络切换以信号质量优先,需要飞行模式设置,0不开,1开启,2开启并加速切换,功耗会增加
  1137. {"CONF_QUALITYFIRST", ROREG_INT(MOBILE_CONF_QUALITYFIRST)},
  1138. //@const CONF_USERDRXCYCLE number LTE跳paging,需要飞行模式设置,谨慎使用,0是不设置,1~7增大或减小DrxCycle周期倍数,1:1/8倍 2:1/4倍 3:1/2倍 4:2倍 5:4倍 6:8倍 7:16倍,8~12配置固定的DrxCycle周期,仅当该周期大于网络分配的DrxCycle周期时该配置才会生效,8:320ms 9:640ms 10:1280ms 11:2560ms 12:5120ms
  1139. {"CONF_USERDRXCYCLE", ROREG_INT(MOBILE_CONF_USERDRXCYCLE)},
  1140. //@const CONF_T3324MAXVALUE number PSM模式中的T3324时间,单位S
  1141. {"CONF_T3324MAXVALUE", ROREG_INT(MOBILE_CONF_T3324MAXVALUE)},
  1142. //@const CONF_PSM_MODE number PSM模式开关,0关,1开
  1143. {"CONF_PSM_MODE", ROREG_INT(MOBILE_CONF_PSM_MODE)},
  1144. //@const CONF_CE_MODE number attach模式,0为EPS ONLY 2为混合,遇到IMSI detach脱网问题,设置为0,注意设置为EPS ONLY时会取消短信功能
  1145. {"CONF_CE_MODE", ROREG_INT(MOBILE_CONF_CE_MODE)},
  1146. //@const CONF_SIM_WC_MODE number SIM写入次数的配置和读取
  1147. {"CONF_SIM_WC_MODE", ROREG_INT(MOBILE_CONF_SIM_WC_MODE)},
  1148. //@const CONF_FAKE_CELL_BARTIME number 伪基站禁止接入的时间,取值为0时取消,0xffff永久
  1149. {"CONF_FAKE_CELL_BARTIME", ROREG_INT(MOBILE_CONF_FAKE_CELL_BARTIME)},
  1150. //@const CONF_RESET_TO_FACTORY number 删除已保存的协议栈参数,重启后会使用默认配置
  1151. {"CONF_RESET_TO_FACTORY", ROREG_INT(MOBILE_CONF_RESET_TO_FACTORY)},
  1152. //@const CONF_USB_ETHERNET number 蜂窝网络模块的usb以太网卡控制,bit0开关1,开0关,bit1模式1NAT,0独立IP(在usb以太网卡开启前可以修改,开启过就不行),bit2协议1ECM,0RNDIS,飞行模式里设置
  1153. {"CONF_USB_ETHERNET", ROREG_INT(MOBILE_CONF_USB_ETHERNET)},
  1154. //@const CONF_DISABLE_NCELL_MEAS number 关闭邻区测量 1关,0开,除了功耗测试外不建议使用
  1155. {"CONF_DISABLE_NCELL_MEAS", ROREG_INT(MOBILE_CONF_DISABLE_NCELL_MEAS)},
  1156. //@const CONF_MAX_TX_POWER number 设置最大发射功率,0~23,必须在每次RRC=1时调用,RRC=0后会自动清除配置
  1157. {"CONF_MAX_TX_POWER", ROREG_INT(MOBILE_CONF_MAX_TX_POWER)},
  1158. //@const PIN_VERIFY number 验证PIN码操作
  1159. {"PIN_VERIFY", ROREG_INT(LUAT_SIM_PIN_VERIFY)},
  1160. //@const PIN_CHANGE number 更换PIN码操作
  1161. {"PIN_CHANGE", ROREG_INT(LUAT_SIM_PIN_CHANGE)},
  1162. //@const PIN_ENABLE number 使能PIN码验证
  1163. {"PIN_ENABLE", ROREG_INT(LUAT_SIM_PIN_ENABLE)},
  1164. //@const PIN_DISABLE number 关闭PIN码验证
  1165. {"PIN_DISABLE", ROREG_INT(LUAT_SIM_PIN_DISABLE)},
  1166. //@const PIN_UNBLOCK number 解锁PIN码
  1167. {"PIN_UNBLOCK", ROREG_INT(LUAT_SIM_PIN_UNBLOCK)},
  1168. {NULL, ROREG_INT(0)}
  1169. };
  1170. LUAMOD_API int luaopen_mobile( lua_State *L ) {
  1171. luat_newlib2(L, reg_mobile);
  1172. return 1;
  1173. }
  1174. static int l_mobile_event_handle(lua_State* L, void* ptr) {
  1175. LUAT_MOBILE_EVENT_E event;
  1176. uint8_t index;
  1177. uint8_t status;
  1178. int ret;
  1179. rtos_msg_t* msg = (rtos_msg_t*)lua_topointer(L, -1);
  1180. event = msg->arg1;
  1181. index = msg->arg2 >> 8;
  1182. status = msg->arg2 & 0xFF;
  1183. // luat_mobile_cell_info_t cell_info;
  1184. // luat_mobile_signal_strength_info_t signal_info;
  1185. // uint8_t csq, i;
  1186. // char imsi[20];
  1187. // char iccid[24] = {0};
  1188. if (lua_getglobal(L, "sys_pub") != LUA_TFUNCTION) {
  1189. return 0;
  1190. };
  1191. switch(event)
  1192. {
  1193. case LUAT_MOBILE_EVENT_CFUN:
  1194. break;
  1195. case LUAT_MOBILE_EVENT_SIM:
  1196. /*
  1197. @sys_pub mobile
  1198. sim卡状态变化
  1199. SIM_IND
  1200. @usage
  1201. sys.subscribe("SIM_IND", function(status, value)
  1202. -- status的取值有:
  1203. -- RDY SIM卡就绪, value为nil
  1204. -- NORDY 无SIM卡, value为nil
  1205. -- SIM_PIN 需要输入PIN, value为nil
  1206. -- GET_NUMBER 获取到电话号码(不一定有值), value为nil
  1207. -- SIM_WC SIM卡的写入次数统计,掉电归0, value为统计值
  1208. log.info("sim status", status, value)
  1209. end)
  1210. */
  1211. switch (status)
  1212. {
  1213. case LUAT_MOBILE_SIM_READY:
  1214. lua_pushstring(L, "SIM_IND");
  1215. lua_pushstring(L, "RDY");
  1216. lua_call(L, 2, 0);
  1217. break;
  1218. case LUAT_MOBILE_NO_SIM:
  1219. lua_pushstring(L, "SIM_IND");
  1220. lua_pushstring(L, "NORDY");
  1221. lua_call(L, 2, 0);
  1222. break;
  1223. case LUAT_MOBILE_SIM_NEED_PIN:
  1224. lua_pushstring(L, "SIM_IND");
  1225. lua_pushstring(L, "SIM_PIN");
  1226. lua_call(L, 2, 0);
  1227. break;
  1228. case LUAT_MOBILE_SIM_NUMBER:
  1229. lua_pushstring(L, "SIM_IND");
  1230. lua_pushstring(L, "GET_NUMBER");
  1231. lua_call(L, 2, 0);
  1232. break;
  1233. case LUAT_MOBILE_SIM_WC:
  1234. lua_pushstring(L, "SIM_IND");
  1235. lua_pushstring(L, "SIM_WC");
  1236. uint32_t tmp = (uint32_t)ptr;
  1237. lua_pushinteger(L, tmp);
  1238. lua_call(L, 3, 0);
  1239. break;
  1240. default:
  1241. break;
  1242. }
  1243. break;
  1244. case LUAT_MOBILE_EVENT_REGISTER_STATUS:
  1245. break;
  1246. case LUAT_MOBILE_EVENT_CELL_INFO:
  1247. switch (status)
  1248. {
  1249. case LUAT_MOBILE_CELL_INFO_UPDATE:
  1250. /*
  1251. @sys_pub mobile
  1252. 基站数据已更新
  1253. CELL_INFO_UPDATE
  1254. @usage
  1255. -- 订阅式
  1256. sys.subscribe("CELL_INFO_UPDATE", function()
  1257. log.info("cell", json.encode(mobile.getCellInfo()))
  1258. end)
  1259. */
  1260. lua_pushstring(L, "CELL_INFO_UPDATE");
  1261. lua_call(L, 1, 0);
  1262. break;
  1263. case LUAT_MOBILE_SERVICE_CELL_UPDATE:
  1264. /*
  1265. @sys_pub mobile
  1266. 服务小区额外信息更新
  1267. SCELL_INFO
  1268. @usage
  1269. -- 订阅式
  1270. sys.subscribe("SCELL_INFO", function()
  1271. log.info("service cell", mobile.scell()))
  1272. end)
  1273. */
  1274. lua_pushstring(L, "SCELL_INFO");
  1275. lua_call(L, 1, 0);
  1276. default:
  1277. break;
  1278. }
  1279. break;
  1280. case LUAT_MOBILE_EVENT_PDP:
  1281. LLOGD("cid%d, state%d", index, status);
  1282. break;
  1283. case LUAT_MOBILE_EVENT_NETIF:
  1284. switch (status)
  1285. {
  1286. case LUAT_MOBILE_NETIF_LINK_ON:
  1287. LLOGD("NETIF_LINK_ON -> IP_READY");
  1288. /*
  1289. @sys_pub mobile
  1290. 已联网
  1291. IP_READY
  1292. @usage
  1293. -- 联网后会发一次这个消息
  1294. sys.subscribe("IP_READY", function(ip, adapter)
  1295. log.info("mobile", "IP_READY", ip, (adapter or -1) == socket.LWIP_GP)
  1296. end)
  1297. */
  1298. lua_pushstring(L, "IP_READY");
  1299. luat_ip_addr_t local_ip, net_mask, gate_way, ipv6;
  1300. #ifdef LUAT_USE_LWIP
  1301. ipv6.type = 0xff;
  1302. int ret = network_get_full_local_ip_info(NULL, NW_ADAPTER_INDEX_LWIP_GPRS, &local_ip, &net_mask, &gate_way, &ipv6);
  1303. #else
  1304. void* userdata = NULL;
  1305. network_adapter_info* info = network_adapter_fetch(NW_ADAPTER_INDEX_LWIP_GPRS, &userdata);
  1306. if (info == NULL)
  1307. ret = -1;
  1308. else
  1309. ret = info->get_local_ip_info(&local_ip, &net_mask, &gate_way, userdata);
  1310. #endif
  1311. if (ret == 0) {
  1312. #ifdef LUAT_USE_LWIP
  1313. lua_pushfstring(L, "%s", ipaddr_ntoa(&local_ip));
  1314. #else
  1315. lua_pushfstring(L, "%d.%d.%d.%d", (local_ip.ipv4 >> 24) & 0xFF, (local_ip.ipv4 >> 16) & 0xFF, (local_ip.ipv4 >> 8) & 0xFF, (local_ip.ipv4 >> 0) & 0xFF);
  1316. #endif
  1317. }
  1318. else {
  1319. lua_pushliteral(L, "0.0.0.0");
  1320. }
  1321. lua_pushinteger(L, NW_ADAPTER_INDEX_LWIP_GPRS);
  1322. lua_call(L, 3, 0);
  1323. break;
  1324. case LUAT_MOBILE_NETIF_LINK_OFF:
  1325. LLOGD("NETIF_LINK_OFF -> IP_LOSE");
  1326. /*
  1327. @sys_pub mobile
  1328. 已断网
  1329. IP_LOSE
  1330. @usage
  1331. -- 断网后会发一次这个消息
  1332. sys.subscribe("IP_LOSE", function(adapter)
  1333. log.info("mobile", "IP_LOSE", (adapter or -1) == socket.LWIP_GP)
  1334. end)
  1335. */
  1336. lua_pushstring(L, "IP_LOSE");
  1337. lua_pushinteger(L, NW_ADAPTER_INDEX_LWIP_GPRS);
  1338. lua_call(L, 2, 0);
  1339. break;
  1340. default:
  1341. break;
  1342. }
  1343. break;
  1344. case LUAT_MOBILE_EVENT_TIME_SYNC:
  1345. /*
  1346. @sys_pub mobile
  1347. 时间已经同步
  1348. NTP_UPDATE
  1349. @usage
  1350. -- 对于电信/移动的卡, 联网后,基站会下发时间,但联通卡不会,务必留意
  1351. sys.subscribe("NTP_UPDATE", function()
  1352. log.info("mobile", "time", os.date())
  1353. end)
  1354. */
  1355. LLOGD("TIME_SYNC %d", status);
  1356. lua_pushstring(L, "NTP_UPDATE");
  1357. lua_call(L, 1, 0);
  1358. break;
  1359. case LUAT_MOBILE_EVENT_CSCON:
  1360. // LLOGD("CSCON %d", status);
  1361. /*
  1362. @sys_pub mobile
  1363. RRC状态
  1364. CSCON
  1365. @usage
  1366. -- state 1 CONNECT 0 IDLE
  1367. sys.subscribe("CSCON", function(state)
  1368. log.info("mobile", "CSCON", state)
  1369. end)
  1370. */
  1371. lua_pushstring(L, "CSCON");
  1372. lua_pushinteger(L, status);
  1373. lua_call(L, 2, 0);
  1374. break;
  1375. case LUAT_MOBILE_EVENT_BEARER:
  1376. LLOGD("bearer act %d, result %d",status, index);
  1377. break;
  1378. case LUAT_MOBILE_EVENT_SMS:
  1379. switch(status)
  1380. {
  1381. case LUAT_MOBILE_SMS_READY:
  1382. LLOGI("sim%d sms ready", index);
  1383. break;
  1384. case LUAT_MOBILE_NEW_SMS:
  1385. break;
  1386. case LUAT_MOBILE_SMS_SEND_DONE:
  1387. break;
  1388. case LUAT_MOBILE_SMS_ACK:
  1389. break;
  1390. }
  1391. break;
  1392. case LUAT_MOBILE_EVENT_IMS_REGISTER_STATUS:
  1393. LLOGD("ims reg state %d", status);
  1394. break;
  1395. case LUAT_MOBILE_EVENT_CC:
  1396. LLOGD("LUAT_MOBILE_EVENT_CC status %d",status);
  1397. /*
  1398. @sys_pub mobile
  1399. 通话状态变化
  1400. CC_IND
  1401. @usage
  1402. sys.subscribe("CC_IND", function(status, value)
  1403. log.info("cc status", status, value)
  1404. end)
  1405. */
  1406. switch(status){
  1407. case LUAT_MOBILE_CC_READY:
  1408. LLOGD("LUAT_MOBILE_CC_READY");
  1409. lua_pushstring(L, "CC_IND");
  1410. lua_pushstring(L, "READY");
  1411. lua_call(L, 2, 0);
  1412. break;
  1413. case LUAT_MOBILE_CC_INCOMINGCALL:
  1414. lua_pushstring(L, "CC_IND");
  1415. lua_pushstring(L, "INCOMINGCALL");
  1416. lua_call(L, 2, 0);
  1417. break;
  1418. case LUAT_MOBILE_CC_CALL_NUMBER:
  1419. // lua_pushstring(L, "CC_IND");
  1420. // lua_pushstring(L, "CALL_NUMBER");
  1421. // lua_call(L, 2, 0);
  1422. break;
  1423. case LUAT_MOBILE_CC_CONNECTED_NUMBER:
  1424. // lua_pushstring(L, "CC_IND");
  1425. // lua_pushstring(L, "CONNECTED_NUMBER");
  1426. // lua_call(L, 2, 0);
  1427. break;
  1428. case LUAT_MOBILE_CC_CONNECTED:
  1429. lua_pushstring(L, "CC_IND");
  1430. lua_pushstring(L, "CONNECTED");
  1431. lua_call(L, 2, 0);
  1432. break;
  1433. case LUAT_MOBILE_CC_DISCONNECTED:
  1434. lua_pushstring(L, "CC_IND");
  1435. lua_pushstring(L, "DISCONNECTED");
  1436. lua_call(L, 2, 0);
  1437. break;
  1438. case LUAT_MOBILE_CC_SPEECH_START:
  1439. lua_pushstring(L, "CC_IND");
  1440. lua_pushstring(L, "SPEECH_START");
  1441. lua_call(L, 2, 0);
  1442. break;
  1443. case LUAT_MOBILE_CC_MAKE_CALL_OK:
  1444. lua_pushstring(L, "CC_IND");
  1445. lua_pushstring(L, "MAKE_CALL_OK");
  1446. lua_call(L, 2, 0);
  1447. break;
  1448. case LUAT_MOBILE_CC_MAKE_CALL_FAILED:
  1449. lua_pushstring(L, "CC_IND");
  1450. lua_pushstring(L, "MAKE_CALL_FAILED");
  1451. lua_call(L, 2, 0);
  1452. break;
  1453. case LUAT_MOBILE_CC_ANSWER_CALL_DONE:
  1454. lua_pushstring(L, "CC_IND");
  1455. lua_pushstring(L, "ANSWER_CALL_DONE");
  1456. lua_call(L, 2, 0);
  1457. break;
  1458. case LUAT_MOBILE_CC_HANGUP_CALL_DONE:
  1459. lua_pushstring(L, "CC_IND");
  1460. lua_pushstring(L, "HANGUP_CALL_DONE");
  1461. lua_call(L, 2, 0);
  1462. break;
  1463. case LUAT_MOBILE_CC_LIST_CALL_RESULT:
  1464. lua_pushstring(L, "CC_IND");
  1465. lua_pushstring(L, "LIST_CALL_RESULT");
  1466. lua_call(L, 2, 0);
  1467. break;
  1468. case LUAT_MOBILE_CC_PLAY:// 最先
  1469. lua_pushstring(L, "CC_IND");
  1470. lua_pushstring(L, "PLAY");
  1471. lua_call(L, 2, 0);
  1472. break;
  1473. }
  1474. break;
  1475. default:
  1476. break;
  1477. }
  1478. return 0;
  1479. }
  1480. void luat_mobile_event_cb(LUAT_MOBILE_EVENT_E event, uint8_t index, uint8_t status, void* ptr) {
  1481. #if defined LUAT_USE_VOLTE
  1482. switch (event){
  1483. case LUAT_MOBILE_EVENT_CC:
  1484. switch(status){
  1485. case LUAT_MOBILE_CC_SPEECH_START:
  1486. luat_cc_start_speech(index+1);
  1487. break;
  1488. case LUAT_MOBILE_CC_PLAY:
  1489. luat_cc_play_tone(index);
  1490. break;
  1491. }
  1492. break;
  1493. default:
  1494. break;
  1495. }
  1496. #endif
  1497. rtos_msg_t msg = {
  1498. .handler = l_mobile_event_handle,
  1499. .arg1 = event,
  1500. .arg2 = (index << 8) + status ,
  1501. .ptr = ptr
  1502. };
  1503. luat_msgbus_put(&msg, 0);
  1504. }