// Helper function to keep code base small void fec_test_codec(fec_scheme _fs, unsigned int _n, void * _opts) { #if !LIBFEC_ENABLED if ( _fs == LIQUID_FEC_CONV_V27 || _fs == LIQUID_FEC_CONV_V29 || _fs == LIQUID_FEC_CONV_V39 || _fs == LIQUID_FEC_CONV_V615 || _fs == LIQUID_FEC_CONV_V27P23 || _fs == LIQUID_FEC_CONV_V27P34 || _fs == LIQUID_FEC_CONV_V27P45 || _fs == LIQUID_FEC_CONV_V27P56 || _fs == LIQUID_FEC_CONV_V27P67 || _fs == LIQUID_FEC_CONV_V27P78 || _fs == LIQUID_FEC_CONV_V29P23 || _fs == LIQUID_FEC_CONV_V29P34 || _fs == LIQUID_FEC_CONV_V29P45 || _fs == LIQUID_FEC_CONV_V29P56 || _fs == LIQUID_FEC_CONV_V29P67 || _fs == LIQUID_FEC_CONV_V29P78 || _fs == LIQUID_FEC_RS_M8) { AUTOTEST_WARN("convolutional, Reed-Solomon codes unavailable (install libfec)\n"); return; } #endif // generate fec object fec q = fec_create(_fs,_opts); // create arrays unsigned int n_enc = fec_get_enc_msg_length(_fs,_n); unsigned char msg[_n]; // original message unsigned char msg_enc[n_enc]; // encoded message unsigned char msg_dec[_n]; // decoded message // initialze message unsigned int i; for (i=0; i<_n; i++) { msg[i] = rand() & 0xff; msg_dec[i] = 0; } // encode message fec_encode(q,_n,msg,msg_enc); // channel: add single error msg_enc[0] ^= 0x01; // decode message fec_decode(q,_n,msg_enc,msg_dec); // validate output CONTEND_SAME_DATA(msg,msg_dec,_n); // clean up objects fec_destroy(q); }
// // AUTOTEST: repeat/3 codec // void autotest_rep5_codec() { unsigned int n=4; unsigned char msg[] = {0x25, 0x62, 0x3F, 0x52}; fec_scheme fs = LIQUID_FEC_REP5; // create arrays unsigned int n_enc = fec_get_enc_msg_length(fs,n); unsigned char msg_dec[n]; unsigned char msg_enc[n_enc]; // create object fec q = fec_create(fs,NULL); if (liquid_autotest_verbose) fec_print(q); // encode message fec_encode(q, n, msg, msg_enc); // corrupt encoded message, but no so much that it // can't be decoded msg_enc[ 0] = ~msg_enc[ 0]; msg_enc[ 4] = ~msg_enc[ 4]; // msg_enc[ 8] = ~msg_enc[ 8]; // msg_enc[12] = ~msg_enc[12]; // msg_enc[16] = ~msg_enc[16]; msg_enc[ 1] = ~msg_enc[ 1]; // msg_enc[ 5] = ~msg_enc[ 5]; msg_enc[ 9] = ~msg_enc[ 9]; // msg_enc[13] = ~msg_enc[13]; // msg_enc[17] = ~msg_enc[17]; // msg_enc[ 2] = ~msg_enc[ 2]; // msg_enc[ 6] = ~msg_enc[ 6]; msg_enc[10] = ~msg_enc[10]; msg_enc[14] = ~msg_enc[14]; // msg_enc[18] = ~msg_enc[18]; msg_enc[ 3] = ~msg_enc[ 3]; // msg_enc[ 7] = ~msg_enc[ 7]; // msg_enc[11] = ~msg_enc[11]; // msg_enc[15] = ~msg_enc[15]; msg_enc[19] = ~msg_enc[19]; // decode message fec_decode(q, n, msg_enc, msg_dec); // validate data are the same CONTEND_SAME_DATA(msg, msg_dec, n); // clean up objects fec_destroy(q); }
// recreate a fec object // _q : initial fec object // _scheme : new scheme // _opts : options (ignored) fec fec_recreate(fec _q, fec_scheme _scheme, void *_opts) { if (_q->scheme != _scheme) { // destroy old object and create new one fec_destroy(_q); _q = fec_create(_scheme,_opts); } // scheme hasn't changed; just return original object return _q; }
// destroy packetizer object void packetizer_destroy(packetizer _p) { // free fec, interleaver objects unsigned int i; for (i=0; i<_p->plan_len; i++) { fec_destroy(_p->plan[i].f); interleaver_destroy(_p->plan[i].q); }; // free plan free(_p->plan); // free buffers free(_p->buffer_0); free(_p->buffer_1); // free packetizer object free(_p); }
// // AUTOTEST: Hamming (7,4) codec // void autotest_hamming74_codec() { unsigned int n=4; unsigned char msg[] = {0x25, 0x62, 0x3F, 0x52}; fec_scheme fs = LIQUID_FEC_HAMMING74; // create arrays unsigned int n_enc = fec_get_enc_msg_length(fs,n); unsigned char msg_dec[n]; unsigned char msg_enc[n_enc]; // create object fec q = fec_create(fs,NULL); if (liquid_autotest_verbose) fec_print(q); // encode message fec_encode(q, n, msg, msg_enc); // corrupt encoded message msg_enc[0] ^= 0x04; // position 5 #if 0 msg_enc[1] ^= 0x04; // msg_enc[2] ^= 0x02; // msg_enc[3] ^= 0x01; // msg_enc[4] ^= 0x80; // msg_enc[5] ^= 0x40; // msg_enc[6] ^= 0x20; // #endif // decode message fec_decode(q, n, msg_enc, msg_dec); // validate data are the same CONTEND_SAME_DATA(msg, msg_dec, n); // clean up objects fec_destroy(q); }
// Helper function to keep code base small void fec_encode_bench( struct rusage *_start, struct rusage *_finish, unsigned long int *_num_iterations, fec_scheme _fs, unsigned int _n, void * _opts) { #if !LIBFEC_ENABLED if ( _fs == LIQUID_FEC_CONV_V27 || _fs == LIQUID_FEC_CONV_V29 || _fs == LIQUID_FEC_CONV_V39 || _fs == LIQUID_FEC_CONV_V615 || _fs == LIQUID_FEC_CONV_V27P23 || _fs == LIQUID_FEC_CONV_V27P34 || _fs == LIQUID_FEC_CONV_V27P45 || _fs == LIQUID_FEC_CONV_V27P56 || _fs == LIQUID_FEC_CONV_V27P67 || _fs == LIQUID_FEC_CONV_V27P78 || _fs == LIQUID_FEC_CONV_V29P23 || _fs == LIQUID_FEC_CONV_V29P34 || _fs == LIQUID_FEC_CONV_V29P45 || _fs == LIQUID_FEC_CONV_V29P56 || _fs == LIQUID_FEC_CONV_V29P67 || _fs == LIQUID_FEC_CONV_V29P78 || _fs == LIQUID_FEC_RS_M8) { fprintf(stderr,"warning: convolutional, Reed-Solomon codes unavailable (install libfec)\n"); getrusage(RUSAGE_SELF, _start); memmove((void*)_finish,(void*)_start,sizeof(struct rusage)); return; } #endif // normalize number of iterations *_num_iterations /= _n; switch (_fs) { case LIQUID_FEC_NONE: *_num_iterations *= 500; break; case LIQUID_FEC_REP3: *_num_iterations *= 200; break; case LIQUID_FEC_REP5: *_num_iterations *= 100; break; case LIQUID_FEC_HAMMING74: *_num_iterations *= 30; break; case LIQUID_FEC_HAMMING84: *_num_iterations *= 100; break; case LIQUID_FEC_HAMMING128: *_num_iterations *= 100; break; case LIQUID_FEC_SECDED2216: *_num_iterations *= 10; break; case LIQUID_FEC_SECDED3932: *_num_iterations *= 10; break; case LIQUID_FEC_SECDED7264: *_num_iterations *= 10; break; case LIQUID_FEC_GOLAY2412: *_num_iterations *= 2; break; case LIQUID_FEC_CONV_V27: case LIQUID_FEC_CONV_V29: case LIQUID_FEC_CONV_V39: case LIQUID_FEC_CONV_V615: case LIQUID_FEC_CONV_V27P23: case LIQUID_FEC_CONV_V27P34: case LIQUID_FEC_CONV_V27P45: case LIQUID_FEC_CONV_V27P56: case LIQUID_FEC_CONV_V27P67: case LIQUID_FEC_CONV_V27P78: case LIQUID_FEC_CONV_V29P23: case LIQUID_FEC_CONV_V29P34: case LIQUID_FEC_CONV_V29P45: case LIQUID_FEC_CONV_V29P56: case LIQUID_FEC_CONV_V29P67: case LIQUID_FEC_CONV_V29P78: case LIQUID_FEC_RS_M8: *_num_iterations *= 1; break; default:; } if (*_num_iterations < 1) *_num_iterations = 1; // generate fec object fec q = fec_create(_fs,_opts); // create arrays unsigned int n_enc = fec_get_enc_msg_length(_fs,_n); unsigned char msg[_n]; // original message unsigned char msg_enc[n_enc]; // encoded message // initialze message unsigned long int i; for (i=0; i<_n; i++) { msg[i] = rand() & 0xff; } // start trials getrusage(RUSAGE_SELF, _start); for (i=0; i<(*_num_iterations); i++) { fec_encode(q,_n,msg,msg_enc); fec_encode(q,_n,msg,msg_enc); fec_encode(q,_n,msg,msg_enc); fec_encode(q,_n,msg,msg_enc); } getrusage(RUSAGE_SELF, _finish); *_num_iterations *= 4; // clean up objects fec_destroy(q); }