- #1
Rx7man
- 425
- 189
I'm working on a turbocharger controller that has to do a lot of real-time (well, close to it) work, it's powered by an Arduino Mega 2560, which has lots of memory, but is quite stingy on processing power.. and to make it harder, transfer has to be done over a serial port to another unit (another Arduino, Raspberry pi, or laptop) to display the current parameters.
It will also have to take data back from whatever unit is connected to it such as tuning parameters and apply them to the program or save to EEPROM.
The data will be a mix of types.. integer, floats, signed, unsigned, and possibly arrays of them or custom data types as well.
I'm looking for guidelines on how to set this up... Currently, I'm looking at a 'packet' that looks somewhat like this
Start marker, 1 byte, probably 0xFF or 0xFE
Sender Address, 1 byte (optional)
Destination address, 1 byte, 0xFF for broadcast (optional)
Packet length, 1 byte (will limit packet size to 255 bytes, yes, I'm OK with that)
Data XXX bytes
Checksum 1 byte (will be a simple one)
Finish marker, 1 byte, probably be 0xFF
That will take care of the sending and receiving of the data, but I will need to do post-processing on it, so the data shown above will contain other things..
I'm thinking of setting it up like this
Data type = Byte 1, indicates the type of data that follows,.. integer, float, signed, or custom.
Destination = Byte 2,3... Where or what do do with this packet of data
I am thinking of using a 'union' to get the bitwise representation of floating point numbers and other types to reduce string parsing.
Arrays will need an additional byte to indicate the length, otherwise they'll be similar
Strings will be handled as character arrays, so no change there except.
I will probably have some method of invoking functions and commands.. such as 'save to eeprom', Reset, Recalibrate, etc.. That can be a data type as well with it's own handlerIs there anything glaring that I'm missing.. perhaps something I should consider, or reconsider?
I enjoy learning the logic of doing it, I'm not very good at C flavored programming, but have moderate knowledge on VB.. I have tried very hard to learn how to be OO, and am starting to 'get it'. I like writing my own code, even if it might not always be the best available, I'll learn how to make it better over time.
It will also have to take data back from whatever unit is connected to it such as tuning parameters and apply them to the program or save to EEPROM.
The data will be a mix of types.. integer, floats, signed, unsigned, and possibly arrays of them or custom data types as well.
I'm looking for guidelines on how to set this up... Currently, I'm looking at a 'packet' that looks somewhat like this
Start marker, 1 byte, probably 0xFF or 0xFE
Sender Address, 1 byte (optional)
Destination address, 1 byte, 0xFF for broadcast (optional)
Packet length, 1 byte (will limit packet size to 255 bytes, yes, I'm OK with that)
Data XXX bytes
Checksum 1 byte (will be a simple one)
Finish marker, 1 byte, probably be 0xFF
That will take care of the sending and receiving of the data, but I will need to do post-processing on it, so the data shown above will contain other things..
I'm thinking of setting it up like this
Data type = Byte 1, indicates the type of data that follows,.. integer, float, signed, or custom.
Destination = Byte 2,3... Where or what do do with this packet of data
I am thinking of using a 'union' to get the bitwise representation of floating point numbers and other types to reduce string parsing.
Arrays will need an additional byte to indicate the length, otherwise they'll be similar
Strings will be handled as character arrays, so no change there except.
I will probably have some method of invoking functions and commands.. such as 'save to eeprom', Reset, Recalibrate, etc.. That can be a data type as well with it's own handlerIs there anything glaring that I'm missing.. perhaps something I should consider, or reconsider?
I enjoy learning the logic of doing it, I'm not very good at C flavored programming, but have moderate knowledge on VB.. I have tried very hard to learn how to be OO, and am starting to 'get it'. I like writing my own code, even if it might not always be the best available, I'll learn how to make it better over time.