Fix code style: Z1 websense example

This commit is contained in:
George Oikonomou 2015-11-24 12:00:56 +00:00 committed by Antonio Lignan
parent e1f6d39857
commit be1bd9a619
4 changed files with 53 additions and 49 deletions

View file

@ -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);

View file

@ -27,7 +27,7 @@
* SUCH DAMAGE. * SUCH DAMAGE.
* *
*/ */
/*---------------------------------------------------------------------------*/
/** /**
* \file * \file
* A simple wget implementation * A simple wget implementation
@ -35,25 +35,26 @@
* 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
@ -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)

View file

@ -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";
@ -88,8 +95,10 @@ 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))
{ {
@ -123,17 +133,14 @@ PT_THREAD(send_values(struct httpd_state *s))
(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);