again another try

pull/14/head
Tom Early 6 years ago
parent a9ead933fd
commit 219967f800

@ -640,17 +640,17 @@ void CQnetGateway::ProcessG2Msg(const unsigned char *data, const int mod)
static unsigned int part[3] = { 0 }; static unsigned int part[3] = { 0 };
static char txt[3][21]; static char txt[3][21];
if ((data[0] != 0x55u) || (data[1] != 0x2du) || (data[2] != 0x16u)) { if ((data[0] != 0x55u) || (data[1] != 0x2du) || (data[2] != 0x16u)) {
unsigned int c[3]; const unsigned int c[3] = {
c[0] = data[0] ^ 0x70u; data[0] ^ 0x70u,
c[1] = data[1] ^ 0x4fu; data[1] ^ 0x4fu,
c[2] = data[2] ^ 0x93u; // unscramble data[2] ^ 0x93u
printf("c=0x%02x 0x%02x 0x%02x\n", c[0], c[1], c[2]); }; // unscramble
if (part[mod]) { if (part[mod]) {
// we are in a message // we are in a message
if (part[mod] % 2) { // true when part[mod] = 1, 3, 5 or 7 if (part[mod] % 2) { // true when part[mod] = 1, 3, 5 or 7
// this is the second part of the 2-frame pair // this is the second part of the 2-frame pair
memcpy(txt[mod]+(5u*(part[mod]/2u)+2u), c, 3); // offset is 2, 7, 12 or 17 memcpy(txt[mod]+(5u*(part[mod]/2u)+2u), c, 3); // offset is 2, 7, 12 or 17
printf("part[%d]=%u Msg='%s'\n", mod, part[mod], txt[mod]); printf("c=0x%02x 0x%02x 0x%02x part[%d]=%u Msg='%s'\n", c[0], c[1], c[2], mod, part[mod], txt[mod]);
if (++part[mod] > 7) { if (++part[mod] > 7) {
// we've got everything! // we've got everything!
part[mod] = 0; // now we can start over part[mod] = 0; // now we can start over
@ -658,7 +658,7 @@ void CQnetGateway::ProcessG2Msg(const unsigned char *data, const int mod)
} else { // we'll get here when part[mod] = 2, 4 or 6 } else { // we'll get here when part[mod] = 2, 4 or 6
unsigned int sequence = part[mod]++ / 2; // this is the sequency we are expecting, 1, 2 or 3 unsigned int sequence = part[mod]++ / 2; // this is the sequency we are expecting, 1, 2 or 3
if ((sequence | 0x40u) == c[0]) { if ((sequence | 0x40u) == c[0]) {
printf("part[%d]=%u Msg='%s'\n", mod, part[mod]-1u, txt[mod]); printf("c=0x%02x 0x%02x 0x%02x part[%d]=%u Msg='%s'\n", c[0], c[1], c[2], mod, part[mod]-1u, txt[mod]);
memcpy(txt[mod]+(5u*sequence), c+1, 2); // got it! get the copy the two chars memcpy(txt[mod]+(5u*sequence), c+1, 2); // got it! get the copy the two chars
} else { } else {
part[mod] = 0; // unexpected part[mod] = 0; // unexpected
@ -666,9 +666,9 @@ void CQnetGateway::ProcessG2Msg(const unsigned char *data, const int mod)
} }
} else if (0x40u == c[0]) { } else if (0x40u == c[0]) {
// start of new message // start of new message
memset(txt[mod], 0, 21);
memcpy(txt[mod], c+1, 2); memcpy(txt[mod], c+1, 2);
memset(txt[mod]+2, 0, 19); printf("c=0x%02x 0x%02x 0x%02x part[%d]=%u Msg='%s'\n", c[0], c[1], c[2], mod, part[mod], txt[mod]);
printf("part[%d]=%u Msg='%s'\n", mod, part[mod], txt[mod]);
part[mod] = 1; part[mod] = 1;
} }
} else { } else {

Loading…
Cancel
Save

Powered by TurnKey Linux.