From be1bd9a6191997a53fb79233b8ba9a66e0389ca0 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Tue, 24 Nov 2015 12:00:56 +0000 Subject: [PATCH] Fix code style: Z1 websense example --- .../z1/ipv6/z1-websense/websense-remote.c | 11 ++-- examples/zolertia/z1/ipv6/z1-websense/wget.c | 30 +++++----- examples/zolertia/z1/ipv6/z1-websense/wget.h | 4 +- .../z1/ipv6/z1-websense/z1-websense.c | 57 +++++++++++-------- 4 files changed, 53 insertions(+), 49 deletions(-) diff --git a/examples/zolertia/z1/ipv6/z1-websense/websense-remote.c b/examples/zolertia/z1/ipv6/z1-websense/websense-remote.c index 7323293ca..7cfebd355 100644 --- a/examples/zolertia/z1/ipv6/z1-websense/websense-remote.c +++ b/examples/zolertia/z1/ipv6/z1-websense/websense-remote.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * */ - +/*---------------------------------------------------------------------------*/ /** * \file * A simple example using HTTP to control and be controlled @@ -35,7 +35,7 @@ * Niclas Finne * Joakim Eriksson */ - +/*---------------------------------------------------------------------------*/ #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 - +/*---------------------------------------------------------------------------*/ /* 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 = "Contiki Websense Remote\n"; static const char *BOTTOM = "\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); diff --git a/examples/zolertia/z1/ipv6/z1-websense/wget.c b/examples/zolertia/z1/ipv6/z1-websense/wget.c index 3d9b56974..d55040b11 100644 --- a/examples/zolertia/z1/ipv6/z1-websense/wget.c +++ b/examples/zolertia/z1/ipv6/z1-websense/wget.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * */ - +/*---------------------------------------------------------------------------*/ /** * \file * A simple wget implementation @@ -35,28 +35,29 @@ * Niclas Finne * Joakim Eriksson */ - +/*---------------------------------------------------------------------------*/ #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 +#define STATS ((DEBUG)&DEBUG_PRINT) && 1 #if STATS static clock_time_t fetch_started; static unsigned long fetch_counter; @@ -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) @@ -115,11 +115,11 @@ webclient_datahandler(char *data, uint16_t len) PRINTF("wget: recv %lu bytes during %lu sec (", fetch_counter, (elapsed / CLOCK_SECOND)); #if CLOCK_SECOND == 128 - PRINTF("%lu.%02lus, ", (unsigned long) elapsed >> 7, + PRINTF("%lu.%02lus, ", (unsigned long)elapsed >> 7, (unsigned long)((elapsed & 127) * 100) / 128); PRINTF("%lu byte/sec ", (fetch_counter * 128L) / elapsed); #endif - PRINTF("%lu tick): ", (unsigned long) elapsed); + PRINTF("%lu tick): ", (unsigned long)elapsed); if(elapsed > CLOCK_SECOND) { PRINTF("%lu", fetch_counter / (elapsed / CLOCK_SECOND)); } else { @@ -132,7 +132,7 @@ webclient_datahandler(char *data, uint16_t len) fetch_running = 0; call_done(WGET_OK); - LEDS_OFF(LEDS_RED|LEDS_YELLOW); + LEDS_OFF(LEDS_RED | LEDS_YELLOW); } else { #if STATS fetch_counter += len; @@ -156,7 +156,7 @@ void webclient_timedout(void) { PRINTF("wget: timedout\n"); - LEDS_OFF(LEDS_RED|LEDS_YELLOW); + LEDS_OFF(LEDS_RED | LEDS_YELLOW); fetch_running = 0; call_done(WGET_TIMEDOUT); } @@ -165,7 +165,7 @@ void webclient_aborted(void) { PRINTF("wget: aborted\n"); - LEDS_OFF(LEDS_RED|LEDS_YELLOW); + LEDS_OFF(LEDS_RED | LEDS_YELLOW); fetch_running = 0; call_done(WGET_ABORTED); } @@ -175,7 +175,7 @@ webclient_closed(void) { PRINTF("wget: closed\n"); fetch_running = 0; - LEDS_OFF(LEDS_RED|LEDS_YELLOW); + LEDS_OFF(LEDS_RED | LEDS_YELLOW); call_done(WGET_CLOSED); } /*---------------------------------------------------------------------------*/ diff --git a/examples/zolertia/z1/ipv6/z1-websense/wget.h b/examples/zolertia/z1/ipv6/z1-websense/wget.h index b87f69692..28ab27aed 100644 --- a/examples/zolertia/z1/ipv6/z1-websense/wget.h +++ b/examples/zolertia/z1/ipv6/z1-websense/wget.h @@ -42,8 +42,8 @@ #include "contiki.h" struct wget_callbacks { - void (* data)(const char *data, uint16_t len); - void (* done)(int status); + void (*data)(const char *data, uint16_t len); + void (*done)(int status); }; void wget_init(void); diff --git a/examples/zolertia/z1/ipv6/z1-websense/z1-websense.c b/examples/zolertia/z1/ipv6/z1-websense/z1-websense.c index 5e8bedb1e..9dca126e9 100644 --- a/examples/zolertia/z1/ipv6/z1-websense/z1-websense.c +++ b/examples/zolertia/z1/ipv6/z1-websense/z1-websense.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * */ - +/*---------------------------------------------------------------------------*/ /** * \file * Battery and Temperature IPv6 Demo for Zolertia Z1 @@ -37,7 +37,7 @@ * Joel Hoglund * Enric M. Calvo */ - +/*---------------------------------------------------------------------------*/ #include "contiki.h" #include "httpd-simple.h" #include "webserver-nogui.h" @@ -46,22 +46,23 @@ #include "cc2420.h" #include "dev/leds.h" #include - - -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 = "Contiki Web Sense\n"; static const char *BOTTOM = "\n"; @@ -85,11 +92,13 @@ static const char *BOTTOM = "\n"; /* Only one single request at time */ static char buf[256]; static int blen; -#define ADD(...) do { \ - blen += snprintf(&buf[blen], sizeof(buf) - blen, __VA_ARGS__); \ - } while(0) +#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)) { @@ -120,20 +130,17 @@ PT_THREAD(send_values(struct httpd_state *s)) ADD("

Current readings

\n" "Battery: %ld.%03d V
" "Temperature: %ld.%03d ° C", - (long) mybatt, (unsigned) ((mybatt-floor(mybatt))*1000), - (long) mytemp, (unsigned) ((mytemp-floor(mytemp))*1000)); + (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); @@ -173,7 +180,7 @@ PROCESS_THREAD(web_sense_process, ev, data) PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer)); etimer_reset(&timer); - battery1[sensors_pos] = get_mybatt()*1000; + battery1[sensors_pos] = get_mybatt() * 1000; temperature[sensors_pos] = get_mytemp(); sensors_pos = (sensors_pos + 1) % HISTORY; }