/*
 * Copyright (c) 2021-2022, Erich Styger
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#ifndef SHELL_H_
#define SHELL_H_

#include "McuShell.h"
#include "McuRTOS.h"
#include <stdint.h>
#include "multi-splitflap.h"

#define SHELL_CMD_IDENTIFY_SF "SplitFlap setId"
#define SHELL_CMD_INIT_ALL_SF "SplitFlap initAll"
#define SHELL_CMD_DISPLAY_STRING_SF "SplitFlap Display"

#define SHELL_CMD_QUEUE_LENGTH 5


typedef enum ShellCmd {
	Shell_Identify_SF,
	Shell_Init_All_SF,
	Shell_Display_String_SF,
	Shell_Powerof_rpi
}Shell_cmd_t;

typedef struct ShellCmd_s {
	Shell_cmd_t shellCmd;
	int32_t numberOfParams;
	int32_t params[NUM_FLAPS];
}Shell_cmd_s;



#ifdef __cplusplus
extern "C" {
#endif

QueueHandle_t SHELL_GetShellCmdQueueHandle();

/*!
 * \brief Converts a string to a integer array for sending with the cmd queue
 * \param str String to convert
 * \param res Array pointer to store the values
 * \param size of the string / array
 */
uint8_t SHELL_stringToInt32ArrayForSFCMD(const unsigned char **str, int32_t* res, int8_t sizeRes);

/*!
 * \brief Converts a int array to a string
 * \param intArray array to convert
 * \param size the size of the array
 * \param str to store string
 */
uint8_t SHELL_Int32ArrayToStringForSF(int32_t* intArray, int8_t size, char *str);
/*!
 * \brief Send a string to all supported I/Os
 * \param str String to send
 */
void SHELL_SendString(const unsigned char *str);

/*!
 * \brief Send a character to all supported I/Os
 * \param ch Character to send
 */
void SHELL_SendChar(unsigned char ch);

/*!
 * \brief Parses a command with a given standard I/O channel
 * \param command Command to be parsed
 * \param io I/O to be used. If NULL, the standard default I/O will be used
 * \param silent If parsing shall be silent or not
 * \return Error code, ERR_OK for no error
 */
uint8_t SHELL_ParseCommandIO(const unsigned char *command, McuShell_ConstStdIOType *io, bool silent);

/*!
 * \brief Module de-initialization
 */
void SHELL_Deinit(void);

/*!
 * \brief Module Initialization
 */
void SHELL_Init(void);

#ifdef __cplusplus
}  /* extern "C" */
#endif

#endif /* SHELL_H_ */
