コード例 #1
0
ファイル: ajax-cgi.c プロジェクト: 13416795/contiki
static
PT_THREAD(sensorscall(struct httpd_state *s, char *ptr))
{
  static struct timer t;
  static int i;
  static char buf[100];
  static unsigned long last_cpu, last_lpm, last_listen, last_transmit;
  
  PSOCK_BEGIN(&s->sout);

  timer_set(&t, CLOCK_SECOND);
  i = 0;
  /*  while(1)*/ {
    /*    timer_restart(&t);
	  PSOCK_WAIT_UNTIL(&s->sout, timer_expired(&t));*/

#if CONTIKI_TARGET_SKY
    SENSORS_ACTIVATE(sht11_sensor);
    SENSORS_ACTIVATE(light_sensor);
    snprintf(buf, sizeof(buf),
	     "t(%d);h(%d);l1(%d);l2(%d);",
	     sht11_sensor.value(SHT11_SENSOR_TEMP),
	     sht11_sensor.value(SHT11_SENSOR_HUMIDITY),
             light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC),
             light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR));
    SENSORS_DEACTIVATE(sht11_sensor);
    SENSORS_DEACTIVATE(light_sensor);
#else /* CONTIKI_TARGET_SKY */
    snprintf(buf, sizeof(buf),
	     "t(%d);h(%d);l1(%d);l2(%d);",
	     0,
	     0,
	     0,
	     0);
#endif /* CONTIKI_TARGET_SKY */
    PSOCK_SEND_STR(&s->sout, buf);


    /*    timer_restart(&t);
	  PSOCK_WAIT_UNTIL(&s->sout, timer_expired(&t));*/
    snprintf(buf, sizeof(buf),
	     "p(%lu,%lu,%lu,%lu);i(%d);",
	     energest_type_time(ENERGEST_TYPE_CPU) - last_cpu,
	     energest_type_time(ENERGEST_TYPE_LPM) - last_lpm,
	     energest_type_time(ENERGEST_TYPE_TRANSMIT) - last_transmit,
	     energest_type_time(ENERGEST_TYPE_LISTEN) - last_listen,
	     i++);
    last_cpu = energest_type_time(ENERGEST_TYPE_CPU);
    last_lpm = energest_type_time(ENERGEST_TYPE_LPM);
    last_transmit = energest_type_time(ENERGEST_TYPE_TRANSMIT);
    last_listen = energest_type_time(ENERGEST_TYPE_LISTEN);
    PSOCK_SEND_STR(&s->sout, buf);

}
  PSOCK_END(&s->sout);
}
コード例 #2
0
ファイル: httpd.c プロジェクト: Madswinther/31370
/*---------------------------------------------------------------------------*/
static PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr)) {
	char *ptr;
	
	PSOCK_BEGIN(&s->sout);
	
	PSOCK_SEND_STR(&s->sout, statushdr);
	
	ptr = strrchr(s->filename, ISO_period);
	if(ptr == NULL) {
		PSOCK_SEND_STR(&s->sout, http_content_type_binary);
	} else if(strncmp(http_html, ptr, 5) == 0 || strncmp(http_shtml, ptr, 6) == 0) {
		PSOCK_SEND_STR(&s->sout, http_content_type_html);
	} else if(strncmp(http_css, ptr, 4) == 0) {
		PSOCK_SEND_STR(&s->sout, http_content_type_css);
	} else if(strncmp(http_png, ptr, 4) == 0) {
		PSOCK_SEND_STR(&s->sout, http_content_type_png);
	} else if(strncmp(http_gif, ptr, 4) == 0) {
		PSOCK_SEND_STR(&s->sout, http_content_type_gif);
	} else if(strncmp(http_jpg, ptr, 4) == 0) {
		PSOCK_SEND_STR(&s->sout, http_content_type_jpg);
	} else if (strncmp(http_xml, ptr, 4) == 0) {
		PSOCK_SEND_STR(&s->sout, http_content_type_xml);
	} else {
		PSOCK_SEND_STR(&s->sout, http_content_type_plain);
	}
	PSOCK_END(&s->sout);
}
コード例 #3
0
ファイル: httpd-cgi.c プロジェクト: ADVANSEE/mist
/*---------------------------------------------------------------------------*/
static
PT_THREAD(rplreset(struct httpd_state *s, char *ptr))
{
  PSOCK_BEGIN(&s->sout);
  if(rpl_repair_root(RPL_DEFAULT_INSTANCE)) {
    PSOCK_SEND_STR(&s->sout, "Initiating global repair of RPL network...");
  } else {
    PSOCK_SEND_STR(&s->sout, "Could not start global network repair");
  }
  PSOCK_END(&s->sout);
}
コード例 #4
0
/*
 * A protosocket always requires a protothread. The protothread
 * contains the code that uses the protosocket. We define the
 * protothread here.
 */
