@@ -254,7 +254,7 @@ int bch_init(bch_t *bch, int m, int length, int t) {
254
254
printf ("This is a (%d, %d, %d) binary BCH code\n" , bch -> length , bch -> k , d );
255
255
256
256
/* Compute the generator polynomial */
257
- bch -> g = malloc (rdncy * sizeof (int ));
257
+ bch -> g = malloc (( rdncy + 1 ) * sizeof (int ));
258
258
bch -> g [0 ] = bch -> alpha_to [zeros [1 ]];
259
259
bch -> g [1 ] = 1 ; /* g(x) = (X + zeros[1]) initially */
260
260
for (ii = 2 ; ii <= rdncy ; ii ++ ) {
@@ -552,26 +552,28 @@ int main()
552
552
};
553
553
554
554
int bits [63 ];
555
+ int temp [8 ];
555
556
bch_t bch ;
556
557
557
558
bch_init (& bch , 6 , 63 , 3 );
558
559
559
560
for (int count = 0 ; count < sizeof (test ) / sizeof (* test ); count ++ ) {
560
561
bytes_to_bits (test [count ], bits , 63 );
561
- #ifdef TEST_BYTES_TO_BITS
562
- printf ("ORIG pkt [%d]\n " , count );
562
+
563
+ printf ("--------------------------\nORIG pkt [%d] " , count );
563
564
for (int i = 0 ; i < 8 ; i ++ ) {
564
565
printf ("%02x " , test [count ][i ]);
565
566
}
566
567
printf ("\n" );
568
+
569
+ #ifdef TEST_BYTES_TO_BITS
567
570
568
571
printf ("ORIG pkt[%d] bits\n" , count );
569
572
for (int i = 0 ; i < 63 ; i ++ ) {
570
573
printf ("%d " , bits [i ]);
571
574
}
572
575
printf ("\n" );
573
576
574
- int temp [8 ];
575
577
bits_to_bytes (bits , temp , 63 );
576
578
printf ("bits_to_bytes pkt [%d]\n" , count );
577
579
for (int i = 0 ; i < 8 ; i ++ ) {
@@ -590,32 +592,41 @@ int main()
590
592
}
591
593
printf ("\n" );
592
594
#endif
595
+
593
596
#ifdef TEST_APPLY
594
597
int recv [63 ];
595
598
596
599
for (int i = 0 ; i < 63 ; i ++ ) {
597
600
recv [i ] = bits [i ];
598
601
}
599
-
602
+ /*
600
603
printf("rearranged packet [%d]: ", count);
601
604
for (int i = 0; i < 63; i++) {
602
605
printf("%d ", recv[i]);
603
606
}
604
607
printf("\n");
605
-
608
+
609
+ bits_to_bytes(recv, temp, 63);
610
+
611
+ printf("original [%d] bytes: ", count);
612
+ for (int i = 0; i < 8; i++) {
613
+ printf("%02x ", temp[i]);
614
+ }
615
+ printf("\n");
616
+ */
606
617
int corrected = apply_bch (& bch , recv );
607
618
608
619
if (corrected >= 0 ) {
620
+ /*
609
621
printf("corrected [%d] packet: ", corrected);
610
622
for (int i = 0; i < 63; i++) {
611
623
printf("%d ", recv[i]);
612
624
}
613
625
printf("\n");
614
-
615
- int temp [8 ];
626
+ */
616
627
bits_to_bytes (recv , temp , 63 );
617
628
618
- printf ("corrected [%d] DATA : " , count );
629
+ printf ("corrected [%d] bytes : " , corrected );
619
630
for (int i = 0 ; i < 8 ; i ++ ) {
620
631
printf ("%02x " , temp [i ]);
621
632
}
0 commit comments