aboutsummaryrefslogtreecommitdiff
path: root/src/framer.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/framer.c
parent6588e77f38bdebd7adffe091b22e7760d95d0ccb (diff)
parent4d6c143c0abec15e1d6ed1fd95d36f80e6cb7df8 (diff)
Merge pull request #3 from drowe67/dr-cleanup21.2.0
Cleanup Part 2
Diffstat (limited to 'src/framer.c')
-rw-r--r--src/framer.c107
1 files changed, 54 insertions, 53 deletions
diff --git a/src/framer.c b/src/framer.c
index 6b2b938..5b1fa8f 100644
--- a/src/framer.c
+++ b/src/framer.c
@@ -9,7 +9,6 @@
\*---------------------------------------------------------------------------*/
-
/*
Copyright (C) 2020 David Rowe
@@ -31,68 +30,70 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+
#include "fsk.h"
-unsigned int toInt(char c)
-{
- if (c >= '0' && c <= '9') return c - '0';
+unsigned int toInt(char c) {
+ if (c >= '0' && c <= '9') return c - '0';
if (c >= 'A' && c <= 'F') return 10 + c - 'A';
if (c >= 'a' && c <= 'f') return 10 + c - 'a';
return -1;
}
-int main(int argc,char *argv[]){
- FILE *fin, *fout;
-
- if (argc != 5) {
- fprintf(stderr,"usage: %s InputBitsOnePerByte OutputBitsOnePerByte frameSizeBits HexUW\n",argv[0]);
- exit(1);
+int main(int argc, char *argv[]) {
+ FILE *fin, *fout;
+
+ if (argc != 5) {
+ fprintf(stderr,
+ "usage: %s InputBitsOnePerByte OutputBitsOnePerByte frameSizeBits "
+ "HexUW\n",
+ argv[0]);
+ exit(1);
+ }
+
+ if (strcmp(argv[1], "-") == 0) {
+ fin = stdin;
+ } else {
+ if ((fin = fopen(argv[1], "rb")) == NULL) {
+ fprintf(stderr, "Couldn't open input file: %s\n", argv[1]);
+ exit(1);
}
-
- if (strcmp(argv[1],"-") == 0) {
- fin = stdin;
- } else {
- if ((fin = fopen(argv[1],"rb")) == NULL) {
- fprintf(stderr,"Couldn't open input file: %s\n", argv[1]);
- exit(1);
- }
- }
-
- if (strcmp(argv[2],"-") == 0) {
- fout = stdout;
- } else {
- if ((fout = fopen(argv[2],"wb")) == NULL) {
- fprintf(stderr,"Couldn't open output file: %s\n", argv[2]);
- exit(1);
- }
+ }
+
+ if (strcmp(argv[2], "-") == 0) {
+ fout = stdout;
+ } else {
+ if ((fout = fopen(argv[2], "wb")) == NULL) {
+ fprintf(stderr, "Couldn't open output file: %s\n", argv[2]);
+ exit(1);
}
+ }
- /* extract UW array */
-
- size_t framesize = atoi(argv[3]);
- char *uw_hex = argv[4];
- uint8_t uw[4*strlen(uw_hex)];
- int uwsize = 0;
- for(int c=0; c<strlen(uw_hex); c++)
- for(int i=0; i<4; i++)
- uw[uwsize++] = (toInt(uw_hex[c]) >> (3-i)) & 0x1; /* MSB first */
- assert(uwsize == 4*strlen(uw_hex));
-
- fprintf(stderr, "uw_hex: %s uwsize: %d\n", uw_hex, uwsize);
- for(int i=0; i<uwsize; i++)
- fprintf(stderr,"%d ", uw[i]);
- fprintf(stderr,"\n");
-
- /* main loop */
-
- uint8_t frame[framesize];
- while(fread(frame,sizeof(uint8_t),framesize,fin) == framesize) {
- fwrite(uw,sizeof(uint8_t),uwsize,fout);
- fwrite(frame,sizeof(uint8_t),framesize,fout);
- }
+ /* extract UW array */
+
+ size_t framesize = atoi(argv[3]);
+ char *uw_hex = argv[4];
+ uint8_t uw[4 * strlen(uw_hex)];
+ int uwsize = 0;
+ for (int c = 0; c < strlen(uw_hex); c++)
+ for (int i = 0; i < 4; i++)
+ uw[uwsize++] = (toInt(uw_hex[c]) >> (3 - i)) & 0x1; /* MSB first */
+ assert(uwsize == 4 * strlen(uw_hex));
+
+ fprintf(stderr, "uw_hex: %s uwsize: %d\n", uw_hex, uwsize);
+ for (int i = 0; i < uwsize; i++) fprintf(stderr, "%d ", uw[i]);
+ fprintf(stderr, "\n");
+
+ /* main loop */
+
+ uint8_t frame[framesize];
+ while (fread(frame, sizeof(uint8_t), framesize, fin) == framesize) {
+ fwrite(uw, sizeof(uint8_t), uwsize, fout);
+ fwrite(frame, sizeof(uint8_t), framesize, fout);
+ }
- fclose(fin);
- fclose(fout);
+ fclose(fin);
+ fclose(fout);
- return 0;
+ return 0;
}