CTS-SAT-1-OBC-Firmware
Loading...
Searching...
No Matches
bulk_downlink_start_blob_main.c File Reference
#include <stdint.h>
#include <stdbool.h>
#include <stdarg.h>
#include "../lfs.h"
Include dependency graph for bulk_downlink_start_blob_main.c:

Macros

#define LFS_MAX_PATH_LENGTH   200
#define LOG(severity, fmt, ...)

Enumerations

enum  LOG_severity_enum_t {
  LOG_SEVERITY_DEBUG = 1 << 0 , LOG_SEVERITY_NORMAL = 1 << 1 , LOG_SEVERITY_WARNING = 1 << 2 , LOG_SEVERITY_ERROR = 1 << 3 ,
  LOG_SEVERITY_CRITICAL = 1 << 4
}
enum  COMMS_bulk_file_downlink_state_enum_t { COMMS_BULK_FILE_DOWNLINK_STATE_IDLE , COMMS_BULK_FILE_DOWNLINK_STATE_DOWNLINKING , COMMS_BULK_FILE_DOWNLINK_STATE_PAUSED }

Functions

int snprintf (char *buf, unsigned int size, const char *fmt,...)
int strlen (const char *s)
void LOG_message (uint32_t source, LOG_severity_enum_t severity, uint32_t sink_mask, const char *fmt,...)
lfs_ssize_t LFS_file_size (const char file_name[], uint8_t enable_log_messages)
 Returns the file size.
int8_t LFS_read_file_checksum_sha256 (const char filepath[], uint32_t start_offset, uint32_t max_length, uint8_t sha256_dest[32])
 Computes the SHA256 checksum of a file in LittleFS.
void GEN_byte_array_to_hex_str (const uint8_t *byte_array, uint32_t byte_array_len, char *dest_str, uint32_t dest_str_size)
 Writes a byte array to a hex string (no spaces between bytes).
int32_t COMMS_bulk_file_downlink_start (char *file_path, uint32_t start_offset, uint32_t max_bytes)
 Initiate a bulk file downlink over the UHF radio.
static uint32_t TIME_uptime_ms ()
static uint16_t parse_token (const char *src, uint16_t src_offset, uint16_t src_len, char *dst, uint16_t dst_size)
static int8_t hex_to_int (char c)
static int32_t parse_int (const char *s, bool *ok)
 Parse a string into an integer.
static int8_t bulk_downlink_start_fixed (const char *src_file_path, uint32_t start_offset, uint32_t byte_count)
 Main operation in this blob.
static int8_t fill_response_output_buffer (const char *src_file_path, uint32_t start_offset, uint32_t max_length, char *response_output_buf, uint16_t response_output_buf_len)
 Fill the response output buffer with info about the file (very helpful for decoding).
 __attribute__ ((used, section(".text.entry")))

Variables

static const uint32_t LOG_SYSTEM_TELECOMMAND = 1 << 12
static const uint32_t LOG_SINK_ALL = (1 << 4) - 1
static const char ARG_DELIM = ';'
static const char * BLOB_NAME = "bulk_downlink_start_blob"
lfs_t LFS_filesystem
volatile uint32_t TIME_uptime_ms_from_tim6
COMMS_bulk_file_downlink_state_enum_t COMMS_bulk_file_downlink_state
char COMMS_bulk_file_downlink_file_path [LFS_MAX_PATH_LENGTH]

Macro Definition Documentation

◆ LFS_MAX_PATH_LENGTH

#define LFS_MAX_PATH_LENGTH   200

◆ LOG

