Example #1
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_timestamp_process, ev, data)
{
  struct msg {
    uint16_t len;
    uint16_t time[2];
    uint16_t timesynch;
    uint8_t data[MAX_COMMANDLENGTH];
  } msg;

  PROCESS_BEGIN();

  while(1) {
    struct shell_input *input;
    PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
    input = data;
    if(input->len1 + input->len2 == 0) {
      PROCESS_EXIT();
    }

    msg.len = 3 + *(uint16_t *)input->data1;
    msg.time[0] = (uint16_t)(shell_time() >> 16);
    msg.time[1] = (uint16_t)(shell_time());
#if TIMESYNCH_CONF_ENABLED
    msg.timesynch = timesynch_time();
#else /* TIMESYNCH_CONF_ENABLED */
    msg.timesynch = 0;
#endif /* TIMESYNCH_CONF_ENABLED */
    memcpy(msg.data, input->data1 + 2,
	   input->len1 - 2 > MAX_COMMANDLENGTH?
	   MAX_COMMANDLENGTH: input->len1 - 2);

    shell_output(&timestamp_command, &msg, 6 + input->len1,
		 input->data2, input->len2);
  }

  PROCESS_END();
}
PROCESS_THREAD(cc26xx_demo_process, ev, data)
{
  PROCESS_EXITHANDLER(broadcast_close(&bc))

  PROCESS_BEGIN();

  gpio_relay_init();
  relay_all_clear();
  
  
  counter = 0;
  broadcast_open(&bc, BROADCAST_CHANNEL, &bc_rx);

  etimer_set(&et, CLOCK_SECOND);
  
  while(1) {

    PROCESS_YIELD();

    if(ev == PROCESS_EVENT_TIMER) {
      leds_on(LEDS_PERIODIC);
     
      etimer_set(&et, CLOCK_SECOND*5);
      rtimer_set(&rt, RTIMER_NOW() + LEDS_OFF_HYSTERISIS, 1,
                 rt_callback, NULL);
      counter = Get_ADC_reading();
      packetbuf_copyfrom(&counter, sizeof(counter));
      broadcast_send(&bc);
     // printf("adc data value : %d \r\n",counter);
        
    } 
     watchdog_periodic();
  }

  PROCESS_END();
}
Example #3
0
/* Process to get ht sensor value.
   ht sensor is sampled. Sampling stopped when sensor is de-activated.
   Event is generated if temp and/or hum value changed at least the value DELTA_TEMP_SENSOR_VALUE
   or DELTA_HUM_SENSOR_VALUE since last event. */
