1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 09:32:44 +01:00

examples: use astyle to adopt current code style guide

This commit is contained in:
Christian Mehlis 2014-01-25 11:22:09 +01:00
parent fbcbd7ff1f
commit f00693255b
7 changed files with 69 additions and 38 deletions

View File

@ -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);
}

View File

@ -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");
}
@ -71,7 +74,7 @@ void init_transceiver(void)
int radio_pid = thread_create(
radio_stack_buffer,
RADIO_STACK_SIZE,
PRIORITY_MAIN-2,
PRIORITY_MAIN - 2,
CREATE_STACKTEST,
radio,
"radio");
@ -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);

View File

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

View File

@ -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,11 +24,13 @@ 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) {
while (1) {
msg_send_receive(&m, &m, pid);
printf("Got msg with content %u\n", m.content.value);
}

View File

@ -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 {

View File

@ -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);
@ -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");
}

View File

@ -48,11 +48,11 @@ void init_udp_server(void)
destiny_socket_close(sock);
}
for(;;) {
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;
}
@ -95,7 +96,7 @@ void udp_send(char *str)
strlen(text) + 1, 0, &sa,
sizeof sa);
if(bytes_sent < 0) {
if (bytes_sent < 0) {
printf("Error sending packet!\n");
}
else {