tested over 1000 frames
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 12 Sep 2016 09:19:45 +0000 (09:19 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 12 Sep 2016 09:19:45 +0000 (09:19 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2857 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/ldpc_enc.c

index d6753bfcc1da9d5a405e4ed38cfa6ce3470f8bf3..a371c59ced0b55a5cb5b741ce7246d467b0dceda 100644 (file)
@@ -9,6 +9,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <errno.h>
 
 /* generated by ldpc_fsk_lib.m:ldpc_decode() */
 
@@ -30,38 +32,45 @@ void encode(unsigned char ibits[], unsigned char pbits[]) {
 
         tmp &= 1;    // only retain the lsb 
         prev = tmp; 
-        pbits[p] =tmp; 
+        pbits[p] = tmp; 
     }
 }
 
-int main(void)
+int main(int argc, char *argv[])
 {
     unsigned char ibits[NUMBERROWSHCOLS];
     unsigned char pbits[NUMBERPARITYBITS];
-    short  k;
-    unsigned int x;
-
-    printf("Test C Encoder\n");
-  
-    FILE *infp, *opfp;
-    infp = fopen("dat_in2064.txt", "r");   // read info bits from file   
-    if (infp == NULL) {printf("Unable to open file.\n"); exit(1);} 
-    for (k=0; k<NUMBERROWSHCOLS; k++)     { 
-        fscanf(infp, "%u\n", &x);
-        ibits[k] = x; 
+    FILE         *fin, *fout;
+
+    if (argc < 2) {
+        fprintf(stderr, "usage: %s InputOneBytePerBit OuputOneBytePerBit\n", argv[0]);
+        exit(0);
+    }
+
+    if (strcmp(argv[1], "-")  == 0) fin = stdin;
+    else if ( (fin = fopen(argv[1],"rb")) == NULL ) {
+        fprintf(stderr, "Error opening input bit file: %s: %s.\n",
+                argv[2], strerror(errno));
+        exit(1);
     }
-    fclose(infp);  
+        
+    if (strcmp(argv[2], "-") == 0) fout = stdout;
+    else if ( (fout = fopen(argv[2],"wb")) == NULL ) {
+        fprintf(stderr, "Error opening output bit file: %s: %s.\n",
+                argv[2], strerror(errno));
+        exit(1);
+    }
+
+    while (fread(ibits, sizeof(char), NUMBERROWSHCOLS, fin) == NUMBERROWSHCOLS) {
 
-    encode(ibits, pbits);  
+        encode(ibits, pbits);  
+        
+        fwrite(ibits, sizeof(char), NUMBERROWSHCOLS, fout); 
+        fwrite(pbits, sizeof(char), NUMBERPARITYBITS, fout); 
+    }
 
-    opfp = fopen("dat_op2064.bin", "wb");   // write par bits to file
-    if (opfp == NULL) {printf("Unable to output file.\n"); exit(1);}  
-    for (k=0; k<NUMBERROWSHCOLS; k++)
-        fwrite(&ibits[k], sizeof(char), 1, opfp); 
-    for (k=0; k<NUMBERPARITYBITS; k++)
-        fwrite(&pbits[k], sizeof(char), 1, opfp); 
-    fclose(opfp); 
+    fclose(fin);  
+    fclose(fout); 
 
     return 1;
 }