Ejemplo n.º 1
0
// Demodulate an ADSB (Long UAT or Basic UAT) downlink frame
// with the first sync bit in 'phi', storing the frame into 'to'
// of length up to LONG_FRAME_BYTES. Set '*rs_errors' to the
// number of corrected errors, or 9999 if demodulation failed.
// Return 0 if demodulation failed, or the number of bits (not
// samples) consumed if demodulation was OK.
static int demod_adsb_frame(uint16_t *phi, uint8_t *to, int *rs_errors)
{
    int16_t center_dphi;
    int frametype;

    if (!check_sync_word(phi, ADSB_SYNC_WORD, &center_dphi)) {
        *rs_errors = 9999;
        return 0;
    }

    demod_frame(phi + SYNC_BITS*2, to, LONG_FRAME_BYTES, center_dphi);
    frametype = correct_adsb_frame(to, rs_errors);
    if (frametype == 1)
        return (SYNC_BITS + SHORT_FRAME_BITS);
    else if (frametype == 2)
        return (SYNC_BITS + LONG_FRAME_BITS);
    else
        return 0;
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
    int i;
    uint8_t input[LONG_FRAME_BYTES];
    uint8_t expected[LONG_FRAME_DATA_BYTES];
    int all_ok = 1;

    init_fec();
    
    for (i = 0; downlink_tests[i].testname; ++i) {
        int rs_errors;
        int frametype;
        int ok = 1;

        fprintf(stderr, "%s: ", downlink_tests[i].testname);

        hex_to_bytes(downlink_tests[i].input, input);
        frametype = correct_adsb_frame(input, &rs_errors);
        if (frametype != downlink_tests[i].frametype) {
            fprintf(stderr, "FAIL: expected frametype %d, got frametype %d\n", downlink_tests[i].frametype, frametype);
            ok = 0;
        } else if (downlink_tests[i].expected) {
            hex_to_bytes(downlink_tests[i].expected, expected);
            if (memcmp(expected, input, (frametype == 2) ? LONG_FRAME_DATA_BYTES : SHORT_FRAME_DATA_BYTES) != 0) {
                fprintf(stderr, "FAIL: wrong corrected output\n");
                ok = 0;
            }
        }

        if (ok)
            fprintf(stderr, "PASS\n");
        else
            all_ok = 0;
    }
    
    return all_ok ? 0 : 1;
}