1 // Bodet BT-6000 decoder.
11 void process(const string &buf)
13 unsigned char checksum = 0;
14 for (size_t i = 1; i <= buf.size() - 2; ++i) {
18 if (checksum < 0x20) {
21 if (checksum != buf.back()) {
22 // fprintf(stderr, "discarding message with broken checksum: [%s] [%x vs. %x]\n", buf.c_str(), checksum, buf.back());
24 string realmsg = buf.substr(3, buf.size() - 5);
25 fprintf(stderr, "msg: [%s]\n", realmsg.c_str());
29 int main(int argc, char **argv)
31 // TODO: open serial port
37 int ret = read(0, &ch, 1);
43 fprintf(stderr, "short read\n");
51 if (buf.size() == 1) {
57 if (buf.size() == 2) {
60 buf.clear(); // STX out-of-order
65 if (!buf.empty() && buf.back() == 3) { // Last was ETX, so this is LTC.
73 if (buf.size() >= 4) {
76 buf.clear(); // ETX out-of-order