static
PT_THREAD(handle_connection(struct psock *p))
{
  /*
   * A protosocket's protothread must start with a PSOCK_BEGIN(), with
   * the protosocket as argument.
   *
   * Remember that the same rules as for protothreads apply: do NOT
   * use local variables unless you are very sure what you are doing!
   * Local (stack) variables are not preserved when the protothread
   * blocks.
   */
  PSOCK_BEGIN(p);

  /*
   * We start by sending out a welcoming message. The message is sent
   * using the PSOCK_SEND_STR() function that sends a null-terminated
   * string.
   */
  PSOCK_SEND_STR(p, "Welcome, please type something and press return.\n");
  
  /*
   * Next, we use the PSOCK_READTO() function to read incoming data
   * from the TCP connection until we get a newline character. The
   * number of bytes that we actually keep is dependant of the length
   * of the input buffer that we use. Since we only have a 10 byte
   * buffer here (the buffer[] array), we can only remember the first
   * 10 bytes received. The rest of the line up to the newline simply
   * is discarded.
   */
  PSOCK_READTO(p, '\n');
  
  /*
   * And we send back the contents of the buffer. The PSOCK_DATALEN()
   * function provides us with the length of the data that we've
   * received. Note that this length will not be longer than the input
   * buffer we're using.
   */
  PSOCK_SEND_STR(p, "Got the following data: ");
  PSOCK_SEND(p, buffer, PSOCK_DATALEN(p));
  PSOCK_SEND_STR(p, "Good bye!\r\n");

  /*
   * We close the protosocket.
   */
  PSOCK_CLOSE(p);

  /*
   * And end the protosocket's protothread.
   */
  PSOCK_END(p);
}
コード例 #5
0
ファイル: client.c プロジェクト: boominda/MScResearch
/*---------------------------------------------------------------------------*/
static int
handle_connection(struct psock *p)
{
    PSOCK_BEGIN(p);
    struct conn_state *s;
    s->state = send1;

    PSOCK_SEND_STR(p, "Connection Request");

    while(1) {
        if(s->state == send1)
        {
            memset(buffer,0,sizeof(buffer));
            PSOCK_READTO(p, '\n');
            printf("Got: %s", buffer);
            printf("Server is Authenticated \n");
            s->state = send2;

        }
        if(s->state == send2)
        {
            PSOCK_SEND_STR(p,"certificate\n");
            s->state = send3;
        }
        if(s->state == send3)
        {
            memset(buffer,0,sizeof(buffer));
            PSOCK_READTO(p, '\n');
            printf("Got: %s", buffer);
            printf("I received servers shared key \n");
            s->state = send4;
        }
        if(s->state == send4)
        {
            printf("I accepted servers shared key \n");
            s->state = send5;
            PSOCK_SEND_STR(p,"shared key accepted\n");
        }
        if(s->state == send5)
        {
            memset(buffer,0,sizeof(buffer));
            PSOCK_READTO(p, '\n');
            printf("Got : %s", buffer);
            printf("Secure Connection Established\n");
            PSOCK_SEND_STR(p,"Connected\n");
            printf("Connected Sent\n");
        }

    }

    PSOCK_END(p);
}
コード例 #6
0
/*
 * This is the protosocket function that handles the communication. A
 * protosocket function must always return an int, but must never
 * explicitly return - all return statements are hidden in the PSOCK
 * macros.
 */
static int handle_connection(struct socket_app_state *s)
{
  PSOCK_BEGIN(&s->p);

  PSOCK_SEND_STR(&s->p, "Hello. What is you name?\n");
  PSOCK_READTO(&s->p, '\n');
  PSOCK_SEND_STR(&s->p, "Hello ");
  PSOCK_SEND_STR(&s->p, s->inputbuffer);
  memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
  PSOCK_CLOSE(&s->p);

  PSOCK_END(&s->p);
}
コード例 #7
0
ファイル: tcp_server.c プロジェクト: codywon/nrf24l01_wsn
static int hello_world_appcall(void)
{
    struct tcp_hello_appstate *s = &(uip_conn->appstate.tcp_hello);

    if(uip_connected()) {
      PSOCK_INIT(&s->p, s->inputbuffer, sizeof(s->inputbuffer));
    }

    PSOCK_BEGIN(&s->p);
    PSOCK_SEND_STR(&s->p, "Hello. What is your name?\n");
    PSOCK_READTO(&s->p, '\n');
    strncpy(s->name, s->inputbuffer, sizeof(s->name));
    s->name[strlen(s->name)-2] = 0;
    PSOCK_SEND_STR(&s->p, "Hello ");
    PSOCK_SEND_STR(&s->p, s->name);
    PSOCK_SEND_STR(&s->p, " !\n");
    sprintf(s->name, "r %d/%d", nrf_link_get_rx_packets(), nrf_link_get_rx_dropped());
    PSOCK_SEND_STR(&s->p, s->name);
    PSOCK_SEND_STR(&s->p, " ");
    sprintf(s->name, "t %d/%d", nrf_link_get_tx_packets(), nrf_link_get_tx_dropped());
    PSOCK_SEND_STR(&s->p, s->name);
    PSOCK_SEND_STR(&s->p, "\n\r");
    PSOCK_CLOSE(&s->p);
    PSOCK_END(&s->p);
}
コード例 #8
0
ファイル: hello-world.c プロジェクト: marcotuliogm/mult-UIP
 /*
  * This is the protosocket function that handles the communication. A
  * protosocket function must always return an int, but must never
  * explicitly return - all return statements are hidden in the PSOCK
  * macros.
  */
 static int
 handle_connection(struct hello_world_state *s)
 {
   PSOCK_BEGIN(&p);
 
   PSOCK_SEND_STR(&p, "Hello. What is your name?\n");
   PSOCK_READTO(&p, '\n');
   strncpy(s->name, s->inputbuffer, sizeof(s->name));
   PSOCK_SEND_STR(&p, "Hello ");
   PSOCK_SEND_STR(&p, s->name);
   PSOCK_CLOSE(&p);
   
   PSOCK_END(&p);
 }
コード例 #9
0
ファイル: socketapp.c プロジェクト: hmeyer/RadioClock
/*
 * This is the protosocket function that handles the communication. A
 * protosocket function must always return an int, but must never
 * explicitly return - all return statements are hidden in the PSOCK
 * macros.
 */
