foxsi / foxsi-4matter

Code for FOXSI-4 formatter.
https://foxsi.umn.edu/
1 stars 3 forks source link

De-string variable-length memory addresses correctly from JSON #26

Open thanasipantazides opened 1 year ago

thanasipantazides commented 1 year ago

The trouble

In *_commands.json command files, there are fields like this:

"address":"0x00"

When they are parsed into a std::vector<uint8_t> by string_to_chars(std::string hex_str), the written string length in the JSON will be preserved. The problem is that this length passes directly to the SpaceWire packet constructing functions, and results in a too-short SpaceWire address field if the JSON addresses are not explicitly written 4 B long.

Fix

When parsing out the command file JSON, guarantee the result stored in Command is 4 B long. This is done in CommandDeck::add_commands().

thanasipantazides commented 1 year ago

For now, this is mitigated by writing all memory addresses in the source .xlsx files (in foxsi4-commands) as 4 byte long.