aboutsummaryrefslogtreecommitdiff
path: root/unittest/tfsk.c
diff options
context:
space:
mode:
authordrowe67 <[email protected]>2023-07-20 08:59:48 +0930
committerGitHub <[email protected]>2023-07-20 08:59:48 +0930
commit06d4c11e699b0351765f10398abb4f663a984f36 (patch)
tree33e22af0814c5b6c3d676f096ae8c2ac8a3ed9f0 /unittest/tfsk.c
parent6588e77f38bdebd7adffe091b22e7760d95d0ccb (diff)
parent4d6c143c0abec15e1d6ed1fd95d36f80e6cb7df8 (diff)
Merge pull request #3 from drowe67/dr-cleanup21.2.0
Cleanup Part 2
Diffstat (limited to 'unittest/tfsk.c')
-rw-r--r--unittest/tfsk.c360
1 files changed, 181 insertions, 179 deletions
diff --git a/unittest/tfsk.c b/unittest/tfsk.c
index 35aa970..337a350 100644
--- a/unittest/tfsk.c
+++ b/unittest/tfsk.c
@@ -27,13 +27,14 @@
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-
//#define MODEMPROBE_ENABLE
-#include "modem_probe.h"
#include <stdio.h>
-/* Note: This is a dirty hack to force fsk.c to compile with modem probing enabled */
+#include "modem_probe.h"
+
+/* Note: This is a dirty hack to force fsk.c to compile with modem probing
+ * enabled */
#include "fsk.c"
#define ST_BITS 10000
@@ -44,189 +45,190 @@
#define ST_EBNO 8
#define ST_M 2
-#define TEST_SELF_FULL 1 /* No-arg self test */
-#define TEST_MOD 2 /* Test modulator using in and out file */
-#define TEST_MOD_H 3 /* Test modulator using in and out file */
-#define TEST_DEMOD 4 /* Test demodulator using in and out file */
-#define TEST_DEMOD_H 5 /* Test demodulator using in and out file */
-
-
-int main(int argc,char *argv[]){
- struct FSK *fsk;
- int Fs,Rs,f1,fs,M, lock_nin;
- FILE *fin,*fout;
-
- uint8_t *bitbuf = NULL;
- float *modbuf = NULL;
- uint8_t *bitbufp;
- float *modbufp;
-
- size_t bitbufsize = 0;
- size_t modbufsize = 0;
-
- int test_type;
-
- int i;
-
- fin = NULL;
- fout = NULL;
-
- /* Set up full self-test */
- if(argc == 1){
- test_type = TEST_SELF_FULL;
- modem_probe_init("fsk2","fsk2_tfsk_log.txt");
- Fs = ST_FS;
- Rs = ST_RS;
- f1 = ST_F1;
- fs = ST_Fs;
- M = ST_M;
- lock_nin = 0;
- } else if (argc<10){
+#define TEST_SELF_FULL 1 /* No-arg self test */
+#define TEST_MOD 2 /* Test modulator using in and out file */
+#define TEST_MOD_H 3 /* Test modulator using in and out file */
+#define TEST_DEMOD 4 /* Test demodulator using in and out file */
+#define TEST_DEMOD_H 5 /* Test demodulator using in and out file */
+
+int main(int argc, char *argv[]) {
+ struct FSK *fsk;
+ int Fs, Rs, f1, fs, M, lock_nin;
+ FILE *fin, *fout;
+
+ uint8_t *bitbuf = NULL;
+ float *modbuf = NULL;
+ uint8_t *bitbufp;
+ float *modbufp;
+
+ size_t bitbufsize = 0;
+ size_t modbufsize = 0;
+
+ int test_type;
+
+ int i;
+
+ fin = NULL;
+ fout = NULL;
+
+ /* Set up full self-test */
+ if (argc == 1) {
+ test_type = TEST_SELF_FULL;
+ modem_probe_init("fsk2", "fsk2_tfsk_log.txt");
+ Fs = ST_FS;
+ Rs = ST_RS;
+ f1 = ST_F1;
+ fs = ST_Fs;
+ M = ST_M;
+ lock_nin = 0;
+ } else if (argc < 10) {
/* Not running any test */
- printf("Usage: %s [(M|D|DX) Mode TXFreq1 TXFreqSpace SampleRate SymbolRate lock_nin InputFile OutputFile OctaveLogFile]\n",argv[0]);
- exit(1);
- } else {
+ printf(
+ "Usage: %s [(M|D|DX) Mode TXFreq1 TXFreqSpace SampleRate SymbolRate "
+ "lock_nin InputFile OutputFile OctaveLogFile]\n",
+ argv[0]);
+ exit(1);
+ } else {
/* Running stim-drivin test */
- /* Mod test */
- if(strcmp(argv[1],"MX")==0){
- test_type = TEST_MOD_H;
- } else if(strcmp(argv[1],"M")==0 || strcmp(argv[1],"m")==0) {
- test_type = TEST_MOD;
- /* Demod test */
- } else if(strcmp(argv[1],"DX")==0) {
- test_type = TEST_DEMOD_H;
- } else if(strcmp(argv[1],"D")==0 || strcmp(argv[1],"d")==0) {
- test_type = TEST_DEMOD;
- } else {
- printf("Must specify mod or demod test with M or D\n");
- exit(1);
- }
- /* Extract parameters */
- M = atoi(argv[2]);
- f1 = atoi(argv[3]);
- fs = atoi(argv[4]);
- Fs = atoi(argv[5]);
- Rs = atoi(argv[6]);
- lock_nin = atoi(argv[7]);
-
- /* Open files */
- fin = fopen(argv[8],"r");
- fout = fopen(argv[9],"w");
-
- if(fin == NULL || fout == NULL){
- printf("Couldn't open test vector files\n");
- exit(1);
- }
- /* Init modem probing */
- modem_probe_init("fsk",argv[10]);
-
+ /* Mod test */
+ if (strcmp(argv[1], "MX") == 0) {
+ test_type = TEST_MOD_H;
+ } else if (strcmp(argv[1], "M") == 0 || strcmp(argv[1], "m") == 0) {
+ test_type = TEST_MOD;
+ /* Demod test */
+ } else if (strcmp(argv[1], "DX") == 0) {
+ test_type = TEST_DEMOD_H;
+ } else if (strcmp(argv[1], "D") == 0 || strcmp(argv[1], "d") == 0) {
+ test_type = TEST_DEMOD;
+ } else {
+ printf("Must specify mod or demod test with M or D\n");
+ exit(1);
}
-
- srand(1);
- /* set up FSK */
- if(test_type == TEST_DEMOD_H || test_type == TEST_MOD_H){
- fsk = fsk_create_hbr(Fs,Rs,M,10,FSK_DEFAULT_NSYM,f1,fs);
- if(test_type == TEST_DEMOD_H)
- test_type = TEST_DEMOD;
- else
- test_type = TEST_MOD;
- }else{
- fsk = fsk_create(Fs,Rs,M,f1,fs);
+ /* Extract parameters */
+ M = atoi(argv[2]);
+ f1 = atoi(argv[3]);
+ fs = atoi(argv[4]);
+ Fs = atoi(argv[5]);
+ Rs = atoi(argv[6]);
+ lock_nin = atoi(argv[7]);
+
+ /* Open files */
+ fin = fopen(argv[8], "r");
+ fout = fopen(argv[9], "w");
+
+ if (fin == NULL || fout == NULL) {
+ printf("Couldn't open test vector files\n");
+ exit(1);
}
- fsk_set_freq_est_limits(fsk, 300, 2800);
- fsk->lock_nin = lock_nin;
-
- /* Modulate! */
- if(test_type == TEST_MOD || test_type == TEST_SELF_FULL){
- /* Generate random bits for self test */
- if(test_type == TEST_SELF_FULL){
- bitbufsize = ST_BITS;
- bitbuf = (uint8_t*) malloc(sizeof(uint8_t)*ST_BITS);
- for(i=0; i<ST_BITS; i++){
- /* Generate a randomish bit */
- bitbuf[i] = (uint8_t)(rand()&0x01);
- }
- } else { /* Load bits from a file */
- /* Figure out how many bits are in the input file */
- fseek(fin, 0L, SEEK_END);
- bitbufsize = ftell(fin);
- fseek(fin, 0L, SEEK_SET);
- bitbuf = malloc(sizeof(uint8_t)*bitbufsize);
- i = 0;
- /* Read in some bits */
- bitbufp = bitbuf;
- while( fread(bitbufp,sizeof(uint8_t),fsk->Nbits,fin) == fsk->Nbits){
- i++;
- bitbufp+=fsk->Nbits;
- /* Make sure we don't break the buffer */
- if(i*fsk->Nbits > bitbufsize){
- bitbuf = realloc(bitbuf,sizeof(uint8_t)*(bitbufsize+fsk->Nbits));
- bitbufsize += fsk->Nbits;
- }
- }
+ /* Init modem probing */
+ modem_probe_init("fsk", argv[10]);
+ }
+
+ srand(1);
+ /* set up FSK */
+ if (test_type == TEST_DEMOD_H || test_type == TEST_MOD_H) {
+ fsk = fsk_create_hbr(Fs, Rs, M, 10, FSK_DEFAULT_NSYM, f1, fs);
+ if (test_type == TEST_DEMOD_H)
+ test_type = TEST_DEMOD;
+ else
+ test_type = TEST_MOD;
+ } else {
+ fsk = fsk_create(Fs, Rs, M, f1, fs);
+ }
+ fsk_set_freq_est_limits(fsk, 300, 2800);
+ fsk->lock_nin = lock_nin;
+
+ /* Modulate! */
+ if (test_type == TEST_MOD || test_type == TEST_SELF_FULL) {
+ /* Generate random bits for self test */
+ if (test_type == TEST_SELF_FULL) {
+ bitbufsize = ST_BITS;
+ bitbuf = (uint8_t *)malloc(sizeof(uint8_t) * ST_BITS);
+ for (i = 0; i < ST_BITS; i++) {
+ /* Generate a randomish bit */
+ bitbuf[i] = (uint8_t)(rand() & 0x01);
+ }
+ } else { /* Load bits from a file */
+ /* Figure out how many bits are in the input file */
+ fseek(fin, 0L, SEEK_END);
+ bitbufsize = ftell(fin);
+ fseek(fin, 0L, SEEK_SET);
+ bitbuf = malloc(sizeof(uint8_t) * bitbufsize);
+ i = 0;
+ /* Read in some bits */
+ bitbufp = bitbuf;
+ while (fread(bitbufp, sizeof(uint8_t), fsk->Nbits, fin) == fsk->Nbits) {
+ i++;
+ bitbufp += fsk->Nbits;
+ /* Make sure we don't break the buffer */
+ if (i * fsk->Nbits > bitbufsize) {
+ bitbuf = realloc(bitbuf, sizeof(uint8_t) * (bitbufsize + fsk->Nbits));
+ bitbufsize += fsk->Nbits;
}
- /* Allocate modulation buffer */
- modbuf = (float*)malloc(sizeof(float)*(bitbufsize/fsk->Nbits)*fsk->N*4);
- modbufsize = (bitbufsize/fsk->Nbits)*fsk->N;
- /* Do the modulation */
- modbufp = modbuf;
- bitbufp = bitbuf;
- while( bitbufp < bitbuf+bitbufsize){
- fsk_mod(fsk, modbufp, bitbufp, fsk->Nbits);
- modbufp += fsk->N;
- bitbufp += fsk->Nbits;
- }
- /* For a mod-only test, write out the result */
- if(test_type == TEST_MOD){
- fwrite(modbuf,sizeof(float),modbufsize,fout);
- free(modbuf);
- }
- /* Free bit buffer */
- free(bitbuf);
+ }
}
-
- /* Now test the demod */
- if(test_type == TEST_DEMOD || test_type == TEST_SELF_FULL){
- free(modbuf);
- modbuf = malloc(sizeof(float)*(fsk->N+fsk->Ts*2));
- bitbuf = malloc(sizeof(uint8_t)*fsk->Nbits);
- /* Demod-only test */
- if(test_type == TEST_DEMOD){
- while( fread(modbuf,sizeof(float),fsk_nin(fsk),fin) == fsk_nin(fsk) ){
- int n = fsk_nin(fsk);
- COMP modbuf_comp[n];
- for(i=0; i<n; i++) {
- modbuf_comp[i].real = modbuf[i];
- modbuf_comp[i].imag = 0.0;
- }
- fsk_demod(fsk,bitbuf,modbuf_comp);
- fwrite(bitbuf,sizeof(uint8_t),fsk->Nbits,fout);
- }
- }
- /* Demod after channel imp. and mod */
- else{
- bitbufp = bitbuf;
- modbufp = modbuf;
- while( modbufp < modbuf + modbufsize){
- int n = fsk_nin(fsk);
- COMP modbuf_comp[n];
- for(i=0; i<n; i++) {
- modbuf_comp[i].real = modbuf[i];
- modbuf_comp[i].imag = 0.0;
- }
- fsk_demod(fsk,bitbuf,modbuf_comp);
- modbufp += fsk_nin(fsk);
- }
+ /* Allocate modulation buffer */
+ modbuf =
+ (float *)malloc(sizeof(float) * (bitbufsize / fsk->Nbits) * fsk->N * 4);
+ modbufsize = (bitbufsize / fsk->Nbits) * fsk->N;
+ /* Do the modulation */
+ modbufp = modbuf;
+ bitbufp = bitbuf;
+ while (bitbufp < bitbuf + bitbufsize) {
+ fsk_mod(fsk, modbufp, bitbufp, fsk->Nbits);
+ modbufp += fsk->N;
+ bitbufp += fsk->Nbits;
+ }
+ /* For a mod-only test, write out the result */
+ if (test_type == TEST_MOD) {
+ fwrite(modbuf, sizeof(float), modbufsize, fout);
+ free(modbuf);
+ }
+ /* Free bit buffer */
+ free(bitbuf);
+ }
+
+ /* Now test the demod */
+ if (test_type == TEST_DEMOD || test_type == TEST_SELF_FULL) {
+ free(modbuf);
+ modbuf = malloc(sizeof(float) * (fsk->N + fsk->Ts * 2));
+ bitbuf = malloc(sizeof(uint8_t) * fsk->Nbits);
+ /* Demod-only test */
+ if (test_type == TEST_DEMOD) {
+ while (fread(modbuf, sizeof(float), fsk_nin(fsk), fin) == fsk_nin(fsk)) {
+ int n = fsk_nin(fsk);
+ COMP modbuf_comp[n];
+ for (i = 0; i < n; i++) {
+ modbuf_comp[i].real = modbuf[i];
+ modbuf_comp[i].imag = 0.0;
}
- free(bitbuf);
+ fsk_demod(fsk, bitbuf, modbuf_comp);
+ fwrite(bitbuf, sizeof(uint8_t), fsk->Nbits, fout);
+ }
}
-
- modem_probe_close();
- if(test_type == TEST_DEMOD || test_type == TEST_MOD){
- fclose(fin);
- fclose(fout);
+ /* Demod after channel imp. and mod */
+ else {
+ bitbufp = bitbuf;
+ modbufp = modbuf;
+ while (modbufp < modbuf + modbufsize) {
+ int n = fsk_nin(fsk);
+ COMP modbuf_comp[n];
+ for (i = 0; i < n; i++) {
+ modbuf_comp[i].real = modbuf[i];
+ modbuf_comp[i].imag = 0.0;
+ }
+ fsk_demod(fsk, bitbuf, modbuf_comp);
+ modbufp += fsk_nin(fsk);
+ }
}
- fsk_destroy(fsk);
- exit(0);
+ free(bitbuf);
+ }
+
+ modem_probe_close();
+ if (test_type == TEST_DEMOD || test_type == TEST_MOD) {
+ fclose(fin);
+ fclose(fout);
+ }
+ fsk_destroy(fsk);
+ exit(0);
}
-