mirror of
https://github.com/markqvist/OpenModem.git
synced 2024-12-29 01:16:17 -05:00
Reworked HDLC struct
This commit is contained in:
parent
e76216875e
commit
e84705e5e1
46
Modem/afsk.c
46
Modem/afsk.c
@ -66,73 +66,73 @@ static bool hdlcParse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo)
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
hdlc->demod_bits <<= 1;
|
||||
hdlc->demod_bits |= bit ? 1 : 0;
|
||||
hdlc->demodulatedBits <<= 1;
|
||||
hdlc->demodulatedBits |= bit ? 1 : 0;
|
||||
|
||||
/* HDLC Flag */
|
||||
if (hdlc->demod_bits == HDLC_FLAG)
|
||||
if (hdlc->demodulatedBits == HDLC_FLAG)
|
||||
{
|
||||
if (!fifo_isfull(fifo))
|
||||
{
|
||||
fifo_push(fifo, HDLC_FLAG);
|
||||
hdlc->rxstart = true;
|
||||
hdlc->receiving = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = false;
|
||||
hdlc->rxstart = false;
|
||||
hdlc->receiving = false;
|
||||
}
|
||||
|
||||
hdlc->currchar = 0;
|
||||
hdlc->bit_idx = 0;
|
||||
hdlc->currentByte = 0;
|
||||
hdlc->bitIndex = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Reset */
|
||||
if ((hdlc->demod_bits & HDLC_RESET) == HDLC_RESET)
|
||||
if ((hdlc->demodulatedBits & HDLC_RESET) == HDLC_RESET)
|
||||
{
|
||||
hdlc->rxstart = false;
|
||||
hdlc->receiving = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!hdlc->rxstart)
|
||||
if (!hdlc->receiving)
|
||||
return ret;
|
||||
|
||||
/* Stuffed bit */
|
||||
if ((hdlc->demod_bits & 0x3f) == 0x3e)
|
||||
if ((hdlc->demodulatedBits & 0x3f) == 0x3e)
|
||||
return ret;
|
||||
|
||||
if (hdlc->demod_bits & 0x01)
|
||||
hdlc->currchar |= 0x80;
|
||||
if (hdlc->demodulatedBits & 0x01)
|
||||
hdlc->currentByte |= 0x80;
|
||||
|
||||
if (++hdlc->bit_idx >= 8)
|
||||
if (++hdlc->bitIndex >= 8)
|
||||
{
|
||||
if ((hdlc->currchar == HDLC_FLAG
|
||||
|| hdlc->currchar == HDLC_RESET
|
||||
|| hdlc->currchar == AX25_ESC))
|
||||
if ((hdlc->currentByte == HDLC_FLAG
|
||||
|| hdlc->currentByte == HDLC_RESET
|
||||
|| hdlc->currentByte == AX25_ESC))
|
||||
{
|
||||
if (!fifo_isfull(fifo))
|
||||
fifo_push(fifo, AX25_ESC);
|
||||
else
|
||||
{
|
||||
hdlc->rxstart = false;
|
||||
hdlc->receiving = false;
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fifo_isfull(fifo))
|
||||
fifo_push(fifo, hdlc->currchar);
|
||||
fifo_push(fifo, hdlc->currentByte);
|
||||
else
|
||||
{
|
||||
hdlc->rxstart = false;
|
||||
hdlc->receiving = false;
|
||||
ret = false;
|
||||
}
|
||||
|
||||
hdlc->currchar = 0;
|
||||
hdlc->bit_idx = 0;
|
||||
hdlc->currentByte = 0;
|
||||
hdlc->bitIndex = 0;
|
||||
}
|
||||
else
|
||||
hdlc->currchar >>= 1;
|
||||
hdlc->currentByte >>= 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -16,10 +16,10 @@
|
||||
|
||||
typedef struct Hdlc
|
||||
{
|
||||
uint8_t demod_bits; ///< Bitstream from the demodulator.
|
||||
uint8_t bit_idx; ///< Current received bit.
|
||||
uint8_t currchar; ///< Current received character.
|
||||
bool rxstart; ///< True if an HDLC_FLAG char has been found in the bitstream.
|
||||
uint8_t demodulatedBits; // Incoming bitstream from demodulator
|
||||
uint8_t bitIndex; // The current received bit in the current received byte
|
||||
uint8_t currentByte; // The byte we're currently receiving
|
||||
bool receiving; // Whether or not where actually receiving data (or just noise ;P)
|
||||
} Hdlc;
|
||||
|
||||
#define AFSK_RXFIFO_OVERRUN BV(0)
|
||||
|
@ -1,2 +1,2 @@
|
||||
#define VERS_BUILD 49
|
||||
#define VERS_BUILD 51
|
||||
#define VERS_HOST "vixen"
|
||||
|
Loading…
Reference in New Issue
Block a user