Skip to content

Add CRC calculation for IL2P #572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add CRC calculation for IL2P
  • Loading branch information
leventelist committed Jun 2, 2025
commit 19596fac12f9a749b6a481665064af38a661970d
1 change: 1 addition & 0 deletions src/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ struct audio_s {
int il2p_max_fec; // 1 for max FEC length, 0 for automatic based on size.

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

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

Expand Down
11 changes: 10 additions & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
p_audio_config->achan[channel].layer2_xmit = LAYER2_AX25;
p_audio_config->achan[channel].il2p_max_fec = 1;
p_audio_config->achan[channel].il2p_invert_polarity = 0;
p_audio_config->achan[channel].il2p_use_crc = IL2P_USECRC;

p_audio_config->achan[channel].fix_bits = DEFAULT_FIX_BITS;
p_audio_config->achan[channel].sanity_test = SANITY_APRS;
Expand Down Expand Up @@ -2625,13 +2626,15 @@ void config_init (char *fname, struct audio_s *p_audio_config,
}

/*
* IL2PTX [ + - ] [ 0 1 ] - Enable IL2P transmission. Default off.
* IL2PTX [ + - ] [ 0 1 ] [ C ] - Enable IL2P transmission. Default off.
* "+" means normal polarity. Redundant since it is the default.
* (command line -I for first channel)
* "-" means inverted polarity. Do not use for 1200 bps.
* (command line -i for first channel)
* "0" means weak FEC. Not recommended.
* "1" means stronger FEC. "Max FEC." Default if not specified.
* "C" means check CRC. Default is not to check CRC.
* Note, that it'll always generate CRC for the frame.
*/

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

while ((t = split(NULL,0)) != NULL) {
for (char *c = t; *c != '\0'; c++) {
Expand All @@ -2659,6 +2663,11 @@ void config_init (char *fname, struct audio_s *p_audio_config,
break;
case '1':
p_audio_config->achan[channel].il2p_max_fec = 1;
break;
case 'C':
case 'c':
p_audio_config->achan[channel].il2p_use_crc = IL2P_USECRC;
dw_printf ("Line %d: IL2P transmission will use CRC.\n", line);
break;
default:
text_color_set(DW_COLOR_ERROR);
Expand Down
2 changes: 1 addition & 1 deletion src/hdlc_rec.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ void hdlc_rec_bit_new (int chan, int subchan, int slice, int raw, int is_scrambl

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

/*
Expand Down
9 changes: 5 additions & 4 deletions src/il2p.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

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

#define IL2P_CODED_CRC_LENGTH 4

///////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -52,7 +53,7 @@ extern void il2p_set_debug(int debug);

// Receives a bit stream from demodulator.

extern void il2p_rec_bit (int chan, int subchan, int slice, int dbit);
extern void il2p_rec_bit (int chan, int subchan, int slice, int dbit, int use_crc);



Expand Down Expand Up @@ -81,9 +82,9 @@ int il2p_send_frame (int chan, packet_t pp, int max_fec, int polarity);

extern int il2p_encode_frame (packet_t pp, int max_fec, unsigned char *iout);

packet_t il2p_decode_frame (unsigned char *irec);
packet_t il2p_decode_frame (unsigned char *irec, int use_crc);

packet_t il2p_decode_header_payload (unsigned char* uhdr, unsigned char *epayload, int *symbols_corrected);
packet_t il2p_decode_header_payload (unsigned char* uhdr, unsigned char *epayload, int *symbols_corrected, int use_crc);



Expand Down Expand Up @@ -138,7 +139,7 @@ extern int il2p_payload_compute (il2p_payload_properties_t *p, int payload_size,

extern int il2p_encode_payload (unsigned char *payload, int payload_size, int max_fec, unsigned char *enc);

extern int il2p_decode_payload (unsigned char *received, int payload_size, int max_fec, unsigned char *payload_out, int *symbols_corrected);
extern int il2p_decode_payload (unsigned char *received, int payload_size, int max_fec, unsigned char *payload_out, int *symbols_corrected, unsigned char **next_hdr);

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

Expand Down
Loading