luat_lib_nimble.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "luat_base.h"
  2. #include "luat_msgbus.h"
  3. #include "luat_malloc.h"
  4. #include "luat_spi.h"
  5. #include "luat_nimble.h"
  6. #define LUAT_LOG_TAG "nimble"
  7. #include "luat_log.h"
  8. static int l_nimble_init(lua_State* L) {
  9. int rc = 0;
  10. char* name = NULL;
  11. if(lua_isstring(L, 1)) {
  12. name = lua_tostring(L, 1);
  13. }
  14. rc = luat_nimble_init(0xFF,name);
  15. if (rc) {
  16. lua_pushboolean(L, 0);
  17. lua_pushinteger(L, rc);
  18. return 2;
  19. }
  20. else {
  21. lua_pushboolean(L, 1);
  22. return 1;
  23. }
  24. }
  25. static int l_nimble_deinit(lua_State* L) {
  26. int rc = 0;
  27. rc = luat_nimble_deinit();
  28. if (rc) {
  29. lua_pushboolean(L, 0);
  30. lua_pushinteger(L, rc);
  31. return 2;
  32. }
  33. else {
  34. lua_pushboolean(L, 1);
  35. return 1;
  36. }
  37. }
  38. static int l_nimble_debug(lua_State* L) {
  39. int level;
  40. if (lua_gettop(L) > 0)
  41. level = luat_nimble_trace_level(luaL_checkinteger(L, 1));
  42. else
  43. level = luat_nimble_trace_level(-1);
  44. lua_pushinteger(L, level);
  45. return 1;
  46. }
  47. static int l_nimble_server_init(lua_State* L) {
  48. test_server_api_init();
  49. return 0;
  50. }
  51. static int l_nimble_server_deinit(lua_State* L) {
  52. test_server_api_deinit();
  53. return 0;
  54. }
  55. static int l_nimble_gap_adv(lua_State* L) {
  56. return 0;
  57. }
  58. #include "rotable.h"
  59. static const rotable_Reg reg_nimble[] =
  60. {
  61. { "init", l_nimble_init, 0},
  62. { "deinit", l_nimble_deinit, 0},
  63. { "debug", l_nimble_debug, 0},
  64. { "server_init", l_nimble_server_init, 0},
  65. { "server_deinit", l_nimble_server_deinit, 0},
  66. { "gap_adv", l_nimble_gap_adv, 0},
  67. { NULL, NULL , 0}
  68. };
  69. LUAMOD_API int luaopen_nimble( lua_State *L ) {
  70. luat_newlib(L, reg_nimble);
  71. return 1;
  72. }