hollyhock
Classes | Macros | Functions | Variables
mcs.hpp File Reference

Functions for retrieving and setting data in the MCS. More...

#include <stdint.h>
Include dependency graph for mcs.hpp:

Go to the source code of this file.

Classes

struct  OBCD
 
struct  CBCD
 

Macros

#define GET_BCD_DIGIT(n, i)   (((n) >> ((i) * 4)) & 0xF)
 

Functions

int MCS_CreateFolder (const char *folder, uint8_t *folderIndex)
 
int MCS_GetVariable (const char *folder, const char *name, uint8_t *variableType, char **name2, void **data, uint32_t *size)
 
int MCS_List_Create (const char *folder, const char *name, uint32_t size, uint16_t length, uint8_t variableType)
 
int MCS_List_Set (const char *folder, const char *name, uint32_t size, int index, uint8_t variableType, void *data)
 
int MCS_SetVariable (const char *folder, const char *name, uint8_t variableType, uint32_t size, void *data)
 

Variables

const uint8_t VARTYPE_OBCD = 0x01
 
const uint8_t VARTYPE_CBCD = 0x02
 
const uint8_t VARTYPE_STR = 0x05
 
const uint8_t VARTYPE_LIST = 0x0A
 
const uint8_t VARTYPE_MAT = 0x0C
 
const uint8_t VARTYPE_PRGM = 0x47
 
const uint8_t VARTYPE_FUNC = 0x48
 
const uint8_t VARTYPE_GEO = 0x54
 
const int MCS_NO_VARIABLE = 0x30
 
const int MCS_NO_FOLDER = 0x40
 
const int MCS_FOLDER_EXISTS = 0x42
 
const int MCS_SIZE_NOT_PO2 = 0x61
 
const int MCS_NOT_LIST = 0x62
 
const int MCS_INDEX_OOB = 0x63
 

Detailed Description

Functions for retrieving and setting data in the MCS.

Macro Definition Documentation

◆ GET_BCD_DIGIT

#define GET_BCD_DIGIT (   n,
 
)    (((n) >> ((i) * 4)) & 0xF)

Retrieves the BCD digit at position i (0 representing the least significant place) from a BCD encoded number n.

Parameters
nThe number to retrieve a digit from.
iThe index of the digit to retrieve.

Function Documentation

◆ MCS_CreateFolder()

int MCS_CreateFolder ( const char *  folder,
uint8_t *  folderIndex 
)

Creates a folder in the MCS.

If the folder name is greater than the 8 character max, it is truncated to a valid length.

The folderIndex parameter is still populated if the folder already exists. However, its purpose is currently unknown.

Parameters
[in]folderThe name of the folder to create.
[out]folderIndexAn unknown index for the folder.
Returns
0 if the folder was created successfully, or MCS_FOLDER_EXISTS if the folder already exists.

◆ MCS_GetVariable()

int MCS_GetVariable ( const char *  folder,
const char *  name,
uint8_t *  variableType,
char **  name2,
void **  data,
uint32_t *  size 
)

Retrieves information about a variable stored in the MCS.

Parameters
[in]folderThe folder the requested MCS variable is located in.
[in]nameThe name of the requested MCS variable.
[out]variableTypeThe variable's type.
[out]name2The variable's name.
[out]dataA pointer to the variable's data.
[out]sizeThe length of the variable's data.
Returns
0 if the variable exists, MCS_NO_VARIABLE if the variable does not exist, or MCS_NO_FOLDER if the folder does not exist.

◆ MCS_List_Create()

int MCS_List_Create ( const char *  folder,
const char *  name,
uint32_t  size,
uint16_t  length,
uint8_t  variableType 
)

Creates a list variable in the MCS.

The list is initially populated with the default value of the variable type specified. If the variable already exists, it is overwritten (even if it's not a list).

Parameters
[in]folderThe folder to create the list in.
[in]nameThe desired name of the variable.
sizeThe size of the variable type specified.
lengthThe number of entries in the list.
variableTypeThe variable type to initialize the list with (macros starting with VARTYPE).
Returns
0 on success, MCS_NO_FOLDER if the requested folder does not exist.

◆ MCS_List_Set()

int MCS_List_Set ( const char *  folder,
const char *  name,
uint32_t  size,
int  index,
uint8_t  variableType,
void *  data 
)

Sets an element of a list in the MCS.

Parameters
[in]folderThe folder containing the list variable.
[in]nameThe name of the list variable.
sizeThe size of the data to store in the element.
indexThe index into the list of the element to modify.
variableTypeThe type of the data to be stored in the list element (macros starting with VARTYPE).
[in]dataThe data to copy into the list element.
Returns
0 on success, MCS_NO_FOLDER if the requested folder does not exist, MCS_NO_VARIABLE if the variable does not exist, MCS_NOT_LIST if the variable was not a list, or MCS_INDEX_OOB if the index was out of bounds.

◆ MCS_SetVariable()

int MCS_SetVariable ( const char *  folder,
const char *  name,
uint8_t  variableType,
uint32_t  size,
void *  data 
)

Sets the value of a variable stored in the MCS. Can be used to create a new variable, or replace the value of an existing variable.

This function does not create the folder if it does not exist. Use MCS_CreateFolder to create a folder if necessary.

Parameters
[in]folderThe folder the variable to set it stored in.
[in]nameThe name of the desired MCS variable.
variableTypeThe type of the variable (macros starting with VARTYPE).
sizeThe size of the variable's data.
[in]dataA pointer to the data to copy into the variable.
Returns
0 if the variable was set successfully, or MCS_NO_FOLDER if the specified folder does not exist.

Variable Documentation

◆ MCS_FOLDER_EXISTS

const int MCS_FOLDER_EXISTS = 0x42

Error code signaling that the folder already exists.

◆ MCS_INDEX_OOB

const int MCS_INDEX_OOB = 0x63

Error code signaling that the index was out of bounds.

◆ MCS_NO_FOLDER

const int MCS_NO_FOLDER = 0x40

Error code signaling that the folder does not exist.

◆ MCS_NO_VARIABLE

const int MCS_NO_VARIABLE = 0x30

Error code signaling that the variable does not exist.

◆ MCS_NOT_LIST

const int MCS_NOT_LIST = 0x62

Error code signaling that the variable was not a list.

◆ MCS_SIZE_NOT_PO2

const int MCS_SIZE_NOT_PO2 = 0x61

Error code signaling that the specified size was not a power of 2.

◆ VARTYPE_CBCD

const uint8_t VARTYPE_CBCD = 0x02

Variable type: CBCD (struct CBCD).

◆ VARTYPE_FUNC

const uint8_t VARTYPE_FUNC = 0x48

Variable type: function.

◆ VARTYPE_GEO

const uint8_t VARTYPE_GEO = 0x54

Variable type: geometry data.

◆ VARTYPE_LIST

const uint8_t VARTYPE_LIST = 0x0A

Variable type: list.

◆ VARTYPE_MAT

const uint8_t VARTYPE_MAT = 0x0C

Variable type: matrix.

◆ VARTYPE_OBCD

const uint8_t VARTYPE_OBCD = 0x01

Variable type: OBCD (struct OBCD).

◆ VARTYPE_PRGM

const uint8_t VARTYPE_PRGM = 0x47

Variable type: program.

◆ VARTYPE_STR

const uint8_t VARTYPE_STR = 0x05

Variable type: null-terminated string.