Browse Source

examples: use astyle to adopt current code style guide

dev/timer
Christian Mehlis 9 years ago
parent
commit
f00693255b
  1. 12
      examples/ccn-lite-client/main.c
  2. 30
      examples/default/main.c
  3. 2
      examples/hello-world/main.c
  4. 17
      examples/ipc_pingpong/main.c
  5. 19
      examples/rpl_udp/helper.c
  6. 12
      examples/rpl_udp/rpl.c
  7. 15
      examples/rpl_udp/udp.c

12
examples/ccn-lite-client/main.c

@ -157,23 +157,29 @@ static void riot_ccn_relay_start(char *str)
char *toc_str = strtok(str, " ");
toc_str = strtok(NULL, " ");
if (!toc_str) {
shell_max_cache_entries = CCNL_DEFAULT_MAX_CACHE_ENTRIES;
} else {
}
else {
shell_max_cache_entries = atoi(toc_str);
}
toc_str = strtok(NULL, " ");
if (!toc_str) {
shell_threshold_prefix = CCNL_DEFAULT_THRESHOLD_PREFIX;
} else {
}
else {
shell_threshold_prefix = atoi(toc_str);
}
toc_str = strtok(NULL, " ");
if (!toc_str) {
shell_threshold_aggregate = CCNL_DEFAULT_THRESHOLD_AGGREGATE;
} else {
}
else {
shell_threshold_aggregate = atoi(toc_str);
}

30
examples/default/main.c

