KETCube
Macros | Functions | Variables
ketCube_terminal.c File Reference

This file contains the KETCube Terminal. More...

#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include "utilities.h"
#include "ketCube_terminal.h"
#include "ketCube_mainBoard.h"
#include "ketCube_common.h"
#include "ketCube_cfg.h"
#include "ketCube_coreCfg.h"
#include "ketCube_eeprom.h"
#include "ketCube_modules.h"
#include "ketCube_uart.h"

Macros

#define KETCUBE_TERMINAL_USART_INSTANCE   USART1
 
#define KETCUBE_TERMINAL_USART_IRQn   USART1_IRQn
 
#define KETCUBE_TERMINAL_USART_BR   9600
 
#define KETCUBE_TERMINAL_USART_CHANNEL   KETCUBE_UART_CHANNEL_1
 
#define KETCUBE_TERMINAL_USART_TX_AF   GPIO_AF4_USART1
 
#define KETCUBE_TERMINAL_USART_RX_AF   GPIO_AF4_USART1
 
#define KETCUBE_TERMINAL_USART_CLK_ENABLE()   __USART1_CLK_ENABLE();
 
#define KETCUBE_TERMINAL_USART_RX_GPIO_CLK_ENABLE()   __GPIOA_CLK_ENABLE()
 
#define KETCUBE_TERMINAL_USART_TX_GPIO_CLK_ENABLE()   __GPIOA_CLK_ENABLE()
 
#define KETCUBE_TERMINAL_USART_FORCE_RESET()   __USART1_FORCE_RESET()
 
#define KETCUBE_TERMINAL_USART_RELEASE_RESET()   __USART1_RELEASE_RESET()
 
#define KETCUBE_TERMINAL_USART_TX_PIN   KETCUBE_MAIN_BOARD_PIN_IO2_PIN
 
#define KETCUBE_TERMINAL_USART_TX_GPIO_PORT   KETCUBE_MAIN_BOARD_PIN_IO2_PORT
 
#define KETCUBE_TERMINAL_USART_RX_PIN   KETCUBE_MAIN_BOARD_PIN_IO1_PIN
 
#define KETCUBE_TERMINAL_USART_RX_GPIO_PORT   KETCUBE_MAIN_BOARD_PIN_IO1_PORT
 
#define USART_BUFFER_SIZE   256
 

Functions

static uint8_t ketCube_terminal_getNextParam (uint8_t ptr)
 Return next command parameter index. More...
 
void ketCube_terminal_usartIoInit (void)
 
void ketCube_terminal_usartIoDeInit (void)
 
void ketCube_terminal_usartRx (void)
 
void ketCube_terminal_usartTx (void)
 
void ketCube_terminal_usartErrorCallback (void)
 
void ketCube_terminal_usartWakeupCallback (void)
 
void ketCube_terminal_UsartPrintVa (char *format, va_list args)
 
void ketCube_terminal_UsartPrint (char *format,...)
 
bool IsNewCharReceived (void)
 
char GetNewChar (void)
 
void ketCube_terminal_Init (void)
 Init terminal. More...
 
static bool ketCube_terminal_parseParams (ketCube_terminal_cmd_t *command, ketCube_terminal_command_flags_t *contextFlags)
 Parse command arguments and validate them. More...
 
static void ketCube_terminal_printCommandOutput (ketCube_terminal_cmd_t *command)
 Parse and print command outputs. More...
 
static int ketCube_terminal_processCommandErrors ()
 Processes command error code, prints the result. More...
 
bool ketCube_terminal_canRunCommand (ketCube_terminal_cmd_t *command, bool local)
 
void ketCube_terminal_execCMD (void)
 Execute command-in-buffer. More...
 
void ketCube_terminal_printCMDHelp (void)
 Print help related to the current user input. More...
 
void ketCube_terminal_UpdateCmdLine (void)
 Print current unfinished command. More...
 
void ketCube_terminal_ClearCmdLine (void)
 Clear command line. More...
 
void ketCube_terminal_ProcessCMD (void)
 Process user input. More...
 
void ketCube_terminal_Println (char *format,...)
 Print line to serial line + newline. More...
 
void ketCube_terminal_Print (char *format,...)
 Print format to serial line. More...
 
