CTS-SAT-1-OBC-Firmware
Loading...
Searching...
No Matches
telecommand_parser.h File Reference
Include dependency graph for telecommand_parser.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define TCMD_ARGS_STR_NO_PARENS_SIZE   255
 
#define TCMD_PREFIX_STR   "CTS1+"
 
#define TCMD_PREFIX_STR_LEN   5
 

Functions

uint8_t TCMD_is_char_alphanumeric (char c)
 Returns whether a character is alphanumeric (0-9, A-Z, a-z).
 
uint8_t TCMD_is_char_valid_telecommand_name_char (char c)
 Returns whether a character is a valid character in a telecommand name.
 
uint8_t TCMD_check_starts_with_device_id (const char *tcmd_str, uint32_t tcmd_str_len)
 Returns whether tcmd_str starts with CTS1+ (TCMD_PREFIX_STR).
 
int32_t TCMD_parse_telecommand_get_index (const char *tcmd_str, uint32_t tcmd_str_len)
 Finds an index into TCMD_telecommand_definitions for the given telecommand string.
 
uint8_t TCMD_process_suffix_tag_tssent (const char *tcmd_suffix_tag_str, const uint16_t tcmd_suffix_tag_str_len, uint64_t *tssent_time_ms)
 Parses the @tssent=xxxx tag from the telecommand string.
 
uint8_t TCMD_process_suffix_tag_tsexec (const char *tcmd_suffix_tag_str, const uint16_t tcmd_suffix_tag_str_len, uint64_t *tsexec_time_ms)
 Parses the @tsexec=xxxx tag from the telecommand string.
 
uint8_t TCMD_process_suffix_tag_sha256 (const char *tcmd_suffix_tag_str, const uint16_t tcmd_suffix_tag_str_len, const char *tcmd_str, const int32_t end_of_args_idx)
 Parses the @sha256=xxxx tag from the telecommand string.
 
uint8_t TCMD_process_suffix_tag_resp_fname (const char *tcmd_suffix_tag_str, const uint16_t tcmd_suffix_tag_str_len, char *resp_fname, const uint8_t resp_fname_len)
 Parses the @resp_fname=xxxx tag from the telecommand string.
 
uint8_t TCMD_get_suffix_tag_uint64 (const char *str, const char *tag_name, uint64_t *value_dest)
 Searches for a str like \@tag_name=xxxx, and sets uint64_t xxxx into out_value.
 
uint8_t TCMD_get_suffix_tag_hex_array (const char *str, const char *tag_name, uint8_t *value_dest)
 Searches for a str like \@tag_name=xxxx, and sets uint8_t array xxxx into value_dest.
 
uint8_t TCMD_get_suffix_tag_str (const char *str, const char *tag_name, char *value_dest, uint16_t value_dest_max_len)
 Searches for a str like \@tag_name=xxxx, and sets char array xxxx into value_dest.
 
uint8_t TCMD_parse_full_telecommand (const char tcmd_str[], TCMD_parsed_tcmd_to_execute_t *parsed_tcmd_output)
 Parses a telecommand into everything needed to execute it.
 

Variables

static const uint8_t TCMD_SHA256_LENGTH_BYTES = 32
 

Macro Definition Documentation

◆ TCMD_ARGS_STR_NO_PARENS_SIZE

#define TCMD_ARGS_STR_NO_PARENS_SIZE   255

◆ TCMD_PREFIX_STR

#define TCMD_PREFIX_STR   "CTS1+"

◆ TCMD_PREFIX_STR_LEN

#define TCMD_PREFIX_STR_LEN   5

Function Documentation

◆ TCMD_check_starts_with_device_id()

uint8_t TCMD_check_starts_with_device_id ( const char * tcmd_str,
uint32_t tcmd_str_len )

Returns whether tcmd_str starts with CTS1+ (TCMD_PREFIX_STR).

Parameters
tcmd_strThe telecommand string to check.
tcmd_str_lenThe length of the telecommand string.
Returns
1 if tcmd_str starts with CTS1+, 0 otherwise.
Here is the caller graph for this function:

◆ TCMD_get_suffix_tag_hex_array()

uint8_t TCMD_get_suffix_tag_hex_array ( const char * str,
const char * tag_name,
uint8_t * value_dest )

Searches for a str like \@tag_name=xxxx, and sets uint8_t array xxxx into value_dest.

Parameters
strThe string to search within for the tag. Excluding the tag name, the length of the string must be 256 characters.
tag_nameThe tag to search for, including the '@' and '='.
value_destThe destination for the value. *value_dest will be set.
Returns
0 if the tag was found successfully. >0 if the tag was not found, or there was an error.
Note
This function will return an error if the character after the string is not one of the following: {'#', '@', '\0', '!'}.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TCMD_get_suffix_tag_str()

uint8_t TCMD_get_suffix_tag_str ( const char * str,
const char * tag_name,
char * value_dest,
uint16_t value_dest_max_len )

Searches for a str like \@tag_name=xxxx, and sets char array xxxx into value_dest.

Parameters
strThe string to search within for the tag. Excluding the tag name, the length of the string must be TCMD_MAX_RESP_FNAME_LEN.
tag_nameThe tag to search for, including the '@' and '='.
value_destThe destination for the value. *value_dest will be set.
Returns
0 if the tag was found successfully. >0 if the tag was not found, or there was an error.
Note
This function will return an error if the character after the string is not one of the following: {'#', '@', '\0', '!'}.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TCMD_get_suffix_tag_uint64()

uint8_t TCMD_get_suffix_tag_uint64 ( const char * str,
const char * tag_name,
uint64_t * value_dest )

Searches for a str like \@tag_name=xxxx, and sets uint64_t xxxx into out_value.

Parameters
strThe string (haystack) to search with for the tag.
tag_nameThe tag to search for, including the '@' and '='.
value_destThe destination for the value. *value_dest will be set.
Returns
0 if the tag was found successfully. >0 if the tag was not found, or there was an error.
Note
This function will return an error if the character after the number is not in: #\@\0!
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TCMD_is_char_alphanumeric()

uint8_t TCMD_is_char_alphanumeric ( char c)

Returns whether a character is alphanumeric (0-9, A-Z, a-z).

Parameters
cThe character to check.
Returns
1 if the character is alphanumeric, 0 otherwise.
Here is the caller graph for this function:

◆ TCMD_is_char_valid_telecommand_name_char()

uint8_t TCMD_is_char_valid_telecommand_name_char ( char c)

Returns whether a character is a valid character in a telecommand name.

Parameters
cThe character to check.
Returns
1 if the character is valid, 0 otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TCMD_parse_full_telecommand()

uint8_t TCMD_parse_full_telecommand ( const char tcmd_str[],
TCMD_parsed_tcmd_to_execute_t * parsed_tcmd_output )

Parses a telecommand into everything needed to execute it.

Parameters
tcmd_strThe telecommand string to parse. Must be null-terminated.
parsed_tcmd_outputPointer to the output struct, which is modified by this function. Not modified if an error occurs.
Returns
0 on success, >0 on error.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TCMD_parse_telecommand_get_index()

int32_t TCMD_parse_telecommand_get_index ( const char * tcmd_str,
uint32_t tcmd_str_len )

Finds an index into TCMD_telecommand_definitions for the given telecommand string.

This function searches for the longest matching telecommand string in TCMD_telecommand_definitions, where all alpha-numeric characters at the start of the to-be-parsed telecommand match the telecommand string in TCMD_telecommand_definitions. This function is case-sensitive.

Parameters
tcmd_strThe telecommand string to search within, starting with prefix, optionally including args.
Returns
The index into TCMD_telecommand_definitions for the given telecommand string. <0 if error. Returns -1 if telecommand not found. Returns -2 if strlen of tcmd_str is less than TCMD_PREFIX_STR_LEN. Returns -3 if tcmd_str does not start with TCMD_PREFIX_STR.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TCMD_process_suffix_tag_resp_fname()

uint8_t TCMD_process_suffix_tag_resp_fname ( const char * tcmd_suffix_tag_str,
const uint16_t tcmd_suffix_tag_str_len,
char * resp_fname,
const uint8_t resp_fname_len )

Parses the @resp_fname=xxxx tag from the telecommand string.

Parameters
tcmd_suffix_tag_strThe telecommand suffix tag string.
tcmd_suffix_tag_str_lenThe length of the telecommand suffix tag string.
resp_fnameThe destination for the log filename.
resp_fname_lenThe length of the log filename.

The log filename is the name of the file to which the telecommand will be logged.

If the length of the filename is > TCMD_MAX_RESP_FNAME_LEN, the filename will be truncated.

Returns
0 if the tag was found successfully or the tag is not present. >0 if there was an error.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TCMD_process_suffix_tag_sha256()

uint8_t TCMD_process_suffix_tag_sha256 ( const char * tcmd_suffix_tag_str,
const uint16_t tcmd_suffix_tag_str_len,
const char * tcmd_str,
const int32_t end_of_args_idx )

Parses the @sha256=xxxx tag from the telecommand string.

This function checks that the SHA256 hash of the telecommand string matches the hash provided in the tag.

Parameters
tcmd_suffix_tag_strThe telecommand suffix tag string.
tcmd_strThe telecommand string.
end_of_args_idxThe index of the end of the arguments in the telecommand string.
sha256_hashThe destination for the SHA256 hash.
Returns
0 if the tag was found successfully or the tag is not present (and not required) . >0 if there was an error.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TCMD_process_suffix_tag_tsexec()

uint8_t TCMD_process_suffix_tag_tsexec ( const char * tcmd_suffix_tag_str,
const uint16_t tcmd_suffix_tag_str_len,
uint64_t * tsexec_time_ms )

Parses the @tsexec=xxxx tag from the telecommand string.

This function checks that the timestamp to execute is valid.

Parameters
tcmd_suffix_tag_strThe telecommand suffix tag string.
tcmd_suffix_tag_str_lenThe length of the telecommand suffix tag string.
tsexec_time_msThe destination for the timestamp to execute.

The timestamp to execute is the time at which the telecommand should be executed.

Returns
0 if the tag was found successfully or the tag is not present. >0 if there was an error.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TCMD_process_suffix_tag_tssent()

uint8_t TCMD_process_suffix_tag_tssent ( const char * tcmd_suffix_tag_str,
const uint16_t tcmd_suffix_tag_str_len,
uint64_t * tssent_time_ms )

Parses the @tssent=xxxx tag from the telecommand string.

Parameters
tcmd_suffix_tag_strThe telecommand suffix tag string.
tcmd_suffix_tag_str_lenThe length of the telecommand suffix tag string.
tssent_time_msThe destination for the timestamp sent.
Returns
0 if the tag was found successfully or there is no tssent tag. >0 if there was an error.
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ TCMD_SHA256_LENGTH_BYTES

const uint8_t TCMD_SHA256_LENGTH_BYTES = 32
static