Beispiel #1
0
PROCESS_THREAD(onboard_flash_test_process, ev, data)
{
	PROCESS_BEGIN();

	etimer_set(&et, CLOCK_SECOND * 5);
	PROCESS_YIELD_UNTIL(etimer_expired(&et));

	while(RUNNING) {
		printf("Starting test...\n");
		int ret = coffee_file_test();
		printf("Test finished with %d\n", ret);

		printf("Result: ");
		if( ret == 0 ) {
			printf("SUCCESS\n");
			RUNNING = 0;
		} else {
			printf("FAILURE\n");

			printf("Formatting Flash...");
			fflush(stdout);
			cfs_coffee_format();
			printf("OK\n");
		}

		etimer_set(&et, CLOCK_SECOND * 60);
		PROCESS_YIELD_UNTIL(etimer_expired(&et));
	}

	PROCESS_END();
}
Beispiel #2
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(rd_client_process, ev, data)
{
  static struct etimer et;
  static coap_packet_t request[1];      /* This way the packet can be treated as pointer as usual. */
  static char query_buffer[200];
  static char rd_client_name[64];

  PROCESS_BEGIN();
  PROCESS_PAUSE();
  PRINTF("RD client started\n");
  sprintf(rd_client_name, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
      uip_lladdr.addr[0], uip_lladdr.addr[1], uip_lladdr.addr[2], uip_lladdr.addr[3],
      uip_lladdr.addr[4], uip_lladdr.addr[5], uip_lladdr.addr[6], uip_lladdr.addr[7]);
  while(1) {
    new_address = 0;
    while(!registered) {
      while(uip_is_addr_unspecified(&rd_server_ipaddr)) {
        status = RD_CLIENT_UNCONFIGURED;
        PROCESS_YIELD();
      }
      status = RD_CLIENT_REGISTERING;
      etimer_set(&et, CLOCK_SECOND);
      PROCESS_YIELD_UNTIL(etimer_expired(&et));
      PRINTF("Registering to ");
      PRINT6ADDR(&rd_server_ipaddr);
      PRINTF(" %d with %s\n", rd_server_port, resources_list);
      coap_init_message(request, COAP_TYPE_CON, COAP_POST, 0);
      coap_set_header_uri_path(request, "rd");
      sprintf(query_buffer, "ep=%s&b=U&lt=%d", rd_client_name, RD_CLIENT_LIFETIME);
      coap_set_header_uri_query(request, query_buffer);
      coap_set_payload(request, (uint8_t *) resources_list, resources_list_size);

      COAP_BLOCKING_REQUEST_BLOCK_RESPONSE(coap_default_context, &rd_server_ipaddr, UIP_HTONS(rd_server_port), request, client_registration_request_handler, client_registration_response_handler);
    }
    status = RD_CLIENT_REGISTERED;
    etimer_set(&et, RD_CLIENT_LIFETIME * CLOCK_SECOND / 10 * 9);
    PROCESS_YIELD_UNTIL(etimer_expired(&et) || new_address);
    registered = 0;

    if(!new_address) {
      PRINTF("Update endpoint %s\n", registration_name);
      coap_init_message(request, COAP_TYPE_CON, COAP_PUT, 0);
      coap_set_header_uri_path(request, registration_name);
      sprintf(query_buffer, "b=U&lt=%d", RD_CLIENT_LIFETIME);
      coap_set_header_uri_query(request, query_buffer);

      COAP_BLOCKING_REQUEST(coap_default_context, &rd_server_ipaddr, UIP_HTONS(rd_server_port), request, client_update_response_handler);
    }
  }

  PROCESS_END();
}
Beispiel #3
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(cc1101_process, ev, data)
{

  PROCESS_POLLHANDLER(pollhandler());

  PROCESS_BEGIN();

#if 0
  while(1) {
    static struct etimer et;
    uint8_t rxbytes, txbytes;
    etimer_set(&et, CLOCK_SECOND * 4);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
    //    cc1101_rx_interrupt();
    burst_read(CC1101_RXBYTES, &rxbytes, 1);
    burst_read(CC1101_TXBYTES, &txbytes, 1);
    printf("state 0x%02x rxbytes 0x%02x txbytes 0x%02x\n",
     state(), rxbytes, txbytes);
    on();
  }
#endif /* 0 */

  PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_EXIT);

  PROCESS_END();
}
Beispiel #4
0
/* Process to handle input packets
 * Receive interrupts cause this process to be polled
 * It calls the core MAC layer which calls rf230_read to get the packet
*/
PROCESS_THREAD(nrf24l01_process, ev, data)
{
  PROCESS_BEGIN();
  
  while(1) 
  {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
    
#if RF230_TIMETABLE_PROFILING
    TIMETABLE_TIMESTAMP(rf230_timetable, "poll");
#endif /* RF230_TIMETABLE_PROFILING */
        
    if(receiver_callback != NULL) 
    {
      receiver_callback(&nrf24l01_driver);
	  
#if RF230_TIMETABLE_PROFILING
      TIMETABLE_TIMESTAMP(rf230_timetable, "end");
      timetable_aggregate_compute_detailed(&aggregate_time,
					   &rf230_timetable);
      timetable_clear(&rf230_timetable);
#endif /* RF230_TIMETABLE_PROFILING */
    } 
    else 
    {
      PRINTF("nrf24l01_process not receiving function\n");
      //flushrx();
    }
  }

  PROCESS_END();
}
Beispiel #5
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(uz2400_process, ev, data)
{
  int len;
  PROCESS_BEGIN();

  PRINTF("uz2400_process: started\n");

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
//#if UZ2400_TIMETABLE_PROFILING
//    TIMETABLE_TIMESTAMP(uz2400_timetable, "poll");
//#endif /* UZ2400_TIMETABLE_PROFILING */

    PRINTF("uz2400_process: calling receiver callback\n");

    packetbuf_clear();
    packetbuf_set_attr(PACKETBUF_ATTR_TIMESTAMP, last_packet_timestamp);
    
    len = uz2400_read(packetbuf_dataptr(), PACKETBUF_SIZE);
    packetbuf_set_datalen(len);

    NETSTACK_RDC.input();
    /* flushrx(); */
//#if UZ2400_TIMETABLE_PROFILING
//    TIMETABLE_TIMESTAMP(uz2400_timetable, "end");
//    timetable_aggregate_compute_detailed(&aggregate_time,
//                                         &uz2400_timetable);
//    timetable_clear(&uz2400_timetable);
//#endif /* UZ2400_TIMETABLE_PROFILING */
	//EXTI4_ClearBit();
  }

  PROCESS_END();
}
Beispiel #6
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(cc2420_process, ev, data)
{
  PROCESS_BEGIN();

  PRINTF("cc2420_process: started\n");
  
  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
#if CC2420_TIMETABLE_PROFILING
    TIMETABLE_TIMESTAMP(cc2420_timetable, "poll");
#endif /* CC2420_TIMETABLE_PROFILING */
        
    if(receiver_callback != NULL) {
      PRINTF("cc2420_process: calling receiver callback\n");
      receiver_callback(&cc2420_driver);
#if CC2420_TIMETABLE_PROFILING
      TIMETABLE_TIMESTAMP(cc2420_timetable, "end");
      timetable_aggregate_compute_detailed(&aggregate_time,
					   &cc2420_timetable);
      timetable_clear(&cc2420_timetable);
#endif /* CC2420_TIMETABLE_PROFILING */
    } else {
      PRINTF("cc2420_process not receiving function\n");
      flushrx();
    }
  }

  PROCESS_END();
}
Beispiel #7
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(etimer_test_process, ev, data)
{
  PROCESS_BEGIN();

  TEST_BEGIN("etimer-test");

  static int idx;

  for(idx = 0; idx < TEST_CONF_ETIMERS; idx++) {
    etimer_set(&et[idx], times[idx]);
  }

  idx = 0;
  while(running) {

    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_TIMER);

    printf("event arrived from\n", data);
    // check if events arrive in the same order we placed them
    TEST_EQUALS((struct etimer*) data - &et[0], evt_orders[idx++]);

    if (idx == TEST_CONF_ETIMERS) {
      TESTS_DONE();
    }

  }

  TEST_END();


  PROCESS_END();
}
Beispiel #8
0
PROCESS_THREAD(cloudcomm_test, ev, data) {
	// lets us know that we can keep transmitting
	PROCESS_BEGIN();
	uint8_t i = 0;
	cloudcomm_set_packet_length(sizeof(opo_data_t));
	simplestore_clear_flash_chip();

	m.dest = &murl[0];
	m.dest_len = 34;
	cloudcomm_set_metainfo(&m);

	cctestvtimer = get_vtimer(vcallback);
	schedule_vtimer(&cctestvtimer, VTIMER_SECOND * 10);
	PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
	request_cloudcomm_data(CLOUDCOMM_REQ_TIME); 
	leds_on(LEDS_GREEN);
	for(i=0;i<24;i++) {
		test[i].version_num = 0xaabb;
		test[i].rx_id = i;
		test[i].tx_id = 0x02;
		test[i].range_dt = 0xbbccddee;
		test[i].ul_dt = 0x00;
		test[i].m_unixtime = 0;
		test[i].m_time_confidence = 1;
		test[i].failed_rx_count = 2;
		test[i].tx_unixtime = 3;
		test[i].tx_time_confidence = 4;
		test[i].ul_rf_dt = 5;
		cloudcomm_store(&test[i]);
	}

	cloudcomm_on(woot, 30000);

	PROCESS_END();
}
Beispiel #9
0
PROCESS_THREAD(ctimer_process, ev, data)
{
  struct ctimer *c;
  PROCESS_BEGIN();

  for(c = list_head(ctimer_list); c != NULL; c = c->next) {
    etimer_set(&c->etimer, c->etimer.tmr.interval);
  }
  initialized = 1;

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_TIMER);
    for(c = list_head(ctimer_list); c != NULL; c = c->next) {
      if(&c->etimer == data) {
	list_remove(ctimer_list, c);
	PROCESS_CONTEXT_BEGIN(c->p);
	if(c->f != NULL) {
	  c->f(c->ptr);
	}
	PROCESS_CONTEXT_END(c->p);
	break;
      }
    }
  }
  PROCESS_END();
}
Beispiel #10
0
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(rx_data_process, ev, data)
{
  PROCESS_BEGIN();
  
  /* Process is polled whenever data is available from uart isr */
  uint8_t c;

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
    /* Read RX ringbuffer. ASCII chars Output when LF is seen. 
       If overflowed, strings are skipped */ 
    do {
      if (get_ringbuf(&c) == -1) {
        break;    /* No more rx char's in ringbuffer */
      } else {
        if (rx_buf_index == RX_BUFFER_SIZE) {   /* Skip current content if buffer full */
          rx_buf_index = 0;
        } 
        rx_buf[rx_buf_index++] = c;
        if ((c == '\n')||(c == '\r')) {
          rx_buf[rx_buf_index] = '\0';
          printf("RX on UART1: %s", rx_buf);   
          /* Signal event to coap clients.
             Demo assumes data is consumed before new data comes in */
          event_coap_rx_uart1_handler();     
          rx_buf_index = 0;      
        }
      }
    } while (1);
  }
  PROCESS_END();
}
Beispiel #12
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(stm32w_radio_process, ev, data)
{
  int len;
  PROCESS_BEGIN();
  PRINTF("stm32w_radio_process: started\r\n");

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
    PRINTF("stm32w_radio_process: calling receiver callback\r\n");

#if DEBUG > 1
    for(uint8_t c = 1; c <= RCVD_PACKET_LEN; c++) {
      PRINTF("%x", stm32w_rxbuf[c]);
    }
    PRINTF("\r\n");
#endif

    packetbuf_clear();
    len = stm32w_radio_read(packetbuf_dataptr(), PACKETBUF_SIZE);
    if(len > 0) {
      packetbuf_set_datalen(len);
      NETSTACK_RDC.input();
    }
    if(!RXBUFS_EMPTY()) {
      /*
       * Some data packet still in rx buffer (this happens because process_poll
       * doesn't queue requests), so stm32w_radio_process needs to be called
       * again.
       */
      process_poll(&stm32w_radio_process);
    }
  }
  PROCESS_END();
}
Beispiel #13
0
/**
 * \brief      Radio RF233 process, infinitely awaits a poll, then checks radio
 *             state and handles received data.
 */
PROCESS_THREAD(rf233_radio_process, ev, data)
{
  int len;
  PROCESS_BEGIN();
  PRINTF("RF233: started.\r\n");

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
    PRINTF("RF233: polled.\r\n");

    if(interrupt_callback_wants_poll) {
      rf233_interrupt_poll();
    }

    packetbuf_clear();
    // packetbuf_set_attr(PACKETBUF_ATTR_TIMESTAMP, last_packet_timestamp);
    len = rf233_read(packetbuf_dataptr(), PACKETBUF_SIZE);
    if(len > 0) {
      packetbuf_set_datalen(len);
      NETSTACK_RDC.input();
    } else {
      PRINTF("RF233: error while reading: %d\r\n", len);
    }
  }
  PROCESS_END();
}
Beispiel #14
0
PROCESS_THREAD(sync_master, ev, data)
{
  static int i=0;
  static struct uip_udp_conn *udp;

  PROCESS_BEGIN();
    
  udp = udp_new(NULL, UIP_HTONS(10000), NULL);
  uip_udp_bind(udp, UIP_HTONS(10000));
  uart0_init(1000000);

  while(1)
  {
    PROCESS_YIELD_UNTIL(ev == tcpip_event);
    int i;
    for (i = 0; i < 16; i++)
      uart0_writeb(UDP_HDR->srcipaddr.u8[i]);
    for (i = 0; i < uip_datalen(); i++)
    {
      uart0_writeb(((uint8_t*)uip_appdata)[i]);
    }
  }

  PROCESS_END();
}
Beispiel #15
0
/* The main TSCH process */
PROCESS_THREAD(tsch_process, ev, data)
{
  static struct pt scan_pt;

  PROCESS_BEGIN();

  while(1) {

    while(!tsch_is_associated) {
      if(tsch_is_coordinator) {
        /* We are coordinator, start operating now */
        tsch_start_coordinator();
      } else {
        /* Start scanning, will attempt to join when receiving an EB */
        PROCESS_PT_SPAWN(&scan_pt, tsch_scan(&scan_pt));
      }
    }

    /* We are part of a TSCH network, start slot operation */
    tsch_slot_operation_start();

    /* Yield our main process. Slot operation will re-schedule itself
     * as long as we are associated */
    PROCESS_YIELD_UNTIL(!tsch_is_associated);

    /* Will need to re-synchronize */
    tsch_reset();
  }

  PROCESS_END();
}
Beispiel #16
0
PROCESS_THREAD(opo8001rxtx, ev, data) {
	PROCESS_BEGIN();
	register_opo_rx_callback((opo_rx_callback_t) opo_rx_callback);
	register_opo_tx_callback(opo_tx_callback);
	tx_delay = get_vtimer(tx_delay_callback);
	process_start(&opo8001rx, NULL);
	process_start(&opo8001tx, NULL);
	process_start(&opo8001ccon, NULL);

	cc_metadata.dest = &murl[0];
	cc_metadata.dest_len = 34;
	cloudcomm_set_packet_length(sizeof(opo_data_t));
	cloudcomm_set_metainfo(&cc_metadata);
	char buffer[50];
	snprintf(buffer, 50, "Opo Data Size: %u", sizeof(opo_data_t));
	send_rf_debug_msg(buffer);
	cloudcomm_clear_data();
	cloudcomm_request_data(CLOUDCOMM_REQ_TIME);
	cloudcomm_on(init_callback, 0);
	PROCESS_YIELD_UNTIL(ev==PROCESS_EVENT_POLL);
	unsigned short randtime = generate_rand_tx();
	schedule_vtimer(&tx_delay, VTIMER_SECOND + (VTIMER_SECOND/1000 * randtime));
	enable_opo_rx();
	PROCESS_END();
}
Beispiel #17
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(cc2420_process, ev, data)
{
  int len;
  PROCESS_BEGIN();

  PRINTF("cc2420_process: started\n");

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
#if CC2420_TIMETABLE_PROFILING
    TIMETABLE_TIMESTAMP(cc2420_timetable, "poll");
#endif /* CC2420_TIMETABLE_PROFILING */
    
    PRINTF("cc2420_process: calling receiver callback\n");

    packetbuf_clear();
    packetbuf_set_attr(PACKETBUF_ATTR_TIMESTAMP, last_packet_timestamp);
    len = cc2420_read(packetbuf_dataptr(), PACKETBUF_SIZE);
    
    packetbuf_set_datalen(len);
    
    NETSTACK_RDC.input();
#if CC2420_TIMETABLE_PROFILING
    TIMETABLE_TIMESTAMP(cc2420_timetable, "end");
    timetable_aggregate_compute_detailed(&aggregate_time,
                                         &cc2420_timetable);
      timetable_clear(&cc2420_timetable);
#endif /* CC2420_TIMETABLE_PROFILING */
  }

  PROCESS_END();
}
Beispiel #18
0
PROCESS_THREAD(uwb_process, ev, data)
{
  int len;
  PROCESS_BEGIN();
  UWBPROCESSFLAG(01);

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
    UWBPROCESSFLAG(02);

    if (uwb_fsm != UWB_STATE_RX_PROCESS_POLLED)
      PRINTF("uwb: wrong state in process: %u\n",uwb_fsm);			

    packetbuf_clear();

    len = ram_rx_buffer[2];
    if ((len > 0) && (len < PACKETBUF_SIZE))
    {
      memcpy(packetbuf_dataptr(),&ram_rx_buffer[3],len); 
      packetbuf_set_datalen(len);
      UWBPROCESSFLAG(03);
      NETSTACK_RDC.input();
    }

    /* switch back to listen-state */
    PRINTF("uwb: enabling rx-mode\r\n");
    enable_rx_mode();

    PRINTF("uwb: read: %u bytes\n",len);

    UWBPROCESSFLAG(04);
  }

  PROCESS_END();
}
PROCESS_THREAD(ledtest_process, ev, data)
{
  static struct etimer timer;
  static u8_t i;
  PROCESS_BEGIN();

  for (i=0; i<sizeof(leds); i++) {
    etimer_set(&timer, 500);
    PROCESS_YIELD_UNTIL(ev==PROCESS_EVENT_TIMER);
    leds_on(leds[i]);
  }

  etimer_set(&timer, 500);
  PROCESS_YIELD_UNTIL(ev==PROCESS_EVENT_TIMER);
  leds_off(LEDS_ALL);
  PROCESS_END();
}
Beispiel #20
0
PROCESS_THREAD(glossy_print_stats_process, ev, data)
{
	PROCESS_BEGIN();

	while(1) {
		PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
		// Print statistics only if Glossy is not still bootstrapping.
		if (!GLOSSY_IS_BOOTSTRAPPING()) {
			if (get_rx_cnt()) {	// Packet received at least once.
				// Increment number of successfully received packets.
				packets_received++;
				// Compute latency during last Glossy phase.
				rtimer_clock_t lat = get_t_first_rx_l() - get_t_ref_l();
				// Add last latency to sum of latencies.
				sum_latency += lat;
				// Convert latency to microseconds.
				latency = (unsigned long)(lat) * 1e6 / RTIMER_SECOND;
				// Print information about last packet and related latency.
				printf("Glossy received %u time%s: seq_no %lu, latency %lu.%03lu ms\n",
						get_rx_cnt(), (get_rx_cnt() > 1) ? "s" : "", glossy_data.seq_no,
								latency / 1000, latency % 1000);
			} else {	// Packet not received.
				// Increment number of missed packets.
				packets_missed++;
				// Print failed reception.
				printf("Glossy NOT received\n");
			}
#if GLOSSY_DEBUG
//			printf("skew %ld ppm\n", (long)(period_skew * 1e6) / GLOSSY_PERIOD);
			printf("high_T_irq %u, rx_timeout %u, bad_length %u, bad_header %u, bad_crc %u\n",
					high_T_irq, rx_timeout, bad_length, bad_header, bad_crc);
#endif /* GLOSSY_DEBUG */
			// Compute current average reliability.
			unsigned long avg_rel = packets_received * 1e5 / (packets_received + packets_missed);
			// Print information about average reliability.
			printf("average reliability %3lu.%03lu %% ",
					avg_rel / 1000, avg_rel % 1000);
			printf("(missed %lu out of %lu packets)\n",
					packets_missed, packets_received + packets_missed);
#if ENERGEST_CONF_ON
			// Compute average radio-on time, in microseconds.
			unsigned long avg_radio_on = (unsigned long)GLOSSY_PERIOD * 1e6 / RTIMER_SECOND *
					(energest_type_time(ENERGEST_TYPE_LISTEN) + energest_type_time(ENERGEST_TYPE_TRANSMIT)) /
					(energest_type_time(ENERGEST_TYPE_CPU) + energest_type_time(ENERGEST_TYPE_LPM));
			// Print information about average radio-on time.
			printf("average radio-on time %lu.%03lu ms\n",
					avg_radio_on / 1000, avg_radio_on % 1000);
#endif /* ENERGEST_CONF_ON */
			// Compute average latency, in microseconds.
			unsigned long avg_latency = sum_latency * 1e6 / (RTIMER_SECOND * packets_received);
			// Print information about average latency.
			printf("average latency %lu.%03lu ms\n",
					avg_latency / 1000, avg_latency % 1000);
		}
	}

	PROCESS_END();
}
Beispiel #21
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(node_process, ev, data)
{
  static struct etimer et;
  PROCESS_BEGIN();

  /* 3 possible roles:
   * - role_6ln: simple node, will join any network, secured or not
   * - role_6dg: DAG root, will advertise (unsecured) beacons
   * */
  static int is_coordinator = 0;
  static enum { role_6ln, role_6dr } node_role;
  node_role = role_6ln;

#if CONFIG_VIA_BUTTON
  {
#define CONFIG_WAIT_TIME 10
    SENSORS_ACTIVATE(button_sensor);
    etimer_set(&et, CLOCK_SECOND * CONFIG_WAIT_TIME);

    while(!etimer_expired(&et)) {
      printf("Init: current role: %s. Will start in %u seconds.\n",
             node_role == role_6ln ? "6ln" : "6dr",
             CONFIG_WAIT_TIME);
      PROCESS_WAIT_EVENT_UNTIL(((ev == sensors_event) &&
                                (data == &button_sensor) && button_sensor.value(0) > 0)
                               || etimer_expired(&et));
      if(ev == sensors_event && data == &button_sensor && button_sensor.value(0) > 0) {
        node_role = (node_role + 1) % 2;
        etimer_restart(&et);
      }
    }
  }

#endif /* CONFIG_VIA_BUTTON */

  printf("Init: node starting with role %s\n",
         node_role == role_6ln ? "6ln" : "6dr");

  is_coordinator = node_role > role_6ln;

  if(is_coordinator) {
    uip_ipaddr_t prefix;
    uip_ip6addr(&prefix, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
    rpl_tools_init(&prefix);
  } else {
    rpl_tools_init(NULL);
  }

  /* Print out routing tables every minute */
  etimer_set(&et, CLOCK_SECOND * 60);
  while(1) {
    print_network_status();
    PROCESS_YIELD_UNTIL(etimer_expired(&et));
    etimer_reset(&et);
  }

  PROCESS_END();
}
Beispiel #22
0
PROCESS_THREAD(opo8001rx, ev, data) {
	PROCESS_BEGIN();
	while(1) {
		PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
		cloudcomm_store(&mdata);
		enable_opo_rx();
	}
	PROCESS_END();
}
Beispiel #23
0
PROCESS_THREAD(opo8001ccon, ev, data) {
	PROCESS_BEGIN();
	while(1) {
		PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
		send_rf_debug_msg("Cloudcomm On");
		cloudcomm_on(cloudcomm_callback, 15000);
	}
	PROCESS_END();
}
Beispiel #24
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(motion_int_process, ev, data)
{
    PROCESS_EXITHANDLER();
    PROCESS_BEGIN();

    while(1) {
        PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
        presence_int_callback(0);
    }
    PROCESS_END();
}
Beispiel #25
0
/* switch the radio off */
static int
off(void)
{
  #if NULLRDC_CONF_802154_AUTOACK_HW
  if(rf212_status() != STATE_RX_AACK_ON ) {
  #else
  if(rf212_status() != STATE_RX_ON) {
  #endif
    /* fail, we need the radio transceiver to be in this state */
    return -1;
  }

  /* turn off the radio transceiver */
  ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
  RF212_COMMAND(TRXCMD_TRX_OFF);
  radio_is_on = 0;
  return 0;
}
/*---------------------------------------------------------------------------*/
/* used for indicating that the interrupt wasn't able to read SPI and must be serviced */
static volatile int interrupt_callback_wants_poll = 0;
/* used as a blocking semaphore to indicate that we are currently servicing an interrupt */
static volatile int interrupt_callback_in_progress = 0;

/**
 * \brief      Radio RF212 process, infinitely awaits a poll, then checks radio
 *             state and handles received data.
 */
PROCESS_THREAD(rf212_radio_process, ev, data)
{
  int len;
  PROCESS_BEGIN();
  PRINTF("RF212: started.\n");

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
    PRINTF("RF212: polled.\n");

    if(interrupt_callback_wants_poll) {
      rf212_interrupt_poll();
    }

    packetbuf_clear();
    // packetbuf_set_attr(PACKETBUF_ATTR_TIMESTAMP, last_packet_timestamp);
    len = rf212_read(packetbuf_dataptr(), PACKETBUF_SIZE);
    if(len > 0) {
      packetbuf_set_datalen(len);
      NETSTACK_RDC.input();
    } else {
      PRINTF("RF212: error while reading: %d\n", len);
    }
  }
  PROCESS_END();
}
Beispiel #26
0
/* A process that is polled from interrupt and calls tx/rx input
 * callbacks, outputs pending logs. */
PROCESS_THREAD(tsch_pending_events_process, ev, data)
{
  PROCESS_BEGIN();
  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
    tsch_rx_process_pending();
    tsch_tx_process_pending();
    tsch_log_process_pending();
  }
  PROCESS_END();
}
Beispiel #27
0
/*
 * This is the process thread that will handle the receive event. It will
 * just post an event to the mac process when a receive event occurs.s
 */
