luat_shell_air105.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #include "luat_base.h"
  22. #include "luat_shell.h"
  23. #include "luat_uart.h"
  24. #include "app_interface.h"
  25. #define LUAT_LOG_TAG "luat.shell"
  26. #include "luat_log.h"
  27. enum
  28. {
  29. SHELL_READ_DATA = USER_EVENT_ID_START + 1,
  30. };
  31. static HANDLE prvhShell;
  32. void luat_shell_write(char* buff, size_t len) {
  33. DBG_DirectOut(buff, len);
  34. }
  35. void luat_shell_notify_recv(void) {
  36. }
  37. static int32_t luat_shell_uart_cb(void *pData, void *pParam){
  38. Task_SendEvent(prvhShell, SHELL_READ_DATA, 0, 0, 0);
  39. return -1;
  40. }
  41. static void luat_shell(void *sdata)
  42. {
  43. OS_EVENT Event;
  44. char buff[512];
  45. int ret = 0;
  46. int len = 1;
  47. while (1) {
  48. // printf("tls_os_queue_receive \r");
  49. Task_GetEvent(prvhShell, CORE_EVENT_ID_ANY, &Event, NULL, 0);
  50. len = 1;
  51. while (len > 0 && len < 512) {
  52. memset(buff, 0, 512);
  53. len = Uart_RxBufferRead(0, buff, 512);
  54. if (len > 0 && len < 512){
  55. buff[len] = 0x00; // 确保结尾
  56. luat_shell_push(buff, len);
  57. }
  58. }
  59. // printf("shell loop end\r");
  60. }
  61. }
  62. void luat_shell_poweron(int _drv) {
  63. DBG_SetRxCB(luat_shell_uart_cb);
  64. if (!prvhShell)
  65. {
  66. prvhShell = Task_Create(luat_shell,
  67. NULL,
  68. 2048,
  69. 1,
  70. "luat_shell");
  71. }
  72. }