cmd_util.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (C) 2017 ALLWINNERTECH TECHNOLOGY CO., LTD. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the
  12. * distribution.
  13. * 3. Neither the name of ALLWINNERTECH TECHNOLOGY CO., LTD. nor the names of
  14. * its contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef _CMD_UTIL_H_
  30. #define _CMD_UTIL_H_
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include "sys/param.h"
  34. #include "cmd_defs.h"
  35. #include "cmd_debug.h"
  36. //#include "console/console.h"
  37. #include "os.h"
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* command format: <command-name> <arg>... */
  42. struct cmd_data {
  43. char *name;
  44. enum cmd_status (*exec)(char *);
  45. };
  46. /* command2 format: <command-name>[ <arg>...] */
  47. struct cmd2_data {
  48. char *name;
  49. int name_len;
  50. enum cmd_status (*exec)(char *);
  51. };
  52. enum cmd_status cmd_exec(char *cmd, const struct cmd_data *cdata, int count);
  53. enum cmd_status cmd2_exec(char *cmd, const struct cmd2_data *cdata, int count);
  54. int cmd_parse_argv(char *cmd, char *argv[], int size);
  55. const char *cmd_get_status_desc(enum cmd_status status);
  56. //const char *cmd_get_event_desc(enum cmd_event event);
  57. int cmd_write(enum cmd_code_type type, int code, const char *fmt, ...);
  58. #define cmd_write_respond(status, fmt, arg...) \
  59. cmd_write(CMD_CODE_TYEP_STATUS, (int)status, fmt, ##arg)
  60. #define cmd_write_event(event, fmt, arg...) \
  61. cmd_write(CMD_CODE_TYEP_EVENT, (int)event, fmt, ##arg)
  62. int32_t cmd_raw_mode_read(uint8_t *buf, int32_t size, uint32_t msec);
  63. int32_t cmd_raw_mode_write(uint8_t *buf, int32_t size);
  64. #define cmd_raw_mode_enable() console_disable();
  65. #define cmd_raw_mode_disable() console_enable();
  66. #define cmd_malloc(l) malloc(l)
  67. #define cmd_free(p) free(p)
  68. #define cmd_memcpy(d, s, n) memcpy(d, s, n)
  69. #define cmd_memset(s, c, n) memset(s, c, n)
  70. #define cmd_memcmp(s1, s2, n) memcmp(s1, s2, n)
  71. #define cmd_strlen(s) strlen(s)
  72. #define cmd_strcmp(s1, s2) strcmp(s1, s2)
  73. #define cmd_strncmp(s1, s2, n) strncmp(s1, s2, n)
  74. #define cmd_strcasecmp(s1, s2) strcasecmp(s1, s2)
  75. #define cmd_strncasecmp(s1, s2, n) strncasecmp(s1, s2, n)
  76. #define cmd_strchr(s, c) strchr(s, c)
  77. #define cmd_strrchr(s, c) strrchr(s, c)
  78. #define cmd_strstr(s1, s2) strstr(s1, s2)
  79. #define cmd_strtol(s, p, b) strtol(s, p, b)
  80. #define cmd_strdup(s) strdup(s)
  81. #define cmd_strlcpy(d, s, n) strlcpy(d, s, n)
  82. #define cmd_atoi(s) atoi(s)
  83. #define cmd_atol(s) atol(s)
  84. #define cmd_sscanf(s, f, a...) sscanf(s, f, ##a)
  85. #define cmd_sprintf(s, f, a...) sprintf(s, f, ##a)
  86. #define cmd_snprintf(s, n, f, a...) snprintf(s, n, f, ##a)
  87. #define cmd_nitems(a) nitems(a)
  88. #define cmd_msleep(msec) OS_MSleep(msec)
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif /* _CMD_UTIL_H_ */