Last active
August 29, 2015 14:21
-
-
Save StuffAndyMakes/ca2b0d1c9f46b36c2ac5 to your computer and use it in GitHub Desktop.
Snippet showing SerialPacket receiving
This file contains hidden or 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
typedef struct { | |
uint8_t device; | |
uint8_t command; | |
uint32_t value; | |
uint64_t serial; | |
uint8_t ack; | |
} Command; | |
void SenderApplication::didReceiveGoodPacket(SerialPacket *p) { | |
Serial.println("Got good packet!"); | |
Command _receivedCommand; | |
memcpy(&_receivedCommand, p->buffer, p->getDataLength()); | |
Serial.println(_receivedCommand.device, DEC); | |
p->startReceiving(); // continue receiving | |
} | |
void SenderApplication::didReceiveBadPacket(SerialPacket *p, uint8_t err) { | |
Serial.println("Got error " + String(err, DEC) + " receiving packet. Boo!") | |
} | |
void SenderApplication::main() { | |
Serial.begin(115200); // debugging output | |
Serial1.begin(19200); // sending & receiving packets | |
SerialPacket p; | |
p.setDelegate(this); | |
p.setTimeout(2000); | |
p.use(&Serial1); | |
for(;;) { | |
p.loop; // give packet some time to work | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment