summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2016-02-12 20:46:34 +0100
committerDaniel Friesel <derf@finalrewind.org>2016-02-12 20:46:34 +0100
commit712950db5e0c08d7b31a5074765d507f73da423c (patch)
tree575ae37257e87e1fe11581be5fe45a2a592d2eaf
parent285952ea1dc6ac40d67820844033d6115ab7e404 (diff)
quick&dirty hamming buffer implementation.
-rw-r--r--src/fecmodem.cc28
-rw-r--r--src/fecmodem.h11
-rw-r--r--src/modem.cc10
-rw-r--r--src/modem.h5
4 files changed, 53 insertions, 1 deletions
diff --git a/src/fecmodem.cc b/src/fecmodem.cc
index bd0d58c..52271fd 100644
--- a/src/fecmodem.cc
+++ b/src/fecmodem.cc
@@ -48,4 +48,32 @@ uint8_t FECModem::hamming2416(uint8_t *byte1, uint8_t *byte2, uint8_t parity)
return 0;
}
+uint8_t FECModem::buffer_available()
+{
+ if (rxWasReset())
+ hammingState = FIRST_BYTE;
+ if (this->Modem::buffer_available() >= 3)
+ return 2;
+ if (hammingState == SECOND_BYTE)
+ return 1;
+ return 0;
+}
+
+uint8_t FECModem::buffer_get()
+{
+ uint8_t byte1, parity;
+ if (hammingState == SECOND_BYTE) {
+ hammingState = FIRST_BYTE;
+ return buf_byte;
+ }
+ hammingState = SECOND_BYTE;
+ byte1 = this->Modem::buffer_get();
+ buf_byte = this->Modem::buffer_get();
+ parity = this->Modem::buffer_get();
+
+ hamming2416(&byte1, &buf_byte, parity);
+
+ return byte1;
+}
+
FECModem modem;
diff --git a/src/fecmodem.h b/src/fecmodem.h
index dd36f68..00487ee 100644
--- a/src/fecmodem.h
+++ b/src/fecmodem.h
@@ -9,10 +9,21 @@
class FECModem : public Modem {
private:
+ enum HammingState : uint8_t {
+ FIRST_BYTE,
+ SECOND_BYTE
+ };
+ HammingState hammingState;
+ uint8_t buf_byte;
+
uint8_t parity128(uint8_t byte);
uint8_t parity2416(uint8_t byte1, uint8_t byte2);
uint8_t correct128(uint8_t *byte, uint8_t parity);
uint8_t hamming2416(uint8_t *byte1, uint8_t *byte2, uint8_t parity);
+ public:
+ FECModem() : Modem() { hammingState = FIRST_BYTE; };
+ uint8_t buffer_available(void);
+ uint8_t buffer_get(void);
};
extern FECModem modem;
diff --git a/src/modem.cc b/src/modem.cc
index 472fe04..dc183b1 100644
--- a/src/modem.cc
+++ b/src/modem.cc
@@ -14,6 +14,15 @@
extern FECModem modem;
+bool Modem::rxWasReset()
+{
+ if (new_transmission) {
+ new_transmission = false;
+ return true;
+ }
+ return false;
+}
+
/*
* Returns number of available bytes in ringbuffer or 0 if empty
*/
@@ -84,6 +93,7 @@ void Modem::receive() {
if (modem_pulselen > MODEM_SYNC_LEN) {
modem_bitlen = (modem_pulselen >> 2);
modem_bit = 0;
+ new_transmission = true;
return;
}
diff --git a/src/modem.h b/src/modem.h
index 4040c92..284edeb 100644
--- a/src/modem.h
+++ b/src/modem.h
@@ -32,9 +32,12 @@ class Modem {
uint8_t buffer_head;
uint8_t buffer_tail;
uint8_t buffer[MODEM_BUFFER_SIZE];
+ bool new_transmission;
void buffer_put(const uint8_t c);
public:
- Modem() {};
+ Modem() {new_transmission = false;};
+
+ bool rxWasReset();
/**
* Checks if there are unprocessed bytes in the modem receive buffer.