45 #include "sys/clock.h"
47 #include "sys/cooja_mt.h"
50 #include "lib/random.h"
51 #include "lib/simEnvChange.h"
58 #include "dev/cooja-radio.h"
59 #include "dev/button-sensor.h"
60 #include "dev/pir-sensor.h"
61 #include "dev/vib-sensor.h"
63 #include "sys/node-id.h"
68 #error CLASSNAME is undefined, required by contiki-cooja-main.c
70 #define COOJA__QUOTEME(a,b,c) COOJA_QUOTEME(a,b,c)
71 #define COOJA_QUOTEME(a,b,c) a##b##c
72 #define COOJA_JNI_PATH Java_org_contikios_cooja_corecomm_
73 #define Java_org_contikios_cooja_corecomm_CLASSNAME_init COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_init)
74 #define Java_org_contikios_cooja_corecomm_CLASSNAME_getMemory COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_getMemory)
75 #define Java_org_contikios_cooja_corecomm_CLASSNAME_setMemory COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_setMemory)
76 #define Java_org_contikios_cooja_corecomm_CLASSNAME_tick COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_tick)
77 #define Java_org_contikios_cooja_corecomm_CLASSNAME_setReferenceAddress COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_setReferenceAddress)
79 #ifndef NETSTACK_CONF_WITH_IPV4
80 #define NETSTACK_CONF_WITH_IPV4 0
82 #if NETSTACK_CONF_WITH_IPV4
83 #include "dev/rs232.h"
87 #include "net/uip-fw-drv.h"
92 {
UIP_FW_NETIF(172,16,0,0, 255,255,0,0, uip_over_mesh_send)};
94 #define UIP_OVER_MESH_CHANNEL 8
95 static uint8_t is_gateway;
98 #ifndef NETSTACK_CONF_WITH_IPV6
99 #define NETSTACK_CONF_WITH_IPV6 0
101 #if NETSTACK_CONF_WITH_IPV6
104 #define PRINT6ADDR(addr) printf("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
108 SIM_INTERFACE_NAME(moteid_interface);
109 SIM_INTERFACE_NAME(vib_interface);
110 SIM_INTERFACE_NAME(rs232_interface);
111 SIM_INTERFACE_NAME(simlog_interface);
112 SIM_INTERFACE_NAME(beep_interface);
113 SIM_INTERFACE_NAME(radio_interface);
114 SIM_INTERFACE_NAME(button_interface);
115 SIM_INTERFACE_NAME(pir_interface);
116 SIM_INTERFACE_NAME(clock_interface);
117 SIM_INTERFACE_NAME(leds_interface);
118 SIM_INTERFACE_NAME(cfs_interface);
119 SIM_INTERFACE_NAME(eeprom_interface);
120 SIM_INTERFACES(&vib_interface, &moteid_interface, &rs232_interface, &simlog_interface, &beep_interface, &radio_interface, &button_interface, &pir_interface, &clock_interface, &leds_interface, &cfs_interface, &eeprom_interface);
126 SENSORS(&button_sensor, &pir_sensor, &vib_sensor);
137 static struct cooja_mt_thread rtimer_thread;
138 static struct cooja_mt_thread process_run_thread;
141 #if NETSTACK_CONF_WITH_IPV4
146 printf(
"%d.%d: making myself the IP network gateway.\n\n",
148 printf(
"IPv4 address of the gateway: %d.%d.%d.%d\n\n",
151 uip_over_mesh_make_announced_gateway();
158 print_processes(
struct process *
const processes[])
162 while(*processes !=
NULL) {
163 printf(
" '%s'", (*processes)->name);
170 rtimer_thread_loop(
void *data)
187 memset(&addr, 0,
sizeof(linkaddr_t));
188 #if NETSTACK_CONF_WITH_IPV6
189 for(i = 0; i <
sizeof(
uip_lladdr.addr); i += 2) {
190 addr.u8[i + 1] = node_id & 0xff;
191 addr.u8[i + 0] = node_id >> 8;
194 addr.u8[0] = node_id & 0xff;
195 addr.u8[1] = node_id >> 8;
198 printf(
"Rime started with address ");
199 for(i = 0; i <
sizeof(addr.u8) - 1; i++) {
200 printf(
"%d.", addr.u8[i]);
202 printf(
"%d\n", addr.u8[i]);
221 printf(CONTIKI_VERSION_STRING
" started. ");
223 printf(
"Node id is set to %u.\n", node_id);
225 printf(
"Node id is not set.\n");
232 memset(longaddr, 0,
sizeof(longaddr));
234 printf(
"MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
235 longaddr[0], longaddr[1], longaddr[2], longaddr[3],
236 longaddr[4], longaddr[5], longaddr[6], longaddr[7]);
243 printf(
"%s/%s/%s, channel check rate %lu Hz\n",
244 NETSTACK_NETWORK.name, NETSTACK_MAC.name, NETSTACK_RDC.name,
245 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
246 NETSTACK_RDC.channel_check_interval()));
248 #if NETSTACK_CONF_WITH_IPV4
251 uip_ipaddr_t hostaddr, netmask;
267 uip_over_mesh_set_net(&hostaddr, &netmask);
268 uip_over_mesh_set_gateway_netif(&slipif);
270 uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
277 #if NETSTACK_CONF_WITH_IPV6
282 for(i = 0; i <
sizeof(
uip_lladdr.addr); i += 2) {
283 addr[i + 1] = node_id & 0xff;
284 addr[i + 0] = node_id >> 8;
291 printf(
"Tentative link-local IPv6 address ");
295 lladdr = uip_ds6_get_link_local(-1);
296 for(i = 0; i < 7; ++i) {
297 printf(
"%02x%02x:", lladdr->ipaddr.u8[i * 2],
298 lladdr->ipaddr.u8[i * 2 + 1]);
300 printf(
"%02x%02x\n", lladdr->ipaddr.u8[14],
301 lladdr->ipaddr.u8[15]);
307 uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
310 printf(
"Tentative global IPv6 address ");
311 for(i = 0; i < 7; ++i) {
313 ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
316 ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
328 print_processes(autostart_processes);
329 autostart_start(autostart_processes);
333 process_run_thread_loop(
void *data)
336 simProcessRunValue = 1;
344 while(simProcessRunValue-- > 0) {
350 if(simDontFallAsleep) {
352 simProcessRunValue = 1;
371 JNIEXPORT
void JNICALL
375 cooja_mt_start(&rtimer_thread, &rtimer_thread_loop,
NULL);
376 cooja_mt_start(&process_run_thread, &process_run_thread_loop,
NULL);
396 JNIEXPORT
void JNICALL
399 (*env)->SetByteArrayRegion(
404 (jbyte *) (((
long)rel_addr) + referenceVar)
423 JNIEXPORT
void JNICALL
426 jbyte *mem = (*env)->GetByteArrayElements(env, mem_arr, 0);
427 memcpy((
char*) (((
long)rel_addr) + referenceVar),
430 (*env)->ReleaseByteArrayElements(env, mem_arr, mem, 0);
452 JNIEXPORT
void JNICALL
455 clock_time_t nextEtimer;
456 rtimer_clock_t nextRtimer;
458 simProcessRunValue = 0;
461 doActionsBeforeTick();
470 cooja_mt_exec(&rtimer_thread);
472 if(simProcessRunValue == 0) {
475 cooja_mt_exec(&process_run_thread);
479 doActionsAfterTick();
483 if(!simEtimerPending) {
489 nextRtimer = rtimer_arch_next() - (rtimer_clock_t) simCurrentTime;
491 simNextExpirationTime = MIN(nextEtimer, nextRtimer);
493 simNextExpirationTime = nextEtimer;
494 }
else if(rtimer_arch_pending()) {
495 simNextExpirationTime = nextRtimer;
508 JNIEXPORT
void JNICALL
511 referenceVar = (((long)&referenceVar) - ((long)addr));
JNIEXPORT void JNICALL Java_org_contikios_cooja_corecomm_CLASSNAME_getMemory(JNIEnv *env, jobject obj, jint rel_addr, jint length, jbyteArray mem_arr)
Get a segment from the process memory.
#define uip_sethostaddr(addr)
Set the IP address of this host.
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
JNIEXPORT void JNICALL Java_org_contikios_cooja_corecomm_CLASSNAME_setMemory(JNIEnv *env, jobject obj, jint rel_addr, jint length, jbyteArray mem_arr)
Replace a segment of the process memory with given byte array.
#define uip_ipaddr(addr, addr0, addr1, addr2, addr3)
Construct an IP address from four bytes.
JNIEXPORT void JNICALL Java_org_contikios_cooja_corecomm_CLASSNAME_init(JNIEnv *env, jobject obj)
Initialize a mote by starting processes etc.
clock_time_t etimer_next_expiration_time(void)
Get next event timer expiration time.
static uip_ds6_addr_t * addr
Pointer to a router list entry.
uint8_t slip_send(void)
Send an IP packet from the uIP buffer with SLIP.
Header file for IPv6-related data structures.
void etimer_request_poll(void)
Make the event timer aware that the clock has changed.
int etimer_pending(void)
Check if there are any non-expired event timers.
Default definitions of C compiler quirk work-arounds.
uip_ipaddr_t ipaddr
The IP address of this interface.
void eeprom_init(void)
Initialize the EEPROM module.
int slip_input_byte(unsigned char c)
Input a SLIP byte.
Header file for tunnelling uIP over Rime mesh
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
int process_run(void)
Run the system once - call poll handlers and process one event.
Unicast address structure.
void uip_fw_init(void)
Initialize the uIP packet forwarding module.
void slip_set_input_callback(void(*c)(void))
Set a function to be called when there is activity on the SLIP interface; used for detecting if a nod...
Header file for the Rime stack
JNIEXPORT void JNICALL Java_org_contikios_cooja_corecomm_CLASSNAME_setReferenceAddress(JNIEnv *env, jobject obj, jint addr)
Set the relative memory address of the reference variable.
#define uip_setnetmask(addr)
Set the netmask.
#define NULL
The null pointer.
#define uip_ipaddr_to_quad(a)
Convert an IP address to four bytes separated by commas.
uIP packet forwarding header file.
void linkaddr_set_node_addr(linkaddr_t *t)
Set the address of the current node.
#define UIP_FW_NETIF(ip1, ip2, ip3, ip4, nm1, nm2, nm3, nm4, outputfunc)
Instantiating macro for a uIP network interface.
#define ADDR_TENTATIVE
Possible states for the an address (RFC 4862)
#define CLOCK_SECOND
A second, measured in system clock time.
void rs232_set_input(int(*f)(unsigned char))
Set an input handler for incoming RS232 data.
#define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7)
Construct an IPv6 address from eight 16-bit words.
Header file for the uIP TCP/IP stack.
void process_start(struct process *p, process_data_t data)
Start a process.
uip_ds6_addr_t * uip_ds6_addr_add(uip_ipaddr_t *ipaddr, unsigned long vlifetime, uint8_t type)
Add a unicast address to the interface.
Header file for module for automatically starting and exiting a list of processes.
Generic serial I/O process header filer.
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
void uip_init(void)
uIP initialization function.
int process_nevents(void)
Number of events waiting to be processed.
void process_init(void)
Initialize the process module.
void ctimer_init(void)
Initialize the callback timer library.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a Rime address.
linkaddr_t linkaddr_node_addr
The Rime address of the node.
Include file for the Contiki low-layer network stack (NETSTACK)
void uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr)
set the last 64 bits of an IP address based on the MAC address
void uip_fw_default(struct uip_fw_netif *netif)
Register a default network interface.
JNIEXPORT void JNICALL Java_org_contikios_cooja_corecomm_CLASSNAME_tick(JNIEnv *env, jobject obj)
Let mote execute one "block" of code (tick mote).
Representation of a uIP network interface.