@ -33,7 +33,8 @@
char radio_stack_buffer[RADIO_STACK_SIZE];
msg_t msg_q[RCV_BUFFER_SIZE];
void radio(void) {
void radio(void)
{
msg_t m;
radio_packet_t *p;
radio_packet_length_t i;
@ -42,8 +43,9 @@ void radio(void) {
while (1) {
msg_receive(&m);
if (m.type == PKT_PENDING) {
p = (radio_packet_t*) m.content.ptr;
p = (radio_packet_t *) m.content.ptr;
printf("Got radio packet:\n");
printf("\tLength:\t%u\n", p->length);
printf("\tSrc:\t%u\n", p->src);
@ -54,6 +56,7 @@ void radio(void) {
for (i = 0; i < p->length; i++) {
printf("%02X ", p->data[i]);
}
p->processing--;
puts("\n");
}
@ -69,12 +72,12 @@ void radio(void) {
void init_transceiver(void)
{
int radio_pid = thread_create(
radio_stack_buffer,
RADIO_STACK_SIZE,
PRIORITY_MAIN-2,
CREATE_STACKTEST,
radio,
"radio");
radio_stack_buffer,
RADIO_STACK_SIZE,
PRIORITY_MAIN - 2,
CREATE_STACKTEST,
radio,
"radio");
uint16_t transceivers = 0;
#ifdef MODULE_CC110X
@ -102,17 +105,20 @@ void init_transceiver(void)
}
#endif /* MODULE_TRANSCEIVER */
static int shell_readc(void) {
static int shell_readc(void)
{
char c = 0;
(void) posix_read(uart0_handler_pid, &c, 1);
return c;
}
static void shell_putchar(int c) {
static void shell_putchar(int c)
{
(void) putchar(c);
}
int main(void) {
int main(void)
{
shell_t shell;
(void) posix_open(uart0_handler_pid, 0);
@ -123,7 +129,7 @@ int main(void) {
#ifdef MODULE_TRANSCEIVER
init_transceiver();
#endif
(void) puts("Welcome to RIOT!");
shell_init(&shell, NULL, UART0_BUFSIZE, shell_readc, shell_putchar);

2
examples/hello-world/main.c

@ -4,5 +4,5 @@ int main(void)
{
puts("Hello World!\n");
while(1);
while (1);
}

17
examples/ipc_pingpong/main.c

@ -3,11 +3,12 @@
#include <msg.h>
#include <kernel.h>
void second_thread(void) {
void second_thread(void)
{
printf("second_thread starting.\n");
msg_t m;
while(1) {
while (1) {
msg_receive(&m);
printf("2nd: got msg from %i\n", m.sender_pid);
m.content.value++;
@ -23,12 +24,14 @@ int main(void)
msg_t m;
int pid = thread_create(second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "pong");
int pid = thread_create(second_thread_stack, sizeof(second_thread_stack),
PRIORITY_MAIN - 1, CREATE_WOUT_YIELD | CREATE_STACKTEST,
second_thread, "pong");
m.content.value = 1;
while(1) {
msg_send_receive(&m, &m, pid);
printf("Got msg with content %u\n", m.content.value);
while (1) {
msg_send_receive(&m, &m, pid);
printf("Got msg with content %u\n", m.content.value);
}
}

19
examples/rpl_udp/helper.c

@ -52,8 +52,9 @@ void rpl_udp_monitor(void)
while (1) {
msg_receive(&m);
if (m.type == PKT_PENDING) {
p = (radio_packet_t*) m.content.ptr;
p = (radio_packet_t *) m.content.ptr;
DEBUG("Received packet from ID %u\n", p->src);
DEBUG("\tLength:\t%u\n", p->length);
@ -65,15 +66,17 @@ void rpl_udp_monitor(void)
for (uint8_t i = 0; i < p->length; i++) {
DEBUG("%02X ", p->data[i]);
}
p->processing--;
DEBUG("\n");
}
else if (m.type == IPV6_PACKET_RECEIVED) {
ipv6_buf = (ipv6_hdr_t*) m.content.ptr;
ipv6_buf = (ipv6_hdr_t *) m.content.ptr;
printf("IPv6 datagram received (next header: %02X)", ipv6_buf->nextheader);
printf(" from %s ", ipv6_addr_to_str(addr_str, &ipv6_buf->srcaddr));
if (ipv6_buf->nextheader == IPV6_PROTO_NUM_ICMPV6) {
icmpv6_buf = (icmpv6_hdr_t*) &ipv6_buf[(LL_HDR_LEN + IPV6_HDR_LEN) + ipv6_ext_hdr_len];
icmpv6_buf = (icmpv6_hdr_t *) &ipv6_buf[(LL_HDR_LEN + IPV6_HDR_LEN) + ipv6_ext_hdr_len];
icmp_type = icmpv6_buf->type;
icmp_code = icmpv6_buf->code;
}
@ -82,6 +85,7 @@ void rpl_udp_monitor(void)
DEBUG("\t ICMP type: %02X ", icmp_type);
DEBUG("\t ICMP code: %02X ", icmp_code);
}
printf("\n");
}
else if (m.type == ENOBUFFER) {
@ -95,8 +99,10 @@ void rpl_udp_monitor(void)
transceiver_command_t tcmd;
void rpl_udp_ignore(char *addr) {
void rpl_udp_ignore(char *addr)
{
uint16_t a;
if (transceiver_pid < 0) {
puts("Transceiver not runnning.");
return;
@ -104,13 +110,14 @@ void rpl_udp_ignore(char *addr) {
msg_t mesg;
mesg.type = DBG_IGN;
mesg.content.ptr = (char*) &tcmd;
mesg.content.ptr = (char *) &tcmd;
tcmd.transceivers = TRANSCEIVER_CC1100;
tcmd.data = &a;
a = atoi(addr + strlen("ign "));
if (strlen(addr) > strlen("ign ")) {
printf("sending to transceiver (%u): %u\n", transceiver_pid, (*(uint8_t*)tcmd.data));
printf("sending to transceiver (%u): %u\n", transceiver_pid, (*(uint8_t *)tcmd.data));
msg_send(&mesg, transceiver_pid, 1);
}
else {

12
examples/rpl_udp/rpl.c

@ -28,18 +28,21 @@ void rpl_udp_init(char *str)
char *toc_str = strtok(str, " ");
toc_str = strtok(NULL, " ");
if (!toc_str) {
printf("Usage: init (r|n)\n");
printf("\tr\tinitialize as root\n");
printf("\tn\tinitialize as node router\n");
return;
}
char command = *toc_str;
uint8_t state;
if ((command == 'n') || (command == 'r')) {
printf("INFO: Initialize as %s on address %d\n", ((command == 'n') ? "node" : "root"), id);
if (!id || (id > 255)) {
printf("ERROR: address not a valid 8 bit integer\n");
return;
@ -61,7 +64,8 @@ void rpl_udp_init(char *str)
else {
ipv6_iface_set_routing_provider(rpl_get_next_hop);
}
int monitor_pid = thread_create(monitor_stack_buffer, MONITOR_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, rpl_udp_monitor, "monitor");
int monitor_pid = thread_create(monitor_stack_buffer, MONITOR_STACK_SIZE, PRIORITY_MAIN - 2, CREATE_STACKTEST, rpl_udp_monitor, "monitor");
transceiver_register(TRANSCEIVER, monitor_pid);
ipv6_register_packet_handler(monitor_pid);
//sixlowpan_lowpan_register(monitor_pid);
@ -80,7 +84,7 @@ void rpl_udp_init(char *str)
/* add global address */
ipv6_addr_set_by_eui64(&tmp, &std_addr);
ipv6_iface_add_addr(&tmp, IPV6_ADDR_TYPE_GLOBAL, NDP_ADDR_STATE_PREFERRED, 0, 0);
/* set channel to 10 */
tcmd.transceivers = TRANSCEIVER;
tcmd.data = &chan;
@ -110,11 +114,13 @@ void rpl_udp_loop(char *unused)
printf("---------------------------\n");
printf("OUTPUT\n");
printf("my rank: %d\n", mydodag->my_rank);
if (!is_root) {
printf("my preferred parent:\n");
printf("%s\n", ipv6_addr_to_str(addr_str, (&mydodag->my_preferred_parent->addr)));
printf("parent lifetime: %d\n", mydodag->my_preferred_parent->lifetime);
}
printf("---------------------------$\n");
for (int i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) {
@ -177,9 +183,11 @@ void rpl_udp_dodag(char *unused)
printf("Part of Dodag:\n");
printf("%s\n", ipv6_addr_to_str(addr_str, (&mydodag->dodag_id)));
printf("my rank: %d\n", mydodag->my_rank);
if (!is_root) {
printf("my preferred parent:\n");
printf("%s\n", ipv6_addr_to_str(addr_str, (&mydodag->my_preferred_parent->addr)));
}
printf("---------------------------\n");
}

15
examples/rpl_udp/udp.c

@ -48,11 +48,11 @@ void init_udp_server(void)
destiny_socket_close(sock);
}
for(;;) {
recsize = destiny_socket_recvfrom(sock, (void *)buffer_main, UDP_BUFFER_SIZE, 0,
for (;;) {
recsize = destiny_socket_recvfrom(sock, (void *)buffer_main, UDP_BUFFER_SIZE, 0,
&sa, &fromlen);
if(recsize < 0) {
if (recsize < 0) {
printf("ERROR: recsize < 0!\n");
}
@ -71,6 +71,7 @@ void udp_send(char *str)
int bytes_sent;
int address;
char text[5];
if (sscanf(str, "send %i %s", &address, text) < 2) {
printf("usage: send <addr> <text>\n");
return;
@ -78,7 +79,7 @@ void udp_send(char *str)
sock = destiny_socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
if(-1 == sock) {
if (-1 == sock) {
printf("Error Creating Socket!");
return;
}
@ -92,10 +93,10 @@ void udp_send(char *str)
sa.sin6_port = HTONS(SERVER_PORT);
bytes_sent = destiny_socket_sendto(sock, (char *)text,
strlen(text) + 1, 0, &sa,
sizeof sa);
strlen(text) + 1, 0, &sa,
sizeof sa);
if(bytes_sent < 0) {
if (bytes_sent < 0) {
printf("Error sending packet!\n");
}
else {

Loading…
Cancel
Save