PROCESS_THREAD(HTSensorSampling, ev, data)
{
  PROCESS_BEGIN();
  static struct etimer et;

  etimer_set(&et, CLOCK_SECOND);
  while(1) {
    PROCESS_WAIT_EVENT_UNTIL((ev == PROCESS_EVENT_TIMER) || (ev == PROCESS_EVENT_MSG));
    if(ev == PROCESS_EVENT_TIMER) {
      /* Handle sensor reading. */
      vHTSstartReadTemp();
      temp_sensor_value = u16HTSreadTempResult();
      PRINTF("Temperature sample: %d\n", temp_sensor_value);
      vHTSstartReadHumidity();
      hum_sensor_value = u16HTSreadHumidityResult();
      PRINTF("Humidity sample: %d\n", hum_sensor_value);
      if((abs(temp_sensor_value - prev_temp_event_val) > DELTA_TEMP_SENSOR_VALUE) ||
         (abs(hum_sensor_value - prev_hum_event_val) > DELTA_HUM_SENSOR_VALUE)) {
        prev_temp_event_val = temp_sensor_value;
        prev_hum_event_val = hum_sensor_value;
        sensors_changed(&ht_sensor);
      }
      etimer_reset(&et);
    } else {
      /* ev == PROCESS_EVENT_MSG */
      if(*(int *)data == HT_SENSOR_STATUS_NOT_ACTIVE) {
        /* Stop sampling */
        etimer_stop(&et);
      } else if((*(int *)data == HT_SENSOR_STATUS_ACTIVE)) {
        /* restart sampling */
        etimer_restart(&et);
      }
    }
  }
  PROCESS_END();
}
Example #4
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(sky_shell_process, ev, data)
{
  PROCESS_BEGIN();

  serial_shell_init();
  /*shell_blink_init();*/
  shell_file_init();
  shell_coffee_init();
  /*shell_ps_init();*/
  /*shell_reboot_init();*/
  /*shell_rime_init();*/
  /*shell_rime_netcmd_init();*/
  /*shell_rime_ping_init();*/
  /*shell_rime_debug_init();*/
  /*shell_rime_sniff_init();*/
  /*shell_sky_init();*/
  shell_text_init();
  /*shell_time_init();*/
  /*  shell_checkpoint_init();*/
  shell_exec_init();
  shell_base64_init();

  PROCESS_END();
}
Example #5
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(wpcap_process, ev, data)
{
  PROCESS_POLLHANDLER(pollhandler());

  PROCESS_BEGIN();

  wpcap_init();

#if !UIP_CONF_IPV6
  tcpip_set_outputfunc(wpcap_output);
#else
#if !FALLBACK_HAS_ETHERNET_HEADERS
  tcpip_set_outputfunc(wpcap_send);
#endif
#endif /* !UIP_CONF_IPV6 */

  process_poll(&wpcap_process);

  PROCESS_WAIT_UNTIL(ev == PROCESS_EVENT_EXIT);

  wpcap_exit();

  PROCESS_END();
}
Example #6
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(sensor_output_process, ev, data)
{
  struct sensors_sensor *s;

  PROCESS_BEGIN();

  /* Activate some sensors to get sensor events */
  button_sensor.configure(SENSORS_ACTIVE, 1);
  pir_sensor.configure(SENSORS_ACTIVE, 1);
  vib_sensor.configure(SENSORS_ACTIVE, 1);

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event);

    s = (struct sensors_sensor *)data;
    printf("%s %d\n", s->type, s->value(0));

    if (data == &button_sensor) leds_invert(LEDS_YELLOW);
    if (data == &pir_sensor) leds_invert(LEDS_GREEN);
    if (data == &vib_sensor) leds_invert(LEDS_RED);
  }

  PROCESS_END();
}
Example #7
0
PROCESS_THREAD(accel_process, ev, data) {
  PROCESS_BEGIN();
  {
    int16_t x, y, z;

    serial_shell_init();
    shell_ps_init();
    shell_file_init();  // for printing out files
    shell_text_init();  // for binprint

    /* Register the event used for lighting up an LED when interrupt strikes. */
    ledOff_event = process_alloc_event();

    /* Start and setup the accelerometer with default values, eg no interrupts enabled. */
    accm_init();

    /* Register the callback functions for each interrupt */
    ACCM_REGISTER_INT1_CB(accm_ff_cb);
    ACCM_REGISTER_INT2_CB(accm_tap_cb);

    /* Set what strikes the corresponding interrupts. Several interrupts per pin is 
      possible. For the eight possible interrupts, see adxl345.h and adxl345 datasheet. */
    accm_set_irq(ADXL345_INT_FREEFALL, ADXL345_INT_TAP + ADXL345_INT_DOUBLETAP);

    while (1) {
	    x = accm_read_axis(X_AXIS);
	    y = accm_read_axis(Y_AXIS);
	    z = accm_read_axis(Z_AXIS);
	    printf("x: %d y: %d z: %d\n", x, y, z);

      etimer_set(&et, ACCM_READ_INTERVAL);
      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
    }
  }
  PROCESS_END();
}
Example #8
0
/* periodic broadcast light sensor data */
PROCESS_THREAD(spam_process, ev, data) {

	PROCESS_BEGIN();
	SENSORS_ACTIVATE(light_sensor);

	// init
	leds_off(LEDS_ALL);
	int light_val = 0;

	while(1) {
		// wait a bit
		static struct etimer et;
		etimer_set(&et, 1 * CLOCK_SECOND / 2);
		PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

		// send packet
		light_val = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
		packetbuf_copyfrom(&light_val, sizeof(int));
		broadcast_send(&broadcast_connection);
	}

	SENSORS_DEACTIVATE(light_sensor);
	PROCESS_END();
}
Example #9
0
/**
 * \brief A process that handles adding/removing
 *        BLE IPSP interfaces.
 */
