Revision 1298
Printing an error message when a received packet is too long.
trunk/code/projects/diagnostic_station/station/comm_robot.c | ||
---|---|---|
281 | 281 |
// The packet buffer might be overwritten after this function returns, so we have to make a copy of the data. |
282 | 282 |
|
283 | 283 |
// First, determine the number of bytes to copy. It is the minimum of the received length and the size of the data |
284 |
// buffer the data is copied to. TODO: signal an error if this happens. |
|
284 |
// buffer the data is copied to. If the received length is greater than the buffer size, print an error message. |
|
285 |
// We could stop here (while (1);), but then any long packet would stop the program, even if it's unrelated to |
|
286 |
// what we're doing. |
|
285 | 287 |
received_length=length; |
286 |
if (sizeof (received_buffer)<received_length) received_length=sizeof (received_buffer); |
|
288 |
if (sizeof (received_buffer)<received_length) |
|
289 |
{ |
|
290 |
received_length=sizeof (received_buffer); |
|
291 |
usb_puts ("# Error: received packet is too long for allocated buffer." NL); |
|
292 |
} |
|
287 | 293 |
|
288 | 294 |
// Now copy the data |
289 | 295 |
memcpy (received_buffer, packet, received_length); |
Also available in: Unified diff