CTS-SAT-1-OBC-Firmware
Loading...
Searching...
No Matches
mpi_command_handling.c File Reference
#include "mpi/mpi_command_handling.h"
#include "mpi/mpi_types.h"
#include "mpi/mpi_transceiver.h"
#include "eps_drivers/eps_channel_control.h"
#include "uart_handler/uart_handler.h"
#include "log/log.h"
#include "debug_tools/debug_uart.h"
#include "littlefs/littlefs_helper.h"
#include "timekeeping/timekeeping.h"
#include "transforms/arrays.h"
#include "main.h"
#include "stm32l4xx_hal.h"
#include <string.h>
#include <stdio.h>
Include dependency graph for mpi_command_handling.c:

Functions

uint8_t MPI_send_command_get_response (const uint8_t *bytes_to_send, const size_t bytes_to_send_len, uint8_t *rx_buffer, const size_t rx_buffer_max_size, uint16_t *rx_buffer_len)
 Sends commandcode+params to the MPI as bytes.
 
uint8_t MPI_validate_command_response (const uint8_t command_code, uint8_t *rx_buffer, const uint16_t rx_buffer_len)
 The MPI responds to each telecommand with a response code consisting of an echo of the telecommand code byte and a status byte (either 254 or OxFE) for success or error code otherwise.
 
static void MPI_power_on ()
 Turns on MPI by setting the corresponding EPS channel.
 
static int8_t MPI_write_file_header ()
 
static int8_t MPI_prepare_receive_data (const char output_file_path[])
 Turns on MPI and prepares a LFS file to store MPI data in.
 
uint8_t MPI_enable_active_mode (const char output_file_path[])
 Turns on MPI science mode and Enables DMA interrupt for MPI channel.
 
static void MPI_power_off ()
 Turns off MPI by resetting the corresponding EPS channel.
 
uint8_t MPI_disable_active_mode ()
 

Variables

static const uint16_t MPI_TX_TIMEOUT_DURATION_MS = 100
 Timeout duration for transmit HAL call, in milliseconds.
 
static const uint16_t MPI_RX_TIMEOUT_DURATION_MS = 2000
 Timeout duration for receive in milliseconds. Same between bytes and at the start.
 
volatile MPI_rx_mode_t MPI_current_uart_rx_mode = MPI_RX_MODE_NOT_LISTENING_TO_MPI
 Current mode under which the MPI is being operated.
 
uint8_t MPI_science_data_file_is_open = 0
 
uint32_t MPI_science_data_bytes_lost = 0
 
lfs_file_t MPI_science_data_file_pointer
 
uint32_t MPI_recording_start_uptime_ms
 

Function Documentation

◆ MPI_disable_active_mode()

uint8_t MPI_disable_active_mode ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MPI_enable_active_mode()

uint8_t MPI_enable_active_mode ( const char output_file_path[])

Turns on MPI science mode and Enables DMA interrupt for MPI channel.

Returns
0: MPI and DMA successfully enabled, < 0: Error
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MPI_power_off()

static void MPI_power_off ( )
static

Turns off MPI by resetting the corresponding EPS channel.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MPI_power_on()

static void MPI_power_on ( )
static

Turns on MPI by setting the corresponding EPS channel.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MPI_prepare_receive_data()

static int8_t MPI_prepare_receive_data ( const char output_file_path[])
static

Turns on MPI and prepares a LFS file to store MPI data in.

Returns
0: System successfully prepared for MPI data, < 0: Error
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MPI_send_command_get_response()

uint8_t MPI_send_command_get_response ( const uint8_t * bytes_to_send,
const size_t bytes_to_send_len,
uint8_t * rx_buffer,
const size_t rx_buffer_max_size,
uint16_t * rx_buffer_len )

Sends commandcode+params to the MPI as bytes.

Parameters
bytes_to_sendBuffer containing the telecommand + params (IF ANY) as hex bytes
bytes_to_send_lenSize of telecommand buffer
rx_bufferBuffer to store incoming response from the MPI
rx_buffer_max_sizeThe maximum size of the MPI response buffer
rx_buffer_lenPointer to variable that will contain the length of the populated MPI response buffer
Returns
0: Success, 2: Failed UART transmission, 3: Failed UART reception, 4: Timeout waiting for 1st byte from MPI, 8: Not enough space in the MPI response buffer
Note
If the MPI is in "science data" mode, it will be disabled after the command is executed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MPI_validate_command_response()

uint8_t MPI_validate_command_response ( const uint8_t command_code,
uint8_t * rx_buffer,
const uint16_t rx_buffer_len )

The MPI responds to each telecommand with a response code consisting of an echo of the telecommand code byte and a status byte (either 254 or OxFE) for success or error code otherwise.

Parameters
tx_bufferMPI telecommand buffer containing bytes sent
rx_bufferMPI response buffer containing bytes received
tx_buffer_sizeSize of the MPI response buffer
Returns
0: MPI successfully executed telecommand, 5: MPI failed to execute telecommand, 6: Invalid response from the MPI
Here is the caller graph for this function:

◆ MPI_write_file_header()

static int8_t MPI_write_file_header ( )
static
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ MPI_current_uart_rx_mode

volatile MPI_rx_mode_t MPI_current_uart_rx_mode = MPI_RX_MODE_NOT_LISTENING_TO_MPI

Current mode under which the MPI is being operated.

◆ MPI_recording_start_uptime_ms

uint32_t MPI_recording_start_uptime_ms

◆ MPI_RX_TIMEOUT_DURATION_MS

const uint16_t MPI_RX_TIMEOUT_DURATION_MS = 2000
static

Timeout duration for receive in milliseconds. Same between bytes and at the start.

◆ MPI_science_data_bytes_lost

uint32_t MPI_science_data_bytes_lost = 0

◆ MPI_science_data_file_is_open

uint8_t MPI_science_data_file_is_open = 0

◆ MPI_science_data_file_pointer

lfs_file_t MPI_science_data_file_pointer

◆ MPI_TX_TIMEOUT_DURATION_MS

const uint16_t MPI_TX_TIMEOUT_DURATION_MS = 100
static

Timeout duration for transmit HAL call, in milliseconds.