PROCESS_THREAD(ble_iface_observer, ev, data)
{
  static struct etimer led_timer;

  PROCESS_BEGIN();

  etimer_set(&led_timer, CLOCK_SECOND/2);

  while(1) {
    PROCESS_WAIT_EVENT();
    if(ev == ble_event_interface_added) {
      etimer_stop(&led_timer);
      leds_off(LEDS_1);
      leds_on(LEDS_2);
    } else if(ev == ble_event_interface_deleted) {
      etimer_set(&led_timer, CLOCK_SECOND/2);
      leds_off(LEDS_2);
    } else if(ev == PROCESS_EVENT_TIMER && etimer_expired(&led_timer)) {
      etimer_reset(&led_timer);
      leds_toggle(LEDS_1);
    }
  }
  PROCESS_END();
}
Example #10
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_send_process, ev, data)
{
  struct shell_input *input;
  int len;
  struct collect_msg *msg;
  
  PROCESS_BEGIN();

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
    input = data;

    len = input->len1 + input->len2;

    if(len == 0) {
      PROCESS_EXIT();
    }

    if(len < PACKETBUF_SIZE) {
      packetbuf_clear();
      packetbuf_set_datalen(len + COLLECT_MSG_HDRSIZE);
      msg = packetbuf_dataptr();
      memcpy(msg->data, input->data1, input->len1);
      memcpy(msg->data + input->len1, input->data2, input->len2);
#if TIMESYNCH_CONF_ENABLED
      msg->timestamp = timesynch_time();
#else
      msg->timestamp = 0;
#endif
      msg->crc = crc16_data(msg->data, len, 0);
      /*      printf("Sending %d bytes\n", len);*/
      collect_send(&collect, COLLECT_REXMITS);
    }
  }
  PROCESS_END();
}
Example #11
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_process_sender, ev, data)
{
  uip_ipaddr_t ipaddr;

  PROCESS_BEGIN();
  PRINTF("Process test UDP sender started\n");

  PRINTF("Local IPv6 address: ");
  PRINT6ADDR(&uip_netif_physical_if.addresses[0].ipaddr);
  PRINTF("\n");

#ifdef UDP_ADDR_A
  uip_ip6addr(&ipaddr,
      UDP_ADDR_A,UDP_ADDR_B,UDP_ADDR_C,UDP_ADDR_D,
      UDP_ADDR_E,UDP_ADDR_F,UDP_ADDR_G,UDP_ADDR_H);
#else /* UDP_ADDR_A */
  uip_ip6addr(&ipaddr,0xfe80,0,0,0,0x6466,0x6666,0x6666,0x6666);
#endif /* UDP_ADDR_A */

  /* new connection with remote host */
  udpconn = udp_new(&ipaddr, HTONS(0xF0B0), NULL);
  udp_bind(udpconn, HTONS(0xF0B0+1));

  PRINTF("Created connection with remote peer ");
  PRINT6ADDR(&udpconn->ripaddr);
  PRINTF("local/remote port %u/%u\n", HTONS(udpconn->lport),HTONS(udpconn->rport));

  etimer_set(&udp_periodic_timer, 15*CLOCK_SECOND);

  while(1) {
    PROCESS_YIELD();
    udphandler(ev, data);
  }

  PROCESS_END();
}
Example #12
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(sensors_process, ev, data)
{
  static int i;
  static int events;

  PROCESS_BEGIN();

  sensors_event = process_alloc_event();

  
  for(i = 0; sensors[i] != NULL; ++i) {
    sensors_flags[i] = 0;
    sensors[i]->configure(SENSORS_HW_INIT, 0);
  }
  num_sensors = i;

  while(1) {

    PROCESS_WAIT_EVENT();

    do {
      events = 0;
      for(i = 0; i < num_sensors; ++i) {
	if(sensors_flags[i] & FLAG_CHANGED) {
	  if(process_post(PROCESS_BROADCAST, sensors_event, (void *)sensors[i]) == PROCESS_ERR_OK) {
	    PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event);
	  }
	  sensors_flags[i] &= ~FLAG_CHANGED;
	  events++;
	}
      }
    } while(events);
  }

  PROCESS_END();
}
Example #13
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(settings_delete_process, ev, data)
{
  PROCESS_BEGIN();

#if (APP_SETTINGS_DELETE == 1)
  // Delete all Settings if no value is defined
#if !defined(NODE_CONF_ID) && !defined(RADIO_CONF_PAN_ID) && !defined(RADIO_CONF_CHANNEL) && !defined(RADIO_CONF_TX_POWER) && !defined(NODE_CONF_EUI64)
  PRINTF("Wiping settings...");
  settings_wipe();
  PRINTF("done.\n");
#else /* !defined(NODE_CONF_ID) && !defined(RADIO_CONF_CHANNEL) && !defined(RADIO_CONF_TX_POWER) */
// NOTE: currently deleting single items is disabled as the library does not provide it!
// TODO: Check Roberts implementation for delete function
#error Settings manager does not support deleting single items yet. Try wipe instead.
#ifdef NODE_CONF_ID
  PRINTF("[APP.settings-delete] node id delete status: %s\n", settings_delete(SETTINGS_KEY_PAN_ADDR, 0) == SETTINGS_STATUS_OK ? "OK" : "FAILED");
  //_do_delete("node id", SETTINGS_KEY_PAN_ADDR);
#endif
#ifdef RADIO_CONF_PAN_ID
  PRINTF("[APP.settings-delete] pan id delete status: %d\n", settings_delete(SETTINGS_KEY_PAN_ID, 0) == SETTINGS_STATUS_OK ? 1 : 0);
#endif
#ifdef RADIO_CONF_CHANNEL
  PRINTF("[APP.settings-delete] channel delete status: %d\n", settings_delete(SETTINGS_KEY_CHANNEL, 0) == SETTINGS_STATUS_OK ? 1 : 0);
#endif
#ifdef RADIO_CONF_TX_POWER
  PRINTF("[APP.settings-delete] tx power delete status: %d\n", settings_delete(SETTINGS_KEY_TXPOWER, 0) == SETTINGS_STATUS_OK ? 1 : 0);
#endif
#ifdef NODE_CONF_EUI64
  PRINTF("[APP.settings-delete] EUI64 delete status: %d\n", settings_delete(SETTINGS_KEY_EUI64, 0) == SETTINGS_STATUS_OK ? 1 : 0);
#endif
#endif /* !defined(NODE_CONF_ID) && !defined(RADIO_CONF_PAN_ID) && !defined(RADIO_CONF_CHANNEL) && !defined(RADIO_CONF_TX_POWER) && !defined(NODE_CONF_EUI64) */

#endif /* (APP_SETTINGS_DELETE == 1) */

  PROCESS_END();
}
Example #14
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(tcpip_process, ev, data)
{
	PROCESS_BEGIN();

#if UIP_TCP
	{
		static unsigned char i;

		for(i = 0; i < UIP_LISTENPORTS; ++i) {
			s.listenports[i].port = 0;
		}
		s.p = PROCESS_CURRENT();
	}
#endif

	tcpip_event = process_alloc_event();
#if UIP_CONF_ICMP6
	tcpip_icmp6_event = process_alloc_event();
#endif /* UIP_CONF_ICMP6 */
	etimer_set(&periodic, CLOCK_SECOND / 2);
	uip_init();
#ifdef UIP_FALLBACK_INTERFACE
	UIP_FALLBACK_INTERFACE.init();
#endif
/* initialize RPL if configured for using RPL */
#if UIP_CONF_IPV6 && UIP_CONF_IPV6_RPL
	rpl_init();
#endif /* UIP_CONF_IPV6_RPL */

	while(1) {
		PROCESS_YIELD();
  		eventhandler(ev, data);
	}

	PROCESS_END();
}
Example #15
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(netperf_shell_process, ev, data)
{
  PROCESS_BEGIN();

  serial_shell_init();
  shell_blink_init();
  /*  shell_file_init();
      shell_coffee_init();*/
  /*  shell_download_init();
      shell_rime_sendcmd_init();*/
  shell_ps_init();
  shell_reboot_init();
  shell_rime_init();
  shell_rime_netcmd_init();
  shell_rime_ping_init();
  shell_rime_debug_init(); 
  shell_rime_sniff_init();
  shell_text_init();
  shell_time_init();
  shell_sendtest_init();
  shell_netperf_init();

  PROCESS_END();
}
Example #16
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 need to be called again.
      process_poll(&stm32w_radio_process);
    }
  }

  PROCESS_END();
}
Example #17
0
PROCESS_THREAD(shell_bc_open_process, ev, data)
{
  uint16_t channel;
  long channel_long;
  const char *next;
  char buf[6];
  PROCESS_BEGIN();

  channel_long = shell_strtolong((char *)data, &next);
  if(channel_long <= 0 || channel_long > 65535){
    shell_output_str(&bc_open_command, "channel has to be in range of [1-65535]", "");
    PROCESS_EXIT();
  }
  channel = (uint16_t) channel_long;
  snprintf(buf, sizeof(buf), "%d", channel);

  struct broadcast_entry *to_add = memb_alloc(&broadcast_mem);
  list_add(broadcast_list, to_add);
  to_add->channel = channel;
  broadcast_open(&to_add->c, channel, &broadcast_callback);
  shell_output_str(&bc_open_command, "opened broadcast connection on channel: ", buf);

  PROCESS_END();
}
Example #18
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(fixed_process, ev, data)
{
  static struct etimer et;
  static uip_ipaddr_t ipaddr;
  PROCESS_BEGIN();

  conn = udp_new(NULL, UIP_HTONS(0), NULL);
  udp_bind(conn, UIP_HTONS(3000));
  memset(history,0,sizeof(history));

  etimer_set(&et, SEND_INTERVAL);
  cur_time = 1;
  while(1) {
    PROCESS_YIELD();
    if(etimer_expired(&et)) {
      timeout_handler();
      etimer_restart(&et);
    } else if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
PROCESS_THREAD(coap_app_client, ev, data)
{
  PROCESS_BEGIN();

  uip_ip6addr_u8(&server_ipaddr,0xfe,0x80,0,0,0,0,0,0,0xc0,0xa0,0x08,0x39,0xd1,0xe4,0x02,0x05);
  /* new connection with server */
  client_conn = udp_new(&server_ipaddr, UIP_HTONS(REMOTE_PORT), NULL);
  udp_bind(client_conn, UIP_HTONS(LOCAL_PORT));

 // UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

  while(1) {
    PROCESS_YIELD();
    if (ev == PROCESS_EVENT_CONTINUE) { 
      send_data();
    } else if (ev == tcpip_event) {
    	sprintf(outStr_buf,"\r\nPacket received\r\n\r\n");
		sendData_inBackground((uint8_t*)outStr_buf,strlen(outStr_buf),1,0);
      //handle_incoming_data();
    }
  }

  PROCESS_END();
}
Example #20
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(temp_filter_process, ev, data)
{
  static struct etimer et;

#define NUMBER_TO_AVERAGE 20
  
  static uint8_t avg = 0;
  static uint8_t n = 0; 
  static uint8_t fake_temp = 17;

  PROCESS_BEGIN();

  while (1) {

    //pretend measurement
    if (n == 0) {
      avg = fake_temp;
    } else {
      avg = (avg * n + fake_temp) / (n + 1);
    }

    n++;

    if (n == NUMBER_TO_AVERAGE) {
      // send here, then reset this crap
      avg = 0;
      n = 0;
    }

    etimer_set(&et, (CLOCK_SECOND * 0.1));

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
  }

  PROCESS_END();
}
Example #21
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(ethernode_uip_process, ev, data)
{
  PROCESS_BEGIN();

  while(1) {
    process_poll(&ethernode_uip_process);
    PROCESS_WAIT_EVENT();
    
    /* Poll Ethernet device to see if there is a frame avaliable. */
    uip_len = ethernode_read(uip_buf, UIP_BUFSIZE);

    if(uip_len > 0) {
      /*      printf("%d: new packet len %d\n", node_id, uip_len);*/

      /*      if((random_rand() % drop) <= drop / 2) {
	printf("Bropp\n");
	} else*/ {

	uip_len = hc_inflate(&uip_buf[UIP_LLH_LEN], uip_len);

#ifdef __CYGWIN__
	wpcap_send();
#else /* __CYGWIN__ */
	tapdev_send();
#endif /* __CYGWIN__ */
	/*    if(uip_fw_forward() == UIP_FW_LOCAL)*/ {
	  /* A frame was avaliable (and is now read into the uip_buf), so
	     we process it. */
	  tcpip_input();
	}
      }
    }
  }
  PROCESS_END();
    
}
Example #22
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_reboot_process, ev, data)
{
  static struct etimer etimer;
  PROCESS_BEGIN();

  shell_output_str(&reboot_command,
		   "Rebooting the node in four seconds...", "");

  etimer_set(&etimer, CLOCK_SECOND);
  PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
  leds_on(LEDS_RED);
  etimer_reset(&etimer);
  PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
  leds_on(LEDS_GREEN);
  etimer_reset(&etimer);
  PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
  leds_on(LEDS_BLUE);
  etimer_reset(&etimer);
  PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
  
  watchdog_reboot();

  PROCESS_END();
}
Example #23
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer et;

  PROCESS_BEGIN();
  PRINTF("UDP client process started\n");
  dest_addr = malloc(sizeof(uip_ipaddr_t));
  memset(dest_addr, 0, sizeof(uip_ipaddr_t));
#if UDP_CLIENT_AUTOSTART
  udp_client_run=1;
#endif
  etimer_set(&et, udp_interval);
  while(1) {
    PROCESS_YIELD();
    if(etimer_expired(&et)) {
      timeout_handler();
      etimer_set(&et, udp_interval);
    } else if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
Example #24
0
File: app.c Project: copton/ocram
PROCESS_THREAD(collect_process, ev, data)
{
    static struct etimer periodic;

    PROCESS_BEGIN();

    SENSORS_ACTIVATE(light_sensor);

    etimer_set(&periodic, DT_COLLECT);

    while(1) {
        PROCESS_YIELD();
        if(etimer_expired(&periodic)) {
            etimer_reset(&periodic);
            uint16_t value = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
            value = rand(); // enable comparison of logs
            printf("trace: reading value from sensor: %u\n", value);
            ASSERT(offset < MAX_NUMBEROF_VALUES);
            values[offset++] = value;
        }
    }

    PROCESS_END();
}
Example #25
0
/* Implementation of the first process */
PROCESS_THREAD(Vaisala_process, ev, data)
{
// variables are declared static to ensure their values are kept
// between kernel calls.
// any process must start with this.
PROCESS_BEGIN();

//leds_on(LEDS_ALL);
printf("I started \n");
uart0_init(BAUD2UBR(19200));
while (1)
{
// wait here for an event to happen
PROCESS_WAIT_EVENT();
if(ev == serial_line_event_message && data != NULL)
 {
leds_toggle(LEDS_ALL);
// do the process work
printf("I recieved :%s\n",data);
printf("%d",strlen(data));

}
// and loop
/*while(1) {
    static struct etimer et;
    etimer_set(&et, CLOCK_SECOND);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
    leds_on(LEDS_ALL);
    etimer_set(&et, CLOCK_SECOND);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
    leds_off(LEDS_ALL);
  }*/

  PROCESS_END();
}
}
Example #26
0
PROCESS_THREAD(rime_unicast_sender, ev, data)
{
  PROCESS_EXITHANDLER(unicast_close(&uc));
  
  PROCESS_BEGIN();

  leds_init();
  leds_off(LEDS_ALL);
  SENSORS_ACTIVATE(button_sensor);//activate button
  unicast_open(&uc, 290, &unicast_callbacks); // channel = 122

  while(1)
  {
    static struct etimer et;
    rimeaddr_t addr;
    
    PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor);

    //etimer_set(&et, CLOCK_SECOND);
    //PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
		
    packetbuf_copyfrom(SECRET, 15); // String + Length to be send
    //packetbuf_copyfrom("ekhais8ca6Aej0", 15); // String + Length to be send
    
    addr.u8[0] = 0x28; // Address of receiving Node
    addr.u8[1] = 0x1;
    
    if(!rimeaddr_cmp(&addr, &rimeaddr_node_addr))
    {
    	printf("Message sent\n"); // debug message
      unicast_send(&uc, &addr);
    }
  }

  PROCESS_END();
}
/*----------------------------------------------------------------------------*/
PROCESS_THREAD(coap_receiver, ev, data)
{
    PROCESS_BEGIN();
    PRINTF("Starting CoAP-07 receiver...\n");

    rest_activate_resource(&resource_well_known_core);

    coap_register_as_transaction_handler();
    coap_init_connection(SERVER_LISTEN_PORT);
    PRINTF("Listening on port %u\n", UIP_HTONS(SERVER_LISTEN_PORT));

    while(1) {
        PROCESS_YIELD();

        if(ev == tcpip_event) {
            coap_receive();
        } else if (ev == PROCESS_EVENT_TIMER) {
            /* retransmissions are handled here */
            coap_check_transactions();
        }
    } /* while (1) */

    PROCESS_END();
}
Example #28
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_ls_process, ev, data)
{
  static struct cfs_dir dir;
  static cfs_offset_t totsize;
  struct cfs_dirent dirent;
  char buf[32];
  PROCESS_BEGIN();
  
  if(cfs_opendir(&dir, "/") != 0) {
    shell_output_str(&ls_command, "Cannot open directory", "");
  } else {
    totsize = 0;
    while(cfs_readdir(&dir, &dirent) == 0) {
      totsize += dirent.size;
      sprintf(buf, "%lu ", (unsigned long)dirent.size);
      /*      printf("'%s'\n", dirent.name);*/
      shell_output_str(&ls_command, buf, dirent.name);
    }
    cfs_closedir(&dir);
    sprintf(buf, "%lu", (unsigned long)totsize);
    shell_output_str(&ls_command, "Total size: ", buf);
  }
  PROCESS_END();
}
Example #29
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(http_socket_process, ev, data)
{
  PROCESS_BEGIN();

  while(1) {

    PROCESS_WAIT_EVENT();

    if(ev == resolv_event_found && data != NULL) {
      struct http_socket *s;
      const char *name = data;
      /* Either found a hostname, or not. We need to go through the
   list of http sockets and figure out to which connection this
   reply corresponds, then either restart the HTTP get, or kill
   it (if no hostname was found). */
      for(s = list_head(socketlist);
    s != NULL;
    s = list_item_next(s)) {
  char host[MAX_HOSTLEN];
  if(parse_url(s->url, host, NULL, NULL) &&
     strcmp(name, host) == 0) {
    if(resolv_lookup(name, 0) == RESOLV_STATUS_CACHED) {
      /* Hostname found, restart request. */
      start_request(s);
    } else {
      /* Hostname not found, kill connection. */
            call_callback(s, HTTP_SOCKET_HOSTNAME_NOT_FOUND, NULL, 0);
            removesocket(s);
    }
  }
      }
    }
  }

  PROCESS_END();
}
Example #30
0
   PROCESS_THREAD( timer_process, ev, data )
   {
      PROCESS_BEGIN();

      while (1)
      {
         PROCESS_YIELD_UNTIL( ev == PROCESS_EVENT_TIMER );
         for ( int i = 0; i < MAX_REGISTERED_TIMER; i++ )
         {
            struct timer_item *c = &timer_items[i];
            if ( &c->etimer == data )
            {
               PROCESS_CONTEXT_BEGIN( c->p );
               if ( c->cb )
                  c->cb( c->ptr );
               PROCESS_CONTEXT_END( c->p );
               c->cb = contiki_timer_delegate_t();
               break;
            }
         }
      }

      PROCESS_END();
   }