Skip to content

Commit

Permalink
Correct few doxygen descriptions and fixes based on coding guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
mcesnik1 committed Aug 14, 2018
1 parent 756081a commit 0be10c8
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 18 deletions.
14 changes: 11 additions & 3 deletions snippets/telnet_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ static const cli_command_t telnet_commands[] = {

/**
* \brief Telnet CLI to terminate the telnet connection
* \param[in] cliprintf: Pointer to CLI printf function
* \param[in] argc: Number fo arguments in argv
* \param[in] argv: Pointer to the commands arguments
*/
static void telnet_cli_exit(cli_printf cliprintf, int argc, char** argv) {
static void
telnet_cli_exit(cli_printf cliprintf, int argc, char** argv) {
close_conn = true;
}

Expand Down Expand Up @@ -217,8 +221,12 @@ telnet_server_thread(void const* arg) {

printf("Telnet new client connected.\r\n");

telnet_client_config(client);
if (res == espCLOSED) {
/*
* Inform telnet client that it should disable LINEMODE
* and that we will echo for him.
*/
res = telnet_client_config(client);
if (res != espOK) {
break;
}

Expand Down
57 changes: 50 additions & 7 deletions src/cli/cli.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
/**
* \file cli.c
* \brief Command line interface
*/

/*
* Copyright (c) 2018 Miha Cesnik
*
* 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.
*
* Author: Miha ČESNIK
*/

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
Expand All @@ -21,7 +52,8 @@ static const cli_command_t commands[] = {
* \param[in] command: pointer to command string for which we are searching
* \return pointer of the command if we found a match, else NULL
*/
const cli_command_t * cli_lookup_command(char* command) {
const cli_command_t *
cli_lookup_command(char* command) {
uint32_t module_index, command_index;
for (module_index = 0; module_index < num_of_modules; module_index++) {
for (command_index = 0; command_index < cli_command_table[module_index].num_of_commands; command_index++) {
Expand All @@ -35,12 +67,13 @@ const cli_command_t * cli_lookup_command(char* command) {

/**
* \brief CLI auto completion function
* \param[in] cliprintf: Pointer CLI printf function
* \param[in] cliprintf: Pointer to CLI printf function
* \param[in] cmd_buffer: CLI command buffer
* \param[in] cmd_pos: pointer to current courser postion in command buffer
* \param[in] print_options: additional prints in case of double tab
*/
void cli_tab_auto_complete(cli_printf cliprintf, char* cmd_buffer, uint32_t* cmd_pos, bool print_options) {
void
cli_tab_auto_complete(cli_printf cliprintf, char* cmd_buffer, uint32_t* cmd_pos, bool print_options) {
const char* matched_command = NULL;
uint32_t module_index, command_index;
uint32_t num_of_matched_commands = 0;
Expand Down Expand Up @@ -103,7 +136,8 @@ void cli_tab_auto_complete(cli_printf cliprintf, char* cmd_buffer, uint32_t* cmd
* \param[in] num_of_commands: Number of new commands
* \return true when new commands where succesfully added, else false
*/
bool cli_register_commands(const cli_command_t *commands, int num_of_commands) {
bool
cli_register_commands(const cli_command_t *commands, int num_of_commands) {
if (num_of_modules >= CLI_MAX_MODULES) {
printf("Exceeded the maximum number of CLI modules\n\r");
return false;
Expand All @@ -122,14 +156,19 @@ bool cli_register_commands(const cli_command_t *commands, int num_of_commands) {
/**
* \brief CLI Init function for adding basic CLI commands
*/
void cli_init(void) {
void
cli_init(void) {
cli_register_commands(commands, sizeof(commands)/sizeof(commands[0]));
}

/**
* \brief CLI command for printing help text of specific command
* \param[in] cliprintf: Pointer to CLI printf function
* \param[in] argc: Number fo arguments in argv
* \param[in] argv: Pointer to the commands arguments
*/
static void cli_help(cli_printf cliprintf, int argc, char** argv) {
static void
cli_help(cli_printf cliprintf, int argc, char** argv) {
const cli_command_t *command;

if (argc < 2) {
Expand All @@ -149,8 +188,12 @@ static void cli_help(cli_printf cliprintf, int argc, char** argv) {

/**
* \brief CLI command for listing all available commands
* \param[in] cliprintf: Pointer to CLI printf function
* \param[in] argc: Number fo arguments in argv
* \param[in] argv: Pointer to the commands arguments
*/
static void cli_list(cli_printf cliprintf, int argc, char** argv) {
static void
cli_list(cli_printf cliprintf, int argc, char** argv) {
uint32_t module_index, command_index;

cliprintf("%-20s%s"CLI_NL, "Command", "Description");
Expand Down
52 changes: 44 additions & 8 deletions src/cli/cli_input.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
/**
* \file cli_input.c
* \brief Command line interface helper funcions for paring input data
*/

/*
* Copyright (c) 2018 Miha Cesnik
*
* 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.
*
* Author: Miha ČESNIK
*/

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
Expand All @@ -16,15 +47,17 @@ static uint32_t cmd_history_full;
/**
* \brief Clear the command buffer and reset the position
*/
static void clear_cmd_buffer( void ) {
static void
clear_cmd_buffer( void ) {
memset(cmd_buffer, 0x0, sizeof(cmd_buffer));
cmd_pos = 0;
}

/**
* \brief Stores the command to history
*/
static void store_command_to_history( void ) {
static void
store_command_to_history( void ) {
uint32_t hist_count;
if (strcmp(cmd_history_buffer[0], cmd_buffer)) {
for (hist_count = CLI_CMD_HISTORY-1; hist_count > 0; hist_count--) {
Expand All @@ -48,11 +81,12 @@ static void store_command_to_history( void ) {
* ^[D : Left
* ^[1~ : Home (TODO)
* ^OF : End (TODO)
* \param[in] cliprintf: Pointer CLI printf function
* \param[in] cliprintf: Pointer to CLI printf function
* \param[in] ch: input char from CLI
* \return true when special key sequence is active, else false
*/
static bool cli_special_key_check(cli_printf cliprintf, char ch) {
static bool
cli_special_key_check(cli_printf cliprintf, char ch) {
static uint32_t key_sequence = 0;
static char last_ch;
bool special_key_found = false;
Expand Down Expand Up @@ -150,11 +184,12 @@ static bool cli_special_key_check(cli_printf cliprintf, char ch) {

/**
* \brief parse and execute the given command
* \param[in] cliprintf: Pointer CLI printf function
* \param[in] cliprintf: Pointer to CLI printf function
* \param[in] input: input string to parse
* \return true when command is found and parsed, else false
*/
static bool cli_parse_and_execute_command(cli_printf cliprintf, char *input) {
static bool
cli_parse_and_execute_command(cli_printf cliprintf, char *input) {
const cli_command_t *command;
char * argv[CLI_MAX_NUM_OF_ARGS];
uint32_t argc = 0;
Expand All @@ -176,10 +211,11 @@ static bool cli_parse_and_execute_command(cli_printf cliprintf, char *input) {

/**
* \brief parse new characters to the CLI
* \param[in] cliprintf: Pointer CLI printf function
* \param[in] cliprintf: Pointer to CLI printf function
* \param[in] ch: new character to CLI
*/
void cli_in_data(cli_printf cliprintf, char ch) {
void
cli_in_data(cli_printf cliprintf, char ch) {
static char last_ch = 0;

if (!cli_special_key_check(cliprintf, ch)) {
Expand Down

0 comments on commit 0be10c8

Please sign in to comment.