Skip to content

Commit

Permalink
minor optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Reto Da Forno committed Mar 8, 2016
1 parent 9e53378 commit d1cc023
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 86 deletions.
10 changes: 4 additions & 6 deletions apps/glossy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
CONTIKI = ../..
CONTIKI_PROJECT = glossy

# specify the target platform (or pass this parameter by command line)
#TARGET = cc430
SRCS = ${shell find . -maxdepth 1 -type f -name "*.[c]" -printf "%f "}

SRCS = ${shell find . -type f -name "*.[c]" -printf "%f "}
#$(info hello world = $(SRCS))
ifndef TARGET
TARGET=olimex
endif

include $(CONTIKI)/Makefile.include

all: $(CONTIKI_PROJECT)

flocklab:
# embed image
@base64 $(CONTIKI_PROJECT).exe > $(CONTIKI_PROJECT).$(TARGET).b64
Expand Down
33 changes: 27 additions & 6 deletions apps/glossy/glossy-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ static struct pt glossy_pt; /* glossy protothread */
PT_YIELD(&glossy_pt);\
TASK_ACTIVE;\
}
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif /* MAX */
/*---------------------------------------------------------------------------*/
PT_THREAD(glossy_thread(rtimer_t *rt))
{
Expand All @@ -73,9 +76,12 @@ PT_THREAD(glossy_thread(rtimer_t *rt))
static rtimer_clock_t t_ref = 0,
t_ref_last = 0,
t_start = 0;
static int32_t avg_rssi = 0;
static uint16_t rssi_cnt = 0;

/* note: all statements above PT_BEGIN() will be executed each time the
* protothread is scheduled */
SVS_DISABLE;

PT_BEGIN(&glossy_pt); /* declare variables before this statement! */

Expand All @@ -92,7 +98,13 @@ PT_THREAD(glossy_thread(rtimer_t *rt))
GLOSSY_WITH_RF_CAL);
WAIT_UNTIL(rt->time + GLOSSY_T_SLOT);
glossy_stop();
DEBUG_PRINT_INFO("packet sent");
if(glossy_get_rssi() != 0) {
avg_rssi += glossy_get_rssi();
rssi_cnt++;
}
DEBUG_PRINT_INFO("packet sent, rssi=%ddBm last_pkt_rssi=%ddBm avg=%ddBm",
glossy_get_rssi(), rf1a_get_last_packet_rssi(),
(int16_t)(avg_rssi / MAX(1, rssi_cnt)));

/* SOURCE NODE */
} else {
Expand Down Expand Up @@ -138,6 +150,10 @@ PT_THREAD(glossy_thread(rtimer_t *rt))
sync_state = 1; /* synchronized */
t_guard = GLOSSY_T_GUARD;
snr = glossy_get_snr();
if(snr) {
avg_rssi += snr;
rssi_cnt++;
}

#if (TIME_SCALE == 1) /* only calc drift when TIME_SCALE is not used */
/* drift compensation (calculate drift in clock cycles per second) */
Expand Down Expand Up @@ -171,11 +187,16 @@ PT_THREAD(glossy_thread(rtimer_t *rt))
}
/* print out some stats */
DEBUG_PRINT_INFO("rcv=%u miss=%u boot=%u d=%d per=%u hop=%u "
"m_hop=%u SNR=%ddBm",
pkt_cnt, miss_cnt, bootstrap_cnt,
drift, glossy_get_per(),
glossy_get_relay_cnt_first_rx(), max_hop,
snr);
"m_hop=%u snr=%ddBm avg_snr=%ddBm",
pkt_cnt,
miss_cnt,
bootstrap_cnt,
drift,
glossy_get_per(),
glossy_get_relay_cnt_first_rx(),
max_hop,
snr,
(int16_t)(avg_rssi / MAX(1, rssi_cnt)));
}
}

Expand Down
10 changes: 4 additions & 6 deletions apps/lwb-rapid/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
CONTIKI = ../..
CONTIKI_PROJECT = lwb

# specify the target platform (or pass this parameter by command line)
#TARGET = cc430
SRCS = ${shell find . -maxdepth 1 -type f -name "*.[c]" -printf "%f "}