static int handle_connection(struct socket_app_state *s){
  PSOCK_BEGIN(&s->p);
  while(1){
	PSOCK_READTO(&s->p, '\n');
	if(*s->inputbuffer=='q'){
		PSOCK_SEND_STR(&s->p, "\n");
		break;
	}
	handleCommand(s->inputbuffer, s->outputbuffer);
	memset(s->inputbuffer, 0x00, SOCKET_BUFFER_LENGTH);
	PSOCK_SEND_STR(&s->p, s->outputbuffer);
  }
  PSOCK_CLOSE(&s->p);
  PSOCK_END(&s->p);
}
コード例 #10
0
ファイル: httpd-cgi.c プロジェクト: ADVANSEE/mist
/*---------------------------------------------------------------------------*/
static
PT_THREAD(rplroot(struct httpd_state *s, char *ptr))
{
  int ret;
  PSOCK_BEGIN(&s->sout);
  ret = simple_rpl_init_dag_immediately();
  if(ret == 0) {
    PSOCK_SEND_STR(&s->sout, "Becomming RPL root of the network...");
  } else if(ret == -1) {
    PSOCK_SEND_STR(&s->sout, "Failed to create a RPL root: no local address found");
  } else if(ret == -2) {
    PSOCK_SEND_STR(&s->sout, "Failed to create a RPL root: no preferred address found");
  }
  PSOCK_END(&s->sout);
}
コード例 #11
0
ファイル: example-psock-client.c プロジェクト: 1uk3/contiki
/*---------------------------------------------------------------------------*/
static int
handle_connection(struct psock *p)
{
  PSOCK_BEGIN(p);

  PSOCK_SEND_STR(p, "GET / HTTP/1.0\r\n");
  PSOCK_SEND_STR(p, "Server: Contiki example protosocket client\r\n");
  PSOCK_SEND_STR(p, "\r\n");

  while(1) {
    PSOCK_READTO(p, '\n');
    printf("Got: %s", buffer);
  }
  
  PSOCK_END(p);
}
コード例 #12
0
ファイル: tcp-server-psock.c プロジェクト: kincki/contiki
static
PT_THREAD(handle_connection(struct psock *p))
{
  static int seq_id = 1;
  
  PSOCK_BEGIN(p);
  
  while(1){
  
    PSOCK_READTO(p, '\r');
    
    buf[PSOCK_DATALEN(p)-1] = '\0';
    PRINTF("Server received: %s", buf);
    PRINTF("\r\nFrom ");
    PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
    PRINTF("\r\n");    
    
    PRINTF("Responding with message: ");
    sprintf((char*)buf, "Hello from the server! (%d)\r", seq_id++);
    PRINTF("%s\r\n", buf);
    PSOCK_SEND_STR(p, (char*)buf);
  
  }  
  
  PSOCK_END(p);
    
}
コード例 #13
0
ファイル: webserver.c プロジェクト: shinsyotta/Unlock
static int handle_connection(struct webserver_state *s)
{
	PSOCK_BEGIN(&s->p);

	// the incoming GET request will have the following format:
	// GET / HTTP/1.1 ....
	// we have to parse this string to determine the resource being requested
	// if the requested resource is not the root webpage ('/') then,
	// GET /<resource name> HTTP/1.1 ....
	// we should parse the specific resource and react appropriately

	// read incoming data until we read a space character
	PSOCK_READTO(&s->p, ISO_space);

	// parse the data to determine if it was a GET request
	if(strncmp(s->inputbuf, http_get, 4) != 0) {
		PSOCK_CLOSE_EXIT(&s->p);
	}

	// continue reading until the next space character
	PSOCK_READTO(&s->p, ISO_space);

	// determine the requested resource
	// in this case, we check if the request was for the '/' root page
	// AKA index.html
	if(s->inputbuf[0] != ISO_slash) {
		// request for unknown webpage, close and exit
		PSOCK_CLOSE_EXIT(&s->p);
	}

	if(s->inputbuf[1] != ISO_space) {
		// request for unavailable resource
		// not supported, modify to add support for additional resources
		PSOCK_CLOSE_EXIT(&s->p);
	}

	lockstate = lockstate+1;

        PSOCK_SEND_STR(&s->p, "HTTP/1.1 200 OK\r\n");
	PSOCK_SEND_STR(&s->p, "Content-Type: text/html\r\n");
	PSOCK_SEND_STR(&s->p, "\r\n");
	PSOCK_SEND_STR(&s->p, "Hello World, I am WiShield");
	PSOCK_SEND_STR(&s->p, "<center><h1>Hello World!! I am Matt's WiShield.  Find me in webserver.c under PSOCK_SEND_STR.</h1></center>");
        PSOCK_GENERATOR_SEND(&s->p, fill_buf, 0);
	PSOCK_CLOSE(&s->p);
	PSOCK_END(&s->p);
}
コード例 #14
0
ファイル: httpd-cgi.c プロジェクト: ADVANSEE/mist
/*---------------------------------------------------------------------------*/
static
PT_THREAD(reboot_function(struct httpd_state *s, char *ptr))
{
  PSOCK_BEGIN(&s->sout);
  network_reboot_reboot(120);
  PSOCK_SEND_STR(&s->sout, "Rebooting network in 120 seconds...");
  PSOCK_END(&s->sout);
}
コード例 #15
0
ファイル: socketapp.c プロジェクト: hugobast/dentsubos-pool
static int handle_connection(struct socket_app_state *s)
{
  PSOCK_BEGIN(&s->p);
  PSOCK_SEND_STR(&s->p, socket_response);

  PSOCK_CLOSE(&s->p);
  PSOCK_END(&s->p);
}
コード例 #16
0
ファイル: FTPD.c プロジェクト: Lzyuan/STE-LPC1768-
/*
 * Simple protothread to send a 421 (service unavailable)
 * when either the USB drive isn't attached or there aren't
 * any free dtpd_state entries.
 */
