Improve code style and remove obsolete lines

This commit is contained in:
George Oikonomou 2017-11-02 00:07:54 +00:00 committed by Simon Duquennoy
parent 71ed11cdea
commit 517031f673
12 changed files with 200 additions and 167 deletions

View File

@ -42,8 +42,6 @@
#include "contiki-net.h"
//#include "urlconv.h"
#if UIP_CONF_TCP == 0
#error HTTP server needs TCP enabled
#endif
@ -153,7 +151,7 @@ PT_THREAD(handle_output(struct httpd_state *s))
/*---------------------------------------------------------------------------*/
const char http_get[] = "GET ";
const char http_index_html[] = "/index.html";
//const char http_referer[] = "Referer:"
static
PT_THREAD(handle_input(struct httpd_state *s))
{
@ -207,7 +205,6 @@ handle_connection(struct httpd_state *s)
handle_output(s);
}
}
/*---------------------------------------------------------------------------*/
void
httpd_appcall(void *state)
@ -250,7 +247,6 @@ httpd_appcall(void *state)
uip_abort();
}
}
/*---------------------------------------------------------------------------*/
void
httpd_init(void)

View File

@ -55,7 +55,6 @@ static int blen;
} while(0)
#endif
/* Use simple webserver with only one page for minimum footprint.
* Multiple connections can result in interleaved tcp segments since
* a single static buffer is used for all segments.
@ -86,7 +85,9 @@ ipaddr_add(const uip_ipaddr_t *addr)
for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) {
a = (addr->u8[i] << 8) + addr->u8[i + 1];
if(a == 0 && f >= 0) {
if(f++ == 0) ADD("::");
if(f++ == 0) {
ADD("::");
}
} else {
if(f > 0) {
f = -1;
@ -118,7 +119,8 @@ PT_THREAD(generate_routes(struct httpd_state *s))
SEND_STRING(&s->sout, TOP);
#if BUF_USES_STACK
bufptr = buf;bufend=bufptr+sizeof(buf);
bufptr = buf;
bufend = bufptr + sizeof(buf);
#else
blen = 0;
#endif
@ -134,11 +136,16 @@ PT_THREAD(generate_routes(struct httpd_state *s))
ipaddr_add(&nbr->ipaddr);
while(bufptr < j) ADD(" ");
switch(nbr->state) {
case NBR_INCOMPLETE: ADD(" INCOMPLETE");break;
case NBR_REACHABLE: ADD(" REACHABLE");break;
case NBR_STALE: ADD(" STALE");break;
case NBR_DELAY: ADD(" DELAY");break;
case NBR_PROBE: ADD(" NBR_PROBE");break;
case NBR_INCOMPLETE: ADD(" INCOMPLETE");
break;
case NBR_REACHABLE: ADD(" REACHABLE");
break;
case NBR_STALE: ADD(" STALE");
break;
case NBR_DELAY: ADD(" DELAY");
break;
case NBR_PROBE: ADD(" NBR_PROBE");
break;
}
}
#else
@ -146,11 +153,16 @@ PT_THREAD(generate_routes(struct httpd_state *s))
ipaddr_add(&nbr->ipaddr);
while(blen < j) ADD(" ");
switch(nbr->state) {
case NBR_INCOMPLETE: ADD(" INCOMPLETE");break;
case NBR_REACHABLE: ADD(" REACHABLE");break;
case NBR_STALE: ADD(" STALE");break;
case NBR_DELAY: ADD(" DELAY");break;
case NBR_PROBE: ADD(" NBR_PROBE");break;
case NBR_INCOMPLETE: ADD(" INCOMPLETE");
break;
case NBR_REACHABLE: ADD(" REACHABLE");
break;
case NBR_STALE: ADD(" STALE");
break;
case NBR_DELAY: ADD(" DELAY");
break;
case NBR_PROBE: ADD(" NBR_PROBE");
break;
}
}
#endif
@ -162,7 +174,8 @@ PT_THREAD(generate_routes(struct httpd_state *s))
#if BUF_USES_STACK
if(bufptr > bufend - 45) {
SEND_STRING(&s->sout, buf);
bufptr = buf; bufend = bufptr + sizeof(buf);
bufptr = buf;
bufend = bufptr + sizeof(buf);
}
#else
if(blen > sizeof(buf) - 45) {
@ -174,7 +187,8 @@ PT_THREAD(generate_routes(struct httpd_state *s))
ADD("</pre>Routes<pre>\n");
SEND_STRING(&s->sout, buf);
#if BUF_USES_STACK
bufptr = buf; bufend = bufptr + sizeof(buf);
bufptr = buf;
bufend = bufptr + sizeof(buf);
#else
blen = 0;
#endif
@ -196,7 +210,7 @@ PT_THREAD(generate_routes(struct httpd_state *s))
ADD("<a href=http://[");
ipaddr_add(&r->ipaddr);
ADD("]/status.shtml>");
SEND_STRING(&s->sout, buf); //TODO: why tunslip6 needs an output here, wpcapslip does not
SEND_STRING(&s->sout, buf);
blen = 0;
ipaddr_add(&r->ipaddr);
ADD("</a>");
@ -213,7 +227,8 @@ PT_THREAD(generate_routes(struct httpd_state *s))
}
SEND_STRING(&s->sout, buf);
#if BUF_USES_STACK
bufptr = buf; bufend = bufptr + sizeof(buf);
bufptr = buf;
bufend = bufptr + sizeof(buf);
#else
blen = 0;
#endif
@ -224,7 +239,8 @@ PT_THREAD(generate_routes(struct httpd_state *s))
ADD("Links<pre>\n");
SEND_STRING(&s->sout, buf);
#if BUF_USES_STACK
bufptr = buf; bufend = bufptr + sizeof(buf);
bufptr = buf;
bufend = bufptr + sizeof(buf);
#else
blen = 0;
#endif
@ -251,7 +267,7 @@ PT_THREAD(generate_routes(struct httpd_state *s))
ADD("<a href=http://[");
ipaddr_add(&child_ipaddr);
ADD("]/status.shtml>");
SEND_STRING(&s->sout, buf); //TODO: why tunslip6 needs an output here, wpcapslip does not
SEND_STRING(&s->sout, buf);
blen = 0;
ipaddr_add(&child_ipaddr);
ADD("</a>");
@ -263,14 +279,14 @@ PT_THREAD(generate_routes(struct httpd_state *s))
ADD(" (parent: ");
ipaddr_add(&parent_ipaddr);
if(1 || (link->lifetime < 600)) {
ADD(") %us\n", (unsigned int)link->lifetime); // iotlab printf does not have %lu
//ADD(") %lus\n", (unsigned long)r->state.lifetime);
ADD(") %us\n", (unsigned int)link->lifetime);
} else {
ADD(")\n");
}
SEND_STRING(&s->sout, buf);
#if BUF_USES_STACK
bufptr = buf; bufend = bufptr + sizeof(buf);
bufptr = buf;
bufend = bufptr + sizeof(buf);
#else
blen = 0;
#endif

View File

@ -47,7 +47,6 @@
#define DEBUG DEBUG_NONE
#include "net/ipv6/uip-debug.h"
uint8_t command_context;
void packet_sent(uint8_t sessionid, uint8_t status, uint8_t tx);

View File

@ -66,7 +66,8 @@ struct tx_callback {
static struct tx_callback callbacks[MAX_CALLBACKS];
/*---------------------------------------------------------------------------*/
void packet_sent(uint8_t sessionid, uint8_t status, uint8_t tx)
void
packet_sent(uint8_t sessionid, uint8_t status, uint8_t tx)
{
if(sessionid < MAX_CALLBACKS) {
struct tx_callback *callback;
@ -114,7 +115,6 @@ send_packet(mac_callback_t sent, void *ptr)
/* Failed to allocate space for headers */
PRINTF("br-rdc: send failed, too large header\n");
mac_call_sent_callback(sent, ptr, MAC_TX_ERR_FATAL, 1);
} else {
/* here we send the data over SLIP to the radio-chip */
size = 0;

View File

@ -100,7 +100,6 @@ border_router_print_stat()
printf("bytes received over SLIP: %ld\n", slip_received);
printf("bytes sent over SLIP: %ld\n", slip_sent);
}
/*---------------------------------------------------------------------------*/
/* Format: <name=value>;<name=value>;...;<name=value>*/
/* this function just cut at ; and store in the sensor array */

View File

@ -40,7 +40,6 @@
/* use a non-default MAC driver */
#define NETSTACK_CONF_MAC border_router_mac_driver
#define SLIP_DEV_CONF_SEND_DELAY (CLOCK_SECOND / 32)
#define WEBSERVER_CONF_CFS_CONNS 2
@ -50,7 +49,6 @@
#define CMD_CONF_OUTPUT border_router_cmd_output
/* used by wpcap (see /cpu/native/net/wpcap-drv.c) */
#define SELECT_CALLBACK 1

View File

@ -113,12 +113,16 @@ slip_config_handle_arguments(int argc, char **argv)
case 'd':
slip_config_basedelay = 10;
if(optarg) slip_config_basedelay = atoi(optarg);
if(optarg) {
slip_config_basedelay = atoi(optarg);
}
break;
case 'v':
slip_config_verbose = 2;
if(optarg) slip_config_verbose = atoi(optarg);
if(optarg) {
slip_config_verbose = atoi(optarg);
}
break;
case '?':

View File

@ -80,7 +80,6 @@ long slip_received = 0;
int slipfd = 0;
//#define PROGRESS(s) fprintf(stderr, s)
#define PROGRESS(s) do { } while(0)
#define SLIP_END 0300
@ -183,7 +182,9 @@ serial_input(FILE *inslip)
#ifdef linux
ret = fread(&c, 1, 1, inslip);
if(ret == -1 || ret == 0) err(1, "serial_input: read");
if(ret == -1 || ret == 0) {
err(1, "serial_input: read");
}
goto after_fread;
#endif
@ -224,13 +225,19 @@ serial_input(FILE *inslip)
if(slip_config_verbose > 4) {
#if WIRESHARK_IMPORT_FORMAT
printf("0000");
for(i = 0; i < inbufptr; i++) printf(" %02x", inbuf[i]);
for(i = 0; i < inbufptr; i++) {
printf(" %02x", inbuf[i]);
}
#else
printf(" ");
for(i = 0; i < inbufptr; i++) {
printf("%02x", inbuf[i]);
if((i & 3) == 3) printf(" ");
if((i & 15) == 15) printf("\n ");
if((i & 3) == 3) {
printf(" ");
}
if((i & 15) == 15) {
printf("\n ");
}
}
#endif
printf("\n");
@ -279,7 +286,6 @@ serial_input(FILE *inslip)
goto read_more;
}
unsigned char slip_buf[2048];
int slip_end, slip_begin, slip_packet_end, slip_packet_count;
static struct timer send_delay_timer;
@ -367,13 +373,19 @@ write_to_serial(int outfd, const uint8_t *inbuf, int len)
if(slip_config_verbose > 4) {
#if WIRESHARK_IMPORT_FORMAT
printf("0000");
for(i = 0; i < len; i++) printf(" %02x", p[i]);
for(i = 0; i < len; i++) {
printf(" %02x", p[i]);
}
#else
printf(" ");
for(i = 0; i < len; i++) {
printf("%02x", p[i]);
if((i & 3) == 3) printf(" ");
if((i & 15) == 15) printf("\n ");
if((i & 3) == 3) {
printf(" ");
}
if((i & 15) == 15) {
printf("\n ");
}
}
#endif
printf("\n");
@ -420,9 +432,13 @@ stty_telos(int fd)
speed_t speed = slip_config_b_rate;
int i;
if(tcflush(fd, TCIOFLUSH) == -1) err(1, "tcflush");
if(tcflush(fd, TCIOFLUSH) == -1) {
err(1, "tcflush");
}
if(tcgetattr(fd, &tty) == -1) err(1, "tcgetattr");
if(tcgetattr(fd, &tty) == -1) {
err(1, "tcgetattr");
}
cfmakeraw(&tty);
@ -440,23 +456,31 @@ stty_telos(int fd)
cfsetispeed(&tty, speed);
cfsetospeed(&tty, speed);
if(tcsetattr(fd, TCSAFLUSH, &tty) == -1) err(1, "tcsetattr");
if(tcsetattr(fd, TCSAFLUSH, &tty) == -1) {
err(1, "tcsetattr");
}
#if 1
/* Nonblocking read and write. */
/* if(fcntl(fd, F_SETFL, O_NONBLOCK) == -1) err(1, "fcntl"); */
tty.c_cflag |= CLOCAL;
if(tcsetattr(fd, TCSAFLUSH, &tty) == -1) err(1, "tcsetattr");
if(tcsetattr(fd, TCSAFLUSH, &tty) == -1) {
err(1, "tcsetattr");
}
i = TIOCM_DTR;
if(ioctl(fd, TIOCMBIS, &i) == -1) err(1, "ioctl");
if(ioctl(fd, TIOCMBIS, &i) == -1) {
err(1, "ioctl");
}
#endif
usleep(10 * 1000); /* Wait for hardware 10ms. */
/* Flush input and output buffers. */
if(tcflush(fd, TCIOFLUSH) == -1) err(1, "tcflush");
if(tcflush(fd, TCIOFLUSH) == -1) {
err(1, "tcflush");
}
}
/*---------------------------------------------------------------------------*/
static int
@ -498,7 +522,6 @@ slip_init(void)
if(slipfd == -1) {
err(1, "can't connect to ``%s:%s''", slip_config_host, slip_config_port);
}
} else if(slip_config_siodev != NULL) {
if(strcmp(slip_config_siodev, "null") == 0) {
/* Disable slip */
@ -508,7 +531,6 @@ slip_init(void)
if(slipfd == -1) {
err(1, "can't open siodev ``/dev/%s''", slip_config_siodev);
}
} else {
static const char *siodevs[] = {
"ttyUSB0", "cuaU0", "ucom0" /* linux, fbsd6, fbsd5 */

View File

@ -96,7 +96,6 @@ ssystem(const char *fmt, ...)
fflush(stdout);
return system(cmd);
}
/*---------------------------------------------------------------------------*/
void
cleanup(void)
@ -110,7 +109,6 @@ cleanup(void)
" | sh",
slip_config_tundev);
}
/*---------------------------------------------------------------------------*/
void
sigcleanup(int signo)
@ -118,7 +116,6 @@ sigcleanup(int signo)
fprintf(stderr, "signal %d\n", signo);
exit(0); /* exit(0) will call cleanup() */
}
/*---------------------------------------------------------------------------*/
void
ifconf(const char *tundev, const char *ipaddr)
@ -164,8 +161,9 @@ tun_alloc(char *dev)
* IFF_NO_PI - Do not provide packet information
*/
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
if(*dev != 0)
if(*dev != 0) {
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
}
if((err = ioctl(fd, TUNSETIFF, (void *)&ifr)) < 0) {
close(fd);
@ -191,7 +189,6 @@ tun_init()
slip_init();
}
#else
static uint16_t delaymsec = 0;
@ -209,7 +206,9 @@ tun_init()
tunfd = tun_alloc(slip_config_tundev);
if(tunfd == -1) err(1, "main: open");
if(tunfd == -1) {
err(1, "main: open");
}
select_set_callback(tunfd, &tun_select_callback);
@ -222,7 +221,6 @@ tun_init()
signal(SIGINT, sigcleanup);
ifconf(slip_config_tundev, slip_config_ipaddr);
}
/*---------------------------------------------------------------------------*/
static int
tun_output(uint8_t *data, int len)
@ -239,11 +237,11 @@ int
tun_input(unsigned char *data, int maxlen)
{
int size;
if((size = read(tunfd, data, maxlen)) == -1)
if((size = read(tunfd, data, maxlen)) == -1) {
err(1, "tun_input: read");
}
return size;
}
/*---------------------------------------------------------------------------*/
static void
init(void)
@ -259,8 +257,6 @@ output(void)
}
return 0;
}
const struct uip_fallback_interface rpl_interface = {
init, output
};
@ -274,7 +270,6 @@ set_fd(fd_set *rset, fd_set *wset)
FD_SET(tunfd, rset);
return 1;
}
/*---------------------------------------------------------------------------*/
static void
@ -288,8 +283,12 @@ handle_fd(fd_set *rset, fd_set *wset)
int dmsec;
gettimeofday(&tv, NULL);
dmsec = (tv.tv_sec - delaystartsec) * 1000 + tv.tv_usec / 1000 - delaystartmsec;
if(dmsec<0) delaymsec=0;
if(dmsec>delaymsec) delaymsec=0;
if(dmsec < 0) {
delaymsec = 0;
}
if(dmsec > delaymsec) {
delaymsec = 0;
}
}
if(delaymsec == 0) {