2019-06-16 22:03:27 +02:00
|
|
|
/*
|
|
|
|
* MIT License
|
|
|
|
*
|
|
|
|
* Copyright (c) 2019 Stefan Strobel <stefan.strobel@shimatta.net>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
|
|
|
|
* THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file shellmatta.c
|
|
|
|
* @brief Main implementation of the Shellmatta terminal implementation
|
|
|
|
* @author Stefan Strobel <stefan.strobel@shimatta.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup shellmatta
|
|
|
|
* @{
|
|
|
|
*/
|
2019-06-10 22:34:12 +02:00
|
|
|
|
|
|
|
#include "shellmatta.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-06-16 22:03:27 +02:00
|
|
|
/**
|
|
|
|
* @brief initialize the shellmatta terminal and provide all callbacks
|
|
|
|
* @param[in,out] inst pointer to a shellmatta instance
|
|
|
|
* @param[in] buffer pointer to the input buffer to use
|
|
|
|
* @param[in] bufferSize size of the provided input buffer
|
|
|
|
* @param[in] historyBuffer pointer to the history buffer to use
|
|
|
|
* NULL in case of no history buffer
|
|
|
|
* @param[in] historyBufferSize size of the history buffer
|
|
|
|
* 0 in case of no history buffer
|
|
|
|
*/
|
|
|
|
void shellmatta_doInit(
|
|
|
|
shellmatta_instance_t *inst,
|
|
|
|
uint8_t *buffer,
|
|
|
|
uint32_t bufferSize,
|
|
|
|
uint8_t *historyBuffer,
|
|
|
|
uint32_t historyBufferSize)
|
2019-06-10 22:34:12 +02:00
|
|
|
{
|
2019-06-16 22:03:27 +02:00
|
|
|
/** - copy all provided buffers into the shellmatta instance */
|
|
|
|
inst->buffer = buffer;
|
|
|
|
inst->bufferSize = bufferSize;
|
|
|
|
inst->bufferReadPointer = 0u;
|
|
|
|
inst->bufferWritePointer = 0u;
|
|
|
|
inst->cmdList = NULL;
|
|
|
|
inst->historyBuffer = historyBuffer;
|
|
|
|
inst->historyBufferSize = historyBufferSize;
|
2019-06-10 22:34:12 +02:00
|
|
|
}
|
|
|
|
|
2019-06-16 22:03:27 +02:00
|
|
|
|
2019-06-10 22:34:12 +02:00
|
|
|
void shellmatta_addCmd(shellmatta_instance_t *inst, shellmatta_cmd_t *cmd)
|
|
|
|
{
|
2019-06-16 22:03:27 +02:00
|
|
|
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;
|
|
|
|
}
|
2019-06-10 22:34:12 +02:00
|
|
|
}
|
|
|
|
|
2019-06-16 22:03:27 +02:00
|
|
|
|
2019-06-10 22:34:12 +02:00
|
|
|
void shellmatta_doTask(shellmatta_instance_t *inst, uint32_t time)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-06-16 22:03:27 +02:00
|
|
|
void shellmatta_processData(shellmatta_instance_t *inst, char *data,
|
|
|
|
uint32_t size)
|
2019-06-10 22:34:12 +02:00
|
|
|
{
|
2019-06-16 22:03:27 +02:00
|
|
|
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++;
|
|
|
|
}
|
2019-06-10 22:34:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void shellmatta_printf(shellmatta_instance_t *inst, const char *fmt, ...)
|
|
|
|
{
|
2019-06-16 22:03:27 +02:00
|
|
|
/*TODO dummy implementation, shall be replaced by a generic output mechanism */
|
|
|
|
printf(fmt);
|
2019-06-10 22:34:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void shellmatta_getArg(uint32_t cnt, uint8_t *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2019-06-16 22:03:27 +02:00
|
|
|
|
|
|
|
/** @} */
|