add USART command
This commit is contained in:
parent
72eff9a4c8
commit
57c9a54615
18
Firmware/Core/apps/Inc/command.h
Normal file
18
Firmware/Core/apps/Inc/command.h
Normal file
@ -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_
|
64
Firmware/Core/apps/src/command.c
Normal file
64
Firmware/Core/apps/src/command.c
Normal file
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user