16#ifndef LOGGING_JSON_CDL_H
17#define LOGGING_JSON_CDL_H
51template <u
int32 NUM_CDLS, u
int32 MAX_JSON_KEY_LEN, u
int32 MAX_JSON_FIELD_LEN>
69 int16
parseCdlFile(
const char* file_data, uint32 file_len);
80 char key[MAX_JSON_KEY_LEN];
99template <u
int32 NUM_CDLS, u
int32 MAX_JSON_KEY_LEN, u
int32 MAX_JSON_FIELD_LEN>
106 if(name ==
nullptr || data_ptr ==
nullptr) {
125template <u
int32 NUM_CDLS, u
int32 MAX_JSON_KEY_LEN, u
int32 MAX_JSON_FIELD_LEN>
128 if(file_data ==
nullptr) {
136 int32 num_tokens =
jsmn_parse(&parser, file_data, file_len, tokens, 2*NUM_CDLS + 1);
137 if (num_tokens < 1) {
149template <u
int32 NUM_CDLS, u
int32 MAX_JSON_KEY_LEN, u
int32 MAX_JSON_FIELD_LEN>
151 if(cdl_info_ptr ==
nullptr || file_data ==
nullptr || json_ptr ==
nullptr) {
160 char value[MAX_JSON_FIELD_LEN];
162 for(int32 i = 1; i < num_tok; i+=2) {
164 key_len = json_ptr[i].
end - json_ptr[i].
start;
165 const char* key = file_data + json_ptr[i].
start;
166 val = json_ptr[i + 1];
168 if(val_len > MAX_JSON_FIELD_LEN) {
171 snprintf(value,
sizeof(value),
"%.*s", val_len, file_data + val.
start);
173 if(key_len == strlen(cdl_info_ptr->
key) && strncmp(cdl_info_ptr->
key, key, key_len) == 0) {
177 int32* write_ptr =
static_cast<int32*
>(cdl_info_ptr->
ptr);
188 floating_point* write_ptr =
static_cast<floating_point*
>(cdl_info_ptr->
ptr);
200 int16 err = converted_ptr->
fromStr(value);
211 int16 err = converted_ptr->
fromStr(value);
Standard vector class derived from Matrix.
Definition CartesianVector.hpp:39
uint32 num_missing
Definition JsonCdl.hpp:73
uint32 num_errors
Definition JsonCdl.hpp:74
int16 parseCdlFile(const char *file_data, uint32 file_len)
Parse a CDL file given at file_data.
Definition JsonCdl.hpp:126
uint32 _storage_index
Definition JsonCdl.hpp:95
JsonCdl()
Definition JsonCdl.hpp:54
~JsonCdl()
Definition JsonCdl.hpp:55
int16 registerCdl(const char *name, cdl_types_e cdl_type, uint8 cdl_size, void *data_ptr)
Register a CDL to be loaded.
Definition JsonCdl.hpp:100
uint32 num_loaded_correct
Definition JsonCdl.hpp:72
_cdl_info_t _cdls[NUM_CDLS]
Storage array for CDLs.
Definition JsonCdl.hpp:96
int16 _loadSingleCdl(const _cdl_info_t *cdl_info_ptr, const char *file_data, jsmntok_t *json_ptr, uint8 num_tok)
Load a single CDL from the json file.
Definition JsonCdl.hpp:150
uint32 num_failed_registries
Definition JsonCdl.hpp:75
int16 fromStr(const char *val)
Set value of matrix from string in same format as str().
Definition Matrix.hpp:341
Quaternion class for attitude representation.
Definition Quaternion.h:68
#define NO_ERROR
Error code in the case where matrix math executed successfully.
Definition clockwerkerrors.h:34
#define ERROR_NULLPTR
Error code in case of a null pointer.
Definition clockwerkerrors.h:60
#define ERROR_DIMENSIONS
Definition clockwerkerrors.h:41
#define ERROR_QUEUE_FULL
Error in case the queue is full.
Definition clockwerkerrors.h:195
#define ERROR_INVALID_RANGE
Definition clockwerkerrors.h:53
#define WARNING_NO_MATCH
Error in the case where dynamics model overruns steps or gets out of whack.
Definition clockwerkerrors.h:185
void jsmn_init(jsmn_parser *parser)
Definition json.cpp:393
int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len, jsmntok_t *tokens, const unsigned int num_tokens)
Definition json.cpp:202
@ JSMN_STRING
Definition json.h:63
Definition CircularBuffer.hpp:28
cdl_types_e
Type definition for CDL types which may be loaded.
Definition JsonCdl.hpp:29
@ INT32_TP
Integer type – can be single value or array.
Definition JsonCdl.hpp:30
@ CARTESIANVECTOR3_TP
Cartesian vector type – is floating_point based.
Definition JsonCdl.hpp:32
@ QUATERNION_TP
Quaternion type – is floating_point based.
Definition JsonCdl.hpp:33
@ FPOINT_TP
floating_point type – can be single value or array
Definition JsonCdl.hpp:31
int16 setArrayFromString(const char *s, T *array, size_t array_size)
Converts a bracket-enclosed comma-separated string to a float array.
Definition stringutils.hpp:230
Hold all info associated with a single CDL.
Definition JsonCdl.hpp:79
void * ptr
Pointer to where to write CDL value.
Definition JsonCdl.hpp:83
char key[MAX_JSON_KEY_LEN]
Key for the CDL.
Definition JsonCdl.hpp:80
cdl_types_e type
Type of the CDL.
Definition JsonCdl.hpp:81
uint8 size
Size of the CDL.
Definition JsonCdl.hpp:82
int end
Definition json.h:85
int start
Definition json.h:84