44 #include "sys/clock.h"
46 #include "sys/cooja_mt.h"
49 #include "lib/random.h"
50 #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"
62 #include "sys/node-id.h"
69 #error CLASSNAME is undefined, required by contiki-cooja-main.c
71 #define COOJA__QUOTEME(a,b,c) COOJA_QUOTEME(a,b,c)
72 #define COOJA_QUOTEME(a,b,c) a##b##c
73 #define COOJA_JNI_PATH Java_org_contikios_cooja_corecomm_
74 #define Java_org_contikios_cooja_corecomm_CLASSNAME_init COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_init)
75 #define Java_org_contikios_cooja_corecomm_CLASSNAME_getMemory COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_getMemory)
76 #define Java_org_contikios_cooja_corecomm_CLASSNAME_setMemory COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_setMemory)
77 #define Java_org_contikios_cooja_corecomm_CLASSNAME_tick COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_tick)
78 #define Java_org_contikios_cooja_corecomm_CLASSNAME_setReferenceAddress COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_setReferenceAddress)
82 #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])
85 SIM_INTERFACE_NAME(moteid_interface);
86 SIM_INTERFACE_NAME(vib_interface);
87 SIM_INTERFACE_NAME(rs232_interface);
88 SIM_INTERFACE_NAME(simlog_interface);
89 SIM_INTERFACE_NAME(beep_interface);
90 SIM_INTERFACE_NAME(radio_interface);
91 SIM_INTERFACE_NAME(button_interface);
92 SIM_INTERFACE_NAME(pir_interface);
93 SIM_INTERFACE_NAME(clock_interface);
94 SIM_INTERFACE_NAME(leds_interface);
95 SIM_INTERFACE_NAME(cfs_interface);
96 SIM_INTERFACES(&vib_interface, &moteid_interface, &rs232_interface, &simlog_interface, &beep_interface, &radio_interface, &button_interface, &pir_interface, &clock_interface, &leds_interface, &cfs_interface);
102 SENSORS(&button_sensor, &pir_sensor, &vib_sensor);
113 static struct cooja_mt_thread rtimer_thread;
114 static struct cooja_mt_thread process_run_thread;
116 #define MIN(a, b) ( (a)<(b) ? (a) : (b) )
120 print_processes(
struct process *
const processes[])
124 while(*processes !=
NULL) {
125 printf(
" '%s'", (*processes)->name);
132 rtimer_thread_loop(
void *data)
149 memset(&addr, 0,
sizeof(linkaddr_t));
150 for(i = 0; i <
sizeof(
uip_lladdr.addr); i += 2) {
151 addr.u8[i + 1] = node_id & 0xff;
152 addr.u8[i + 0] = node_id >> 8;
155 printf(
"MAC address ");
156 for(i = 0; i <
sizeof(addr.u8) - 1; i++) {
157 printf(
"%d.", addr.u8[i]);
159 printf(
"%d\n", addr.u8[i]);
180 printf(CONTIKI_VERSION_STRING
" started. ");
182 printf(
"Node id is set to %u.\n", node_id);
184 printf(
"Node id is not set.\n");
193 printf(
"%s/%s/%s, channel check rate %lu Hz\n",
194 NETSTACK_NETWORK.name, NETSTACK_MAC.name, NETSTACK_RDC.name,
195 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
196 NETSTACK_RDC.channel_check_interval()));
201 for(i = 0; i <
sizeof(
uip_lladdr.addr); i += 2) {
202 addr[i + 1] = node_id & 0xff;
203 addr[i + 0] = node_id >> 8;
210 printf(
"Tentative link-local IPv6 address ");
212 lladdr = uip_ds6_get_link_local(-1);
213 for(i = 0; i < 7; ++i) {
214 printf(
"%02x%02x:", lladdr->ipaddr.u8[i * 2],
215 lladdr->ipaddr.u8[i * 2 + 1]);
217 printf(
"%02x%02x\n", lladdr->ipaddr.u8[14],
218 lladdr->ipaddr.u8[15]);
220 uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
223 printf(
"Tentative global IPv6 address ");
224 for(i = 0; i < 7; ++i) {
226 ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
229 ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
235 print_processes(autostart_processes);
236 autostart_start(autostart_processes);
239 printf(
"Initiating SLIP with IP address is 172.16.0.2.\n");
243 ip64_set_ipv4_address(&ipv4addr, &netmask);
246 log_set_putchar_with_slip(1);
249 uip_ip6addr_t ip6addr;
252 ip64_addr_4to6(&ip4addr, &ip6addr);
258 process_run_thread_loop(
void *data)
261 simProcessRunValue = 1;
268 while(simProcessRunValue-- > 0) {
274 if(simDontFallAsleep) {
275 simDontFallAsleep = 0;
276 simProcessRunValue = 1;
295 JNIEXPORT
void JNICALL
299 cooja_mt_start(&rtimer_thread, &rtimer_thread_loop,
NULL);
300 cooja_mt_start(&process_run_thread, &process_run_thread_loop,
NULL);
320 JNIEXPORT
void JNICALL
323 (*env)->SetByteArrayRegion(
328 (jbyte *) (((
long)rel_addr) + referenceVar)
347 JNIEXPORT
void JNICALL
350 jbyte *mem = (*env)->GetByteArrayElements(env, mem_arr, 0);
351 memcpy((
char *)(((
long)rel_addr) + referenceVar),
354 (*env)->ReleaseByteArrayElements(env, mem_arr, mem, 0);
376 JNIEXPORT
void JNICALL
379 clock_time_t nextEtimer;
380 rtimer_clock_t nextRtimer;
382 simProcessRunValue = 0;
385 doActionsBeforeTick();
394 cooja_mt_exec(&rtimer_thread);
396 if(simProcessRunValue == 0) {
399 cooja_mt_exec(&process_run_thread);
403 doActionsAfterTick();
407 if(!simEtimerPending) {
413 nextRtimer = rtimer_arch_next() - (rtimer_clock_t) simCurrentTime;
415 simNextExpirationTime = MIN(nextEtimer, nextRtimer);
417 simNextExpirationTime = nextEtimer;
418 }
else if(rtimer_arch_pending()) {
419 simNextExpirationTime = nextRtimer;
432 JNIEXPORT
void JNICALL
435 referenceVar = (((long)&referenceVar) - ((long)addr));
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.
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
#define uip_ipaddr(addr, addr0, addr1, addr2, addr3)
Construct an IP address from four bytes.
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.
Header file for IPv6-related data structures.
JNIEXPORT void JNICALL Java_org_contikios_cooja_corecomm_CLASSNAME_tick(JNIEnv *env, jobject obj)
Let mote execute one "block" of code (tick mote).
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.
int slip_input_byte(unsigned char c)
Input a SLIP byte.
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.
void uip_nameserver_update(const uip_ipaddr_t *nameserver, uint32_t lifetime)
Initialize the module variables.
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.
Representation of an IP address.
int process_run(void)
Run the system once - call poll handlers and process one event.
Unicast address structure.
Header file for the Rime stack
#define NULL
The null pointer.
void linkaddr_set_node_addr(linkaddr_t *t)
Set the address of the current node.
#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.
#define UIP_NAMESERVER_INFINITE_LIFETIME
Infinite Lifetime indicator.
Header file for module for automatically starting and exiting a list of processes.
uIP Name Server interface
JNIEXPORT void JNICALL Java_org_contikios_cooja_corecomm_CLASSNAME_init(JNIEnv *env, jobject obj)
Initialize a mote by starting processes etc.
Generic serial I/O process header filer.
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
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