void ketCube_terminal_CoreSeverityPrintln (ketCube_severity_t msgSeverity, char *format,...)
 Print Debug info to serial line + newline. More...
 
void ketCube_terminal_DriverSeverityPrintln (const char *drvName, ketCube_severity_t msgSeverity, char *format,...)
 Print Debug info to serial line + newline. More...
 
void ketCube_terminal_ModSeverityPrintln (ketCube_severity_t msgSeverity, ketCube_cfg_moduleIDs_t modId, char *format, va_list args)
 Print Debug info to serial line + newline. More...
 
void ketCube_terminal_DebugPrintln (char *format,...)
 Print Debug info to serial line + newline. More...
 
void ketCube_terminal_DebugPrint (char *format,...)
 Print Debug info to serial line. More...
 

Variables

static UART_HandleTypeDef ketCube_terminal_UsartHandle
 
static ketCube_UART_descriptor_t ketCube_terminal_UsartDescriptor
 
static volatile uint8_t usartRxWrite = 0
 
static volatile uint8_t usartRxRead = 0
 
static char usartRxBuffer [USART_BUFFER_SIZE]
 
static char usartTxBuffer [USART_BUFFER_SIZE]
 
static ketCube_terminal_buffer_t commandHistory [KETCUBE_TERMINAL_HISTORY_LEN]
 
static char * commandBuffer = (char *) &(commandHistory[0].buffer[0])
 
static uint8_t * commandPtr = (uint8_t *) & (commandHistory[0].ptr)
 
static uint8_t commandHistoryPtr = 0
 
static uint8_t commandParamsPos
 

Detailed Description

This file contains the KETCube Terminal.

Author
Jan Belohoubek
Martin Ubl
Version
0.2
Date
2018-10-10
Attention

© Copyright (c) 2018 University of West Bohemia in Pilsen All rights reserved.

Developed by: The SmartCampus Team Department of Technologies and Measurement www.smartcampus.cz | www.zcu.cz

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal with 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 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 CONTRIBUTORS 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 WITH THE SOFTWARE.

Macro Definition Documentation

◆ KETCUBE_TERMINAL_USART_BR

#define KETCUBE_TERMINAL_USART_BR   9600

◆ KETCUBE_TERMINAL_USART_CHANNEL

#define KETCUBE_TERMINAL_USART_CHANNEL   KETCUBE_UART_CHANNEL_1

◆ KETCUBE_TERMINAL_USART_CLK_ENABLE

#define KETCUBE_TERMINAL_USART_CLK_ENABLE ( )    __USART1_CLK_ENABLE();

◆ KETCUBE_TERMINAL_USART_FORCE_RESET

#define KETCUBE_TERMINAL_USART_FORCE_RESET ( )    __USART1_FORCE_RESET()

◆ KETCUBE_TERMINAL_USART_INSTANCE

#define KETCUBE_TERMINAL_USART_INSTANCE   USART1

◆ KETCUBE_TERMINAL_USART_IRQn

#define KETCUBE_TERMINAL_USART_IRQn   USART1_IRQn

◆ KETCUBE_TERMINAL_USART_RELEASE_RESET

#define KETCUBE_TERMINAL_USART_RELEASE_RESET ( )    __USART1_RELEASE_RESET()

◆ KETCUBE_TERMINAL_USART_RX_AF

#define KETCUBE_TERMINAL_USART_RX_AF   GPIO_AF4_USART1

◆ KETCUBE_TERMINAL_USART_RX_GPIO_CLK_ENABLE

#define KETCUBE_TERMINAL_USART_RX_GPIO_CLK_ENABLE ( )    __GPIOA_CLK_ENABLE()

◆ KETCUBE_TERMINAL_USART_RX_GPIO_PORT

#define KETCUBE_TERMINAL_USART_RX_GPIO_PORT   KETCUBE_MAIN_BOARD_PIN_IO1_PORT

◆ KETCUBE_TERMINAL_USART_RX_PIN

#define KETCUBE_TERMINAL_USART_RX_PIN   KETCUBE_MAIN_BOARD_PIN_IO1_PIN

◆ KETCUBE_TERMINAL_USART_TX_AF

#define KETCUBE_TERMINAL_USART_TX_AF   GPIO_AF4_USART1

