42 #include "net/ethernode.h"
53 #include "lib/random.h"
56 #include <sys/select.h>
59 #include "net/ethernode.h"
61 #define BUF ((uip_tcpip_hdr *)&uip_buf[HDR_LEN])
82 static int radio_is_on = 1;
89 ether_set_radio_status(radio_is_on);
95 ethernode_safe_off(
void)
98 ether_set_radio_status(radio_is_on);
122 #define HDR_LEN UIP_LLH_LEN
124 #define ID_BROADCAST 0x80
126 PROCESS(ethernode_process,
"Ethernode");
129 do_send(u8_t type, u8_t dest,
struct hdr *hdr,
int len)
137 hdr->seqno = state.seqno;
141 PRINTF(
"ether_send len %d\n", len);
142 return ether_send((
char *)hdr, len);
156 ether_client_init(port);
159 state.id = random_rand() & 0x7f;
160 }
while(state.id == ID_BROADCAST);
175 return ether_client_poll();
179 ethernode_read(
void *buf,
unsigned short bufsize)
183 struct hdr *hdr = (
struct hdr *)tmpbuf;
185 len = ether_client_read(tmpbuf,
sizeof(tmpbuf));
190 if(radio_is_on == 0) {
198 if(hdr->dest == state.id ||
199 hdr->dest == ID_BROADCAST) {
200 memcpy(buf, tmpbuf + HDR_LEN, bufsize);
201 return len - HDR_LEN;
205 printf(
"<%d>: Received ack packet from %d\n", state.id, hdr->src);
208 printf(
"<%d>: Received unknown packet type %d from %d\n", state.id, hdr->type, hdr->src);
231 static char tmpbuf[2048];
232 struct hdr *hdr = (
struct hdr *)tmpbuf;
237 PRINTF((
"Ethernode_send: too large uip_len %d\n",
uip_len));
241 memcpy(&tmpbuf[HDR_LEN], &uip_buf[HDR_LEN],
uip_len);
246 tv.tv_usec = (random_rand() % 1000);
249 do_send(TYPE_DATA, dest, hdr, len);
254 static char tmpbuf[2048];
255 static struct hdr *hdr = (
struct hdr *)tmpbuf;
259 prepare(
const void *buf,
unsigned short len)
261 memcpy(&tmpbuf[HDR_LEN], buf, len);
269 transmit(
unsigned short len)
271 do_send(TYPE_DATA, dest, hdr, len + HDR_LEN);
276 send(
const void *payload,
unsigned short payload_len)
278 prepare(payload, payload_len);
279 return transmit(payload_len);
298 NETSTACK_RDC.input();