aboutsummaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
Diffstat (limited to 'libraries')
-rw-r--r--libraries/Bridge/Bridge.cpp34
-rw-r--r--libraries/Bridge/Bridge.h13
2 files changed, 18 insertions, 29 deletions
diff --git a/libraries/Bridge/Bridge.cpp b/libraries/Bridge/Bridge.cpp
index d6d830c..6e9cafc 100644
--- a/libraries/Bridge/Bridge.cpp
+++ b/libraries/Bridge/Bridge.cpp
@@ -31,19 +31,19 @@ void BridgeClass::begin() {
do {
dropAll();
delay(1100);
- } while (available()>0);
+ } while (stream.available()>0);
// Bridge startup:
// - If the bridge is not running starts it safely
- print(CTRL_C);
+ stream.print(CTRL_C);
delay(250);
- print(F("\n"));
+ stream.print(F("\n"));
delay(500);
- print(F("\n"));
+ stream.print(F("\n"));
delay(750);
// Wait for OpenWRT message
// "Press enter to activate console"
- print(F("run-bridge\n"));
+ stream.print(F("run-bridge\n"));
delay(500);
dropAll();
@@ -111,8 +111,8 @@ void BridgeClass::crcReset() {
}
void BridgeClass::crcWrite() {
- write((char)(CRC >> 8));
- write((char)(CRC & 0xFF));
+ stream.write((char)(CRC >> 8));
+ stream.write((char)(CRC & 0xFF));
}
bool BridgeClass::crcCheck(uint16_t _CRC) {
@@ -128,24 +128,24 @@ uint16_t BridgeClass::transfer(const uint8_t *buff1, uint16_t len1,
for ( ; ; delay(100), dropAll() /* Delay for retransmission */) {
// Send packet
crcReset();
- write((char)0xFF); // Start of packet (0xFF)
+ stream.write((char)0xFF); // Start of packet (0xFF)
crcUpdate(0xFF);
- write((char)index); // Message index
+ stream.write((char)index); // Message index
crcUpdate(index);
- write((char)((len >> 8) & 0xFF)); // Message length (hi)
+ stream.write((char)((len >> 8) & 0xFF)); // Message length (hi)
crcUpdate((len >> 8) & 0xFF);
- write((char)(len & 0xFF)); // Message length (lo)
+ stream.write((char)(len & 0xFF)); // Message length (lo)
crcUpdate(len & 0xFF);
for (uint16_t i=0; i<len1; i++) { // Payload
- write((char)buff1[i]);
+ stream.write((char)buff1[i]);
crcUpdate(buff1[i]);
}
for (uint16_t i=0; i<len2; i++) { // Payload
- write((char)buff2[i]);
+ stream.write((char)buff2[i]);
crcUpdate(buff2[i]);
}
for (uint16_t i=0; i<len3; i++) { // Payload
- write((char)buff3[i]);
+ stream.write((char)buff3[i]);
crcUpdate(buff3[i]);
}
crcWrite(); // CRC
@@ -209,15 +209,15 @@ int BridgeClass::timedRead(unsigned int timeout) {
int c;
unsigned long _startMillis = millis();
do {
- c = read();
+ c = stream.read();
if (c >= 0) return c;
} while(millis() - _startMillis < timeout);
return -1; // -1 indicates timeout
}
void BridgeClass::dropAll() {
- while (available() > 0) {
- read();
+ while (stream.available() > 0) {
+ stream.read();
}
}
diff --git a/libraries/Bridge/Bridge.h b/libraries/Bridge/Bridge.h
index f606492..3aabeff 100644
--- a/libraries/Bridge/Bridge.h
+++ b/libraries/Bridge/Bridge.h
@@ -22,7 +22,7 @@
#include <Arduino.h>
#include <Stream.h>
-class BridgeClass: public Stream {
+class BridgeClass {
public:
BridgeClass(Stream &_stream);
void begin();
@@ -40,17 +40,6 @@ public:
unsigned int get(const char *key, char *value, unsigned int maxlen)
{ get(key, reinterpret_cast<uint8_t *>(value), maxlen); }
- // Print methods (proxy to "stream" object) [CM: are these really needed?]
- size_t write(uint8_t c) { return stream.write(c); }
- size_t write(const uint8_t *buffer, size_t size)
- { return stream.write(buffer, size); }
-
- // Stream methods (proxy to "stream" object) [CM: are these really needed?]
- int available() { return stream.available(); }
- int read() { return stream.read(); }
- int peek() { return stream.peek(); }
- void flush() { stream.flush(); }
-
// Trasnfer a frame (with error correction and response)
uint16_t transfer(const uint8_t *buff1, uint16_t len1,
const uint8_t *buff2, uint16_t len2,