Skip to content

Commit b8fe661

Browse files
committed
Add CRC calculation for IL2P
1 parent 486b3cf commit b8fe661

File tree

9 files changed

+220
-38
lines changed

9 files changed

+220
-38
lines changed

src/audio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ struct audio_s {
208208
int il2p_max_fec; // 1 for max FEC length, 0 for automatic based on size.
209209

210210
int il2p_invert_polarity; // 1 means invert on transmit. Receive handles either automatically.
211+
enum il2p_use_crc_t { IL2P_NOCRC = 0, IL2P_USECRC } il2p_use_crc;
211212

212213
enum v26_e { V26_UNSPECIFIED=0, V26_A, V26_B } v26_alternative;
213214

src/config.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
791791
p_audio_config->achan[channel].layer2_xmit = LAYER2_AX25;
792792
p_audio_config->achan[channel].il2p_max_fec = 1;
793793
p_audio_config->achan[channel].il2p_invert_polarity = 0;
794+
p_audio_config->achan[channel].il2p_use_crc = IL2P_USECRC;
794795

795796
p_audio_config->achan[channel].fix_bits = DEFAULT_FIX_BITS;
796797
p_audio_config->achan[channel].sanity_test = SANITY_APRS;
@@ -2625,13 +2626,14 @@ void config_init (char *fname, struct audio_s *p_audio_config,
26252626
}
26262627

26272628
/*
2628-
* IL2PTX [ + - ] [ 0 1 ] - Enable IL2P transmission. Default off.
2629+
* IL2PTX [ + - ] [ 0 1 ] [ C ] - Enable IL2P transmission. Default off.
26292630
* "+" means normal polarity. Redundant since it is the default.
26302631
* (command line -I for first channel)
26312632
* "-" means inverted polarity. Do not use for 1200 bps.
26322633
* (command line -i for first channel)
26332634
* "0" means weak FEC. Not recommended.
26342635
* "1" means stronger FEC. "Max FEC." Default if not specified.
2636+
* "C" means use CRC. Default is no CRC.
26352637
*/
26362638

26372639
else if (strcasecmp(t, "IL2PTX") == 0) {
@@ -2644,6 +2646,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
26442646
p_audio_config->achan[channel].layer2_xmit = LAYER2_IL2P;
26452647
p_audio_config->achan[channel].il2p_max_fec = 1;
26462648
p_audio_config->achan[channel].il2p_invert_polarity = 0;
2649+
p_audio_config->achan[channel].il2p_use_crc = IL2P_NOCRC; // Default is no CRC.
26472650

26482651
while ((t = split(NULL,0)) != NULL) {
26492652
for (char *c = t; *c != '\0'; c++) {
@@ -2659,6 +2662,11 @@ void config_init (char *fname, struct audio_s *p_audio_config,
26592662
break;
26602663
case '1':
26612664
p_audio_config->achan[channel].il2p_max_fec = 1;
2665+
break;
2666+
case 'C':
2667+
case 'c':
2668+
p_audio_config->achan[channel].il2p_use_crc = IL2P_USECRC;
2669+
dw_printf ("Line %d: IL2P transmission will use CRC.\n", line);
26622670
break;
26632671
default:
26642672
text_color_set(DW_COLOR_ERROR);

src/hdlc_rec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ void hdlc_rec_bit_new (int chan, int subchan, int slice, int raw, int is_scrambl
504504

505505
if (g_audio_p->achan[chan].modem_type != MODEM_AIS) {
506506
fx25_rec_bit (chan, subchan, slice, dbit);
507-
il2p_rec_bit (chan, subchan, slice, raw); // Note: skip NRZI.
507+
il2p_rec_bit (chan, subchan, slice, raw, g_audio_p->achan[chan].il2p_use_crc); // Note: skip NRZI.
508508
}
509509

510510
/*

src/hdlc_send.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ int layer2_send_frame (int chan, packet_t pp, int bad_fcs, struct audio_s *audio
8787
if (audio_config_p->achan[chan].layer2_xmit == LAYER2_IL2P) {
8888

8989
int n = il2p_send_frame (chan, pp, audio_config_p->achan[chan].il2p_max_fec,
90-
audio_config_p->achan[chan].il2p_invert_polarity);
90+
audio_config_p->achan[chan].il2p_invert_polarity, audio_config_p->achan[chan].il2p_use_crc);
9191
if (n > 0) {
9292
return (n);
9393
}

src/il2p.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#define IL2P_MAX_PACKET_SIZE (IL2P_SYNC_WORD_SIZE + IL2P_HEADER_SIZE + IL2P_HEADER_PARITY + IL2P_MAX_ENCODED_PAYLOAD_SIZE)
2121

22+
#define IL2P_CODED_CRC_LENGTH 4
2223

2324
///////////////////////////////////////////////////////////////////////////////
2425
//
@@ -52,7 +53,7 @@ extern void il2p_set_debug(int debug);
5253

5354
// Receives a bit stream from demodulator.
5455

55-
extern void il2p_rec_bit (int chan, int subchan, int slice, int dbit);
56+
extern void il2p_rec_bit (int chan, int subchan, int slice, int dbit, int use_crc);
5657

5758

5859

@@ -67,7 +68,7 @@ extern void il2p_rec_bit (int chan, int subchan, int slice, int dbit);
6768

6869
// Send bit stream to modulator.
6970

70-
int il2p_send_frame (int chan, packet_t pp, int max_fec, int polarity);
71+
int il2p_send_frame (int chan, packet_t pp, int max_fec, int polarity, int use_crc);
7172

7273

7374

@@ -79,11 +80,11 @@ int il2p_send_frame (int chan, packet_t pp, int max_fec, int polarity);
7980

8081
#include "ax25_pad.h"
8182

82-
extern int il2p_encode_frame (packet_t pp, int max_fec, unsigned char *iout);
83+
extern int il2p_encode_frame (packet_t pp, int max_fec, unsigned char *iout, int use_crc);
8384

84-
packet_t il2p_decode_frame (unsigned char *irec);
85+
packet_t il2p_decode_frame (unsigned char *irec, int use_crc);
8586

86-
packet_t il2p_decode_header_payload (unsigned char* uhdr, unsigned char *epayload, int *symbols_corrected);
87+
packet_t il2p_decode_header_payload (unsigned char* uhdr, unsigned char *epayload, int *symbols_corrected, int use_crc);
8788

8889

8990

@@ -136,9 +137,9 @@ typedef struct {
136137

137138
extern int il2p_payload_compute (il2p_payload_properties_t *p, int payload_size, int max_fec);
138139

139-
extern int il2p_encode_payload (unsigned char *payload, int payload_size, int max_fec, unsigned char *enc);
140+
extern int il2p_encode_payload (unsigned char *payload, int payload_size, int max_fec, unsigned char *enc, unsigned char **next);
140141

141-
extern int il2p_decode_payload (unsigned char *received, int payload_size, int max_fec, unsigned char *payload_out, int *symbols_corrected);
142+
extern int il2p_decode_payload (unsigned char *received, int payload_size, int max_fec, unsigned char *payload_out, int *symbols_corrected, unsigned char **next);
142143

143144
extern int il2p_get_header_attributes (unsigned char *hdr, int *hdr_type, int *max_fec);
144145

0 commit comments

Comments
 (0)