summaryrefslogtreecommitdiff
path: root/components/finsh/msh_parse.c
diff options
context:
space:
mode:
authorxfwangqiang <[email protected]>2022-05-30 18:00:26 +0800
committerGitHub <[email protected]>2022-05-30 18:00:26 +0800
commite8d775f888f14e4fe3cc7bd57740fda0caaf4ece (patch)
tree9bc4bb197e278e971390de0ca04d5283774815c0 /components/finsh/msh_parse.c
parent04a17d469a686282254f038f78d634a7420a1e0d (diff)
[componnets][pin]add pin operate command in MSH (#5892)
* 1. 在AT32的BSP的drv_gpio中增加了at32_pin_get函数,用于实现rt_pin_ops对象中的pin_get 2. 在MSH中增加了PIN的操作命令 3. 为了方便在MSH命令中解析字符串,增加了一些字符串相关的函数
Diffstat (limited to 'components/finsh/msh_parse.c')
-rw-r--r--components/finsh/msh_parse.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/components/finsh/msh_parse.c b/components/finsh/msh_parse.c
new file mode 100644
index 0000000000..a0f5f5e96d
--- /dev/null
+++ b/components/finsh/msh_parse.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2022-05-25 WangQiang the first verion for msh parse
+ */
+
+#include <rtthread.h>
+#include <ctype.h>
+
+#define forstrloop(str) for (; '\0' != *(str); (str)++)
+
+/**
+ * This function will check integer.
+ *
+ * @param strvalue string
+ *
+ * @return true or false
+ */
+rt_bool_t msh_isint(char *strvalue)
+{
+ if ((RT_NULL == strvalue) || ('\0' == strvalue[0]))
+ {
+ return RT_FALSE;
+ }
+ if (('+' == *strvalue) || ('-' == *strvalue))
+ {
+ strvalue++;
+ }
+ forstrloop(strvalue)
+ {
+ if (!isdigit((int)(*strvalue)))
+ {
+ return RT_FALSE;
+ }
+ }
+ return RT_TRUE;
+}
+
+/**
+ * This function will check hex.
+ *
+ * @param strvalue string
+ *
+ * @return true or false
+ */
+rt_bool_t msh_ishex(char *strvalue)
+{
+ int c;
+ if ((RT_NULL == strvalue) || ('\0' == strvalue[0]))
+ {
+ return RT_FALSE;
+ }
+ if ('0' != *(strvalue++))
+ {
+ return RT_FALSE;
+ }
+ if ('x' != *(strvalue++))
+ {
+ return RT_FALSE;
+ }
+
+ forstrloop(strvalue)
+ {
+ c = tolower(*strvalue);
+ if (!isxdigit(c))
+ {
+ return RT_FALSE;
+ }
+ }
+ return RT_TRUE;
+}
+
+/**
+ * This function will transform for string to hex.
+ *
+ * @param strvalue string
+ *
+ * @return true or false
+ */
+int msh_strtohex(char *strvalue)
+{
+ char c = 0;
+ int value = 0;
+ strvalue += 2;
+ forstrloop(strvalue)
+ {
+ value *= 16;
+ c = tolower(*strvalue);
+ value += isdigit(c) ? c - '0' : c - 'a' + 10;
+ }
+ return value;
+}