aboutsummaryrefslogtreecommitdiff
path: root/src/ofdm_get_test_bits.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 /src/ofdm_get_test_bits.c
parent6588e77f38bdebd7adffe091b22e7760d95d0ccb (diff)
parent4d6c143c0abec15e1d6ed1fd95d36f80e6cb7df8 (diff)
Merge pull request #3 from drowe67/dr-cleanup21.2.0
Cleanup Part 2
Diffstat (limited to 'src/ofdm_get_test_bits.c')
-rw-r--r--src/ofdm_get_test_bits.c216
1 files changed, 106 insertions, 110 deletions
diff --git a/src/ofdm_get_test_bits.c b/src/ofdm_get_test_bits.c
index c13c410..d5a7210 100644
--- a/src/ofdm_get_test_bits.c
+++ b/src/ofdm_get_test_bits.c
@@ -27,135 +27,131 @@
#define OPTPARSE_IMPLEMENTATION
#define OPTPARSE_API static
-#include "optparse.h"
-
#include <assert.h>
+#include <errno.h>
+#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <math.h>
-#include <errno.h>
#include "codec2_ofdm.h"
-#include "ofdm_internal.h"
-#include "ldpc_codes.h"
#include "interldpc.h"
+#include "ldpc_codes.h"
+#include "ofdm_internal.h"
+#include "optparse.h"
#include "varicode.h"
-#define IS_DIR_SEPARATOR(c) ((c) == '/')
+#define IS_DIR_SEPARATOR(c) ((c) == '/')
static const char *progname;
void opt_help() {
- fprintf(stderr, "\nUsage: %s [options]\n\n", progname);
- fprintf(stderr, " --out filename Name of OutputOneCharPerBitFile\n");
- fprintf(stderr, " --frames n Number of frames to output (default 10)\n");
- fprintf(stderr, " --length n Frame length in bits (default 238)\n");
- fprintf(stderr, " --bcb Insert burst control byte at the start of each frame (FSK_LDPC testing)\n");
- fprintf(stderr, " --verbose Output variable assigned values to stderr\n\n");
-
- exit(-1);
+ fprintf(stderr, "\nUsage: %s [options]\n\n", progname);
+ fprintf(stderr, " --out filename Name of OutputOneCharPerBitFile\n");
+ fprintf(stderr,
+ " --frames n Number of frames to output (default 10)\n");
+ fprintf(stderr, " --length n Frame length in bits (default 238)\n");
+ fprintf(stderr,
+ " --bcb Insert burst control byte at the start of "
+ "each frame (FSK_LDPC testing)\n");
+ fprintf(
+ stderr,
+ " --verbose Output variable assigned values to stderr\n\n");
+
+ exit(-1);
}
-int main(int argc, char *argv[])
-{
- FILE *fout;
- char *fout_name = NULL;
- int opt, verbose, n;
- int Nframes, output_specified, bcb_en;
- int Ndatabitsperpacket;
- uint8_t burst_control;
-
- char *pn = argv[0] + strlen (argv[0]);
-
- while (pn != argv[0] && !IS_DIR_SEPARATOR (pn[-1]))
- --pn;
-
- progname = pn;
-
- /* Turn off stream buffering */
-
- setvbuf(stdout, NULL, _IONBF, BUFSIZ);
-
- fout = stdout;
- output_specified = 0;
- Nframes = 10;
- Ndatabitsperpacket = 224;
- verbose = 0;
- bcb_en = 0;
-
- struct optparse options;
-
- struct optparse_long longopts[] = {
- {"bcb", 'b', OPTPARSE_NONE},
- {"out", 'o', OPTPARSE_REQUIRED},
- {"frames", 'n', OPTPARSE_REQUIRED},
- {"length", 'l', OPTPARSE_REQUIRED},
- {"verbose", 'v', OPTPARSE_NONE},
- {0, 0, 0}
- };
-
- optparse_init(&options, argv);
-
- while ((opt = optparse_long(&options, longopts, NULL)) != -1) {
- switch (opt) {
- case '?':
- opt_help();
- case 'b':
- bcb_en = 1;
- break;
- case 'o':
- fout_name = options.optarg;
- output_specified = 1;
- break;
- case 'n':
- Nframes = atoi(options.optarg);
- break;
- case 'l':
- Ndatabitsperpacket = atoi(options.optarg);
- break;
- case 'v':
- verbose = 1;
- }
+int main(int argc, char *argv[]) {
+ FILE *fout;
+ char *fout_name = NULL;
+ int opt, verbose, n;
+ int Nframes, output_specified, bcb_en;
+ int Ndatabitsperpacket;
+ uint8_t burst_control;
+
+ char *pn = argv[0] + strlen(argv[0]);
+
+ while (pn != argv[0] && !IS_DIR_SEPARATOR(pn[-1])) --pn;
+
+ progname = pn;
+
+ /* Turn off stream buffering */
+
+ setvbuf(stdout, NULL, _IONBF, BUFSIZ);
+
+ fout = stdout;
+ output_specified = 0;
+ Nframes = 10;
+ Ndatabitsperpacket = 224;
+ verbose = 0;
+ bcb_en = 0;
+
+ struct optparse options;
+
+ struct optparse_long longopts[] = {
+ {"bcb", 'b', OPTPARSE_NONE}, {"out", 'o', OPTPARSE_REQUIRED},
+ {"frames", 'n', OPTPARSE_REQUIRED}, {"length", 'l', OPTPARSE_REQUIRED},
+ {"verbose", 'v', OPTPARSE_NONE}, {0, 0, 0}};
+
+ optparse_init(&options, argv);
+
+ while ((opt = optparse_long(&options, longopts, NULL)) != -1) {
+ switch (opt) {
+ case '?':
+ opt_help();
+ case 'b':
+ bcb_en = 1;
+ break;
+ case 'o':
+ fout_name = options.optarg;
+ output_specified = 1;
+ break;
+ case 'n':
+ Nframes = atoi(options.optarg);
+ break;
+ case 'l':
+ Ndatabitsperpacket = atoi(options.optarg);
+ break;
+ case 'v':
+ verbose = 1;
}
+ }
- /* Print remaining arguments to give user a hint */
-
- char *arg;
+ /* Print remaining arguments to give user a hint */
- while ((arg = optparse_arg(&options)))
- fprintf(stderr, "%s\n", arg);
+ char *arg;
- if (output_specified) {
- if ((fout = fopen(fout_name, "wb")) == NULL) {
- fprintf(stderr, "Error opening output bit file: %s\n", fout_name);
- exit(-1);
- }
- }
-
- if (verbose)
- fprintf(stderr, "Nframes: %d Ndatabitsperframe: %d bcb: %d\n", Nframes, Ndatabitsperpacket, bcb_en);
+ while ((arg = optparse_arg(&options))) fprintf(stderr, "%s\n", arg);
- uint8_t data_bits[Ndatabitsperpacket];
- ofdm_generate_payload_data_bits(data_bits, Ndatabitsperpacket);
-
- burst_control = 1;
- for (n = 0; n<Nframes; n++) {
- if (bcb_en) fwrite(&burst_control, 1, 1, fout);
- fwrite(data_bits, sizeof(char), Ndatabitsperpacket, fout);
- burst_control = 0;
+ if (output_specified) {
+ if ((fout = fopen(fout_name, "wb")) == NULL) {
+ fprintf(stderr, "Error opening output bit file: %s\n", fout_name);
+ exit(-1);
}
- if (bcb_en) {
- // dummy end frame just to signal end of burst
- burst_control = 2;
- fwrite(&burst_control, 1, 1, fout);
- memset(data_bits, 0, Ndatabitsperpacket);
- fwrite(data_bits, sizeof(char), Ndatabitsperpacket, fout);
- }
-
- if (output_specified)
- fclose(fout);
-
- return 0;
+ }
+
+ if (verbose)
+ fprintf(stderr, "Nframes: %d Ndatabitsperframe: %d bcb: %d\n", Nframes,
+ Ndatabitsperpacket, bcb_en);
+
+ uint8_t data_bits[Ndatabitsperpacket];
+ ofdm_generate_payload_data_bits(data_bits, Ndatabitsperpacket);
+
+ burst_control = 1;
+ for (n = 0; n < Nframes; n++) {
+ if (bcb_en) fwrite(&burst_control, 1, 1, fout);
+ fwrite(data_bits, sizeof(char), Ndatabitsperpacket, fout);
+ burst_control = 0;
+ }
+ if (bcb_en) {
+ // dummy end frame just to signal end of burst
+ burst_control = 2;
+ fwrite(&burst_control, 1, 1, fout);
+ memset(data_bits, 0, Ndatabitsperpacket);
+ fwrite(data_bits, sizeof(char), Ndatabitsperpacket, fout);
+ }
+
+ if (output_specified) fclose(fout);
+
+ return 0;
}
-