Skip to content

Commit cbc39fc

Browse files
committed
added comments & debug msg
1 parent 2e6da54 commit cbc39fc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

examples/uart_rx_file/uart_rx_file.ino

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ void setup()
1414
Serial1.begin(115200);
1515

1616
myTransfer.begin(Serial1);
17+
18+
/*
19+
Or, use the full constructor:
20+
myTransfer.begin(Serial1, true, Serial, 50);
21+
With the timeout parameter set to 50ms, a packet must be fully received and parsed within 50ms,
22+
or it will be discarded.
23+
The timeout value should depend on the baud rate and on the application.
24+
Example back-of-the-envelope calculation:
25+
115200bps = 14400Bps
26+
One packet = 264B (max) should take max 264/11400 s = 0.02s = 20ms
27+
to transfer. Include some time for parsing the packet (which depends on the frequency
28+
of whatever task is calling transfer.available()) - and 50ms does not sound unreasonable.
1729
}
1830
1931

src/Packet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ uint8_t Packet::constructPacket(const uint16_t& messageLen, const uint8_t packet
124124
uint8_t Packet::parse(uint8_t recChar, bool valid)
125125
{
126126
bool packet_fresh = packetStart==0 || millis()-packetStart<timeout;
127-
if(!packet_fresh){
128-
127+
if(!packet_fresh){ //packet is stale, start over.
128+
debugPort->println("STALE PACKET");
129129
bytesRead = 0;
130130
state = find_start_byte;
131131
packetStart=0;

0 commit comments

Comments
 (0)