tcp_cmd
Add doxygen documentation to the functions
This commit is contained in:
@@ -20,11 +20,20 @@ static bool tcp_cmd_parser(struct tcp_pcb* pcb, int argc, char** argv);
|
|||||||
static err_t tcp_cmd_accept(void* arg, struct tcp_pcb* pcb, err_t err);
|
static err_t tcp_cmd_accept(void* arg, struct tcp_pcb* pcb, err_t err);
|
||||||
static void tcp_cmd_close(struct tcp_pcb* pcb);
|
static void tcp_cmd_close(struct tcp_pcb* pcb);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is a wrapper for tcp_write and tcp_output
|
||||||
|
* @param pcb The tcp_pcb struct to write to
|
||||||
|
* @param str The string to write
|
||||||
|
*/
|
||||||
static void tcp_cmd_write(struct tcp_pcb* pcb, const char* str) {
|
static void tcp_cmd_write(struct tcp_pcb* pcb, const char* str) {
|
||||||
tcp_write(pcb, str, strlen(str), TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
tcp_write(pcb, str, strlen(str), TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||||
tcp_output(pcb);
|
tcp_output(pcb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function prints the header of the tcp command interface
|
||||||
|
* @param pcb The tcp_pcb struct to write to
|
||||||
|
*/
|
||||||
static void tcp_cmd_print_header(struct tcp_pcb* pcb) {
|
static void tcp_cmd_print_header(struct tcp_pcb* pcb) {
|
||||||
tcp_cmd_write(pcb, " Welcome to the TCP CMD interface\r\n"
|
tcp_cmd_write(pcb, " Welcome to the TCP CMD interface\r\n"
|
||||||
"(Type help for a list of the commands! exit to close)\r\n"
|
"(Type help for a list of the commands! exit to close)\r\n"
|
||||||
@@ -32,6 +41,11 @@ static void tcp_cmd_print_header(struct tcp_pcb* pcb) {
|
|||||||
"$>");
|
"$>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function prints the help text
|
||||||
|
* @param pcb The tcp_pcb struct to write to
|
||||||
|
*/
|
||||||
|
void
|
||||||
static void tcp_cmd_print_help(struct tcp_pcb* pcb) {
|
static void tcp_cmd_print_help(struct tcp_pcb* pcb) {
|
||||||
tcp_cmd_write(pcb,
|
tcp_cmd_write(pcb,
|
||||||
"help : shows a list of commands\r\n"
|
"help : shows a list of commands\r\n"
|
||||||
@@ -44,6 +58,10 @@ static void tcp_cmd_print_help(struct tcp_pcb* pcb) {
|
|||||||
"exit : closes the connection\r\n");
|
"exit : closes the connection\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function removes the newline from a string
|
||||||
|
* @param str The string to remove the newline from
|
||||||
|
*/
|
||||||
void remove_newline(char* str) {
|
void remove_newline(char* str) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (str[i] != '\0') {
|
while (str[i] != '\0') {
|
||||||
@@ -54,6 +72,10 @@ void remove_newline(char* str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function converts a string to lowercase
|
||||||
|
* @param str The string to convert
|
||||||
|
*/
|
||||||
void str_tolower(char* str) {
|
void str_tolower(char* str) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (str[i] != '\0') {
|
while (str[i] != '\0') {
|
||||||
@@ -62,6 +84,11 @@ void str_tolower(char* str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the extension of a file
|
||||||
|
* @param filename The filename to get the extension from
|
||||||
|
* @return char* The extension of the file
|
||||||
|
*/
|
||||||
char* get_filename_ext(char* filename) {
|
char* get_filename_ext(char* filename) {
|
||||||
char* dot = strrchr(filename, '.');
|
char* dot = strrchr(filename, '.');
|
||||||
if (!dot || dot == filename)
|
if (!dot || dot == filename)
|
||||||
@@ -69,8 +96,14 @@ char* get_filename_ext(char* filename) {
|
|||||||
return dot + 1;
|
return dot + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to find the next token in the input string
|
/**
|
||||||
// If the token is between quotes, return the whole string between quotes
|
* @brief This function finds the next token in the input string
|
||||||
|
* If the token is between quotes, return the whole string between quotes
|
||||||
|
* @param input The input string
|
||||||
|
* @param delimiter The delimiters to use
|
||||||
|
* @param next The next token
|
||||||
|
* @return char* The next token
|
||||||
|
*/
|
||||||
char* get_next_token(char* input, const char* delimiters, char** next) {
|
char* get_next_token(char* input, const char* delimiters, char** next) {
|
||||||
if (input == NULL) {
|
if (input == NULL) {
|
||||||
input = *next;
|
input = *next;
|
||||||
@@ -222,6 +255,14 @@ static bool tcp_cmd_parser(struct tcp_pcb* pcb, int argc, char** argv) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is called when the tcp connection receives data
|
||||||
|
* @param arg The argument ptr
|
||||||
|
* @param pcb The tcp_pcb struct
|
||||||
|
* @param p The pbuf struct
|
||||||
|
* @param err The error code from the tcp stack
|
||||||
|
* @return err_t ERR_OK if successful
|
||||||
|
*/
|
||||||
err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) {
|
err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) {
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
char cmd[MAX_CMD_LEN];
|
char cmd[MAX_CMD_LEN];
|
||||||
@@ -280,6 +321,13 @@ defer:
|
|||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is called when a new tcp connection is accepted
|
||||||
|
* @param arg The argument
|
||||||
|
* @param pcb The tcp_pcb struct
|
||||||
|
* @param err The error
|
||||||
|
* @return err_t ERR_OK
|
||||||
|
*/
|
||||||
static err_t tcp_cmd_accept(void* arg, struct tcp_pcb* pcb, err_t err) {
|
static err_t tcp_cmd_accept(void* arg, struct tcp_pcb* pcb, err_t err) {
|
||||||
LWIP_UNUSED_ARG(arg);
|
LWIP_UNUSED_ARG(arg);
|
||||||
LWIP_UNUSED_ARG(err);
|
LWIP_UNUSED_ARG(err);
|
||||||
@@ -291,7 +339,10 @@ static err_t tcp_cmd_accept(void* arg, struct tcp_pcb* pcb, err_t err) {
|
|||||||
tcp_cmd_print_header(pcb);
|
tcp_cmd_print_header(pcb);
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @brief This function closes the tcp connection
|
||||||
|
* @param pcb The tcp_pcb struct to close
|
||||||
|
*/
|
||||||
static void tcp_cmd_close(struct tcp_pcb* pcb) {
|
static void tcp_cmd_close(struct tcp_pcb* pcb) {
|
||||||
tcp_arg(pcb, NULL);
|
tcp_arg(pcb, NULL);
|
||||||
tcp_sent(pcb, NULL);
|
tcp_sent(pcb, NULL);
|
||||||
@@ -299,6 +350,9 @@ static void tcp_cmd_close(struct tcp_pcb* pcb) {
|
|||||||
tcp_close(pcb);
|
tcp_close(pcb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function initializes the tcp command interface
|
||||||
|
*/
|
||||||
void tcp_cmd_init(void) {
|
void tcp_cmd_init(void) {
|
||||||
struct tcp_pcb* tcp_pcb;
|
struct tcp_pcb* tcp_pcb;
|
||||||
tcp_pcb = tcp_new();
|
tcp_pcb = tcp_new();
|
||||||
|
|||||||
Reference in New Issue
Block a user