Beispiel #1
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(batmon_process, ev, data)
{

  PROCESS_BEGIN();

  PRINTF("BatMon\n", sizeof(r));

  s = sensors_find(ADC_SENSOR);
  if (!s) {
    PRINTF("BatMon: ADC not found\n");
    PROCESS_EXIT();
  }

  n740_analog_deactivate();
  m25p16_res();
  n740_analog_activate();

  /* Find last written location */
  if(find_gap() == -1) {
    PRINTF("BatMon: Flash storage full\n");
    PROCESS_EXIT();
  }

  etimer_set(&et, BATMON_LOG_PERIOD * CLOCK_SECOND);

  while(1) {
    PROCESS_YIELD();
    if(ev == PROCESS_EVENT_TIMER && etimer_expired(&et)) {
      batmon_log(LOG_TRIGGER_PERIODIC);
    }
  }

  PROCESS_END();
}
Beispiel #2
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_leds_process, ev, data)
{
    struct acc_msg *msg;
    struct shell_input *input;
    int val, i;
    static int num;
    const char *args, *next;

    PROCESS_BEGIN();

    args = data;
    if(args == NULL) {
        shell_output_str(&acc_command, "usage 0", "");
        PROCESS_EXIT();
    }

    num = shell_strtolong(args, &next);
    if(next == args) {
        shell_output_str(&acc_command, "usage 1", "");
        PROCESS_EXIT();
    }

    PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
    input = data;
    msg = (struct acc_msg *)input->data1;
    val = 0;
    for(i = 0; i < msg->acc[num] >> 9; ++i) {
        val = (val << 1) | 1;
    }
    leds_on(val & 0xff);
    leds_off(~(val & 0xff));

    PROCESS_END();
}
Beispiel #3
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_udpsend_process, ev, data)
{
  const char *next, *nextptr;
  struct shell_input *input;
  uint16_t port, local_port;
  
  PROCESS_BEGIN();

  next = strchr(data, ' ');
  if(next == NULL) {
    shell_output_str(&udpsend_command,
		     "udpsend <server> <port> [localport]: server as address", "");
    PROCESS_EXIT();
  }
  ++next;
  strncpy(server, data, sizeof(server));
  port = shell_strtolong(next, &nextptr);

  uiplib_ipaddrconv(server, (u8_t *)&serveraddr);
  udpconn = udp_new(&serveraddr, htons(port), NULL);
  
  if(next != nextptr) {
    local_port = shell_strtolong(nextptr, &nextptr);
    udp_bind(udpconn, htons(local_port));
  }
  running = 1;


  while(running) {
    PROCESS_WAIT_EVENT();

    if(ev == shell_event_input) {
      input = data;
      if(input->len1 + input->len2 == 0) {
	PROCESS_EXIT();
      }

      if(input->len1 > 0) {
	send_line(input->data1, input->len1);
      }
    } else if(ev == tcpip_event) {
      if(uip_newdata()) {
	newdata(uip_appdata, uip_datalen());
      }
#if 0
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
	 resolv_lookup((char *)data) != NULL) {
	uip_ipaddr_copy(serveraddr, ipaddr);
	telnet_connect(&s, server, serveraddr, nick);
      } else {
	shell_output_str(&udpsend_command, "Host not found.", "");
      }
#endif /* 0 */
    }
  }

  PROCESS_END();
}
Beispiel #4
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_peek_process, ev, data)
{
    uint8_t *address;
    const char *args, *next;
    char buf[32];

    PROCESS_BEGIN();

    args = data;

    if(args == NULL) {
        shell_output_str(&peek_command, "usage 0", "");
        PROCESS_EXIT();
    }

    address = (uint8_t *)(int)shell_strtolong(args, &next);
    if(next == args) {
        shell_output_str(&peek_command, "usage 1", "");
        PROCESS_EXIT();
    }

    snprintf(buf, sizeof(buf), "0x%02x", *address);

    shell_output_str(&peek_command, buf, "");

    PROCESS_END();
}
Beispiel #5
0
PROCESS_THREAD(shell_ruc_close_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(&ruc_close_command, "channel has to be in range of [1-65535]", "");
    PROCESS_EXIT();
  }
  channel = (uint16_t) channel_long;
  snprintf(buf, sizeof(buf), "%d", channel);
  struct runicast_entry *e = list_head(runicast_list);
  while(e != NULL){
    if(e->channel == channel){
      struct runicast_entry *to_remove = e;
      e = e->next;
      runicast_close(&to_remove->c);
      list_remove(runicast_list, to_remove);
      memb_free(&runicast_mem, to_remove);
      shell_output_str(&ruc_close_command, "closed unicast connection on channel: ", buf);
      PROCESS_EXIT();
    }
  }
  shell_output_str(&ruc_close_command, "uc_close error: channel not open","");

  PROCESS_END();
}
PROCESS_THREAD(shell_sendfile_process, ev, data)
{
	const char *nextptr;
	static rimeaddr_t addr;
	int len;
	char buf[32];
	PROCESS_BEGIN();
	/* Parse node addr */
	addr.u8[0] = shell_strtolong(data, &nextptr);
	if(nextptr == data || *nextptr != '.') {
	    printf("sendfile <node addr> <filename>: need node address\n");
	    PROCESS_EXIT();
	}
	++nextptr;
	addr.u8[1] = shell_strtolong(nextptr, &nextptr);
	printf("\nnode address: %d.%d\n", addr.u8[0], addr.u8[1]);

	while(nextptr[0] == ' ') nextptr++;
	len = strlen(nextptr);
	//snprintf(buf, sizeof(buf), "%d.%d", addr.u8[0], addr.u8[1]);
	if(len > MAX_FILENAME_SIZE) {
	    snprintf(buf, sizeof(buf), "%d", len);
	    printf("filename too large: ", buf);
	    PROCESS_EXIT();
	}
	sendfile_filename = nextptr;
	printf("filename: %s\n", sendfile_filename);
	sprintf(filenameOriginatorSent.name, "%s", sendfile_filename);
	filenameOriginatorSent.originator = node_id;
	packetbuf_copyfrom(&filenameOriginatorSent, sizeof(filenameOriginatorSent));
	runicast_send(&runicastSendCommand, &addr, MAX_RETRANSMISSIONS);
    PROCESS_END();
}
Beispiel #7
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_poke_process, ev, data)
{
    uint8_t *address;
    uint8_t byte;
    const char *args, *next;

    PROCESS_BEGIN();

    args = data;

    if(args == NULL) {
        shell_output_str(&poke_command, "usage 0", "");
        PROCESS_EXIT();
    }

    address = (uint8_t *)(int)shell_strtolong(args, &next);
    if(next == args) {
        shell_output_str(&poke_command, "usage 1", "");
        PROCESS_EXIT();
    }

    args = next;
    byte = shell_strtolong(args, &next);
    if(next == args) {
        shell_output_str(&poke_command, "usage 2", "");
        PROCESS_EXIT();
    }

    printf("address %p byte 0x%02x\n", address, byte);

    *address = byte;

    PROCESS_END();
}
Beispiel #8
0
/*-----------------------------------------------------------------------------------*/
PROCESS_THREAD(about_process, ev, data)
{
    unsigned char width;

    PROCESS_BEGIN();

    width = ctk_desktop_width(NULL);

    strcpy(abouturl_ascii, abouturl_petscii);
    petsciiconv_toascii(abouturl_ascii, sizeof(abouturl_ascii));

    if(width > 34) {
        ctk_dialog_new(&aboutdialog, 32, 9);
    } else {
        ctk_dialog_new(&aboutdialog, width - 2, 9);
    }
    CTK_WIDGET_ADD(&aboutdialog, &aboutlabel1);
    CTK_WIDGET_ADD(&aboutdialog, &aboutlabel2);
    CTK_WIDGET_ADD(&aboutdialog, &aboutlabel3);
    CTK_WIDGET_ADD(&aboutdialog, &aboutlabel4);
    if(width > 34) {
        CTK_WIDGET_ADD(&aboutdialog, &abouturl);
        CTK_WIDGET_SET_FLAG(&abouturl, CTK_WIDGET_FLAG_MONOSPACE);
    } else {
        CTK_WIDGET_SET_XPOS(&aboutlabel1, 0);
        CTK_WIDGET_SET_XPOS(&aboutlabel2, 0);
        CTK_WIDGET_SET_XPOS(&aboutlabel3, 0);
        CTK_WIDGET_SET_XPOS(&aboutlabel4, 0);

        CTK_WIDGET_SET_XPOS(&aboutclose, 0);
    }
    CTK_WIDGET_ADD(&aboutdialog, &aboutclose);
    CTK_WIDGET_FOCUS(&aboutdialog, &aboutclose);

    ctk_dialog_open(&aboutdialog);

    while(1) {
        PROCESS_WAIT_EVENT();
        if(ev == PROCESS_EVENT_EXIT) {
            about_quit();
            PROCESS_EXIT();
        } else if(ev == ctk_signal_button_activate) {
            if(data == (process_data_t)&aboutclose) {
                about_quit();
                PROCESS_EXIT();
            }
        } else if(ev == ctk_signal_hyperlink_activate) {
            if((struct ctk_widget *)data == (struct ctk_widget *)&abouturl) {
                about_quit();
                PROCESS_EXIT();
            }
        }
    }

    PROCESS_END();
}
Beispiel #9
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_download_process, ev, data)
{
  const char *nextptr;
  static rimeaddr_t addr;
  int len;
  char buf[32];

  PROCESS_BEGIN();

  /* Parse node addr */
  addr.u8[0] = shell_strtolong(data, &nextptr);
  if(nextptr == data || *nextptr != '.') {
    shell_output_str(&download_command,
        "download <node addr> <filename>: need node address", "");
    PROCESS_EXIT();
  }
  ++nextptr;
  addr.u8[1] = shell_strtolong(nextptr, &nextptr);

  /* Get the length of the file, excluding a terminating NUL character. */
  while(nextptr[0] == ' ') {
    nextptr++;
  }
  len = strlen(nextptr);

  /*snprintf(buf, sizeof(buf), "%d.%d", addr.u8[0], addr.u8[1]);*/
  /*shell_output_str(&download_command, "Downloading from: ", buf);*/

  if(len > PACKETBUF_SIZE - 32) {
    snprintf(buf, sizeof(buf), "%d", len);
    shell_output_str(&download_command, "filename too large: ", buf);
    PROCESS_EXIT();
  }

  /*shell_output_str(&download_command, "Downloading file: ", nextptr);*/

  /* Send file request */
  downloading = 1;
  rucb_open(&rucb, RUCB_CHANNEL, &rucb_call);
  packetbuf_clear();
  *((uint8_t *)packetbuf_dataptr()) = ++req_seq_counter;
  memcpy(((char *)packetbuf_dataptr()) + 1, nextptr, len + 1);
  packetbuf_set_datalen(len + 2);
  PRINTF("requesting '%s'\n", nextptr);
  runicast_send(&runicast, &addr, MAX_RETRANSMISSIONS);

  /* Wait for download to finish */
  leds_on(LEDS_BLUE);
  PROCESS_WAIT_UNTIL(!runicast_is_transmitting(&runicast) && !downloading);
  leds_off(LEDS_BLUE);

  rucb_close(&rucb);
  /*shell_output_str(&download_command, "Done!", "");*/

  PROCESS_END();
}
Beispiel #10
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_tcpsend_process, ev, data)
{
  char *next;
  const char *dummy; 
  struct shell_input *input;
  uint16_t port;
  
  PROCESS_BEGIN();

  next = strchr(data, ' ');
  if(next == NULL) {
    shell_output_str(&tcpsend_command,
		     "tcpsend <server> <port>: server as address", "");
    PROCESS_EXIT();
  }
  *next = 0;
  ++next;
  strncpy(server, data, sizeof(server));
  port = shell_strtolong(next, &dummy);
  
  running = 1;

  uiplib_ipaddrconv(server, &serveraddr);
  telnet_connect(&s, &serveraddr, port);
  while(running) {
    PROCESS_WAIT_EVENT();

    if(ev == shell_event_input) {
      input = data;
      if(input->len1 + input->len2 == 0) {
	PROCESS_EXIT();
      }

      if(input->len1 > 0) {
	send_line(&s, input->data1, input->len1);
      }
    } else if(ev == tcpip_event) {
      telnet_app(data);
#if 0            
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
	 resolv_lookup((char *)data) != NULL) {
	uip_ipaddr_copy(serveraddr, ipaddr);
	telnet_connect(&s, server, serveraddr, nick);
      } else {
	shell_output_str(&tcpsend_command, "Host not found.", "");
      }
#endif /* 0 */
    }
  }

  PROCESS_END();
}
Beispiel #11
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_unicast_send_process, ev, data)
{
  struct shell_input *input;
  static linkaddr_t receiver;
  int len;
  const char *nextptr;
  struct unicast_msg *msg;
  
  PROCESS_BEGIN();
  
  receiver.u8[0] = shell_strtolong(data, &nextptr);
  if(nextptr == data || *nextptr != '.') {
    shell_output_str(&unicast_send_command,
		     "unicast <receiver>: recevier must be specified", "");
    PROCESS_EXIT();
  }
  ++nextptr;
  receiver.u8[1] = shell_strtolong(nextptr, &nextptr);

  /*  snprintf(buf, sizeof(buf), "%d.%d", receiver.u8[0], receiver.u8[1]);
      shell_output_str(&unicast_send_command, "Sending unicast packets to ", buf);*/

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

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

    if(len == 0) {
      PROCESS_EXIT();
    }
    
    if(len < MAX_DATALEN) {
      packetbuf_clear();
      packetbuf_set_datalen(len + UNICAST_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
      /*      printf("Sending %d bytes\n", len);*/
      unicast_send(&uc, &receiver);
    }
  }
  PROCESS_END();
}
Beispiel #12
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(test_remote_rtcc_process, ev, data)
{
  PROCESS_BEGIN();

  printf("RE-Mote RTC test\n");

  /* Map interrupt callback handler */
  RTCC_REGISTER_INT1(rtcc_interrupt_callback);

  /* Wait a bit */
  etimer_set(&et, (CLOCK_SECOND * 2));
  PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

  /* Retrieve the configured time and date, this doesn't overwrites the
   * mode and century values
   */
  if(rtcc_get_time_date(simple_td) == AB08_ERROR) {
    printf("Fail: Couldn't read time and date\n");
    PROCESS_EXIT();
  }

  /* ...or for visualization only, just print the date directly from the RTCC */
  printf("Configured time: ");
  rtcc_print(RTCC_PRINT_DATE_DEC);

#if TEST_ALARM_MATCH_MIN
  /* Configure the RTCC to trigger an alarm every TEST_ALARM_SECOND match */
  printf("Setting an alarm to tick every %u seconds match\n", TEST_ALARM_SECOND);

  simple_td->seconds = TEST_ALARM_SECOND;

  /* Notice the arguments, we want to trigger the alarm every time the clock
   * matches the seconds values, so the alarm would have to be repeated every
   * minute.  In case we would want to trigger the alarm on a specific time,
   * then we would want to set a daily repeat interval
   */
  if(rtcc_set_alarm_time_date(simple_td, RTCC_ALARM_ON, RTCC_REPEAT_MINUTE,
                              RTCC_TRIGGER_INT1) == AB08_ERROR) {
    printf("Fail: couldn't set the alarm\n");
    PROCESS_EXIT();
  }

#else
  /* Configure the RTCC to trigger an alarm every TEST_ALARM_SECOND tick */
  printf("Setting an alarm to tick every %u seconds\n", TEST_ALARM_SECOND);

  configure_new_alarm();
#endif

  PROCESS_END();
}
Beispiel #13
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_sendcmd_process, ev, data)
{
  struct cmd_msg  *msg;
  int len;
  linkaddr_t addr;
  const char *nextptr;
  char buf[32];

  PROCESS_BEGIN();

  addr.u8[0] = shell_strtolong(data, &nextptr);
  if(nextptr == data || *nextptr != '.') {
    shell_output_str(&sendcmd_command,
             "sendcmd <node addr>: receiver must be specified", "");
    PROCESS_EXIT();
  }
  ++nextptr;
  addr.u8[1] = shell_strtolong(nextptr, &nextptr);

  snprintf(buf, sizeof(buf), "%d.%d", addr.u8[0], addr.u8[1]);
  shell_output_str(&sendcmd_command, "Sending command to ", buf);

  /* Get the length of the command line, excluding a terminating NUL character. */
  len = strlen((char *)nextptr);

  /* Check the length of the command line to see that it is small
     enough to fit in a packet. We count with 32 bytes of header,
     which may be a little too much, but at least we are on the safe
     side. */
  if(len > PACKETBUF_SIZE - 32) {
    snprintf(buf, sizeof(buf), "%d", len);
    shell_output_str(&sendcmd_command, "command line too large: ", buf);
    PROCESS_EXIT();
  }

  packetbuf_clear();
  msg = packetbuf_dataptr();
  packetbuf_set_datalen(len + 1 + CMDMSG_HDR_SIZE);
  strcpy(msg->sendcmd, nextptr);

  /* Terminate the string with a NUL character. */
  msg->sendcmd[len] = 0;
  msg->crc = crc16_data((unsigned char *)msg->sendcmd, len, 0);
  /*    printf("sendcmd sending '%s'\n", msg->sendcmd);*/
  unicast_send(&uc, &addr);

  PROCESS_END();
}
Beispiel #14
0
/*---------------------------------------------------------------------------*/
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(border_router_process, ev, data)
{
  static struct etimer et;

  PROCESS_BEGIN();
  PRINTF("Border Router started\n");
  prefix_set = 0;

  leds_on(LEDS_RED);

  /* Request prefix until it has been received */
  while(!prefix_set) {
    leds_on(LEDS_GREEN);
    PRINTF("Prefix request.\n");
    etimer_set(&et, CLOCK_SECOND);
    request_prefix();
    leds_off(LEDS_GREEN);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
  }

  /* We have created a new DODAG when we reach here */
  PRINTF("On Channel %u\n", (uint8_t)((FREQCTRL + 44) / 5));

  print_local_addresses();

  leds_off(LEDS_RED);

  PROCESS_EXIT();

  PROCESS_END();
}
Beispiel #16
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_sensors_process, ev, data)
{
  char str_buf[22];

  PROCESS_BEGIN();
  if(data == NULL) {
    shell_output_str(&sensors_command,
                     "sensors {temp|acc}: a sensor must be specified", "");
    PROCESS_EXIT();
  }

  if(strcmp(data, "temp") == 0) {
    unsigned int temp = temperature_sensor.value(0);
    snprintf(str_buf, sizeof(str_buf), "%d.%d degC", temp / 10,
             temp - (temp / 10) * 10);
    shell_output_str(&sensors_command, "Temp: ", str_buf);
  } else {
    if(strcmp(data, "acc") == 0) {
      snprintf(str_buf, sizeof(str_buf), "%d,%d,%d) mg",
               acc_sensor.value(ACC_X_AXIS), acc_sensor.value(ACC_Y_AXIS),
               acc_sensor.value(ACC_Z_AXIS));
      shell_output_str(&sensors_command, "(X,Y,Z): (", str_buf);
    }
  }
  PROCESS_END();
}
Beispiel #17
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(broadcast_example_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t addr;
 
  PROCESS_BEGIN();
//set_global_address();
 udp_bconn = udp_broadcast_new(UIP_HTONS(BROADCAST_PORT),NULL);
    //uip_create_unspecified(&udp_bconn->ripaddr);	
    if(udp_bconn == NULL) {
        printf("NUC E\n");
        PROCESS_EXIT();
    }

  etimer_set(&periodic_timer, SEND_INTERVAL);
  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
    etimer_reset(&periodic_timer);
    etimer_set(&send_timer, SEND_TIME);

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));
    printf("Sending broadcast\n");
    send_broadcast("hi",sizeof("hi"));
  }

  PROCESS_END();
}
Beispiel #18
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_kill_process, ev, data)
{
  struct shell_command *c;
  char *name;
  PROCESS_BEGIN();

  name = data;
  if(name == NULL || strlen(name) == 0) {
    shell_output_str(&kill_command,
		     "kill <command>: command name must be given", "");
  }

  for(c = list_head(commands);
      c != NULL;
      c = c->next) {
    if(strcmp(name, c->command) == 0 &&
       c != &kill_command &&
       process_is_running(c->process)) {
      command_kill(c);
      PROCESS_EXIT();
    }
  }

  shell_output_str(&kill_command, "Command not found: ", name);
  
  PROCESS_END();
}
Beispiel #19
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_append_process, ev, data)
{
  static int fd = 0;
  struct shell_input *input;

  PROCESS_EXITHANDLER(cfs_close(fd));
  
  PROCESS_BEGIN();

  fd = cfs_open(data, CFS_WRITE | CFS_APPEND);

  if(fd < 0) {
    shell_output_str(&append_command,
		     "append: could not open file for writing: ", data);
  } else {
    while(1) {
      PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
      input = data;
      /*    printf("cat input %d %d\n", input->len1, input->len2);*/
      if(input->len1 + input->len2 == 0) {
	cfs_close(fd);
	PROCESS_EXIT();
      }
      
      cfs_write(fd, input->data1, input->len1);
      cfs_write(fd, input->data2, input->len2);
      
      shell_output(&append_command,
		   input->data1, input->len1,
		   input->data2, input->len2);
    }
  }
  
  PROCESS_END();
}
Beispiel #20
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_server_process, ev, data)
{
  PROCESS_BEGIN();

  print_local_addresses();

  dtls_init();
  init_dtls();

  if (!dtls_context) {
    dsrv_log(LOG_EMERG, "cannot create context\n");
    PROCESS_EXIT();
  }

  while(1) {
    PROCESS_WAIT_EVENT();
    if(ev == tcpip_event) {
      dtls_handle_read(dtls_context);
    }
#if 0
    if (bytes_read > 0) {
      /* dtls_handle_message(dtls_context, &the_session, readbuf, bytes_read); */
      read_from_peer(dtls_context, &the_session, readbuf, bytes_read);
    }
    dtls_handle_message(ctx, &session, uip_appdata, bytes_read);
#endif
  }

  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(test_pm10_sensor_process, ev, data)
{
  PROCESS_BEGIN();

  static uint16_t pm10_value;

  /* Use pin number not mask, for uart_demo if using the PA5 pin then use 2 */
  pm10.configure(SENSORS_ACTIVE, ADC_PIN);

  /* And periodically poll the sensor */

  while(1) {
    etimer_set(&et, SENSOR_READ_INTERVAL);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

    leds_toggle(LEDS_GREEN);
    pm10_value = pm10.value(1);

    if(pm10_value != ADC_WRAPPER_ERROR) {
      printf("PM10 value = %u ppm\n", pm10_value);
    } else {
      printf("Error, enable the DEBUG flag in adc-wrapper.c for info\n");
      PROCESS_EXIT();
    }
  }
  PROCESS_END();
}
Beispiel #22
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(sniffer_process, ev, data)
{
  PROCESS_BEGIN();
  PRINTF("Sniffer started\n");
  PROCESS_EXIT();
  PROCESS_END();
}
Beispiel #23
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_powergraph_process, ev, data)
{
  struct power_msg *msg;
  struct shell_input *input;
  int len;

  PROCESS_BEGIN();
  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
    input = data;
    
    if(input->len1 + input->len2 == 0) {
      PROCESS_EXIT();
    }
    len = input->len1;
    for(msg = (struct power_msg *)input->data1;
	len > 0;
	msg++, len -= sizeof(struct power_msg)) {
      printpowergraph(msg);
    }
    len = input->len2;
    for(msg = (struct power_msg *)input->data2;
	len > 0;
	msg++, len -= sizeof(struct power_msg)) {
      printpowergraph(msg);
    }

  }
  
  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_sender_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t global_ipaddr;

  PROCESS_BEGIN();


  random_rand();
  rpl_log_start();
  if(node_id ==0) {
    NETSTACK_RDC.off(0);
    uint16_t mymac = linkaddr_node_addr.u8[7] << 8 | linkaddr_node_addr.u8[6];
    printf("Node id unset, my mac is 0x%04x\n", mymac);
    PROCESS_EXIT();
  }

  cc2420_set_txpower(RF_POWER);
  cc2420_set_cca_threshold(RSSI_THR);
  printf("App: %u starting\n", node_id);

  deployment_init(&global_ipaddr);
  //rpl_setup(node_id == ROOT_ID, node_id);
  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  if(node_id == ROOT_ID) {
    uip_ipaddr_t my_ipaddr;
    set_ipaddr_from_id(&my_ipaddr, node_id);
    //NETSTACK_RDC.off(1);
  }
  else {
    etimer_set(&periodic_timer,1 * 30 * CLOCK_SECOND);

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
    etimer_set(&periodic_timer, SEND_INTERVAL);


    while(1) {

      etimer_set(&send_timer, random_rand() % (SEND_INTERVAL));

      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));
      int rank = default_instance != NULL ? default_instance->current_dag->rank : 0xffff;
     if(rank != 0xffff){
      app_send_to(ROOT_ID);
      }
      else{
        printf("App: not in DODAG\n");
      }

      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
      etimer_reset(&periodic_timer);

    }
  }

  PROCESS_END();
}
Beispiel #25
0
/*---------------------------------------------------------------------------*/
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();
}
Beispiel #26
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_broadcast_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
      /*      printf("Sending %d bytes\n", len);*/
      broadcast_send(&broadcast);
    }
  }
  PROCESS_END();
}
Beispiel #27
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(border_router_process, ev, data)
{
  static struct etimer et;

  PROCESS_BEGIN();
  PUTSTRING("Border Router started\n");
  prefix_set = 0;

  leds_on(LEDS_GREEN);

  /* Request prefix until it has been received */
  while(!prefix_set) {
    leds_on(LEDS_RED);
    PUTSTRING("Prefix request.\n");
    etimer_set(&et, CLOCK_SECOND);
    request_prefix();
    leds_off(LEDS_RED);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
  }
  /* We have created a new DODAG when we reach here */
  PUTSTRING("On Channel ");
  PUTDEC(cc2530_rf_channel_get());
  PUTCHAR('\n');

  print_local_addresses();

  leds_off(LEDS_GREEN);

  PROCESS_EXIT();

  PROCESS_END();
}
Beispiel #28
0
/* --------------------------------------------------------------- */
PROCESS_THREAD(node_process, ev, data)
{
    // All the process start with this
    PROCESS_BEGIN();
    PRINTF("# Starting...\n");

    // Configure the network
    network_config();
    if (!conn) {
         printf("E01\n");
         PROCESS_EXIT();
    }

    #if IS_RPL_ROOT
    create_dag();
    #endif

    // Main, infinite, loop of the process
    PRINTF("# Ready!\n");
    while (1) {
        // Wait, block the process, until an event happens.
        // Meanwhile, other process will continue running.
        PROCESS_WAIT_EVENT();

        // Check the type of event that unblock the process
        if (ev == tcpip_event)
            tcpip_handler();
        else if (ev == serial_line_event_message)
            input_handler((char*)data);
    }

    // All the process ends with this
    PROCESS_END();
}
Beispiel #29
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_server_process, ev, data)
{
  PROCESS_BEGIN();

  dtls_init();
  init_dtls();

  print_local_addresses();

  if (!dtls_context) {
    dtls_emerg("cannot create context\n");
    PROCESS_EXIT();
  }

#ifdef ENABLE_POWERTRACE
  powertrace_start(CLOCK_SECOND * 2); 
#endif

  while(1) {
    PROCESS_WAIT_EVENT();
    if(ev == tcpip_event) {
      dtls_handle_read(dtls_context);
    }
  }

  PROCESS_END();
}
Beispiel #30
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(remote_bmp085_process, ev, data)
{
  PROCESS_BEGIN();
  static uint16_t pressure;
  static int16_t temperature;

  /* Use Contiki's sensor macro to enable the sensor */
  SENSORS_ACTIVATE(bmp085);

  /* And periodically poll the sensor */

  while(1) {
    etimer_set(&et, SENSOR_READ_INTERVAL);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

    pressure = bmp085.value(BMP085_READ_PRESSURE);
    temperature = bmp085.value(BMP085_READ_TEMP);

    if((pressure != BMP085_ERROR) && (temperature != BMP085_ERROR)) {
      printf("Pressure = %u.%u(hPa), ", pressure / 10, pressure % 10);
      printf("Temperature = %d.%u(ºC)\n", temperature / 10, temperature % 10);
    } else {
      printf("Error, enable the DEBUG flag in the BMP085 driver for info, ");
      printf("or check if the sensor is properly connected\n");
      PROCESS_EXIT();
    }
  }
  PROCESS_END();
}