fixed nullnet and its examples
This commit is contained in:
parent
3091a9010a
commit
1b2b043f24
@ -33,7 +33,7 @@
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
*/
|
||||
|
||||
#include "net/ip/uip.h"
|
||||
#include "net/ipv6/uip.h"
|
||||
#include "net/ipv6/uip-ds6.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -52,7 +52,7 @@
|
||||
|
||||
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/ip/uip-debug.h"
|
||||
#include "net/ipv6/uip-debug.h"
|
||||
|
||||
#ifdef linux
|
||||
#include <linux/if.h>
|
||||
|
@ -41,7 +41,7 @@
|
||||
#include "contiki.h"
|
||||
#include "net/netstack.h"
|
||||
#include "net/nullnet/nullnet.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h> /* For printf() */
|
||||
|
||||
/* Log configuration */
|
||||
@ -57,6 +57,10 @@
|
||||
static linkaddr_t coordinator_addr = {{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }};
|
||||
#endif /* MAC_CONF_WITH_TSCH */
|
||||
|
||||
uint8_t nullnet_buf[128];
|
||||
uint16_t nullnet_len;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(nullnet_example_process, "NullNet broadcast example");
|
||||
AUTOSTART_PROCESSES(&nullnet_example_process);
|
||||
@ -89,7 +93,11 @@ PROCESS_THREAD(nullnet_example_process, ev, data)
|
||||
LOG_INFO("Sending %u to ", count);
|
||||
LOG_INFO_LLADDR(NULL);
|
||||
LOG_INFO_("\n");
|
||||
nullnet_output(&count, sizeof(count), NULL);
|
||||
|
||||
memcpy(nullnet_buf, &count, sizeof(count));
|
||||
nullnet_len = sizeof(count);
|
||||
|
||||
NETSTACK_NETWORK.output(NULL);
|
||||
count++;
|
||||
etimer_reset(&periodic_timer);
|
||||
}
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "net/netstack.h"
|
||||
#include "net/nullnet/nullnet.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h> /* For printf() */
|
||||
|
||||
/* Log configuration */
|
||||
@ -58,6 +59,9 @@ static linkaddr_t dest_addr = {{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0
|
||||
static linkaddr_t coordinator_addr = {{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }};
|
||||
#endif /* MAC_CONF_WITH_TSCH */
|
||||
|
||||
uint8_t nullnet_buf[128];
|
||||
uint16_t nullnet_len;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(nullnet_example_process, "NullNet unicast example");
|
||||
AUTOSTART_PROCESSES(&nullnet_example_process);
|
||||
@ -91,7 +95,11 @@ PROCESS_THREAD(nullnet_example_process, ev, data)
|
||||
LOG_INFO("Sending %u to ", count);
|
||||
LOG_INFO_LLADDR(&dest_addr);
|
||||
LOG_INFO_("\n");
|
||||
nullnet_output(&count, sizeof(count), &dest_addr);
|
||||
|
||||
memcpy(nullnet_buf, &count, sizeof(count));
|
||||
nullnet_len = sizeof(count);
|
||||
|
||||
NETSTACK_NETWORK.output(&dest_addr);
|
||||
count++;
|
||||
etimer_reset(&periodic_timer);
|
||||
}
|
||||
|
@ -53,6 +53,9 @@
|
||||
#define LOG_MODULE "NullNet"
|
||||
#define LOG_LEVEL LOG_LEVEL_NULLNET
|
||||
|
||||
extern uint8_t *nullnet_buf;
|
||||
extern uint16_t nullnet_len;
|
||||
|
||||
static nullnet_input_callback current_callback = NULL;
|
||||
/*--------------------------------------------------------------------*/
|
||||
static void
|
||||
@ -80,11 +83,11 @@ nullnet_set_input_callback(nullnet_input_callback callback)
|
||||
current_callback = callback;
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
void
|
||||
nullnet_output(const void *data, uint16_t len, const linkaddr_t *dest)
|
||||
static uint8_t
|
||||
output(const linkaddr_t *dest)
|
||||
{
|
||||
packetbuf_clear();
|
||||
packetbuf_copyfrom(data, len);
|
||||
packetbuf_copyfrom(nullnet_buf, nullnet_len);
|
||||
if(dest != NULL) {
|
||||
packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, dest);
|
||||
} else {
|
||||
@ -95,12 +98,14 @@ nullnet_output(const void *data, uint16_t len, const linkaddr_t *dest)
|
||||
LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
|
||||
LOG_INFO_("\n");
|
||||
NETSTACK_MAC.send(NULL, NULL);
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
const struct network_driver nullnet_driver = {
|
||||
"nullnet",
|
||||
init,
|
||||
input
|
||||
input,
|
||||
output
|
||||
};
|
||||
/*--------------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
@ -65,14 +65,5 @@ typedef void (* nullnet_input_callback)(const void *data, uint16_t len,
|
||||
*/
|
||||
void nullnet_set_input_callback(nullnet_input_callback callback);
|
||||
|
||||
/**
|
||||
* Send data with NullNet
|
||||
*
|
||||
* \param data The payload
|
||||
* \param len The payload len
|
||||
* \param dest The destination link-layer address
|
||||
*/
|
||||
void nullnet_output(const void *data, uint16_t len, const linkaddr_t *dest);
|
||||
|
||||
#endif /* NULLNET_H_ */
|
||||
/** @} */
|
||||
|
Loading…
Reference in New Issue
Block a user