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.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* A simple example using HTTP to control and be controlled
@ -35,7 +35,7 @@
* Niclas Finne <nfi@sics.se>
* Joakim Eriksson <joakime@sics.se>
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "dev/button-sensor.h"
#include "dev/leds.h"
@ -43,7 +43,7 @@
#include "webserver-nogui.h"
#include "httpd-simple.h"
#include <stdio.h>
/*---------------------------------------------------------------------------*/
/* The address of the server to register the services for this node */
#define SERVER "aaaa::1"
@ -56,11 +56,9 @@
/* The commands to send to the other node */
#define SET_LEDS_ON "/1"
#define SET_LEDS_OFF "/0"
/*---------------------------------------------------------------------------*/
PROCESS(websense_remote_process, "Websense Remote");
AUTOSTART_PROCESSES(&websense_remote_process);
/*---------------------------------------------------------------------------*/
static const char *TOP = "<html><head><title>Contiki Websense Remote</title></head><body>\n";
static const char *BOTTOM = "</body></html>\n";
@ -161,7 +159,6 @@ PROCESS_THREAD(websense_remote_process, ev, data)
}
/* Alternate between the two commands */
mode = !mode;
} else if(ev == PROCESS_EVENT_TIMER && etimer_expired(&timer)) {
printf("Registering services\n");
send_command(SERVER, REGISTER_COMMAND);

View File

@ -27,7 +27,7 @@
* SUCH DAMAGE.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* A simple wget implementation
@ -35,25 +35,26 @@
* Niclas Finne <nfi@sics.se>
* Joakim Eriksson <joakime@sics.se>
*/
/*---------------------------------------------------------------------------*/
#include "webclient.h"
#include "wget.h"
#include "dev/leds.h"
/*---------------------------------------------------------------------------*/
#define DEBUG DEBUG_NONE
#include "net/ip/uip-debug.h"
/*---------------------------------------------------------------------------*/
#define DEBUG_LEDS 0
#undef LEDS_ON
#undef LEDS_OFF
#if DEBUG_LEDS
#define LEDS_ON(led) leds_on(led)
#define LEDS_OFF(led) leds_off(led)
#else
#define LEDS_ON(led)
#define LEDS_OFF(led)
#endif /* DEBUG */
#endif /* DEBUG_LEDS */
/*---------------------------------------------------------------------------*/
static int fetch_running;
#define STATS ((DEBUG)&DEBUG_PRINT) && 1
@ -66,9 +67,8 @@ static const char *server;
static const char *file;
static uint16_t port;
static const struct wget_callbacks *callbacks;
/*---------------------------------------------------------------------------*/
PROCESS(wget_process, "wget");
/*---------------------------------------------------------------------------*/
static void
call_done(int status)

View File

@ -27,7 +27,7 @@
* SUCH DAMAGE.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* Battery and Temperature IPv6 Demo for Zolertia Z1
@ -37,7 +37,7 @@
* Joel Hoglund <joel@sics.se>
* Enric M. Calvo <ecalvo@zolertia.com>
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "httpd-simple.h"
#include "webserver-nogui.h"
@ -46,22 +46,23 @@
#include "cc2420.h"
#include "dev/leds.h"
#include <stdio.h>
float floor(float x){
if(x>=0.0f) return (float) ((int)x);
else return (float) ((int)x-1);
/*---------------------------------------------------------------------------*/
float
floor(float x)
{
if(x >= 0.0f) {
return (float)((int)x);
} else { return (float)((int)x - 1);
}
}
/*---------------------------------------------------------------------------*/
PROCESS(web_sense_process, "Sense Web Demo");
AUTOSTART_PROCESSES(&web_sense_process);
/*---------------------------------------------------------------------------*/
#define HISTORY 16
static int temperature[HISTORY];
static int battery1[HISTORY];
static int sensors_pos;
/*---------------------------------------------------------------------------*/
static int
get_battery(void)
@ -74,10 +75,16 @@ get_temp(void)
{
return temperature_sensor.value(0);
}
static float get_mybatt(void){ return (float) ((get_battery()*2.500*2)/4096);}
static float get_mytemp(void){ return (float) (((get_temp()*2.500)/4096)-0.986)*282;}
static float
get_mybatt(void)
{
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 *BOTTOM = "</body></html>\n";
@ -88,8 +95,10 @@ static int blen;
#define ADD(...) do { \
blen += snprintf(&buf[blen], sizeof(buf) - blen, __VA_ARGS__); \
} while(0)
/*---------------------------------------------------------------------------*/
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;
blen = 0;
@ -103,6 +112,7 @@ generate_chart(const char *title, const char *unit, int min, int max, int *value
}
ADD("\">");
}
/*---------------------------------------------------------------------------*/
static
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)mytemp, (unsigned)((mytemp - floor(mytemp)) * 1000));
SEND_STRING(&s->sout, buf);
} else if(s->filename[1] == '0') {
/* Turn off leds */
leds_off(LEDS_ALL);
SEND_STRING(&s->sout, "Turned off leds!");
} else if(s->filename[1] == '1') {
/* Turn on leds */
leds_on(LEDS_ALL);
SEND_STRING(&s->sout, "Turned on leds!");
} else {
if(s->filename[1] != 't') {
generate_chart("Battery", "mV", 0, 4000, battery1);