OSFI-C  3.10.0
OpenSF Integration Library
ConFM.c

Basic usage of the ConFM module to read values from configuration files.

#include <OSFIC.h>
// Example external function using the values from the parameters
bool dcm2quat(double out[4], double* in, int stride);
int main(int argc, char* argv[]) {
// Open two different configuration files, and validate the latter against a schema
if (!gcf || !lcf || osfiConFmValidateSchema(lcf, NULL) != OSFI_CONFM_VAL_PASSED) {
osfiLoggerError("Error parsing or validating configuration files!");
return 1;
}
// Read some parameters from both files, with some value checks
osfi_ownstr_t* scName;
double dragCoef;
osfi_matDouble_t* i2b; // inertial-to-body rotation matrix
if (!osfiConFmParamValue(&scName, gcf, "satellite.name")) {
osfiLoggerError("Cannot read S/C name");
return 1;
}
// Checks on the value can be made after the GetValue call, in the same conditional
if (!osfiConFmParamValue(&dragCoef, lcf, "integration.drag.cd") || dragCoef < 0) {
osfiLoggerError("Invalid drag coefficient value");
return 1;
}
if (!osfiConFmParamValue(&i2b, lcf, "att.dcm0") || i2b->rows != 3 || i2b->cols != 3) {
osfiLoggerError("Invalid I2B rotation matrix values or size");
return 1;
}
// More checks on the values, more parameters, etc.
// The syntax is uniform for all types: first check the bool return, then the output argument.
osfiLoggerInfo("Simulation for satellite: %s with Cd=%f", scName->value, dragCoef);
// Example external function using the values
double attQ[4];
if (!dcm2quat(attQ, i2b->values, 3)) {
osfiLoggerError("Cannot convert rotation matrix to quaternion form");
return 1;
}
osfiLoggerInfo("Initial attitude: [%f, %f, %f, %f]", attQ[0], attQ[1], attQ[2], attQ[3]);
// More module computations using the values of the parameters
// Close the files, releasing all memory allocated by ConFM. This is only relevant if not done
// right at the end i.e. if the module extracts the data from OSFI into its own structures (like
// attQ here), closes the configuration files, and then keeps processing.
osfiConFmCfgFileClose(gcf); // gcf and scName are released
osfiConFmCfgFileClose(lcf); // lcf and i2b are released (not dragCoef, as it was not allocated)
return 0;
}
// Dummy definition of the "external" function above
bool dcm2quat(double out[4], double* in, int stride) {
return false;
}
OSFI-C public API header.
void osfiConFmCfgFileClose(osfi_paramreader_t *pr)
Closes the configuration file pointed by pr and releases all resources tied to it.
struct osfi_paramreader osfi_paramreader_t
Opaque type representing an open configuration file.
Definition: OSFIC.h:211
#define osfiConFmParamValue(dest, pr, param)
Value getter for non-ARRAY parameters.
Definition: OSFIC.h:364
enum osfi_confm_val_res osfiConFmValidateSchema(osfi_paramreader_t *pr, const char *schemaFile)
Performs validation of the given configuration file against a schema document.
osfi_paramreader_t * osfiConFmCfgFileOpen(const char *path)
Parses the configuration file at path and returns a handle to it.
@ OSFI_CONFM_VAL_PASSED
Definition: OSFIC.h:219
void osfiLoggerInfo(const char *format,...)
void osfiLoggerError(const char *format,...)
Matrix of floating point values, with dimension sizes and contents.
Definition: OSFIC.h:296
double values[]
Data in row-major order, up to rows*cols-1.
Definition: OSFIC.h:296
int cols
Number of columns, never negative.
Definition: OSFIC.h:296
int rows
Number of rows, never negative.
Definition: OSFIC.h:296
String allocated by OSFI.
Definition: OSFIC.h:257
char value[]
String data, null terminated.
Definition: OSFIC.h:257