◆ KETCUBE_TERMINAL_USART_TX_GPIO_CLK_ENABLE

#define KETCUBE_TERMINAL_USART_TX_GPIO_CLK_ENABLE ( )    __GPIOA_CLK_ENABLE()

◆ KETCUBE_TERMINAL_USART_TX_GPIO_PORT

#define KETCUBE_TERMINAL_USART_TX_GPIO_PORT   KETCUBE_MAIN_BOARD_PIN_IO2_PORT

◆ KETCUBE_TERMINAL_USART_TX_PIN

#define KETCUBE_TERMINAL_USART_TX_PIN   KETCUBE_MAIN_BOARD_PIN_IO2_PIN

◆ USART_BUFFER_SIZE

#define USART_BUFFER_SIZE   256

Function Documentation

◆ GetNewChar()

char GetNewChar ( void  )

◆ IsNewCharReceived()

bool IsNewCharReceived ( void  )

◆ ketCube_terminal_canRunCommand()

bool ketCube_terminal_canRunCommand ( ketCube_terminal_cmd_t command,
bool  local 
)

◆ ketCube_terminal_execCMD()

void ketCube_terminal_execCMD ( void  )

Execute command-in-buffer.

◆ ketCube_terminal_getNextParam()

uint8_t ketCube_terminal_getNextParam ( uint8_t  ptr)
static

Return next command parameter index.

Note
This function is deprecated and will be removed in the next release(s)
Todo:
This is a deprecated function
Parameters
ptrindex where to start parameter search
Return values
indexnext parameter index

◆ ketCube_terminal_parseParams()

static bool ketCube_terminal_parseParams ( ketCube_terminal_cmd_t command,
ketCube_terminal_command_flags_t contextFlags 
)
static

Parse command arguments and validate them.

Parameters
commandptr to current command
contextFlagsptr to context flags
Return values
TRUEif parameters parsed successfuly, else return FALSE

◆ ketCube_terminal_printCMDHelp()

void ketCube_terminal_printCMDHelp ( void  )

Print help related to the current user input.

◆ ketCube_terminal_printCommandOutput()

static void ketCube_terminal_printCommandOutput ( ketCube_terminal_cmd_t command)
static

Parse and print command outputs.

◆ ketCube_terminal_processCommandErrors()

static int ketCube_terminal_processCommandErrors ( )
static

Processes command error code, prints the result.

◆ ketCube_terminal_usartErrorCallback()

void ketCube_terminal_usartErrorCallback ( void  )

◆ ketCube_terminal_usartIoDeInit()

void ketCube_terminal_usartIoDeInit ( void  )

◆ ketCube_terminal_usartIoInit()

void ketCube_terminal_usartIoInit ( void  )

◆ ketCube_terminal_UsartPrintVa()

void ketCube_terminal_UsartPrintVa ( char *  format,
va_list  args 
)

◆ ketCube_terminal_usartRx()

void ketCube_terminal_usartRx ( void  )

◆ ketCube_terminal_usartTx()

void ketCube_terminal_usartTx ( void  )

◆ ketCube_terminal_usartWakeupCallback()

void ketCube_terminal_usartWakeupCallback ( void  )

Variable Documentation

◆ commandBuffer

char* commandBuffer = (char *) &(commandHistory[0].buffer[0])
static

◆ commandHistory

◆ commandHistoryPtr

uint8_t commandHistoryPtr = 0
static

◆ commandParamsPos

uint8_t commandParamsPos
static

◆ commandPtr

uint8_t* commandPtr = (uint8_t *) & (commandHistory[0].ptr)
static

◆ ketCube_terminal_UsartDescriptor

ketCube_UART_descriptor_t ketCube_terminal_UsartDescriptor
static

◆ ketCube_terminal_UsartHandle

UART_HandleTypeDef ketCube_terminal_UsartHandle
static

◆ usartRxBuffer

char usartRxBuffer[USART_BUFFER_SIZE]
static

◆ usartRxRead

volatile uint8_t usartRxRead = 0
static

◆ usartRxWrite

volatile uint8_t usartRxWrite = 0
static

◆ usartTxBuffer

char usartTxBuffer[USART_BUFFER_SIZE]
static