CTS-SAT-1-OBC-Firmware
Loading...
Searching...
No Matches
telecommand_executor.c File Reference
#include "telecommand_exec/telecommand_parser.h"
#include "telecommand_exec/telecommand_definitions.h"
#include "telecommand_exec/telecommand_executor.h"
#include "telecommand_exec/telecommand_types.h"
#include "debug_tools/debug_uart.h"
#include "timekeeping/timekeeping.h"
#include "log/log.h"
#include "transforms/arrays.h"
#include "config/configuration.h"
#include "littlefs/littlefs_helper.h"
#include "comms_drivers/comms_tx.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
Include dependency graph for telecommand_executor.c:

Functions

uint8_t TCMD_add_tcmd_to_agenda (const TCMD_parsed_tcmd_to_execute_t *parsed_tcmd)
 Adds a telecommand to the agenda (schedule/queue) of telecommands to execute.
 
uint16_t TCMD_get_agenda_used_slots_count ()
 Gets the number of used slots in the agenda.
 
int16_t TCMD_get_next_tcmd_agenda_slot_to_execute ()
 Finds the index into TCMD_agenda (slot_num) of the next telecommand to execute.
 
static int8_t TCMD_store_resp_to_file (const char *resp_fname, const char *response_output_buf, uint64_t timestamp_sent, const char args_str_no_parens[], uint8_t tcmd_idx, uint32_t duration_ms, uint8_t return_code)
 Logs a message to a file.
 
static uint8_t TCMD_execute_parsed_telecommand_now (const uint16_t tcmd_idx, const char args_str_no_parens[], const uint64_t timestamp_sent, const char *tcmd_resp_fname, char *response_output_buf, uint16_t response_output_buf_size)
 Executes a telecommand immediately, based on the minimum info required to execute a telecommand.
 
uint8_t TCMD_execute_telecommand_in_agenda (const uint16_t tcmd_agenda_slot_num, char *response_output_buf, uint16_t response_output_buf_size)
 Executes a telecommand from the agenda immediately.
 
void TCMD_agenda_delete_all ()
 Deletes all entries from the agenda.
 
uint8_t TCMD_agenda_delete_by_tssent (uint64_t tssent)
 Deletes a telecommand from the agenda by its tssent (timestamp sent) field.
 
uint8_t TCMD_agenda_fetch ()
 Fetches the active agendas.
 
uint8_t TCMD_agenda_delete_by_name (const char *telecommand_name)
 Deletes all agenda entries with a telecommand name.
 

Variables

uint32_t TCMD_total_tcmd_queued_count = 0
 
uint64_t TCMD_latest_received_tcmd_timestamp_sent = 0
 
uint16_t TCMD_timestamp_sent_head = 0
 The head of the circular buffer of timestamps of telecommands that have been sent.
 
uint64_t TCMD_timestamp_sent_store [TCMD_TIMESTAMP_RECORD_SIZE] = {0}
 The circular buffer of timestamps of telecommands that have been sent.
 
TCMD_parsed_tcmd_to_execute_t TCMD_agenda [TCMD_AGENDA_SIZE]
 The agenda (schedule queue) of telecommands to execute.
 
uint8_t TCMD_agenda_is_valid [TCMD_AGENDA_SIZE] = {0}
 A flag indicating whether a given index in TCMD_agenda is valid (i.e., filled with a not-yet-executed command).
 

Function Documentation

◆ TCMD_add_tcmd_to_agenda()

uint8_t TCMD_add_tcmd_to_agenda ( const TCMD_parsed_tcmd_to_execute_t * parsed_tcmd)

Adds a telecommand to the agenda (schedule/queue) of telecommands to execute.

Parameters
parsed_tcmdThe parsed telecommand to add to the agenda.
Returns
0 on success, 1 if the agenda is full.
Note
Performs a deep copy of the parsed_tcmd arg into the agenda.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TCMD_agenda_delete_all()

void TCMD_agenda_delete_all ( )

Deletes all entries from the agenda.

Returns
Cannot fail, so no return value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TCMD_agenda_delete_by_name()

uint8_t TCMD_agenda_delete_by_name ( const char * telecommand_name)

Deletes all agenda entries with a telecommand name.

Parameters
telecommand_nameThe name of the telecommand in the agenda to delete. (e.g, hello_world)
Returns
0 on success, > 0 on error.
Note
Calls LOG_message() before all returns. Argument is case-insensitive.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TCMD_agenda_delete_by_tssent()

