Fix interleaver lengths.

pull/1/head
Mark Jessop 2020-06-28 00:55:42 +09:30
rodzic 48dbff4ed3
commit ef5bf76dfd
4 zmienionych plików z 99 dodań i 24 usunięć

Wyświetl plik

@ -14,7 +14,7 @@
#define H_128_384_23_MAX_COL_WEIGHT 5
#define H_128_384_23_DEC_TYPE 0
#define H_128_384_23_MAX_ITER 100
#define H_128_384_23_COPRIME 347
#define H_128_384_23_COPRIME 383
extern const uint16_t H_128_384_23_H_rows[];
extern const uint16_t H_128_384_23_H_cols[];

Wyświetl plik

@ -14,7 +14,7 @@
#define H_256_768_22_MAX_COL_WEIGHT 4
#define H_256_768_22_DEC_TYPE 0
#define H_256_768_22_MAX_ITER 100
#define H_256_768_22_COPRIME 347
#define H_256_768_22_COPRIME 761
extern const uint16_t H_256_768_22_H_rows[];
extern const uint16_t H_256_768_22_H_cols[];

Wyświetl plik

@ -170,9 +170,8 @@ struct horus *horus_open_advanced (int mode, int Rs, int tx_tone_spacing) {
}
if (mode == HORUS_MODE_BINARY_V2_256BIT) {
// Parameter setup for the Legacy Horus Binary Mode (22 byte frames, Golay encoding)
hstates->mFSK = 4;
hstates->mFSK = 2;
hstates->max_packet_len = HORUS_BINARY_V2_256BIT_NUM_CODED_BITS ;
// If baud rate not provided, use default
@ -200,9 +199,9 @@ struct horus *horus_open_advanced (int mode, int Rs, int tx_tone_spacing) {
}
if (mode == HORUS_MODE_BINARY_V2_128BIT) {
// Parameter setup for the Legacy Horus Binary Mode (22 byte frames, Golay encoding)
// Parameter setup for the New v2 Horus Binary mode.
hstates->mFSK = 4;
hstates->mFSK = 2; // Lock to 2FSK until we have decent LLRs for 4FSK.
hstates->max_packet_len = HORUS_BINARY_V2_128BIT_NUM_CODED_BITS ;
// If baud rate not provided, use default
@ -556,6 +555,81 @@ int extract_horus_binary_v2_128(struct horus *hstates, char hex_out[], int uw_lo
}
int extract_horus_binary_v2_256(struct horus *hstates, char hex_out[], int uw_loc) {
const int nfield = 8; /* 8 bit binary */
int st = uw_loc; /* first bit of first char */
int en = uw_loc + hstates->max_packet_len; /* last bit of max length packet */
int j, b, nout;
uint8_t rxpacket[hstates->max_packet_len];
uint8_t rxbyte, *pout;
/* convert bits to a packet of bytes */
pout = rxpacket; nout = 0;
for (b=st; b<en; b+=nfield) {
/* assemble bytes MSB to LSB */
rxbyte = 0;
for(j=0; j<nfield; j++) {
assert(hstates->rx_bits[b+j] <= 1);
rxbyte <<= 1;
rxbyte |= hstates->rx_bits[b+j];
}
/* build up output array */
*pout++ = rxbyte;
nout++;
}
if (hstates->verbose) {
fprintf(stderr, " extract_horus_binary_v2_256 nout: %d\n Received Packet before decoding:\n ", nout);
for (b=0; b<nout; b++) {
fprintf(stderr, "%02X", rxpacket[b]);
}
fprintf(stderr, "\n");
}
uint8_t payload_bytes[HORUS_BINARY_V2_256BIT_NUM_UNCODED_PAYLOAD_BYTES];
float *softbits = hstates->soft_bits + uw_loc + sizeof(uw_horus_binary_v2);
horus_ldpc_decode( payload_bytes, softbits , HORUS_MODE_BINARY_V2_256BIT);
uint16_t crc_tx, crc_rx;
crc_rx = horus_l2_gen_crc16(payload_bytes, HORUS_BINARY_V2_256BIT_NUM_UNCODED_PAYLOAD_BYTES-2);
crc_tx = (uint16_t)payload_bytes[HORUS_BINARY_V2_256BIT_NUM_UNCODED_PAYLOAD_BYTES-2] +
((uint16_t)payload_bytes[HORUS_BINARY_V2_256BIT_NUM_UNCODED_PAYLOAD_BYTES-1]<<8);
if (hstates->verbose) {
fprintf(stderr, " extract_horus_binary_v2_256 crc_tx: %04X crc_rx: %04X\n", crc_tx, crc_rx);
}
/* convert to ASCII string of hex characters */
hex_out[0] = 0;
char hex[3];
for (b=0; b<HORUS_BINARY_V2_256BIT_NUM_UNCODED_PAYLOAD_BYTES; b++) {
sprintf(hex, "%02X", payload_bytes[b]);
strcat(hex_out, hex);
}
if (hstates->verbose) {
fprintf(stderr, " nout: %d Decoded Payload bytes:\n %s\n", nout, hex_out);
}
/* With noise input to FSK demod we can get occasinal UW matches,
so a good idea to only pass on any packets that pass CRC */
hstates->crc_ok = (crc_tx == crc_rx);
if ( hstates->crc_ok) {
hstates->total_payload_bits = HORUS_BINARY_V2_256BIT_NUM_UNCODED_PAYLOAD_BYTES;
}
return hstates->crc_ok;
}
int horus_rx(struct horus *hstates, char ascii_out[], short demod_in[], int quadrature) {
int i, j, uw_loc, packet_detected;
@ -627,6 +701,9 @@ int horus_rx(struct horus *hstates, char ascii_out[], short demod_in[], int quad
if (hstates->mode == HORUS_MODE_BINARY_V2_128BIT){
packet_detected = extract_horus_binary_v2_128(hstates, ascii_out, uw_loc);
}
if (hstates->mode == HORUS_MODE_BINARY_V2_256BIT){
packet_detected = extract_horus_binary_v2_256(hstates, ascii_out, uw_loc);
}
}
return packet_detected;
}

Wyświetl plik

@ -39,10 +39,10 @@
4/ Streaming test bits to stdout, for 'live' testing with fsk_mod and horus_demod:
$ gcc horus_l2.c golay23.c -o horus_l2 -Wall -DGEN_TX_BITSTREAM -DSCRAMBLER -DINTERLEAVER
$ ggcc horus_l2.c golay23.c H_128_384_23.c H_256_768_22.c mpdecode_core.c phi0.c -o horus_l2 -Wall -DGEN_TX_BITSTREAM -DSCRAMBLER -DINTERLEAVER
$ cp horus_l2 ../build/src/
$ cd ../build/src/
$ ./horus_l2 100 | ./fsk_mod 4 48000 100 750 250 - - | ./horus_demod -m binary - -
$ ./horus_l2 100 0 | ./fsk_mod 4 48000 100 750 250 - - | ./horus_demod -m binary - -
5/ Unit testing interleaver:
@ -485,7 +485,8 @@ uint16_t primes[] = {
127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
283, 293, 307, 311, 313, 317, 331, 337, 347
283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
379, 383, 389, 757, 761, 769, 773
};
void interleave(unsigned char *inout, int nbytes, int dir)
@ -507,6 +508,8 @@ void interleave(unsigned char *inout, int nbytes, int dir)
i++;
b = primes[i-1];
fprintf(stderr,"nbits: %d coprime: %d\n", nbits, b);
for(n=0; n<nbits; n++) {
/*
@ -984,7 +987,7 @@ int main(int argc,char *argv[]) {
input_payload.Counter = 2;
input_payload.Checksum = horus_l2_gen_crc16((unsigned char*)&input_payload, nbytes-2);
int ldpc_tx_bytes = ldpc_encode_packet(tx, (unsigned char*)&input_payload, 2);
int ldpc_tx_bytes = ldpc_encode_packet(tx, (unsigned char*)&input_payload, 1);
int b;
uint8_t tx_bit;
@ -1216,27 +1219,21 @@ void horus_ldpc_decode(uint8_t *payload, float *sd, int mode) {
payload_bytes = H_128_384_23_DATA_BYTES;
}
double sd_double[bits_per_packet];
float llr[bits_per_packet];
float temp[bits_per_packet];
uint8_t outbits[bits_per_packet];
int b, i, parityCC;
int b, i, parityCC;
struct LDPC ldpc;
/* normalise bitstream to log-like */
sum = 0.0;
for ( i = 0; i < bits_per_packet; i++ )
sum += fabs(sd[i]);
mean = sum / bits_per_packet;
// cast incoming SDs to doubles for sd_to_llr
// For some reason I need to flip the sign ?!?!
for ( i = 0; i < bits_per_packet; i++ )
sd_double[i] = (double)sd[i]*-1.0;
sumsq = 0.0;
for ( i = 0; i < bits_per_packet; i++ ) {
x = fabs(sd[i]) / mean - 1.0;
sumsq += x * x;
}
estEsN0 = 2.0 * bits_per_packet / (sumsq + 1.0e-3) / mean;
for ( i = 0; i < bits_per_packet; i++ )
llr[i] = estEsN0 * sd[i];
sd_to_llr(llr, sd_double, bits_per_packet);
/* reverse whitening and re-order bits */
soft_unscramble(llr, temp, bits_per_packet);
@ -1272,6 +1269,7 @@ void horus_ldpc_decode(uint8_t *payload, float *sd, int mode) {
}
i = run_ldpc_decoder(&ldpc, outbits, llr, &parityCC);
fprintf(stderr,"iterations: %d\n", i);
/* convert MSB bits to a packet of bytes */
for (b = 0; b < payload_bytes; b++) {