SRCS = ${shell find . -type f -name "*.[c]" -printf "%f "}
#$(info hello world = $(SRCS))
ifndef TARGET
TARGET=olimex
endif

include $(CONTIKI)/Makefile.include

all: $(CONTIKI_PROJECT)

flocklab:
# embed image
@base64 $(CONTIKI_PROJECT).exe > $(CONTIKI_PROJECT).$(TARGET).b64
Expand Down
9 changes: 4 additions & 5 deletions apps/lwb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
CONTIKI = ../..
CONTIKI_PROJECT = lwb

# specify the target platform (or pass this parameter by command line)
#TARGET = cc430
SRCS = ${shell find . -maxdepth 1 -type f -name "*.[c]" -printf "%f "}

SRCS = ${shell find . -type f -name "*.[c]" -printf "%f "}
ifndef TARGET
TARGET=olimex
endif

include $(CONTIKI)/Makefile.include

all: $(CONTIKI_PROJECT)

flocklab:
# embed image
@base64 $(CONTIKI_PROJECT).exe > $(CONTIKI_PROJECT).$(TARGET).b64
Expand Down
2 changes: 1 addition & 1 deletion apps/lwb/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#define RF_CONF_TX_POWER RF1A_TX_POWER_MAX
#define RF_CONF_TX_CH 10 /* approx. 870 MHz */
#define LWB_CONF_TASK_ACT_PIN FLOCKLAB_LED1
#define DEBUG_PRINT_TASK_ACT_PIN FLOCKLAB_LED2
#define DEBUG_PRINT_TASK_ACT_PIN FLOCKLAB_LED3
#define APP_TASK_ACT_PIN FLOCKLAB_LED3
#else
/* only define a node ID if FlockLAB is not used (FlockLAB automatically
Expand Down
47 changes: 41 additions & 6 deletions core/net/glossy.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
#include <stdlib.h>


/* whether the initiator should retransmit the packet after a certain
* time of no reception */
#ifndef GLOSSY_CONF_RETRANSMISSION_TIMEOUT
#define GLOSSY_CONF_RETRANSMISSION_TIMEOUT 1
#endif /* GLOSSY_CONF_RETRANSMISSION_TIMEOUT */


enum {
GLOSSY_UNKNOWN_INITIATOR = 0
};
Expand Down Expand Up @@ -109,20 +116,53 @@ uint8_t glossy_is_active(void);

/**
* @brief get the number of received packets
* during the last flood
*/
uint8_t glossy_get_n_rx(void);

/**
* @brief get the number of transmitted packets
* @brief get the number of transmitted packets during the last flood
*/
uint8_t glossy_get_n_tx(void);

/**
* @brief get the number of started receptions
* (preamble + sync detection) during the last flood
*/
uint8_t glossy_get_n_rx_started(void);

/**
* @brief get the number of received packets with CRC ok during the last flood
*/
uint8_t glossy_get_n_crc_ok(void);

/**
* @brief get the number of received packets with CRC failed during the last
* flood
*/
uint8_t glossy_get_n_rx_fail(void);

/**
* @brief get the number of received packets with CRC ok, but header validation
* failed during the last flood
*/
uint8_t glossy_get_n_header_fail(void);


/**
* @brief get the signal-to-noise ratio (average RSSI value of all received
* packets of the last flood minus RSSI of the noise floor before the flood)
* @note this function is only returns a value != 0 if at least one packet
* was successfully received in the last slot and the node was not the
* initiator of the flood
*/
int8_t glossy_get_snr(void);

/**
* @brief get the average RSSI value of the last flood
*/
int8_t glossy_get_rssi(void);

/**
* @brief get the length of the payload of the received/transmitted packet
*/
Expand Down Expand Up @@ -155,11 +195,6 @@ uint8_t glossy_get_per(void);
*/
uint32_t glossy_get_n_pkts(void);

/**
* @brief returns 1 if activity was detected during the last flood
*/
uint8_t glossy_activity_detected(void);


#endif /* __GLOSSY_H__ */

Expand Down
Loading

0 comments on commit d1cc023

Please sign in to comment.