cliface.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**
  2. * \file cliface.h
  3. *
  4. * This file contains definitions for command line interface (CLI) framework.
  5. */
  6. /*
  7. * Copyright (C) 2017. Mindtree Ltd.
  8. * All rights reserved.
  9. */
  10. #ifndef _H_CLIFACE_
  11. #define _H_CLIFACE_
  12. /* --------------------------------------------- Header File Inclusion */
  13. //#include "mcu.h"
  14. #include "hal_mcu.h" // Looks like this file is used in 6212.
  15. #include <string.h>
  16. /* --------------------------------------------- Global Definitions */
  17. /* --------------------------------------------- Macros */
  18. /* Debug Macros */
  19. /* TBD: Mapped with debug sub-system */
  20. #define CLI_ERR(...) /* printf(__VA_ARGS__) */
  21. #define CLI_TRC(...) /* printf(__VA_ARGS__) */
  22. #define CLI_INF(...) /* printf(__VA_ARGS__) */
  23. #define CLI_STR_COMPARE(s0, s1) strcmp((const char *)(s0), (const char *)(s1))
  24. #define CLI_NULL_CHECK(ptr) \
  25. if (NULL == (ptr)) \
  26. {\
  27. CLI_ERR( \
  28. "[CLI] NULL Pointer\n"); \
  29. \
  30. return 0xffff; \
  31. }
  32. #define AT_CMD
  33. #define CLI_IS_WHITE_SPACE(ch) ((' ' == (ch)) || ('\t' == (ch)))
  34. #ifdef AT_CMD
  35. #define CLI_IS_CMD_SEPARATOR(ch) (('=' == (ch)) || (',' == (ch)) || ('\r' == (ch)) || ('\n' == (ch)))
  36. #else // original one.
  37. #define CLI_IS_CMD_SEPARATOR(ch) ((' ' == (ch)) || ('\t' == (ch)) || ('\r' == (ch)) || ('\n' == (ch)))
  38. #endif //end AT_CMD
  39. /** TBD: Move to limits/configuration header file */
  40. #define CLI_MAX_ARGS 16
  41. #define CLI_strlen(s) strlen((const char*)s)
  42. /* --------------------------------------------- Data Types/ Structures */
  43. /**
  44. * CLI command handler.
  45. *
  46. * CLI will call the handler for the received command.
  47. *
  48. * \param [in] argc Number of arguments.
  49. * \param [in] argv List of arguments.
  50. */
  51. typedef uint16_t (* CLI_CMD_HANDLER)
  52. (
  53. uint32_t argc,
  54. uint8_t * argv[]
  55. ) ;
  56. /** This data structure represents a CLI command */
  57. typedef struct _cli_command
  58. {
  59. /** Command name */
  60. const uint8_t * cmd;
  61. /* Command description */
  62. const uint8_t * desc;
  63. /** Command handler */
  64. const CLI_CMD_HANDLER cmd_hdlr;
  65. } CLI_COMMAND;
  66. /* --------------------------------------------- Functions */
  67. uint16_t CLI_init
  68. (
  69. void
  70. );
  71. uint16_t CLI_process_line
  72. (
  73. /* IN */ uint8_t * buffer,
  74. /* IN */ uint32_t buffer_len,
  75. /* IN */ CLI_COMMAND * cmd_list,
  76. /* IN */ uint32_t cmd_count
  77. );
  78. int32_t CLI_strtoi
  79. (
  80. /* IN */ uint8_t *data,
  81. /* IN */ uint16_t data_length,
  82. /* IN */ uint8_t base
  83. );
  84. uint16_t CLI_strtoarray
  85. (
  86. /* IN */ uint8_t * data,
  87. /* IN */ uint16_t data_length,
  88. /* OUT */ uint8_t * output_array,
  89. /* IN */ uint16_t output_array_len
  90. );
  91. uint16_t CLI_strtoarray_le
  92. (
  93. /* IN */ uint8_t * data,
  94. /* IN */ uint16_t data_length,
  95. /* OUT */ uint8_t * output_array,
  96. /* IN */ uint16_t output_array_len
  97. );
  98. #endif /* _H_CLIFACE_ */