Skip to content

Instantly share code, notes, and snippets.

@goebish
Last active November 29, 2018 09:42
Show Gist options
  • Save goebish/d08d9a7458cc34eafe5cc6f64bf34ceb to your computer and use it in GitHub Desktop.
Save goebish/d08d9a7458cc34eafe5cc6f64bf34ceb to your computer and use it in GitHub Desktop.
#include <QtCore/QCoreApplication>
#include <stdio.h>
#include <stdint.h>
#include "qfile.h"
// xn297 scramble table
static const uint8_t xn297_scramble[] = {
0xe3, 0xb1, 0x4b, 0xea, 0x85, 0xbc, 0xe5, 0x66,
0x0d, 0xae, 0x8c, 0x88, 0x12, 0x69, 0xee, 0x1f,
0xc7, 0x62, 0x97, 0xd5, 0x0b, 0x79, 0xca, 0xcc,
0x1b, 0x5d, 0x19, 0x10, 0x24, 0xd3, 0xdc, 0x3f,
0x8e, 0xc5, 0x2f};
uint8_t bit_reverse(uint8_t b_in)
{
uint8_t b_out = 0;
for (uint8_t i = 0; i < 8; ++i) {
b_out = (b_out << 1) | (b_in & 1);
b_in >>= 1;
}
return b_out;
}
int main(int argc, char *argv[])
{
if(argc<2 || !(QFile::exists(argv[1]))) {
printf("no input file\npress return to exit");
getchar();
return 1;
}
QFile in_file(argv[1]);
in_file.open(QIODevice::ReadOnly);
uint8_t byte, bit_count, byte_count;
bool in_packet = false;
uint8_t address_length = 5;
uint8_t packet_size = 19;
for(;;)
while(!in_file.atEnd()) {
char bit;
in_file.read(&bit, 1);
if((bit & 0x02) && !in_packet ) { // found correlate access code bit (1st bit of address)
byte = 0;
bit_count = 0;
byte_count = 0;
in_packet = true;
// adress | data
// CC CC CC CC CC AA D7 23 63 27 FF FF FF FF D0 07 D0 07 E8 03 E8 03 11 00
}
if(in_packet) {
if(bit & 0x01) {
byte |= 1 << (7-bit_count);
}
bit_count++;
if(bit_count > 7) {
if(byte_count < address_length)
byte = byte ^ xn297_scramble[byte_count];
else
byte = bit_reverse(byte) ^ bit_reverse(xn297_scramble[byte_count]);
if(byte_count == address_length)
printf("| ");
printf("%02x ", byte);
bit_count = 0;
byte = 0;
byte_count++;
if(byte_count == address_length + packet_size) {
in_packet = false;
printf("\n");
}
}
}
}
in_file.close();
printf("press return to exit");
getchar();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment