NMaas:
0x08 0x42 0xC0 0x01 0x00 0x07 0xFF 0xFF as output,
however I get
0x50 0x08 0x07 0x00 0x07 0x00 0xFF 0xFF
It is somehow mixing stuff up and I don't know why.
Any help?
Thank you
You constructed your expected output with incorrect assumptions. For example, bits 0-2 are actually the least significant bits, not the most significant bits of the integer and you have 3 unsigned integers in this structure. Hence, you are populating the bits of each integer beginning with the least significant bits.
Therefore the expected output would be:
0x08 0x50 0x00 0x07 0x00 0x07 0xFF 0xFF
However, this Arduino is little endian so in memory the bytes of each integer are swapped giving:
Hi ToddL, thank you very much for your insightful answer!
I try to implement parts of the CCSDS TM/TC protocol for Arduino ( https://public.ccsds.org/Pubs/133x0b1c2.pdf Page 31 / 4-2) - actually the primary header and added some data to it. My expected value is a known good packet, as it would be used by the processing software - hence I try to transform my generated packet (with the same values as the known good packet) in such a way, that it should match the known good.
I thought I could just take the start position of the pointer of the tm packet, add the size of it and then start from this point reading backwards to reverse the output
unsigned int writePacket (const packet & value)
{
byte * y = (byte*) &value;
*y = *y + sizeof(value);
unsigned int i;
for (i = sizeof value; i > 0; i--)
SerialUSB.write(*y--);
return i;
}
However, this ended in the output of
0x17 0x00 0x00 0x21 0x67 0x20 0x00 0x00
So I am probably still doing something wrong. Any ideas - and thanks a lot!
NMaas:
Hi ToddL, thank you very much for your insightful answer!
I try to implement parts of the CCSDS TM/TC protocol for Arduino ( https://public.ccsds.org/Pubs/133x0b1c2.pdf Page 31 / 4-2) - actually the primary header and added some data to it. My expected value is a known good packet, as it would be used by the processing software - hence I try to transform my generated packet (with the same values as the known good packet) in such a way, that it should match the known good.
So I am probably still doing something wrong. Any ideas - and thanks a lot!
You new prHdr structure looks correct now so all you really need to do is byte swap the header so it is in big endian order. You do not need to mess with the data bytes as long as you are populating the data one byte at a time.
Here is a new pkt_assembly function that does a quick and dirty conversion using the htons (host to network short) function which converts to big endian. You will need to include util.h to use that function.
The code does compile, however, gives out quite a few warnings:
error: operation on 'pHdr_temp' may be undefined [-Werror=sequence-point]
Also, it seems like something is going wrong. I can upload the code to the Arduino Zero, however, it is not recognized as USB device again. Seems like it crashes hard somehow. I need to be quick and double press the reset button to get it back into bootloader mode to upload new code.