mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-08-14 09:28:59 +00:00
Fix code style: Z1 websense example
This commit is contained in:
parent
e1f6d39857
commit
be1bd9a619
@ -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);
|
||||
|
@ -27,7 +27,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \file
|
||||
* A simple wget implementation
|
||||
@ -35,28 +35,29 @@
|
||||
* 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
|
||||
#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);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -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);
|
||||
|
@ -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";
|
||||
@ -87,9 +94,11 @@ static char buf[256];
|
||||
static int blen;
|
||||
#define ADD(...) do { \
|
||||
blen += snprintf(&buf[blen], sizeof(buf) - blen, __VA_ARGS__); \
|
||||
} while(0)
|
||||
} 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("<h1>Current readings</h1>\n"
|
||||
"Battery: %ld.%03d V<br>"
|
||||
"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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user