Ejemplo n.º 1
0
Archivo: main.c Proyecto: AnonMall/RIOT
static void riot_ccn_transceiver_start(kernel_pid_t _relay_pid)
{
    transceiver_init(TRANSCEIVER);
    int transceiver_pid = transceiver_start();
    DEBUG("transceiver on thread_id %d...\n", transceiver_pid);

    /* register for transceiver events */
    uint8_t reg = transceiver_register(TRANSCEIVER, _relay_pid);
    if (reg != 1) {
        DEBUG("transceiver register failed\n");
    }

    /* set channel to CCNL_CHAN */
    msg_t mesg;
    transceiver_command_t tcmd;
    int32_t c = CCNL_DEFAULT_CHANNEL;
    tcmd.transceivers = TRANSCEIVER;
    tcmd.data = &c;
    mesg.content.ptr = (char *) &tcmd;
    mesg.type = SET_CHANNEL;
    msg_send_receive(&mesg, &mesg, transceiver_pid);
    if (c == -1) {
        puts("[transceiver] Error setting/getting channel");
    }
    else {
        printf("[transceiver] Got channel: %" PRIi32 "\n", c);
    }
}
Ejemplo n.º 2
0
int main(void) {
    int radio_pid;
    uint8_t i;
    for (i = 0; i < SND_BUFFER_SIZE; i++) { 
        memset(snd_buffer[i], i, CC1100_MAX_DATA_LENGTH);
    }
    thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, shell_runner, "shell");
    radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio");
    transceiver_init(TRANSCEIVER_CC1100);
    transceiver_start();
    transceiver_register(TRANSCEIVER_CC1100, radio_pid);
    sender(NULL);

    printf("Config:\n");
    printf("\tid: %u\n", sysconfig.id);
    printf("\taddr: %u\n", sysconfig.radio_address);
    printf("\tchannel: %u\n", sysconfig.radio_channel);
   
   while (1) {
       extern void thread_print_all(void);
       thread_print_all();
       print_buffer(NULL);
       hwtimer_wait(50000);
   }
}
Ejemplo n.º 3
0
int net_if_register(int if_id, kernel_pid_t pid)
{
    if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) {
        DEBUG("Register thread: No interface initialized with ID %d.\n", if_id);
        return 0;
    }

    return (int)transceiver_register(interfaces[if_id].transceivers, pid);
}
Ejemplo n.º 4
0
Archivo: mac.c Proyecto: fjrk/RIOT
void sixlowpan_mac_init(transceiver_type_t type)
{
    int recv_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE,
                                 PRIORITY_MAIN - 2, CREATE_STACKTEST, recv_ieee802154_frame , "radio");
    transceiver_type = type;
    transceiver_init(transceiver_type);
    transceiver_start();
    transceiver_register(type, recv_pid);

    macdsn = rand() % 256;
}
Ejemplo n.º 5
0
int main(void)
{
    int16_t a;
    msg_t mesg;
    transceiver_command_t tcmd;

    printf("\n\tmain(): initializing transceiver\n");
    transceiver_init(TRANSCEIVER_NATIVE);

    printf("\n\tmain(): starting transceiver\n");
    transceiver_start();

#ifndef SENDER
    printf("\n\tmain(): starting radio thread\n");
    kernel_pid_t radio_pid = thread_create(
            radio_stack_buffer, sizeof(radio_stack_buffer),
            PRIORITY_MAIN - 2, CREATE_STACKTEST,
            radio, NULL, "radio");
    transceiver_register(TRANSCEIVER_NATIVE, radio_pid);
#endif

#ifdef SENDER
    a = SENDER_ADDR;
#elif defined ADDR
    a = ADDR;
#else
    a = DEFAULT_RCV_ADDR;
#endif
    tcmd.transceivers = TRANSCEIVER_NATIVE;
    tcmd.data = &a;
    mesg.content.ptr = (char *) &tcmd;
    mesg.type = SET_ADDRESS;

    printf("[nativenet] trying to set address %" PRIi16 "\n", a);
    msg_send_receive(&mesg, &mesg, transceiver_pid);

#ifdef SENDER
    hwtimer_wait(HWTIMER_TICKS(SECOND));
    sender();
#else
    hwtimer_wait(HWTIMER_TICKS(WAIT_TIME * SECOND));
    receiving = 0;
    printf("Missed %u of %u packets after %u seconds\n", missed_cnt, (last_seq - first),  WAIT_TIME);
#endif

    return 0;
}
Ejemplo n.º 6
0
int main(void) {
    int radio_pid;
    uint8_t i;
    for (i = 0; i < SND_BUFFER_SIZE; i++) { 
        memset(snd_buffer[i], i, CC1100_MAX_DATA_LENGTH);
    }
    thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell");
    radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio");
    transceiver_init(TRANSCEIVER_CC1100);
    transceiver_start();
    transceiver_register(TRANSCEIVER_CC1100, radio_pid);
   
   while (1) {
//       LED_GREEN_TOGGLE;
       hwtimer_wait(1000 * 1000);
   }
}
Ejemplo n.º 7
0
Archivo: main.c Proyecto: ShaneLan/RIOT
void init_transceiver(void)
{
    kernel_pid_t radio_pid = thread_create(
                        radio_stack_buffer,
                        sizeof(radio_stack_buffer),
                        PRIORITY_MAIN - 2,
                        CREATE_STACKTEST,
                        radio,
                        NULL,
                        "radio");

    uint16_t transceivers = TRANSCEIVER_DEFAULT;

    transceiver_init(transceivers);
    (void) transceiver_start();
    transceiver_register(transceivers, radio_pid);
}
Ejemplo n.º 8
0
Archivo: ping.c Proyecto: AnonMall/RIOT
/* public interface functions */
void l2_ping_init(void)
{
    mutex_init(&ping_sender_mutex);
    kernel_pid_t l2_pkt_handler_pid = thread_create(l2_pkt_handler_stack_buffer,
                                                    RADIO_STACK_SIZE,
                                                    PRIORITY_MAIN - 2,
                                                    CREATE_STACKTEST,
                                                    l2_pkt_handler, NULL,
                                                    "l2_pkt_handler");
    uint16_t transceivers = TRANSCEIVER_DEFAULT;

#ifndef MODULE_NET_IF
    transceiver_init(transceivers);
    (void) transceiver_start();
#endif
    transceiver_register(transceivers, l2_pkt_handler_pid);
}
Ejemplo n.º 9
0
void etx_init_beaconing(ipv6_addr_t *address)
{
    own_address = address;
    //set code
    DEBUGF("ETX BEACON INIT");
    etx_send_buf[0] = ETX_PKT_OPTVAL;

    etx_beacon_pid = thread_create(etx_beacon_buf, ETX_BEACON_STACKSIZE,
                                   PRIORITY_MAIN - 1, CREATE_STACKTEST,
                                   etx_beacon, NULL, "etx_beacon");

    etx_radio_pid = thread_create(etx_radio_buf, ETX_RADIO_STACKSIZE,
                                  PRIORITY_MAIN - 1, CREATE_STACKTEST,
                                  etx_radio, NULL, "etx_radio");

    etx_clock_pid = thread_create(etx_clock_buf, ETX_CLOCK_STACKSIZE,
                                  PRIORITY_MAIN - 1, CREATE_STACKTEST,
                                  etx_clock, NULL, "etx_clock");
    //register at transceiver
    transceiver_register(TRANSCEIVER_CC1100, etx_radio_pid);
    DEBUG("...[DONE]\n");
}
Ejemplo n.º 10
0
void init_transceiver(void)
{
    kernel_pid_t radio_pid = thread_create(
                        radio_stack_buffer,
                        sizeof(radio_stack_buffer),
                        PRIORITY_MAIN - 2,
                        CREATE_STACKTEST,
                        radio,
                        NULL,
                        "radio");

    uint16_t transceivers = TRANSCEIVER_DEFAULT;

    transceiver_init(transceivers);
    transceiver_start();
    transceiver_register(transceivers, radio_pid);

    msg_t mesg;
    mesg.type = SET_CHANNEL;
    mesg.content.ptr = (char *) &tcmd;

    uint16_t c = 10;

    tcmd.transceivers = TRANSCEIVER_DEFAULT;
    tcmd.data = &c;
    printf("Set transceiver to channel %u\n", c);
    msg_send(&mesg, transceiver_pid);

    mesg.type = SET_MONITOR;
    mesg.content.ptr = (char *) &tcmd;

    uint16_t v = 1;

    tcmd.data = &v;
    printf("Set transceiver into monitor mode\n");
    msg_send(&mesg, transceiver_pid);
}
Ejemplo n.º 11
0
void init(char *str)
{
    transceiver_command_t tcmd;
    msg_t m;
    uint8_t chan = RADIO_CHANNEL;

    char command;

    int res = sscanf(str, "init %c", &command);

    if (res < 1) {
        printf("Usage: init (r|n)\n");
        printf("\tr\tinitialize as root\n");
        printf("\tn\tinitialize as node router\n");
    }

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

        state = rpl_init(TRANSCEIVER, id);

        if (state != SIXLOWERROR_SUCCESS) {
            printf("Error initializing RPL\n");
        }
        else {
            puts("6LoWPAN and RPL initialized.");
        }

        if (command == 'r') {
            rpl_init_root();
            is_root = 1;
        }
        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, monitor, "monitor");
        transceiver_register(TRANSCEIVER, monitor_pid);
        ipv6_register_packet_handler(monitor_pid);
        //sixlowpan_lowpan_register(monitor_pid);
    }
    else {
        printf("ERROR: Unknown command '%c'\n", command);
        return;
    }

    /* TODO: check if this works as intended */
    ipv6_addr_t prefix, tmp;
    ipv6_addr_init(&std_addr, 0xABCD, 0xEF12, 0, 0, 0x1034, 0x00FF, 0xFE00, id);
    ipv6_addr_init_prefix(&prefix, &std_addr, 64);
    plist_add(&prefix, 64, NDP_OPT_PI_VLIFETIME_INFINITE, 0, 1, ICMPV6_NDP_OPT_PI_FLAG_AUTONOM);
    ipv6_init_iface_as_router();
    /* 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;
    m.type = SET_CHANNEL;
    m.content.ptr = (void *) &tcmd;

    msg_send_receive(&m, &m, transceiver_pid);
    printf("Channel set to %u\n", RADIO_CHANNEL);

    destiny_init_transport_layer();
    puts("Destiny initialized");
    /* start transceiver watchdog */
}
Ejemplo n.º 12
0
void rpl_udp_init(int argc, char **argv)
{
    transceiver_command_t tcmd;
    msg_t m;
    uint8_t chan = RADIO_CHANNEL;

    if (argc != 2) {
        printf("Usage: %s (r|n)\n", argv[0]);
        printf("\tr\tinitialize as root\n");
        printf("\tn\tinitialize as node router\n");
        return;
    }

    uint8_t state;

    char command = argv[1][0];
    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;
        }

        DEBUGF("Setting HW address to %u\n", id);
        net_if_set_hardware_address(0, id);

        DEBUGF("Initializing RPL for interface 0\n");
        state = rpl_init(0);

        if (state != SIXLOWERROR_SUCCESS) {
            printf("Error initializing RPL\n");
        }
        else {
            puts("6LoWPAN and RPL initialized.");
        }

        if (command == 'r') {
            rpl_init_root();
            is_root = 1;
        }
        else {
            ipv6_iface_set_routing_provider(rpl_get_next_hop);
        }

        DEBUGF("Start monitor\n");
        int monitor_pid = thread_create(
                monitor_stack_buffer, sizeof(monitor_stack_buffer),
                PRIORITY_MAIN - 2, CREATE_STACKTEST,
                rpl_udp_monitor, NULL, "monitor");
        DEBUGF("Register at transceiver %02X\n", TRANSCEIVER);
        transceiver_register(TRANSCEIVER, monitor_pid);
        ipv6_register_packet_handler(monitor_pid);
        //sixlowpan_lowpan_register(monitor_pid);
    }
    else {
        printf("ERROR: Unknown command '%c'\n", command);
        return;
    }

    /* TODO: check if this works as intended */
    ipv6_addr_t prefix, tmp;
    ipv6_addr_init(&std_addr, 0xABCD, 0xEF12, 0, 0, 0x1034, 0x00FF, 0xFE00, id);
    ipv6_addr_init_prefix(&prefix, &std_addr, 64);
    ndp_add_prefix_info(0, &prefix, 64, NDP_OPT_PI_VLIFETIME_INFINITE,
                        NDP_OPT_PI_PLIFETIME_INFINITE, 1,
                        ICMPV6_NDP_OPT_PI_FLAG_AUTONOM);
    ipv6_init_as_router();
    /* add global address */
    ipv6_addr_set_by_eui64(&tmp, 0, &std_addr);
    ipv6_net_if_add_addr(0, &tmp, NDP_ADDR_STATE_PREFERRED, 0, 0, 0);

    /* set channel to 10 */
    tcmd.transceivers = TRANSCEIVER;
    tcmd.data = &chan;
    m.type = SET_CHANNEL;
    m.content.ptr = (void *) &tcmd;

    msg_send_receive(&m, &m, transceiver_pid);
    printf("Channel set to %u\n", RADIO_CHANNEL);

    puts("Destiny initialized");
    /* start transceiver watchdog */
}