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;
|
bool ret = true;
|
||||||
|
|
||||||
hdlc->demod_bits <<= 1;
|
hdlc->demodulatedBits <<= 1;
|
||||||
hdlc->demod_bits |= bit ? 1 : 0;
|
hdlc->demodulatedBits |= bit ? 1 : 0;
|
||||||
|
|
||||||
/* HDLC Flag */
|
/* HDLC Flag */
|
||||||
if (hdlc->demod_bits == HDLC_FLAG)
|
if (hdlc->demodulatedBits == HDLC_FLAG)
|
||||||
{
|
{
|
||||||
if (!fifo_isfull(fifo))
|
if (!fifo_isfull(fifo))
|
||||||
{
|
{
|
||||||
fifo_push(fifo, HDLC_FLAG);
|
fifo_push(fifo, HDLC_FLAG);
|
||||||
hdlc->rxstart = true;
|
hdlc->receiving = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = false;
|
ret = false;
|
||||||
hdlc->rxstart = false;
|
hdlc->receiving = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
hdlc->currchar = 0;
|
hdlc->currentByte = 0;
|
||||||
hdlc->bit_idx = 0;
|
hdlc->bitIndex = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset */
|
/* Reset */
|
||||||
if ((hdlc->demod_bits & HDLC_RESET) == HDLC_RESET)
|
if ((hdlc->demodulatedBits & HDLC_RESET) == HDLC_RESET)
|
||||||
{
|
{
|
||||||
hdlc->rxstart = false;
|
hdlc->receiving = false;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hdlc->rxstart)
|
if (!hdlc->receiving)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* Stuffed bit */
|
/* Stuffed bit */
|
||||||
if ((hdlc->demod_bits & 0x3f) == 0x3e)
|
if ((hdlc->demodulatedBits & 0x3f) == 0x3e)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (hdlc->demod_bits & 0x01)
|
if (hdlc->demodulatedBits & 0x01)
|
||||||
hdlc->currchar |= 0x80;
|
hdlc->currentByte |= 0x80;
|
||||||
|
|
||||||
if (++hdlc->bit_idx >= 8)
|
if (++hdlc->bitIndex >= 8)
|
||||||
{
|
{
|
||||||
if ((hdlc->currchar == HDLC_FLAG
|
if ((hdlc->currentByte == HDLC_FLAG
|
||||||
|| hdlc->currchar == HDLC_RESET
|
|| hdlc->currentByte == HDLC_RESET
|
||||||
|| hdlc->currchar == AX25_ESC))
|
|| hdlc->currentByte == AX25_ESC))
|
||||||
{
|
{
|
||||||
if (!fifo_isfull(fifo))
|
if (!fifo_isfull(fifo))
|
||||||
fifo_push(fifo, AX25_ESC);
|
fifo_push(fifo, AX25_ESC);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hdlc->rxstart = false;
|
hdlc->receiving = false;
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fifo_isfull(fifo))
|
if (!fifo_isfull(fifo))
|
||||||
fifo_push(fifo, hdlc->currchar);
|
fifo_push(fifo, hdlc->currentByte);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hdlc->rxstart = false;
|
hdlc->receiving = false;
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
hdlc->currchar = 0;
|
hdlc->currentByte = 0;
|
||||||
hdlc->bit_idx = 0;
|
hdlc->bitIndex = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
hdlc->currchar >>= 1;
|
hdlc->currentByte >>= 1;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
|
|
||||||
typedef struct Hdlc
|
typedef struct Hdlc
|
||||||
{
|
{
|
||||||
uint8_t demod_bits; ///< Bitstream from the demodulator.
|
uint8_t demodulatedBits; // Incoming bitstream from demodulator
|
||||||
uint8_t bit_idx; ///< Current received bit.
|
uint8_t bitIndex; // The current received bit in the current received byte
|
||||||
uint8_t currchar; ///< Current received character.
|
uint8_t currentByte; // The byte we're currently receiving
|
||||||
bool rxstart; ///< True if an HDLC_FLAG char has been found in the bitstream.
|
bool receiving; // Whether or not where actually receiving data (or just noise ;P)
|
||||||
} Hdlc;
|
} Hdlc;
|
||||||
|
|
||||||
#define AFSK_RXFIFO_OVERRUN BV(0)
|
#define AFSK_RXFIFO_OVERRUN BV(0)
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
#define VERS_BUILD 49
|
#define VERS_BUILD 51
|
||||||
#define VERS_HOST "vixen"
|
#define VERS_HOST "vixen"
|
||||||
|
|
Loading…
Reference in New Issue