/*---------------------------------------------------------------------------*\ FILE........: fsk_get_test_bits.c AUTHOR......: Brady O'Brien DATE CREATED: January 2016 Generates a pseudorandom sequence of bits for testing of fsk_mod and fsk_demod. \*---------------------------------------------------------------------------*/ /* Copyright (C) 2016 David Rowe All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1, as published by the Free Software Foundation. This program 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 Lesser General Public License along with this program; if not, see . */ #include #include #include #include "fsk.h" #define TEST_FRAME_SIZE 100 /* must match fsk_get_test_bits.c */ #define VALID_PACKET_BER_THRESH 0.1 int main(int argc,char *argv[]){ int bitcnt,biterr,i,errs,packetcnt; int framesize = TEST_FRAME_SIZE; float valid_packet_ber_thresh = VALID_PACKET_BER_THRESH; int packet_pass_thresh = 0; float ber_pass_thresh = 0; FILE *fin; uint8_t *bitbuf_tx, *bitbuf_rx, abit; int verbose = 1; char usage[] = "usage: %s [-f frameSizeBits] [-t VaildFrameBERThreshold] [-b BERPass] [-p numPacketsPass] InputOneBitPerByte\n"; int opt; while ((opt = getopt(argc, argv, "f:b:p:hqt:")) != -1) { switch (opt) { case 't': valid_packet_ber_thresh = atof(optarg); break; case 'b': ber_pass_thresh = atof(optarg); break; case 'p': packet_pass_thresh = atoi(optarg); break; case 'f': framesize = atoi(optarg); break; case 'q': verbose = 0; break; case 'h': default: fprintf(stderr, usage, argv[0]); exit(1); } } if (argc == 1) { fprintf(stderr, usage, argv[0]); exit(1); } char *fname = argv[optind++]; if ((strcmp(fname,"-")==0) || (argc<2)){ fin = stdin; } else { fin = fopen(fname,"r"); } if(fin==NULL){ fprintf(stderr,"Couldn't open input file: %s\n", argv[1]); exit(1); } /* allocate buffers for processing */ bitbuf_tx = (uint8_t*)alloca(sizeof(uint8_t)*framesize); bitbuf_rx = (uint8_t*)alloca(sizeof(uint8_t)*framesize); /* Generate known tx frame from known seed */ srand(158324); for(i=0; i0){ /* update sliding window of input bits */ for(i=0; i= packet_pass_thresh) && (ber <= ber_pass_thresh)) { fprintf(stderr,"PASS\n"); return 0; } else { fprintf(stderr,"FAIL\n"); return 1; } }