#define LOG ( severity,
fmt,
... )
Value:
LOG_message(LOG_SYSTEM_TELECOMMAND, severity, LOG_SINK_ALL, fmt, ##__VA_ARGS__)
void LOG_message(LOG_system_enum_t source, LOG_severity_enum_t severity, uint32_t sink_mask, const char fmt[],...) __attribute__((format(printf
@ LOG_SYSTEM_TELECOMMAND
Definition log.h:45
@ LOG_SINK_ALL
Definition log.h:24

Enumeration Type Documentation

◆ COMMS_bulk_file_downlink_state_enum_t

Enumerator
COMMS_BULK_FILE_DOWNLINK_STATE_IDLE 
COMMS_BULK_FILE_DOWNLINK_STATE_DOWNLINKING 
COMMS_BULK_FILE_DOWNLINK_STATE_PAUSED 

◆ LOG_severity_enum_t

Enumerator
LOG_SEVERITY_DEBUG 
LOG_SEVERITY_NORMAL 
LOG_SEVERITY_WARNING 
LOG_SEVERITY_ERROR 
LOG_SEVERITY_CRITICAL 

Function Documentation

◆ __attribute__()

__attribute__ ( (used, section(".text.entry")) )
Here is the call graph for this function:

◆ bulk_downlink_start_fixed()

int8_t bulk_downlink_start_fixed ( const char * src_file_path,
uint32_t start_offset,
uint32_t byte_count )
static

Main operation in this blob.

Parameters
src_file_path
start_offset
byte_count
Returns

Implementation is like this: The goal here is not to re-implement COMMS_bulk_file_downlink_start(), but rather to set the state to trick that function into first closing the open file (if applicable), and then doing its normal thing (which is 100% correct).

We are fixing a bug in the "end of bulk downlink" logic by a hack at the start of the next downlink, basically.

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

◆ COMMS_bulk_file_downlink_start()

int32_t COMMS_bulk_file_downlink_start ( char * file_path,
uint32_t start_offset,
uint32_t max_bytes )

Initiate a bulk file downlink over the UHF radio.

Parameters
file_pathFile name/path to downlink.
start_offsetThe byte offset in the file to start downlinking from (0 for start).
max_bytesThe maximum number of bytes to downlink. Maximum value is 1000000 (1 MB, COMMS_bulk_file_downlink_total_bytes), for safety (to avoid a very very long-running downlink chain). Values >1 MB will be limited to 1 MB, and value 0 will be set to 1 MB.
Returns
0 on success. Negative LFS failure code on LFS failure. Positive error code on other (logical/request) errors.
Note
1 MB takes about 15 minutes to downlink at 9600 baud.
This function is safe to call at any point (including mid-downlink, or mid-pause). It will close the previous file and start a new downlink.
Here is the caller graph for this function:

◆ fill_response_output_buffer()

int8_t fill_response_output_buffer ( const char * src_file_path,
uint32_t start_offset,
uint32_t max_length,
char * response_output_buf,
uint16_t response_output_buf_len )
static

Fill the response output buffer with info about the file (very helpful for decoding).

Note
This is a totally new feature, independent from the original bulk downlink telecommand. It is observed as a helpful feature for re-assembling the downlinked files during mission ops.
Parameters
src_file_path
start_offset
max_lengthMax length of the file to read, or 0 to read full file.
response_output_buf
response_output_buf_len
Returns
0 on success, non-zero on error.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GEN_byte_array_to_hex_str()

void GEN_byte_array_to_hex_str ( const uint8_t * byte_array,
uint32_t byte_array_len,
char * dest_str,
uint32_t dest_str_size )
extern

Writes a byte array to a hex string (no spaces between bytes).

Parameters
byte_arrayInput byte array.
byte_array_lenLength of input byte_array.
dest_strThe destination to write a C-string to.
dest_str_sizeThe size of the dest_str array, allocated before calling. Must be at least byte_array_len * 3 + 1 to fit the entire string.
Here is the caller graph for this function:

◆ hex_to_int()

int8_t hex_to_int ( char c)
static
Here is the caller graph for this function:

◆ LFS_file_size()

lfs_ssize_t LFS_file_size ( const char file_name[],
uint8_t enable_log_messages )

Returns the file size.

Parameters
file_name- Pointer to buffer holding the file name to open
Returns
Returns negative values if read or file open failed, else the number of bytes in the file.
Here is the caller graph for this function:

◆ LFS_read_file_checksum_sha256()

int8_t LFS_read_file_checksum_sha256 ( const char filepath[],
uint32_t start_offset,
uint32_t max_length,
uint8_t sha256_dest[32] )
extern

Computes the SHA256 checksum of a file in LittleFS.

Parameters
filepathPath to the file to read and compute the checksum for.
start_offsetThe offset in the file from which to start reading.
max_lengthThe maximum number of bytes to read from the file. 0 means read the entire file.
sha256_dest32-byte array to be filled with checksum.
Returns
0 on success. Negative LFS error codes on error.
Here is the caller graph for this function:

◆ LOG_message()

void LOG_message ( uint32_t source,
LOG_severity_enum_t severity,
uint32_t sink_mask,
const char * fmt,
... )
extern

◆ parse_int()

int32_t parse_int ( const char * s,
bool * ok )
static

Parse a string into an integer.

Parameters
sString to parse. Valid formats: "0x<digits>" or "<digits>". Underscores are ignored.
Returns
Parsed integer, or 0 if invalid.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_token()

uint16_t parse_token ( const char * src,
uint16_t src_offset,
uint16_t src_len,
char * dst,
uint16_t dst_size )
static
Here is the caller graph for this function:

◆ snprintf()

int snprintf ( char * buf,
unsigned int size,
const char * fmt,
... )
extern

◆ strlen()

int strlen ( const char * s)
extern

◆ TIME_uptime_ms()

uint32_t TIME_uptime_ms ( void )
inlinestatic

Variable Documentation

◆ ARG_DELIM

const char ARG_DELIM = ';'
static

◆ BLOB_NAME

const char* BLOB_NAME = "bulk_downlink_start_blob"
static

◆ COMMS_bulk_file_downlink_file_path

char COMMS_bulk_file_downlink_file_path[LFS_MAX_PATH_LENGTH]
extern

◆ COMMS_bulk_file_downlink_state

COMMS_bulk_file_downlink_state_enum_t COMMS_bulk_file_downlink_state
extern

◆ LFS_filesystem

lfs_t LFS_filesystem
extern

littlefs_helper.h

Created on: May 2, 2024 Author: Saksham Puri

◆ LOG_SINK_ALL

const uint32_t LOG_SINK_ALL = (1 << 4) - 1
static

◆ LOG_SYSTEM_TELECOMMAND

const uint32_t LOG_SYSTEM_TELECOMMAND = 1 << 12
static

◆ TIME_uptime_ms_from_tim6

volatile uint32_t TIME_uptime_ms_from_tim6
extern