From d87d827d8881772903c1ebf470c06305dc6ad340 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Sat, 23 Nov 2013 14:03:26 +0100 Subject: [PATCH] transceiver return signed values for sending negative values indicate an error value --- cpu/native/include/nativenet.h | 4 ++-- cpu/native/net/interface.c | 8 ++------ drivers/at86rf231/at86rf231_tx.c | 1 + drivers/cc110x_ng/cc110x-tx.c | 4 ++-- drivers/cc110x_ng/include/cc110x_ng.h | 2 +- sys/transceiver/transceiver.c | 20 ++++++-------------- 6 files changed, 14 insertions(+), 25 deletions(-) diff --git a/cpu/native/include/nativenet.h b/cpu/native/include/nativenet.h index 25c75f6e4e..62e00bfcce 100644 --- a/cpu/native/include/nativenet.h +++ b/cpu/native/include/nativenet.h @@ -59,9 +59,9 @@ void nativenet_set_monitor(uint8_t mode); * Send a packet * * @param packet a radio packet - * @return 1 on success, 0 otherwise + * @return -1 if the operation failed, 0 otherwise */ -uint8_t nativenet_send(radio_packet_t *packet); +int8_t nativenet_send(radio_packet_t *packet); /** * Set transceiver address diff --git a/cpu/native/net/interface.c b/cpu/native/net/interface.c index a3af8a49e6..215f16b02f 100644 --- a/cpu/native/net/interface.c +++ b/cpu/native/net/interface.c @@ -107,16 +107,12 @@ radio_address_t nativenet_get_address() return _native_net_addr; } -uint8_t nativenet_send(radio_packet_t *packet) +int8_t nativenet_send(radio_packet_t *packet) { packet->src = _native_net_addr; DEBUG("nativenet_send: Sending packet of length %"PRIu16" from %"PRIu16" to %"PRIu16"\n", packet->length, packet->src, packet->dst); - if (send_buf(packet) == -1) { - warnx("nativenet_send: error sending packet"); - return 0; - } - return true; + return send_buf(packet); } void nativenet_switch_to_rx() diff --git a/drivers/at86rf231/at86rf231_tx.c b/drivers/at86rf231/at86rf231_tx.c index 1ca09e8f8e..1bb2231468 100644 --- a/drivers/at86rf231/at86rf231_tx.c +++ b/drivers/at86rf231/at86rf231_tx.c @@ -54,6 +54,7 @@ int16_t at86rf231_send(at86rf231_packet_t *packet) // transmit packet at86rf231_xmit(pkt, packet->length); + return packet->length; } static void at86rf231_xmit(uint8_t *data, uint8_t length) diff --git a/drivers/cc110x_ng/cc110x-tx.c b/drivers/cc110x_ng/cc110x-tx.c index 586654058c..6759db3069 100644 --- a/drivers/cc110x_ng/cc110x-tx.c +++ b/drivers/cc110x_ng/cc110x-tx.c @@ -28,7 +28,7 @@ //#include -uint8_t cc110x_send(cc110x_packet_t *packet) +int8_t cc110x_send(cc110x_packet_t *packet) { volatile uint32_t abort_count; uint8_t size; @@ -95,6 +95,6 @@ uint8_t cc110x_send(cc110x_packet_t *packet) /* Go to mode after TX (CONST_RX -> RX, WOR -> WOR) */ cc110x_switch_to_rx(); - return true; + return size; } diff --git a/drivers/cc110x_ng/include/cc110x_ng.h b/drivers/cc110x_ng/include/cc110x_ng.h index c3ca907474..a45a6b9cce 100644 --- a/drivers/cc110x_ng/include/cc110x_ng.h +++ b/drivers/cc110x_ng/include/cc110x_ng.h @@ -116,7 +116,7 @@ void cc110x_init(int transceiver_pid); void cc110x_rx_handler(void); -uint8_t cc110x_send(cc110x_packet_t *pkt); +int8_t cc110x_send(cc110x_packet_t *pkt); uint8_t cc110x_get_buffer_pos(void); diff --git a/sys/transceiver/transceiver.c b/sys/transceiver/transceiver.c index 6c36de4715..1131710db7 100644 --- a/sys/transceiver/transceiver.c +++ b/sys/transceiver/transceiver.c @@ -116,7 +116,7 @@ static void receive_nativenet_packet(radio_packet_t *trans_p); #ifdef MODULE_AT86RF231 void receive_at86rf231_packet(radio_packet_t *trans_p); #endif -static uint8_t send_packet(transceiver_type_t t, void *pkt); +static int8_t send_packet(transceiver_type_t t, void *pkt); static int16_t get_channel(transceiver_type_t t); static int16_t set_channel(transceiver_type_t t, void *channel); static int16_t get_address(transceiver_type_t t); @@ -580,14 +580,11 @@ void receive_at86rf231_packet(radio_packet_t *trans_p) { * @param t The transceiver device * @param pkt Generic pointer to the packet * - * @return 1 on success, 0 otherwise + * @return A negative value if operation failed, 0 or the number of bytes sent otherwise. */ -static uint8_t send_packet(transceiver_type_t t, void *pkt) +static int8_t send_packet(transceiver_type_t t, void *pkt) { - uint8_t res = 0; -#ifdef MODULE_CC110X - int snd_ret; -#endif + int8_t res = -1; radio_packet_t p = *((radio_packet_t *)pkt); #ifdef MODULE_CC110X_NG @@ -617,13 +614,8 @@ static uint8_t send_packet(transceiver_type_t t, void *pkt) #elif MODULE_CC110X memcpy(cc1100_pkt, p.data, p.length); - if ((snd_ret = cc1100_send_csmaca(p.dst, 4, 0, (char *) cc1100_pkt, p.length)) < 0) { - DEBUG("transceiver: snd_ret (%u) = %i\n", p.length, snd_ret); - res = 0; - } - else { - res = 1; - } + res = cc1100_send_csmaca(p.dst, 4, 0, (char *) cc1100_pkt, p.length); + DEBUG("transceiver: snd_ret (%u) = %i\n", p.length, snd_ret); #else puts("Unknown transceiver"); #endif