static PT_THREAD(send_421_response( ftpd_appstate_t *s ))
{
    PSOCK_BEGIN(&s->ps);

    PSOCK_SEND_STR(&s->ps, Resp421);
    PSOCK_CLOSE(&s->ps);

    PSOCK_END(&s->ps);
}
コード例 #17
0
static int handle_connection(struct socket_app_state *s)
{
  PSOCK_BEGIN(&s->p);
  PSOCK_READTO(&s->p, '\n');
  memcpy(buffer,s->inputbuffer,PSOCK_DATALEN(&s->p));
  memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
  PSOCK_SEND_STR(&s->p, outBuffer);
  PSOCK_END(&s->p);
}
コード例 #18
0
ファイル: ajax-cgi.c プロジェクト: 13416795/contiki
/*---------------------------------------------------------------------------*/
static
PT_THREAD(nodeidcall(struct httpd_state *s, char *ptr))
{
  static char buf[10];
  PSOCK_BEGIN(&s->sout);
  snprintf(buf, sizeof(buf), "%d.%d",
	   linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1]);
  PSOCK_SEND_STR(&s->sout, buf);
  PSOCK_END(&s->sout);
}
コード例 #19
0
ファイル: ajax-cgi.c プロジェクト: AWRyder/contiki
/*---------------------------------------------------------------------------*/
static
PT_THREAD(sensorscall(struct httpd_state *s, char *ptr))
{
  static struct timer t;
  static int i;
  static char buf[100];
  static unsigned long last_cpu, last_lpm, last_listen, last_transmit;
  
  PSOCK_BEGIN(&s->sout);

  timer_set(&t, CLOCK_SECOND);
 
  SENSORS_ACTIVATE(acc_sensor);
      
  snprintf(buf, sizeof(buf),
            "t(%d);ax(%d);ay(%d);az(%d);",
	     temperature_sensor.value(0),
	     acc_sensor.value(ACC_X_AXIS),
	     acc_sensor.value(ACC_Y_AXIS),
	     acc_sensor.value(ACC_Z_AXIS));
    
  SENSORS_DEACTIVATE(acc_sensor);

  PSOCK_SEND_STR(&s->sout, buf);


  snprintf(buf, sizeof(buf),
	     "p(%lu,%lu,%lu,%lu);v(%d);",
	     energest_type_time(ENERGEST_TYPE_CPU) - last_cpu,
	     energest_type_time(ENERGEST_TYPE_LPM) - last_lpm,
	     energest_type_time(ENERGEST_TYPE_TRANSMIT) - last_transmit,
	     energest_type_time(ENERGEST_TYPE_LISTEN) - last_listen,
	     i++);
  last_cpu = energest_type_time(ENERGEST_TYPE_CPU);
  last_lpm = energest_type_time(ENERGEST_TYPE_LPM);
  last_transmit = energest_type_time(ENERGEST_TYPE_TRANSMIT);
  last_listen = energest_type_time(ENERGEST_TYPE_LISTEN);
  PSOCK_SEND_STR(&s->sout, buf);

  PSOCK_END(&s->sout);
}
コード例 #20
0
ファイル: echo-server.c プロジェクト: RauPerez25/Wall-E
/* -------------------------------------------------------------------------- */
static PT_THREAD(handle_connection(struct psock *p))
{
    // So, as always let's start
    PSOCK_BEGIN(p);

    // Let's send a hello world
    PSOCK_SEND_STR(p, "Welcome, please type something and press return.\n");

    // Let's block this thread untile a new line is received
    PSOCK_READTO(p, '\n');

    // And what we receive, we send it back, MUAHAHA
    PSOCK_SEND_STR(p, "Got the following data: ");
    PSOCK_SEND(p, buffer, PSOCK_DATALEN(p));
    PSOCK_SEND_STR(p, "Good bye!\r\n");

    // Finally close the socket
    PSOCK_CLOSE(p);

    // The End...
    PSOCK_END(p);
}
コード例 #21
0
ファイル: hello.c プロジェクト: atalax/avr-uip-2
static PT_THREAD(run_hello(struct httpd_state *s, char *ptr))
{
	//NOTE:local variables are not preserved during the calls to proto socket functins
	static char hello_name[20] = "";
	PSOCK_BEGIN(&s->sout);
	//check if there are parameters passed
	if (s->param[0] && (find_key_val(s->param, hello_name, 20, "name") > 0)) {
		PSOCK_SEND_PSTR(&s->sout, PSTR("<H1>Hello "));
		PSOCK_SEND_STR(&s->sout, hello_name);
		PSOCK_SEND_PSTR(&s->sout, PSTR("</H1><br>"));
	}

	PSOCK_SEND_PSTR(&s->sout, PSTR("\
<form action=\"/hello.shtml\" method=\"get\" bgcolor=\"#808080\">\
Enter your name: <input type=\"text\" name=\"name\" size=\"10\" value=\""));

	PSOCK_SEND_STR(&s->sout, hello_name);

	PSOCK_SEND_PSTR(&s->sout, PSTR("\
\"/><br><input type = \"submit\" value=\"Send\" size=\"8\"> <input type = \"reset\"  value=\"cancel\" size=\"8\">"));
	PSOCK_END(&s->sout);
}
コード例 #22
0
ファイル: socketapp.c プロジェクト: thiagorogelio/RoboControl
static int handle_connection(struct socket_app_state *s)
{
  PSOCK_BEGIN(&s->p);
  
  while(1){
     PSOCK_READTO(&s->p, '\n');
     strin = s->inputbuffer;
     memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
     PSOCK_SEND_STR(&s->p, strout);
  }
  PSOCK_CLOSE(&s->p);
  PSOCK_END(&s->p);
}
コード例 #23
0
ファイル: ahrs_estimate.c プロジェクト: cloud-hot/Jennisense
static
PT_THREAD(handle_connection(struct psock *p))
{
  PSOCK_BEGIN(p);

  while (true) {
  if (PSOCK_NEWDATA(p))
    PSOCK_CLOSE(p);
  else
    PSOCK_SEND_STR(p,msg);
  }

  PSOCK_END(p);
}
コード例 #24
0
static PT_THREAD(handle_connection(struct psock *p))
{
    static char buf[100];
    PSOCK_BEGIN(p);

    snprintf(buf, sizeof(buf), "%02X:%02X		temperature: %d\n\r",
             rimeaddr_node_addr.u8[0],
             rimeaddr_node_addr.u8[1],
             temperature_sensor.value(0)/10);

    PSOCK_SEND_STR(p, buf);

    PSOCK_END(p);
}
コード例 #25
0
ファイル: webserver.c プロジェクト: imoas83/WiShield
static int handle_connection(struct webserver_state *s) {
  PSOCK_BEGIN(&s->p);
  
  /* the incoming GET request will have the following format:
   * GET / HTTP/1.1 ....
   * we have to parse this string to determine the resource being requested
   * if the requested resource is not the root webpage ('/') then,
   * GET /<resource name> HTTP/1.1 ....
   * we should parse the specific resource and react appropriately
   */
  
  // read incoming data until we read a space character
  PSOCK_READTO(&s->p, ISO_space);
  
  // parse the data to determine if it was a GET request
  if(strncmp(s->inputbuf, http_get, 4) != 0) {
    PSOCK_CLOSE_EXIT(&s->p);
  }
  
  // continue reading until the next space character
  PSOCK_READTO(&s->p, ISO_space);
  
  // determine the requested resource
  // in this case, we check if the request was for the '/' root page
  // AKA index.html
  if(s->inputbuf[0] != ISO_slash) {
    // request for unknown webpage, close and exit
    PSOCK_CLOSE_EXIT(&s->p);
  }
  
  // This is the web page served by the webserver
  PSOCK_SEND_STR(&s->p, "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\r\n");
  PSOCK_SEND_STR(&s->p, "<HTML>\r\n<HEAD>\r\n\t<META http-equiv=\"Content-type\" content=\"text/html;charset=UTF-8\">\r\n\t<TITLE>Arduino WiShield 2.0</TITLE>\r\n");
  PSOCK_SEND_STR(&s->p, "\t<STYLE type=\"text/css\">\r\n\t\tP,H1 {text-align: center;}\r\n\t</STYLE>\r\n</HEAD>\r\n<BODY>\r\n");
  PSOCK_SEND_STR(&s->p, "\t<H1>Hello World!! I am an Arduino with a WiShield 2.0</H1>\r\n\t<P><A href=\"T\">Toggle LED</A></P>\r\n");
  
  if(s->inputbuf[1] != ISO_space) {
    // request for a resource
    if(s->inputbuf[1] != ISO_T) {
      // not supported
      PSOCK_SEND_STR(&s->p, "\t<P>Request not supported</P>\r\n");
    } else {
      PSOCK_SEND_STR(&s->p, "\t<P>TOGGLE LED command received</P>\r\n");
      // Toggle WiShield 2.0 Led status
      digitalWrite(9, !digitalRead(9));
    }
  }
  
  PSOCK_SEND_STR(&s->p, "</BODY>\r\n</HTML>");
  PSOCK_CLOSE(&s->p);
  PSOCK_END(&s->p);
}
コード例 #26
0
ファイル: socketapp.c プロジェクト: m1k3lm/mOwayduinoWifiRC
/*
 * This is the protosocket function that handles the communication. A
 * protosocket function must always return an int, but must never
 * explicitly return - all return statements are hidden in the PSOCK
 * macros.
 */
