Skip to content

Commit ac9798b

Browse files
committed
Merge remote-tracking branch 'lev/il2p_crc' into il2p_crc
2 parents 2e9e7f5 + e78c215 commit ac9798b

File tree

3 files changed

+44
-37
lines changed

3 files changed

+44
-37
lines changed

src/il2p_codec.c

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,34 @@
4040
*--------------------------------------------------------------*/
4141

4242

43+
static int il2p_check_crc(unsigned char *payload, int payload_length, unsigned char *coded_crc);
44+
static int il2p_generate_crc(unsigned char *coded_crc, unsigned char *payload, int payload_length);
45+
46+
#define IL2P_NIBLE_MASK 0x0f
47+
#define IL2P_DECODE_MASK 0x7f
48+
49+
// local variables
50+
51+
static uint8_t encode_table[16] = { 0x0, 0x71, 0x62, 0x13, 0x54, 0x25, 0x36, 0x47, 0x38, 0x49, 0x5a, 0x2b, 0x6c, 0x1d, 0x0e, 0x7f };
52+
53+
static uint8_t decode_table[128] = { 0x0, 0x0, 0x0, 0x3, 0x0, 0x5, 0xe, 0x7,
54+
0x0, 0x9, 0xe, 0xb, 0xe, 0xd, 0xe, 0xe,
55+
0x0, 0x3, 0x3, 0x3, 0x4, 0xd, 0x6, 0x3,
56+
0x8, 0xd, 0xa, 0x3, 0xd, 0xd, 0xe, 0xd,
57+
0x0, 0x5, 0x2, 0xb, 0x5, 0x5, 0x6, 0x5,
58+
0x8, 0xb, 0xb, 0xb, 0xc, 0x5, 0xe, 0xb,
59+
0x8, 0x1, 0x6, 0x3, 0x6, 0x5, 0x6, 0x6,
60+
0x8, 0x8, 0x8, 0xb, 0x8, 0xd, 0x6, 0xf,
61+
0x0, 0x9, 0x2, 0x7, 0x4, 0x7, 0x7, 0x7,
62+
0x9, 0x9, 0xa, 0x9, 0xc, 0x9, 0xe, 0x7,
63+
0x4, 0x1, 0xa, 0x3, 0x4, 0x4, 0x4, 0x7,
64+
0xa, 0x9, 0xa, 0xa, 0x4, 0xd, 0xa, 0xf,
65+
0x2, 0x1, 0x2, 0x2, 0xc, 0x5, 0x2, 0x7,
66+
0xc, 0x9, 0x2, 0xb, 0xc, 0xc, 0xc, 0xf,
67+
0x1, 0x1, 0x2, 0x1, 0x4, 0x1, 0x6, 0xf,
68+
0x8, 0x1, 0xa, 0xf, 0xc, 0xf, 0xf, 0xf };
69+
70+
4371
/*-------------------------------------------------------------
4472
*
4573
* Name: il2p_encode_frame
@@ -52,6 +80,8 @@
5280
*
5381
* max_fec - 1 to send maximum FEC size rather than automatic.
5482
*
83+
* use_crc - 1 to use CRC for the payload.
84+
*
5585
* Outputs: iout - Encoded result, excluding the 3 byte sync word.
5686
* Caller should provide IL2P_MAX_PACKET_SIZE bytes.
5787
*
@@ -69,34 +99,6 @@
6999
*
70100
*--------------------------------------------------------------*/
71101

72-
static int il2p_check_crc(unsigned char *payload, int payload_length, unsigned char *coded_crc);
73-
static int il2p_generate_crc(unsigned char *coded_crc, unsigned char *payload, int payload_length);
74-
75-
#define IL2P_NIBLE_MASK 0x0f
76-
#define IL2P_DECODE_MASK 0x7f
77-
78-
// local variables
79-
80-
static uint8_t encode_table[16] = { 0x0, 0x71, 0x62, 0x13, 0x54, 0x25, 0x36, 0x47, 0x38, 0x49, 0x5a, 0x2b, 0x6c, 0x1d, 0x0e, 0x7f };
81-
82-
static uint8_t decode_table[128] = { 0x0, 0x0, 0x0, 0x3, 0x0, 0x5, 0xe, 0x7,
83-
0x0, 0x9, 0xe, 0xb, 0xe, 0xd, 0xe, 0xe,
84-
0x0, 0x3, 0x3, 0x3, 0x4, 0xd, 0x6, 0x3,
85-
0x8, 0xd, 0xa, 0x3, 0xd, 0xd, 0xe, 0xd,
86-
0x0, 0x5, 0x2, 0xb, 0x5, 0x5, 0x6, 0x5,
87-
0x8, 0xb, 0xb, 0xb, 0xc, 0x5, 0xe, 0xb,
88-
0x8, 0x1, 0x6, 0x3, 0x6, 0x5, 0x6, 0x6,
89-
0x8, 0x8, 0x8, 0xb, 0x8, 0xd, 0x6, 0xf,
90-
0x0, 0x9, 0x2, 0x7, 0x4, 0x7, 0x7, 0x7,
91-
0x9, 0x9, 0xa, 0x9, 0xc, 0x9, 0xe, 0x7,
92-
0x4, 0x1, 0xa, 0x3, 0x4, 0x4, 0x4, 0x7,
93-
0xa, 0x9, 0xa, 0xa, 0x4, 0xd, 0xa, 0xf,
94-
0x2, 0x1, 0x2, 0x2, 0xc, 0x5, 0x2, 0x7,
95-
0xc, 0x9, 0x2, 0xb, 0xc, 0xc, 0xc, 0xf,
96-
0x1, 0x1, 0x2, 0x1, 0x4, 0x1, 0x6, 0xf,
97-
0x8, 0x1, 0xa, 0xf, 0xc, 0xf, 0xf, 0xf };
98-
99-
100102
int il2p_encode_frame (packet_t pp, int max_fec, unsigned char *iout, int use_crc)
101103
{
102104

@@ -204,6 +206,7 @@ int il2p_encode_frame (packet_t pp, int max_fec, unsigned char *iout, int use_cr
204206
* applied first so we would know how much to collect for the payload.
205207
*
206208
* Inputs: irec - Received IL2P frame excluding the 3 byte sync word.
209+
* use_crc - 1 to chec CRC for the payload.
207210
*
208211
* Future Out: Number of symbols corrected.
209212
*
@@ -230,6 +233,7 @@ packet_t il2p_decode_frame (unsigned char *irec, int use_crc)
230233
*
231234
* Inputs: uhdr - Received header after FEC and descrambling.
232235
* epayload - Encoded payload.
236+
* use_crc - 1 to check CRC for the payload.
233237
*
234238
* In/Out: symbols_corrected - Symbols (bytes) corrected in the header.
235239
* Should be 0 or 1 because it has 2 parity symbols.

src/il2p_send.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ static void send_bit (int chan, int b, int polarity);
5050
* max_fec - 1 to force 16 parity symbols for each payload block.
5151
* 0 for automatic depending on block size.
5252
*
53+
* use_crc - 1 to use CRC for the payload.
54+
*
5355
* polarity - 0 for normal. 1 to invert signal.
5456
* 2 special case for testing - introduce some errors to test FEC.
5557
*

src/il2p_test.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,9 @@ static void test_payload(void)
288288
for (int max_fec = 0; max_fec <= 1; max_fec++) {
289289
for (int payload_length = 1; payload_length <= IL2P_MAX_PAYLOAD_SIZE; payload_length++) {
290290
//dw_printf ("\n--------- max_fec = %d, payload_length = %d\n", max_fec, payload_length);
291+
unsigned char *next = NULL;
291292
unsigned char encoded[IL2P_MAX_ENCODED_PAYLOAD_SIZE];
292-
int k = il2p_encode_payload (original_payload, payload_length, max_fec, encoded);
293+
int k = il2p_encode_payload (original_payload, payload_length, max_fec, encoded, &next);
293294

294295
//dw_printf ("payload length %d %s -> %d\n", payload_length, max_fec ? "M" : "", k);
295296
assert (k > payload_length && k <= IL2P_MAX_ENCODED_PAYLOAD_SIZE);
@@ -298,7 +299,7 @@ static void test_payload(void)
298299

299300
unsigned char extracted[IL2P_MAX_PAYLOAD_SIZE];
300301
int symbols_corrected = 0;
301-
int e = il2p_decode_payload (encoded, payload_length, max_fec, extracted, &symbols_corrected);
302+
int e = il2p_decode_payload (encoded, payload_length, max_fec, extracted, &symbols_corrected, &next);
302303
//dw_printf ("e = %d, payload_length = %d\n", e, payload_length);
303304
assert (e == payload_length);
304305

@@ -584,7 +585,7 @@ static void test_example_headers()
584585

585586
int max_fec = 0;
586587
unsigned char iout[IL2P_MAX_PACKET_SIZE];
587-
e = il2p_encode_frame (pp, max_fec, iout);
588+
e = il2p_encode_frame (pp, max_fec, iout, 1);
588589

589590
//dw_printf ("expected for example 3:\n");
590591
//fx_hex_dump(complete3, sizeof(complete3));
@@ -616,11 +617,11 @@ static void enc_dec_compare (packet_t pp1)
616617

617618
unsigned char encoded[IL2P_MAX_PACKET_SIZE];
618619
int enc_len;
619-
enc_len = il2p_encode_frame (pp1, max_fec, encoded);
620+
enc_len = il2p_encode_frame (pp1, max_fec, encoded, 1);
620621
assert (enc_len >= 0);
621622

622623
packet_t pp2;
623-
pp2 = il2p_decode_frame (encoded);
624+
pp2 = il2p_decode_frame (encoded, 1);
624625
assert (pp2 != NULL);
625626

626627
// Is it the same after encoding to IL2P and then decoding?
@@ -851,7 +852,7 @@ static void decode_bitstream(void)
851852
while ( (ch = fgetc(fp)) != EOF) {
852853

853854
if (ch == '0' || ch == '1') {
854-
il2p_rec_bit (0, 0, 0, ch - '0');
855+
il2p_rec_bit (0, 0, 0, ch - '0', 1);
855856
}
856857
}
857858
fclose(fp);
@@ -918,11 +919,11 @@ static void test_serdes (void)
918919

919920
for (max_fec = 0; max_fec <= 1; max_fec++) {
920921
for (polarity = 0; polarity <= 2; polarity++) { // 2 means throw in some errors.
921-
int num_bits_sent = il2p_send_frame (chan, pp, max_fec, polarity);
922+
int num_bits_sent = il2p_send_frame (chan, pp, max_fec, polarity, 1);
922923
dw_printf ("%d bits sent.\n", num_bits_sent);
923924

924925
// Need extra bit at end to flush out state machine.
925-
il2p_rec_bit (0, 0, 0, 0);
926+
il2p_rec_bit (0, 0, 0, 0, 1);
926927
}
927928
}
928929
ax25_delete(pp);
@@ -938,7 +939,7 @@ static void test_serdes (void)
938939

939940
void tone_gen_put_bit (int chan, int data)
940941
{
941-
il2p_rec_bit (chan, 0, 0, data);
942+
il2p_rec_bit (chan, 0, 0, data, 1);
942943
}
943944

944945
// This is called when a complete frame has been deserialized.

0 commit comments

Comments
 (0)