Commit b3df113a authored by Reto Da Forno's avatar Reto Da Forno
Browse files

gloria code cleanup, new radio config function, option to set max. payload length added

parent b38c672c
......@@ -581,7 +581,7 @@ static command_return_t gloria_rx_command_handler(command_execution_t execution)
flood.max_acks = macks;
flood.data_slots = slots;
flood.payload = message;
flood.initial = false;
flood.initiator = false;
flood.rx_timeout = cad * HS_TIMER_FREQUENCY_MS;
flood.sync_timer = (bool) sync;
flood.lp_listening = lp_listening;
......@@ -717,7 +717,7 @@ static command_return_t gloria_tx_command_handler(command_execution_t execution)
flood.max_acks = macks;
flood.data_slots = slots;
flood.payload = message;
flood.initial = true;
flood.initiator = true;
if (cont) {
tx_period = txper;
......@@ -737,7 +737,7 @@ static void sync_callback() {
}
static void gloria_cont_callback() {
if (flood.initial) {
if (flood.initiator) {
gloria_last_sync = flood.marker;
}
if (flood.msg_received) {
......@@ -753,7 +753,7 @@ static void gloria_cont_callback() {
flood.guard_time = guard_time * HS_TIMER_FREQUENCY_US;
flood.flood_idx++;
if (!flood.initial || flood.flood_idx < iterations) {
if (!flood.initiator || flood.flood_idx < iterations) {
gloria_run_flood(&flood, &gloria_cont_callback);
}
}
......@@ -762,7 +762,7 @@ static void gloria_finish_callback() {
if (flood.msg_received) {
hs_timer_generic(flood.reconstructed_marker + gloria_calculate_flood_time(flood.payload_size, flood.modulation, flood.data_slots, flood.header.sync, flood.ack_mode) + 50*HS_TIMER_FREQUENCY_MS, &sync_callback);
}
if (flood.initial) {
if (flood.initiator) {
gloria_last_sync = flood.marker;
}
......@@ -817,7 +817,7 @@ void gloria_print_flood(gloria_flood_t *print_flood) {
goto end;
}
if (cJSON_AddBoolToObject(flood_result, "initial", print_flood->initial) == NULL) {
if (cJSON_AddBoolToObject(flood_result, "initiator", print_flood->initiator) == NULL) {
goto end;
}
......
/*
* Copyright (c) 2018 - 2021, ETH Zurich, Computer Engineering Group (TEC)
* Copyright (c) 2018 - 2022, ETH Zurich, Computer Engineering Group (TEC)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -32,37 +32,32 @@
#if GLORIA_ENABLE
extern volatile uint64_t gloria_last_sync;
gloria_flood_t* current_flood = NULL;
static void (*flood_callback)();
static gloria_flood_t* current_flood = NULL;
static gloria_flood_cb_t flood_callback = NULL;
static void gloria_rx_callback(uint8_t* payload, uint8_t size);
static void gloria_process_rx(uint8_t* payload, uint8_t size);
static void gloria_tx_callback();
static void gloria_process_slot();
static void gloria_finish_slot();
static void gloria_tx_callback(void);
static void gloria_process_slot(void);
static void gloria_finish_slot(void);
/*
* initialize the necessary flood and message header parameters
* start the flood
*/
void gloria_run_flood(gloria_flood_t* flood, void (*callback)())
void gloria_run_flood(gloria_flood_t* flood, gloria_flood_cb_t callback)
{
current_flood = flood;
flood_callback = callback;
// initialize flood parameters
current_flood->first_rx_index = ((current_flood->ack_mode ? -2 : -1));
current_flood->header.protocol_id = PROTOCOL_ID_GLORIA;
current_flood->header.type = 0;
current_flood->header.slot_index = 0;
current_flood->msg_received = current_flood->initial;
current_flood->last_active_slot = gloria_calculate_last_active_slot(current_flood);
current_flood->first_rx_index = (current_flood->ack_mode ? -2 : -1);
current_flood->header.protocol_id = PROTOCOL_ID_GLORIA;
current_flood->header.type = 0;
current_flood->header.slot_index = 0;
current_flood->msg_received = current_flood->initiator;
current_flood->last_active_slot = gloria_calculate_last_active_slot(current_flood);
current_flood->rem_retransmissions = current_flood->max_retransmissions;
current_flood->ack_message.protocol_id = PROTOCOL_ID_GLORIA;
......@@ -74,16 +69,19 @@ void gloria_run_flood(gloria_flood_t* flood, void (*callback)())
// calculate the message size; always needed for the initiator; other nodes need it for low power listening
current_flood->header_size = (current_flood->ack_mode ? GLORIA_HEADER_LENGTH : GLORIA_HEADER_LENGTH_MIN);
if (current_flood->header.sync) {
current_flood->header_size += GLORIA_TIMESTAMP_LENGTH;
}
// calculate the message size for the initiator, initialize markers
if (current_flood->initial) {
if (current_flood->initiator) {
current_flood->received_marker = flood->marker;
current_flood->reconstructed_marker = flood->marker;
// add timestamp for sync floods
if (current_flood->header.sync) {
uint64_t new_timestamp = current_flood->received_marker / GLORIA_SCHEDULE_GRANULARITY;
memcpy(current_flood->payload + current_flood->payload_size, (uint8_t*) &new_timestamp, GLORIA_TIMESTAMP_LENGTH);
memcpy(current_flood->header.timestamp, (uint8_t*)&new_timestamp, GLORIA_TIMESTAMP_LENGTH);
}
}
else {
......@@ -98,7 +96,7 @@ void gloria_run_flood(gloria_flood_t* flood, void (*callback)())
slot_time = gloria_calculate_slot_time(current_flood->modulation, current_flood->ack_mode, 1, GLORIA_ACK_LENGTH);
}
else {
slot_time = gloria_calculate_slot_time(current_flood->modulation, current_flood->ack_mode, 0, current_flood->payload_size + current_flood->header_size + current_flood->header.sync * GLORIA_TIMESTAMP_LENGTH);
slot_time = gloria_calculate_slot_time(current_flood->modulation, current_flood->ack_mode, 0, current_flood->payload_size + current_flood->header_size);
}
if (slot_time < rx2rx_trans + gloria_calculate_rx_timeout(current_flood)) {
......@@ -120,7 +118,7 @@ void gloria_run_flood(gloria_flood_t* flood, void (*callback)())
// initialize message header
if (current_flood->ack_mode) {
current_flood->header.src = (current_flood->initial ? current_flood->node_id : 0);
current_flood->header.src = (current_flood->initiator ? current_flood->node_id : 0);
}
// initialize error flags
......@@ -128,19 +126,13 @@ void gloria_run_flood(gloria_flood_t* flood, void (*callback)())
current_flood->crc_timeout = false;
// set radio config
radio_set_config_tx(current_flood->modulation, current_flood->band, current_flood->power, -1, -1, -1, false, true);
radio_set_config_rx(current_flood->modulation, current_flood->band, -1, -1, -1, 0, false, 0, true, false);
uint8_t max_packet_len = current_flood->payload_size + current_flood->header_size;
radio_set_config(current_flood->modulation, current_flood->band, current_flood->power, max_packet_len);
gloria_process_slot();
}
void gloria_update()
{
//gloria_print_flood_periodic();
}
void gloria_process_slot()
{
if (current_flood->stop) {
......@@ -211,14 +203,14 @@ static void gloria_rx_callback(uint8_t* payload, uint8_t size)
static void gloria_process_rx(uint8_t* payload, uint8_t size)
{
gloria_header_t* header = (gloria_header_t*) payload;
gloria_header_t* header = (gloria_header_t*)payload;
if (!current_flood->msg_received) {
// the size of the actual payload is the message size minus the header length and for sync floods minus the timestamp length
current_flood->payload_size = size - current_flood->header_size - current_flood->header.sync * GLORIA_TIMESTAMP_LENGTH;
current_flood->payload_size = MIN(current_flood->payload_size, size - current_flood->header_size);
current_flood->msg_received = true;
memcpy(current_flood->payload, payload + current_flood->header_size, size - current_flood->header_size);
memcpy(current_flood->payload, payload + current_flood->header_size, current_flood->payload_size);
current_flood->header.slot_index = header->slot_index;
gloria_reconstruct_flood_marker(current_flood);
......
/*
* Copyright (c) 2018 - 2021, ETH Zurich, Computer Engineering Group (TEC)
* Copyright (c) 2018 - 2022, ETH Zurich, Computer Engineering Group (TEC)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -47,7 +47,7 @@
#include "protocol/gloria/gloria_interface.h"
void gloria_run_flood(gloria_flood_t* flood, void (*callback)());
void gloria_update();
void gloria_run_flood(gloria_flood_t* flood, gloria_flood_cb_t callback);
#endif /* PROTOCOL_GLORIA_GLORIA_H_ */
/*
* Copyright (c) 2018 - 2021, ETH Zurich, Computer Engineering Group (TEC)
* Copyright (c) 2018 - 2022, ETH Zurich, Computer Engineering Group (TEC)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -28,94 +28,92 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* THIS FILE HAS BEEN AUTOGENERATED BY FLORA-TOOLS */
#include "flora_lib.h"
const uint8_t gloria_modulations[] = {3,5,7,9};
const int8_t gloria_powers[] = {0,10,22}; // dBm
const uint8_t gloria_default_power_levels[] = {0,0,0,0,0,0,0,0,2,2}; // see radio_powers
const uint8_t gloria_default_retransmissions[] = {3,3,3,3,3,3,3,3,3,3,3};
const uint8_t gloria_default_acks[] = {3,3,3,3,3,3,3,3,3,3,3};
const uint8_t gloria_default_data_slots[] = {4,4,4,4,8,8,12,12,16,16,16};
const uint8_t gloria_modulations[] = { 3, 5, 7, 9 };
const int8_t gloria_powers[] = { 0, 10, 22 }; // dBm
const uint8_t gloria_default_power_levels[] = { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2 }; // see radio_powers
const uint8_t gloria_default_retransmissions[] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };
const uint8_t gloria_default_acks[] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };
const uint8_t gloria_default_data_slots[] = { 4, 4, 4, 4, 8, 8, 12, 12, 16, 16, 16 };
const gloria_timings_t gloria_timings[] = {
{ // 0 (SF12)
.slotOverhead = 4179556, // 522.444 ms
.slotAckOverhead = 4965988, // 620.749 ms
.floodInitOverhead = 795938, // 99.492 ms
.rxOffset = 786432, // 98.304 ms
.txSync = 6078848, // 759.856 ms (updated 20200812)
.slotOverhead = 4179556, // 522.444 ms
.slotAckOverhead = 4965988, // 620.749 ms
.floodInitOverhead = 795938, // 99.492 ms
.rxOffset = 786432, // 98.304 ms
.txSync = 6078848, // 759.856 ms (updated 20200812)
},
{ // 1 (SF11)
.slotOverhead = 2132075, // 266.509 ms
.slotAckOverhead = 2525291, // 315.661 ms
.floodInitOverhead = 402722, // 50.340 ms
.rxOffset = 393216, // 49.152 ms
.txSync = 3032500, // 379.063 ms (updated 20200812)
.slotOverhead = 2132075, // 266.509 ms
.slotAckOverhead = 2525291, // 315.661 ms
.floodInitOverhead = 402722, // 50.340 ms
.rxOffset = 393216, // 49.152 ms
.txSync = 3032500, // 379.063 ms (updated 20200812)
},
{ // 2 (SF10)
.slotOverhead = 1050062, // 131.258 ms
.slotAckOverhead = 1246670, // 155.834 ms
.floodInitOverhead = 206114, // 25.764 ms
.rxOffset = 196608, // 24.576 ms
.txSync = 1513412, // 189.177 ms (updated 20200812)
.slotOverhead = 1050062, // 131.258 ms
.slotAckOverhead = 1246670, // 155.834 ms
.floodInitOverhead = 206114, // 25.764 ms
.rxOffset = 196608, // 24.576 ms
.txSync = 1513412, // 189.177 ms (updated 20200812)
},
{ // 3 (SF9)
.slotOverhead = 537151, // 67.144 ms
.slotAckOverhead = 635455, // 79.432 ms
.floodInitOverhead = 107810, // 13.476 ms
.rxOffset = 98304, // 12.288 ms
.txSync = 755928, // 94.491 ms (updated 20200812)
.slotOverhead = 537151, // 67.144 ms
.slotAckOverhead = 635455, // 79.432 ms
.floodInitOverhead = 107810, // 13.476 ms
.rxOffset = 98304, // 12.288 ms
.txSync = 755928, // 94.491 ms (updated 20200812)
},
{ // 4 (SF8)
.slotOverhead = 283375, // 35.422 ms
.slotAckOverhead = 332527, // 41.566 ms
.floodInitOverhead = 58658, // 7.332 ms
.rxOffset = 49152, // 6.144 ms
.txSync = 378216, // 47.277 ms (updated 20200812)
.slotOverhead = 283375, // 35.422 ms
.slotAckOverhead = 332527, // 41.566 ms
.floodInitOverhead = 58658, // 7.332 ms
.rxOffset = 49152, // 6.144 ms
.txSync = 378216, // 47.277 ms (updated 20200812)
},
{ // 5 (SF7)
.slotOverhead = 153639, // 19.205 ms
.slotAckOverhead = 178215, // 22.277 ms
.floodInitOverhead = 34082, // 4.260 ms
.rxOffset = 24576, // 3.072 ms
.txSync = 189864, // 23.733 ms (updated 20200812)
.slotOverhead = 153639, // 19.205 ms
.slotAckOverhead = 178215, // 22.277 ms
.floodInitOverhead = 34082, // 4.260 ms
.rxOffset = 24576, // 3.072 ms
.txSync = 189864, // 23.733 ms (updated 20200812)
},
{ // 6 (SF6)
.slotOverhead = 79827, // 9.978 ms
.slotAckOverhead = 102827, // 12.853 ms
.floodInitOverhead = 32507, // 4.063 ms
.rxOffset = 23001, // 2.875 ms
.txSync = 112356, // 14.045 ms (updated 20200812)
.slotOverhead = 79827, // 9.978 ms
.slotAckOverhead = 102827, // 12.853 ms
.floodInitOverhead = 32507, // 4.063 ms
.rxOffset = 23001, // 2.875 ms
.txSync = 112356, // 14.045 ms (updated 20200812)
},
{ // 7 (SF5)
.slotOverhead = 50171, // 6.271 ms
.slotAckOverhead = 61672, // 7.709 ms
.floodInitOverhead = 21007, // 2.626 ms
.rxOffset = 11500, // 1.438 ms
.txSync = 57316, // 7.165 ms (updated 20200812)
.slotOverhead = 50171, // 6.271 ms
.slotAckOverhead = 61672, // 7.709 ms
.floodInitOverhead = 21007, // 2.626 ms
.rxOffset = 11500, // 1.438 ms
.txSync = 57316, // 7.165 ms (updated 20200812)
},
{ // 8 (FSK 125k)
.slotOverhead = 28000, // 3.5 ms (adapted by kelmicha)
.slotAckOverhead = 28000, // 3.5 ms (adapted by kelmicha)
.floodInitOverhead = 18000, // 2.25 ms
.rxOffset = 4096, // 512.000 us
.txSync = 4137, // 517.125 us (updated 20200812)
.slotOverhead = 28000, // 3.5 ms
.slotAckOverhead = 28000, // 3.5 ms
.floodInitOverhead = 18000, // 2.25 ms
.rxOffset = 4096, // 512.000 us
.txSync = 4137, // 517.125 us (updated 20200812)
},
{ // 9 (FSK 200k)
.slotOverhead = 26400, // 3.3 ms (adapted by kelmicha)
.slotAckOverhead = 26400, // 3.3 ms (adapted by kelmicha)
.floodInitOverhead = 18000, // 2.25 ms
.rxOffset = 2560, // 320.000 us
// .txSync = 3206, // 400.75 us (adapted by kelmicha)
.txSync = 3034, // 379.25 us (updated 20200812)
.slotOverhead = 26400, // 3.3 ms
.slotAckOverhead = 26400, // 3.3 ms
.floodInitOverhead = 18000, // 2.25 ms
.rxOffset = 2560, // 320.000 us
// .txSync = 3206, // 400.75 us
.txSync = 3034, // 379.25 us (updated 20200812)
},
{ // 10 (FSK 250k)
.slotOverhead = 14000, // 1.75 ms
.slotAckOverhead = 14000, // 1.75 ms
.floodInitOverhead = 18000, // 2.25 ms
.rxOffset = 2560, // 320.000 us (copy from 9)
.txSync = 3140, // 392.5 us (updated 20200814)
.slotOverhead = 14000, // 1.75 ms
.slotAckOverhead = 14000, // 1.75 ms
.floodInitOverhead = 18000, // 2.25 ms
.rxOffset = 2560, // 320.000 us (copy from 9)
.txSync = 3140, // 392.5 us (updated 20200814)
},
};
/*
* Copyright (c) 2018 - 2021, ETH Zurich, Computer Engineering Group (TEC)
* Copyright (c) 2018 - 2022, ETH Zurich, Computer Engineering Group (TEC)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -28,16 +28,14 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* THIS FILE HAS BEEN AUTOGENERATED BY FLORA-TOOLS */
#ifndef PROTOCOL_GLORIA_GLORIA_CONSTANTS_H_
#define PROTOCOL_GLORIA_GLORIA_CONSTANTS_H_
#define GLORIA_PHY_MAX_PAYLOAD 255 // max length of the physical layer payload (given by the hardware)
#define GLORIA_HEADER_LENGTH_WITH_TS (4 + GLORIA_TIMESTAMP_LENGTH) // length of the gloria header, with timestamp
#define GLORIA_HEADER_LENGTH 4 // length of the gloria header
#define GLORIA_HEADER_LENGTH_MIN 2 // length of the gloria header without ACK mode
#define GLORIA_MAX_PAYLOAD_LENGTH (GLORIA_PHY_MAX_PAYLOAD - GLORIA_HEADER_LENGTH) // length of the gloria header
#define GLORIA_MAX_PAYLOAD_LENGTH (GLORIA_PHY_MAX_PAYLOAD - GLORIA_HEADER_LENGTH_WITH_TS)
#define GLORIA_ACK_LENGTH 2 // length of the gloria ack message
#define GLORIA_TIMESTAMP_LENGTH 8 // length of the timestamp to send with sync floods
......@@ -59,7 +57,6 @@
#define GLORIA_RX_SETUP 5326 // 665.750 us time needed for the rx radio setup
#define GLORIA_TX_SETUP 10083 // 1.260 ms time needed for the tx radio setup
typedef struct {
uint32_t slotOverhead;
uint32_t slotAckOverhead;
......@@ -69,12 +66,11 @@ typedef struct {
} gloria_timings_t;
extern const gloria_timings_t gloria_timings[];
extern const uint8_t gloria_modulations[];
extern const int8_t gloria_powers[];
extern const uint8_t gloria_default_power_levels[];
extern const uint8_t gloria_default_retransmissions[];
extern const uint8_t gloria_default_acks[];
extern const uint8_t gloria_default_data_slots[];
extern const uint8_t gloria_modulations[];
extern const int8_t gloria_powers[];
extern const uint8_t gloria_default_power_levels[];
extern const uint8_t gloria_default_retransmissions[];
extern const uint8_t gloria_default_acks[];
extern const uint8_t gloria_default_data_slots[];
#endif /* PROTOCOL_GLORIA_GLORIA_CONSTANTS_H_ */
/*
* Copyright (c) 2018 - 2021, ETH Zurich, Computer Engineering Group (TEC)
* Copyright (c) 2018 - 2022, ETH Zurich, Computer Engineering Group (TEC)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -32,22 +32,15 @@
#if GLORIA_ENABLE
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif /* MIN */
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif /* MAX */
/*
* calculate the last active slot (rx or tx) for this flood based on the first rx index
* returns 0 if the node is not the initiator and no msg has been received and lp_listening is false
* returns the max number of slots for low power listening
*/
inline uint8_t gloria_calculate_last_active_slot(gloria_flood_t* flood) {
if (flood->msg_received || flood->initial) {
inline uint8_t gloria_calculate_last_active_slot(gloria_flood_t* flood)
{
if (flood->msg_received || flood->initiator) {
uint8_t las;
switch (flood->ack_mode) {
case 0:
......@@ -85,7 +78,8 @@ inline uint8_t gloria_calculate_last_active_slot(gloria_flood_t* flood) {
* slot_index <= last_active_slot &&
* (!ack_mode || ack_counter < MAX_ACKS)
*/
inline bool gloria_is_not_finished(gloria_flood_t* flood) {
inline bool gloria_is_not_finished(gloria_flood_t* flood)
{
if (flood->header.slot_index <= flood->last_active_slot
&& (!flood->ack_mode || flood->ack_counter < flood->max_acks)) {
return true;
......@@ -102,7 +96,8 @@ inline bool gloria_is_not_finished(gloria_flood_t* flood) {
* remaining retransmissions > 0 &&
* flood was not acked
*/
inline bool gloria_valid_to_send(gloria_flood_t* flood) {
inline bool gloria_valid_to_send(gloria_flood_t* flood)
{
if (flood->msg_received && flood->rem_retransmissions && !flood->acked) {
return true;
}
......@@ -112,7 +107,8 @@ inline bool gloria_valid_to_send(gloria_flood_t* flood) {
}
inline bool gloria_is_ack_slot(gloria_flood_t* flood) {
inline bool gloria_is_ack_slot(gloria_flood_t* flood)
{
return (flood->ack_mode && (flood->header.slot_index % 2));
}
......
/*
* Copyright (c) 2018 - 2021, ETH Zurich, Computer Engineering Group (TEC)
* Copyright (c) 2018 - 2022, ETH Zurich, Computer Engineering Group (TEC)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -31,12 +31,16 @@
#ifndef PROTOCOL_GLORIA_GLORIA_HELPERS_H_
#define PROTOCOL_GLORIA_GLORIA_HELPERS_H_
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif /* MIN */
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif /* MAX */
void gloria_load_id_and_role();
uint8_t gloria_calculate_last_active_slot(gloria_flood_t* flood);
bool gloria_is_not_finished(gloria_flood_t* flood);
bool gloria_valid_to_send(gloria_flood_t* flood);
bool gloria_is_ack_slot(gloria_flood_t* flood);
uint16_t gloria_get_id();
uint8_t gloria_calculate_last_active_slot(gloria_flood_t* flood);
bool gloria_is_not_finished(gloria_flood_t* flood);
bool gloria_valid_to_send(gloria_flood_t* flood);
bool gloria_is_ack_slot(gloria_flood_t* flood);
#endif /* PROTOCOL_GLORIA_GLORIA_HELPERS_H_ */
/*
* Copyright (c) 2018 - 2021, ETH Zurich, Computer Engineering Group (TEC)
* Copyright (c) 2018 - 2022, ETH Zurich, Computer Engineering Group (TEC)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -37,7 +37,6 @@
#define GLORIA_STOP_IND()
#endif /* GLORIA_START_IND */
/* internal state */
static gloria_flood_t flood; // flood struct which (serves as input, state, and output to/from gloria_run_flood)
static uint8_t gloria_payload[GLORIA_INTERFACE_MAX_PAYLOAD_LEN]; // buffer for the message
......@@ -50,16 +49,13 @@ static int8_t internal_power = GLORIA_INTERFACE_POWER; // int
static uint8_t internal_modulation = GLORIA_INTERFACE_MODULATION; // internal state for the radio modulation (can be adapted from the upper layer)
static uint8_t internal_band = GLORIA_INTERFACE_RF_BAND; // internal state for the frequency band (can be adapted from the upper layer)
static bool internal_enable_flood_printing = false; // enable printing of finished (i.e. completely received/transmitted) floods
static bool internal_append_timestamp = GLORIA_INTERFACE_APPEND_TIMESTAMP;
static uint64_t tx_start_timestamp = 0; // an optional user-defined TX start marker
#if GLORIA_INTERFACE_APPEND_TIMESTAMP
static uint8_t last_timestamp[GLORIA_TIMESTAMP_LENGTH]; // last received 64-bit hstimer timestamp
#endif /* GLORIA_INTERFACE_APPEND_TIMESTAMP */
/* variables to store gloria_start arguments */
static uint8_t* arg_payload_ptr = NULL; // pointer to payload of currently ongoing flood
static bool arg_sync_slot; // holds state whether current flood is used to update last_t_ref or not
/* Private Function Prototypes */
static void flood_callback(void);
static void copy_payload(void);
......@@ -68,7 +64,7 @@ static void update_t_ref(void);
/* INTERFACE FUNCTIONS ********************************************************/
void gloria_start(bool is_initiator,
uint8_t *payload,
uint8_t* payload,
uint8_t payload_len,
uint8_t n_tx_max,
uint8_t sync_slot)
......@@ -82,12 +78,12 @@ void gloria_start(bool is_initiator,
return;
}
/* radio must be woken from sleep mode! */
// radio must be woken from sleep mode!
if (radio_wakeup()) {
LOG_WARNING("radio was in sleep mode");
}
/* argument checks */
// argument checks
if (payload_len > GLORIA_INTERFACE_MAX_PAYLOAD_LEN) {
if (is_initiator) {
LOG_WARNING("payload_len passed to gloria_start as initiator exceeds limit! payload will be truncated");
......@@ -99,11 +95,11 @@ void gloria_start(bool is_initiator,
GLORIA_START_IND();
/* store arguments for further use */
// store arguments for further use
arg_payload_ptr = payload;
arg_sync_slot = sync_slot;
/* initialize internal state */
// initialize internal state
flood_running = true; // keep ordering: first internal state variable to update here
flood_completed = false;
lastrun_n_rx_started = 0;
......@@ -116,14 +112,14 @@ void gloria_start(bool is_initiator,
flood.guard_time = 0;
flood.header.protocol_id = PROTOCOL_ID_GLORIA;
flood.header.type = 0;
flood.header.sync = (GLORIA_INTERFACE_APPEND_TIMESTAMP != 0); // no sync flood (i.e. timestamp for absolute sync to initiator is not included in to payload)
flood.header.sync = (internal_append_timestamp != 0); // no sync flood (i.e. timestamp for absolute sync to initiator is not included in to payload)
flood.header.slot_index = 0;
flood.initial = is_initiator;
flood.initiator = is_initiator;
flood.lp_listening = false;
flood.max_retransmissions = n_tx_max;
flood.modulation = internal_modulation;
flood.payload = gloria_payload;
flood.payload_size = 0;
flood.payload_size = payload_len;
flood.power = internal_power;
flood.radio_no_sleep = true;
flood.rem_retransmissions = n_tx_max;
......@@ -168,14 +164,13 @@ void gloria_start(bool is_initiator,
// use current timestamp
flood.marker = ((hs_timer_get_current_timestamp() + (GLORIA_SCHEDULE_GRANULARITY - 1))) / GLORIA_SCHEDULE_GRANULARITY * GLORIA_SCHEDULE_GRANULARITY;
}
flood.payload_size =