mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 17:32:44 +01:00
examples: use astyle to adopt current code style guide
This commit is contained in:
parent
fbcbd7ff1f
commit
f00693255b
@ -157,23 +157,29 @@ static void riot_ccn_relay_start(char *str)
|
|||||||
char *toc_str = strtok(str, " ");
|
char *toc_str = strtok(str, " ");
|
||||||
|
|
||||||
toc_str = strtok(NULL, " ");
|
toc_str = strtok(NULL, " ");
|
||||||
|
|
||||||
if (!toc_str) {
|
if (!toc_str) {
|
||||||
shell_max_cache_entries = CCNL_DEFAULT_MAX_CACHE_ENTRIES;
|
shell_max_cache_entries = CCNL_DEFAULT_MAX_CACHE_ENTRIES;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
shell_max_cache_entries = atoi(toc_str);
|
shell_max_cache_entries = atoi(toc_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
toc_str = strtok(NULL, " ");
|
toc_str = strtok(NULL, " ");
|
||||||
|
|
||||||
if (!toc_str) {
|
if (!toc_str) {
|
||||||
shell_threshold_prefix = CCNL_DEFAULT_THRESHOLD_PREFIX;
|
shell_threshold_prefix = CCNL_DEFAULT_THRESHOLD_PREFIX;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
shell_threshold_prefix = atoi(toc_str);
|
shell_threshold_prefix = atoi(toc_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
toc_str = strtok(NULL, " ");
|
toc_str = strtok(NULL, " ");
|
||||||
|
|
||||||
if (!toc_str) {
|
if (!toc_str) {
|
||||||
shell_threshold_aggregate = CCNL_DEFAULT_THRESHOLD_AGGREGATE;
|
shell_threshold_aggregate = CCNL_DEFAULT_THRESHOLD_AGGREGATE;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
shell_threshold_aggregate = atoi(toc_str);
|
shell_threshold_aggregate = atoi(toc_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,8 @@
|
|||||||
char radio_stack_buffer[RADIO_STACK_SIZE];
|
char radio_stack_buffer[RADIO_STACK_SIZE];
|
||||||
msg_t msg_q[RCV_BUFFER_SIZE];
|
msg_t msg_q[RCV_BUFFER_SIZE];
|
||||||
|
|
||||||
void radio(void) {
|
void radio(void)
|
||||||
|
{
|
||||||
msg_t m;
|
msg_t m;
|
||||||
radio_packet_t *p;
|
radio_packet_t *p;
|
||||||
radio_packet_length_t i;
|
radio_packet_length_t i;
|
||||||
@ -42,8 +43,9 @@ void radio(void) {
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
msg_receive(&m);
|
msg_receive(&m);
|
||||||
|
|
||||||
if (m.type == PKT_PENDING) {
|
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("Got radio packet:\n");
|
||||||
printf("\tLength:\t%u\n", p->length);
|
printf("\tLength:\t%u\n", p->length);
|
||||||
printf("\tSrc:\t%u\n", p->src);
|
printf("\tSrc:\t%u\n", p->src);
|
||||||
@ -54,6 +56,7 @@ void radio(void) {
|
|||||||
for (i = 0; i < p->length; i++) {
|
for (i = 0; i < p->length; i++) {
|
||||||
printf("%02X ", p->data[i]);
|
printf("%02X ", p->data[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
p->processing--;
|
p->processing--;
|
||||||
puts("\n");
|
puts("\n");
|
||||||
}
|
}
|
||||||
@ -69,12 +72,12 @@ void radio(void) {
|
|||||||
void init_transceiver(void)
|
void init_transceiver(void)
|
||||||
{
|
{
|
||||||
int radio_pid = thread_create(
|
int radio_pid = thread_create(
|
||||||
radio_stack_buffer,
|
radio_stack_buffer,
|
||||||
RADIO_STACK_SIZE,
|
RADIO_STACK_SIZE,
|
||||||
PRIORITY_MAIN-2,
|
PRIORITY_MAIN - 2,
|
||||||
CREATE_STACKTEST,
|
CREATE_STACKTEST,
|
||||||
radio,
|
radio,
|
||||||
"radio");
|
"radio");
|
||||||
|
|
||||||
uint16_t transceivers = 0;
|
uint16_t transceivers = 0;
|
||||||
#ifdef MODULE_CC110X
|
#ifdef MODULE_CC110X
|
||||||
@ -102,17 +105,20 @@ void init_transceiver(void)
|
|||||||
}
|
}
|
||||||
#endif /* MODULE_TRANSCEIVER */
|
#endif /* MODULE_TRANSCEIVER */
|
||||||
|
|
||||||
static int shell_readc(void) {
|
static int shell_readc(void)
|
||||||
|
{
|
||||||
char c = 0;
|
char c = 0;
|
||||||
(void) posix_read(uart0_handler_pid, &c, 1);
|
(void) posix_read(uart0_handler_pid, &c, 1);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void shell_putchar(int c) {
|
static void shell_putchar(int c)
|
||||||
|
{
|
||||||
(void) putchar(c);
|
(void) putchar(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void)
|
||||||
|
{
|
||||||
shell_t shell;
|
shell_t shell;
|
||||||
(void) posix_open(uart0_handler_pid, 0);
|
(void) posix_open(uart0_handler_pid, 0);
|
||||||
|
|
||||||
|
@ -4,5 +4,5 @@ int main(void)
|
|||||||
{
|
{
|
||||||
puts("Hello World!\n");
|
puts("Hello World!\n");
|
||||||
|
|
||||||
while(1);
|
while (1);
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,12 @@
|
|||||||
#include <msg.h>
|
#include <msg.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
|
|
||||||
void second_thread(void) {
|
void second_thread(void)
|
||||||
|
{
|
||||||
printf("second_thread starting.\n");
|
printf("second_thread starting.\n");
|
||||||
msg_t m;
|
msg_t m;
|
||||||
|
|
||||||
while(1) {
|
while (1) {
|
||||||
msg_receive(&m);
|
msg_receive(&m);
|
||||||
printf("2nd: got msg from %i\n", m.sender_pid);
|
printf("2nd: got msg from %i\n", m.sender_pid);
|
||||||
m.content.value++;
|
m.content.value++;
|
||||||
@ -23,12 +24,14 @@ int main(void)
|
|||||||
|
|
||||||
msg_t m;
|
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;
|
m.content.value = 1;
|
||||||
|
|
||||||
while(1) {
|
while (1) {
|
||||||
msg_send_receive(&m, &m, pid);
|
msg_send_receive(&m, &m, pid);
|
||||||
printf("Got msg with content %u\n", m.content.value);
|
printf("Got msg with content %u\n", m.content.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,9 @@ void rpl_udp_monitor(void)
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
msg_receive(&m);
|
msg_receive(&m);
|
||||||
|
|
||||||
if (m.type == PKT_PENDING) {
|
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("Received packet from ID %u\n", p->src);
|
||||||
DEBUG("\tLength:\t%u\n", p->length);
|
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++) {
|
for (uint8_t i = 0; i < p->length; i++) {
|
||||||
DEBUG("%02X ", p->data[i]);
|
DEBUG("%02X ", p->data[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
p->processing--;
|
p->processing--;
|
||||||
DEBUG("\n");
|
DEBUG("\n");
|
||||||
}
|
}
|
||||||
else if (m.type == IPV6_PACKET_RECEIVED) {
|
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("IPv6 datagram received (next header: %02X)", ipv6_buf->nextheader);
|
||||||
printf(" from %s ", ipv6_addr_to_str(addr_str, &ipv6_buf->srcaddr));
|
printf(" from %s ", ipv6_addr_to_str(addr_str, &ipv6_buf->srcaddr));
|
||||||
|
|
||||||
if (ipv6_buf->nextheader == IPV6_PROTO_NUM_ICMPV6) {
|
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_type = icmpv6_buf->type;
|
||||||
icmp_code = icmpv6_buf->code;
|
icmp_code = icmpv6_buf->code;
|
||||||
}
|
}
|
||||||
@ -82,6 +85,7 @@ void rpl_udp_monitor(void)
|
|||||||
DEBUG("\t ICMP type: %02X ", icmp_type);
|
DEBUG("\t ICMP type: %02X ", icmp_type);
|
||||||
DEBUG("\t ICMP code: %02X ", icmp_code);
|
DEBUG("\t ICMP code: %02X ", icmp_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
else if (m.type == ENOBUFFER) {
|
else if (m.type == ENOBUFFER) {
|
||||||
@ -95,8 +99,10 @@ void rpl_udp_monitor(void)
|
|||||||
|
|
||||||
transceiver_command_t tcmd;
|
transceiver_command_t tcmd;
|
||||||
|
|
||||||
void rpl_udp_ignore(char *addr) {
|
void rpl_udp_ignore(char *addr)
|
||||||
|
{
|
||||||
uint16_t a;
|
uint16_t a;
|
||||||
|
|
||||||
if (transceiver_pid < 0) {
|
if (transceiver_pid < 0) {
|
||||||
puts("Transceiver not runnning.");
|
puts("Transceiver not runnning.");
|
||||||
return;
|
return;
|
||||||
@ -104,13 +110,14 @@ void rpl_udp_ignore(char *addr) {
|
|||||||
|
|
||||||
msg_t mesg;
|
msg_t mesg;
|
||||||
mesg.type = DBG_IGN;
|
mesg.type = DBG_IGN;
|
||||||
mesg.content.ptr = (char*) &tcmd;
|
mesg.content.ptr = (char *) &tcmd;
|
||||||
|
|
||||||
tcmd.transceivers = TRANSCEIVER_CC1100;
|
tcmd.transceivers = TRANSCEIVER_CC1100;
|
||||||
tcmd.data = &a;
|
tcmd.data = &a;
|
||||||
a = atoi(addr + strlen("ign "));
|
a = atoi(addr + strlen("ign "));
|
||||||
|
|
||||||
if (strlen(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);
|
msg_send(&mesg, transceiver_pid, 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -28,18 +28,21 @@ void rpl_udp_init(char *str)
|
|||||||
|
|
||||||
char *toc_str = strtok(str, " ");
|
char *toc_str = strtok(str, " ");
|
||||||
toc_str = strtok(NULL, " ");
|
toc_str = strtok(NULL, " ");
|
||||||
|
|
||||||
if (!toc_str) {
|
if (!toc_str) {
|
||||||
printf("Usage: init (r|n)\n");
|
printf("Usage: init (r|n)\n");
|
||||||
printf("\tr\tinitialize as root\n");
|
printf("\tr\tinitialize as root\n");
|
||||||
printf("\tn\tinitialize as node router\n");
|
printf("\tn\tinitialize as node router\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char command = *toc_str;
|
char command = *toc_str;
|
||||||
|
|
||||||
uint8_t state;
|
uint8_t state;
|
||||||
|
|
||||||
if ((command == 'n') || (command == 'r')) {
|
if ((command == 'n') || (command == 'r')) {
|
||||||
printf("INFO: Initialize as %s on address %d\n", ((command == 'n') ? "node" : "root"), id);
|
printf("INFO: Initialize as %s on address %d\n", ((command == 'n') ? "node" : "root"), id);
|
||||||
|
|
||||||
if (!id || (id > 255)) {
|
if (!id || (id > 255)) {
|
||||||
printf("ERROR: address not a valid 8 bit integer\n");
|
printf("ERROR: address not a valid 8 bit integer\n");
|
||||||
return;
|
return;
|
||||||
@ -61,7 +64,8 @@ void rpl_udp_init(char *str)
|
|||||||
else {
|
else {
|
||||||
ipv6_iface_set_routing_provider(rpl_get_next_hop);
|
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);
|
transceiver_register(TRANSCEIVER, monitor_pid);
|
||||||
ipv6_register_packet_handler(monitor_pid);
|
ipv6_register_packet_handler(monitor_pid);
|
||||||
//sixlowpan_lowpan_register(monitor_pid);
|
//sixlowpan_lowpan_register(monitor_pid);
|
||||||
@ -110,11 +114,13 @@ void rpl_udp_loop(char *unused)
|
|||||||
printf("---------------------------\n");
|
printf("---------------------------\n");
|
||||||
printf("OUTPUT\n");
|
printf("OUTPUT\n");
|
||||||
printf("my rank: %d\n", mydodag->my_rank);
|
printf("my rank: %d\n", mydodag->my_rank);
|
||||||
|
|
||||||
if (!is_root) {
|
if (!is_root) {
|
||||||
printf("my preferred parent:\n");
|
printf("my preferred parent:\n");
|
||||||
printf("%s\n", ipv6_addr_to_str(addr_str, (&mydodag->my_preferred_parent->addr)));
|
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("parent lifetime: %d\n", mydodag->my_preferred_parent->lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("---------------------------$\n");
|
printf("---------------------------$\n");
|
||||||
|
|
||||||
for (int i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) {
|
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("Part of Dodag:\n");
|
||||||
printf("%s\n", ipv6_addr_to_str(addr_str, (&mydodag->dodag_id)));
|
printf("%s\n", ipv6_addr_to_str(addr_str, (&mydodag->dodag_id)));
|
||||||
printf("my rank: %d\n", mydodag->my_rank);
|
printf("my rank: %d\n", mydodag->my_rank);
|
||||||
|
|
||||||
if (!is_root) {
|
if (!is_root) {
|
||||||
printf("my preferred parent:\n");
|
printf("my preferred parent:\n");
|
||||||
printf("%s\n", ipv6_addr_to_str(addr_str, (&mydodag->my_preferred_parent->addr)));
|
printf("%s\n", ipv6_addr_to_str(addr_str, (&mydodag->my_preferred_parent->addr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("---------------------------\n");
|
printf("---------------------------\n");
|
||||||
}
|
}
|
||||||
|
@ -48,11 +48,11 @@ void init_udp_server(void)
|
|||||||
destiny_socket_close(sock);
|
destiny_socket_close(sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(;;) {
|
for (;;) {
|
||||||
recsize = destiny_socket_recvfrom(sock, (void *)buffer_main, UDP_BUFFER_SIZE, 0,
|
recsize = destiny_socket_recvfrom(sock, (void *)buffer_main, UDP_BUFFER_SIZE, 0,
|
||||||
&sa, &fromlen);
|
&sa, &fromlen);
|
||||||
|
|
||||||
if(recsize < 0) {
|
if (recsize < 0) {
|
||||||
printf("ERROR: recsize < 0!\n");
|
printf("ERROR: recsize < 0!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +71,7 @@ void udp_send(char *str)
|
|||||||
int bytes_sent;
|
int bytes_sent;
|
||||||
int address;
|
int address;
|
||||||
char text[5];
|
char text[5];
|
||||||
|
|
||||||
if (sscanf(str, "send %i %s", &address, text) < 2) {
|
if (sscanf(str, "send %i %s", &address, text) < 2) {
|
||||||
printf("usage: send <addr> <text>\n");
|
printf("usage: send <addr> <text>\n");
|
||||||
return;
|
return;
|
||||||
@ -78,7 +79,7 @@ void udp_send(char *str)
|
|||||||
|
|
||||||
sock = destiny_socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
sock = destiny_socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
|
|
||||||
if(-1 == sock) {
|
if (-1 == sock) {
|
||||||
printf("Error Creating Socket!");
|
printf("Error Creating Socket!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -92,10 +93,10 @@ void udp_send(char *str)
|
|||||||
sa.sin6_port = HTONS(SERVER_PORT);
|
sa.sin6_port = HTONS(SERVER_PORT);
|
||||||
|
|
||||||
bytes_sent = destiny_socket_sendto(sock, (char *)text,
|
bytes_sent = destiny_socket_sendto(sock, (char *)text,
|
||||||
strlen(text) + 1, 0, &sa,
|
strlen(text) + 1, 0, &sa,
|
||||||
sizeof sa);
|
sizeof sa);
|
||||||
|
|
||||||
if(bytes_sent < 0) {
|
if (bytes_sent < 0) {
|
||||||
printf("Error sending packet!\n");
|
printf("Error sending packet!\n");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
Reference in New Issue
Block a user