static int handle_connection(struct socket_app_state *s)
{
  PSOCK_BEGIN(&s->p);

  PSOCK_SEND_STR(&s->p, "Hello. Mowayduino ready\n");
  PSOCK_READTO(&s->p, '\n');
  if (s->inputbuffer[0] == 'r')
  {
    red = 1;
    green = 0;
    blue = 0;
    PSOCK_SEND_STR(&s->p, s->inputbuffer);
    memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
  }
  else if (s->inputbuffer[0] == 'g')
  {
    red = 0;
    green = 1;
    blue = 0;
    PSOCK_SEND_STR(&s->p, s->inputbuffer);
    memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
  }
  else if (s->inputbuffer[0] == 'b')
  {
    red = 0;
    green = 0;
    blue = 1;
    PSOCK_SEND_STR(&s->p, s->inputbuffer);
    memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
  }

  if (s->inputbuffer[0] == 'q')
  {
    PSOCK_CLOSE(&s->p);
    PSOCK_END(&s->p);
  }  
}
コード例 #27
0
ファイル: ajax-cgi.c プロジェクト: AWRyder/contiki
/*---------------------------------------------------------------------------*/
static
PT_THREAD(nodeidcall(struct httpd_state *s, char *ptr))
{
  static char buf[24];
  PSOCK_BEGIN(&s->sout);
  snprintf(buf, sizeof(buf), "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
	   rimeaddr_node_addr.u8[0],
       rimeaddr_node_addr.u8[1],
       rimeaddr_node_addr.u8[2],
       rimeaddr_node_addr.u8[3],
       rimeaddr_node_addr.u8[4],
       rimeaddr_node_addr.u8[5],
       rimeaddr_node_addr.u8[6],
       rimeaddr_node_addr.u8[7]);
  PSOCK_SEND_STR(&s->sout, buf);
  PSOCK_END(&s->sout);
}
コード例 #28
0
static int handle_connection(struct socket_app_state *s)
{
  PSOCK_BEGIN(&s->p);
//  str2 = const_cast<char*>("cheney");

  Serial.print("send ");
//  str1 = const_cast<char*>("hello");
  Serial.print((const char* )hokuyo_data);
  PSOCK_SEND_STR(&s->p, hokuyo_data);

//  delay(5000);

//  PSOCK_READTO(&s->p, '\n');
//  Serial.println("after readto");

//  PSOCK_SEND_STR(&s->p, "Hello\n");
//  PSOCK_SEND_STR(&s->p, s->inputbuffer);
//  memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
  PSOCK_CLOSE(&s->p);

  PSOCK_END(&s->p);
}
コード例 #29
0
ファイル: httpd-cgi.c プロジェクト: chanhemow/contiki-fork
/*---------------------------------------------------------------------------*/
static
PT_THREAD(ajax_call(struct httpd_state *s, char *ptr))
{
  static struct timer t;
  static int iter;
  static char buf[128];
  static uint8_t numprinted;
  
  PSOCK_BEGIN(&s->sout);
/*TODO:pick up time from ? parameter */
  timer_set(&t, 2*CLOCK_SECOND);
  iter = 0;
  
  while(1) {
  	iter++;

#if CONTIKI_TARGET_SKY
    SENSORS_ACTIVATE(sht11_sensor);
    SENSORS_ACTIVATE(light_sensor);
    numprinted = snprintf(buf, sizeof(buf),
	     "t(%d);h(%d);l1(%d);l2(%d);",
	     sht11_sensor.value(SHT11_SENSOR_TEMP),
	     sht11_sensor.value(SHT11_SENSOR_HUMIDITY),
         light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC),
         light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR));
    SENSORS_DEACTIVATE(sht11_sensor);
    SENSORS_DEACTIVATE(light_sensor);

#elif CONTIKI_TARGET_MB851
  SENSORS_ACTIVATE(acc_sensor);    
  numprinted = snprintf(buf, sizeof(buf),"t(%d);ax(%d);ay(%d);az(%d);",
	     temperature_sensor.value(0),
	     acc_sensor.value(ACC_X_AXIS),
	     acc_sensor.value(ACC_Y_AXIS),
	     acc_sensor.value(ACC_Z_AXIS));   
  SENSORS_DEACTIVATE(acc_sensor);

#elif CONTIKI_TARGET_REDBEE_ECONOTAG
{	uint8_t c;
	adc_reading[8]=0;
	adc_init();
	while (adc_reading[8]==0) adc_service();
    adc_disable();
    numprinted = snprintf(buf, sizeof(buf),"b(%u);adc(%u,%u,%u,%u,%u,%u,%u,%u);",
        1200*0xfff/adc_reading[8],adc_reading[0],adc_reading[1],adc_reading[2],adc_reading[3],adc_reading[4],adc_reading[5],adc_reading[6],adc_reading[7]);
}
		
#elif CONTIKI_TARGET_MINIMAL_NET
static uint16_t c0=0x3ff,c1=0x3ff,c2=0x3ff,c3=0x3ff,c4=0x3ff,c5=0x3ff,c6=0x3ff,c7=0x3ff;
    numprinted = snprintf(buf, sizeof(buf), "t(%d);b(%u);v(%u);",273+(rand()&0x3f),3300-iter/10,iter);
	numprinted += snprintf(buf+numprinted, sizeof(buf)-numprinted,"adc(%u,%u,%u,%u,%u,%u,%u,%u);",c0,c1,c2,c3,c4,c5,c6,c7);
	c0+=(rand()&0xf)-8;
	c1+=(rand()&0xf)-8;
	c2+=(rand()&0xf)-7;
	c3+=(rand()&0x1f)-15;
	c4+=(rand()&0x3)-1;
	c5+=(rand()&0xf)-8;
	c6+=(rand()&0xf)-8;
	c7+=(rand()&0xf)-8;
  if (iter==1) {
    static const char httpd_cgi_ajax11[] HTTPD_STRING_ATTR = "wt('Minimal-net ";
	static const char httpd_cgi_ajax12[] HTTPD_STRING_ATTR = "');";
    numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax11);
#if WEBSERVER_CONF_PRINTADDR
/* Note address table is filled from the end down */
{int i;
    for (i=0; i<UIP_DS6_ADDR_NB;i++) {
      if (uip_ds6_if.addr_list[i].isused) {
	    numprinted += httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr, buf + numprinted);
	    break;
	  }
    }
}
#endif
	numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax12);
  }

