fix #15 added an api to control mode and echo + fixed the implementation and added tests

This commit is contained in:
prozessorkern
2020-03-08 19:56:04 +01:00
parent e970b6c941
commit 2921f9791b
7 changed files with 164 additions and 30 deletions

View File

@@ -307,6 +307,35 @@ shellmatta_retCode_t shellmatta_removeCmd(shellmatta_handle_t handle, shellmatta
return ret;
}
/**
* @brief changes configuration of a shellmatta instance
* @param[in] handle shellmatta instance handle
* @param[in] mode insert mode of the shellmatta type #shellmatta_mode_t
* @param[in] echoEnabled true: echo received chars to the output
* @return errorcode #SHELLMATTA_OK
* #SHELLMATTA_USE_FAULT (param err)
*/
shellmatta_retCode_t shellmatta_configure(shellmatta_handle_t handle, shellmatta_mode_t mode, bool echoEnabled)
{
shellmatta_instance_t *inst = (shellmatta_instance_t*)handle;
shellmatta_retCode_t ret = SHELLMATTA_OK;
/** -# check parameters for plausibility */
if( (NULL != inst)
&& (SHELLMATTA_MAGIC == inst->magic)
&& ((mode == SHELLMATTA_MODE_INSERT) || (mode == SHELLMATTA_MODE_OVERWRITE)))
{
inst->mode = mode;
inst->echoEnabled = echoEnabled;
}
else
{
ret = SHELLMATTA_USE_FAULT;
}
return ret;
}
/**
* @brief processes the passed amount of data
* @param[in] handle shellmatta instance handle
@@ -471,26 +500,18 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
/** -# search for a matching command */
while (NULL != cmd)
{
/** -# compare command string and length */
if ((0 == strncmp( argumentString,
/** -# compare command and alias string and length */
if ( ((0 == strncmp( argumentString,
cmd->cmd,
cmdLen))
&& (cmdLen == strlen(cmd->cmd)))
{
inst->write("\r\n", 2u);
cmdExecuted = 1u;
cmd->cmdFct(inst, argumentString, argumentLength);
cmd = NULL;
}
/** -# compare command alias if any and length */
else if((NULL != cmd->cmdAlias)
&& (cmdLen == strlen(cmd->cmd)))
|| ((NULL != cmd->cmdAlias)
&& ((0 == strncmp( argumentString,
cmd->cmdAlias,
cmdLen))
&& (cmdLen == strlen(cmd->cmdAlias))))
&& (cmdLen == strlen(cmd->cmdAlias)))))
{
inst->write("\r\n", 2u);
utils_writeEcho(inst, "\r\n", 2u);
cmdExecuted = 1u;
cmd->cmdFct(inst, argumentString, argumentLength);

View File

@@ -25,7 +25,7 @@
#include <stdint.h>
/**
* @brief processes the excape character stream of the instance and chacks
* @brief processes the excape character stream of the instance and checks
* if an arrow key was pressed
* @param[in] inst pointer to a shellmatta instance
* @return #SHELLMATTA_OK if an arrow key was pressed

View File

@@ -162,6 +162,7 @@ void utils_forwardCursor(shellmatta_instance_t *inst, uint32_t length)
* @param[in] inst pointer to shellmatta instance
* @param[in] data pointer to the data to be inserted
* @param[in] length length of the data to be inserted
* @todo this function shall check buffer overflows
*/
void utils_insertChars( shellmatta_instance_t *inst,
char *data,
@@ -192,16 +193,20 @@ void utils_insertChars( shellmatta_instance_t *inst,
&(inst->buffer[inst->cursor + length]),
inst->inputCount - inst->cursor);
utils_restoreCursorPos(inst);
inst->cursor += length;
inst->inputCount += length;
}
/** -# just overwrite/append the chars */
/** -# overwrite - if the cursor reaches the end of the input it is pushed further */
else
{
memcpy(&(inst->buffer[inst->cursor]), data, length);
utils_writeEcho(inst, data, length);
inst->cursor += length;
if(inst->cursor > inst->inputCount)
{
inst->inputCount = inst->cursor;
}
}
inst->inputCount += length;
inst->cursor += length;
}
}