initial commit with at least some code that does something

This commit is contained in:
prozessorkern 2019-06-10 22:34:12 +02:00
parent 3d60361bc5
commit f15b7473a9
3 changed files with 133 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
output

41
api/shellmatta.h Normal file
View File

@ -0,0 +1,41 @@
#include <stdint.h>
typedef enum
{
SHELLMATTA_OK = 0u
, SHELLMATTA_ERROR
, SHELLMATTA_CONTINUE
, SHELLMATTA_USE_FAULT
} shellmatta_retCode_t;
typedef shellmatta_retCode_t (*shellmatta_cmdFct_t)(int argc, char *argv[]);
typedef struct shellmatta_cmd
{
char *cmd;
char *cmdAlias;
char *helpText;
char *usageText;
shellmatta_cmdFct_t cmdFct;
struct shellmatta_cmd *next;
} shellmatta_cmd_t;
typedef struct
{
uint8_t *buffer;
uint32_t bufferSize;
uint32_t bufferWritePointer;
uint32_t bufferReadPointer;
uint8_t *historyBuffer;
uint32_t historyBufferSize;
shellmatta_cmd_t *cmdList;
} shellmatta_instance_t;
extern void shellmatta_doInit(shellmatta_instance_t *inst, uint8_t *buffer, uint32_t bufferSize, uint8_t *historyBuffer, uint32_t historyBufferSize);
extern void shellmatta_addCmd(shellmatta_instance_t *inst, shellmatta_cmd_t *cmd);
extern void shellmatta_doTask(shellmatta_instance_t *inst, uint32_t time);
extern void shellmatta_processData(shellmatta_instance_t *inst, char *data, uint32_t size);
extern void shellmatta_printf(shellmatta_instance_t *inst, const char *fmt, ...);
extern void shellmatta_getArg(uint32_t cnt, uint8_t *arg);

91
src/shellmatta.c Normal file
View File

@ -0,0 +1,91 @@
#include "shellmatta.h"
#include <stdio.h>
#include <stddef.h>
#include <string.h>
void shellmatta_doInit(shellmatta_instance_t *inst, uint8_t *buffer, uint32_t bufferSize, uint8_t *historyBuffer, uint32_t historyBufferSize)
{
inst->buffer = buffer;
inst->bufferSize = bufferSize;
inst->bufferReadPointer = 0u;
inst->bufferWritePointer = 0u;
inst->cmdList = NULL;
inst->historyBuffer = historyBuffer;
inst->historyBufferSize = historyBufferSize;
}
void shellmatta_addCmd(shellmatta_instance_t *inst, shellmatta_cmd_t *cmd)
{
shellmatta_cmd_t *tempCmd = inst->cmdList;
if(NULL == tempCmd)
{
inst->cmdList = cmd;
cmd->next = NULL;
}
else
{
while(tempCmd->next != NULL)
{
tempCmd = tempCmd->next;
}
tempCmd->next = cmd;
cmd->next = NULL;
}
}
void shellmatta_doTask(shellmatta_instance_t *inst, uint32_t time)
{
}
void shellmatta_processData(shellmatta_instance_t *inst, char *data, uint32_t size)
{
printf("%c", *data);
if(0x0A == *data)
{
shellmatta_cmd_t *cmd = inst->cmdList;
uint8_t cmdExecuted = 0u;
inst->buffer[inst->bufferWritePointer] = 0u;
while(NULL != cmd)
{
if(0 == strcmp(inst->buffer, cmd->cmd))
{
cmdExecuted = 1u;
char *blubb[10];
blubb[0] = inst->buffer;
cmd->cmdFct(1, blubb);
cmd = NULL;
}
else
{
cmd = cmd->next;
}
}
if(cmdExecuted == 0u)
{
printf("failed to find command");
}
inst->bufferWritePointer = 0u;
}
else
{
inst->buffer[inst->bufferWritePointer] = *data;
inst->bufferWritePointer ++;
}
}
void shellmatta_printf(shellmatta_instance_t *inst, const char *fmt, ...)
{
printf(fmt);
}
void shellmatta_getArg(uint32_t cnt, uint8_t *arg)
{
}