Fix code style: Z1 websense example
This commit is contained in:
parent
e1f6d39857
commit
be1bd9a619
|
@ -27,7 +27,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* A simple example using HTTP to control and be controlled
|
* A simple example using HTTP to control and be controlled
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
* Niclas Finne <nfi@sics.se>
|
* Niclas Finne <nfi@sics.se>
|
||||||
* Joakim Eriksson <joakime@sics.se>
|
* Joakim Eriksson <joakime@sics.se>
|
||||||
*/
|
*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
#include "dev/button-sensor.h"
|
#include "dev/button-sensor.h"
|
||||||
#include "dev/leds.h"
|
#include "dev/leds.h"
|
||||||
|
@ -43,7 +43,7 @@
|
||||||
#include "webserver-nogui.h"
|
#include "webserver-nogui.h"
|
||||||
#include "httpd-simple.h"
|
#include "httpd-simple.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
/* The address of the server to register the services for this node */
|
/* The address of the server to register the services for this node */
|
||||||
#define SERVER "aaaa::1"
|
#define SERVER "aaaa::1"
|
||||||
|
|
||||||
|
@ -56,11 +56,9 @@
|
||||||
/* The commands to send to the other node */
|
/* The commands to send to the other node */
|
||||||
#define SET_LEDS_ON "/1"
|
#define SET_LEDS_ON "/1"
|
||||||
#define SET_LEDS_OFF "/0"
|
#define SET_LEDS_OFF "/0"
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
PROCESS(websense_remote_process, "Websense Remote");
|
PROCESS(websense_remote_process, "Websense Remote");
|
||||||
|
|
||||||
AUTOSTART_PROCESSES(&websense_remote_process);
|
AUTOSTART_PROCESSES(&websense_remote_process);
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static const char *TOP = "<html><head><title>Contiki Websense Remote</title></head><body>\n";
|
static const char *TOP = "<html><head><title>Contiki Websense Remote</title></head><body>\n";
|
||||||
static const char *BOTTOM = "</body></html>\n";
|
static const char *BOTTOM = "</body></html>\n";
|
||||||
|
@ -161,7 +159,6 @@ PROCESS_THREAD(websense_remote_process, ev, data)
|
||||||
}
|
}
|
||||||
/* Alternate between the two commands */
|
/* Alternate between the two commands */
|
||||||
mode = !mode;
|
mode = !mode;
|
||||||
|
|
||||||
} else if(ev == PROCESS_EVENT_TIMER && etimer_expired(&timer)) {
|
} else if(ev == PROCESS_EVENT_TIMER && etimer_expired(&timer)) {
|
||||||
printf("Registering services\n");
|
printf("Registering services\n");
|
||||||
send_command(SERVER, REGISTER_COMMAND);
|
send_command(SERVER, REGISTER_COMMAND);
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* A simple wget implementation
|
* A simple wget implementation
|
||||||
|
@ -35,28 +35,29 @@
|
||||||
* Niclas Finne <nfi@sics.se>
|
* Niclas Finne <nfi@sics.se>
|
||||||
* Joakim Eriksson <joakime@sics.se>
|
* Joakim Eriksson <joakime@sics.se>
|
||||||
*/
|
*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
#include "webclient.h"
|
#include "webclient.h"
|
||||||
#include "wget.h"
|
#include "wget.h"
|
||||||
#include "dev/leds.h"
|
#include "dev/leds.h"
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
#define DEBUG DEBUG_NONE
|
#define DEBUG DEBUG_NONE
|
||||||
#include "net/ip/uip-debug.h"
|
#include "net/ip/uip-debug.h"
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
#define DEBUG_LEDS 0
|
#define DEBUG_LEDS 0
|
||||||
#undef LEDS_ON
|
#undef LEDS_ON
|
||||||
#undef LEDS_OFF
|
#undef LEDS_OFF
|
||||||
|
|
||||||
#if DEBUG_LEDS
|
#if DEBUG_LEDS
|
||||||
#define LEDS_ON(led) leds_on(led)
|
#define LEDS_ON(led) leds_on(led)
|
||||||
#define LEDS_OFF(led) leds_off(led)
|
#define LEDS_OFF(led) leds_off(led)
|
||||||
#else
|
#else
|
||||||
#define LEDS_ON(led)
|
#define LEDS_ON(led)
|
||||||
#define LEDS_OFF(led)
|
#define LEDS_OFF(led)
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUG_LEDS */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
static int fetch_running;
|
static int fetch_running;
|
||||||
|
|
||||||
#define STATS ((DEBUG) & DEBUG_PRINT) && 1
|
#define STATS ((DEBUG)&DEBUG_PRINT) && 1
|
||||||
#if STATS
|
#if STATS
|
||||||
static clock_time_t fetch_started;
|
static clock_time_t fetch_started;
|
||||||
static unsigned long fetch_counter;
|
static unsigned long fetch_counter;
|
||||||
|
@ -66,9 +67,8 @@ static const char *server;
|
||||||
static const char *file;
|
static const char *file;
|
||||||
static uint16_t port;
|
static uint16_t port;
|
||||||
static const struct wget_callbacks *callbacks;
|
static const struct wget_callbacks *callbacks;
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
PROCESS(wget_process, "wget");
|
PROCESS(wget_process, "wget");
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
call_done(int status)
|
call_done(int status)
|
||||||
|
@ -115,11 +115,11 @@ webclient_datahandler(char *data, uint16_t len)
|
||||||
PRINTF("wget: recv %lu bytes during %lu sec (",
|
PRINTF("wget: recv %lu bytes during %lu sec (",
|
||||||
fetch_counter, (elapsed / CLOCK_SECOND));
|
fetch_counter, (elapsed / CLOCK_SECOND));
|
||||||
#if CLOCK_SECOND == 128
|
#if CLOCK_SECOND == 128
|
||||||
PRINTF("%lu.%02lus, ", (unsigned long) elapsed >> 7,
|
PRINTF("%lu.%02lus, ", (unsigned long)elapsed >> 7,
|
||||||
(unsigned long)((elapsed & 127) * 100) / 128);
|
(unsigned long)((elapsed & 127) * 100) / 128);
|
||||||
PRINTF("%lu byte/sec ", (fetch_counter * 128L) / elapsed);
|
PRINTF("%lu byte/sec ", (fetch_counter * 128L) / elapsed);
|
||||||
#endif
|
#endif
|
||||||
PRINTF("%lu tick): ", (unsigned long) elapsed);
|
PRINTF("%lu tick): ", (unsigned long)elapsed);
|
||||||
if(elapsed > CLOCK_SECOND) {
|
if(elapsed > CLOCK_SECOND) {
|
||||||
PRINTF("%lu", fetch_counter / (elapsed / CLOCK_SECOND));
|
PRINTF("%lu", fetch_counter / (elapsed / CLOCK_SECOND));
|
||||||
} else {
|
} else {
|
||||||
|
@ -132,7 +132,7 @@ webclient_datahandler(char *data, uint16_t len)
|
||||||
|
|
||||||
fetch_running = 0;
|
fetch_running = 0;
|
||||||
call_done(WGET_OK);
|
call_done(WGET_OK);
|
||||||
LEDS_OFF(LEDS_RED|LEDS_YELLOW);
|
LEDS_OFF(LEDS_RED | LEDS_YELLOW);
|
||||||
} else {
|
} else {
|
||||||
#if STATS
|
#if STATS
|
||||||
fetch_counter += len;
|
fetch_counter += len;
|
||||||
|
@ -156,7 +156,7 @@ void
|
||||||
webclient_timedout(void)
|
webclient_timedout(void)
|
||||||
{
|
{
|
||||||
PRINTF("wget: timedout\n");
|
PRINTF("wget: timedout\n");
|
||||||
LEDS_OFF(LEDS_RED|LEDS_YELLOW);
|
LEDS_OFF(LEDS_RED | LEDS_YELLOW);
|
||||||
fetch_running = 0;
|
fetch_running = 0;
|
||||||
call_done(WGET_TIMEDOUT);
|
call_done(WGET_TIMEDOUT);
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ void
|
||||||
webclient_aborted(void)
|
webclient_aborted(void)
|
||||||
{
|
{
|
||||||
PRINTF("wget: aborted\n");
|
PRINTF("wget: aborted\n");
|
||||||
LEDS_OFF(LEDS_RED|LEDS_YELLOW);
|
LEDS_OFF(LEDS_RED | LEDS_YELLOW);
|
||||||
fetch_running = 0;
|
fetch_running = 0;
|
||||||
call_done(WGET_ABORTED);
|
call_done(WGET_ABORTED);
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ webclient_closed(void)
|
||||||
{
|
{
|
||||||
PRINTF("wget: closed\n");
|
PRINTF("wget: closed\n");
|
||||||
fetch_running = 0;
|
fetch_running = 0;
|
||||||
LEDS_OFF(LEDS_RED|LEDS_YELLOW);
|
LEDS_OFF(LEDS_RED | LEDS_YELLOW);
|
||||||
call_done(WGET_CLOSED);
|
call_done(WGET_CLOSED);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -42,8 +42,8 @@
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
|
|
||||||
struct wget_callbacks {
|
struct wget_callbacks {
|
||||||
void (* data)(const char *data, uint16_t len);
|
void (*data)(const char *data, uint16_t len);
|
||||||
void (* done)(int status);
|
void (*done)(int status);
|
||||||
};
|
};
|
||||||
|
|
||||||
void wget_init(void);
|
void wget_init(void);
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* Battery and Temperature IPv6 Demo for Zolertia Z1
|
* Battery and Temperature IPv6 Demo for Zolertia Z1
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
* Joel Hoglund <joel@sics.se>
|
* Joel Hoglund <joel@sics.se>
|
||||||
* Enric M. Calvo <ecalvo@zolertia.com>
|
* Enric M. Calvo <ecalvo@zolertia.com>
|
||||||
*/
|
*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
#include "httpd-simple.h"
|
#include "httpd-simple.h"
|
||||||
#include "webserver-nogui.h"
|
#include "webserver-nogui.h"
|
||||||
|
@ -46,22 +46,23 @@
|
||||||
#include "cc2420.h"
|
#include "cc2420.h"
|
||||||
#include "dev/leds.h"
|
#include "dev/leds.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
float
|
||||||
float floor(float x){
|
floor(float x)
|
||||||
if(x>=0.0f) return (float) ((int)x);
|
{
|
||||||
else return (float) ((int)x-1);
|
if(x >= 0.0f) {
|
||||||
|
return (float)((int)x);
|
||||||
|
} else { return (float)((int)x - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
PROCESS(web_sense_process, "Sense Web Demo");
|
PROCESS(web_sense_process, "Sense Web Demo");
|
||||||
|
|
||||||
AUTOSTART_PROCESSES(&web_sense_process);
|
AUTOSTART_PROCESSES(&web_sense_process);
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
#define HISTORY 16
|
#define HISTORY 16
|
||||||
static int temperature[HISTORY];
|
static int temperature[HISTORY];
|
||||||
static int battery1[HISTORY];
|
static int battery1[HISTORY];
|
||||||
static int sensors_pos;
|
static int sensors_pos;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
get_battery(void)
|
get_battery(void)
|
||||||
|
@ -74,10 +75,16 @@ get_temp(void)
|
||||||
{
|
{
|
||||||
return temperature_sensor.value(0);
|
return temperature_sensor.value(0);
|
||||||
}
|
}
|
||||||
|
static float
|
||||||
static float get_mybatt(void){ return (float) ((get_battery()*2.500*2)/4096);}
|
get_mybatt(void)
|
||||||
static float get_mytemp(void){ return (float) (((get_temp()*2.500)/4096)-0.986)*282;}
|
{
|
||||||
|
return (float)((get_battery() * 2.500 * 2) / 4096);
|
||||||
|
}
|
||||||
|
static float
|
||||||
|
get_mytemp(void)
|
||||||
|
{
|
||||||
|
return (float)(((get_temp() * 2.500) / 4096) - 0.986) * 282;
|
||||||
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static const char *TOP = "<html><head><title>Contiki Web Sense</title></head><body>\n";
|
static const char *TOP = "<html><head><title>Contiki Web Sense</title></head><body>\n";
|
||||||
static const char *BOTTOM = "</body></html>\n";
|
static const char *BOTTOM = "</body></html>\n";
|
||||||
|
@ -85,11 +92,13 @@ static const char *BOTTOM = "</body></html>\n";
|
||||||
/* Only one single request at time */
|
/* Only one single request at time */
|
||||||
static char buf[256];
|
static char buf[256];
|
||||||
static int blen;
|
static int blen;
|
||||||
#define ADD(...) do { \
|
#define ADD(...) do { \
|
||||||
blen += snprintf(&buf[blen], sizeof(buf) - blen, __VA_ARGS__); \
|
blen += snprintf(&buf[blen], sizeof(buf) - blen, __VA_ARGS__); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
generate_chart(const char *title, const char *unit, int min, int max, int *values)
|
generate_chart(const char *title, const char *unit, int min, int max,
|
||||||
|
int *values)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
blen = 0;
|
blen = 0;
|
||||||
|
@ -103,6 +112,7 @@ generate_chart(const char *title, const char *unit, int min, int max, int *value
|
||||||
}
|
}
|
||||||
ADD("\">");
|
ADD("\">");
|
||||||
}
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
static
|
static
|
||||||
PT_THREAD(send_values(struct httpd_state *s))
|
PT_THREAD(send_values(struct httpd_state *s))
|
||||||
{
|
{
|
||||||
|
@ -120,20 +130,17 @@ PT_THREAD(send_values(struct httpd_state *s))
|
||||||
ADD("<h1>Current readings</h1>\n"
|
ADD("<h1>Current readings</h1>\n"
|
||||||
"Battery: %ld.%03d V<br>"
|
"Battery: %ld.%03d V<br>"
|
||||||
"Temperature: %ld.%03d ° C",
|
"Temperature: %ld.%03d ° C",
|
||||||
(long) mybatt, (unsigned) ((mybatt-floor(mybatt))*1000),
|
(long)mybatt, (unsigned)((mybatt - floor(mybatt)) * 1000),
|
||||||
(long) mytemp, (unsigned) ((mytemp-floor(mytemp))*1000));
|
(long)mytemp, (unsigned)((mytemp - floor(mytemp)) * 1000));
|
||||||
SEND_STRING(&s->sout, buf);
|
SEND_STRING(&s->sout, buf);
|
||||||
|
|
||||||
} else if(s->filename[1] == '0') {
|
} else if(s->filename[1] == '0') {
|
||||||
/* Turn off leds */
|
/* Turn off leds */
|
||||||
leds_off(LEDS_ALL);
|
leds_off(LEDS_ALL);
|
||||||
SEND_STRING(&s->sout, "Turned off leds!");
|
SEND_STRING(&s->sout, "Turned off leds!");
|
||||||
|
|
||||||
} else if(s->filename[1] == '1') {
|
} else if(s->filename[1] == '1') {
|
||||||
/* Turn on leds */
|
/* Turn on leds */
|
||||||
leds_on(LEDS_ALL);
|
leds_on(LEDS_ALL);
|
||||||
SEND_STRING(&s->sout, "Turned on leds!");
|
SEND_STRING(&s->sout, "Turned on leds!");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if(s->filename[1] != 't') {
|
if(s->filename[1] != 't') {
|
||||||
generate_chart("Battery", "mV", 0, 4000, battery1);
|
generate_chart("Battery", "mV", 0, 4000, battery1);
|
||||||
|
@ -173,7 +180,7 @@ PROCESS_THREAD(web_sense_process, ev, data)
|
||||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
|
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
|
||||||
etimer_reset(&timer);
|
etimer_reset(&timer);
|
||||||
|
|
||||||
battery1[sensors_pos] = get_mybatt()*1000;
|
battery1[sensors_pos] = get_mybatt() * 1000;
|
||||||
temperature[sensors_pos] = get_mytemp();
|
temperature[sensors_pos] = get_mytemp();
|
||||||
sensors_pos = (sensors_pos + 1) % HISTORY;
|
sensors_pos = (sensors_pos + 1) % HISTORY;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue