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.h
|
|
|
|
* @brief API definition of the Shellmatta terminal implementation
|
|
|
|
* @author Stefan Strobel <stefan.strobel@shimatta.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup shellmatta
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SHELLMATTA_H_
|
|
|
|
#define _SHELLMATTA_H_
|
2019-06-10 22:34:12 +02:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2019-06-21 04:47:35 +02:00
|
|
|
#include <stdbool.h>
|
2019-06-10 22:34:12 +02:00
|
|
|
|
2019-06-16 22:03:27 +02:00
|
|
|
/**
|
|
|
|
* @brief definition of shellmatta return codes
|
|
|
|
*/
|
2019-06-10 22:34:12 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
2019-06-16 22:03:27 +02:00
|
|
|
SHELLMATTA_OK = 0u, /**< everything is OK */
|
|
|
|
SHELLMATTA_ERROR , /**< error occured */
|
|
|
|
SHELLMATTA_CONTINUE , /**< the function is not over */
|
2019-06-21 04:47:35 +02:00
|
|
|
SHELLMATTA_USE_FAULT , /**< parameter error - wrong usage */
|
|
|
|
SHELLMATTA_DUPLICATE /**< duplicate command */
|
2019-06-10 22:34:12 +02:00
|
|
|
} shellmatta_retCode_t;
|
|
|
|
|
2019-06-21 04:47:35 +02:00
|
|
|
/**
|
|
|
|
* @brief definition of shellmatta insert mode
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
SHELLMATTA_MODE_INSERT = 0u, /**< insert mode */
|
|
|
|
SHELLMATTA_MODE_OVERWRITE , /**< overwrite mode */
|
|
|
|
} shellmatta_mode_t;
|
|
|
|
|
2019-06-16 22:03:27 +02:00
|
|
|
/**
|
|
|
|
* @brief shellmatta command function definition
|
|
|
|
*/
|
2019-06-10 22:34:12 +02:00
|
|
|
typedef shellmatta_retCode_t (*shellmatta_cmdFct_t)(int argc, char *argv[]);
|
|
|
|
|
2019-06-21 04:47:35 +02:00
|
|
|
/**
|
|
|
|
* @brief shellmatta write function definition
|
|
|
|
*/
|
|
|
|
typedef shellmatta_retCode_t (*shellmatta_write_t)(const char* data, uint32_t length);
|
|
|
|
|
2019-06-16 22:03:27 +02:00
|
|
|
/**
|
|
|
|
* @brief structure of one shellmatta command
|
|
|
|
*/
|
2019-06-10 22:34:12 +02:00
|
|
|
typedef struct shellmatta_cmd
|
|
|
|
{
|
2019-06-21 04:47:35 +02:00
|
|
|
char *cmd; /**< command name */
|
|
|
|
char *cmdAlias; /**< command alias */
|
|
|
|
char *helpText; /**< help text to print in "help" command */
|
|
|
|
char *usageText; /**< usage text to print on parameter error */
|
|
|
|
shellmatta_cmdFct_t cmdFct; /**< pointer to the cmd callack function */
|
|
|
|
struct shellmatta_cmd *next; /**< pointer to next command or NULL */
|
2019-06-10 22:34:12 +02:00
|
|
|
} shellmatta_cmd_t;
|
|
|
|
|
2019-06-16 22:03:27 +02:00
|
|
|
/**
|
|
|
|
* @brief structure of one shellmatta instance
|
|
|
|
*/
|
2019-06-10 22:34:12 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2019-06-21 04:47:35 +02:00
|
|
|
uint8_t *buffer; /**< input buffer */
|
|
|
|
uint32_t bufferSize; /**< size of the input buffer */
|
|
|
|
uint32_t inputCount; /**< offset of the current write operation */
|
|
|
|
uint32_t cursor; /**< offset where the cursor is at */
|
|
|
|
uint8_t *historyBuffer; /**< buffer to store the last commands */
|
|
|
|
uint32_t historyBufferSize; /**< size of the history buffer */
|
|
|
|
uint32_t historyStart; /**< index of the oldest stored command */
|
|
|
|
uint32_t historyEnd; /**< index of the newest stored command */
|
|
|
|
uint32_t historyRead; /**< index of the current search */
|
|
|
|
bool historyReadUp; /**< flag to show the last history dir */
|
|
|
|
uint32_t tabCounter; /**< counts the tabulator key presses */
|
|
|
|
uint32_t escapeCounter; /**< counts the characters of an escape seq */
|
|
|
|
uint8_t escapeChars[4]; /**< buffer to save the escape characters */
|
|
|
|
bool echoEnabled; /**< if true the input is printed */
|
|
|
|
bool dirty; /**< dirty flag to show changes */
|
|
|
|
const char *prompt; /**< prompt is printed after every command */
|
|
|
|
shellmatta_mode_t mode; /**< mode of the shell */
|
|
|
|
shellmatta_write_t write; /**< pointer to write function */
|
|
|
|
shellmatta_cmd_t *cmdList; /**< pointer to the first command */
|
2019-06-10 22:34:12 +02:00
|
|
|
} shellmatta_instance_t;
|
|
|
|
|
2019-06-21 04:47:35 +02:00
|
|
|
shellmatta_retCode_t shellmatta_doInit( shellmatta_instance_t *inst,
|
|
|
|
uint8_t *buffer,
|
|
|
|
uint32_t bufferSize,
|
|
|
|
uint8_t *historyBuffer,
|
|
|
|
uint32_t historyBufferSize,
|
|
|
|
const char *prompt,
|
|
|
|
shellmatta_write_t writeFct);
|
|
|
|
shellmatta_retCode_t shellmatta_addCmd(shellmatta_instance_t *inst, shellmatta_cmd_t *cmd);
|
2019-06-16 22:03:27 +02:00
|
|
|
void shellmatta_doTask(shellmatta_instance_t *inst, uint32_t time);
|
|
|
|
void shellmatta_processData(shellmatta_instance_t *inst, char *data, uint32_t size);
|
|
|
|
void shellmatta_printf(shellmatta_instance_t *inst, const char *fmt, ...);
|
|
|
|
void shellmatta_getArg(uint32_t cnt, uint8_t *arg);
|
|
|
|
|
|
|
|
#endif
|
2019-06-10 22:34:12 +02:00
|
|
|
|
2019-06-16 22:03:27 +02:00
|
|
|
/** @} */
|