Bypass the FEC if the packet has a valid CRC
This commit is contained in:
parent
fc3f3f2dff
commit
e6a3cfbe42
68
ssdv.c
68
ssdv.c
|
@ -1300,19 +1300,50 @@ char ssdv_dec_is_packet(uint8_t *packet, int *errors)
|
||||||
memcpy(pkt, packet, SSDV_PKT_SIZE);
|
memcpy(pkt, packet, SSDV_PKT_SIZE);
|
||||||
pkt[0] = 0x55;
|
pkt[0] = 0x55;
|
||||||
|
|
||||||
|
type = SSDV_TYPE_INVALID;
|
||||||
|
|
||||||
if(pkt[1] == 0x66 + SSDV_TYPE_NOFEC)
|
if(pkt[1] == 0x66 + SSDV_TYPE_NOFEC)
|
||||||
{
|
{
|
||||||
type = SSDV_TYPE_NOFEC;
|
/* Test for a valid NOFEC packet */
|
||||||
|
|
||||||
pkt_size_payload = SSDV_PKT_SIZE - SSDV_PKT_SIZE_HEADER - SSDV_PKT_SIZE_CRC;
|
pkt_size_payload = SSDV_PKT_SIZE - SSDV_PKT_SIZE_HEADER - SSDV_PKT_SIZE_CRC;
|
||||||
pkt_size_crcdata = SSDV_PKT_SIZE_HEADER + pkt_size_payload - 1;
|
pkt_size_crcdata = SSDV_PKT_SIZE_HEADER + pkt_size_payload - 1;
|
||||||
|
|
||||||
|
/* No FEC scan */
|
||||||
if(errors) *errors = 0;
|
if(errors) *errors = 0;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
type = SSDV_TYPE_NORMAL;
|
|
||||||
|
|
||||||
|
/* Test the checksum */
|
||||||
|
x = crc32(&pkt[1], pkt_size_crcdata);
|
||||||
|
|
||||||
|
i = 1 + pkt_size_crcdata;
|
||||||
|
if(x == (pkt[i + 3] | (pkt[i + 2] << 8) | (pkt[i + 1] << 16) | (pkt[i] << 24)))
|
||||||
|
{
|
||||||
|
/* Valid, set the type and continue */
|
||||||
|
type = SSDV_TYPE_NOFEC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(pkt[1] == 0x66 + SSDV_TYPE_NORMAL)
|
||||||
|
{
|
||||||
|
/* Test for a valid NORMAL packet */
|
||||||
|
pkt_size_payload = SSDV_PKT_SIZE - SSDV_PKT_SIZE_HEADER - SSDV_PKT_SIZE_CRC - SSDV_PKT_SIZE_RSCODES;
|
||||||
|
pkt_size_crcdata = SSDV_PKT_SIZE_HEADER + pkt_size_payload - 1;
|
||||||
|
|
||||||
|
/* No FEC scan */
|
||||||
|
if(errors) *errors = 0;
|
||||||
|
|
||||||
|
/* Test the checksum */
|
||||||
|
x = crc32(&pkt[1], pkt_size_crcdata);
|
||||||
|
|
||||||
|
i = 1 + pkt_size_crcdata;
|
||||||
|
if(x == (pkt[i + 3] | (pkt[i + 2] << 8) | (pkt[i + 1] << 16) | (pkt[i] << 24)))
|
||||||
|
{
|
||||||
|
/* Valid, set the type and continue */
|
||||||
|
type = SSDV_TYPE_NORMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(type == SSDV_TYPE_INVALID)
|
||||||
|
{
|
||||||
|
/* Test for a valid NORMAL packet with correctable errors */
|
||||||
pkt_size_payload = SSDV_PKT_SIZE - SSDV_PKT_SIZE_HEADER - SSDV_PKT_SIZE_CRC - SSDV_PKT_SIZE_RSCODES;
|
pkt_size_payload = SSDV_PKT_SIZE - SSDV_PKT_SIZE_HEADER - SSDV_PKT_SIZE_CRC - SSDV_PKT_SIZE_RSCODES;
|
||||||
pkt_size_crcdata = SSDV_PKT_SIZE_HEADER + pkt_size_payload - 1;
|
pkt_size_crcdata = SSDV_PKT_SIZE_HEADER + pkt_size_payload - 1;
|
||||||
|
|
||||||
|
@ -1322,6 +1353,22 @@ char ssdv_dec_is_packet(uint8_t *packet, int *errors)
|
||||||
|
|
||||||
if(i < 0) return(-1); /* Reed-solomon decoder failed */
|
if(i < 0) return(-1); /* Reed-solomon decoder failed */
|
||||||
if(errors) *errors = i;
|
if(errors) *errors = i;
|
||||||
|
|
||||||
|
/* Test the checksum */
|
||||||
|
x = crc32(&pkt[1], pkt_size_crcdata);
|
||||||
|
|
||||||
|
i = 1 + pkt_size_crcdata;
|
||||||
|
if(x == (pkt[i + 3] | (pkt[i + 2] << 8) | (pkt[i + 1] << 16) | (pkt[i] << 24)))
|
||||||
|
{
|
||||||
|
/* Valid, set the type and continue */
|
||||||
|
type = SSDV_TYPE_NORMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(type == SSDV_TYPE_INVALID)
|
||||||
|
{
|
||||||
|
/* All attempts to read the packet have failed */
|
||||||
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
|
@ -1335,15 +1382,6 @@ char ssdv_dec_is_packet(uint8_t *packet, int *errors)
|
||||||
if(p.mcu_offset >= pkt_size_payload) return(-1);
|
if(p.mcu_offset >= pkt_size_payload) return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test the checksum */
|
|
||||||
x = crc32(&pkt[1], pkt_size_crcdata);
|
|
||||||
|
|
||||||
i = 1 + pkt_size_crcdata;
|
|
||||||
if(pkt[i++] != ((x >> 24) & 0xFF)) return(-1);
|
|
||||||
if(pkt[i++] != ((x >> 16) & 0xFF)) return(-1);
|
|
||||||
if(pkt[i++] != ((x >> 8) & 0xFF)) return(-1);
|
|
||||||
if(pkt[i++] != (x & 0xFF)) return(-1);
|
|
||||||
|
|
||||||
/* Appears to be a valid packet! Copy it back */
|
/* Appears to be a valid packet! Copy it back */
|
||||||
memcpy(packet, pkt, SSDV_PKT_SIZE);
|
memcpy(packet, pkt, SSDV_PKT_SIZE);
|
||||||
|
|
||||||
|
|
5
ssdv.h
5
ssdv.h
|
@ -42,8 +42,9 @@ extern "C" {
|
||||||
|
|
||||||
#define SSDV_MAX_CALLSIGN (6) /* Maximum number of characters in a callsign */
|
#define SSDV_MAX_CALLSIGN (6) /* Maximum number of characters in a callsign */
|
||||||
|
|
||||||
#define SSDV_TYPE_NORMAL (0)
|
#define SSDV_TYPE_INVALID (0xFF)
|
||||||
#define SSDV_TYPE_NOFEC (1)
|
#define SSDV_TYPE_NORMAL (0x00)
|
||||||
|
#define SSDV_TYPE_NOFEC (0x01)
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue