47 #include "contiki-net.h"
49 #include "contiki-main.h"
54 #include "net/ethernode.h"
56 #include <sys/types.h>
62 #include <arpa/inet.h>
64 in_addr_t gwaddr, winifaddr;
66 void netsim_init(
void);
68 static int main_process = 0;
72 sigchld_handler(
int sig)
76 struct nodes_node *node;
81 pid = waitpid(-1, &status, WNOHANG);
83 if(WIFSIGNALED(status) &&
84 WTERMSIG(status) == SIGSEGV) {
85 node = nodes_find_pid(pid);
87 printf(
"A Contiki node crashed, but it wasn't even started by the system. Something weird is going on!\n");
89 printf(
"Contiki node at (%d, %d) crashed - Segmentation fault\n",
107 printf(
"events %d\n", events);
114 start_node(
int x,
int y,
int b)
118 static unsigned short port = NODES_PORTBASE;
128 setvbuf(stdout, (
char *)
NULL, _IONBF, 0);
134 tv.tv_usec = 1000 * (rand() % 1000);
137 node_init(port - NODES_PORTBASE + 2, x, y, b);
146 nodes_base_node_port = port;
151 nodes_add(pid, x, y, port, port - NODES_PORTBASE + 2);
155 return port - NODES_PORTBASE + 1;
159 main_add_node(
int x,
int y)
161 return start_node(x, y, 0);
165 main_add_base(
int x,
int y)
171 main(
int argc,
char **argv)
175 inet_addr(argv[1]) == INADDR_NONE &&
176 inet_addr(argv[2]) == INADDR_NONE) {
177 printf(
"usage: %s <ip addr of ethernet card to share> "
178 "<ip addr of netsim gateway>\n", argv[0]);
180 }
else if(argc >= 2) {
181 gwaddr = inet_addr(argv[2]);
182 winifaddr = inet_addr(argv[1]);
193 atexit(ether_print_stats);
209 if(argc > 1 && (strcmp(argv[1],
"-q") ||
210 strcmp(argv[2],
"-q") ||
211 strcmp(argv[3],
"-q")) == 0) {
213 if(argc > 1 && strcmp(argv[1],
"-q") == 0) {
215 display_init(idle, 50, 0);
217 display_init(idle, 50, 1);
221 signal(SIGCHLD, sigchld_handler);
232 void arg_init(
void) {}
236 char *shell_prompt_text =
"sensor-router> ";
239 #include <sys/time.h>
241 static signed long drift = 0;
248 tv.tv_usec = 100 * num;
253 clock_set_time(clock_time_t time, clock_time_t ftime)
255 drift = time - node_time();
261 return drift + node_time();
267 return node_seconds();
281 configurator_send_config(
uip_ipaddr_t *addr,
unsigned long seconds)
283 printf(
"Configurator: address %d.%d.%d.%d, seconds %lu\n",