#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void parse_at_command(char *command) {
char *buffer = strdup(command);
if (!buffer) {
perror("Memory allocation failed");
return;
}
char *at_pos = strstr(buffer, "AT+");
if (!at_pos) {
printf("Not a valid AT command.\n");
free(buffer);
return;
}
char *cmd_name = at_pos + 3;
char *equal_pos = strchr(cmd_name, '=');
if (equal_pos) {
*equal_pos = '\0';
printf("Command: AT+%s\n", cmd_name);
printf("Parameters: %s\n", equal_pos + 1);
} else {
char *question_pos = strchr(cmd_name, '?');
if (question_pos) {
*question_pos = '\0';
printf("Query Command: AT+%s\n", cmd_name);
} else {
printf("Execute Command: AT+%s\n", cmd_name);
}
}
free(buffer);
}
int main() {
char at_cmd1[] = "AT+UART=9600,0,8,1";
char at_cmd2[] = "AT+UART?";
char at_cmd3[] = "AT+UART";
parse_at_command(at_cmd1);
parse_at_command(at_cmd2);
parse_at_command(at_cmd3);
return 0;
}