48 #include <sys/select.h>
52 #include "net/wpcap-drv.h"
59 #include "ctk/ctk-curses.h"
65 #include "dev/button-sensor.h"
66 #include "dev/pir-sensor.h"
67 #include "dev/vib-sensor.h"
75 #ifdef SELECT_CONF_MAX
76 #define SELECT_MAX SELECT_CONF_MAX
81 static const struct select_callback *select_callback[SELECT_MAX];
82 static int select_max = 0;
84 SENSORS(&pir_sensor, &vib_sensor, &button_sensor);
86 static uint8_t serial_id[] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};
87 static uint16_t node_id = 0x0102;
90 select_set_callback(
int fd,
const struct select_callback *callback)
93 if(fd >= 0 && fd < SELECT_MAX) {
95 if(callback !=
NULL &&
96 (callback->set_fd ==
NULL || callback->handle_fd ==
NULL)) {
100 select_callback[fd] = callback;
103 if(callback !=
NULL) {
104 if(fd > select_max) {
109 for(i = SELECT_MAX - 1; i > 0; i--) {
110 if(select_callback[i] !=
NULL) {
122 stdin_set_fd(fd_set *rset, fd_set *wset)
124 FD_SET(STDIN_FILENO, rset);
128 stdin_handle_fd(fd_set *rset, fd_set *wset)
131 if(FD_ISSET(STDIN_FILENO, rset)) {
132 if(read(STDIN_FILENO, &c, 1) > 0) {
137 const static struct select_callback stdin_fd = {
138 stdin_set_fd, stdin_handle_fd
147 memset(&addr, 0,
sizeof(linkaddr_t));
149 memcpy(addr.u8, serial_id,
sizeof(addr.u8));
152 for(i = 0; i <
sizeof(linkaddr_t); ++i) {
153 addr.u8[i] = serial_id[7 - i];
156 addr.u8[0] = node_id & 0xff;
157 addr.u8[1] = node_id >> 8;
161 printf(
"Rime started with address ");
162 for(i = 0; i <
sizeof(addr.u8) - 1; i++) {
163 printf(
"%d.", addr.u8[i]);
165 printf(
"%d\n", addr.u8[i]);
170 int contiki_argc = 0;
174 main(
int argc,
char **argv)
177 #if UIP_CONF_IPV6_RPL
178 printf(CONTIKI_VERSION_STRING
" started with IPV6, RPL\n");
180 printf(CONTIKI_VERSION_STRING
" started with IPV6\n");
183 printf(CONTIKI_VERSION_STRING
" started\n");
196 #ifdef UIP_FALLBACK_INTERFACE
214 printf(
"MAC %s RDC %s NETWORK %s\n", NETSTACK_MAC.name, NETSTACK_RDC.name, NETSTACK_NETWORK.name);
225 printf(
"Tentative link-local IPv6 address ");
229 lladdr = uip_ds6_get_link_local(-1);
230 for(i = 0; i < 7; ++i) {
231 printf(
"%02x%02x:", lladdr->ipaddr.u8[i * 2],
232 lladdr->ipaddr.u8[i * 2 + 1]);
235 lladdr->state = ADDR_AUTOCONF;
237 printf(
"%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
245 autostart_start(autostart_processes);
248 setvbuf(stdout, (
char *)
NULL, _IONBF, 0);
250 select_set_callback(STDIN_FILENO, &stdin_fd);
262 tv.tv_usec = retval ? 1 : 1000;
267 for(i = 0; i <= select_max; i++) {
268 if(select_callback[i] !=
NULL && select_callback[i]->set_fd(&fdr, &fdw)) {
273 retval = select(maxfd + 1, &fdr, &fdw,
NULL, &tv);
278 }
else if(retval > 0) {
280 for(i = 0; i <= maxfd; i++) {
281 if(select_callback[i] !=
NULL) {
282 select_callback[i]->handle_fd(&fdr, &fdw);
290 if(console_resize()) {
300 log_message(
char *m1,
char *m2)
302 fprintf(stderr,
"%s%s\n", m1, m2);
308 fprintf(stderr,
"%s\n", m);
int serial_line_input_byte(unsigned char c)
Get one byte of input from the serial driver.
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
Unicast address structure.
Header file for the uIP TCP/IP stack.
void rtimer_init(void)
Initialize the real-time scheduler.
Network interface and stateless autoconfiguration (RFC 4862)
#define NULL
The null pointer.
void uip_log(char *msg)
Print out a uIP log message.
int main(void)
This is main...
void process_init(void)
Initialize the process module.
Header file for the Rime stack
Generic serial I/O process header filer.
void ctimer_init(void)
Initialize the callback timer library.
void etimer_request_poll(void)
Make the event timer aware that the clock has changed.
void process_start(struct process *p, process_data_t data)
Start a process.
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.
Include file for the Contiki low-layer network stack (NETSTACK)