mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-27 07:21:18 +01:00
[projects/sixlowpan/main.c]
* Added features to sixlowpan shell like: choice of node type, choice of radio address, request of IP information, request of context information
This commit is contained in:
parent
aeae15be8a
commit
d207d5c72e
@ -18,6 +18,74 @@
|
||||
#include <time.h>
|
||||
#include <rtc.h>
|
||||
#include "sys/net/sixlowpan/sixlowmac.h"
|
||||
#include "sys/net/sixlowpan/sixlowip.h"
|
||||
#include "sys/net/sixlowpan/sixlowedge.h"
|
||||
#include "sys/net/sixlowpan/sixlowpan.h"
|
||||
#include "sys/net/sixlowpan/sixlowerror.h"
|
||||
|
||||
void init(char *str){
|
||||
char command;
|
||||
uint16_t r_addr;
|
||||
ipv6_addr_t std_addr;
|
||||
|
||||
int res = sscanf(str, "init %c %hu", &command, &r_addr);
|
||||
|
||||
if(res < 1){
|
||||
printf("Usage: init {h | r | a | e} radio_address\n");
|
||||
printf("\th\tinitialize as host\n");
|
||||
printf("\tr\tinitialize as router\n");
|
||||
printf("\ta\tinitialize as ad-hoc router\n");
|
||||
printf("\te\tinitialize as edge router\n\n");
|
||||
printf("\tradio_address must be an 8 bit integer\n");
|
||||
}
|
||||
|
||||
ipv6_init_address(&std_addr,0xABCD,0,0,0,0x1034,0x00FF,0xFE00,r_addr);
|
||||
|
||||
switch (command) {
|
||||
case 'h':
|
||||
printf("INFO: Initialize as host on radio address %hu\n", r_addr);
|
||||
if (r_addr > 255) {
|
||||
printf("ERROR: radio_address not an 8 bit integer\n");
|
||||
return;
|
||||
}
|
||||
sixlowpan_init(TRANSCEIVER_CC1100,r_addr);
|
||||
break;
|
||||
case 'r':
|
||||
printf("INFO: Initialize as router on radio address %hu\n", r_addr);
|
||||
if (r_addr > 255) {
|
||||
printf("ERROR: radio_address not an 8 bit integer\n");
|
||||
return;
|
||||
}
|
||||
sixlowpan_init(TRANSCEIVER_CC1100, r_addr);
|
||||
ipv6_init_iface_as_router();
|
||||
break;
|
||||
case 'a':
|
||||
printf("INFO: Initialize as adhoc router on radio address %hu\n", r_addr);
|
||||
if (r_addr > 255) {
|
||||
printf("ERROR: radio_address not an 8 bit integer\n");
|
||||
return;
|
||||
}
|
||||
sixlowpan_adhoc_init(TRANSCEIVER_CC1100, &std_addr, r_addr);
|
||||
break;
|
||||
case 'e':
|
||||
printf("INFO: Initialize as edge router on radio address %hu\n", r_addr);
|
||||
if (r_addr > 255) {
|
||||
printf("ERROR: radio_address not an 8 bit integer\n");
|
||||
return;
|
||||
}
|
||||
res = edge_initialize(TRANSCEIVER_CC1100, &std_addr);
|
||||
switch (res) {
|
||||
case (SUCCESS): printf("INFO: Edge router initialized.\n"); break;
|
||||
case (SIXLOWERROR_ADDRESS): printf("ERROR: Illegal IP address: ");
|
||||
ipv6_print_addr(&std_addr); break;
|
||||
default: printf("ERROR: Unknown error (%d).\n", res); break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("ERROR: Unknown command '%c'\n", command);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void bootstrapping(char *str){
|
||||
sixlowpan_bootstrapping();
|
||||
@ -35,7 +103,7 @@ void send_packet(char *str){
|
||||
for(int j=0;j<100;j++){
|
||||
test[0] = j;
|
||||
for(int i=0;i<1000;i++){
|
||||
sixlowpan_send(&ipaddr, &test, 2);
|
||||
sixlowpan_send(&ipaddr, test, 2);
|
||||
}
|
||||
//lib6lowpan_bootstrapping(&addr8);
|
||||
}
|
||||
@ -55,28 +123,45 @@ void get_r_address(char *str){
|
||||
printf("radio: %hu\n", cc110x_get_address());
|
||||
}
|
||||
|
||||
void ip(char *str){
|
||||
ipv6_iface_print_addrs();
|
||||
}
|
||||
|
||||
void context(char *str){
|
||||
uint8_t i;
|
||||
lowpan_context_t *context;
|
||||
|
||||
for(i = 0; i < LOWPAN_CONTEXT_MAX; i++){
|
||||
context = lowpan_context_num_lookup(i);
|
||||
if (context != NULL) {
|
||||
printf("%2d\tLength: %3d\t",context->num,context->length);
|
||||
ipv6_print_addr(&(context->prefix));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const shell_command_t shell_commands[] = {
|
||||
{"send", "", send_packet},
|
||||
{"init", "", init},
|
||||
{"addr", "", get_r_address},
|
||||
{"set_chann", "", set_radio_chann},
|
||||
{"boot", "", bootstrapping},
|
||||
{"ip", "", ip},
|
||||
{"context", "", context},
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
//printf("Moin. build on %s %s SVN-Revision: %s\n", kernel_builddate, kernel_buildtime, kernel_svnrevision);
|
||||
printf("6LoWPAN\n");
|
||||
vtimer_init();
|
||||
|
||||
posix_open(uart0_handler_pid, 0);
|
||||
struct tm now;
|
||||
//struct tm now;
|
||||
//rtc_get_localtime(&now);
|
||||
|
||||
//srand((unsigned int)now.tm_sec);
|
||||
//uint8_t random = rand() % 256;
|
||||
//printf("address: %d\n", random);
|
||||
sixlowpan_init(TRANSCEIVER_CC1100,5);
|
||||
|
||||
shell_t shell;
|
||||
shell_init(&shell, shell_commands, uart0_readc, uart0_putc);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user