luat_lib_lora.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /*
  2. @module lora
  3. @summary lora驱动模块
  4. @version 1.0
  5. @date 2022.06.24
  6. @demo lora
  7. @tag LUAT_USE_LORA
  8. */
  9. #include "luat_base.h"
  10. #include "luat_rtos.h"
  11. #include "luat_gpio.h"
  12. #include "luat_spi.h"
  13. #include "luat_malloc.h"
  14. #include "sx126x/radio.h"
  15. #include "sx126x/sx126x.h"
  16. #include "sx126x/sx126x-board.h"
  17. #define LUAT_LOG_TAG "lora"
  18. #include "luat_log.h"
  19. extern uint8_t SX126xSpi;
  20. extern uint8_t SX126xCsPin;
  21. extern uint8_t SX126xResetPin;
  22. extern uint8_t SX126xBusyPin;
  23. extern uint8_t SX126xDio1Pin;
  24. static RadioEvents_t RadioEvents;
  25. enum{
  26. LORA_TX_DONE,
  27. LORA_RX_DONE,
  28. LORA_TX_TIMEOUT,
  29. LORA_RX_TIMEOUT,
  30. LORA_RX_ERROR,
  31. };
  32. static int l_lora_handler(lua_State* L, void* ptr) {
  33. rtos_msg_t* msg = (rtos_msg_t*)lua_topointer(L, -1);
  34. int event = msg->arg1;
  35. lua_getglobal(L, "sys_pub");
  36. if (lua_isnil(L, -1)) {
  37. lua_pushinteger(L, 0);
  38. return 1;
  39. }
  40. switch (event){
  41. case LORA_TX_DONE:
  42. /*
  43. @sys_pub lora
  44. LORA 发送完成
  45. LORA_TX_DONE
  46. @usage
  47. sys.subscribe("LORA_TX_DONE", function()
  48. lora.recive(1000)
  49. end)
  50. */
  51. lua_pushstring(L, "LORA_TX_DONE");
  52. lua_call(L, 1, 0);
  53. break;
  54. case LORA_RX_DONE:
  55. /*
  56. @sys_pub lora
  57. LORA 接收完成
  58. LORA_RX_DONE
  59. @usage
  60. sys.subscribe("LORA_RX_DONE", function(data, size)
  61. log.info("LORA_RX_DONE: ", data, size)
  62. lora.send("PING")
  63. end)
  64. */
  65. lua_pushstring(L, "LORA_RX_DONE");
  66. lua_pushlstring(L, (const char *)msg->ptr,msg->arg2);
  67. lua_pushinteger(L, msg->arg2);
  68. lua_call(L, 3, 0);
  69. luat_heap_free(msg->ptr);
  70. break;
  71. case LORA_TX_TIMEOUT:
  72. /*
  73. @sys_pub lora
  74. LORA 发送超时
  75. LORA_TX_TIMEOUT
  76. @usage
  77. sys.subscribe("LORA_TX_TIMEOUT", function()
  78. lora.recive(1000)
  79. end)
  80. */
  81. lua_pushstring(L, "LORA_TX_TIMEOUT");
  82. lua_call(L, 1, 0);
  83. break;
  84. case LORA_RX_TIMEOUT:
  85. /*
  86. @sys_pub lora
  87. LORA 接收超时
  88. LORA_RX_TIMEOUT
  89. @usage
  90. sys.subscribe("LORA_RX_TIMEOUT", function()
  91. lora.recive(1000)
  92. end)
  93. */
  94. lua_pushstring(L, "LORA_RX_TIMEOUT");
  95. lua_call(L, 1, 0);
  96. break;
  97. case LORA_RX_ERROR:
  98. /*
  99. @sys_pub lora
  100. LORA 接收错误
  101. LORA_RX_ERROR
  102. @usage
  103. sys.subscribe("LORA_RX_ERROR", function()
  104. lora.recive(1000)
  105. end)
  106. */
  107. lua_pushstring(L, "LORA_RX_ERROR");
  108. lua_call(L, 1, 0);
  109. break;
  110. }
  111. return 0;
  112. }
  113. static void OnTxDone( void ){
  114. rtos_msg_t msg = {0};
  115. msg.handler = l_lora_handler;
  116. msg.ptr = NULL;
  117. msg.arg1 = LORA_TX_DONE;
  118. msg.arg2 = 0;
  119. luat_msgbus_put(&msg, 1);
  120. }
  121. static void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ){
  122. // printf("RxDone size:%d rssi:%d snr:%d\n",size,rssi,snr);
  123. // printf("RxDone payload: %.*s",size,payload);
  124. char* rx_buff = luat_heap_malloc(size);
  125. memcpy( rx_buff, payload, size );
  126. rtos_msg_t msg = {0};
  127. msg.handler = l_lora_handler;
  128. msg.ptr = rx_buff;
  129. msg.arg1 = LORA_RX_DONE;
  130. msg.arg2 = size;
  131. luat_msgbus_put(&msg, 1);
  132. }
  133. static void OnTxTimeout( void ){
  134. rtos_msg_t msg = {0};
  135. msg.handler = l_lora_handler;
  136. msg.ptr = NULL;
  137. msg.arg1 = LORA_TX_TIMEOUT;
  138. msg.arg2 = 0;
  139. luat_msgbus_put(&msg, 1);
  140. }
  141. static void OnRxTimeout( void ){
  142. rtos_msg_t msg = {0};
  143. msg.handler = l_lora_handler;
  144. msg.ptr = NULL;
  145. msg.arg1 = LORA_RX_TIMEOUT;
  146. msg.arg2 = 0;
  147. luat_msgbus_put(&msg, 1);
  148. }
  149. static void OnRxError( void ){
  150. rtos_msg_t msg = {0};
  151. msg.handler = l_lora_handler;
  152. msg.ptr = NULL;
  153. msg.arg1 = LORA_RX_ERROR;
  154. msg.arg2 = 0;
  155. luat_msgbus_put(&msg, 1);
  156. }
  157. extern void RadioEventsInit(RadioEvents_t *events);
  158. /*
  159. lora初始化
  160. @api lora.init(ic, loraconfig,spiconfig)
  161. @string lora 型号,当前支持:<br>llcc68<br>sx1268
  162. @table lora配置参数,与具体设备有关
  163. @usage
  164. lora.init("llcc68",
  165. {
  166. id = 0, -- SPI id
  167. cs = pin.PB04, -- SPI 片选的GPIO号,如果没有pin库,填GPIO数字编号就行
  168. res = pin.PB00, -- 复位脚连接的GPIO号,如果没有pin库,填GPIO数字编号就行
  169. busy = pin.PB01, -- 忙检测脚的GPIO号
  170. dio1 = pin.PB06, -- 数据输入中断脚
  171. lora_init = true -- 是否发送初始化命令. 如果是唤醒后直接读取, 就传false
  172. }
  173. )
  174. */
  175. static int luat_lora_init(lua_State *L){
  176. size_t len = 0;
  177. const char* lora_ic = luaL_checklstring(L, 1, &len);
  178. if(strcmp("llcc68",lora_ic)== 0||strcmp("LLCC68",lora_ic)== 0||strcmp("sx1268",lora_ic)== 0||strcmp("SX1268",lora_ic)== 0){
  179. uint8_t id = 0,cs = 0,res = 0,busy = 0,dio1 = 0;
  180. bool lora_init = true;
  181. if (lua_istable(L, 2)) {
  182. lua_pushstring(L, "id");
  183. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  184. id = luaL_checkinteger(L, -1);
  185. }
  186. lua_pop(L, 1);
  187. lua_pushstring(L, "cs");
  188. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  189. cs = luaL_checkinteger(L, -1);
  190. }
  191. lua_pop(L, 1);
  192. lua_pushstring(L, "res");
  193. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  194. res = luaL_checkinteger(L, -1);
  195. }
  196. lua_pop(L, 1);
  197. lua_pushstring(L, "busy");
  198. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  199. busy = luaL_checkinteger(L, -1);
  200. }
  201. lua_pop(L, 1);
  202. lua_pushstring(L, "dio1");
  203. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  204. dio1 = luaL_checkinteger(L, -1);
  205. }
  206. lua_pop(L, 1);
  207. lua_pushstring(L, "lora_init");
  208. if (LUA_TBOOLEAN == lua_gettable(L, 2)) {
  209. lora_init = lua_toboolean(L, -1);
  210. }
  211. lua_pop(L, 1);
  212. }
  213. luat_spi_t sx126x_spi = {0};
  214. sx126x_spi.id = id;
  215. sx126x_spi.CPHA = 0;
  216. sx126x_spi.CPOL = 0;
  217. sx126x_spi.dataw = 8;
  218. sx126x_spi.bit_dict = 1;
  219. sx126x_spi.master = 1;
  220. sx126x_spi.mode = 0;
  221. sx126x_spi.bandrate = 20000000;
  222. sx126x_spi.cs = Luat_GPIO_MAX_ID;
  223. luat_spi_setup(&sx126x_spi);
  224. SX126xSpi = id;
  225. SX126xCsPin = cs;
  226. SX126xResetPin = res;
  227. SX126xBusyPin = busy;
  228. SX126xDio1Pin = dio1;
  229. luat_gpio_mode(SX126xCsPin, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);
  230. luat_gpio_mode(SX126xResetPin, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_HIGH);
  231. luat_gpio_mode(SX126xBusyPin, Luat_GPIO_INPUT, Luat_GPIO_PULLUP, Luat_GPIO_LOW);
  232. luat_gpio_mode(SX126xDio1Pin, Luat_GPIO_INPUT, Luat_GPIO_PULLUP, Luat_GPIO_LOW);
  233. RadioEvents.TxDone = OnTxDone;
  234. RadioEvents.RxDone = OnRxDone;
  235. RadioEvents.TxTimeout = OnTxTimeout;
  236. RadioEvents.RxTimeout = OnRxTimeout;
  237. RadioEvents.RxError = OnRxError;
  238. RadioEventsInit(&RadioEvents);
  239. if (lora_init) Radio.Init( &RadioEvents );
  240. luat_start_rtos_timer(luat_create_rtos_timer(Radio.IrqProcess, NULL, NULL), 10, 1);
  241. }
  242. else {
  243. LLOGE("no such ic %s", lora_ic);
  244. }
  245. return 0;
  246. }
  247. /*
  248. 设置频道频率
  249. @api lora.set_channel(freq)
  250. @number 频率
  251. @usage
  252. lora.set_channel(433000000)
  253. */
  254. static int luat_lora_set_channel(lua_State *L){
  255. uint32_t freq = luaL_optinteger(L, 1,433000000);
  256. Radio.SetChannel(freq);
  257. return 0;
  258. }
  259. /*
  260. lora配置发送参数
  261. @api lora.set_txconfig(ic, txconfig)
  262. @string lora 型号,当前支持:<br>llcc68<br>sx1268
  263. @table lora发送配置参数,与具体设备有关
  264. @usage
  265. lora.set_txconfig("llcc68",
  266. {
  267. mode=1,
  268. power=22,
  269. fdev=0,
  270. bandwidth=0,
  271. datarate=9,
  272. coderate=4,
  273. preambleLen=8,
  274. fixLen=false,
  275. crcOn=true,
  276. freqHopOn=0,
  277. hopPeriod=0,
  278. iqInverted=false,
  279. timeout=3000
  280. }
  281. )
  282. */
  283. static int luat_lora_set_txconfig(lua_State *L){
  284. size_t len = 0;
  285. const char* lora_ic = luaL_checklstring(L, 1, &len);
  286. if(strcmp("llcc68",lora_ic)== 0||strcmp("LLCC68",lora_ic)== 0||strcmp("sx1268",lora_ic)== 0||strcmp("SX1268",lora_ic)== 0){
  287. uint8_t mode = 1,power = 0,fdev = 0,bandwidth = 0,datarate = 9,coderate = 4,preambleLen = 8,freqHopOn = 0,hopPeriod = 0;
  288. uint32_t timeout = 0;
  289. bool fixLen = false,crcOn = true,iqInverted = false,rateOptimize = false;
  290. if (lua_istable(L, 2)) {
  291. lua_pushstring(L, "mode");
  292. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  293. mode = luaL_optinteger(L, -1,1);
  294. }
  295. lua_pop(L, 1);
  296. lua_pushstring(L, "power");
  297. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  298. power = luaL_optinteger(L, -1,22);
  299. }
  300. lua_pop(L, 1);
  301. lua_pushstring(L, "fdev");
  302. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  303. fdev = luaL_optinteger(L, -1,0);
  304. }
  305. lua_pop(L, 1);
  306. lua_pushstring(L, "bandwidth");
  307. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  308. bandwidth = luaL_optinteger(L, -1,0);
  309. }
  310. lua_pop(L, 1);
  311. lua_pushstring(L, "datarate");
  312. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  313. datarate = luaL_optinteger(L, -1,9);
  314. }
  315. lua_pop(L, 1);
  316. lua_pushstring(L, "coderate");
  317. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  318. coderate = luaL_optinteger(L, -1,4);
  319. }
  320. lua_pop(L, 1);
  321. lua_pushstring(L, "preambleLen");
  322. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  323. preambleLen = luaL_optinteger(L, -1,8);
  324. }
  325. lua_pop(L, 1);
  326. lua_pushstring(L, "fixLen");
  327. if (LUA_TBOOLEAN == lua_gettable(L, 2)) {
  328. fixLen = lua_toboolean(L, -1);
  329. }
  330. lua_pop(L, 1);
  331. lua_pushstring(L, "crcOn");
  332. if (LUA_TBOOLEAN == lua_gettable(L, 2)) {
  333. crcOn = lua_toboolean(L, -1);
  334. }
  335. lua_pop(L, 1);
  336. lua_pushstring(L, "freqHopOn");
  337. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  338. freqHopOn = luaL_optinteger(L, -1,0);
  339. }
  340. lua_pop(L, 1);
  341. lua_pushstring(L, "hopPeriod");
  342. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  343. hopPeriod = luaL_optinteger(L, -1,0);
  344. }
  345. lua_pop(L, 1);
  346. lua_pushstring(L, "iqInverted");
  347. if (LUA_TBOOLEAN == lua_gettable(L, 2)) {
  348. iqInverted = lua_toboolean(L, -1);
  349. }
  350. lua_pop(L, 1);
  351. lua_pushstring(L, "timeout");
  352. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  353. timeout = luaL_optinteger(L, -1,3000);
  354. }
  355. lua_pop(L, 1);
  356. lua_pushstring(L, "rateOptimize");
  357. if (LUA_TBOOLEAN == lua_gettable(L, 2)) {
  358. rateOptimize = lua_toboolean(L, -1);
  359. }
  360. lua_pop(L, 1);
  361. }
  362. Radio.SetTxConfig( mode, power, fdev, bandwidth,
  363. datarate, coderate,
  364. preambleLen, fixLen,
  365. crcOn, freqHopOn, hopPeriod, iqInverted, timeout ,rateOptimize);
  366. }
  367. else {
  368. LLOGE("no such ic %s", lora_ic);
  369. }
  370. return 0;
  371. }
  372. /*
  373. lora配置接收参数
  374. @api lora.set_rxconfig(ic, set_rxconfig)
  375. @string lora 型号,当前支持:<br>llcc68<br>sx1268
  376. @table lora接收配置参数,与具体设备有关
  377. @usage
  378. lora.set_rxconfig("llcc68",
  379. {
  380. mode=1,
  381. bandwidth=0,
  382. datarate=9,
  383. coderate=4,
  384. bandwidthAfc=0,
  385. preambleLen=8,
  386. symbTimeout=0,
  387. fixLen=false,
  388. payloadLen=0,
  389. crcOn=true,
  390. freqHopOn=0,
  391. hopPeriod=0,
  392. iqInverted=false,
  393. rxContinuous=false
  394. }
  395. )
  396. */
  397. static int luat_lora_set_rxconfig(lua_State *L){
  398. size_t len = 0;
  399. const char* lora_ic = luaL_checklstring(L, 1, &len);
  400. if(strcmp("llcc68",lora_ic)== 0||strcmp("LLCC68",lora_ic)== 0||strcmp("sx1268",lora_ic)== 0||strcmp("SX1268",lora_ic)== 0){
  401. uint8_t mode = 1,bandwidth = 0,datarate = 9,coderate = 4,bandwidthAfc = 0,preambleLen = 8,symbTimeout = 0,payloadLen = 0,freqHopOn = 0,hopPeriod = 0;
  402. uint32_t frequency = 433000000,timeout = 0;
  403. bool fixLen = false,crcOn = true,iqInverted = false,rxContinuous = false,rateOptimize = false;
  404. if (lua_istable(L, 2)) {
  405. lua_pushstring(L, "mode");
  406. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  407. mode = luaL_optinteger(L, -1,1);
  408. }
  409. lua_pop(L, 1);
  410. lua_pushstring(L, "bandwidth");
  411. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  412. bandwidth = luaL_optinteger(L, -1,0);
  413. }
  414. lua_pop(L, 1);
  415. lua_pushstring(L, "datarate");
  416. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  417. datarate = luaL_optinteger(L, -1,9);
  418. }
  419. lua_pop(L, 1);
  420. lua_pushstring(L, "coderate");
  421. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  422. coderate = luaL_optinteger(L, -1,4);
  423. }
  424. lua_pop(L, 1);
  425. lua_pushstring(L, "bandwidthAfc");
  426. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  427. bandwidthAfc = luaL_optinteger(L, -1,0);
  428. }
  429. lua_pop(L, 1);
  430. lua_pushstring(L, "preambleLen");
  431. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  432. preambleLen = luaL_optinteger(L, -1,8);
  433. }
  434. lua_pop(L, 1);
  435. lua_pushstring(L, "symbTimeout");
  436. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  437. symbTimeout = luaL_optinteger(L, -1,0);
  438. }
  439. lua_pop(L, 1);
  440. lua_pushstring(L, "fixLen");
  441. if (LUA_TBOOLEAN == lua_gettable(L, 2)) {
  442. fixLen = lua_toboolean(L, -1);
  443. }
  444. lua_pop(L, 1);
  445. lua_pushstring(L, "payloadLen");
  446. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  447. payloadLen = luaL_optinteger(L, -1,0);
  448. }
  449. lua_pop(L, 1);
  450. lua_pushstring(L, "crcOn");
  451. if (LUA_TBOOLEAN == lua_gettable(L, 2)) {
  452. crcOn = lua_toboolean(L, -1);
  453. }
  454. lua_pop(L, 1);
  455. lua_pushstring(L, "freqHopOn");
  456. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  457. freqHopOn = luaL_optinteger(L, -1,0);
  458. }
  459. lua_pop(L, 1);
  460. lua_pushstring(L, "hopPeriod");
  461. if (LUA_TNUMBER == lua_gettable(L, 2)) {
  462. hopPeriod = luaL_optinteger(L, -1,0);
  463. }
  464. lua_pop(L, 1);
  465. lua_pushstring(L, "iqInverted");
  466. if (LUA_TBOOLEAN == lua_gettable(L, 2)) {
  467. iqInverted = lua_toboolean(L, -1);
  468. }
  469. lua_pop(L, 1);
  470. lua_pushstring(L, "rxContinuous");
  471. if (LUA_TBOOLEAN == lua_gettable(L, 2)) {
  472. rxContinuous = lua_toboolean(L, -1);
  473. }
  474. lua_pop(L, 1);
  475. lua_pushstring(L, "rateOptimize");
  476. if (LUA_TBOOLEAN == lua_gettable(L, 2)) {
  477. rateOptimize = lua_toboolean(L, -1);
  478. }
  479. lua_pop(L, 1);
  480. }
  481. Radio.SetRxConfig( mode, bandwidth, datarate,
  482. coderate, bandwidthAfc, preambleLen,
  483. symbTimeout, fixLen,
  484. payloadLen, crcOn, freqHopOn, hopPeriod, iqInverted, rxContinuous ,rateOptimize);
  485. }
  486. else {
  487. LLOGE("no such ic %s", lora_ic);
  488. }
  489. return 0;
  490. }
  491. /*
  492. 发数据
  493. @api lora.send(data)
  494. @string 写入的数据
  495. @usage
  496. lora.send("PING")
  497. */
  498. static int luat_lora_send(lua_State *L){
  499. size_t len;
  500. const char* send_buff = luaL_checklstring(L, 1, &len);
  501. Radio.Standby();
  502. Radio.Send( send_buff, len);
  503. return 0;
  504. }
  505. /*
  506. 开启收数据
  507. @api lora.recv(timeout)
  508. @number 超时时间,默认1000 单位ms
  509. @usage
  510. sys.subscribe("LORA_RX_DONE", function(data, size)
  511. log.info("LORA_RX_DONE: ", data, size)
  512. lora.send("PING")
  513. end)
  514. -- 老版本没有recv, 可以改成 lora.recive
  515. lora.recv(1000)
  516. */
  517. static int luat_lora_recive(lua_State *L){
  518. int rx_timeout = luaL_optinteger(L, 1, 1000);
  519. Radio.Standby();
  520. Radio.Rx(rx_timeout);
  521. return 0;
  522. }
  523. /*
  524. 设置进入模式(休眠,正常等)
  525. @api lora.mode(mode)
  526. @number 模式 正常模式:lora.STANDBY 休眠模式:lora.SLEEP 默认为正常模式
  527. @usage
  528. lora.mode(lora.STANDBY)
  529. */
  530. static int luat_lora_mode(lua_State *L){
  531. int mode = luaL_optinteger(L, 1, 1);
  532. if (mode == 1){
  533. Radio.Standby();
  534. }else if (mode == 0){
  535. Radio.Sleep();
  536. }
  537. return 0;
  538. }
  539. #include "rotable2.h"
  540. static const rotable_Reg_t reg_lora[] =
  541. {
  542. { "init", ROREG_FUNC(luat_lora_init)},
  543. { "set_channel", ROREG_FUNC(luat_lora_set_channel)},
  544. { "set_txconfig",ROREG_FUNC(luat_lora_set_txconfig)},
  545. { "set_rxconfig",ROREG_FUNC(luat_lora_set_rxconfig)},
  546. { "send", ROREG_FUNC(luat_lora_send)},
  547. { "recv", ROREG_FUNC(luat_lora_recive)},
  548. { "recive", ROREG_FUNC(luat_lora_recive)},
  549. { "mode", ROREG_FUNC(luat_lora_mode)},
  550. //@const SLEEP number SLEEP模式
  551. { "SLEEP", ROREG_INT(0)},
  552. //@const STANDBY number STANDBY模式
  553. { "STANDBY", ROREG_INT(1)},
  554. { NULL, ROREG_INT(0)}
  555. };
  556. LUAMOD_API int luaopen_lora( lua_State *L ) {
  557. luat_newlib2(L, reg_lora);
  558. return 1;
  559. }