2022-03-22 20:26:15 +00:00
|
|
|
#include <stdio.h>
|
2022-04-29 19:11:10 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
2022-03-22 20:26:15 +00:00
|
|
|
#include "bch.h"
|
2022-04-04 22:53:27 +00:00
|
|
|
#include "eotd.h"
|
|
|
|
#include "eotd_defs.h"
|
|
|
|
|
|
|
|
void dump(uint8_t *bytes, char type) {
|
|
|
|
unsigned char eotd[9];
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
eotd[i] = bytes[i] & 0xff;
|
|
|
|
}
|
|
|
|
eotd[8] = type;
|
|
|
|
// Slice packet
|
|
|
|
char buffer[512];
|
|
|
|
eotd_to_text(eotd, 9, buffer, sizeof(buffer));
|
|
|
|
printf("%s\n", buffer);
|
|
|
|
};
|
|
|
|
|
|
|
|
void rotate_bytes(uint8_t *src, uint8_t *dest, int count) {
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
dest[count - i - 1] = rotate_byte(src[i]);
|
|
|
|
}
|
|
|
|
}
|
2022-03-22 20:26:15 +00:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
bch_t bch;
|
2022-04-04 22:53:27 +00:00
|
|
|
uint8_t bytes[8];
|
|
|
|
int m, length, t;
|
|
|
|
int count = 0;
|
|
|
|
int rev = 0;
|
|
|
|
char type = EOTD_TYPE_R2F;
|
|
|
|
|
2022-03-22 20:26:15 +00:00
|
|
|
|
2022-04-04 22:53:27 +00:00
|
|
|
if (argc < 5) {
|
|
|
|
fprintf(stderr, "Expecting 4+ arguments - m, length, t, type (F or R) and optionally rev to reverse the input bytes.\n");
|
2022-04-09 17:03:51 +00:00
|
|
|
fprintf(stderr, "THE BCH CODE IS NOT VERIFIED!\n");
|
2022-03-22 20:26:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-04-04 22:53:27 +00:00
|
|
|
sscanf(argv[1], "%d", &m);
|
|
|
|
sscanf(argv[2], "%d", &length);
|
|
|
|
sscanf(argv[3], "%d", &t);
|
|
|
|
sscanf(argv[4], "%c", &type);
|
|
|
|
|
|
|
|
if (argc > 5) {
|
|
|
|
if (strcasecmp(argv[5], "rev") == 0) {
|
|
|
|
rev = 1;
|
|
|
|
}
|
2022-03-22 20:26:15 +00:00
|
|
|
}
|
2022-04-04 22:53:27 +00:00
|
|
|
|
|
|
|
init_bch(&bch, m, length, t);
|
|
|
|
|
2022-03-22 20:26:15 +00:00
|
|
|
while (1) {
|
|
|
|
for (int i = 0; i < 8; i++) {
|
2022-04-04 22:53:27 +00:00
|
|
|
int t;
|
|
|
|
int status = scanf("%x ", &t);
|
|
|
|
bytes[i] = t;
|
2022-03-22 20:26:15 +00:00
|
|
|
if (status == EOF) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != 1) {
|
|
|
|
fprintf(stderr, "Error: %d", status);
|
|
|
|
}
|
|
|
|
}
|
2022-04-04 22:53:27 +00:00
|
|
|
if (rev) {
|
|
|
|
uint8_t temp[8];
|
|
|
|
rotate_bytes(bytes, temp, 8);
|
|
|
|
memcpy(bytes, temp, 8);
|
2022-03-22 20:26:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-04 22:53:27 +00:00
|
|
|
printf("%04d,", count++);
|
|
|
|
dump(bytes, type);
|
2022-03-22 20:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|