44 #include "sys/clock.h"
46 #include "sys/cooja_mt.h"
49 #include "lib/random.h"
50 #include "lib/simEnvChange.h"
56 #include "dev/cooja-radio.h"
57 #include "dev/button-sensor.h"
58 #include "dev/pir-sensor.h"
59 #include "dev/vib-sensor.h"
61 #include "sys/node-id.h"
66 #error CLASSNAME is undefined, required by contiki-cooja-main.c
68 #define COOJA__QUOTEME(a,b,c) COOJA_QUOTEME(a,b,c)
69 #define COOJA_QUOTEME(a,b,c) a##b##c
70 #define COOJA_JNI_PATH Java_org_contikios_cooja_corecomm_
71 #define Java_org_contikios_cooja_corecomm_CLASSNAME_init COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_init)
72 #define Java_org_contikios_cooja_corecomm_CLASSNAME_getMemory COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_getMemory)
73 #define Java_org_contikios_cooja_corecomm_CLASSNAME_setMemory COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_setMemory)
74 #define Java_org_contikios_cooja_corecomm_CLASSNAME_tick COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_tick)
75 #define Java_org_contikios_cooja_corecomm_CLASSNAME_setReferenceAddress COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_setReferenceAddress)
81 #include "dev/rs232.h"
85 #include "net/uip-fw-drv.h"
90 {
UIP_FW_NETIF(172,16,0,0, 255,255,0,0, uip_over_mesh_send)};
92 #define UIP_OVER_MESH_CHANNEL 8
93 static uint8_t is_gateway;
101 #include "net/ipv6/uip-ds6.h"
102 #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])
106 SIM_INTERFACE_NAME(moteid_interface);
107 SIM_INTERFACE_NAME(vib_interface);
108 SIM_INTERFACE_NAME(rs232_interface);
109 SIM_INTERFACE_NAME(simlog_interface);
110 SIM_INTERFACE_NAME(beep_interface);
111 SIM_INTERFACE_NAME(radio_interface);
112 SIM_INTERFACE_NAME(button_interface);
113 SIM_INTERFACE_NAME(pir_interface);
114 SIM_INTERFACE_NAME(clock_interface);
115 SIM_INTERFACE_NAME(leds_interface);
116 SIM_INTERFACE_NAME(cfs_interface);
117 SIM_INTERFACES(&vib_interface, &moteid_interface, &rs232_interface, &simlog_interface, &beep_interface, &radio_interface, &button_interface, &pir_interface, &clock_interface, &leds_interface, &cfs_interface);
123 SENSORS(&button_sensor, &pir_sensor, &vib_sensor);
134 static struct cooja_mt_thread rtimer_thread;
135 static struct cooja_mt_thread process_run_thread;
137 #define MIN(a, b) ( (a)<(b) ? (a) : (b) )
145 printf(
"%d.%d: making myself the IP network gateway.\n\n",
147 printf(
"IPv4 address of the gateway: %d.%d.%d.%d\n\n",
150 uip_over_mesh_make_announced_gateway();
157 print_processes(
struct process *
const processes[])
161 while(*processes !=
NULL) {
162 printf(
" '%s'", (*processes)->name);
169 rtimer_thread_loop(
void *data)
186 memset(&addr, 0,
sizeof(linkaddr_t));
188 for(i = 0; i <
sizeof(
uip_lladdr.addr); i += 2) {
189 addr.u8[i + 1] = node_id & 0xff;
190 addr.u8[i + 0] = node_id >> 8;
193 addr.u8[0] = node_id & 0xff;
194 addr.u8[1] = node_id >> 8;
197 printf(
"Rime started with address ");
198 for(i = 0; i <
sizeof(addr.u8) - 1; i++) {
199 printf(
"%d.", addr.u8[i]);
201 printf(
"%d\n", addr.u8[i]);
220 printf(CONTIKI_VERSION_STRING
" started. ");
222 printf(
"Node id is set to %u.\n", node_id);
224 printf(
"Node id is not set.\n");
234 memset(longaddr, 0,
sizeof(longaddr));
236 printf(
"MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
237 longaddr[0], longaddr[1], longaddr[2], longaddr[3],
238 longaddr[4], longaddr[5], longaddr[6], longaddr[7]);
245 printf(
"%s/%s/%s, channel check rate %lu Hz\n",
246 NETSTACK_NETWORK.name, NETSTACK_MAC.name, NETSTACK_RDC.name,
247 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
248 NETSTACK_RDC.channel_check_interval()));
253 uip_ipaddr_t hostaddr, netmask;
259 slip_set_input_callback(set_gateway);
269 uip_over_mesh_set_net(&hostaddr, &netmask);
270 uip_over_mesh_set_gateway_netif(&slipif);
272 uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
284 for(i = 0; i <
sizeof(
uip_lladdr.addr); i += 2) {
285 addr[i + 1] = node_id & 0xff;
286 addr[i + 0] = node_id >> 8;
293 printf(
"Tentative link-local IPv6 address ");
297 lladdr = uip_ds6_get_link_local(-1);
298 for(i = 0; i < 7; ++i) {
299 printf(
"%02x%02x:", lladdr->ipaddr.u8[i * 2],
300 lladdr->ipaddr.u8[i * 2 + 1]);
302 printf(
"%02x%02x\n", lladdr->ipaddr.u8[14],
303 lladdr->ipaddr.u8[15]);
311 uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
312 printf(
"Tentative global IPv6 address ");
313 for(i = 0; i < 7; ++i) {
315 ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
318 ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
327 print_processes(autostart_processes);
328 autostart_start(autostart_processes);
332 process_run_thread_loop(
void *data)
335 simProcessRunValue = 1;
343 while(simProcessRunValue-- > 0) {
349 if(simDontFallAsleep) {
351 simProcessRunValue = 1;
368 JNIEXPORT
void JNICALL
372 cooja_mt_start(&rtimer_thread, &rtimer_thread_loop,
NULL);
373 cooja_mt_start(&process_run_thread, &process_run_thread_loop,
NULL);
390 JNIEXPORT
void JNICALL
393 (*env)->SetByteArrayRegion(
398 (jbyte *) (((
long)rel_addr) + referenceVar)
415 JNIEXPORT
void JNICALL
418 jbyte *mem = (*env)->GetByteArrayElements(env, mem_arr, 0);
420 (
char*) (((
long)rel_addr) + referenceVar),
423 (*env)->ReleaseByteArrayElements(env, mem_arr, mem, 0);
443 JNIEXPORT
void JNICALL
446 clock_time_t nextEtimer;
447 rtimer_clock_t nextRtimer;
449 simProcessRunValue = 0;
452 doActionsBeforeTick();
461 cooja_mt_exec(&rtimer_thread);
463 if(simProcessRunValue == 0) {
466 cooja_mt_exec(&process_run_thread);
470 doActionsAfterTick();
474 if(!simEtimerPending) {
480 nextRtimer = rtimer_arch_next() - (rtimer_clock_t) simCurrentTime;
482 simNextExpirationTime = MIN(nextEtimer, nextRtimer);
484 simNextExpirationTime = nextEtimer;
485 }
else if (rtimer_arch_pending()) {
486 simNextExpirationTime = nextRtimer;
497 JNIEXPORT
void JNICALL
500 referenceVar = (((long)&referenceVar) - ((long)addr));