uint8_t TCMD_agenda_delete_by_tssent ( uint64_t tssent)

Deletes a telecommand from the agenda by its tssent (timestamp sent) field.

Parameters
tssentThe timestamp_sent value of the telecommand to delete.
Returns
0 on success, 1 if the telecommand was not found.
Note
Calls LOG_message() to log the deletion before all returns.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TCMD_agenda_fetch()

uint8_t TCMD_agenda_fetch ( )

Fetches the active agendas.

Returns
0 on success, 1 if there are no active agendas.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TCMD_execute_parsed_telecommand_now()

static uint8_t TCMD_execute_parsed_telecommand_now ( const uint16_t tcmd_idx,
const char args_str_no_parens[],
const uint64_t timestamp_sent,
const char * tcmd_resp_fname,
char * response_output_buf,
uint16_t response_output_buf_size )
static

Executes a telecommand immediately, based on the minimum info required to execute a telecommand.

Parameters
tcmd_idxThe index into TCMD_telecommand_definitions for the telecommand to execute.
args_str_no_parensA cstring containing the arguments for the telecommand. Null-terminated.
timestamp_sentThe value of the @tssent field when the telecommand was received.
response_output_bufA buffer to store the response from the telecommand.
response_output_buf_sizeThe size of the response_output_buf.
Returns
0 on success, 254 if tcmd_idx is out of bounds, otherwise the error code from the telecommand function.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TCMD_execute_telecommand_in_agenda()

uint8_t TCMD_execute_telecommand_in_agenda ( const uint16_t tcmd_agenda_slot_num,
char * response_output_buf,
uint16_t response_output_buf_size )

Executes a telecommand from the agenda immediately.

Parameters
tcmd_agenda_slot_numThe index into TCMD_agenda for the telecommand to execute.
response_output_bufA buffer to store the response from the telecommand.
response_output_buf_sizeThe size of the response_output_buf.
Returns
0 on success, 253/254 if an error occurs in the callers, otherwise the error code from the telecommand function.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TCMD_get_agenda_used_slots_count()

uint16_t TCMD_get_agenda_used_slots_count ( )

Gets the number of used slots in the agenda.

Returns
The number of currently-filled slots in the agenda.
Note
This function is mostly intended for "system stats" telecommands and logging.
Here is the caller graph for this function:

◆ TCMD_get_next_tcmd_agenda_slot_to_execute()

int16_t TCMD_get_next_tcmd_agenda_slot_to_execute ( )

Finds the index into TCMD_agenda (slot_num) of the next telecommand to execute.

Returns
The index into TCMD_agenda of the next telecommand to execute, or -1 if none are available/ready.
Note
This function will return the slot_num which has the lowest timestamp_to_execute value. If multiple slots have the same timestamp_to_execute, the lowest slot_num will be returned.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TCMD_store_resp_to_file()

static int8_t TCMD_store_resp_to_file ( const char * resp_fname,
const char * response_output_buf,
uint64_t timestamp_sent,
const char args_str_no_parens[],
uint8_t tcmd_idx,
uint32_t duration_ms,
uint8_t return_code )
static

Logs a message to a file.

Parameters
resp_fnameThe name of the file to log to.
response_output_bufThe message to log.
Returns
0 on success, LFS error code on failure.
Note
This function is used to log telecommand responses to a file.
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ TCMD_agenda

The agenda (schedule queue) of telecommands to execute.

◆ TCMD_agenda_is_valid

uint8_t TCMD_agenda_is_valid[TCMD_AGENDA_SIZE] = {0}

A flag indicating whether a given index in TCMD_agenda is valid (i.e., filled with a not-yet-executed command).

◆ TCMD_latest_received_tcmd_timestamp_sent

uint64_t TCMD_latest_received_tcmd_timestamp_sent = 0

◆ TCMD_timestamp_sent_head

uint16_t TCMD_timestamp_sent_head = 0

The head of the circular buffer of timestamps of telecommands that have been sent.

◆ TCMD_timestamp_sent_store

uint64_t TCMD_timestamp_sent_store[TCMD_TIMESTAMP_RECORD_SIZE] = {0}

The circular buffer of timestamps of telecommands that have been sent.

◆ TCMD_total_tcmd_queued_count

uint32_t TCMD_total_tcmd_queued_count = 0