#elif CONTIKI_TARGET_AVR_ATMEGA128RFA1
{ uint8_t i;int16_t tmp,bat;
  BATMON = 16; //give BATMON time to stabilize at highest range and lowest voltage
/* Measure internal temperature sensor, see atmega128rfa1 datasheet */
/* This code disabled by default for safety.
   Selecting an internal reference will short it to anything connected to the AREF pin
 */
#if 1
  ADCSRB|=1<<MUX5;          //this bit buffered till ADMUX written to!
  ADMUX =0xc9;              // Select internal 1.6 volt ref, temperature sensor ADC channel
  ADCSRA=0x85;              //Enable ADC, not free running, interrupt disabled, clock divider 32 (250 KHz@ 8 MHz)
//  while ((ADCSRB&(1<<AVDDOK))==0);  //wait for AVDD ok
//  while ((ADCSRB&(1<<REFOK))==0);  //wait for ref ok 
  ADCSRA|=1<<ADSC;          //Start throwaway conversion
  while (ADCSRA&(1<<ADSC)); //Wait till done
  ADCSRA|=1<<ADSC;          //Start another conversion
  while (ADCSRA&(1<<ADSC)); //Wait till done
  tmp=ADC;                  //Read adc
  tmp=11*tmp-2728+(tmp>>2); //Convert to celcius*10 (should be 11.3*h, approximate with 11.25*h)
  ADCSRA=0;                 //disable ADC
  ADMUX=0;                  //turn off internal vref      
#endif
/* Bandgap can't be measured against supply voltage in this chip. */
/* Use BATMON register instead */
  for ( i=16; i<31; i++) {
    BATMON = i;
    if ((BATMON&(1<<BATMON_OK))==0) break;
  }
  bat=2550-75*16-75+75*i;  //-75 to take the floor of the 75 mv transition window
  static const char httpd_cgi_ajax10[] HTTPD_STRING_ATTR ="t(%u),b(%u);adc(%d,%d,%u,%u,%u,%u,%u,%lu);";
  numprinted = httpd_snprintf(buf, sizeof(buf),httpd_cgi_ajax10,tmp,bat,iter,tmp,bat,sleepcount,OCR2A,0,clock_time(),clock_seconds());
  if (iter==1) {
    static const char httpd_cgi_ajax11[] HTTPD_STRING_ATTR = "wt('128rfa1 [";
	static const char httpd_cgi_ajax12[] HTTPD_STRING_ATTR = "]');";
    numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax11);
#if WEBSERVER_CONF_PRINTADDR
/* Note address table is filled from the end down */
{int i;
    for (i=0; i<UIP_DS6_ADDR_NB;i++) {
      if (uip_ds6_if.addr_list[i].isused) {
	    numprinted += httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr, buf + numprinted);
	    break;
	  }
    }
}
#endif
	numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax12);
  }
}
#elif CONTIKI_TARGET_AVR_RAVEN
{ int16_t tmp,bat;
#if 1
/* Usual way to get AVR supply voltage, measure 1.1v bandgap using Vcc as reference.
 * This connects the bandgap to the AREF pin, so enable only if there is no external AREF!
 * A capacitor may be connected to this pin to reduce reference noise.
 */
  ADMUX =0x5E;              //Select AVCC as reference, measure 1.1 volt bandgap reference.
  ADCSRA=0x87;              //Enable ADC, not free running, interrupt disabled, clock divider  128 (62 KHz@ 8 MHz)
  ADCSRA|=1<<ADSC;          //Start throwaway conversion
  while (ADCSRA&(1<<ADSC)); //Wait till done
  ADCSRA|=1<<ADSC;          //Start another conversion
  while (ADCSRA&(1<<ADSC)); //Wait till done
//bat=1126400UL/ADC;        //Get supply voltage (factor nominally 1100*1024)
  bat=1198070UL/ADC;        //My Raven
  ADCSRA=0;                 //disable ADC
  ADMUX=0;                  //turn off internal vref
#else
  bat=3300;  
#endif
   
  tmp=420;
  
  static const char httpd_cgi_ajax10[] HTTPD_STRING_ATTR ="t(%u),b(%u);adc(%d,%d,%u,%u,%u,%u,%u,%lu);";
  numprinted = httpd_snprintf(buf, sizeof(buf),httpd_cgi_ajax10,tmp,bat,iter,tmp,bat,sleepcount,OCR2A,0,clock_time(),clock_seconds());
  if (iter<3) {
    static const char httpd_cgi_ajax11[] HTTPD_STRING_ATTR = "wt('Raven [";
	static const char httpd_cgi_ajax12[] HTTPD_STRING_ATTR = "]');";
    numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax11);
#if WEBSERVER_CONF_PRINTADDR
/* Note address table is filled from the end down */
{int i;
    for (i=0; i<UIP_DS6_ADDR_NB;i++) {
      if (uip_ds6_if.addr_list[i].isused) {
	    numprinted += httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr, buf + numprinted);
	    break;
	  }
    }
}
#endif
	numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax12);
  }
}

//#elif CONTIKI_TARGET_IS_SOMETHING_ELSE
#else
{
  static const char httpd_cgi_ajax10[] HTTPD_STRING_ATTR ="v(%u);";
  numprinted = httpd_snprintf(buf, sizeof(buf),httpd_cgi_ajax10,iter);
  if (iter==1) {
    static const char httpd_cgi_ajax11[] HTTPD_STRING_ATTR = "wt('Contiki Ajax ";
	static const char httpd_cgi_ajax12[] HTTPD_STRING_ATTR = "');";
    numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax11);
#if WEBSERVER_CONF_PRINTADDR
/* Note address table is filled from the end down */
{int i;
    for (i=0; i<UIP_DS6_ADDR_NB;i++) {
      if (uip_ds6_if.addr_list[i].isused) {
	    numprinted += httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr, buf + numprinted);
	    break;
	  }
    }
}
#endif
	numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax12);
  }
}
#endif
 
#if CONTIKIMAC_CONF_COMPOWER
#include "sys/compower.h"
{
//sl=compower_idle_activity.transmit/RTIMER_ARCH_SECOND;
//sl=compower_idle_activity.listen/RTIMER_ARCH_SECOND;
}
#endif

#if RIMESTATS_CONF_ON

#include "net/rime/rimestats.h"
    static const char httpd_cgi_ajaxr1[] HTTPD_STRING_ATTR ="rime(%lu,%lu,%lu,%lu);";
    numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajaxr1,
		rimestats.tx,rimestats.rx,rimestats.lltx-rimestats.tx,rimestats.llrx-rimestats.rx);
#endif

#if ENERGEST_CONF_ON
{
#if 1
/* Send on times in percent since last update. Handle 16 bit rtimer wraparound. */
/* Javascript must convert based on platform cpu, tx, rx power, e.g. 20ma*3v3=66mW*(% on time/100) */
	static rtimer_clock_t last_send;
	rtimer_clock_t delta_time;
    static unsigned long last_cpu, last_lpm, last_listen, last_transmit;
    energest_flush();
	delta_time=RTIMER_NOW()-last_send;
	if (RTIMER_CLOCK_LT(RTIMER_NOW(),last_send)) delta_time+=RTIMER_ARCH_SECOND;
	last_send=RTIMER_NOW();
    static const char httpd_cgi_ajaxe1[] HTTPD_STRING_ATTR = "p(%lu,%lu,%lu,%lu);";	
    numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajaxe1,
	    (100UL*(energest_total_time[ENERGEST_TYPE_CPU].current - last_cpu))/delta_time,
		(100UL*(energest_total_time[ENERGEST_TYPE_LPM].current - last_lpm))/delta_time,
        (100UL*(energest_total_time[ENERGEST_TYPE_TRANSMIT].current - last_transmit))/delta_time,
        (100UL*(energest_total_time[ENERGEST_TYPE_LISTEN].current - last_listen))/delta_time);
    last_cpu = energest_total_time[ENERGEST_TYPE_CPU].current;
    last_lpm = energest_total_time[ENERGEST_TYPE_LPM].current;
    last_transmit = energest_total_time[ENERGEST_TYPE_TRANSMIT].current;
    last_listen = energest_total_time[ENERGEST_TYPE_LISTEN].current;
