Copying structs by bytes:
- At first I had it so that I was setting pointers for each struct and then casting the pointers into a char*. Putting a & in front of the struct name returns the address of the struct eliminating the need for the extra pointers. ex: char* test = (char*) originalData
- Another thing that was wrong was that I was getting the size by measuring the length of the character array. This worked fine when I was using unsigned chars as data members but when I changed it to int things broke. The proper way to do it seems to be sizeof(structName). This has worked consistently no matter what the data types were including non-primitive string type. (NOTE: to use string with printf, the c_str() method needs to be called to format it properly.)
- sizeof(somePtr) seems to always return 4 bytes which I assume is the size of the memory address. This may be why we were having trouble with sizeof because we were taking the size of a char*, if we were looking for a sizeof(char[]) it would have probably worked. I tried to find the sizeof the contents of the pointer and it also said 4 bytes. This might have been because the address it was pointing to was type int. Either way it wasn’t giving the full size of the allocation which was 12 as found by sizeof(struct) which makes sense considering it had 3 ints in it.
ComMgr:
- It seems I can put the memory address into a void pointer so that send data won’t have to worry about what type it is. The size will also have to be passed in because its hard to get the size from the pointer.
- The type needs to be identified so the arduino will know what to do with the data.
- Just noticed WriteFile is taking the address of the object and the next parameter is the size. So I guess you can pass anything you want into it as long as you know the size.
- Have it working with the objectPtr and the size but its still only working with one byte.
Arduino
- Phil recommended that there be 4 states for the arduino: Ready, Reading, Converting, and Writing. We may need a 5th for executing once it has to actually do stuff but for communications this should do. He also suggested putting 4 leds and indicators of each state so we don’t have to depend on the console to tell us during the debugging phase.
- Had to change the write method on the arduino side to print for whatever reason. Have to look into why this suddenly stopped working tomorrow.
