View previous topic :: View next topic |
Author |
Message |
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Tue Aug 04, 2015 9:41 am |
|
|
Ttelmah wrote: | Questions:
How does the code 'know' where the data block ends?.
What has to happen for the different commands?.
There is a big problem with the CRC calculation. As written, it can generate an ETX character. This could be disastrous. |
1.How does the code 'know' where the data block ends?.
if(rxBuff[index-1]==etxPC)
2.What has to happen for the different commands?.
This is not complete program!
3.There is a big problem with the CRC calculation. As written, it can generate an ETX character.
With This example crc calc is not perform yet. But what is the problem ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19242
|
|
Posted: Tue Aug 04, 2015 10:56 am |
|
|
Imagine you have 208 in the sum so far, and then a '1' is sent (49). This will add to 257. This then adds another 1 to the sum (258), for the carry, and takes the low eight bits, and gets 2. ETX. So your CRC sends as ETX. Result everything starts to go wrong.... |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Tue Aug 04, 2015 1:47 pm |
|
|
Ttelmah wrote: | Imagine you have 208 in the sum so far, and then a '1' is sent (49). This will add to 257. This then adds another 1 to the sum (258), for the carry, and takes the low eight bits, and gets 2. ETX. So your CRC sends as ETX. Result everything starts to go wrong.... |
ETX=0xE3;
Code: |
if (temp<224)
checksum=temp;
else
checksum=temp-224; |
|
|
|
|