diff --git a/Firmware/Core/apps/Inc/command.h b/Firmware/Core/apps/Inc/command.h new file mode 100644 index 0000000..14462c9 --- /dev/null +++ b/Firmware/Core/apps/Inc/command.h @@ -0,0 +1,18 @@ +/** + ****************************************************************************** + * @文件名 : command.h + * @作 者 : 小冯Sir + * @brief : None + * @注意 : None + * @日 期 : 24-5-3 + ****************************************************************************** + */ +#ifndef FIRMWARE_CORE_APPS_INC_COMMAND_H_ +#define FIRMWARE_CORE_APPS_INC_COMMAND_H_ + +#include "main.h" +#include "string.h" + +void command_Process(uint8_t *str,uint16_t size); + +#endif //FIRMWARE_CORE_APPS_INC_COMMAND_H_ diff --git a/Firmware/Core/apps/src/command.c b/Firmware/Core/apps/src/command.c new file mode 100644 index 0000000..2c58e31 --- /dev/null +++ b/Firmware/Core/apps/src/command.c @@ -0,0 +1,64 @@ +/** + ****************************************************************************** + * @文件名 : command.c + * @作 者 : 小冯Sir + * @brief : None + * @注意 : None + * @日 期 : 24-5-3 + ****************************************************************************** + */ +#include "command.h" +#include "ctype.h" +uint8_t flag = 0; + +uint8_t parsedate(const char *date_str, int *year, int *month, int *day) { + if (date_str == NULL || year == NULL || month == NULL || day == NULL) { + return -1; + } + if (sscanf(date_str, "%4d-%2d-%2d", year, month, day) != 3) { + return -3; + } + if (*month < 1 || *month > 12) { + return -4; + } + if (*day < 1 || *day > 31) { + return -5; + } + return 0; +} +uint8_t parseTime(const char *str, int *hour, int *minute, int *second) { + if(sscanf(str,"%d:%d:%d",hour,minute,second) == 3){ + return 1; + } + return 0; +} +void command_Process(uint8_t *str, uint16_t size) { + int year, month, day; + int hour, minute, second; + int result; + if (strstr(str, "setdate")) flag = 1; + if (strstr(str, "settime")) flag = 2; + if (flag == 1) { + printf("请以下日期格式输入:\r\n"); + printf("example: 2024-05-03\r\n"); + result = parsedate(str, &year, &month, &day); + if (result == 0) { + printf("Year: %d, Month: %d, Day: %d\r\n", year, month, day); + } else { + printf("Error parsing date: %d\n", result); + } + } + if (flag == 2) { + printf("请以一下时间格式输入:\r\n"); + printf("example: 02:44:30\r\n"); + result = parseTime(str,&hour,&minute,&second); + if(result == 1){ + printf("Hours: %d, Minutes: %d, Seconds: %d\n", hour, minute, second); + } + else{ + printf("Error parsing time: %d\n",result); + } + } + + printf("%s", str); +} \ No newline at end of file