polybassa/Wifly_Light — pull request #24 by tawarisch (2012-11-06 23:51:06+00:00)
Title: Pic18 master

Making RingBuf a "class" was a very good idea. The only thing i had to adjust was your makro usage
Macro(param) param ## something is not working with gcc! And not necessary as you can see with my solution. However its still not nice, because we cannot see if RingBufXYZ is a macro or a function. Next step should be to make all macros functions or at least adjust the macros to use pointers too! like:
Macro(param) (param)->something then we will call the macro exactly like the other RingBuf functions:

Macro(&g_RingBuf)

To Crc:
I fixed the problem. I was introduced, when I simplified the UnmaskControlCharacters function. Intheory Crc validation is very easy because if you add the crc to itself you get zero. So if crc in the bootloader response would be in network byte order we could just read all bytes one by one and add them to the crc checksum. And at the end the checksum has to be 0. But since the bootloader sends the low crc byte first this simple adding of bytes does not work (I didnt checked that before because I had no real HW in the train). To keep the crc calculation simple i just safe the last two versions of the crc so i have three crcs. crc is the current crc. preCrc is the previous crc without the latest added byte and prepreCrc is the crc before the last two bytes were added. To compare the checksum I just build the checksum for the full message and than just take prepreCrc which is the crc before the crc from the datastream was added. Now, i can add the datastream crc in the correct order and will get zero if the checksum is correct.