45 #include "sys/clock.h"
47 #include "sys/cooja_mt.h"
50 #include "lib/random.h"
51 #include "lib/simEnvChange.h"
57 #include "dev/cooja-radio.h"
58 #include "dev/button-sensor.h"
59 #include "dev/pir-sensor.h"
60 #include "dev/vib-sensor.h"
67 #error CLASSNAME is undefined, required by contiki-cooja-main.c
69 #define COOJA__QUOTEME(a,b,c) COOJA_QUOTEME(a,b,c)
70 #define COOJA_QUOTEME(a,b,c) a##b##c
71 #define COOJA_JNI_PATH Java_se_sics_cooja_corecomm_
72 #define Java_se_sics_cooja_corecomm_CLASSNAME_init COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_init)
73 #define Java_se_sics_cooja_corecomm_CLASSNAME_getMemory COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_getMemory)
74 #define Java_se_sics_cooja_corecomm_CLASSNAME_setMemory COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_setMemory)
75 #define Java_se_sics_cooja_corecomm_CLASSNAME_tick COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_tick)
76 #define Java_se_sics_cooja_corecomm_CLASSNAME_setReferenceAddress COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_setReferenceAddress)
82 #include "dev/rs232.h"
86 #include "net/uip-fw-drv.h"
91 {
UIP_FW_NETIF(172,16,0,0, 255,255,0,0, uip_over_mesh_send)};
93 #define UIP_OVER_MESH_CHANNEL 8
94 static uint8_t is_gateway;
103 #define PRINT6ADDR(addr) printf("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", ((u8_t *)addr)[0], ((u8_t *)addr)[1], ((u8_t *)addr)[2], ((u8_t *)addr)[3], ((u8_t *)addr)[4], ((u8_t *)addr)[5], ((u8_t *)addr)[6], ((u8_t *)addr)[7], ((u8_t *)addr)[8], ((u8_t *)addr)[9], ((u8_t *)addr)[10], ((u8_t *)addr)[11], ((u8_t *)addr)[12], ((u8_t *)addr)[13], ((u8_t *)addr)[14], ((u8_t *)addr)[15])
106 PROCINIT(&etimer_process,&sensors_process);
109 SIM_INTERFACE_NAME(moteid_interface);
110 SIM_INTERFACE_NAME(vib_interface);
111 SIM_INTERFACE_NAME(rs232_interface);
112 SIM_INTERFACE_NAME(simlog_interface);
113 SIM_INTERFACE_NAME(beep_interface);
114 SIM_INTERFACE_NAME(radio_interface);
115 SIM_INTERFACE_NAME(button_interface);
116 SIM_INTERFACE_NAME(pir_interface);
117 SIM_INTERFACE_NAME(clock_interface);
118 SIM_INTERFACE_NAME(leds_interface);
119 SIM_INTERFACE_NAME(cfs_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);
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;
140 #define MIN(a, b) ( (a)<(b) ? (a) : (b) )
148 printf(
"%d.%d: making myself the IP network gateway.\n\n",
150 printf(
"IPv4 address of the gateway: %d.%d.%d.%d\n\n",
153 uip_over_mesh_make_announced_gateway();
160 print_processes(
struct process *
const processes[])
164 while(*processes !=
NULL) {
165 printf(
" '%s'", (*processes)->name);
172 rtimer_thread_loop(
void *data)
195 printf(CONTIKI_VERSION_STRING
" started. ");
197 printf(
"Node id is set to %u.\n", node_id);
199 printf(
"Node id is not set.\n");
209 rimeaddr.u8[0] = node_id & 0xff;
210 rimeaddr.u8[1] = node_id >> 8;
212 printf(
"Rime address: ");
223 printf(
"MAC %s RDC %s NETWORK %s\n", NETSTACK_MAC.name, NETSTACK_RDC.name, NETSTACK_NETWORK.name);
234 slip_set_input_callback(set_gateway);
244 uip_over_mesh_set_net(&hostaddr, &netmask);
245 uip_over_mesh_set_gateway_netif(&slipif);
247 uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
260 addr[i] = node_id & 0xff;
265 printf(
"Tentative link-local IPv6 address ");
268 for(a = 0; a < UIP_DS6_ADDR_NB; a++) {
269 if (uip_ds6_if.addr_list[a].isused) {
270 for(i = 0; i < 7; ++i) {
272 uip_ds6_if.addr_list[a].ipaddr.u8[i * 2],
273 uip_ds6_if.addr_list[a].ipaddr.u8[i * 2 + 1]);
276 uip_ds6_if.addr_list[a].ipaddr.u8[14],
277 uip_ds6_if.addr_list[a].ipaddr.u8[15]);
288 printf(
"Tentative global IPv6 address ");
289 for(i = 0; i < 7; ++i) {
291 ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
294 ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
303 print_processes(autostart_processes);
304 autostart_start(autostart_processes);
308 process_run_thread_loop(
void *data)
311 simProcessRunValue = 1;
319 while(simProcessRunValue-- > 0) {
325 if(simDontFallAsleep) {
327 simProcessRunValue = 1;
344 JNIEXPORT
void JNICALL
348 cooja_mt_start(&rtimer_thread, &rtimer_thread_loop,
NULL);
349 cooja_mt_start(&process_run_thread, &process_run_thread_loop,
NULL);
366 JNIEXPORT
void JNICALL
369 (*env)->SetByteArrayRegion(
374 (jbyte *) (((
long)rel_addr) + referenceVar)
391 JNIEXPORT
void JNICALL
394 jbyte *mem = (*env)->GetByteArrayElements(env, mem_arr, 0);
396 (
char*) (((
long)rel_addr) + referenceVar),
399 (*env)->ReleaseByteArrayElements(env, mem_arr, mem, 0);
419 JNIEXPORT
void JNICALL
422 clock_time_t nextEtimer;
423 rtimer_clock_t nextRtimer;
425 simProcessRunValue = 0;
428 doActionsBeforeTick();
437 cooja_mt_exec(&rtimer_thread);
439 if(simProcessRunValue == 0) {
442 cooja_mt_exec(&process_run_thread);
446 doActionsAfterTick();
450 if(!simEtimerPending) {
456 nextRtimer = rtimer_arch_next() - (rtimer_clock_t) simCurrentTime;
458 simNextExpirationTime = MIN(nextEtimer, nextRtimer);
460 simNextExpirationTime = nextEtimer;
461 }
else if (rtimer_arch_pending()) {
462 simNextExpirationTime = nextRtimer;
473 JNIEXPORT
void JNICALL
476 referenceVar = (((long)&referenceVar) - ((long)addr));