I think there's just an error in the description. It looks like they are summing all the bytes between the header and the checksum. And the checksum is just a number that clears the lower 8 bits.So, for the first example, the sum of all bytes between the header and the checksum is 0x0313.
Or.
I think there's just an error in the description. It looks like they are summing all the bytes between the header and the checksum. And the checksum is just a number that clears the lower 8 bits.So, for the first example, the sum of all bytes between the header and the checksum is 0x0313.
Or 0x0313 0000 0011 0001 0011 0x00ED 0000 0000 1110 1101 When it's lined up like that, you can clearly see you'll be zeroing out the lower 8 bits and returning: 0x0400 0000 0100 0000 0000 You didn't specify a language, but you could also quickly calculate your own checksum by doing (0 XOR calculatedSum) + 1.
Aha! I found it. It is including the header.
– Martijn Courteaux Sep 17 at 20:21.
You Sum up all the bytes before the check sum field. Extract the low 8 bits of the sum Find the value("value to make zero"), that, when added to the computed sum becomes 0 (i.e. You solve "x + computed sum = 0") Anyway, this C code computes the correct sum for all your 4 examples: uint8_t silly_chksum(const uint8_t *data, size_t len) { size_t i; unsigned int chk = -1; for(i = 0; I.
Just for fun, I took this as an exercise in writing a simple binary parser using Boost Spirit (c++). I included the conversion from the question format and the checksum verification. I made the parser recognize actual datalength and arbitrary choice of STL container for the packet data.
Output below: #include #include #include #include namespace qi=boost::spirit::qi; namespace karma=boost::spirit::karma; namespace phx=boost::phoenix; typedef unsigned char uchar; static const auto inbyte = qi::uint_parser(); static const auto outbyte = karma::right_align(2,'0') karma::hex ; // for some reason the alignment doesn't 'take' with the above, so HACK: #define outbyte karma::right_align(2,'0') karma::hex struct packet_t { enum { HEADER = 0x02 }; uchar checksum, id; typedef std::string data_t; /// the following work without modification: // typedef std::vector data_t; // typedef std::list data_t; data_t data; uchar do_checksum() const { return (uchar) -std::accumulate(data.begin(), data.end(), HEADER + data.size()); } bool is_valid() const { return checksum == do_checksum(); } }; BOOST_FUSION_ADAPT_STRUCT(packet_t, (packet_t::data_t, data) (uchar, checksum) (uchar, id)); int main() { static const std::string input = "02:0d:be:ef:03:06:00:19:d3:02:00:00:60:00:00:ed:01\n" "02:0d:be:ef:03:06:00:cd:d2:02:00:00:20:00:00:7a:01\n" "02:0d:be:ef:03:06:00:10:f6:02:00:ba:30:00:00:49:01\n" "02:0d:be:ef:03:06:00:c8:d8:02:00:20:30:00:00:49:01\n" "02:08:c8:d8:02:00:20:30:00:00:49:01\n"; // failure test case // convert hex to bytes std::vector > rawpackets; if (!qi::parse(input.begin(), input.end(), (inbyte % ':') % qi::eol, rawpackets)) { std::cerr parser; parser %= byte_(packet_t::HEADER) > omit byte_ _a = _1 // datalen > repeat(_a)byte_ // data > byte_ // checksum > byte_; // id packet_t packet; if (!parse(raw.begin(), raw.end(), parser, packet)) { std::cerr.
If you add up all the hex numbers in the Header, DataLength, CommandData, and CheckSum, it makes 1024. For example, here's the sum of the second example (I skipped the 0x00's): 0x02+0x0d+0xbe+0xef+0x03+0x06+0xcd+0xd2+0x02+0x20+0x7a = 1024 Screenshot (sum is just a javascript function I wrote to sum the hex values automatically): EDIT: It will not necessarily sum to 1024, rather, if it is valid it will sum to a number where the 8 lower bits are 0, such as 1024 (10000000000), 768 (1100000000), and 1280 (10100000000).
This is the solution, but it isn't completely valid. I'm getting as sums 768, 1024 and 1280. – Martijn Courteaux Sep 17 at 20:33 Can you post the packets which are not summing correctly?
Perhaps they were corrupted in transit. All the examples you provided seem to work. (see screenshot added to my post) – someone Sep 17 at 20:46 I added two packets.
– Martijn Courteaux Sep 17 at 20:53 768, 1024 and 1280 are all valid. When the checksum is ok, the lower 8 bits of the sum of the bytes and the checksum byte will be 0. – nos Sep 17 at 21:04 I know.
That's why I wrote "This is the solution". Notice that your last phrase of your comment isn't true. – Martijn Courteaux Sep 17 at 21:07.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.