unicast.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include "net/rime.h"
00048 #include "net/rime/unicast.h"
00049 #include <string.h>
00050
00051 static const struct packetbuf_attrlist attributes[] =
00052 {
00053 UNICAST_ATTRIBUTES
00054 PACKETBUF_ATTR_LAST
00055 };
00056
00057 #define DEBUG 0
00058 #if DEBUG
00059 #include <stdio.h>
00060 #define PRINTF(...) printf(__VA_ARGS__)
00061 #else
00062 #define PRINTF(...)
00063 #endif
00064
00065
00066 static void
00067 recv_from_broadcast(struct broadcast_conn *broadcast, const rimeaddr_t *from)
00068 {
00069 struct unicast_conn *c = (struct unicast_conn *)broadcast;
00070
00071 PRINTF("%d.%d: uc: recv_from_broadcast, receiver %d.%d\n",
00072 rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
00073 packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[0],
00074 packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[1]);
00075 if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &rimeaddr_node_addr)) {
00076 c->u->recv(c, from);
00077 }
00078 }
00079
00080 static void
00081 sent_by_broadcast(struct broadcast_conn *broadcast, int status, int num_tx)
00082 {
00083 struct unicast_conn *c = (struct unicast_conn *)broadcast;
00084
00085 PRINTF("%d.%d: uc: recv_from_broadcast, receiver %d.%d\n",
00086 rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
00087 packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[0],
00088 packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[1]);
00089
00090 if(c->u->sent) {
00091 c->u->sent(c, status, num_tx);
00092 }
00093 }
00094
00095 static const struct broadcast_callbacks uc = {recv_from_broadcast,
00096 sent_by_broadcast};
00097
00098 void
00099 unicast_open(struct unicast_conn *c, uint16_t channel,
00100 const struct unicast_callbacks *u)
00101 {
00102 broadcast_open(&c->c, channel, &uc);
00103 c->u = u;
00104 channel_set_attributes(channel, attributes);
00105 }
00106
00107 void
00108 unicast_close(struct unicast_conn *c)
00109 {
00110 broadcast_close(&c->c);
00111 }
00112
00113 int
00114 unicast_send(struct unicast_conn *c, const rimeaddr_t *receiver)
00115 {
00116 PRINTF("%d.%d: unicast_send to %d.%d\n",
00117 rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
00118 receiver->u8[0], receiver->u8[1]);
00119 packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, receiver);
00120 return broadcast_send(&c->c);
00121 }
00122
00123