diff --git a/SP5WWP/include/m17/m17.h b/SP5WWP/include/m17/m17.h index 559064e..0fb5c11 100644 --- a/SP5WWP/include/m17/m17.h +++ b/SP5WWP/include/m17/m17.h @@ -69,6 +69,7 @@ uint16_t LSF_CRC(const struct LSF *in); // M17 C library - lib/payload/lich.c void extract_LICH(uint8_t outp[6], const uint8_t cnt, const struct LSF *inp); +void unpack_LICH(uint8_t *out, const uint8_t in[12]); // M17 C library - lib/math/golay.c extern const uint16_t encode_matrix[12]; diff --git a/SP5WWP/lib/payload/lich.c b/SP5WWP/lib/payload/lich.c index 8d00c24..b1f34cc 100644 --- a/SP5WWP/lib/payload/lich.c +++ b/SP5WWP/lib/payload/lich.c @@ -76,3 +76,18 @@ void extract_LICH(uint8_t outp[6], const uint8_t cnt, const struct LSF *inp) outp[5]=cnt<<5; } + +/** + * @brief Unpack LICH bytes. + * + * @param out Unpacked, encoded LICH bits (array of at least 96 bytes). + * @param in 12-byte (96 bits) encoded LICH, packed. + */ +void unpack_LICH(uint8_t *out, const uint8_t in[12]) +{ + for(uint8_t i=0; i<12; i++) + { + for(uint8_t j=0; j<8; j++) + out[i*8+j]=(in[i]>>(7-j))&1; + } +} diff --git a/SP5WWP/m17-coder/m17-coder-sym.c b/SP5WWP/m17-coder/m17-coder-sym.c index 5bb9f26..103eac0 100644 --- a/SP5WWP/m17-coder/m17-coder-sym.c +++ b/SP5WWP/m17-coder/m17-coder-sym.c @@ -72,14 +72,9 @@ int main(void) encode_LICH(lich_encoded, lich); //unpack LICH (12 bytes) - memset(enc_bits, 0, SYM_PER_PLD*2); - for(uint8_t i=0; i<12; i++) - { - for(uint8_t j=0; j<8; j++) - enc_bits[i*8+j]=(lich_encoded[i]>>(7-j))&1; - } + unpack_LICH(enc_bits, lich_encoded); - //encode the rest of the frame + //encode the rest of the frame (starting at bit 96 - 0..95 are filled with LICH) conv_encode_stream_frame(&enc_bits[96], data, finished ? (fn | 0x8000) : fn); //reorder bits @@ -119,9 +114,6 @@ int main(void) { got_lsf=1; - //encode LSF data - conv_encode_LSF(enc_bits, &lsf); - //send out the preamble frame_buff_cnt=0; send_preamble(frame_buff, &frame_buff_cnt, 0); //0 - LSF preamble, as opposed to 1 - BERT preamble @@ -132,21 +124,14 @@ int main(void) send_syncword(frame_buff, &frame_buff_cnt, SYNC_LSF); fwrite((uint8_t*)frame_buff, SYM_PER_SWD*sizeof(float), 1, stdout); + //encode LSF data + conv_encode_LSF(enc_bits, &lsf); + //reorder bits - for(uint16_t i=0; i>(7-(i%8)))&1) //flip bit if '1' - { - if(rf_bits[i]) - rf_bits[i]=0; - else - rf_bits[i]=1; - } - } + randomize_bits(rf_bits); //send LSF data frame_buff_cnt=0;