Permalink
Browse files

Full extended header support

  • Loading branch information...
gioblu committed Nov 13, 2016
1 parent 5e4fa16 commit 29d9ac7cc3654fc833c997df4e6bdb5c8875edb8
8 PJON.h
@@ -269,11 +269,9 @@ limitations under the License. */
void parse(const uint8_t *packet, PacketInfo &packet_info) const {
packet_info.receiver_id = packet[0];
packet_info.header = packet[1];
bool extended_header = packet_info.header & EXTEND_HEADER_BIT;
bool extended_length = packet_info.header & EXTEND_LENGTH_BIT;
if(extended_header) packet_info.extended_header = packet[2];
else packet_info.extended_header = 0;
bool extended_header = packet[1] & EXTEND_HEADER_BIT;
bool extended_length = packet[1] & EXTEND_LENGTH_BIT;
packet_info.header = (extended_header) ? packet[2] << 8 | packet[1] : packet[1];
if((packet_info.header & MODE_BIT) != 0) {
copy_bus_id(packet_info.receiver_bus_id, packet + 3 + extended_header + extended_length);
if((packet_info.header & SENDER_INFO_BIT) != 0) {
@@ -100,6 +100,13 @@ limitations under the License. */
#define CRC_BIT B00100000 // 1 - CRC32 | 0 - CRC8
#define EXTEND_LENGTH_BIT B01000000 // 1 - 2 bytes length | 0 - 1 byte length
#define EXTEND_HEADER_BIT B10000000 // 1 - 2 bytes header | 0 - 1 byte header
#define ROUTING_BIT 0B0100000000000000 // 1 - Routing request 0 - No routing requested
#define SEGMENTATION_BIT 0B0010000000000000 // 1 - Segmentated | 0 - Not segmented
#define SESSION_BIT 0B0001000000000000 // 1 - Session | 0 - Not including Session
#define PARITY_BIT 0B0000100000000000 // 1 - Parity redundant info | 0 - No parity included
#define ENCODING_BIT 0B0000010000000000 // 1 - Encoding info | 0 - Not including encoding ingo
#define DATA_COMP_BIT 0B0000001000000000 // 1 - Data compression | 0 - No data compression
#define ENCRYPTION_BIT 0B0000000100000000 // 1 - Encrypted data | 0 - Not encrypted data
/* ERRORS: */
#define CONNECTION_LOST 101
@@ -162,8 +169,7 @@ limitations under the License. */
/* Last received packet Metainfo */
struct PacketInfo {
uint8_t header = 0;
uint8_t extended_header = 0;
uint16_t header = 0;
uint8_t receiver_id = 0;
uint8_t receiver_bus_id[4];
uint8_t sender_id = 0;
@@ -34,11 +34,6 @@ void setup() {
void receiver_function(uint8_t *payload, uint16_t length, const PacketInfo &packet_info) {
Serial.print("Header: ");
Serial.print(packet_info.header, BIN);
// If extended header included
if(packet_info.header & EXTEND_HEADER_BIT) {
Serial.print(" Extended header: ");
Serial.print(packet_info.extended_header);
}
// If packet formatted for a shared medium
if(packet_info.header & MODE_BIT) {
Serial.print(" Receiver bus id: ");
@@ -23,11 +23,6 @@ void receiver_function(uint8_t *payload, uint16_t length, const PacketInfo &pack
if(debug) {
Serial.print("Header: ");
Serial.print(packet_info.header, BIN);
// If extended header included
if(packet_info.header & EXTEND_HEADER_BIT) {
Serial.print(" Extended header: ");
Serial.print(packet_info.extended_header);
}
// If packet formatted for a shared medium
if(packet_info.header & MODE_BIT) {
Serial.print(" Receiver bus id: ");

0 comments on commit 29d9ac7

Please sign in to comment.