summaryrefslogtreecommitdiff
path: root/examples/var_export
diff options
context:
space:
mode:
authorWillianChan <[email protected]>2021-09-02 20:18:30 +0800
committerWillianChan <[email protected]>2021-09-02 20:20:29 +0800
commitf7657a94b5643948689b06679d172d994cf653bf (patch)
treec32b7f4e91521255b622c0c6419154e2de82004a /examples/var_export
parente53ae3ddfa0e0ca9857283c934d03304578545aa (diff)
[add][examples][var_export]add sample code for the var_export component
Signed-off-by: WillianChan <[email protected]>
Diffstat (limited to 'examples/var_export')
-rw-r--r--examples/var_export/var_export_example.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/examples/var_export/var_export_example.c b/examples/var_export/var_export_example.c
new file mode 100644
index 0000000000..9ea45de1c3
--- /dev/null
+++ b/examples/var_export/var_export_example.c
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-09-02 WillianChan add var_export example code
+ */
+
+#include <var_export.h>
+
+/* use VAR_EXPOR() to export 10 pieces of data into sections */
+VAR_EXPORT(module0, identi0, 0);
+VAR_EXPORT(module1, identi1, 1);
+VAR_EXPORT(module2, identi2, 2);
+VAR_EXPORT(module3, identi3, 3);
+VAR_EXPORT(module4, identi4, 4);
+VAR_EXPORT(module5, identi5, 5);
+VAR_EXPORT(module6, identi6, 6);
+VAR_EXPORT(module7, identi7, 7);
+VAR_EXPORT(module8, identi8, 8);
+VAR_EXPORT(module9, identi9, 9);
+
+void found_by_module(void)
+{
+ ve_iterator_t iter;
+ const ve_exporter_t* exporter;
+ ve_module_t module;
+ rt_base_t value;
+
+ /* query all exporters with the same name as module1 */
+ if (!ve_module_init(&module, "module1"))
+ /* initialize the iterator */
+ ve_iter_init(&module, &iter);
+ else
+ return;
+
+ while (1)
+ {
+ /* start iterating */
+ exporter = ve_iter_next(&iter);
+ if (exporter == RT_NULL)
+ break;
+ else
+ {
+ /* checks whether the value exists */
+ if (ve_value_exist(&module, "identi1") == RT_TRUE)
+ {
+ value = ve_value_get(&module, "identi1");
+ rt_kprintf("[ve_example] value = %dn", value);
+ return;
+ }
+ else
+ {
+ rt_kprintf("[ve_example] value not exist.\n");
+ return;
+ }
+ }
+ }
+}
+#ifdef RT_USING_FINSH
+#include <finsh.h>
+MSH_CMD_EXPORT(found_by_module, found by module);
+#endif /* RT_USING_FINSH */ \ No newline at end of file