rs41dm: ecc 2nd pass update

pull/11/head
Zilog80 2019-02-13 21:22:58 +01:00
rodzic a29d3f83f3
commit 19ff0c87dd
2 zmienionych plików z 130 dodań i 83 usunięć

Wyświetl plik

@ -326,6 +326,23 @@ int check_CRC(ui32_t pos, ui32_t pck) {
#define crc_ZERO (1<<6) // LEN variable
#define pck_ZERO 0x7600
#define pck_ZEROstd 0x7611 // NDATA std-frm, no aux
#define pos_ZEROstd 0x12B // pos_AUX(0)
/*
frame[pos_FRAME-1] == 0x0F: len == NDATA_LEN(320)
frame[pos_FRAME-1] == 0xF0: len == FRAME_LEN(518)
*/
int frametype() { // -4..+4: 0xF0 -> -4 , 0x0F -> +4
int i;
ui8_t b = frame[pos_FRAME-1];
int ft = 0;
for (i = 0; i < 4; i++) {
ft += ((b>>i)&1) - ((b>>(i+4))&1);
}
return ft;
}
ui8_t calibytes[51*16];
@ -778,6 +795,8 @@ int get_Aux() {
count7E = 0;
pos7E = pos_AUX;
if (frametype(gpx) > 0) return 0; //pos7E == pos7611 ...
// 7Exx: xdata
while ( pos7E < FRAME_LEN && framebyte(pos7E) == 0x7E ) {
@ -790,7 +809,8 @@ int get_Aux() {
//fprintf(stdout, " # %02x : ", framebyte(pos7E+2));
for (i = 1; i < auxlen; i++) {
fprintf(stdout, "%c", framebyte(pos7E+2+i));
ui8_t c = framebyte(pos7E+2+i);
if (c > 0x1E) fprintf(stdout, "%c", c);
}
count7E++;
pos7E += 2+auxlen+2;
@ -880,20 +900,6 @@ int get_Calconf(int out) {
return 0;
}
/*
frame[pos_FRAME-1] == 0x0F: len == NDATA_LEN(320)
frame[pos_FRAME-1] == 0xF0: len == FRAME_LEN(518)
*/
int frametype() { // -4..+4: 0xF0 -> -4 , 0x0F -> +4
int i;
ui8_t b = frame[pos_FRAME-1];
int ft = 0;
for (i = 0; i < 4; i++) {
ft += ((b>>i)&1) - ((b>>(i+4))&1);
}
return ft;
}
/* ------------------------------------------------------------------------------------ */
/*
(uses fec-lib by KA9Q)
@ -946,15 +952,26 @@ int rs41_ecc(int frmlen) {
errors2 = rs_decode(cw2, err_pos2, err_val2);
if (option_ecc == 2 && (errors1 < 0 || errors2 < 0)) {
if (option_ecc == 2 && (errors1 < 0 || errors2 < 0))
{ // 2nd pass
frame[pos_FRAME] = (pck_FRAME>>8)&0xFF; frame[pos_FRAME+1] = pck_FRAME&0xFF;
frame[pos_PTU] = (pck_PTU >>8)&0xFF; frame[pos_PTU +1] = pck_PTU &0xFF;
frame[pos_GPS1] = (pck_GPS1 >>8)&0xFF; frame[pos_GPS1 +1] = pck_GPS1 &0xFF;
frame[pos_GPS2] = (pck_GPS2 >>8)&0xFF; frame[pos_GPS2 +1] = pck_GPS2 &0xFF;
frame[pos_GPS3] = (pck_GPS3 >>8)&0xFF; frame[pos_GPS3 +1] = pck_GPS3 &0xFF;
if (frametype() < -2) {
// AUX-frames mit vielen Fehlern besser mit 00 auffuellen
// std-O3-AUX-frame: NDATA+7
if (frametype() < -2) { // ft >= 0: NDATA_LEN , ft < 0: FRAME_LEN
for (i = NDATA_LEN + 7; i < FRAME_LEN-2; i++) frame[i] = 0;
}
else { // std-frm (len=320): std_ZERO-frame (7611 00..00 ECC7)
for (i = NDATA_LEN; i < FRAME_LEN; i++) frame[i] = 0;
frame[pos_ZEROstd ] = 0x76; // pck_ZEROstd
frame[pos_ZEROstd+1] = 0x11; // pck_ZEROstd
for (i = pos_ZEROstd+2; i < NDATA_LEN-2; i++) frame[i] = 0;
frame[NDATA_LEN-2] = 0xEC; // crc(pck_ZEROstd)
frame[NDATA_LEN-1] = 0xC7; // crc(pck_ZEROstd)
}
for (i = 0; i < rs_K; i++) cw1[rs_R+i] = frame[cfg_rs41.msgpos+2*i ];
for (i = 0; i < rs_K; i++) cw2[rs_R+i] = frame[cfg_rs41.msgpos+2*i+1];
errors1 = rs_decode(cw1, err_pos1, err_val1);
@ -1142,7 +1159,14 @@ void print_frame(int len) {
}
if (option_ecc) {
if (ec >= 0) fprintf(stdout, " [OK]"); else fprintf(stdout, " [NO]");
if (option_ecc == 2 && ec > 0) fprintf(stdout, " (%d)", ec);
if (option_ecc == 2) {
if (ec > 0) fprintf(stdout, " (%d)", ec);
if (ec < 0) {
if (ec == -1) fprintf(stdout, " (-+)");
else if (ec == -2) fprintf(stdout, " (+-)");
else /*ec == -3*/ fprintf(stdout, " (--)");
}
}
}
fprintf(stdout, "\n");
}
@ -1179,8 +1203,8 @@ int main(int argc, char *argv[]) {
float thres = 0.7;
int bitofs = 0;
int symlen = 1;
int bitofs = 2;
#ifdef CYGWIN
@ -1338,8 +1362,9 @@ int main(int argc, char *argv[]) {
Qerror_count += 1;
}
}
header_found = 0;
print_frame(ft_len);
header_found = 0;
while ( bit_count < BITS*(FRAME_LEN-8+24) ) {
bitQ = read_sbit(fp, symlen, &bit, option_inv, bitofs, bit_count==0, 0); // symlen=1, return: zeroX/bit

Wyświetl plik

@ -328,6 +328,23 @@ int check_CRC(ui32_t pos, ui32_t pck) {
#define crc_ZERO (1<<6) // LEN variable
#define pck_ZERO 0x7600
#define pck_ZEROstd 0x7611 // NDATA std-frm, no aux
#define pos_ZEROstd 0x12B // pos_AUX(0)
/*
frame[pos_FRAME-1] == 0x0F: len == NDATA_LEN(320)
frame[pos_FRAME-1] == 0xF0: len == FRAME_LEN(518)
*/
int frametype() { // -4..+4: 0xF0 -> -4 , 0x0F -> +4
int i;
ui8_t b = frame[pos_FRAME-1];
int ft = 0;
for (i = 0; i < 4; i++) {
ft += ((b>>i)&1) - ((b>>(i+4))&1);
}
return ft;
}
ui8_t calibytes[51*16];
@ -649,9 +666,8 @@ int get_GPS1() {
err = check_CRC(pos_GPS1, pck_GPS1);
if (err) gpx.crc |= crc_GPS1;
//err = 0;
err |= get_GPSweek();
err |= get_GPStime();
err |= get_GPSweek(); // no plausibility-check
err |= get_GPStime(); // no plausibility-check
return err;
}
@ -728,7 +744,7 @@ int get_GPSkoord() {
gpx.lat = lat;
gpx.lon = lon;
gpx.alt = alt;
if ((alt < -1000) || (alt > 80000)) return -3;
if ((alt < -1000) || (alt > 80000)) return -3; // plausibility-check: altitude, if ecef=(0,0,0)
// ECEF-Velocities
@ -767,7 +783,7 @@ int get_GPS3() {
err = check_CRC(pos_GPS3, pck_GPS3);
if (err) gpx.crc |= crc_GPS3;
err |= get_GPSkoord();
err |= get_GPSkoord(); // plausibility-check: altitude, if ecef=(0,0,0)
return err;
}
@ -781,6 +797,8 @@ int get_Aux() {
count7E = 0;
pos7E = pos_AUX;
if (frametype(gpx) > 0) return 0; //pos7E == pos7611 ...
// 7Exx: xdata
while ( pos7E < FRAME_LEN && framebyte(pos7E) == 0x7E ) {
@ -793,7 +811,8 @@ int get_Aux() {
//fprintf(stdout, " # %02x : ", framebyte(pos7E+2));
for (i = 1; i < auxlen; i++) {
fprintf(stdout, "%c", framebyte(pos7E+2+i));
ui8_t c = framebyte(pos7E+2+i);
if (c > 0x1E) fprintf(stdout, "%c", c);
}
count7E++;
pos7E += 2+auxlen+2;
@ -883,20 +902,6 @@ int get_Calconf(int out) {
return 0;
}
/*
frame[pos_FRAME-1] == 0x0F: len == NDATA_LEN(320)
frame[pos_FRAME-1] == 0xF0: len == FRAME_LEN(518)
*/
int frametype() { // -4..+4: 0xF0 -> -4 , 0x0F -> +4
int i;
ui8_t b = frame[pos_FRAME-1];
int ft = 0;
for (i = 0; i < 4; i++) {
ft += ((b>>i)&1) - ((b>>(i+4))&1);
}
return ft;
}
/* ------------------------------------------------------------------------------------ */
/*
(uses fec-lib by KA9Q)
@ -949,15 +954,26 @@ int rs41_ecc(int frmlen) {
errors2 = rs_decode(cw2, err_pos2, err_val2);
if (option_ecc == 2 && (errors1 < 0 || errors2 < 0)) {
if (option_ecc == 2 && (errors1 < 0 || errors2 < 0))
{ // 2nd pass
frame[pos_FRAME] = (pck_FRAME>>8)&0xFF; frame[pos_FRAME+1] = pck_FRAME&0xFF;
frame[pos_PTU] = (pck_PTU >>8)&0xFF; frame[pos_PTU +1] = pck_PTU &0xFF;
frame[pos_GPS1] = (pck_GPS1 >>8)&0xFF; frame[pos_GPS1 +1] = pck_GPS1 &0xFF;
frame[pos_GPS2] = (pck_GPS2 >>8)&0xFF; frame[pos_GPS2 +1] = pck_GPS2 &0xFF;
frame[pos_GPS3] = (pck_GPS3 >>8)&0xFF; frame[pos_GPS3 +1] = pck_GPS3 &0xFF;
if (frametype() < -2) {
// AUX-frames mit vielen Fehlern besser mit 00 auffuellen
// std-O3-AUX-frame: NDATA+7
if (frametype() < -2) { // ft >= 0: NDATA_LEN , ft < 0: FRAME_LEN
for (i = NDATA_LEN + 7; i < FRAME_LEN-2; i++) frame[i] = 0;
}
else { // std-frm (len=320): std_ZERO-frame (7611 00..00 ECC7)
for (i = NDATA_LEN; i < FRAME_LEN; i++) frame[i] = 0;
frame[pos_ZEROstd ] = 0x76; // pck_ZEROstd
frame[pos_ZEROstd+1] = 0x11; // pck_ZEROstd
for (i = pos_ZEROstd+2; i < NDATA_LEN-2; i++) frame[i] = 0;
frame[NDATA_LEN-2] = 0xEC; // crc(pck_ZEROstd)
frame[NDATA_LEN-1] = 0xC7; // crc(pck_ZEROstd)
}
for (i = 0; i < rs_K; i++) cw1[rs_R+i] = frame[cfg_rs41.msgpos+2*i ];
for (i = 0; i < rs_K; i++) cw2[rs_R+i] = frame[cfg_rs41.msgpos+2*i+1];
errors1 = rs_decode(cw1, err_pos1, err_val1);
@ -1046,47 +1062,43 @@ int print_position(int ec) {
}
//if (output)
{
if (option_crc) {
fprintf(stdout, " # ");
if (option_ecc && ec >= 0 && (gpx.crc & 0x1F) != 0) {
int pos, blk, len, crc; // unexpected blocks
int flen = NDATA_LEN;
if (frametype() < 0) flen += XDATA_LEN;
pos = pos_FRAME;
while (pos < flen-1) {
blk = frame[pos]; // 0x80XX: encrypted block
len = frame[pos+1]; // 0x76XX: 00-padding block
crc = check_CRC(pos, blk<<8);
fprintf(stdout, " %02X%02X", frame[pos], frame[pos+1]);
fprintf(stdout, "[%d]", crc&1);
pos = pos+2+len+2;
}
if (option_crc) { // show CRC-checks (and RS-check)
fprintf(stdout, " # ");
if (option_ecc && ec >= 0 && (gpx.crc & 0x1F) != 0) {
int pos, blk, len, crc; // unexpected blocks
int flen = NDATA_LEN;
if (frametype() < 0) flen += XDATA_LEN;
pos = pos_FRAME;
while (pos < flen-1) {
blk = frame[pos]; // 0x80XX: encrypted block
len = frame[pos+1]; // 0x76XX: 00-padding block
crc = check_CRC(pos, blk<<8);
fprintf(stdout, " %02X%02X", frame[pos], frame[pos+1]);
fprintf(stdout, "[%d]", crc&1);
pos = pos+2+len+2;
}
else {
fprintf(stdout, "[");
for (i=0; i<5; i++) fprintf(stdout, "%d", (gpx.crc>>i)&1);
fprintf(stdout, "]");
}
if (option_ecc == 2) {
if (ec > 0) fprintf(stdout, " (%d)", ec);
if (ec < 0) {
if (ec == -1) fprintf(stdout, " (-+)");
else if (ec == -2) fprintf(stdout, " (+-)");
else /*ec == -3*/ fprintf(stdout, " (--)");
}
}
else {
fprintf(stdout, "[");
for (i=0; i<5; i++) fprintf(stdout, "%d", (gpx.crc>>i)&1);
fprintf(stdout, "]");
}
if (option_ecc == 2) {
if (ec > 0) fprintf(stdout, " (%d)", ec);
if (ec < 0) {
if (ec == -1) fprintf(stdout, " (-+)");
else if (ec == -2) fprintf(stdout, " (+-)");
else /*ec == -3*/ fprintf(stdout, " (--)");
}
}
}
get_Calconf(output);
//if (output)
{
if (option_verbose > 1) get_Aux();
fprintf(stdout, "\n"); // fflush(stdout);
}
if (option_verbose > 1) get_Aux();
fprintf(stdout, "\n"); // fflush(stdout);
}
err |= err1 | err3;
@ -1136,7 +1148,14 @@ void print_frame(int len) {
}
if (option_ecc) {
if (ec >= 0) fprintf(stdout, " [OK]"); else fprintf(stdout, " [NO]");
if (option_ecc == 2 && ec > 0) fprintf(stdout, " (%d)", ec);
if (option_ecc == 2) {
if (ec > 0) fprintf(stdout, " (%d)", ec);
if (ec < 0) {
if (ec == -1) fprintf(stdout, " (-+)");
else if (ec == -2) fprintf(stdout, " (+-)");
else /*ec == -3*/ fprintf(stdout, " (--)");
}
}
}
fprintf(stdout, "\n");
}
@ -1173,9 +1192,9 @@ int main(int argc, char *argv[]) {
float thres = 0.7;
int bitofs = 0;
int symlen = 1;
int shift = 2;
int bitofs = 2;
int shift = 0;
#ifdef CYGWIN
@ -1231,8 +1250,8 @@ int main(int argc, char *argv[]) {
++argv;
if (*argv) {
shift = atoi(*argv);
if (shift > 6) shift = 6;
if (shift < -2) shift = -2;
if (shift > 4) shift = 4;
if (shift < -4) shift = -4;
}
else return -1;
}
@ -1275,7 +1294,9 @@ int main(int argc, char *argv[]) {
// rs41: BT=0.5, h=0.8,1.0 ?
symlen = 1;
headerlen = strlen(header);
bitofs = shift; // +0 .. +3 // FM: +1 , IQ: +2
if (option_iq >= 2) bitofs += 1;
bitofs += shift; // +0 .. +3 // FM: +1 , IQ: +2
K = init_buffers(header, headerlen, 0.5, option_iq); // BT=0.5 (IQ-Int: BT > 0.5 ?)
if ( K < 0 ) {
fprintf(stderr, "error: init buffers\n");
@ -1364,8 +1385,9 @@ int main(int argc, char *argv[]) {
Qerror_count += 1;
}
}
header_found = 0;
print_frame(ft_len);
header_found = 0;
while ( bit_count < BITS*(FRAME_LEN-8+24) ) {
bitQ = read_sbit(fp, symlen, &bit, option_inv, bitofs, bit_count==0, 0); // symlen=1, return: zeroX/bit