shellmatta/src/shellmatta.c

92 lines
1.6 KiB
C
Raw Normal View History

#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)
{
}