Discard repeated messages
parent
a8df6732fe
commit
b143247caf
|
|
@ -227,6 +227,8 @@ bool Application::CheckMsgs() {
|
||||||
while (modules::serial::Available()) {
|
while (modules::serial::Available()) {
|
||||||
switch (protocol.DecodeRequest(modules::serial::ConsumeByte())) {
|
switch (protocol.DecodeRequest(modules::serial::ConsumeByte())) {
|
||||||
case mpd::MessageCompleted:
|
case mpd::MessageCompleted:
|
||||||
|
// Discard any unread data
|
||||||
|
modules::serial::Reset();
|
||||||
// process the input message
|
// process the input message
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,16 @@ uint8_t USART::Read() {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void USART::ResetReceiver()
|
||||||
|
{
|
||||||
|
// Disable/Enable Receiver to discard pending bytes
|
||||||
|
husart->UCSRxB &= ~(1 << 4);
|
||||||
|
husart->UCSRxB |= (1 << 4);
|
||||||
|
|
||||||
|
// Reset circular buffer, head = tail
|
||||||
|
rx_buf.reset();
|
||||||
|
}
|
||||||
|
|
||||||
void USART::Write(uint8_t c) {
|
void USART::Write(uint8_t c) {
|
||||||
_written = true;
|
_written = true;
|
||||||
// If the buffer and the data register is empty, just write the byte
|
// If the buffer and the data register is empty, just write the byte
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,11 @@ public:
|
||||||
return ((index_t)(head - tail) % (size * 2)) == size;
|
return ((index_t)(head - tail) % (size * 2)) == size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reset the circular buffer to empty
|
||||||
|
inline void reset() {
|
||||||
|
head = tail;
|
||||||
|
}
|
||||||
|
|
||||||
/// Advance the head index of the buffer.
|
/// Advance the head index of the buffer.
|
||||||
/// No checks are performed. full() needs to be queried beforehand.
|
/// No checks are performed. full() needs to be queried beforehand.
|
||||||
inline void push() {
|
inline void push() {
|
||||||
|
|
@ -101,6 +106,11 @@ public:
|
||||||
return index.full();
|
return index.full();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reset the circular buffer to empty
|
||||||
|
inline void reset() {
|
||||||
|
index.reset();
|
||||||
|
}
|
||||||
|
|
||||||
/// Insert an element into the buffer.
|
/// Insert an element into the buffer.
|
||||||
/// Checks for empty spot for the element and does not change the buffer content
|
/// Checks for empty spot for the element and does not change the buffer content
|
||||||
/// in case the buffer is full.
|
/// in case the buffer is full.
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,9 @@ public:
|
||||||
/// @returns current character from the UART and extracts it from the read buffer
|
/// @returns current character from the UART and extracts it from the read buffer
|
||||||
uint8_t Read();
|
uint8_t Read();
|
||||||
|
|
||||||
|
/// Discard all pending data from the receiver
|
||||||
|
void ResetReceiver();
|
||||||
|
|
||||||
/// @param c character to be pushed into the TX buffer (to be sent)
|
/// @param c character to be pushed into the TX buffer (to be sent)
|
||||||
void Write(uint8_t c);
|
void Write(uint8_t c);
|
||||||
/// @param str pointer to a string in RAM to be pushed byte-by-byte into the TX buffer (to be sent)
|
/// @param str pointer to a string in RAM to be pushed byte-by-byte into the TX buffer (to be sent)
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,10 @@ uint8_t ConsumeByte() {
|
||||||
return hu::usart1.Read();
|
return hu::usart1.Read();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Reset() {
|
||||||
|
hu::usart1.ResetReceiver();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace serial
|
} // namespace serial
|
||||||
|
|
||||||
} // namespace modules
|
} // namespace modules
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ bool Available();
|
||||||
|
|
||||||
uint8_t ConsumeByte();
|
uint8_t ConsumeByte();
|
||||||
|
|
||||||
|
void Reset();
|
||||||
|
|
||||||
} // namespace serial
|
} // namespace serial
|
||||||
|
|
||||||
} // namespace modules
|
} // namespace modules
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue