|
| 1 | +#include <rtthread.h> |
| 2 | +#include <stdlib.h> // For atoi() |
| 3 | +#include <finsh.h> // For MSH_CMD_EXPORT |
| 4 | + |
| 5 | +// The global variable you want to expose to FinSH |
| 6 | +// NOTE: It must be a global or static global variable. |
| 7 | +int app_data_value = 100; |
| 8 | + |
| 9 | +// Function to handle reading and setting the variable |
| 10 | +// All FinSH commands in msh mode must have this signature: (int argc, char **argv) |
| 11 | +void app_data_cmd(int argc, char **argv) |
| 12 | +{ |
| 13 | + // Check if the FinSH C-style interpreter is disabled |
| 14 | + #ifndef FINSH_USING_MSH |
| 15 | + rt_kprintf("Error: This command requires msh mode enabled.\n"); |
| 16 | + return; |
| 17 | + #endif |
| 18 | + |
| 19 | + if (argc == 1) |
| 20 | + { |
| 21 | + // Case 1: No arguments (e.g., 'app_data_cmd') -> Read the current value |
| 22 | + rt_kprintf("app_data_value (current): %d\n", app_data_value); |
| 23 | + } |
| 24 | + else if (argc == 2) |
| 25 | + { |
| 26 | + // Case 2: One argument (e.g., 'app_data_cmd 250') -> Set a new value |
| 27 | + int new_value = atoi(argv[1]); |
| 28 | + app_data_value = new_value; |
| 29 | + rt_kprintf("app_data_value set to: %d\n", app_data_value); |
| 30 | + } |
| 31 | + else |
| 32 | + { |
| 33 | + // Case 3: Invalid number of arguments |
| 34 | + rt_kprintf("Usage:\n"); |
| 35 | + rt_kprintf(" Read: app_data_cmd\n"); |
| 36 | + rt_kprintf(" Write: app_data_cmd <value>\n"); |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +// Export the function as a FinSH command. |
| 41 | +// Format: MSH_CMD_EXPORT(function_name, description) |
| 42 | +MSH_CMD_EXPORT(app_data_cmd, Get or set the application data value); |
1 | 43 | /* |
2 | 44 | * Copyright (c) 2021-2022, RT-Thread Development Team |
3 | 45 | * |
|
9 | 51 | * 2022-06-02 supperthomas fix version |
10 | 52 | * 2023-10-20 WCX1024979076 add wifi application |
11 | 53 | */ |
12 | | - |
| 54 | +#define RT_BSP_LED_PIN 2 |
13 | 55 | #include <rtthread.h> |
14 | 56 | #include <rtdevice.h> |
15 | 57 | #include <board.h> |
|
0 commit comments