예제 #1
0
파일: main.c 프로젝트: centurysys/RIOT
void* pir_handler(void *arg)
{
    msg_t msg_q[1];
    msg_init_queue(msg_q, 1);

    printf("Registering PIR handler thread...     %s\n",
           pir_register_thread(&dev) == 0 ? "[OK]" : "[Failed]");

    msg_t m;
    while (msg_receive(&m)) {
        printf("PIR handler got a message: ");
        switch (m.type) {
            case PIR_STATUS_HI:
                puts("something started moving.");
                break;
            case PIR_STATUS_LO:
                puts("the movement has ceased.");
                break;
            default:
                puts("stray message.");
                break;
        }
    }
    puts("PIR handler: this should not have happened!");

    return NULL;
}
예제 #2
0
void* pir_handler(void *arg)
{
    (void) arg; /* unused */

    msg_t msg_q[1];
    msg_init_queue(msg_q, 1);

#ifndef TEST_PIR_POLLING
    printf("Registering PIR handler thread...     %s\n",
           pir_register_thread(&pir) == 0 ? "[OK]" : "[Failed]");
#endif

    msg_t m;
    while (msg_receive(&m)) {
        printf("PIR handler got a message: ");
        switch (m.type) {
            case PIR_STATUS_HI:
                puts("something started moving.");
                gpio_set(led_red);
                gpio_clear(led_green);
                break;
            case PIR_STATUS_LO:
                puts("the movement has ceased.");
                gpio_set(led_green);
                gpio_clear(led_red);
                break;
            default:
                puts("stray message.");
                break;
        }
    }
    puts("PIR handler: this should not have happened!");

    return NULL;
}
예제 #3
0
파일: main.c 프로젝트: cgundogan/RIOT-APPS
int main(void)
{
    /* we need a message queue for the thread running the shell in order to
     * receive potentially fast incoming networking packets */
    struct timespec ts;
    clock_gettime(CLOCK_MONOTONIC, &ts);
    random_init((uint32_t)ts.tv_nsec);
    msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);
    puts("RIOT network stack example application");

    gnrc_rpl_init(6);

    /* start shell */
    puts("All up, running the shell now");
    char line_buf[SHELL_DEFAULT_BUFSIZE];
    char *arg[2];
    char *cmd = "stats";
    char *status = "start";
    arg[0] = cmd;
    arg[1] = status;
    _stats_cmd(2, arg);

    shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);

    /* should be never reached */
    return 0;
}
예제 #4
0
파일: udp.c 프로젝트: aabadie/Tutorials
void *_udp_server(void *args)
{
    uint16_t port = (uint16_t) atoi(args);
    ipv6_addr_t server_addr = IPV6_ADDR_UNSPECIFIED;
    msg_init_queue(server_msg_queue, SERVER_MSG_QUEUE_SIZE);

    if(conn_udp_create(&conn, &server_addr, sizeof(server_addr), AF_INET6, port) < 0) {
        return NULL;
    }

    server_running = true;
    printf("Success: started UDP server on port %" PRIu8 "\n", port);

    while (1) {
        int res;
        ipv6_addr_t src;
        size_t src_len = sizeof(ipv6_addr_t);
        if ((res = conn_udp_recvfrom(&conn, server_buffer, sizeof(server_buffer),
                                     &src, &src_len, &port)) < 0) {
            puts("Error while receiving");
        }
        else if (res == 0) {
            puts("No data received");
        }
        else {
            server_buffer[res] = '\0';
            printf("Recvd: %s\n", server_buffer);
        }
    }

    return NULL;
}
예제 #5
0
static void riot_ccnl_appserver_ioloop(void)
{
    DEBUGMSG(1, "starting appserver main event and IO loop\n");

    if (msg_init_queue(msg_buffer_appserver, APPSERVER_MSG_BUFFER_SIZE) != 0) {
        DEBUGMSG(1, "msg init queue failed...abording\n");
    }

    msg_t in;
    riot_ccnl_msg_t *m;

    while (1) {
        DEBUGMSG(1, "appserver: waiting for incomming msg\n");
        msg_receive(&in);

        switch (in.type) {
            case (CCNL_RIOT_MSG):
                m = (riot_ccnl_msg_t *) in.content.ptr;
                DEBUGMSG(1, "new msg: size=%" PRIu16 " sender_pid=%" PRIu16 "\n",
                         m->size, in.sender_pid);
                appserver_handle_interest(m->payload, m->size, in.sender_pid);

                ccnl_free(m);
                break;

            default:
                DEBUGMSG(1,
                         "received unknown msg type: '%" PRIu16 "' dropping it\n",
                         in.type);
                break;
        }
    }
}
예제 #6
0
파일: udp.c 프로젝트: 4dahalibut/RIOT
void *udp_packet_handler(void *arg)
{
    (void) arg;

    msg_t m_recv_ip, m_send_ip, m_recv_udp, m_send_udp;
    socket_internal_t *udp_socket = NULL;

    msg_init_queue(udp_msg_queue, UDP_PKT_RECV_BUF_SIZE);

    while (1) {
        msg_receive(&m_recv_ip);
        ipv6_hdr_t *ipv6_header = ((ipv6_hdr_t *)m_recv_ip.content.ptr);
        udp_hdr_t *udp_header = ((udp_hdr_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN));

        uint16_t chksum = ipv6_csum(ipv6_header, (uint8_t*) udp_header, NTOHS(udp_header->length), IPPROTO_UDP);

        if (chksum == 0xffff) {
            udp_socket = get_udp_socket(udp_header);

            if (udp_socket != NULL) {
                m_send_udp.content.ptr = (char *)ipv6_header;

                msg_send_receive(&m_send_udp, &m_recv_udp, udp_socket->recv_pid);
            }
            else {
                printf("Dropped UDP Message because no thread ID was found for delivery!\n");
            }
        }
        else {
            printf("Wrong checksum (%x)!\n", chksum);
        }

        msg_reply(&m_recv_ip, &m_send_ip);
    }
}
예제 #7
0
파일: main.c 프로젝트: Nordzisko/RIOT
int main(void)
{
    puts("RIOT microcoap example application");

    /* microcoap_server uses conn which uses gnrc which needs a msg queue */
    msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);

    puts("Waiting for address autoconfiguration...");
    xtimer_sleep(3);

    /* print network addresses */
    puts("Configured network interfaces:");
    _netif_config(0, NULL);


	/*
	* Author: Norbert Danisik
	*
	* Following block of code was added as an part of bachelor thesis.
	*/
    thread_create(btn_handler_stack, sizeof(btn_handler_stack),
    THREAD_PRIORITY_MAIN,
    THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,
    btn_handler_function, NULL, btn_handler);




    /* start coap server loop */
    microcoap_server_loop();

    /* should be never reached */
    return 0;
}
예제 #8
0
파일: nhdp.c 프로젝트: cococolo/RIOT
/**
 * Function executed by NHDP thread receiving messages in an endless loop
 */
