#include #include #include #include //libm17 #include //#define FN60_DEBUG struct LSF lsf, next_lsf; uint8_t lich[6]; //48 bits packed raw, unencoded LICH uint8_t lich_encoded[12]; //96 bits packed, encoded LICH uint8_t enc_bits[SYM_PER_PLD*2]; //type-2 bits, unpacked uint8_t rf_bits[SYM_PER_PLD*2]; //type-4 bits, unpacked float frame_buff[192]; uint32_t frame_buff_cnt; uint8_t data[16], next_data[16]; //raw payload, packed bits uint16_t fn=0; //16-bit Frame Number (for the stream mode) uint8_t lich_cnt=0; //0..5 LICH counter uint8_t got_lsf=0; //have we filled the LSF struct yet? uint8_t finished=0; //main routine int main(void) { //debug //printf("%06X\n", golay24_encode(1)); //golay encoder codeword test //printf("%d -> %d -> %d\n", 1, intrl_seq[1], intrl_seq[intrl_seq[1]]); //interleaver bijective reciprocality test, f(f(x))=x //return 0; if(fread(&(next_lsf.dst), 6, 1, stdin)<1) finished=1; if(fread(&(next_lsf.src), 6, 1, stdin)<1) finished=1; if(fread(&(next_lsf.type), 2, 1, stdin)<1) finished=1; if(fread(&(next_lsf.meta), 14, 1, stdin)<1) finished=1; if(fread(next_data, 16, 1, stdin)<1) finished=1; while(!finished) { if(lich_cnt == 0) { lsf = next_lsf; //calculate LSF CRC uint16_t ccrc=LSF_CRC(&lsf); lsf.crc[0]=ccrc>>8; lsf.crc[1]=ccrc&0xFF; } memcpy(data, next_data, sizeof(data)); //we could discard the data we already have if(fread(&(next_lsf.dst), 6, 1, stdin)<1) finished=1; if(fread(&(next_lsf.src), 6, 1, stdin)<1) finished=1; if(fread(&(next_lsf.type), 2, 1, stdin)<1) finished=1; if(fread(&(next_lsf.meta), 14, 1, stdin)<1) finished=1; if(fread(next_data, 16, 1, stdin)<1) finished=1; if(got_lsf) //stream frames { //send stream frame syncword frame_buff_cnt=0; send_syncword(frame_buff, &frame_buff_cnt, SYNC_STR); //extract LICH from the whole LSF extract_LICH(lich, lich_cnt, &lsf); //encode the LICH encode_LICH(lich_encoded, lich); //unpack LICH (12 bytes) unpack_LICH(enc_bits, lich_encoded); //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 reorder_bits(rf_bits, enc_bits); //randomize randomize_bits(rf_bits); //send dummy symbols (debug) /*float s=0.0; for(uint8_t i=0; i