LogUtilities 1.5.1
A small compiled library for C logging and configuration utility functions.
Loading...
Searching...
No Matches
File Input/Output

Functions for making it easier to create/access files. The LogUtilities let the user read from config.yaml so long as there is only a simple yaml syntax (i.e. no nested structures), and only handles explicitly-enumerated field name conventions.
More...

Data Structures

struct  HeaderData
 Structure to store header data. More...
 
struct  Config
 Structure to store configuration data parsed from yaml files.
More...
 

Functions

void containerFolder (char *filePathFS, int levelsUp)
 Retrieves the container folder of a file path up to a specified number of levels.
 
int createFolderIfNotExists (const char *folderPath)
 Creates a folder at the specified path if it doesn't already exist.
 
void replaceBackslashes (char *filePath, char *filePathFS)
 Replaces backslashes in a file path with forward slashes.
 

Detailed Description

Functions for making it easier to create/access files. The LogUtilities let the user read from config.yaml so long as there is only a simple yaml syntax (i.e. no nested structures), and only handles explicitly-enumerated field name conventions.

For example, config.yaml may take the following format (which includes the correct name syntax for valid yaml variables):

# Put this config.yaml in same folder as `NHP_Wrist_State_Server.exe`
# Controller Device IP Address (runs UI to control state machine)
ControllerDeviceIP: 127.0.0.1
# Default parameters file to load for file-based initialization
DefaultParametersFile: C:\Data\Parameters\Default\example_parameters.txt
# Folder where logs can be read from (for playback/debug etc.)
LogReadFolder: C:\Data\TaskLogs
# Folder where the logs will be saved
LogSaveFolder: C:\Data\TaskLogs
# Folder where the parameters are saved
ParameterSaveFolder: C:\Data\Parameters
# Plexon Device IP Address (for the machine running neural data acquisition)
PlexonDeviceIP: 127.0.0.1
# Render Device IP Address (i.e. the Jetson rendering the task)
RenderDeviceIP: 127.0.0.1
# Reward Device IP Address (i.e. some device connected to microcontroller with reward dispenser)
RewardDeviceIP: 127.0.0.1
# Server Device IP Address (i.e. any host device running task state server)
ServerDeviceIP: 127.0.0.1
# Starting port (i.e. for 3070, will use 3070-3079 so ensure they are open!)
StartPort: 3070

Function Documentation

◆ containerFolder()

void containerFolder ( char * filePathFS,
int levelsUp )

Retrieves the container folder of a file path up to a specified number of levels.

This function modifies the provided file path string to represent the container folder up to the specified number of levels. It replaces the characters beyond the container folder with a null terminator ('\0').

Parameters
filePathFSThe file path for which the container folder is to be determined. This string should use forward slashes ('/') as path separators.
levelsUpThe number of levels up from the file path to consider for the container folder. A value of 0 indicates the immediate parent folder, 1 indicates one level up, and so on.

◆ createFolderIfNotExists()

int createFolderIfNotExists ( const char * folderPath)

Creates a folder at the specified path if it doesn't already exist.

This function handles various error cases such as existing folders and non-existing parent directories.

Parameters
folderPathThe path of the folder to create.
Returns
0 if the folder was created successfully or already exists, 1 otherwise.

◆ replaceBackslashes()

void replaceBackslashes ( char * filePath,
char * filePathFS )

Replaces backslashes in a file path with forward slashes.

This function ensures cross-platform compatibility in file paths.

Parameters
filePathThe original file path.
filePathFSThe file path with backslashes replaced by forward slashes.