From e4b1771276f9f3f2c3d23f4db2d4e3471ab12dc1 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Tue, 19 Nov 2013 23:45:03 +0100 Subject: [PATCH] added a transceiver independent ignore function --- sys/transceiver/transceiver.c | 39 ++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/sys/transceiver/transceiver.c b/sys/transceiver/transceiver.c index 4374d67d57..6c36de4715 100644 --- a/sys/transceiver/transceiver.c +++ b/sys/transceiver/transceiver.c @@ -129,7 +129,11 @@ static void powerdown(transceiver_type_t t); static void switch_to_rx(transceiver_type_t t); #ifdef DBG_IGNORE -static void ignore_add(transceiver_type_t t, void *address); +static int16_t ignore_add(transceiver_type_t t, void *address); + +#define MAX_IGNORED_ADDR (10) + +radio_address_t ignored_addr[MAX_IGNORED_ADDR]; #endif /*------------------------------------------------------------------------------------*/ @@ -146,6 +150,9 @@ void transceiver_init(transceiver_type_t t) /* Initializing transceiver buffer and data buffer */ memset(transceiver_buffer, 0, TRANSCEIVER_BUFFER_SIZE * sizeof(radio_packet_t)); memset(data_buffer, 0, TRANSCEIVER_BUFFER_SIZE * PAYLOAD_SIZE); +#ifdef DBG_IGNORE + memset(ignored_addr, 0, MAX_IGNORED_ADDR * sizeof(radio_address_t)); +#endif for (i = 0; i < TRANSCEIVER_MAX_REGISTERED; i++) { reg[i].transceivers = TRANSCEIVER_NONE; @@ -304,10 +311,9 @@ void run(void) msg_reply(&m, &m); break; #ifdef DBG_IGNORE - case DBG_IGN: - printf("Transceiver PID: %i (%p), rx_buffer_next: %u\n", transceiver_pid, &transceiver_pid, rx_buffer_next); - ignore_add(cmd->transceivers, cmd->data); + *((int16_t*) cmd->data) = ignore_add(cmd->transceivers, cmd->data); + msg_reply(&m, &m); break; #endif @@ -421,6 +427,15 @@ static void receive_packet(uint16_t type, uint8_t pos) puts("Invalid transceiver type"); return; } +#ifdef DBG_IGNORE + for (uint8_t i = 0; (i < MAX_IGNORED_ADDR) && (ignored_addr[i]); i++) { + DEBUG("check if source (%u) is ignored -> %u\n", trans_p->src, ignored_addr[i]); + if (trans_p->src == ignored_addr[i]) { + DEBUG("ignored packet from %"PRIu16"\n", trans_p->src); + return; + } + } +#endif } /* finally notify waiting upper layers @@ -992,17 +1007,17 @@ static void switch_to_rx(transceiver_type_t t) } #ifdef DBG_IGNORE -static void ignore_add(transceiver_type_t t, void *address) +static int16_t ignore_add(transceiver_type_t t, void *address) { radio_address_t addr = *((radio_address_t *)address); - switch(t) { - case TRANSCEIVER_CC1100: - cc110x_add_ignored(addr); - break; - - default: - break; + for (uint8_t i = 0; i < MAX_IGNORED_ADDR; i++) { + if (ignored_addr[i] == 0) { + ignored_addr[i] = addr; + DEBUG("addr %u will be ignored (%u)\n", addr, i); + return i; + } } + return -1; } #endif