Created
March 23, 2017 12:09
-
-
Save jaz303/653d9659a0302480bae67e08ade14704 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <HardwareSerial* T> | |
class SerialWriter | |
{ | |
public: | |
void writeMessage(unsigned char *message, int length); | |
}; | |
template <HardwareSerial* T> | |
void SerialWriter<T>::writeMessage(unsigned char *message, int length) { | |
T->write(SafeSerial::MESSAGE_START); | |
for (int ix = 0; ix < length; ++ix) { | |
byte b = message[ix]; | |
if (b == SafeSerial::MESSAGE_START || b == SafeSerial::MESSAGE_END || b == SafeSerial::MESSAGE_ESCAPE) { | |
T->write(SafeSerial::MESSAGE_ESCAPE); | |
T->write(SafeSerial::MESSAGE_XOR ^ b); | |
} else { | |
T->write(b); | |
} | |
} | |
T->write(SafeSerial::MESSAGE_END); | |
} | |
SerialWriter<&SERIAL> writer; | |
unsigned char inBuffer[BUFFER_SIZE]; | |
void main() { | |
// Error: undefined reference to `SerialWriter<&Serial>::writeMessage(unsigned char*, int)' | |
writer.writeMessage(inBuffer, 10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment