aboutsummaryrefslogtreecommitdiff
path: root/src/fsk_get_test_bits.c
blob: 937ccf057ba54ae7c6d26145f4168d5b672d06e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*---------------------------------------------------------------------------*\

  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 <http://www.gnu.org/licenses/>.
*/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "fsk.h"

#define TEST_FRAME_SIZE 100  /* arbitrary choice, repeats after this
                                many bits, sets frame size for rx
                                processing */

int main(int argc,char *argv[]){
    int bitcnt, framecnt;
    int framesize = TEST_FRAME_SIZE;
    int i;
    FILE *fout;
    uint8_t *bitbuf;
    
    if(argc < 3){
        fprintf(stderr,"usage: %s OutputBitsOnePerByte numBits [framesize]\n",argv[0]);
        exit(1);
    }

    if (argc == 4){
        framesize = atoi(argv[3]);
        fprintf(stderr, "Using custom frame size of %d bits\n", framesize);
    }
    
    /* Extract parameters */
    bitcnt = atoi(argv[2]);
    framecnt = bitcnt/framesize;
    if (framecnt == 0) {
        fprintf(stderr,"Need a minimum of %d bits\n", framesize);
        exit(1);
    }

    if(strcmp(argv[1],"-")==0){
        fout = stdout;
    }else{
        fout = fopen(argv[1],"w");
    }
    
    if(fout==NULL){
        fprintf(stderr,"Couldn't open output file: %s\n", argv[1]);
        exit(1);
    }
    
    /* allocate buffers for processing */
    bitbuf = (uint8_t*)malloc(sizeof(uint8_t)*framesize);
    
    /* Generate buffer of test frame bits from known seed */
    srand(158324);
    for(i=0; i<framesize; i++){
	bitbuf[i] = rand()&0x1;
    }
        
    /* Output test frames */
    srand(158324);
    for(i=0; i<framecnt; i++){
	fwrite(bitbuf,sizeof(uint8_t),framesize,fout);
	if(fout == stdout){
	    fflush(fout);
	}
    }
    
    free(bitbuf);
    fclose(fout);

    return 0;
}