f0x.at1/Core/Src/commands.c

50 lines
1.5 KiB
C

/**
******************************************************************************
* @file commands.c
* @brief command.c file, the command interpreter, a generic one
******************************************************************************
* @author: Thomas Kuschel KW4NZ
* created 2022-06-04
*
******************************************************************************/
#include "cmsis_os.h"
#include <stdint.h>
#include "commands.h"
typedef struct command_ctx_s {
osThreadId_t thread_id;
osMutexId_t mutex;
char *last_cmd;
size_t last_cmd_size;
} command_ctx_t;
typedef enum {
CMD_HIDDEN = 0x01, /*!< Not shown in help but listed with "help all" or with "?" */
CMD_SECRET = 0x02, /*!< Not shown in help - hidden and secret commands */
CMD_ADMIN = 0x04, /*!< Only an administrator or privileged person can use this command */
CMD_NOT_IMPLEMENTED = 0x80 /*!< A command which is not implemented yet */
} cmd_flags_t;
#define CMD_LENGTH 16
typedef struct{
const char name[CMD_LENGTH]; /*!< command name */
const uint8_t significantlength; /*!< length of command for the compare function */
const uint8_t flag; /*!< command flags, i.e. CMD_HIDDEN, CMD_SECRET, CMD_ADMIN, etc. */
int(*func)(command_ctx_t *ctx, char *args);
} cmd_table_t;
static const cmd_table_t cmd_table[] = {
{"altitude", 1, CMD_NOT_IMPLEMENTED, not_implemented },
{"date", 1, CMD_NOT_IMPLEMENTED, not_implemented },
};
int not_implemented(command_ctx_t *ctx, char *args) {
(void) *ctx;
(void) *args;
return 0;
}