44 lines
914 B
C
44 lines
914 B
C
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
#include "esp32-uart-cmdr.h"
|
|
|
|
#define MAX_COMMANDS (10)
|
|
|
|
static struct Cmd cmd_list[MAX_COMMANDS];
|
|
static volatile uint8_t cmd_count = 0;
|
|
|
|
uint8_t ucmdr_install(char *cmd, void(*callback)(void *p)) {
|
|
//printf("installing: %s\n", cmd);
|
|
cmd_list[cmd_count].cmd = cmd;
|
|
cmd_list[cmd_count].callback = callback;
|
|
|
|
//printf("cmd_count: %d\n", cmd_count);
|
|
++cmd_count;
|
|
//printf("cmd_count: %d\n", cmd_count);
|
|
|
|
return cmd_count;
|
|
};
|
|
|
|
uint8_t ucmdr_match(char *str, struct Cmd **handler) {
|
|
uint8_t i = 0;
|
|
|
|
//printf("Checking against %d handlers\n", cmd_count);
|
|
|
|
for(; i < cmd_count; i++) {
|
|
//printf("checking %s\n", (const char*)cmd_list[i].cmd);
|
|
|
|
if(strstr(str, (const char*)cmd_list[i].cmd) != NULL) {
|
|
*handler = &cmd_list[i];
|
|
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
};
|
|
|
|
void ucmdr_init() {
|
|
bzero(&cmd_list, sizeof(cmd_list));
|
|
cmd_count = 0;
|
|
};
|