- Addressing
- Configuration
- Data reception
- Data structures
- Data transmission
- Error handling
- Routing
- IO setup
PJON is designed to inform the user if an error is detected. A function of type void
can be defined and registered to be called by the PJON object in case of error; it receives 3 parameters, the first is the error code of type uint8_t
, the second is additional data related to the error of type uint16_t
and the third is a general purpose custom pointer of type void *
.
Error types:
PJON_CONNECTION_LOST
or 101,data
parameter contains lost packet's index in the buffer.PJON_PACKETS_BUFFER_FULL
or 102,data
parameter contains buffer length.PJON_CONTENT_TOO_LONG
or 104,data
parameter contains content length.
void error_handler(uint8_t code, uint16_t data, void *custom_pointer) {
if(code == PJON_CONNECTION_LOST) {
Serial.print("Connection with device ID ");
Serial.print(bus.packets[data].content[0], DEC);
Serial.println(" is lost.");
}
if(code == PJON_PACKETS_BUFFER_FULL) {
Serial.print("Packet buffer is full, has now a length of ");
Serial.println(data);
Serial.println("Possible wrong bus configuration!");
Serial.println("higher PJON_MAX_PACKETS if necessary.");
}
if(code == PJON_CONTENT_TOO_LONG) {
Serial.print("Content is too long, length: ");
Serial.println(data);
}
}
Now inform the instance to call error_handler
in case of error:
bus.set_error(error_handler);