/*---------------------------------------------------------------------------*/ PROCESS_THREAD(tcp_client_process, ev, data) { static struct etimer et; PROCESS_BEGIN(); PRINTF("TCP client process started\n"); process_start(&adjust_packet_length_process, 0); #if UIP_CONF_ROUTER set_global_address(); #endif print_local_addresses(); /* Fill buffer with test data */ for (int i = 0; i < MAX_PAYLOAD_LEN; i++) { buf[i] = i; } static resolv_status_t status = RESOLV_STATUS_UNCACHED; while(status != RESOLV_STATUS_CACHED) { status = set_connection_address(&ipaddr); if(status == RESOLV_STATUS_RESOLVING) { PROCESS_WAIT_EVENT_UNTIL(ev == resolv_event_found); } else if(status != RESOLV_STATUS_CACHED) { PRINTF("Can't get connection address.\n"); PROCESS_YIELD(); } } /* new connection with remote host */ tcp_socket_register(&socket, NULL, inputbuf, sizeof(inputbuf), outputbuf, sizeof(outputbuf), input, event); tcp_socket_connect(&socket, &ipaddr, SERVER_PORT); PRINTF("Connecting with the server..."); PRINT6ADDR(&ipaddr); PRINTF("\n"); while(1) { etimer_set(&et, send_interval); PROCESS_YIELD(); if(etimer_expired(&et)) { timeout_handler(); } } PROCESS_END(); }
/*----------------------------------------------------------------------------*/ PROCESS_THREAD(tres_process, ev, data) { PROCESS_BEGIN(); srand(node_id); rest_init_engine(); tres_init(); SENSORS_ACTIVATE(light_sensor); rest_activate_periodic_resource(&periodic_resource_light); rplinfo_activate_resources(); static coap_packet_t request[1]; /* This way the packet can be treated as pointer as usual. */ SERVER_NODE(&server_ipaddr); /* receives all CoAP messages */ coap_receiver_init(); int wait_time = getRandUint(MAX_WAITING); int base_wait = BASE_WAITING; static int g_time=0; static char content[12]; etimer_set(&et, (wait_time + base_wait) * CLOCK_SECOND); while(1) { PROCESS_YIELD(); if (etimer_expired(&et)) break; } etimer_reset(&et); etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND); while(1) { PROCESS_YIELD(); if (etimer_expired(&et)) { coap_init_message(request, COAP_TYPE_NON, COAP_POST, 0 ); coap_set_header_uri_path(request, service_urls[1]); coap_set_payload(request, content, snprintf(content, sizeof(content), "%d", g_time++)); coap_transaction_t *transaction; request->mid = coap_get_mid(); if ((transaction = coap_new_transaction(request->mid, &server_ipaddr, REMOTE_PORT))) { transaction->packet_len = coap_serialize_message(request, transaction->packet); coap_send_transaction(transaction); } etimer_reset(&et); } } /* while (1) */ PROCESS_END(); }
/*----------------------------------------------------------------------------*/ PROCESS_THREAD(tres_process, ev, data) { PROCESS_BEGIN(); srand(node_id); rest_init_engine(); tres_init(); rest_activate_resource(&actuator, "actuator"); rplinfo_activate_resources(); sprintf(setpoint, "0"); #if PYOT_KEEPALIVE static coap_packet_t request[1]; /* This way the packet can be treated as pointer as usual. */ SERVER_NODE(&server_ipaddr); int wait_time = (unsigned int)(rand() % MAX_WAITING); int base_wait = BASE_WAITING; static int g_time=0; static char content[12]; etimer_set(&et, (wait_time + base_wait) * CLOCK_SECOND); while(1) { PROCESS_YIELD(); //PROCESS_WAIT_EVENT(); if (etimer_expired(&et)) break; } etimer_reset(&et); etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND); while(1) { PROCESS_YIELD(); if (etimer_expired(&et)) { coap_init_message(request, COAP_TYPE_NON, COAP_POST, 0 ); coap_set_header_uri_path(request, "/rd"); coap_set_payload(request, content, snprintf(content, sizeof(content), "%d", g_time++)); //PRINT6ADDR(&server_ipaddr); //PRINTF(" : %u\n", UIP_HTONS(REMOTE_PORT)); coap_transaction_t *transaction; request->mid = coap_get_mid(); if ((transaction = coap_new_transaction(request->mid, &server_ipaddr, REMOTE_PORT))) { transaction->packet_len = coap_serialize_message(request, transaction->packet); coap_send_transaction(transaction); } etimer_reset(&et); } } /* while (1) */ #endif PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_client_process, ev, data) { static struct etimer et; uip_ipaddr_t ipaddr; int port = 3000; /* Default to 3000 if not using service discovery. */ PROCESS_BEGIN(); PRINTF("UDP client process started\n"); #if UIP_CONF_ROUTER set_global_address(); #endif print_local_addresses(); static resolv_status_t status = RESOLV_STATUS_UNCACHED; while(status != RESOLV_STATUS_CACHED) { #if RESOLV_CONF_SUPPORTS_MDNS && RESOLV_CONF_SUPPORTS_DNS_SD status = set_connection_address(&ipaddr, &port); #else status = set_connection_address(&ipaddr, NULL); #endif if(status == RESOLV_STATUS_RESOLVING) { PROCESS_WAIT_EVENT_UNTIL(ev == resolv_event_found); } else if(status != RESOLV_STATUS_CACHED) { PRINTF("Can't get connection address.\n"); PROCESS_YIELD(); } } /* new connection with remote host */ client_conn = udp_new(&ipaddr, UIP_HTONS(port), NULL); udp_bind(client_conn, UIP_HTONS(port + 1)); PRINTF("Created a connection with the server "); PRINT6ADDR(&client_conn->ripaddr); PRINTF(" local/remote port %u/%u\n", UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport)); etimer_set(&et, SEND_INTERVAL); while(1) { PROCESS_YIELD(); if(etimer_expired(&et)) { timeout_handler(); etimer_restart(&et); } else if(ev == tcpip_event) { tcpip_handler(); } } PROCESS_END(); }
PROCESS_THREAD(default_app_process, ev, data) { PROCESS_BEGIN(); SENSORS_ACTIVATE(acc_sensor); SENSORS_ACTIVATE(gyro_sensor); SENSORS_ACTIVATE(pressure_sensor); etimer_set(&timer, CLOCK_SECOND * 0.05); while (1) { PROCESS_YIELD(); etimer_set(&timer, CLOCK_SECOND); printf("X_ACC=%d, Y_ACC=%d, Z_ACC=%d\n", acc_sensor.value(ACC_X), acc_sensor.value(ACC_Y), acc_sensor.value(ACC_Z)); printf("X_AS=%d, Y_AS=%d, Z_AS=%d\n", gyro_sensor.value(X_AS), gyro_sensor.value(Y_AS), gyro_sensor.value(Z_AS)); // printf("PRESS=%u, TEMP=%d\n\n", pressure_sensor.value(PRESS), pressure_sensor.value(TEMP)); } PROCESS_END(); }
PROCESS_THREAD(adc_read_process, ev, data) { PROCESS_POLLHANDLER(pollhandler()); PROCESS_BEGIN(); PROCESS_PAUSE(); process_poll(&adc_read_process); while(1) { PROCESS_YIELD(); } PROCESS_END(); }
PROCESS_THREAD(rtc_test, ev, data) { PROCESS_BEGIN(); leds_off(LEDS_ALL); etimer_set(&periodic_timer_rtc, CLOCK_SECOND*5); while(1) { PROCESS_YIELD(); if (etimer_expired(&periodic_timer_rtc)) { rv3049_read_time(&rtctime); if (rtctime.seconds - 3 > last_seconds) { leds_toggle(LEDS_BLUE); leds_off(LEDS_RED); } else { leds_toggle(LEDS_RED); leds_off(LEDS_BLUE); } last_seconds = rtctime.seconds; etimer_restart(&periodic_timer_rtc); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(etimer_process, ev, data, buf, user_data) { struct etimer *t; PROCESS_BEGIN(); while(1) { PROCESS_YIELD(); PRINTF("%s():%d timerlist %p\n", __FUNCTION__, __LINE__, timerlist); for(t = timerlist; t != NULL; t = t->next) { PRINTF("%s():%d timer %p remaining %d triggered %d\n", __FUNCTION__, __LINE__, t, timer_remaining(&t->timer), etimer_is_triggered(t)); if(etimer_expired(t) && !etimer_is_triggered(t)) { PRINTF("%s():%d timer %p expired, process %p\n", __FUNCTION__, __LINE__, t, t->p); if (t->p == NULL) { PRINTF("calling tcpip_process\n"); process_post_synch(&tcpip_process, PROCESS_EVENT_TIMER, t, NULL); } else { process_post_synch(t->p, PROCESS_EVENT_TIMER, t, NULL); } } } update_time(); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_client_process, ev, data) { PROCESS_BEGIN(); PROCESS_PAUSE(); set_global_address(); PRINTF("UDP client process started\n"); print_local_addresses(); /* new connection with remote host */ client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); PRINTF("Created a connection with the server "); PRINT6ADDR(&client_conn->ripaddr); PRINTF(" local/remote port %u/%u\n", UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport)); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { tcpip_handler(); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_server_process, ev, data) { PROCESS_BEGIN(); putstring("Starting UDP server\n"); #if BUTTON_SENSOR_ON putstring("Button 1: Print RIME stats\n"); #endif #if SERVER_RPL_ROOT create_dag(); #endif server_conn = udp_new(NULL, UIP_HTONS(0), NULL); udp_bind(server_conn, UIP_HTONS(3000)); PRINTF("Listen port: 3000, TTL=%u\n", server_conn->ttl); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { tcpip_handler(); #if (BUTTON_SENSOR_ON && (DEBUG==DEBUG_PRINT)) } else if(ev == sensors_event && data == &button_sensor) { print_stats(); #endif /* BUTTON_SENSOR_ON */ } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(mcast_sink_process, ev, data) { PROCESS_BEGIN(); PRINTF("Multicast Engine: '%s'\n", UIP_MCAST6.name); if(join_mcast_group() == NULL) { PRINTF("Failed to join multicast group\n"); PROCESS_EXIT(); } count = 0; sink_conn = udp_new(NULL, UIP_HTONS(0), NULL); udp_bind(sink_conn, UIP_HTONS(MCAST_SINK_UDP_PORT)); PRINTF("Listening: "); PRINT6ADDR(&sink_conn->ripaddr); PRINTF(" local/remote port %u/%u\n", UIP_HTONS(sink_conn->lport), UIP_HTONS(sink_conn->rport)); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { tcpip_handler(); } } PROCESS_END(); }
PROCESS_THREAD(freakusb_process, ev, data_proc) { PROCESS_POLLHANDLER(freakusb_pollhandler()); PROCESS_BEGIN(); usb_init(); hw_init(); cdc_init(); /* TODO: Implement this when we decide to accept commands over the USB */ cdc_reg_rx_handler(test_avr_usb_rx_handler); /* hook the putchar function to the printf and use it for stdout */ stdout = &file_str; /* kick off the polling function */ process_poll(&freakusb_process); while (1) { PROCESS_YIELD(); } PROCESS_END(); }
PROCESS_THREAD(raven_lcd_process, ev, data) { u8_t error; PROCESS_BEGIN(); /*Create a udp connection to the IPSOserver*/ //swisscom uip_ip6addr(&udp_addr,0x2001,918,0xfff9,0,0,0,0,1); //HE uip_ip6addr(&udp_addr,0x2001,0x470,0x1f12,0x5ec,0x12,0x13ff,0xfe14,0x1516); uip_ip6addr(&udp_addr,0x2001,0x420,0x5FFF,0x7D,0x2D0,0xB7FF,0xFE23,0xE6DB); /* set destination parameters*/ udp_conn = udp_new(&udp_addr, HTONS(0xF0B0), NULL); /*set local port */ udp_bind(udp_conn, HTONS(0xF0B0+1)); if((error = icmp6_new(NULL)) == 0) { while(1) { PROCESS_YIELD(); raven_gui_loop(ev, data); } } PROCESS_END(); }
PROCESS_THREAD(receive_process, ev, data) { PROCESS_BEGIN(); static struct uip_udp_conn* server_conn; server_conn = udp_new(NULL, UIP_HTONS(UDP_CLIENT_PORT), NULL); udp_bind(server_conn, UIP_HTONS(UDP_SERVER_PORT)); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { uint8_t* appdata = uip_appdata; ASSERT((uip_datalen() % sizeof(uint32_t)) == 0); size_t numberof_values = uip_datalen() / sizeof(uint32_t); printf("trace: received values: "); uint32_t value; size_t i; for (i=0; i<numberof_values; i++) { ASSERT(offset < MAX_NUMBEROF_VALUES); memcpy(&value, &appdata[i * sizeof(uint32_t)], sizeof(uint32_t)); printf("%lu ", value); values[offset++] = value; } printf("\n"); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(coap_engine, ev, data, buf) { PROCESS_BEGIN(); #if 0 /* This is not used in Zephyr. */ PRINTF("Starting %s receiver...\n", coap_rest_implementation.name); rest_activate_resource(&res_well_known_core, ".well-known/core"); coap_register_as_transaction_handler(); coap_init_connection(SERVER_LISTEN_PORT); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { coap_engine_receive(COAP_CONTEXT_NONE); } else if(ev == PROCESS_EVENT_TIMER) { /* retransmissions are handled here */ coap_check_transactions(); } } /* while (1) */ #endif /* 0 */ PROCESS_END(); }
PROCESS_THREAD(udp_plug_process, ev, data) { static struct etimer et; PROCESS_BEGIN(); PRINTF("UDP server started\r\n"); #if DEV_BOARD leds_on(LEDS_RED | LEDS_GREEN); SENSORS_ACTIVATE(button_sensor); #else leds_on(LEDS_GREEN); #ifdef HAS_PIR_SENSOR pir_state = PIR_DISPATCH; etimer_set(&pir_timer, PIR_INIT_TIME); #endif #endif #if HAS_TEMP_SENSOR start_temp_conv(); #endif #if HAS_LIGHT_SENSOR light_sensor_init(); #endif udp_conn = udp_new(NULL, UIP_HTONS(0), NULL); udp_bind(udp_conn, UIP_HTONS(PLUG_PORT)); PRINTF("listening on udp port %u\r\n",UIP_HTONS(udp_conn->lport)); etimer_set(&et, SEND_INTERVAL); while(1) { PROCESS_YIELD(); if(etimer_expired(&et)) { timeout_handler(); etimer_restart(&et); } #ifdef HAS_PIR_SENSOR if((pir_state == PIR_DISPATCH)&&(etimer_expired(&pir_timer))) { SENSORS_ACTIVATE(button_sensor); pir_state = PIR_READY; } #endif if(ev == tcpip_event) { PRINTF("Calling tcpip_Handler\r\n"); tcpip_handler(); } if (ev == sensors_event && data == &button_sensor) { #ifndef DEV_BOARD handle_pir_event(); #endif PRINTF("Button Pressed\r\n"); } } PROCESS_END(); }
/*---------------------------------------------------------------------*/ PROCESS_THREAD(tcp_loader_process, ev, data) { PROCESS_BEGIN(); tcp_listen(HTONS(CODEPROP_DATA_PORT)); while(1) { PROCESS_YIELD(); if(ev == tcpip_event && uip_conn->lport == HTONS(CODEPROP_DATA_PORT)) { if(uip_connected()) { /* Really uip_connecting()!!! */ if(data == NULL) { PT_INIT(&s.tcpthread_pt); process_poll(&tcp_loader_process); tcp_markconn(uip_conn, &s); } else { PRINTF(("codeprop: uip_connected() and data != NULL\n")); uip_abort(); } } recv_tcpthread(&s.tcpthread_pt); /* Run thread */ if(uip_closed() || uip_aborted() || uip_timedout()) { PRINTF(("codeprop: connection down\n")); tcp_markconn(uip_conn, NULL); } } } PROCESS_END(); }
PROCESS_THREAD(oled_temp_process, ev, data) { static struct etimer sensors_timer; PROCESS_BEGIN(); draw_init(); draw_clear(); onewire_init(); etimer_set(&sensors_timer, READ_INTERVAL); timer_callback(); while(1) { PROCESS_YIELD(); if(etimer_expired(&sensors_timer)) { timer_callback(); etimer_set(&sensors_timer, READ_INTERVAL); } } PROCESS_END(); }
/* * Entry point of the SNMP server. */ PROCESS_THREAD(snmpd_process, ev, data) { PROCESS_BEGIN(); snmp_packets = 0; #ifndef CONTIKI_TARGET_AVR_RAVEN systemStartTime = clock_time(); #endif #if CHECK_STACK_SIZE u16t i = 0; u32t pointer; u32t* p = &pointer; for (i = 0; i < 1000; i++) { *p = 0xAAAAAAAA; p--; } marker = &pointer; #endif udpconn = udp_new(NULL, UIP_HTONS(0), NULL); udp_bind(udpconn, UIP_HTONS(LISTEN_PORT)); /* init MIB */ if (mib_init() != -1) { while(1) { PROCESS_YIELD(); udp_handler(ev, data); } } else { snmp_log("error occurs while initializing the MIB\n"); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(http_example_process, ev, data) { static struct etimer et; PROCESS_BEGIN(); SENSORS_ACTIVATE(sht25); ubidots_init(&http_example_process, headers); while(1) { PROCESS_YIELD(); if(ev == ubidots_event_established || (ev == PROCESS_EVENT_TIMER && data == &et)) { leds_on(LEDS_GREEN); post_collection(); } else if(ev == ubidots_event_post_sent) { leds_off(LEDS_GREEN); etimer_set(&et, POST_PERIOD); } // else if(ev == ubidots_event_post_reply_received) { // print_reply((ubidots_reply_part_t *)data); // } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(rpl_root_process, ev, data) { static struct etimer et; PROCESS_BEGIN(); PRINTF("Multicast Engine: '%s'\n", UIP_MCAST6.name); NETSTACK_MAC.off(1); set_own_addresses(); prepare_mcast(); etimer_set(&et, START_DELAY * CLOCK_SECOND); while(1) { PROCESS_YIELD(); if(etimer_expired(&et)) { if(seq_id == ITERATIONS) { etimer_stop(&et); } else { multicast_send(); etimer_set(&et, SEND_INTERVAL); } } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(ipv6_process, ev, data) { PROCESS_BEGIN(); printf("started!\n"); etimer_set(&periodic_timer, 1*CLOCK_SECOND); while(1) { PROCESS_YIELD(); if (etimer_expired(&periodic_timer)) { if (!(spibyte & 0x01)) { SPI_READ(spibuf[0]); } else { SPI_WRITE(spibuf[1]); } spibyte++; etimer_restart(&periodic_timer); } } PROCESS_END(); }
PROCESS_THREAD(tcp_process, ev, data) { static char incoming[10]; static struct psock ps; PROCESS_BEGIN(); uart0_set_br(1000000); tcp_listen(UIP_HTONS(2020)); while(1) { PROCESS_YIELD(); } { /* wait for tcp connection */ PROCESS_WAIT_EVENT_UNTIL(ev==tcpip_event && uip_connected()); /* start estimator process and init psock connection handler */ process_start(&ahrs_process, NULL); PSOCK_INIT(&ps,incoming,sizeof(incoming)); /* loop until connection is closed */ while (!(uip_aborted() || uip_closed() || uip_timedout())) { PROCESS_YIELD_UNTIL(ev==tcpip_event); handle_connection(&ps); } /* stop ahrs process */ process_exit(&ahrs_process); } PROCESS_END(); }
/*----------------------------------------------------------------------------*/ PROCESS_THREAD(coap_receiver, ev, data) { PROCESS_BEGIN(); PRINTF("Starting CoAP-13 receiver...\n"); rest_activate_resource(&resource_well_known_core); #if ! COAP_CEU coap_register_as_transaction_handler(); #endif coap_init_connection(SERVER_LISTEN_PORT); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { coap_receive(); } else if (ev == PROCESS_EVENT_TIMER) { /* retransmissions are handled here */ #if ! COAP_CEU coap_check_transactions(); #endif } } /* while (1) */ PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_client_process, ev, data) { static struct etimer periodic; static struct ctimer backoff_timer; #if WITH_COMPOWER static int print = 0; #endif PROCESS_BEGIN(); PROCESS_PAUSE(); set_global_address(); PRINTF("UDP client process started\n"); print_local_addresses(); /* new connection with remote host */ client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); if(client_conn == NULL) { PRINTF("No UDP connection available, exiting the process!\n"); PROCESS_EXIT(); } udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); PRINTF("Created a connection with the server "); PRINT6ADDR(&client_conn->ripaddr); PRINTF(" local/remote port %u/%u\n", UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport)); #if WITH_COMPOWER powertrace_sniff(POWERTRACE_ON); #endif etimer_set(&periodic, SEND_INTERVAL); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { tcpip_handler(); } if(etimer_expired(&periodic)) { etimer_reset(&periodic); ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL); #if WITH_COMPOWER if (print == 0) { powertrace_print("#P"); } if (++print == 3) { print = 0; } #endif } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_server_process, ev, data) { PROCESS_BEGIN(); PRINTF("UDP server started\n"); #if UIP_CONF_ROUTER uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_netif_addr_add(&ipaddr, 64, 0, AUTOCONF); #endif /* UIP_CONF_ROUTER */ print_local_addresses(); server_conn = udp_new(NULL, HTONS(61617), NULL); udp_bind(server_conn, HTONS(61616)); PRINTF("Created a server connection with remote address "); PRINT6ADDR(&server_conn->ripaddr); PRINTF("local/remote port %u/%u\n", HTONS(server_conn->lport), HTONS(server_conn->rport)); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { tcpip_handler(); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(slip_radio_process, ev, data) { static struct etimer et; PROCESS_BEGIN(); init(); NETSTACK_RDC.off(1); #ifdef SLIP_RADIO_CONF_SENSORS SLIP_RADIO_CONF_SENSORS.init(); #endif printf("Slip Radio started...\n"); etimer_set(&et, CLOCK_SECOND * 3); while(1) { PROCESS_YIELD(); if(etimer_expired(&et)) { etimer_reset(&et); #ifdef SLIP_RADIO_CONF_SENSORS SLIP_RADIO_CONF_SENSORS.send(); #endif } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(coap_engine, ev, data) { PROCESS_BEGIN(); PRINTF("Starting %s receiver...\n", coap_rest_implementation.name); #if WITH_WELL_KNOWN_CORE rest_activate_resource(&res_well_known_core, ".well-known/core"); #endif coap_register_as_transaction_handler(); coap_init_connection(SERVER_LISTEN_PORT); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { coap_handle_receive(coap_default_context); } else if(ev == PROCESS_EVENT_TIMER) { /* retransmissions are handled here */ coap_check_transactions(); } } /* while (1) */ PROCESS_END(); }
PROCESS_THREAD(raven_lcd_process, ev, data) { PROCESS_BEGIN(); /* Initialize the sensor data history */ memcpy(last_temp, "20.0", sizeof("20.0")); /*Create a udp connection to the server*/ uip_ip6addr(&server_addr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1); /* set destination parameters */ send_conn = udp_new(&server_addr, SERVER_PORT, NULL); /*set local port */ udp_bind(send_conn, HTONS(0xF0B0+1)); /* Listen to port 0xF0B0 for commands */ node_conn = udp_new(NULL, 0, NULL); udp_bind(node_conn, HTONS(0xF0B0)); if(icmp6_new(NULL) != NULL) { while(1) { PROCESS_YIELD(); raven_gui_loop(ev, data); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(sensortag_process, ev, data) { static struct etimer et; uip_ipaddr_t ipaddr; etimer_set(&et, CLOCK_CONF_SECOND*20); PROCESS_BEGIN(); PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER); if(uip_ds6_get_global(ADDR_PREFERRED) == NULL) { printf("NO IP \n\r"); } else{ printf("Good \n\r"); } print_local_addresses(); if(uiplib_ipaddrconv("2001:0db8:0002:0000:0000:0000:0000:0002", &ipaddr)){ printf("Get server IP! \n\r"); } /* new connection with remote host */ client_conn = udp_new(&ipaddr, UIP_HTONS(10001), NULL); udp_bind(client_conn, UIP_HTONS(10002)); printf("Connect! \n\r"); init_hdc_reading(NULL); while(1) { PROCESS_YIELD(); if(ev == sensors_event && data == &hdc_1000_sensor) { get_hdc_reading(); } } PROCESS_END(); }