// static callback function
static int callback(unsigned char *  _header,
                    int              _header_valid,
                    unsigned char *  _payload,
                    unsigned int     _payload_len,
                    int              _payload_valid,
                    framesyncstats_s _stats,
                    void *           _userdata)
{
    printf("*** callback invoked ***\n");
    printf("    error vector mag.   : %12.8f dB\n", _stats.evm);
    printf("    rssi                : %12.8f dB\n", _stats.rssi);
    printf("    carrier offset      : %12.8f\n", _stats.cfo);
    printf("    mod. scheme         : %s\n", modulation_types[_stats.mod_scheme].fullname);
    printf("    mod. depth          : %u\n", _stats.mod_bps);
    printf("    payload CRC         : %s\n", crc_scheme_str[_stats.check][1]);
    printf("    payload fec (inner) : %s\n", fec_scheme_str[_stats.fec0][1]);
    printf("    payload fec (outer) : %s\n", fec_scheme_str[_stats.fec1][1]);
    printf("    header crc          : %s\n", _header_valid ? "pass" : "FAIL");
    printf("    header data         : %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n",
            _header[0], _header[1], _header[2], _header[3],
            _header[4], _header[5], _header[6], _header[7]);
    printf("    num header errors   : %u / %u\n",
            count_bit_errors_array(_header, header, 8),
            8*8);
    printf("    payload crc         : %s\n", _payload_valid ? "pass" : "FAIL");
    printf("    num payload errors  : %u / %u\n",
            count_bit_errors_array(_payload, payload, 64),
            64*8);

    return 0;
}
int main(int argc, char*argv[])
{
    // Table G.18: coded bits of first DATA symbol
    unsigned char * msg_org = annexg_G18;

    // Table G.21: interleaved bits of first DATA symbol
    unsigned char * msg_test = annexg_G21;

    // options...
    unsigned int ncbps = 192;   // number of coded bits per OFDM symbol
    //unsigned int nbpsc = 4;     // number of bits per subcarrier (modulation depth)
    unsigned int rate = WLANFRAME_RATE_36;

    unsigned int n = ncbps / 8;
    
    unsigned int i;

    // 
    // interleave message
    //
    unsigned char msg_enc[n];
    wlan_interleaver_encode_symbol(rate, msg_org, msg_enc);
    
    // print results
    printf("interleaved:\n");
    for (i=0; i<n; i++)
        printf("%3u : 0x%.2x > 0x%.2x (0x%.2x) %s\n", i, msg_org[i], msg_enc[i], msg_test[i], msg_enc[i] == msg_test[i] ? "" : "*");
    printf("errors : %3u / %3u\n", count_bit_errors_array(msg_enc, msg_test, n), ncbps);

    if (count_bit_errors_array(msg_enc, msg_test, n) > 0) {
        fprintf(stderr,"fail: %s, encoding failure\n", __FILE__);
        exit(1);
    }

    // 
    // de-interleave message
    //
    unsigned char msg_dec[n];
    wlan_interleaver_decode_symbol(rate, msg_enc, msg_dec);
    
    // print results
    printf("de-interleaved:\n");
    for (i=0; i<n; i++)
        printf("%3u : 0x%.2x > 0x%.2x (0x%.2x) %s\n", i, msg_enc[i], msg_dec[i], msg_org[i], msg_dec[i] == msg_org[i] ? "" : "*");
    printf("errors : %3u / %3u\n", count_bit_errors_array(msg_dec, msg_org, n), ncbps);

    if (count_bit_errors_array(msg_dec, msg_org, n) > 0) {
        fprintf(stderr,"fail: %s, decoding failure\n", __FILE__);
        exit(1);
    }

    return 0;
}
// callback function
int callback(unsigned char *  _header,
             int              _header_valid,
             unsigned char *  _payload,
             unsigned int     _payload_len,
             int              _payload_valid,
             framesyncstats_s _stats,
             void *           _userdata)
{
    printf("**** callback invoked : rssi = %8.3f dB, evm = %8.3f dB, cfo = %8.5f\n", _stats.rssi, _stats.evm, _stats.cfo);

    unsigned int i;

    // print header data to standard output
    printf("  header rx  :");
    for (i=0; i<8; i++)
        printf(" %.2X", _header[i]);
    printf("\n");

    // print payload data to standard output
    printf("  payload rx :");
    for (i=0; i<_payload_len; i++) {
        printf(" %.2X", _payload[i]);
        if ( ((i+1)%26)==0 && i !=_payload_len-1 )
            printf("\n              ");
    }
    printf("\n");

    // count errors in received payload and print to standard output
    unsigned char * payload_tx = (unsigned char*) _userdata;
    unsigned int num_errors = count_bit_errors_array(_payload, payload_tx, _payload_len);
    printf("  bit errors : %u / %u\n", num_errors, 8*_payload_len);

    return 0;
}
static int callback(unsigned char *        _payload,
                    struct wlan_rxvector_s _rxvector,
                    void *                 _userdata)
{
    printf("**** callback invoked\n");

    struct wlanframesync_autotest_s * testdata = (struct wlanframesync_autotest_s*) _userdata;

    // count errors
    unsigned int num_bit_errors = count_bit_errors_array(_payload, testdata->msg_org, _rxvector.LENGTH);
    printf("bit errors : %4u / %4u\n", num_bit_errors, 8*_rxvector.LENGTH);

    // increment number of frames decoded
    testdata->num_frames++;

    // check results
    if (num_bit_errors != 0) {
        fprintf(stderr,"wlanframesync_autotest: errors detected!\n");
        testdata->valid = 0;

    } else if (testdata->length != _rxvector.LENGTH) {
        fprintf(stderr,"wlanframesync_autotest: length mismatch\n");
        testdata->valid = 0;

    } else if (testdata->datarate != _rxvector.DATARATE) {
        fprintf(stderr,"wlanframesync_autotest: rate mismatch\n");
        testdata->valid = 0;

    } else if (testdata->num_frames != 1) {
        fprintf(stderr,"wlanframesync_autotest: frame number mismatch\n");
        testdata->valid = 0;
    }

    return 0;
}
static int callback(int                    _header_valid,
                    unsigned char *        _payload,
                    struct wlan_rxvector_s _rxvector,
                    void *                 _userdata)
{
    printf("**** callback invoked (header: %s)\n", _header_valid ? "valid" : "INVALID");

    if (!_header_valid)
        return 1;

    // type cast 'userdata' as original data vector
    unsigned char * msg_org = (unsigned char*) _userdata;

    // count errors
    unsigned int num_bit_errors = count_bit_errors_array(_payload, msg_org, _rxvector.LENGTH);
    printf("bit errors : %4u / %4u\n", num_bit_errors, 8*_rxvector.LENGTH);

    return 0;
}
示例#6
0
int main(int argc, char*argv[])
{
    unsigned int i;
    
    // error vector [72 x 1]
    unsigned char e[9] = {0,0,0,0,0,0,0,0,2};

    // original message [64 x 1]
    unsigned char m[8] = {0,0,0,0,0,0,0,1};

    // derived values
    unsigned char v[9];     // encoded/transmitted message
    unsigned char r[9];     // received vector
    unsigned char s;        // syndrome vector
    unsigned char v_hat[9]; // estimated transmitted message
    unsigned char m_hat[8]; // estimated original message

    // original message
    printf("m (original message):\n         ");
    print_bitstring(m,64);

    // compute encoded/transmitted message: v = m*G
    v[0] = 0;
    for (i=0; i<8; i++) {
        v[0] <<= 1;

        unsigned int p = liquid_c_ones[ P[8*i+0] & m[0] ] +
                         liquid_c_ones[ P[8*i+1] & m[1] ] +
                         liquid_c_ones[ P[8*i+2] & m[2] ] +
                         liquid_c_ones[ P[8*i+3] & m[3] ] +
                         liquid_c_ones[ P[8*i+4] & m[4] ] +
                         liquid_c_ones[ P[8*i+5] & m[5] ] +
                         liquid_c_ones[ P[8*i+6] & m[6] ] +
                         liquid_c_ones[ P[8*i+7] & m[7] ];
        //printf("p = %u\n", p);
        v[0] |= p & 0x01;
    }
    for (i=0; i<8; i++)
        v[i+1] = m[i];
    printf("v (encoded/transmitted message):\n");
    print_bitstring(v,72);

    // use pre-determined error vector
    printf("e (error vector):\n");
    print_bitstring(e,72);

    // compute received vector: r = v + e
    for (i=0; i<9; i++)
        r[i] = v[i] ^ e[i];
    printf("r (received vector):\n");
    print_bitstring(r,72);

    // compute syndrome vector, s = r*H^T = ( H*r^T )^T
    s = 0;
    for (i=0; i<8; i++) {
        s <<= 1;
        unsigned int p =
            ( (r[0] & (1<<(8-i-1))) ? 1 : 0 )+
            liquid_c_ones[ P[8*i+0] & r[1] ] +
            liquid_c_ones[ P[8*i+1] & r[2] ] +
            liquid_c_ones[ P[8*i+2] & r[3] ] +
            liquid_c_ones[ P[8*i+3] & r[4] ] +
            liquid_c_ones[ P[8*i+4] & r[5] ] +
            liquid_c_ones[ P[8*i+5] & r[6] ] +
            liquid_c_ones[ P[8*i+6] & r[7] ] +
            liquid_c_ones[ P[8*i+7] & r[8] ];

        printf("p = %u\n", p);

        s |= p & 0x01;
    }
    printf("s (syndrome vector):\n");
    print_bitstring(&s,8);

    // compute weight of s
    unsigned int ws = liquid_count_ones(s);
    printf("w(s) = %u\n", ws);

    // estimated error vector
    unsigned char e_hat[9] = {0,0,0,0,0,0,0,0,0}; 

    if (ws == 0) {
        printf("no errors detected\n");
    } else {
        // estimate error location
        int syndrome_match = 0;

        // TODO : these can be pre-computed
        unsigned int n;
        for (n=0; n<72; n++) {
            // compute syndrome
            unsigned char e_test[9]  = {0,0,0,0,0,0,0,0,0};
            unsigned char s_hat = 0;

            div_t d = div(n,8);
            e_test[9-d.quot-1] = 1 << d.rem;

            for (i=0; i<8; i++) {
                s_hat <<= 1;
                unsigned int p =
                    ( (e_test[0] & (1<<(8-i-1))) ? 1 : 0 )+
                    liquid_c_ones[ P[8*i+0] & e_test[1] ] +
                    liquid_c_ones[ P[8*i+1] & e_test[2] ] +
                    liquid_c_ones[ P[8*i+2] & e_test[3] ] +
                    liquid_c_ones[ P[8*i+3] & e_test[4] ] +
                    liquid_c_ones[ P[8*i+4] & e_test[5] ] +
                    liquid_c_ones[ P[8*i+5] & e_test[6] ] +
                    liquid_c_ones[ P[8*i+6] & e_test[7] ] +
                    liquid_c_ones[ P[8*i+7] & e_test[8] ];

                s_hat |= p & 0x01;
            }

            // print results
            //printf("e_test:"); print_bitstring(e_test, 72);
            printf("%2u e=", n);
            for (i=0; i<9; i++) {
                print_bitstring_short(e_test[i],8);
                printf(" ");
            }
            printf("s=");
            print_bitstring_short(s_hat,8);
            if (s == s_hat) printf("*");
            printf("\n");

            if (s == s_hat) {
                memmove(e_hat, e_test, 9*sizeof(unsigned char));
                syndrome_match = 1;
            }
        }

        if (syndrome_match) {
            printf("syndrome match!\n");
        } else {
            printf("no syndrome match; expected multiple errors\n");
        }
    }

    // compute estimated transmitted message: v_hat = r + e_hat
    printf("e-hat (estimated error vector):\n");
    print_bitstring(e_hat,72);

    printf("v-hat (estimated transmitted vector):\n");
    for (i=0; i<9; i++)
        v_hat[i] = r[i] ^ e_hat[i];
    print_bitstring(v_hat,72);
    //print_bitstring(v,    72);

    // compute errors between v, v_hat
    unsigned int num_errors_encoded = count_bit_errors_array(v, v_hat, 9);
    printf("decoding errors (encoded)  : %2u / 72\n", num_errors_encoded);

    // compute estimated original message: (last 64 bits of encoded message)
    for (i=0; i<9; i++)
        m_hat[i] = v_hat[i+1];
    printf("m-hat (estimated original vector):\n         ");
    print_bitstring(m_hat,64);
    //print_bitstring(m,    64);

    // compute errors between m, m_hat
    unsigned int num_errors_decoded = count_bit_errors_array(m, m_hat, 8);
    printf("decoding errors (original) : %2u / 64\n", num_errors_decoded);

    return 0;
}
示例#7
0
int main(int argc, char*argv[])
{
    unsigned int i;
    
    // error vector [22 x 1]
    unsigned char err[5] = {0,0,0,0,2};

    // original message [16 x 1]
    unsigned char m[4] = {0,0,0,1};
    //m[0] = rand() & 0xffff;
    //m[1] = rand() & 0xffff;

    // derived values
    unsigned char v[5];     // encoded/transmitted message
    unsigned char e[5];     // error vector
    unsigned char r[5];     // received vector
    unsigned char s;        // syndrome vector
    unsigned char e_hat[5] = {0,0,0,0,0};  // estimated error vector
    unsigned char v_hat[5]; // estimated transmitted message
    unsigned char m_hat[4]; // estimated original message

#if 0
    // print P matrix
    printf("P : \n");
    print_bitstring(&P[ 0],32);
    print_bitstring(&P[ 4],32);
    print_bitstring(&P[ 8],32);
    print_bitstring(&P[12],32);
    print_bitstring(&P[16],32);
    print_bitstring(&P[20],32);
    print_bitstring(&P[24],32);
#endif

    // original message
    printf("m (original message):   ");
    print_bitstring(m,32);

    // compute encoded/transmitted message: v = m*G
    v[0] = 0;
    for (i=0; i<7; i++) {
        v[0] <<= 1;

        unsigned int p = liquid_c_ones[P[4*i+0] & m[0]] +
                         liquid_c_ones[P[4*i+1] & m[1]] +
                         liquid_c_ones[P[4*i+2] & m[2]] +
                         liquid_c_ones[P[4*i+3] & m[3]];
        //printf("p = %u\n", p);
        v[0] |= p & 0x01;
    }
    v[1] = m[0];
    v[2] = m[1];
    v[3] = m[2];
    v[4] = m[3];
    printf("v (encoded message):    ");
    print_bitstring(v,39);

    // use pre-determined error vector
    e[0] = err[0];
    e[1] = err[1];
    e[2] = err[2];
    e[3] = err[3];
    e[4] = err[4];
    printf("e (error vector):       ");
    print_bitstring(e,39);

    // compute received vector: r = v + e
    r[0] = v[0] ^ e[0];
    r[1] = v[1] ^ e[1];
    r[2] = v[2] ^ e[2];
    r[3] = v[3] ^ e[3];
    r[4] = v[4] ^ e[4];
    printf("r (received vector):    ");
    print_bitstring(r,39);

    // compute syndrome vector, s = r*H^T = ( H*r^T )^T
    s = 0;
    for (i=0; i<7; i++) {
        s <<= 1;

        unsigned int p =
            ( (r[0] & (1<<(7-i-1))) ? 1 : 0 )+
            liquid_count_ones(P[4*i+0] & r[1]) +
            liquid_count_ones(P[4*i+1] & r[2]) +
            liquid_count_ones(P[4*i+2] & r[3]) +
            liquid_count_ones(P[4*i+3] & r[4]);
        //printf("p = %u\n", p);

        s |= p & 0x01;
    }
    printf("s (syndrome vector):    ");
    print_bitstring(&s,7);

    // compute weight of s
    unsigned int ws = liquid_count_ones(s);
    printf("weight(s) = %u\n", ws);

    if (ws == 0) {
        printf("no errors detected\n");
    } else {
        // estimate error location
        int syndrome_match = 0;

        // TODO : these can be pre-computed
        unsigned int n;
        for (n=0; n<39; n++) {
            // compute syndrome
            unsigned int s_test = 0;
            unsigned char e_test[5] = {0,0,0,0,0};

            div_t d = div(n,8);
            e_test[5-d.quot-1] = 1 << d.rem;

            for (i=0; i<7; i++) {
                s_test <<= 1;
                unsigned int p =
                    ( (e_test[0] & (1<<(7-i-1))) ? 1 : 0 )+
                    liquid_count_ones(P[4*i+0] & e_test[1]) +
                    liquid_count_ones(P[4*i+1] & e_test[2]) +
                    liquid_count_ones(P[4*i+2] & e_test[3]) +
                    liquid_count_ones(P[4*i+3] & e_test[4]);

                s_test |= p & 0x01;
            }

#if 1
            // print results
            //printf("e_test:"); print_bitstring(e_test, 72);
            printf("%3u : e = ", n);
            print_bitstring_short(e_test[0],7); printf(" ");
            print_bitstring_short(e_test[1],8); printf(" ");
            print_bitstring_short(e_test[2],8); printf(" ");
            print_bitstring_short(e_test[3],8); printf(" ");
            print_bitstring_short(e_test[4],8); printf(" ");
            printf(", s = ");
            print_bitstring_short(s_test,7);
            if (s == s_test) printf(" *");
            printf("\n");
#else
            // print output array (secded2216_syndrome_w1[])
            printf("0x%.2x\n", s_test);
#endif

            if (s == s_test) {
                memmove(e_hat, e_test, sizeof(e_test));
                syndrome_match = 1;
            }
        }

        if (syndrome_match) {
            printf("syndrome match!\n");
        } else {
            printf("no syndrome match; expected multiple errors\n");
        }
    }

    // compute estimated transmitted message: v_hat = r + e_hat
    printf("e-hat (estimated error):");
    print_bitstring(e_hat,39);

    printf("v-hat (estimated tx):   ");
    v_hat[0] = r[0] ^ e_hat[0];
    v_hat[1] = r[1] ^ e_hat[1];
    v_hat[2] = r[2] ^ e_hat[2];
    v_hat[3] = r[3] ^ e_hat[3];
    v_hat[4] = r[4] ^ e_hat[4];
    print_bitstring(v_hat,39);

    // compute estimated original message: (last 16 bits of encoded message)
    m_hat[0] = v_hat[1];
    m_hat[1] = v_hat[2];
    m_hat[2] = v_hat[3];
    m_hat[3] = v_hat[4];
    printf("m-hat (estimated orig.):");
    print_bitstring(m_hat,32);

    // compute errors between v, v_hat
    unsigned int num_errors_encoded = count_bit_errors_array(v, v_hat, 5);
    printf("decoding errors (encoded)  : %2u / 39\n", num_errors_encoded);

    // compute errors between m, m_hat
    unsigned int num_errors_decoded = count_bit_errors_array(m, m_hat, 4);
    printf("decoding errors (original) : %2u / 32\n", num_errors_decoded);

    return 0;
}