parent
502cc280a5
commit
d9f05dcaf5
@ -1,8 +0,0 @@ |
||||
/*
|
||||
* uart1.c |
||||
* |
||||
* Created on: 7 Oct 2022 |
||||
* Author: simon |
||||
*/ |
||||
|
||||
|
||||
@ -1,13 +0,0 @@ |
||||
/*
|
||||
* uart1.h |
||||
* |
||||
* Created on: 7 Oct 2022 |
||||
* Author: simon |
||||
*/ |
||||
|
||||
#ifndef COMMUNICATION_UART1_H_ |
||||
#define COMMUNICATION_UART1_H_ |
||||
|
||||
|
||||
|
||||
#endif /* COMMUNICATION_UART1_H_ */ |
||||
@ -0,0 +1,119 @@ |
||||
/*
|
||||
* Copyright (c) 2019-2022, Erich Styger |
||||
* |
||||
* SPDX-License-Identifier: BSD-3-Clause |
||||
*/ |
||||
|
||||
#include "platform.h" |
||||
#include "Shell.h" |
||||
#include "McuShell.h" |
||||
#include "McuRTOS.h" |
||||
#include "McuRTT.h" |
||||
#include "McuArmTools.h" |
||||
#include "McuShellUart.h" |
||||
#include "McuLog.h" |
||||
#include "McuUtility.h" |
||||
|
||||
static uint8_t splitFlapId = 0; |
||||
static uint8_t ParseCommand(const uint8_t *cmd, bool *handled, McuShell_ConstStdIOType *io){ |
||||
uint8_t size = sizeof(SHELL_CMD_IDENTIFY_SF)-1; |
||||
if (McuUtility_strcmp((char*)cmd, McuShell_CMD_HELP)==0) { |
||||
McuShell_SendStr((unsigned char*)"\r\n", io->stdOut); |
||||
McuShell_SendStr((unsigned char*)McuShell_DASH_LINE, io->stdOut); |
||||
McuShell_SendStr((unsigned char*)"\r\n", io->stdOut); |
||||
McuShell_SendHelpStr((unsigned char*)"SplitFlap Help", (const unsigned char*)"Group of SplitFlap commands\r\n", io->stdOut); |
||||
McuShell_SendHelpStr((unsigned char*)" help", (const unsigned char*)"Print help this message\r\n", io->stdOut); |
||||
McuShell_SendHelpStr((unsigned char*)SHELL_CMD_IDENTIFY_SF, (const unsigned char*)"<SplitFlapId> (uint8_t)\r\n", io->stdOut); |
||||
McuShell_SendHelpStr((unsigned char*)" ", (const unsigned char*)"the number printed on the splitflap\r\n", io->stdOut); |
||||
McuShell_SendHelpStr((unsigned char*)" ", (const unsigned char*)"Splitflap Number:16\n", io->stdOut); |
||||
|
||||
|
||||
*handled = TRUE; |
||||
return ERR_OK; |
||||
} else if(McuUtility_strncmp((char*)cmd, SHELL_CMD_IDENTIFY_SF, size) == 0){ |
||||
*handled = TRUE; |
||||
cmd += sizeof(SHELL_CMD_IDENTIFY_SF)-1; |
||||
if(McuUtility_ScanDecimal8uNumber(&cmd, &splitFlapId) != ERR_OK){ |
||||
// Do not save id
|
||||
return ERR_FAILED; |
||||
} |
||||
} |
||||
return ERR_OK; |
||||
|
||||
} |
||||
|
||||
static const McuShell_ParseCommandCallback CmdParserTable[] = |
||||
{ |
||||
ParseCommand, |
||||
McuShell_ParseCommand, |
||||
McuRTOS_ParseCommand, |
||||
NULL /* Sentinel */ |
||||
}; |
||||
|
||||
typedef struct { |
||||
McuShell_ConstStdIOType *stdio; |
||||
unsigned char *buf; |
||||
size_t bufSize; |
||||
} SHELL_IODesc; |
||||
|
||||
static const SHELL_IODesc ios[] = |
||||
{ |
||||
// {&McuShellUart_stdio, McuShellUart_DefaultShellBuffer, sizeof(McuShellUart_DefaultShellBuffer)},
|
||||
{&McuRTT_stdio, McuRTT_DefaultShellBuffer, sizeof(McuRTT_DefaultShellBuffer)}, |
||||
// {&USB_CdcStdio, USB_CdcDefaultShellBuffer, sizeof(USB_CdcDefaultShellBuffer)},
|
||||
}; |
||||
|
||||
void SHELL_SendChar(unsigned char ch) { |
||||
for(int i=0;i<sizeof(ios)/sizeof(ios[0]);i++) { |
||||
McuShell_SendCh(ch, ios[i].stdio->stdOut); |
||||
} |
||||
} |
||||
|
||||
uint8_t SHELL_ParseCommandIO(const unsigned char *command, McuShell_ConstStdIOType *io, bool silent) { |
||||
if (io==NULL) { /* use a default */ |
||||
io = McuShell_GetStdio(); |
||||
} |
||||
return McuShell_ParseWithCommandTableExt(command, io, CmdParserTable, silent); |
||||
} |
||||
|
||||
void SHELL_SendString(const unsigned char *str) { |
||||
for(int i=0;i<sizeof(ios)/sizeof(ios[0]);i++) { |
||||
McuShell_SendStr(str, ios[i].stdio->stdOut); |
||||
} |
||||
} |
||||
|
||||
static void ShellTask(void *pv) { |
||||
int i; |
||||
|
||||
McuLog_info("Shell task started"); |
||||
for(i=0;i<sizeof(ios)/sizeof(ios[0]);i++) { |
||||
ios[i].buf[0] = '\0'; |
||||
} |
||||
for(;;) { |
||||
/* process all I/Os */ |
||||
for(i=0;i<sizeof(ios)/sizeof(ios[0]);i++) { |
||||
(void)McuShell_ReadAndParseWithCommandTable(ios[i].buf, ios[i].bufSize, ios[i].stdio, CmdParserTable); |
||||
} |
||||
vTaskDelay(pdMS_TO_TICKS(20)); |
||||
} |
||||
} |
||||
|
||||
void SHELL_Init(void) { |
||||
if (xTaskCreate( |
||||
ShellTask, /* pointer to the task */ |
||||
"Shell", /* task name for kernel awareness debugging */ |
||||
800/sizeof(StackType_t), /* task stack size */ |
||||
(void*)NULL, /* optional task startup argument */ |
||||
tskIDLE_PRIORITY+2, /* initial priority */ |
||||
(TaskHandle_t*)NULL /* optional task handle to create */ |
||||
) != pdPASS) |
||||
{ |
||||
McuLog_fatal("failed creating Shell task"); |
||||
for(;;){} /* error! probably out of memory */ |
||||
} |
||||
McuShell_SetStdio(McuRTT_GetStdio()); /* use RTT as the default */ |
||||
vTaskStartScheduler(); |
||||
} |
||||
|
||||
void SHELL_Deinit(void) {} |
||||
|
||||
@ -0,0 +1,53 @@ |
||||
/*
|
||||
* Copyright (c) 2021-2022, Erich Styger |
||||
* |
||||
* SPDX-License-Identifier: BSD-3-Clause |
||||
*/ |
||||
|
||||
#ifndef SHELL_H_ |
||||
#define SHELL_H_ |
||||
|
||||
#include "McuShell.h" |
||||
|
||||
#define SHELL_CMD_IDENTIFY_SF "Splitflap Number:" |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/*!
|
||||
* \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_ */ |
||||
Loading…
Reference in new issue