Removed unused Stream interface from Bridge class

This commit is contained in:
Cristian Maglie 2013-06-24 11:23:35 +02:00
parent 8ac5c7c076
commit fdae2dbb6e
2 changed files with 18 additions and 29 deletions

View File

@ -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();
}
}

View File

@ -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,