Commit 7566dc02 authored by Reto Da Forno's avatar Reto Da Forno
Browse files

fix issue with timestamp alignment in gloria header and arguments for packet...

fix issue with timestamp alignment in gloria header and arguments for packet filter callback changed
parent 3ed6c1cb
......@@ -292,7 +292,7 @@ static void elwb_update_rssi_snr(void)
}
static bool elwb_bootstrap_sched_pkt_filter(uint8_t* pkt, uint8_t len)
static bool elwb_bootstrap_sched_pkt_filter(const uint8_t* gloria_hdr, uint8_t hdr_len, const uint8_t* pkt, uint8_t len)
{
if ((len > ELWB_PKT_HDR_LEN) && ELWB_IS_PKT_HEADER_VALID((elwb_packet_t*)pkt) && ELWB_IS_SCHEDULE_PACKET((elwb_packet_t*)pkt) && ELWB_SCHED_IS_FIRST((elwb_schedule_t*)pkt)) {
return true;
......@@ -300,6 +300,7 @@ static bool elwb_bootstrap_sched_pkt_filter(uint8_t* pkt, uint8_t len)
return false;
}
static bool elwb_is_schedule_valid(elwb_schedule_t* schedule)
{
if (!gloria_is_t_ref_updated() || !ELWB_IS_PKT_HEADER_VALID(schedule) || !ELWB_IS_SCHEDULE_PACKET(schedule) || (gloria_get_payload_len() < (ELWB_SCHED_HDR_LEN + ELWB_SCHED_CRC_LEN))) {
......
......@@ -79,7 +79,7 @@ void gloria_run_flood(gloria_flood_t* flood, gloria_flood_cb_t callback)
// add timestamp for sync floods
if (current_flood->header.sync) {
uint64_t new_timestamp = current_flood->received_marker / GLORIA_SCHEDULE_GRANULARITY;
memcpy(current_flood->header.timestamp, (uint8_t*)&new_timestamp, GLORIA_TIMESTAMP_LENGTH);
memcpy(current_flood->ack_mode ? current_flood->header.ext.timestamp : current_flood->header.min.timestamp, (uint8_t*)&new_timestamp, GLORIA_TIMESTAMP_LENGTH);
current_flood->header_size += GLORIA_TIMESTAMP_LENGTH;
}
}
......@@ -117,7 +117,7 @@ void gloria_run_flood(gloria_flood_t* flood, gloria_flood_cb_t callback)
// initialize message header
if (current_flood->ack_mode) {
current_flood->header.src = (current_flood->initiator ? current_flood->node_id : 0);
current_flood->header.ext.src = (current_flood->initiator ? current_flood->node_id : 0);
}
// initialize error flags
......@@ -244,10 +244,10 @@ static void gloria_process_rx(uint8_t* payload, uint8_t size)
current_flood->guard_time = 0; // set guard time to 0 as node is now synced to this flood
// check if node is also the destination
if (current_flood->ack_mode && (header->dst == current_flood->node_id)) {
if (current_flood->ack_mode && (header->ext.dst == current_flood->node_id)) {
// prepare ack if flood should be acked
current_flood->acked = true;
current_flood->ack_message.dst = header->src;
current_flood->ack_message.dst = header->ext.src;
}
if (!current_flood->ack_mode) {
......
......@@ -136,8 +136,6 @@ void gloria_start(bool is_initiator,
flood.first_rx_index = 0;
flood.flood_idx = 0;
flood.header_size = 0;
flood.header.src = 0;
flood.header.dst = 0;
flood.last_active_slot = 0;
flood.max_acks = 0;
flood.msg_received = false;
......@@ -413,7 +411,7 @@ void gloria_enable_append_timestamp(bool enable)
bool gloria_get_received_timestamp(uint8_t* out_timestamp)
{
if (out_timestamp && flood.header.sync) {
memcpy(out_timestamp, flood.header.timestamp, GLORIA_TIMESTAMP_LENGTH);
memcpy(out_timestamp, flood.header.min.timestamp, GLORIA_TIMESTAMP_LENGTH);
return true;
}
return false;
......
......@@ -314,9 +314,9 @@ void gloria_register_flood_callback(gloria_flood_cb_t flood_cb);
/**
* \brief Set a custom RX packet filter
* \param A callback function that takes a pointer to the received
* payload as well as the payload length. It must returns true
* if the received packet should be kept / accepted and false
* otherwise.
* header, the header length, a pointer to the payload and the
* payload length. It must returns true if the received packet
* should be kept / accepted and false otherwise.
* IMPORTANT: The function must be fast and deterministic. Make
* sure the function completes execution within ~100us. Longer
* execution times may disrupt the Gloria timing.
......
......@@ -300,7 +300,7 @@ static void gloria_radio_rx_callback(uint8_t* payload, uint16_t size, int16_t r
// check packet type and apply user-defined packet filter
if ((header->protocol_id != PROTOCOL_ID_GLORIA) ||
(current_flood->filter_cb && (size > current_flood->header_size) && !current_flood->filter_cb(payload + current_flood->header_size, size - current_flood->header_size))) {
(current_flood->filter_cb && (size > current_flood->header_size) && !current_flood->filter_cb(payload, current_flood->header_size, payload + current_flood->header_size, size - current_flood->header_size))) {
gloria_radio_continue_rx();
}
else {
......
......@@ -33,7 +33,7 @@
typedef void (* gloria_flood_cb_t)(void);
typedef bool (* gloria_filter_cb_t)(uint8_t*, uint8_t);
typedef bool (* gloria_filter_cb_t)(const uint8_t*, uint8_t, const uint8_t*, uint8_t);
typedef bool (* gloria_rx_cb_t)(void);
typedef struct __attribute__((__packed__, __aligned__(1))) {
......@@ -48,9 +48,16 @@ typedef struct __attribute__((__packed__, __aligned__(1))) {
uint8_t type : 3; // msg type
uint8_t sync: 1; // 1: message includes ts for sync, 0: no ts
int8_t slot_index; // current slot index (must be signed due to init values for ACK floods)
uint8_t src; // msg source
uint8_t dst; // msg destination
uint8_t timestamp[GLORIA_TIMESTAMP_LENGTH];
union {
struct { // extended header for ACK mode
uint8_t src; // msg source
uint8_t dst; // msg destination
uint8_t timestamp[GLORIA_TIMESTAMP_LENGTH]; // optional timestamp
} ext;
struct { // minimal header
uint8_t timestamp[GLORIA_TIMESTAMP_LENGTH]; // optional timestamp
} min;
};
} gloria_header_t;
typedef enum {
......
......@@ -289,7 +289,7 @@ static void lwb_update_rssi_snr(void)
}
static bool lwb_bootstrap_sched_pkt_filter(uint8_t* pkt, uint8_t len)
static bool lwb_bootstrap_sched_pkt_filter(const uint8_t* gloria_hdr, uint8_t hdr_len, const uint8_t* pkt, uint8_t len)
{
if ((len > LWB_PKT_HDR_LEN) && LWB_IS_PKT_HEADER_VALID((lwb_packet_t*)pkt) && LWB_IS_SCHEDULE_PACKET((lwb_packet_t*)pkt)) {
return true;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment