/* -*- c++ -*- */ /* * Copyright 2023 jmfriedt. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3, or (at your option) * any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "m17_coder_impl.h" #include #include #include #include #include "../M17_Implementations/SP5WWP/lib/lib.h" #include "../M17_Implementations/SP5WWP/lib/math/golay.h" #include "../M17_Implementations/SP5WWP/lib/payload/crc.h" #include "../M17_Implementations/SP5WWP/lib/encode/symbols.h" #include "../M17_Implementations/SP5WWP/lib/phy/sync.h" #include "../M17_Implementations/SP5WWP/lib/encode/convol.h" #include "../M17_Implementations/SP5WWP/lib/payload/call.h" #include "../M17_Implementations/SP5WWP/lib/payload/lsf.h" #include "../M17_Implementations/SP5WWP/lib/phy/interleave.h" #include "../M17_Implementations/SP5WWP/lib/phy/randomize.h" namespace gr { namespace m17 { struct LSF lsf; void send_Preamble(const uint8_t type,float *out, int *counterout) { float symb; if(type) //pre-BERT { for(uint16_t i=0; i<(int)(192/2); i++) //40ms * 4800 = 192 { symb=-3.0; // write(STDOUT_FILENO, (uint8_t*)&symb, sizeof(float)); out[*counterout]=symb; *counterout=(*counterout)+1; symb=+3.0; // write(STDOUT_FILENO, (uint8_t*)&symb, sizeof(float)); out[*counterout]=symb; *counterout=(*counterout)+1; } } else //pre-LSF { for(uint16_t i=0; i<(int)(192/2); i++) //40ms * 4800 = 192 { symb=+3.0; // write(STDOUT_FILENO, (uint8_t*)&symb, sizeof(float)); out[*counterout]=symb; *counterout=(*counterout)+1; symb=-3.0; // write(STDOUT_FILENO, (uint8_t*)&symb, sizeof(float)); out[*counterout]=symb; *counterout=(*counterout)+1; } } } // now ../M17_Implementations/SP5WWP/lib/lib.c:void send_syncword(const uint16_t syncword) void send_Syncword(const uint16_t sword, float *out, int *counterout) { float symb; for(uint8_t i=0; i<16; i+=2) { symb=symbol_map[(sword>>(14-i))&3]; // write(STDOUT_FILENO, (uint8_t*)&symb, sizeof(float)); out[*counterout]=symb; *counterout=(*counterout)+1; } } m17_coder::sptr m17_coder::make(std::string src_id,std::string dst_id,short type,std::string meta, bool debug) { return gnuradio::get_initial_sptr (new m17_coder_impl(src_id,dst_id,type,meta,debug)); } /* * The private constructor */ m17_coder_impl::m17_coder_impl(std::string src_id,std::string dst_id,short type,std::string meta, bool debug) : gr::block("m17_coder", gr::io_signature::make(1, 1, sizeof(char)), gr::io_signature::make(1, 1, sizeof(float))) , _meta(meta),_type(type), _debug(debug) { set_meta(meta); set_src_id(src_id); set_dst_id(dst_id); set_type(type); set_debug(debug); set_output_multiple(192); uint16_t ccrc=LSF_CRC(&lsf); lsf.crc[0]=ccrc>>8; lsf.crc[1]=ccrc&0xFF; _got_lsf=0; //have we filled the LSF struct yet? _fn=0; //16-bit Frame Number (for the stream mode) } void m17_coder_impl::set_debug(bool debug) {_debug=debug; if (_debug==true) printf("Debug true\n"); else printf("Debug false\n"); } void m17_coder_impl::set_src_id(std::string src_id) {int length; for (int i=0;i<10;i++) {_src_id[i]=0;} if (src_id.length()>9) length=9; else length=src_id.length(); for (int i=0;i>8; lsf.crc[1]=ccrc&0xFF; } void m17_coder_impl::set_dst_id(std::string dst_id) {int length; for (int i=0;i<10;i++) {_dst_id[i]=0;} if (dst_id.length()>9) length=9; else length=dst_id.length(); for (int i=0;i>8; lsf.crc[1]=ccrc&0xFF; } void m17_coder_impl::set_meta(std::string meta) {int length; printf("new meta: %s\n",meta.c_str());fflush(stdout); _meta.assign(meta); if (meta.length()<14) length=meta.length(); else length=14; for (int i=0;i>8; lsf.crc[1]=ccrc&0xFF; } void m17_coder_impl::set_type(short type) {_type=type; lsf.type[0]=_type>>8; // MSB lsf.type[1]=_type&0xff; // LSB uint16_t ccrc=LSF_CRC(&lsf); lsf.crc[0]=ccrc>>8; lsf.crc[1]=ccrc&0xFF; printf("new type: %hhd %hhd\n",lsf.type[1],lsf.type[0]);fflush(stdout); } /* * Our virtual destructor. */ m17_coder_impl::~m17_coder_impl() { } void m17_coder_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required) { ninput_items_required[0] = noutput_items/12; // 16 inputs -> 192 outputs } int m17_coder_impl::general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { const char *in = (const char *) input_items[0]; float *out = (float *) output_items[0]; int countin=0; int countout=0; uint8_t enc_bits[SYM_PER_PLD*2]; //type-2 bits, unpacked uint8_t rf_bits[SYM_PER_PLD*2]; //type-4 bits, unpacked uint8_t lich[6]; //48 bits packed raw, unencoded LICH uint8_t lich_encoded[12]; //96 bits packed, encoded LICH uint8_t data[16]; //raw payload, packed bits uint8_t lich_cnt=0; //0..5 LICH counter, derived from the Frame Number while (countout>4)); lich_encoded[0]=(val>>16)&0xFF; lich_encoded[1]=(val>>8)&0xFF; lich_encoded[2]=(val>>0)&0xFF; val=golay24_encode(((lich[1]&0x0F)<<8)|lich[2]); lich_encoded[3]=(val>>16)&0xFF; lich_encoded[4]=(val>>8)&0xFF; lich_encoded[5]=(val>>0)&0xFF; val=golay24_encode((lich[3]<<4)|(lich[4]>>4)); lich_encoded[6]=(val>>16)&0xFF; lich_encoded[7]=(val>>8)&0xFF; lich_encoded[8]=(val>>0)&0xFF; val=golay24_encode(((lich[4]&0x0F)<<8)|lich[5]); lich_encoded[9]=(val>>16)&0xFF; lich_encoded[10]=(val>>8)&0xFF; lich_encoded[11]=(val>>0)&0xFF; //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; } //encode the rest of the frame conv_encode_stream_frame(&enc_bits[96], data, _fn); //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; } } //send dummy symbols (debug) /*float s=0.0; for(uint8_t i=0; i>8; // lsf.crc[1]=ccrc&0xFF; _got_lsf=1; // printf("got_lsf=1\n"); //encode LSF data conv_encode_LSF(enc_bits, &lsf); //send out the preamble and LSF send_Preamble(0,out,&countout); //0 - LSF preamble, as opposed to 1 - BERT preamble //send LSF syncword send_Syncword(SYNC_LSF,out,&countout); //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; } } float s; for(uint16_t i=0; i