static void *_nhdp_runner(void *arg)
{
    nhdp_if_entry_t *if_entry;
    msg_t msg_rcvd, msg_queue[NHDP_MSG_QUEUE_SIZE];

    (void)arg;
    msg_init_queue(msg_queue, NHDP_MSG_QUEUE_SIZE);

    while (1) {
        msg_receive(&msg_rcvd);

        switch (msg_rcvd.type) {
            case MSG_TIMER:
                mutex_lock(&send_rcv_mutex);
                if_entry = (nhdp_if_entry_t *) msg_rcvd.content.ptr;

                nhdp_writer_send_hello(if_entry);

                /* TODO: Add jitter */

                /* Schedule next sending */
                vtimer_set_msg(&if_entry->if_timer, if_entry->hello_interval,
                               thread_getpid(), MSG_TIMER, (void *) if_entry);
                mutex_unlock(&send_rcv_mutex);
                break;

            default:
                break;
        }
    }

    return 0;
}
예제 #9
0
파일: mac.c 프로젝트: fjrk/RIOT
void recv_ieee802154_frame(void)
{
    msg_t m;
    radio_packet_t *p;
    uint8_t hdrlen, length;
    ieee802154_frame_t frame;

    msg_init_queue(msg_q, RADIO_RCV_BUF_SIZE);

    while (1) {
        msg_receive(&m);

        if (m.type == PKT_PENDING) {

            p = (radio_packet_t *) m.content.ptr;
            hdrlen = read_802154_frame(p->data, &frame, p->length);
            length = p->length - hdrlen;

            /* deliver packet to network(6lowpan)-layer */
            lowpan_read(frame.payload, length, (ieee_802154_long_t *)&frame.src_addr,
                        (ieee_802154_long_t *)&frame.dest_addr);

            p->processing--;
        }
        else if (m.type == ENOBUFFER) {
            puts("Transceiver buffer full");
        }
        else {
            puts("Unknown packet received");
        }
    }
}
예제 #10
0
파일: main.c 프로젝트: AdamRLukaitis/RIOT
int main(void)
{
    /* initialization */
    gnrc_pktbuf_init();
    msg_init_queue(_main_msg_queue, _MAIN_MSG_QUEUE_SIZE);
    netdev2_test_setup(&_dev, NULL);
    netdev2_test_set_isr_cb(&_dev, _dev_isr);
    netdev2_test_set_recv_cb(&_dev, _dev_recv);
    netdev2_test_set_send_cb(&_dev, _dev_send);
    netdev2_test_set_get_cb(&_dev, NETOPT_ADDRESS, _dev_get_addr);
    netdev2_test_set_set_cb(&_dev, NETOPT_ADDRESS, _dev_set_addr);
    gnrc_netdev2_eth_init(&_gnrc_dev, (netdev2_t *)(&_dev));
    _mac_pid = gnrc_netdev2_init(_mac_stack, _MAC_STACKSIZE, _MAC_PRIO,
                                 "gnrc_netdev_eth_test", &_gnrc_dev);
    if (_mac_pid <= KERNEL_PID_UNDEF) {
        puts("Could not start MAC thread\n");
        return 1;
    }

    /* test execution */
    EXECUTE(test_get_addr);
    EXECUTE(test_send);
    EXECUTE(test_receive);
    EXECUTE(test_set_addr);
    puts("ALL TESTS SUCCESSFUL");

    return 0;
}
예제 #11
0
파일: main.c 프로젝트: Teresa-P/RIOT
static void *printer(void *arg)
{
    (void)arg;
    msg_t msg;
    msg_t msg_queue[8];
    msg_init_queue(msg_queue, 8);

    while (1) {
        msg_receive(&msg);
        int dev = (int)msg.content.value;
        char c;

        printf("UART_DEV(%i) RX: ", dev);
        do {
            c = (int)ringbuffer_get_one(&(ctx[dev].rx_buf));
            if (c == 0) {
                puts("");
            }
            else if (c >= ' ' && c <= '~') {
                printf("%c", c);
            }
            else {
                printf("0x%02x", (unsigned char)c);
            }
        } while (c != 0);
    }

    /* this should never be reached */
    return NULL;
}
예제 #12
0
파일: main.c 프로젝트: SilkeRieger/projects
void radio(void) {
    msg_t m;
    radio_packet_t *p;
    uint8_t i;

    msg_init_queue(msg_q, RCV_BUFFER_SIZE);

    while (1) {
        msg_receive(&m);
        if (m.type == PKT_PENDING) {
            p = (radio_packet_t*) m.content.ptr;
            printf("Packet waiting, process %p...\n", p);
            printf("\tLength:\t%u\n", p->length);
            printf("\tSrc:\t%u\n", p->src);
            printf("\tDst:\t%u\n", p->dst);
            printf("\tLQI:\t%u\n", p->lqi);
            printf("\tRSSI:\t%u\n", p->rssi);

            for (i = 0; i < p->length; i++) {
                printf("%02X ", p->data[i]);
            }
            p->processing--;
            printf("\n");
        }
        else if (m.type == ENOBUFFER) {
            puts("Transceiver buffer full");
        }
        else {
            puts("Unknown packet received");
        }
    }
}
예제 #13
0
파일: main.c 프로젝트: RIOT-OS/Tutorials
int main(void)
{
    tlsf_create_with_pool(_tlsf_heap, sizeof(_tlsf_heap));
    msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);

    puts("Basic CCN-Lite example");

    ccnl_core_init();

    ccnl_start();

    /* get the default interface */
    gnrc_netif_t *netif = gnrc_netif_iter(NULL);

    /* set the relay's PID, configure the interface to interface to use CCN
     * nettype */
    if ((netif == NULL) || (ccnl_open_netif(netif->pid, GNRC_NETTYPE_CCN) < 0)) {
        puts("Error registering at network interface!");
        return -1;
    }

    char line_buf[SHELL_DEFAULT_BUFSIZE];
    shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
    return 0;
}
예제 #14
0
static void *_event_loop(void *arg)
{
    msg_t reply, msg_queue[GNRC_NETTEST_MSG_QUEUE_SIZE];

    (void)arg;
    msg_init_queue(msg_queue, GNRC_NETTEST_MSG_QUEUE_SIZE);
    reply.type = GNRC_NETAPI_MSG_TYPE_ACK;

    while (1) {
        msg_t msg;
        gnrc_netapi_opt_t *opt;

        msg_receive(&msg);

        switch (msg.type) {
        case GNRC_NETAPI_MSG_TYPE_GET:
            opt = (gnrc_netapi_opt_t *)msg.content.ptr;
            reply.content.value = _get_set_opt(_opt_cbs[opt->opt].get,
                                               opt->context, opt->data,
                                               opt->data_len);
            break;

        case GNRC_NETAPI_MSG_TYPE_SET:
            opt = (gnrc_netapi_opt_t *)msg.content.ptr;
            reply.content.value = _get_set_opt(_opt_cbs[opt->opt].set,
                                               opt->context, opt->data,
                                               opt->data_len);
            break;
        }

        msg_reply(&msg, &reply);
    }

    return NULL;
}
예제 #15
0
파일: main.c 프로젝트: cgundogan/RIOT-APPS
void *_send(void *args)
{
    (void) args;
    msg_init_queue(_send_msg_queue, MAIN_QUEUE_SIZE);

    char *arg[4];
    char *cmd = "udp_send";
    char *dst = "abcd::1";
    char *port = "8888";
    char rank[12];

    arg[0] = cmd;
    arg[1] = dst;
    arg[2] = port;

    while(1) {
        xtimer_sleep(2);
        if (gnrc_rpl_instances[0].state && gnrc_rpl_instances[0].dodag.my_rank == GNRC_RPL_ROOT_RANK) {
            return NULL;
        }

        if (gnrc_rpl_instances[0].state) {
            memset(rank, 0, sizeof(rank));
            sprintf(rank, "%u", gnrc_rpl_instances[0].dodag.my_rank);
            arg[3] = rank;
            udp_send(4, arg);
        }
    }
    return NULL;
}
예제 #16
0
파일: main.c 프로젝트: PeterKietzmann/Demos
void *beaconing(void *arg)
{
    (void) arg;
    xtimer_t status_timer;
    msg_t msg;
    msg_t update_msg;
    kernel_pid_t mypid = thread_getpid();

    /* initialize message queue */
    msg_init_queue(_beac_msg_q, Q_SZ);

    /* start periodic timer */
    update_msg.type = MSG_UPDATE_EVENT;
    xtimer_set_msg(&status_timer, UPDATE_INTERVAL, &update_msg, mypid);

    while(1) {
        msg_receive(&msg);

        switch (msg.type) {
            case MSG_UPDATE_EVENT:
                xtimer_set_msg(&status_timer, UPDATE_INTERVAL, &update_msg, mypid);
                send_update(initial_pos, p_buf);
                break;
            default:
                break;
        }
    }

    /* never reached */
    return NULL;
}
예제 #17
0
파일: main.c 프로젝트: ShaneLan/RIOT
void *radio(void *arg)
{
    (void) arg;

    msg_t m;

#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X
    ieee802154_packet_t *p;
#else
    radio_packet_t *p;
    radio_packet_length_t i;
#endif

    msg_init_queue(msg_q, RCV_BUFFER_SIZE);

    while (1) {
        msg_receive(&m);

        if (m.type == PKT_PENDING) {
#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X
            p = (ieee802154_packet_t*) m.content.ptr;
            printf("Got radio packet:\n");
            printf("\tLength:\t%u\n", p->length);
            printf("\tSrc:\t%u\n", p->frame.src_addr[0]);
            printf("\tDst:\t%u\n", p->frame.dest_addr[0]);
            printf("\tLQI:\t%u\n", p->lqi);
            printf("\tRSSI:\t%u\n", p->rssi);

            printf("Payload Length:%u\n", p->frame.payload_len);
            printf("Payload:%s\n", p->frame.payload);

            p->processing--;
#else
            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);
            printf("\tDst:\t%u\n", p->dst);
            printf("\tLQI:\t%u\n", p->lqi);
            printf("\tRSSI:\t%u\n", p->rssi);

            for (i = 0; i < p->length; i++) {
                printf("%02X ", p->data[i]);
            }

            p->processing--;
            puts("\n");
#endif

        }
        else if (m.type == ENOBUFFER) {
            puts("Transceiver buffer full");
        }
        else {
            puts("Unknown packet received");
        }
    }
}
예제 #18
0
static void* uhcp_client_thread(void *arg)
{
    (void)arg;

    msg_init_queue(_uhcp_msg_queue, sizeof(_uhcp_msg_queue)/sizeof(msg_t));
    uhcp_client(gnrc_border_interface);
    return NULL;
}
예제 #19
0
static void* _coap_server_thread(void* arg)
{
    (void)arg;
    msg_init_queue(_server_msg_queue, SERVER_QUEUE_SIZE);
    puts("Launching server loop");

    coap_server_loop(handleData, handleConfig);

    return NULL;
}
예제 #20
0
파일: udp.c 프로젝트: jonkster/biot
/*
 * trampoline for udp_server_loop()
 */
void *udp_server(void *arg)
{
    (void) arg;
    msg_init_queue(msg_q, MUDP_Q_SZ);

    udp_server_loop();

    /* never reached */
    return NULL;
}
예제 #21
0
파일: udp.c 프로젝트: cgundogan/RIOT-APPS
void *_udp_server(void *args)
{
    uint16_t port = (uint16_t) atoi(args);
    ipv6_addr_t server_addr = IPV6_ADDR_UNSPECIFIED;
    msg_init_queue(server_msg_queue, SERVER_MSG_QUEUE_SIZE);

    if(conn_udp_create(&conn, &server_addr, sizeof(server_addr), AF_INET6, port) < 0) {
        return NULL;
    }

    server_running = true;
    printf("Success: started UDP server on port %" PRIu16 "\n", port);

    char *arg[4];
    char *cmd = "udp_send";
    char *port_str = "8888";

    arg[0] = cmd;
    arg[2] = port_str;
    char src_str[IPV6_ADDR_MAX_STR_LEN];

    while (1) {
        int res;
        ipv6_addr_t src;
        size_t src_len = sizeof(ipv6_addr_t);
        if ((res = conn_udp_recvfrom(&conn, server_buffer, sizeof(server_buffer),
                                     &src, &src_len, &port)) < 0) {
            puts("Error while receiving");
        }
        else if (res == 0) {
            puts("No data received");
        }
        else {
            server_buffer[res] = '\0';
            if (gnrc_rpl_instances[0].state && gnrc_rpl_instances[0].dodag.node_status == GNRC_RPL_ROOT_NODE) {
                printf("%s;%s\n", ipv6_addr_to_str(src_str, &src, sizeof(src_str)),
                                                   server_buffer);
                ipv6_addr_to_str(addr_str, &ipv6_addr_all_nodes_link_local, sizeof(addr_str));
                arg[1] = addr_str;
                arg[3] = src_str;
                udp_send(4, arg);
            }
            else {
                ipv6_addr_t payload;
                ipv6_addr_from_str(&payload, server_buffer);
                if ((gnrc_ipv6_netif_find_by_addr(NULL, &payload) != KERNEL_PID_UNDEF) && (!acked)) {
                    acked = true;
                    printf("diff: %llu\n", xtimer_now64() - time);
                }
            }
        }
    }

    return NULL;
}
예제 #22
0
int
sol_mainloop_impl_platform_init(void)
{
#ifdef THREADS
    mutex_init(&_lock);
    _main_pid = thread_getpid();
#endif
    sol_interrupt_scheduler_set_pid(sched_active_pid);
    msg_init_queue(msg_buffer, MSG_BUFFER_SIZE);
    return 0;
}
예제 #23
0
int main(void)
{
    msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);

    puts("This is Task-02");

    char line_buf[SHELL_DEFAULT_BUFSIZE];
    shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);

    return 0;
}
예제 #24
0
파일: gnrc_rpl.c 프로젝트: aabadie/RIOT
static void *_event_loop(void *args)
{
    msg_t msg, reply;

    (void)args;
    msg_init_queue(_msg_q, GNRC_RPL_MSG_QUEUE_SIZE);

    /* preinitialize ACK */
    reply.type = GNRC_NETAPI_MSG_TYPE_ACK;

    trickle_t *trickle;
    /* start event loop */
    while (1) {
        DEBUG("RPL: waiting for incoming message.\n");
        msg_receive(&msg);

        switch (msg.type) {
            case GNRC_RPL_MSG_TYPE_LIFETIME_UPDATE:
                DEBUG("RPL: GNRC_RPL_MSG_TYPE_LIFETIME_UPDATE received\n");
                _update_lifetime();
                break;
            case GNRC_RPL_MSG_TYPE_TRICKLE_INTERVAL:
                DEBUG("RPL: GNRC_RPL_MSG_TYPE_TRICKLE_INTERVAL received\n");
                trickle = msg.content.ptr;
                if (trickle && (trickle->callback.func != NULL)) {
                    trickle_interval(trickle);
                }
                break;
            case GNRC_RPL_MSG_TYPE_TRICKLE_CALLBACK:
                DEBUG("RPL: GNRC_RPL_MSG_TYPE_TRICKLE_CALLBACK received\n");
                trickle = msg.content.ptr;
                if (trickle && (trickle->callback.func != NULL)) {
                    trickle_callback(trickle);
                }
                break;
            case GNRC_NETAPI_MSG_TYPE_RCV:
                DEBUG("RPL: GNRC_NETAPI_MSG_TYPE_RCV received\n");
                _receive(msg.content.ptr);
                break;
            case GNRC_NETAPI_MSG_TYPE_SND:
                break;
            case GNRC_NETAPI_MSG_TYPE_GET:
            case GNRC_NETAPI_MSG_TYPE_SET:
                DEBUG("RPL: reply to unsupported get/set\n");
                reply.content.value = -ENOTSUP;
                msg_reply(&msg, &reply);
                break;
            default:
                break;
        }
    }

    return NULL;
}
예제 #25
0
int main(void) {
    tlsf_create_with_pool(_tlsf_heap, sizeof(_tlsf_heap));

    printf("%s started\n", APPLICATION_NAME);
    xtimer_init();
    msg_init_queue(main_msg_queue, MAIN_MSG_QUEUE_SIZE);
    netdev_init();
    stack_init();
    exp_run();
    printf("%s stopped\n", APPLICATION_NAME);
    return 0;
}
예제 #26
0
static void *_event_loop(void *args)
{
    msg_t msg, reply, msg_q[GNRC_SIXLOWPAN_MSG_QUEUE_SIZE];
    gnrc_netreg_entry_t me_reg = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL,
                                                            sched_active_pid);

    (void)args;
    msg_init_queue(msg_q, GNRC_SIXLOWPAN_MSG_QUEUE_SIZE);

    /* register interest in all 6LoWPAN packets */
    gnrc_netreg_register(GNRC_NETTYPE_SIXLOWPAN, &me_reg);

    /* preinitialize ACK */
    reply.type = GNRC_NETAPI_MSG_TYPE_ACK;

    /* start event loop */
    while (1) {
        DEBUG("6lo: waiting for incoming message.\n");
        msg_receive(&msg);

        switch (msg.type) {
            case GNRC_NETAPI_MSG_TYPE_RCV:
                DEBUG("6lo: GNRC_NETDEV_MSG_TYPE_RCV received\n");
                _receive(msg.content.ptr);
                break;

            case GNRC_NETAPI_MSG_TYPE_SND:
                DEBUG("6lo: GNRC_NETDEV_MSG_TYPE_SND received\n");
                _send(msg.content.ptr);
                break;

            case GNRC_NETAPI_MSG_TYPE_GET:
            case GNRC_NETAPI_MSG_TYPE_SET:
                DEBUG("6lo: reply to unsupported get/set\n");
                reply.content.value = -ENOTSUP;
                msg_reply(&msg, &reply);
                break;
#ifdef MODULE_GNRC_SIXLOWPAN_FRAG
            case GNRC_SIXLOWPAN_MSG_FRAG_SND:
                DEBUG("6lo: send fragmented event received\n");
                gnrc_sixlowpan_frag_send(msg.content.ptr);
                break;
#endif

            default:
                DEBUG("6lo: operation not supported\n");
                break;
        }
    }

    return NULL;
}
예제 #27
0
파일: main.c 프로젝트: JiapengLi/RIOT
void *radio(void *arg)
{
    (void) arg;

    msg_t m;
    radio_packet_t *p;
    unsigned int tmp = 0, cur_seq = 0;

    msg_init_queue(msg_q, RCV_BUFFER_SIZE);

    puts("Start receiving");

    while (receiving) {
        msg_receive(&m);

        if (m.type == PKT_PENDING) {
            p = (radio_packet_t *) m.content.ptr;

            if ((p->src == SENDER_ADDR) && (p->length == PACKET_SIZE)) {
                puts("received");
                cur_seq = (p->data[0] << 8) + p->data[1];

                if (first < 0) {
                    first = cur_seq;
                }
                else {
                    tmp = cur_seq - last_seq;

                    if (last_seq && (tmp > 1)) {
                        missed_cnt += (tmp - 1);
                    }
                }

                last_seq = cur_seq;
            }
            else {
                printf("sender was %i\n", p->src);
            }

            p->processing--;
        }
        else if (m.type == ENOBUFFER) {
            puts("Transceiver buffer full");
        }
        else {
            puts("Unknown packet received");
        }
    }

    return NULL;
}
예제 #28
0
파일: ping.c 프로젝트: AnonMall/RIOT
/* internal functions */
static void *l2_pkt_handler(void *unused)
{
    (void) unused;

    msg_t m;
    radio_packet_t *p;
    l2_ping_payload_t *pp;

    msg_init_queue(msg_q, sizeof(msg_q));

    while (1) {
        msg_receive(&m);

        if (m.type == PKT_PENDING) {
            vtimer_now(&end);
            p = (radio_packet_t *) m.content.ptr;
            pp = (l2_ping_payload_t *) p->data;

            if ((pp->type & L2_PAYLOAD_TYPE) == L2_PAYLOAD_PING) {
                DEBUGF("INFO: received l2_ping_packet number %d from %d with payload(%d) %.*s.\n",
                        pp->seq, p->src, pp->payload_len, pp->payload_len, pp->payload);
                switch (pp->type & L2_PING_TYPE) {
                    case L2_PING:
                        ping_handler(p->src, pp->seq);
                        break;
                    case L2_PONG:
                        pong_handler();
                        break;
                    case L2_PROBE:
                        probe_handler(p->src);
                        break;
                    default:
                        DEBUGF("ERROR: Unknown L2 PING type\n");
                }
            }
            else {
                DEBUGF("WARN: no L2 ping packet, type is %02X\n", pp->type);
            }

            p->processing--;
        }
        else if (m.type == ENOBUFFER) {
            DEBUGF("ERROR: Transceiver buffer full\n");
        }
        else {
            DEBUGF("ERROR: Unknown messagereceived\n");
        }
    }

    return NULL;
}
예제 #29
0
static void *etx_radio(void *arg)
{
    (void) arg;

    msg_t m;
    radio_packet_t *p;

    ieee802154_frame_t frame;

    msg_init_queue(msg_que, ETX_RCV_QUEUE_SIZE);

    ipv6_addr_t ll_address;
    ipv6_addr_t candidate_addr;

    ipv6_addr_set_link_local_prefix(&ll_address);
    ipv6_net_if_get_best_src_addr(&candidate_addr, &ll_address);

    while (1) {
        msg_receive(&m);

        if (m.type == PKT_PENDING) {
            p = (radio_packet_t *) m.content.ptr;

            ieee802154_frame_read(p->data, &frame, p->length);

            if (frame.payload[0] == ETX_PKT_OPTVAL) {
                //copy to receive buffer
                memcpy(etx_rec_buf, &frame.payload[0], frame.payload_len);

                //create IPv6 address from radio packet
                //we can do the cast here since rpl nodes can only have addr
                //up to 8 bits
                candidate_addr.uint8[ETX_IPV6_LAST_BYTE] = (uint8_t) p->src;
                //handle the beacon
                mutex_lock(&etx_mutex);
                etx_handle_beacon(&candidate_addr);
                mutex_unlock(&etx_mutex);
            }

            p->processing--;
        }
        else if (m.type == ENOBUFFER) {
            DEBUGF("Transceiver buffer full\n");
        }
        else {
            //packet is not for me, whatever
        }
    }

    return NULL;
}
예제 #30
0
static void *_event_loop(void *arg)
{
    (void)arg;
    msg_init_queue(_queue, LWIP_NETDEV2_QUEUE_LEN);
    while (1) {
        msg_t msg;
        msg_receive(&msg);
        if (msg.type == LWIP_NETDEV2_MSG_TYPE_EVENT) {
            netdev2_t *dev = msg.content.ptr;
            dev->driver->isr(dev);
        }
    }
    return NULL;
}