Porównaj commity

...

2 Commity

Autor SHA1 Wiadomość Data
Wojciech Kaczmarski 7a30b90e15 added new function
- unpack_LICH()
2024-01-09 12:07:05 +01:00
Wojciech Kaczmarski a6c75950e6 added new functions
- soft_bit_NOT()
- reorder_soft_bits()
2024-01-09 11:05:06 +01:00
6 zmienionych plików z 52 dodań i 29 usunięć

Wyświetl plik

@ -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];
@ -84,6 +85,7 @@ void encode_LICH(uint8_t outp[12], const uint8_t inp[6]);
extern const uint16_t intrl_seq[SYM_PER_PLD*2];
void reorder_bits(uint8_t outp[SYM_PER_PLD*2], const uint8_t inp[SYM_PER_PLD*2]);
void reorder_soft_bits(uint16_t outp[SYM_PER_PLD*2], const uint16_t inp[SYM_PER_PLD*2]);
// M17 C library - lib/math/math.c
uint16_t q_abs_diff(const uint16_t v1, const uint16_t v2);
@ -93,6 +95,7 @@ uint16_t soft_to_int(const uint16_t* in, const uint8_t len);
uint16_t div16(const uint16_t a, const uint16_t b);
uint16_t mul16(const uint16_t a, const uint16_t b);
uint16_t soft_bit_XOR(const uint16_t a, const uint16_t b);
uint16_t soft_bit_NOT(const uint16_t a);
void soft_XOR(uint16_t* out, const uint16_t* a, const uint16_t* b, const uint8_t len);
// M17 C library - lib/phy/randomize.c

Wyświetl plik

@ -153,6 +153,17 @@ uint16_t soft_bit_XOR(const uint16_t a, const uint16_t b)
return add16(mul16(a, sub16(0xFFFF, b)), mul16(b, sub16(0xFFFF, a)));
}
/**
* @brief Soft logic NOT.
*
* @param a Input A.
* @return uint16_t Output = not A.
*/
uint16_t soft_bit_NOT(const uint16_t a)
{
return 0xFFFFU-a;
}
/**
* @brief XOR for vectors of soft-valued logic.
* Max length is 255.

Wyświetl plik

@ -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;
}
}

Wyświetl plik

@ -36,7 +36,7 @@ const uint16_t intrl_seq[SYM_PER_PLD*2]=
};
/**
* @brief Reorder (interleave) unpacked payload bits.
* @brief Reorder (interleave) 368 unpacked payload bits.
*
* @param outp Reordered, unpacked type-4 bits.
* @param inp Input unpacked type-2/3 bits.
@ -46,3 +46,15 @@ void reorder_bits(uint8_t outp[SYM_PER_PLD*2], const uint8_t inp[SYM_PER_PLD*2])
for(uint16_t i=0; i<SYM_PER_PLD*2; i++)
outp[i]=inp[intrl_seq[i]];
}
/**
* @brief Reorder (interleave) 368 soft bits.
*
* @param outp Reordered soft bits.
* @param inp Input soft bits.
*/
void reorder_soft_bits(uint16_t outp[SYM_PER_PLD*2], const uint16_t inp[SYM_PER_PLD*2])
{
for(uint16_t i=0; i<SYM_PER_PLD*2; i++)
outp[i]=inp[intrl_seq[i]];
}

Wyświetl plik

@ -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<SYM_PER_PLD*2; i++)
rf_bits[i]=enc_bits[intrl_seq[i]];
reorder_bits(rf_bits, enc_bits);
//randomize
for(uint16_t i=0; i<SYM_PER_PLD*2; i++)
{
if((rand_seq[i/8]>>(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;

Wyświetl plik

@ -121,15 +121,12 @@ int main(void)
//derandomize
for(uint16_t i=0; i<SYM_PER_PLD*2; i++)
{
if((rand_seq[i/8]>>(7-(i%8)))&1) //soft XOR. flip soft bit if "1"
soft_bit[i]=0xFFFF-soft_bit[i];
if((rand_seq[i/8]>>(7-(i%8)))&1) //soft NOT. flip soft bit if "1"
soft_bit[i]=soft_bit_NOT(soft_bit[i]);
}
//deinterleave
for(uint16_t i=0; i<SYM_PER_PLD*2; i++)
{
d_soft_bit[i]=soft_bit[intrl_seq[i]];
}
reorder_soft_bits(d_soft_bit, soft_bit);
//if it is a frame
if(!fl)