This one has me stumped.
What I'm trying to do is store an array in my Arduino, that gets updated with sensor values. These values are unsigned integers.
When the computer requests, I want to send back the array. I am trying to cut back on how much code is used. When sending back data to the computer, I "encapsulate" it by first sending each "packet" with a byte indicating the size of the data to follow.
This isn't working, and I think that it might be more simple if I were to just send the whole array as one string.
Before, I had something like this: (excerpts)
const int logSize = 127;
int localLog[logSize]; // Data while pc is off
..
for (int adcCount=0; adcCount <= logSize; adcCount++) {
sendData(localLog[adcCount]);
}
where that sendData is a function to encapsulate the data. that in itself takes up a lot of resources, so I was thinking if I could send the whole array back to the computer without all these loops, that'd be great.
problems with storing data comes in unsigned integers led to the change to that data type.
A separate program, created solely for the purposes of figuring out this challenge, goes like this:
int unsigned fubar[5];
After asking around on IRC for some syntax help, someone brought me to this:
Serial.print(reinterpret_cast<char*>(fubar));
with my array filled with numbers greater than 255, this works great, and sends back 14 bytes representing the values inside this array.
Problems were encountered, however, when a value of 255 or less was in one of these array elements. This is, because if an integer is less than 255, stored in memory it's "most significant byte" would be zero, indicating end of the string I am sending.
So, I want to send this whole array over, expecting some of the values to contain and translate to character zero, which causes the transmission to cease. Of course I know how much data in the end I will be transmitting, but I could not find any routines that let me tell the serial print function that I am passing it a string/char array, and specify the length.
Therefore, if at any where in my array something less than 256 exists, it interrupts the serial communication and my array is not received on the other end, in full.
So my question is, when sending a string (for example) that contains character 0, but is not intended to mark the end of the string, how would I send to the PC the whole entire string?
I did not see in HardwareSerial.h a definition of the print function also accepting the length of the data to be transmitted. How do you go about sending a full string, even if it has these characters in it?
My reason for this packetization is so that my PC software end of the contraption can discriminate between discrete responses to its requests.
TIA