#endif
#if 1
/* Send cumulative on times in percent*100 */
	uint16_t cpp,txp,rxp;
	uint32_t sl,clockseconds=clock_seconds();
//	energest_flush();
//	sl=((10000UL*energest_total_time[ENERGEST_TYPE_CPU].current)/RTIMER_ARCH_SECOND)/clockseconds;
    sl=energest_total_time[ENERGEST_TYPE_CPU].current/RTIMER_ARCH_SECOND;
    cpp=(10000UL*sl)/clockseconds;
//    txp=((10000UL*energest_total_time[ENERGEST_TYPE_TRANSMIT].current)/RTIMER_ARCH_SECOND)/clockseconds;
    sl=energest_total_time[ENERGEST_TYPE_TRANSMIT].current/RTIMER_ARCH_SECOND;
    txp=(10000UL*sl)/clockseconds;

 //   rxp=((10000UL*energest_total_time[ENERGEST_TYPE_LISTEN].current)/RTIMER_ARCH_SECOND)/clockseconds;
    sl=energest_total_time[ENERGEST_TYPE_LISTEN].current/RTIMER_ARCH_SECOND;
    rxp=(10000UL*sl)/clockseconds;

    static const char httpd_cgi_ajaxe2[] HTTPD_STRING_ATTR = "ener(%u,%u,%u);";	
    numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajaxe2,cpp,txp,rxp);
#endif
}
#endif /* ENERGEST_CONF_ON */
 
    PSOCK_SEND_STR(&s->sout, buf);
    timer_restart(&t);
	PSOCK_WAIT_UNTIL(&s->sout, timer_expired(&t));
}
  PSOCK_END(&s->sout);
}
コード例 #30
0
ファイル: smtp.c プロジェクト: ichpuchtli/freeburn
/*---------------------------------------------------------------------------*/
static
PT_THREAD(smtp_thread(void))
{
  PSOCK_BEGIN(&s.psock);

  PSOCK_READTO(&s.psock, ISO_nl);
   
  if(strncmp(s.inputbuffer, smtp_220, 3) != 0) {
    PSOCK_CLOSE(&s.psock);
    smtp_done(2);
    PSOCK_EXIT(&s.psock);
  }
  
  PSOCK_SEND_STR(&s.psock, (char *)smtp_helo);
  PSOCK_SEND_STR(&s.psock, localhostname);
  PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);

  PSOCK_READTO(&s.psock, ISO_nl);
  
  if(s.inputbuffer[0] != ISO_2) {
    PSOCK_CLOSE(&s.psock);
    smtp_done(3);
    PSOCK_EXIT(&s.psock);
  }

  PSOCK_SEND_STR(&s.psock, (char *)smtp_mail_from);
  PSOCK_SEND_STR(&s.psock, s.from);
  PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);

  PSOCK_READTO(&s.psock, ISO_nl);
  
  if(s.inputbuffer[0] != ISO_2) {
    PSOCK_CLOSE(&s.psock);
    smtp_done(4);
    PSOCK_EXIT(&s.psock);
  }

  PSOCK_SEND_STR(&s.psock, (char *)smtp_rcpt_to);
  PSOCK_SEND_STR(&s.psock, s.to);
  PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);

  PSOCK_READTO(&s.psock, ISO_nl);
  
  if(s.inputbuffer[0] != ISO_2) {
    PSOCK_CLOSE(&s.psock);
    smtp_done(5);
    PSOCK_EXIT(&s.psock);
  }
  
  if(s.cc != 0) {
    PSOCK_SEND_STR(&s.psock, (char *)smtp_rcpt_to);
    PSOCK_SEND_STR(&s.psock, s.cc);
    PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);

    PSOCK_READTO(&s.psock, ISO_nl);
  
    if(s.inputbuffer[0] != ISO_2) {
      PSOCK_CLOSE(&s.psock);
      smtp_done(6);
      PSOCK_EXIT(&s.psock);
    }
  }
  
  PSOCK_SEND_STR(&s.psock, (char *)smtp_data);
  
  PSOCK_READTO(&s.psock, ISO_nl);
  
  if(s.inputbuffer[0] != ISO_3) {
    PSOCK_CLOSE(&s.psock);
    smtp_done(7);
    PSOCK_EXIT(&s.psock);
  }

  PSOCK_SEND_STR(&s.psock, (char *)smtp_to);
  PSOCK_SEND_STR(&s.psock, s.to);
  PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);
  
  if(s.cc != 0) {
    PSOCK_SEND_STR(&s.psock, (char *)smtp_cc);
    PSOCK_SEND_STR(&s.psock, s.cc);
    PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);
  }
  
  PSOCK_SEND_STR(&s.psock, (char *)smtp_from);
  PSOCK_SEND_STR(&s.psock, s.from);
  PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);
  
  PSOCK_SEND_STR(&s.psock, (char *)smtp_subject);
  PSOCK_SEND_STR(&s.psock, s.subject);
  PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);

  PSOCK_SEND(&s.psock, s.msg, s.msglen);
  
  PSOCK_SEND_STR(&s.psock, (char *)smtp_crnlperiodcrnl);

  PSOCK_READTO(&s.psock, ISO_nl);
  if(s.inputbuffer[0] != ISO_2) {
    PSOCK_CLOSE(&s.psock);
    smtp_done(8);
    PSOCK_EXIT(&s.psock);
  }

  PSOCK_SEND_STR(&s.psock, (char *)smtp_quit);
  smtp_done(SMTP_ERR_OK);
  PSOCK_END(&s.psock);
}