Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 53d5b2b

Browse files
committedMar 22, 2022
checked return status and found that we _can_ use 'forward' packets (data + bch), not only (bch + data).
1 parent 475f951 commit 53d5b2b

File tree

1 file changed

+48
-12
lines changed

1 file changed

+48
-12
lines changed
 

‎src/bch.c

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,29 @@ void bytes_to_bits(int *bytes, int *bit_dest, int num_bits) {
505505
}
506506
}
507507

508+
void bits_to_bytes(int *bits, int *byte_dest, int num_bits) {
509+
510+
int index;
511+
512+
for (int i = 0; i < num_bits; i++) {
513+
index = i / 8;
514+
if (i % 8 == 0) {
515+
byte_dest[index] = 0;
516+
}
517+
518+
byte_dest[index] <<= 1;
519+
byte_dest[index] |= bits[i] & 0x01;
520+
}
521+
522+
byte_dest[index] <<= 8 - (num_bits % 8);
523+
}
524+
525+
508526
void dump_bch(bch_t *bch) {
509527
printf("m: %d length: %d t: %d n: %d k: %d\n", bch->m, bch->length, bch->t, bch->n, bch->k);
510528
}
511529

530+
#undef TEST_BYTES_TO_BITS
512531
#define TEST_APPLY
513532

514533
int main()
@@ -551,7 +570,17 @@ int main()
551570
printf("%d ", bits[i]);
552571
}
553572
printf("\n");
573+
574+
int temp[8];
575+
bits_to_bytes(bits, temp, 63);
576+
printf("bits_to_bytes pkt [%d]\n", count);
577+
for (int i = 0; i < 8; i++) {
578+
printf("%02x ", temp[i]);
579+
}
580+
printf("\n");
581+
554582
#endif
583+
555584
#ifdef TEST_GENERATE
556585
int bch_code[18];
557586
generate_bch(&bch, bits, bch_code);
@@ -563,13 +592,9 @@ int main()
563592
#endif
564593
#ifdef TEST_APPLY
565594
int recv[63];
566-
// backwards, for now
567-
for (int i = 0; i < 45; i++) {
568-
recv[i + 18] = bits[i];
569-
}
570-
571-
for (int i = 0; i < 18; i++) {
572-
recv[i] = bits[i + 45];
595+
596+
for (int i = 0; i < 63; i++) {
597+
recv[i] = bits[i];
573598
}
574599

575600
printf("rearranged packet [%d]: ", count);
@@ -579,12 +604,23 @@ int main()
579604
printf("\n");
580605

581606
int corrected = apply_bch(&bch, recv);
582-
583-
printf("corrected [%d] packet: ", corrected);
584-
for (int i = 0; i < 63; i++) {
585-
printf("%d ", recv[i]);
607+
608+
if (corrected >= 0) {
609+
printf("corrected [%d] packet: ", corrected);
610+
for (int i = 0; i < 63; i++) {
611+
printf("%d ", recv[i]);
612+
}
613+
printf("\n");
614+
615+
int temp[8];
616+
bits_to_bytes(recv, temp, 63);
617+
618+
printf("corrected [%d] DATA: ", count);
619+
for (int i = 0; i < 8; i++) {
620+
printf("%02x ", temp[i]);
621+
}
622+
printf("\n");
586623
}
587-
printf("\n");
588624
#endif
589625
}
590626
}

0 commit comments

Comments
 (0)
Please sign in to comment.