This is what I am finding so far. I prefer it this way though because I am not actually saving any sim variables in a struct. Rather, in each simvar object I am saving a pointer to an element in array of double ( to ensure proper alignment, but the pointer can be cast to any size in case the size of the data returned is different from float64). That way regardless of the number of bytes needed to store the value, all I need to do is do pointer math to point the next index to however many bytes past the current index. It has the added advantage of being able to copy a big blob of data in one memcpy operation when the request ID is returned. All my variables are in one package definition.
I agree. That would probably be horrendous to try to send a ton of those values down the serial line to an Arduino. Which is why I come up with a bit packing technique to compress the variables into 2 bytes. It only deals with cases that I expect to encounter. Numbers less than 16384 can have a sign ( i.e. vertical speed can’t possibly be greater than 16000 right? If you have VS of -20,000, game over, you are probably screaming as your plane is plummeting to the ground ); numbers below 256 can have 2 decimal places ( i.e. 108.55 Mhz ) but always positive; numbers above 16384 are stored as a square root with a decimal so squaring ( to decode back to float ) will lose some precision but when dealing with altitudes for example, the difference is not significant.
I am trying to make the configuration of the data definition to be demand driven. If an arduino requests a simvar, it gets activated and put in the data definition. If a simvar is not requested for a number of cycles, it gets deactivated and removed from the data definition. It could still work but now I have to redo the whole definition package instead of making tweaks.
I will now be working on the serial communication stuff. Any pointers from people who have gone down that road already? This will be for talking to an arduino via a comm port. I have read that it must be put on a separate thread at least.
I have found this:
Thanks,
Chris