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"
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_org_contikios_cooja_corecomm_
72 #define Java_org_contikios_cooja_corecomm_CLASSNAME_init COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_init)
73 #define Java_org_contikios_cooja_corecomm_CLASSNAME_getMemory COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_getMemory)
74 #define Java_org_contikios_cooja_corecomm_CLASSNAME_setMemory COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_setMemory)
75 #define Java_org_contikios_cooja_corecomm_CLASSNAME_tick COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_tick)
76 #define Java_org_contikios_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", ((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])
107 SIM_INTERFACE_NAME(moteid_interface);
108 SIM_INTERFACE_NAME(vib_interface);
109 SIM_INTERFACE_NAME(rs232_interface);
110 SIM_INTERFACE_NAME(simlog_interface);
111 SIM_INTERFACE_NAME(beep_interface);
112 SIM_INTERFACE_NAME(radio_interface);
113 SIM_INTERFACE_NAME(button_interface);
114 SIM_INTERFACE_NAME(pir_interface);
115 SIM_INTERFACE_NAME(clock_interface);
116 SIM_INTERFACE_NAME(leds_interface);
117 SIM_INTERFACE_NAME(cfs_interface);
118 SIM_INTERFACE_NAME(eeprom_interface);
119 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);
125 SENSORS(&button_sensor, &pir_sensor, &vib_sensor);
136 static struct cooja_mt_thread rtimer_thread;
137 static struct cooja_mt_thread process_run_thread;
139 #define MIN(a, b) ( (a)<(b) ? (a) : (b) )
147 printf(
"%d.%d: making myself the IP network gateway.\n\n",
149 printf(
"IPv4 address of the gateway: %d.%d.%d.%d\n\n",
152 uip_over_mesh_make_announced_gateway();
159 print_processes(
struct process *
const processes[])
163 while(*processes !=
NULL) {
164 printf(
" '%s'", (*processes)->name);
171 rtimer_thread_loop(
void *data)
188 memset(&addr, 0,
sizeof(linkaddr_t));
190 for(i = 0; i <
sizeof(
uip_lladdr.addr); i += 2) {
191 addr.u8[i + 1] = node_id & 0xff;
192 addr.u8[i + 0] = node_id >> 8;
195 addr.u8[0] = node_id & 0xff;
196 addr.u8[1] = node_id >> 8;
199 printf(
"Rime started with address ");
200 for(i = 0; i <
sizeof(addr.u8) - 1; i++) {
201 printf(
"%d.", addr.u8[i]);
203 printf(
"%d\n", addr.u8[i]);
222 printf(CONTIKI_VERSION_STRING
" started. ");
224 printf(
"Node id is set to %u.\n", node_id);
226 printf(
"Node id is not set.\n");
233 memset(longaddr, 0,
sizeof(longaddr));
235 printf(
"MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
236 longaddr[0], longaddr[1], longaddr[2], longaddr[3],
237 longaddr[4], longaddr[5], longaddr[6], longaddr[7]);
244 printf(
"%s/%s/%s, channel check rate %lu Hz\n",
245 NETSTACK_NETWORK.name, NETSTACK_MAC.name, NETSTACK_RDC.name,
246 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
247 NETSTACK_RDC.channel_check_interval()));
252 uip_ipaddr_t hostaddr, netmask;
258 slip_set_input_callback(set_gateway);
268 uip_over_mesh_set_net(&hostaddr, &netmask);
269 uip_over_mesh_set_gateway_netif(&slipif);
271 uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
283 for(i = 0; i <
sizeof(
uip_lladdr.addr); i += 2) {
284 addr[i + 1] = node_id & 0xff;
285 addr[i + 0] = node_id >> 8;
292 printf(
"Tentative link-local IPv6 address ");
296 lladdr = uip_ds6_get_link_local(-1);
297 for(i = 0; i < 7; ++i) {
298 printf(
"%02x%02x:", lladdr->ipaddr.u8[i * 2],
299 lladdr->ipaddr.u8[i * 2 + 1]);
301 printf(
"%02x%02x\n", lladdr->ipaddr.u8[14],
302 lladdr->ipaddr.u8[15]);
311 printf(
"Tentative global IPv6 address ");
312 for(i = 0; i < 7; ++i) {
314 ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
317 ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
329 print_processes(autostart_processes);
330 autostart_start(autostart_processes);
334 process_run_thread_loop(
void *data)
337 simProcessRunValue = 1;
345 while(simProcessRunValue-- > 0) {
351 if(simDontFallAsleep) {
353 simProcessRunValue = 1;
370 JNIEXPORT
void JNICALL
374 cooja_mt_start(&rtimer_thread, &rtimer_thread_loop,
NULL);
375 cooja_mt_start(&process_run_thread, &process_run_thread_loop,
NULL);
392 JNIEXPORT
void JNICALL
395 (*env)->SetByteArrayRegion(
400 (jbyte *) (((
long)rel_addr) + referenceVar)
417 JNIEXPORT
void JNICALL
420 jbyte *mem = (*env)->GetByteArrayElements(env, mem_arr, 0);
422 (
char*) (((
long)rel_addr) + referenceVar),
425 (*env)->ReleaseByteArrayElements(env, mem_arr, mem, 0);
445 JNIEXPORT
void JNICALL
448 clock_time_t nextEtimer;
449 rtimer_clock_t nextRtimer;
451 simProcessRunValue = 0;
454 doActionsBeforeTick();
463 cooja_mt_exec(&rtimer_thread);
465 if(simProcessRunValue == 0) {
468 cooja_mt_exec(&process_run_thread);
472 doActionsAfterTick();
476 if(!simEtimerPending) {
482 nextRtimer = rtimer_arch_next() - (rtimer_clock_t) simCurrentTime;
484 simNextExpirationTime = MIN(nextEtimer, nextRtimer);
486 simNextExpirationTime = nextEtimer;
487 }
else if (rtimer_arch_pending()) {
488 simNextExpirationTime = nextRtimer;
499 JNIEXPORT
void JNICALL
502 referenceVar = (((long)&referenceVar) - ((long)addr));
#define uip_sethostaddr(addr)
Set the IP address of this host.
linkaddr_t linkaddr_node_addr
The Rime address of the node.
uIP packet forwarding header file.
int process_nevents(void)
Number of events waiting to be processed.
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
#define UIP_FW_NETIF(ip1, ip2, ip3, ip4, nm1, nm2, nm3, nm4, outputfunc)
Instantiating macro for a uIP network interface.
Representation of a uIP network interface.
Unicast address structure.
uip_ipaddr_t ipaddr
The IP address of this interface.
Header file for the uIP TCP/IP stack.
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_init(void)
Initialize the uIP packet forwarding module.
JNIEXPORT void JNICALL Java_org_contikios_cooja_corecomm_CLASSNAME_tick(JNIEnv *env, jobject obj)
Let mote execute one "block" of code (tick mote).
Network interface and stateless autoconfiguration (RFC 4862)
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 rs232_set_input(int(*f)(unsigned char))
Set an input handler for incoming RS232 data.
#define NULL
The null pointer.
Header file for tunnelling uIP over Rime mesh
void process_init(void)
Initialize the process module.
Header file for the Rime stack
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a Rime address.
void eeprom_init(void)
Initialize the EEPROM module.
Generic serial I/O process header filer.
Header file for module for automatically starting and exiting a list of processes.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
void ctimer_init(void)
Initialize the callback timer library.
clock_time_t etimer_next_expiration_time(void)
Get next event timer expiration time.
#define uip_ipaddr_to_quad(a)
Convert an IP address to four bytes separated by commas.
void uip_init(void)
uIP initialization function.
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.
void etimer_request_poll(void)
Make the event timer aware that the clock has changed.
void uip_fw_default(struct uip_fw_netif *netif)
Register a default network interface.
int etimer_pending(void)
Check if there are any non-expired event timers.
void process_start(struct process *p, process_data_t data)
Start a process.
JNIEXPORT void JNICALL Java_org_contikios_cooja_corecomm_CLASSNAME_init(JNIEnv *env, jobject obj)
Initialize a mote by starting processes etc.
#define ADDR_TENTATIVE
Possible states for the an address (RFC 4862)
int process_run(void)
Run the system once - call poll handlers and process one event.
void linkaddr_set_node_addr(linkaddr_t *t)
Set the address of the current node.
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.
#define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7)
Construct an IPv6 address from eight 16-bit words.
#define uip_setnetmask(addr)
Set the netmask.
Include file for the Contiki low-layer network stack (NETSTACK)
#define CLOCK_SECOND
A second, measured in system clock time.