PROCESS_THREAD(drvr_process, ev, data)
{
	PROCESS_BEGIN();

	while (1) {
		PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
		process_post(&mac_process, event_mac_rx, NULL);
	}

	PROCESS_END();
}
Beispiel #28
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(slip_process, ev, data)
{
  PROCESS_BEGIN();

  rxbuf_init();

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);

    slip_active = 1;

    /* Move packet from rxbuf to buffer provided by uIP. */
    uip_len = slip_poll_handler(&uip_buf[UIP_LLH_LEN],
				UIP_BUFSIZE - UIP_LLH_LEN);
#if !UIP_CONF_IPV6
    if(uip_len == 4 && strncmp((char*)&uip_buf[UIP_LLH_LEN], "?IPA", 4) == 0) {
      char buf[8];
      memcpy(&buf[0], "=IPA", 4);
      memcpy(&buf[4], &uip_hostaddr, 4);
      if(input_callback) {
	input_callback();
      }
      slip_write(buf, 8);
    } else if(uip_len > 0
       && uip_len == (((u16_t)(BUF->len[0]) << 8) + BUF->len[1])
       && uip_ipchksum() == 0xffff) {
#define IP_DF   0x40
      if(BUF->ipid[0] == 0 && BUF->ipid[1] == 0 && BUF->ipoffset[0] & IP_DF) {
	static u16_t ip_id;
	u16_t nid = ip_id++;
	BUF->ipid[0] = nid >> 8;
	BUF->ipid[1] = nid;
	nid = uip_htons(nid);
	nid = ~nid;		/* negate */
	BUF->ipchksum += nid;	/* add */
	if(BUF->ipchksum < nid) { /* 1-complement overflow? */
	  BUF->ipchksum++;
	}
      }
      tcpip_input();
    } else {
      uip_len = 0;
      SLIP_STATISTICS(slip_ip_drop++);
    }
#else /* UIP_CONF_IPV6 */
    if(uip_len > 0) {
      if(input_callback) {
        input_callback();
      }
      tcpip_input();
    }
#endif /* UIP_CONF_IPV6 */
  }
Beispiel #29
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(delete_process, ev, data)
{
  static struct etimer update_check_timer;
  static struct etimer update_send_timer;
  static struct akes_nbr_entry *next;

  PROCESS_BEGIN();

  PRINTF("akes-delete: Started update_process\n");
  etimer_set(&update_check_timer, UPDATE_CHECK_INTERVAL * CLOCK_SECOND);

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&update_check_timer));
    PRINTF("akes-delete: #permanent = %d\n", akes_nbr_count(AKES_NBR_PERMANENT));
    next = akes_nbr_head();
    while(next) {
      if(!next->permanent || !akes_nbr_is_expired(next, AKES_NBR_PERMANENT)) {
        next = akes_nbr_next(next);
        continue;
      }

      /* wait for a random period of time to avoid collisions */
      etimer_set(&update_send_timer, akes_get_random_waiting_period());
      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&update_send_timer));

      /* check if something happened in the meantime */
      if(!akes_nbr_is_expired(next, AKES_NBR_PERMANENT)) {
        next = akes_nbr_next(next);
        continue;
      }

      /* send UPDATE */
      akes_send_update(next);
      PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
      PRINTF("akes-delete: Sent UPDATE\n");
      etimer_set(&update_send_timer, UPDATEACK_WAITING_PERIOD * CLOCK_SECOND);
      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&update_send_timer));
      if(akes_nbr_is_expired(next, AKES_NBR_PERMANENT)) {
        akes_nbr_delete(next, AKES_NBR_PERMANENT);
        next = akes_nbr_head();
      } else {
        next = akes_nbr_next(next);
      }
    }
    etimer_restart(&update_check_timer);
  }

  PROCESS_END();
}
PROCESS_THREAD(end_node_process, ev, data)
{
    PROCESS_BEGIN();
    static struct etimer et;
    etimer_set(&et, CLOCK_SECOND);

    printf("Using NodeId: %X\n\r", get_nodeid());

    /* Turn off AES */
    netstack_aes_set_active(1);

    /* Allocate events */
    reconnect_event = process_alloc_event();

    /* Reconnect from here */

    while(1) {
        if(simple_rpl_parent() == NULL) {

            printf("\r\n Connecting to a Wireless Network...\r\n");
            etimer_set(&et, CLOCK_SECOND / 1);
            while(simple_rpl_parent() == NULL) {
                PROCESS_YIELD_UNTIL(etimer_expired(&et));
                etimer_reset(&et);
            }
            printf("\r\n Connected to Wireless network\r\n");
        }

        process_start(&prox_agent_process, NULL);

        /* Reset reconnecting flag */
        reconnecting = 0;

        /* Main loop */
        while(1) {

            PROCESS_WAIT_EVENT();
            if(ev == reconnect_event) {
                reconnecting = 1;
                etimer_set(&reconnect_timer, CLOCK_SECOND*10);
            }
            if(reconnecting &&
                    etimer_expired(&reconnect_timer)) {
                break;
            }
        }
    }
    PROCESS_END();
}