@@ -518,7 +518,7 @@ int apply_bch(const bch_t *bch, int *recd)
518
518
}
519
519
520
520
/* LEFT justified in hex */
521
- void bytes_to_bits (const int * bytes , int * bit_dest , int num_bits ) {
521
+ void bytes_to_bits (const uint8_t * bytes , int * bit_dest , int num_bits ) {
522
522
for (int i = 0 ; i < num_bits ; i ++ ) {
523
523
int index = i / 8 ;
524
524
int bit_pos = 7 - (i % 8 );
@@ -527,7 +527,7 @@ void bytes_to_bits(const int *bytes, int *bit_dest, int num_bits) {
527
527
}
528
528
}
529
529
530
- void bits_to_bytes (const int * bits , int * byte_dest , int num_bits ) {
530
+ void bits_to_bytes (const int * bits , uint8_t * byte_dest , int num_bits ) {
531
531
532
532
int index ;
533
533
@@ -540,8 +540,6 @@ void bits_to_bytes(const int *bits, int *byte_dest, int num_bits) {
540
540
byte_dest [index ] <<= 1 ;
541
541
byte_dest [index ] |= (bits [i ] & 0x01 );
542
542
}
543
-
544
- byte_dest [index ] <<= 8 - (num_bits % 8 );
545
543
}
546
544
547
545
void swap_format (const int * bits , int * dest , int cutoff , int num_bits ) {
@@ -555,8 +553,8 @@ void swap_format(const int *bits, int *dest, int cutoff, int num_bits) {
555
553
}
556
554
}
557
555
558
- int rotate_byte (int x ) {
559
- int y = 0 ;
556
+ uint8_t rotate_byte (uint8_t x ) {
557
+ uint8_t y = 0 ;
560
558
561
559
for (int i = 0 ; i < 8 ; i ++ ) {
562
560
y <<= 1 ;
@@ -583,143 +581,16 @@ void dump_bch(const bch_t *bch) {
583
581
printf ("m: %d length: %d t: %d n: %d k: %d\n" , bch -> m , bch -> length , bch -> t , bch -> n , bch -> k );
584
582
}
585
583
586
- void print_array (const char * msg , const char * format , const int * bytes , int num_bytes ) {
584
+ void print_bytes (const char * msg , const uint8_t * bytes , int num_bytes ) {
587
585
printf ("%s" , msg );
588
586
for (int i = 0 ; i < num_bytes ; i ++ ) {
589
- printf (format , bytes [i ]);
587
+ printf ("%02x " , bytes [i ]);
590
588
}
591
589
}
592
590
593
- void print_bytes (const char * msg , const int * bytes , int num_bytes ) {
594
- print_array (msg , "%02x " , bytes , num_bytes );
595
- }
596
-
597
591
void print_bits (const char * msg , const int * bits , int num_bits ) {
598
- print_array (msg , "%d " , bits , num_bits );
599
- }
600
-
601
- #undef MAIN
602
- #undef TEST_BYTES_TO_BITS
603
- #define TEST_SWAP
604
- #ifdef MAIN
605
- int main ()
606
- {
607
- int test [][8 ] = {
608
- /* 0 errors */ { 0xb2 , 0x17 , 0xa2 , 0xb9 , 0x53 , 0xdd , 0xc5 , 0x52 }, /* perfect random test */
609
- { 0xf0 , 0x5a , 0x6a , 0x6a , 0x01 , 0x63 , 0x33 , 0xd0 }, /* g001-cut-lenthened_457.938M.wav */
610
- { 0xf0 , 0x81 , 0x52 , 0x6b , 0x71 , 0xa5 , 0x63 , 0x08 }, /* 1st in eotd_received_data */
611
- /* 3 errors */ { 0xf0 , 0x85 , 0x50 , 0x6a , 0x01 , 0xe5 , 0x6e , 0x84 }, /* 2nd in eotd_received_data - 3 bad bits */
612
- /* 0 errors */ { 0xf0 , 0x85 , 0x50 , 0x6a , 0x01 , 0xe5 , 0x06 , 0x84 }, /* 2nd, but with the bits fixed */
613
- /* 3 errors */ { 0xf0 , 0x85 , 0x59 , 0x5a , 0x01 , 0xe5 , 0x6e , 0x84 }, /* 3rd - 3 bad bits */
614
- /* 0 errors */ { 0xb0 , 0x85 , 0x59 , 0x5a , 0x11 , 0xe5 , 0x6f , 0x84 }, /* 3rd fixed */
615
- { 0xf1 , 0x34 , 0x50 , 0x1a , 0x01 , 0xe5 , 0x66 , 0xfe }, /* 4th */
616
- { 0xf0 , 0xeb , 0x10 , 0xea , 0x01 , 0x6e , 0x54 , 0x1c }, /* 5th */
617
- { 0xf0 , 0xea , 0x5c , 0xea , 0x01 , 0x6e , 0x55 , 0x0e }, /* 6th */
618
- { 0xe0 , 0x21 , 0x10 , 0x1a , 0x01 , 0x32 , 0xbc , 0xe4 }, /* Sun Mar 20 05:41:00 2022 */
619
- { 0xf0 , 0x42 , 0x50 , 0x5b , 0xcf , 0xd5 , 0x64 , 0xe4 }, /* Sun Mar 20 12:58:43 2022 */
620
- { 0xf0 , 0x8c , 0x10 , 0xaa , 0x01 , 0x73 , 0x7b , 0x1a }, /* Sun Mar 20 13:35:48 2022 */
621
- { 0xf0 , 0x8c , 0x10 , 0xb1 , 0xc0 , 0xe0 , 0x90 , 0x64 }, /* Sun Mar 20 13:37:05 2022 */
622
- /* 3 errors */ { 0xf0 , 0x8c , 0x10 , 0x6a , 0x01 , 0x64 , 0x7a , 0xe8 }, /* Sun Mar 20 13:37:48 2022 - 3 bad bits */
623
- /* 0 errors */ { 0x50 , 0x8c , 0x12 , 0x6a , 0x01 , 0x64 , 0x7a , 0xe8 }, /* Sun Mar 20 13:37:48 2022 with bits fixed */
624
- };
625
-
626
- int bits [63 ];
627
- int temp [8 ];
628
- bch_t bch ;
629
-
630
- init_bch (& bch , 6 , 63 , 3 );
631
-
632
- for (int count = 0 ; count < sizeof (test ) / sizeof (* test ); count ++ ) {
633
- bytes_to_bits (test [count ], bits , 63 );
634
-
635
- printf ("--------------------------\nORIG pkt [%d] " , count );
636
- for (int i = 0 ; i < 8 ; i ++ ) {
637
- printf ("%02x " , test [count ][i ]);
638
- }
639
- printf ("\n" );
640
-
641
- #ifdef TEST_BYTES_TO_BITS
642
-
643
- printf ("ORIG pkt[%d] bits\n" , count );
644
- for (int i = 0 ; i < 63 ; i ++ ) {
645
- printf ("%d " , bits [i ]);
646
- }
647
- printf ("\n" );
648
-
649
- bits_to_bytes (bits , temp , 63 );
650
- printf ("bits_to_bytes pkt [%d]\n" , count );
651
- for (int i = 0 ; i < 8 ; i ++ ) {
652
- printf ("%02x " , temp [i ]);
653
- }
654
- printf ("\n" );
655
-
656
- #endif
657
-
658
- #ifdef TEST_GENERATE
659
- int bch_code [18 ];
660
- generate_bch (& bch , bits , bch_code );
661
- printf ("generated BCH\n" );
662
- for (int i = 0 ; i < 18 ; i ++ ) {
663
- printf ("%d " , bch_code [i ]);
664
- }
665
- printf ("\n" );
666
- #endif
667
-
668
- #ifdef TEST_SWAP
669
- printf ("orig: " );
670
- for (int i = 0 ; i < 63 ; i ++ ) {
671
- printf ("%d " , bits [i ]);
672
- }
673
- printf ("\n" );
674
-
675
- swap_format (bits , 45 , 63 );
676
-
677
- printf ("rev: " );
678
- for (int i = 0 ; i < 63 ; i ++ ) {
679
- printf ("%d " , bits [i ]);
680
- }
681
- printf ("\n" );
682
- #endif
683
- #ifdef TEST_APPLY
684
- int recv [63 ];
685
-
686
- for (int i = 0 ; i < 63 ; i ++ ) {
687
- recv [i ] = bits [i ];
688
- }
689
- /*
690
- printf("rearranged packet [%d]: ", count);
691
- for (int i = 0; i < 63; i++) {
692
- printf("%d ", recv[i]);
693
- }
694
- printf("\n");
695
-
696
- bits_to_bytes(recv, temp, 63);
697
-
698
- printf("original [%d] bytes: ", count);
699
- for (int i = 0; i < 8; i++) {
700
- printf("%02x ", temp[i]);
701
- }
702
- printf("\n");
703
- */
704
- int corrected = apply_bch (& bch , recv );
705
-
706
- if (corrected >= 0 ) {
707
- /*
708
- printf("corrected [%d] packet: ", corrected);
709
- for (int i = 0; i < 63; i++) {
710
- printf("%d ", recv[i]);
711
- }
712
- printf("\n");
713
- */
714
- bits_to_bytes (recv , temp , 63 );
715
-
716
- printf ("corrected [%d] bytes: " , corrected );
717
- for (int i = 0 ; i < 8 ; i ++ ) {
718
- printf ("%02x " , temp [i ]);
719
- }
720
- printf ("\n" );
721
- }
722
- #endif
592
+ printf ("%s" , msg );
593
+ for (int i = 0 ; i < num_bits ; i ++ ) {
594
+ printf ("%d " , bits [i ]);
723
595
}
724
596
}
725
- #endif
0 commit comments