Exemple #1
0
/*---------------------------------------------------------------------------*/
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();
}
/*---------------------------------------------------------------------------*/
void
cc26xx_web_demo_restore_defaults(void)
{
  cc26xx_web_demo_sensor_reading_t *reading = NULL;

  leds_on(LEDS_ALL);

  for(reading = list_head(sensor_list);
      reading != NULL;
      reading = list_item_next(reading)) {
    reading->publish = 1;
  }

#if CC26XX_WEB_DEMO_MQTT_CLIENT
  process_post_synch(&mqtt_client_process,
                     cc26xx_web_demo_load_config_defaults, NULL);
#endif

#if CC26XX_WEB_DEMO_NET_UART
  process_post_synch(&net_uart_process, cc26xx_web_demo_load_config_defaults,
                     NULL);
#endif

  save_config();

  leds_off(LEDS_ALL);
}
static void contiki_appcall(void *data)
{
	contiki_data_t *s = (contiki_data_t *)data;

	if (uip_closed() || uip_aborted() || uip_timedout()) {
		//xprintf("closed or aborted or timedout\n");
		if (s->state == READING || s->state == WRITTING) {
			s->state = ERROR;
		} else {
			s->state = CLOSED;
		}
		process_post_synch(s->process, xively_event, s);
	} else if (uip_connected()) {
		s->state = CONNECTED;
		PSOCK_INIT(&s->p, NULL, 0);
		process_post_synch(s->process, xively_event, s);
	} else if (uip_newdata()) {
		if (s->state == READING) {
			s->state = READ_END;
			process_post_synch(s->process, xively_event, s);
		}
	}
	if (s->state == CLOSING) {
		uip_close();
	}
	handle_output(s);
}
Exemple #4
0
/*---------------------------------------------------------------------------*/
void
tcpip_input(void)
{
	//printf("Guess I managed to go the stack up \n");
	process_post_synch(&tcpip_process, PACKET_INPUT, NULL);
	uip_clear_buf();
}
Exemple #5
0
/*---------------------------------------------------------------------------*/
clock_time_t
etimer_request_poll(void)
{
  process_post_synch(&etimer_process, PROCESS_EVENT_POLL,
		     NULL, NULL);
  return next_expiration;
}
/*---------------------------------------------------------------------------*/
void
process_start(struct process *p, const char *arg)
{
  struct process *q;

  /* First make sure that we don't try to start a process that is
     already running. */
  for(q = process_list; q != p && q != NULL; q = q->next);

  /* If we found the process on the process list, we bail out. */
  if(q == p) {
    return;
  }
  /* Put on the procs list.*/
  p->next = process_list;
  process_list = p;
  p->state = PROCESS_STATE_RUNNING;
  PT_INIT(&p->pt);

  PRINTF("process: starting '%s'\n", PROCESS_NAME_STRING(p));

  /* Post a synchronous initialization event to the process. */

  process_post_synch(p, PROCESS_EVENT_INIT, (process_data_t)arg);
}
Exemple #7
0
bool
i2cb(u8_t addr, u8_t wrlen, u8_t rdlen, u8_t buf[])
{
  static i2c_t t = {.buf = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};

  t.addr    = addr;
  t.wrlen   = wrlen;
  t.rdlen   = rdlen;
  t.cb      = internal_cb;
  memcpy(t.buf, buf, wrlen);

  i2c(&t);

  pending = true;
  while (pending) {
    if (i2c_process.needspoll) {
      process_post_synch(&i2c_process, PROCESS_EVENT_POLL, NULL);
      i2c_process.needspoll = false;
    }
  }

  memcpy(buf+wrlen,t.buf+wrlen,rdlen);

  return i2c_status;
}
Exemple #8
0
/*---------------------------------------------------------------------------*/
static void
tsch_reset(void)
{
  int i;
  frame802154_set_pan_id(0xffff);
  /* First make sure pending packet callbacks are sent etc */
  process_post_synch(&tsch_pending_events_process, PROCESS_EVENT_POLL, NULL);
  /* Empty all neighbor queues */
  /* tsch_queue_flush_all(); */
  /* Remove unused neighbors */
  tsch_queue_free_unused_neighbors();
  tsch_queue_update_time_source(NULL);
  /* Initialize global variables */
  tsch_join_priority = 0xff;
  ASN_INIT(current_asn, 0, 0);
  current_link = NULL;
  /* Reset timeslot timing to defaults */
  for(i = 0; i < tsch_ts_elements_count; i++) {
    tsch_timing[i] = US_TO_RTIMERTICKS(tsch_default_timing_us[i]);
  }
#ifdef TSCH_CALLBACK_LEAVING_NETWORK
  TSCH_CALLBACK_LEAVING_NETWORK();
#endif
#if TSCH_AUTOSELECT_TIME_SOURCE
  best_neighbor_eb_count = 0;
  nbr_table_register(eb_stats, NULL);
  tsch_set_eb_period(TSCH_EB_PERIOD);
#endif
}
Exemple #9
0
/*---------------------------------------------------------------------------*/
void
tcpip_input(void)
{
    process_post_synch(&tcpip_process, PACKET_INPUT, NULL);
    uip_len = 0;
#if UIP_CONF_IPV6
    uip_ext_len = 0;
#endif /*UIP_CONF_IPV6*/
}
Exemple #10
0
static void complete_pending(mqtt_state_t* state, int event_type)
{
  mqtt_event_data_t event_data;

  state->pending_msg_type = 0;
  mqtt_flags |= MQTT_FLAG_READY;
  event_data.type = event_type;
  process_post_synch(state->calling_process, mqtt_event, &event_data);
}
Exemple #11
0
void
tcpip_icmp6_call(uint8_t type)
{
    if(uip_icmp6_conns.appstate.p != PROCESS_NONE) {
        /* XXX: This is a hack that needs to be updated. Passing a pointer (&type)
           like this only works with process_post_synch. */
        process_post_synch(uip_icmp6_conns.appstate.p, tcpip_icmp6_event, &type);
    }
    return;
}
static PT_THREAD(handle_output(contiki_data_t *s))
{
	PSOCK_BEGIN(&s->p);
	if (s->state == WRITTING) {
		PSOCK_SEND(&s->p, s->out_buf, s->out_len);
		s->state = WRITE_END;
		process_post_synch(s->process, xively_event, s);
	}
	PSOCK_END(&s->p);
}
Exemple #13
0
int net_context_tcp_send(struct net_buf *buf)
{
	/* Prepare data to be sent */
	process_post_synch(&ip_buf_context(buf)->tcp,
			   tcpip_event,
			   INT_TO_POINTER(TCP_WRITE_EVENT),
			   buf);


	return ip_buf_sent_status(buf);
}
Exemple #14
0
/*---------------------------------------------------------------------------*/
void
tcpip_input(void)
{
//  printf("Tcpip: input");
//      rpl_trace(rpl_dataptr_from_packetbuf());
  process_post_synch(&tcpip_process, PACKET_INPUT, NULL);
  uip_len = 0;
#if UIP_CONF_IPV6
  uip_ext_len = 0;
#endif /*UIP_CONF_IPV6*/
}
Exemple #15
0
void response_handler(ChannelState *state, DataPayload *dp){
	if (state->state != STATE_CONNECTED && state->state != STATE_PING){
		PRINTF("Not connected to device!\n");
		return;
	}
	state->ticks = 100;
	ResponseMsg *rmsg = (ResponseMsg *)dp->data;
	PRINTF("%s %d\n", rmsg->name, uip_ntohs(rmsg->data));
	/*RESET PING TIMER*/
	ctimer_restart(&(state->timer));
	process_post_synch(state->ccb.client_process, KNOT_EVENT_DATA_READY, rmsg);
}
Exemple #16
0
/*---------------------------------------------------------------------------*/
static void
input_to_child_command(struct shell_command *c,
		       char *data1, int len1,
		       const char *data2, int len2)
{
  struct shell_input input;
  if(process_is_running(c->process)) {
    input.data1 = data1;
    input.len1 = len1;
    input.data2 = data2;
    input.len2 = len2;
    process_post_synch(c->process, shell_event_input, &input);
  }
}
Exemple #17
0
static void deliver_publish_continuation(mqtt_state_t* state, uint16_t offset, uint8_t* buffer, uint16_t length)
{
  mqtt_event_data_t event_data;

  event_data.type = MQTT_EVENT_TYPE_PUBLISH_CONTINUATION;
  event_data.topic_length = 0;
  event_data.topic = NULL;
  event_data.data_length = length;
  event_data.data_offset = offset;
  event_data.data = (char*)buffer;
  ((char*)event_data.data)[event_data.data_length] = '\0';

  process_post_synch(state->calling_process, mqtt_event, &event_data);
}
Exemple #18
0
//process
PROCESS_THREAD(ntp_client_Process, ev, data)
{
    static struct etimer ntp_timer;
    PROCESS_BEGIN();
    //printf("ntp_client_Process begin\n");
    
    process_start(&ntp_connectPprocess, NULL);

    ntp.client_sock = -1;
    ntp.exit_process = 0;
    ntp.retry_cnt = 0;
    
    ntp.client_sock = udpcreate(NTP_LOCAL_PORT, &ntp_connectPprocess);
    if(ntp.client_sock == -1) {
        printf("create udp socket fail");
        ntp.exit_process = 1;
    } else {
        //printf("create socket:%d\n", ntp.client_sock);
        //us.pool.ntp.org(108.61.56.35)
        if( uiplib_ipaddrconv("108.61.56.35", &ntp.server_ip)  == 0) {
            printf("erro ip format\n");
            ntp.exit_process = 1;
        }
    }
    
    memset( &packet, 0, sizeof( ntp_packet ) );
    *( ( char * ) &packet + 0 ) = 0x1b; // Represents 27 in base 10 or 00011011 in base 2.
    
    while(!ntp.exit_process) {
        if(ntp.retry_cnt > MAX_RETRYCNT) {
            printf("ntp client can not rece ntp server data, please check network\n");
            break;
        }
        etimer_set(&ntp_timer, 1 * CLOCK_SECOND);
        PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);

        if(udpsendto(ntp.client_sock, (char *)&packet, sizeof(packet), &ntp.server_ip, NTP_SERVER_PORT) == -1) {
            printf("udpsendto fail\n");
        }
        ntp.retry_cnt++;
    }

    if(udpclose(ntp.client_sock) == -1) {
        printf("udpclose fail\n");
    }
    process_post_synch(&ntp_connectPprocess, PROCESS_EVENT_EXIT, NULL);
    //printf("ntp_client_Process end\n");
    PROCESS_END();
}
Exemple #19
0
/*---------------------------------------------------------------------------*/
void
tcpip_uipcall(void)
{
    static uip_udp_appstate_t *ts;

#if UIP_UDP
    if(uip_conn != NULL) {
        ts = &uip_conn->appstate;
    } else {
        ts = &uip_udp_conn->appstate;
    }
#else /* UIP_UDP */
    ts = &uip_conn->appstate;
#endif /* UIP_UDP */

#if UIP_TCP
    {
        static unsigned char i;
        register struct listenport *l;

        /* If this is a connection request for a listening port, we must
           mark the connection with the right process ID. */
        if(uip_connected()) {
            l = &s.listenports[0];
            for(i = 0; i < UIP_LISTENPORTS; ++i) {
                if(l->port == uip_conn->lport &&
                        l->p != PROCESS_NONE) {
                    ts->p = l->p;
                    ts->state = NULL;
                    break;
                }
                ++l;
            }

            /* Start the periodic polling, if it isn't already active. */
            start_periodic_tcp_timer();
        }
    }
#endif /* UIP_TCP */

    if(ts->p != NULL) {
#if SHORTCUTS_CONF_NETSTACK
        /* Directly invoke the relevant thread to reduce stack usage by 15 bytes */
        ts->p->thread(&ts->p->pt, tcpip_event, ts->state);
#else
        process_post_synch(ts->p, tcpip_event, ts->state);
#endif
    }
}
Exemple #20
0
/*---------------------------------------------------------------------------*/
void
tcpip_input(void)
{
#if SHORTCUTS_CONF_NETSTACK
    /* calling process_post_sync, adds many bytes onto stack with the
     * only affect being process.c::process_current modified and restored
     * this is unnessary overhead, since it always leads to packet_input
     */
    packet_input();
#else
    process_post_synch(&tcpip_process, PACKET_INPUT, NULL);
#endif
    uip_len = 0;
#if UIP_CONF_IPV6
    uip_ext_len = 0;
#endif /*UIP_CONF_IPV6*/
}
Exemple #21
0
/*---------------------------------------------------------------------------*/
void
tcpip_uipcall(void)
{
  register uip_udp_appstate_t *ts;
  
#if UIP_UDP
  if(uip_conn != NULL) {
    ts = &uip_conn->appstate;
  } else {
    ts = &uip_udp_conn->appstate;
  }
#else /* UIP_UDP */
  ts = &uip_conn->appstate;
#endif /* UIP_UDP */

#if UIP_TCP
 {
   static unsigned char i;
   register struct listenport *l;
   
   /* If this is a connection request for a listening port, we must
      mark the connection with the right process ID. */
   if(uip_connected()) {
     l = &s.listenports[0];
     for(i = 0; i < UIP_LISTENPORTS; ++i) {
       if(l->port == uip_conn->lport &&
	  l->p != PROCESS_NONE) {
	 ts->p = l->p;
	 ts->state = NULL;
	 break;
       }
       ++l;
     }
     
     /* Start the periodic polling, if it isn't already active. */
     if(etimer_expired(&periodic)) {
       etimer_restart(&periodic);
     }
   }
 }
#endif
  
  if(ts->p != NULL) {
    process_post_synch(ts->p, tcpip_event, ts->state);
  }
}
Exemple #22
0
int
cc2420_send(struct hdr_802_15 *hdr, u8_t hdr_len,
	    const u8_t *payload, u8_t payload_len)
{
  u8_t spiStatusByte;
  int s;

  /* struct hdr_802_15::len shall *not* be counted, thus the -1.
   * 2 == sizeof(footer).
   */
  if (((hdr_len - 1) + payload_len + 2) > MAX_PACKET_LEN)
    return -1;

  /* This code uses the CC2420 CCA (Clear Channel Assessment) to
   * implement Carrier Sense Multiple Access with Collision Avoidance
   * (CSMA-CA) and requires the receiver to be enabled and ready.
   */
  if (!receive_on)
    return -2;

  /* Wait for previous transmission to finish and RSSI. */
  do {
    spiStatusByte = cc2420_status();
    if (!(spiStatusByte & BV(CC2420_RSSI_VALID))) /* RSSI needed by CCA */
      continue;
  } while (spiStatusByte & BV(CC2420_TX_ACTIVE));

  hdr->dst_pan = pan_id;	/* Not at fixed position! xxx/bg */
  last_dst = hdr->dst;		/* Not dst either. */
  last_used_seq++;
  hdr->seq = last_used_seq;
  cc2420_ack_received = 0;

  /* Write packet to TX FIFO, appending FCS if AUTOCRC is enabled. */
  cc2420_strobe(CC2420_SFLUSHTX); /* Cancel send that never started. */
  s = splhigh();
  FASTSPI_WRITE_FIFO(hdr, hdr_len);
  FASTSPI_WRITE_FIFO(payload, payload_len);
  splx(s);

  /* Send stuff from FIFO now! */
  process_post_synch(&cc2420_retransmit_process, PROCESS_EVENT_MSG, NULL);

  return UIP_FW_OK;
}
Exemple #23
0
/*---------------------------------------------------------------------------*/
void
tcpip_uipcall(void)
{
	uip_udp_appstate_t *ts;

#if UIP_UDP
	if(uip_conn != NULL) {
		ts = &uip_conn->appstate;
	} else {
		ts = &uip_udp_conn->appstate;
	}
#else /* UIP_UDP */
	ts = &uip_conn->appstate;
#endif /* UIP_UDP */

#if UIP_TCP
	{
		static unsigned char i;
		struct listenport *l;

		/* If this is a connection request for a listening port, we must
		   mark the connection with the right process ID. */
		if(uip_connected()) {
			l = &s.listenports[0];
			for(i = 0; i < UIP_LISTENPORTS; ++i) {
				if(l->port == uip_conn->lport && l->p != PROCESS_NONE) {
#if NO_XMOS_PROJECT
					ts->p = l->p;
					ts->state = NULL;
#else
          printf("### %s: Here the process should be called.\n", __func__);
#endif
					break;
				}
				++l;
			}
			/* Start the periodic polling, if it isn't already active. */
			start_periodic_tcp_timer();
		}
	}
#endif /* UIP_TCP */
	if(ts->p != NULL) {
		process_post_synch(ts->p, tcpip_event, ts->state);
	}
}
Exemple #24
0
/*---------------------------------------------------------------------------*/
uint8_t
tcpip_input(struct net_buf *buf)
{
  process_post_synch(&tcpip_process, PACKET_INPUT, NULL, buf);
  if (uip_len(buf) == 0) {
    /* This indicates that there was a parsing/other error
     * in packet.
     */
    return 0;
  }

  uip_len(buf) = 0;
#if NETSTACK_CONF_WITH_IPV6
  uip_ext_len(buf) = 0;
#endif /*NETSTACK_CONF_WITH_IPV6*/

  return 1;
}
static void periodic_timer_cb(void)
{
    mqtt_event_data_t event_data;
    uint8_t val, frac;
    uint16_t temp;

    printf("Ping timer %d\n", mqtt.keepalive_error);

    if (mqtt.state != MQTT_STATE_CONNECTED)
    {
        /* Not connected : try to reconnect */
        printf("Try to reconnect\n");
        mqtt_msg_connect_send(&mqtt);
        uip_udp_packet_send(mqtt.udp_connection, mqtt.data, mqtt.len);
        return;
    }


    if (mqtt.keepalive_error >= MAX_KEEPALIVE_ERROR)
    {

        PRINTF("DISCONNECTED\n");
        mqtt.state = MQTT_STATE_CONNECTION_IN_PROGRESS;
        event_data.type = MQTT_EVENT_TYPE_DISCONNECTED;
        process_post_synch(mqtt.calling_process, mqtt_event, &event_data);
        return;
    }
    else
    {
        mqtt.keepalive_error++;
    }

    temp = onewire_temp_read();

    val = temp / 100;
    frac = temp % 100;
    sprintf(temperature, "%d.%d", val, frac);
    printf("temperature : %s\n", temperature);
    mqtt_msg_publish(topic_name, temperature);

    mqtt_msg_ping_send(&mqtt, MQTT_MSG_PINGREQ);
    uip_udp_packet_send(mqtt.udp_connection, mqtt.data, mqtt.len);
}
Exemple #26
0
static void deliver_publish(mqtt_state_t* state, uint8_t* message, int length)
{
  mqtt_event_data_t event_data;

  event_data.type = MQTT_EVENT_TYPE_PUBLISH;

  event_data.topic_length = length;
  event_data.topic = mqtt_get_publish_topic(message, &event_data.topic_length);

  event_data.data_length = length;
  event_data.data = mqtt_get_publish_data(message, &event_data.data_length);

  memmove((char*)event_data.data + 1, (char*)event_data.data, event_data.data_length);
  event_data.data += 1;
  ((char*)event_data.topic)[event_data.topic_length] = '\0';
  ((char*)event_data.data)[event_data.data_length] = '\0';

  process_post_synch(state->calling_process, mqtt_event, &event_data);
}
/*---------------------------------------------------------------------------*/
void
tcpip_input(void)
{
  /*sz*/
  /*Blinking LED packet receiving*/
  PORTB &= ~(1 << PIN6);
  /*sz*/

  process_post_synch(&tcpip_process, PACKET_INPUT, NULL);
  uip_len = 0;
#if UIP_CONF_IPV6
  uip_ext_len = 0;
#endif /*UIP_CONF_IPV6*/
  
  /*sz*/
  /*Blinking LED packet receiving*/
  PORTB |= (1 << PIN6);
  /*sz*/
}
Exemple #28
0
/*---------------------------------------------------------------------------*/
void
shell_input(char *commandline, int commandline_len)
{
  struct shell_input input;

  /*  printf("shell_input front_process '%s'\n", front_process->name);*/

  if(commandline[0] == '~' &&
     commandline[1] == 'K') {
    /*    process_start(&shell_killall_process, commandline);*/
    if(front_process != &shell_process) {
      process_exit(front_process);
    }
  } else {
    if(process_is_running(front_process)) {
      input.data1 = commandline;
      input.len1 = commandline_len;
      input.data2 = "";
      input.len2 = 0;
      process_post_synch(front_process, shell_event_input, &input);
    }
  }
}
Exemple #29
0
PROCESS_THREAD(mqtt_process, ev, data)
{
  mqtt_event_data_t event_data;

  PROCESS_BEGIN();

  while(1)
  {
    printf("mqtt: connecting...\n");
    mqtt_state.tcp_connection = tcp_connect(&mqtt_state.address, 
                                            mqtt_state.port, NULL);
    PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);

    if(!uip_connected())
    {
      printf("mqtt: connect failed\n");
      continue;
    }
    else
      printf("mqtt: connected\n");

    // reserve one byte at the end of the buffer so there's space to NULL terminate
    PSOCK_INIT(&mqtt_state.ps, mqtt_state.in_buffer, mqtt_state.in_buffer_length - 1);

    handle_mqtt_connection(&mqtt_state);

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

      if(mqtt_flags & MQTT_FLAG_EXIT)
      {
        uip_close();

        event_data.type = MQTT_EVENT_TYPE_EXITED;
        process_post_synch(mqtt_state.calling_process, mqtt_event, &event_data);
        PROCESS_EXIT();
      }

      if(uip_aborted() || uip_timedout() || uip_closed())
      {
        event_data.type = MQTT_EVENT_TYPE_DISCONNECTED;
        process_post_synch(mqtt_state.calling_process, mqtt_event, &event_data);
        printf("mqtt: lost connection: %s\n", uip_aborted() ? "aborted" : 
                                              uip_timedout() ? "timed out" : 
                                              uip_closed() ? "closed" : 
                                              "unknown");
        break;
      }
      else
        handle_mqtt_connection(&mqtt_state);
    }

    if(!mqtt_state.auto_reconnect)
      break;
  }

  event_data.type = MQTT_EVENT_TYPE_EXITED;
  process_post_synch(mqtt_state.calling_process, mqtt_event, &event_data);

  PROCESS_END();
}
Exemple #30
0
/*---------------------------------------------------------------------------*/
void
tcpip_input(void)
{
  process_post_synch(&tcpip_process, PACKET_INPUT, NULL);
  uip_clear_buf();
}