コード例 #1
0
ファイル: uhcpc.c プロジェクト: LudwigKnuepfer/RIOT
/**
 * @brief Request prefix from uhcp server
 *
 * Never returns.
 * Calls @c uhcp_handle_prefix() when a prefix or prefix change is received.
 *
 * @param[in]   iface   interface to request prefix on
 */
void uhcp_client(uhcp_iface_t iface)
{
    sock_udp_t sock;
    sock_udp_ep_t local = { .family=AF_INET6, .port=UHCP_PORT, .netif=iface };
    sock_udp_ep_t req_target = { .family=AF_INET6, .port=UHCP_PORT, .netif=iface };
    sock_udp_ep_t remote;

    inet_pton(AF_INET6, "ff15::abcd", req_target.addr.ipv6);

    /* prepare UHCP header */
    uhcp_req_t req;
    uhcp_hdr_set(&req.hdr, UHCP_REQ);
    req.prefix_len = 64;

    /* create listening socket */
    int res = sock_udp_create(&sock, &local, NULL, 0);

    uint8_t buf[sizeof(uhcp_push_t) + 16];

    while(1) {
        puts("uhcp_client(): sending REQ...");
        sock_udp_send(&sock, &req, sizeof(uhcp_req_t), &req_target);
        res = sock_udp_recv(&sock, buf, sizeof(buf), 10U*US_PER_SEC, &remote);
        if (res > 0) {
            uhcp_handle_udp(buf, res, remote.addr.ipv6, remote.port, iface);
            xtimer_sleep(60);
        }
        else {
            puts("uhcp_client(): no reply received");
        }
    }
}
コード例 #2
0
ファイル: main.c プロジェクト: LudwigKnuepfer/RIOT
int main(void)
{
    printf("Init HTS221 on I2C_DEV(%i)\n", (int)hts221_params[0].i2c);
    if (hts221_init(&dev, &hts221_params[0]) != HTS221_OK) {
        puts("[FAILED]");
        return 1;
    }
    if (hts221_power_on(&dev) != HTS221_OK) {
        puts("[FAILED] to set power on!");
        return 2;
    }
    if (hts221_set_rate(&dev, dev.p.rate) != HTS221_OK) {
        puts("[FAILED] to set continuous mode!");
        return 3;
    }

    while(1) {
        uint16_t hum = 0;
        int16_t temp = 0;
        if (hts221_read_humidity(&dev, &hum) != HTS221_OK) {
            puts(" -- failed to humidity!");
        }
        if (hts221_read_temperature(&dev, &temp) != HTS221_OK) {
            puts(" -- failed to temperature!");
        }
        bool negative = (temp < 0);
        if (negative) {
            temp = -temp;
        }
        printf("H: %u.%u%%, T:%c%u.%u°C\n", (hum/10), (hum%10),
               (negative ? '-' : ' '), (temp/10), (temp%10));
        xtimer_sleep(SLEEP_S);
    }
    return 0;
}
コード例 #3
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;
}
コード例 #4
0
ファイル: main.c プロジェクト: miri64/RIOT_playground
int main(void)
{
    sock_udp_ep_t corerd_server;

    /* Schalte On-Board-LED aus */
    LED0_OFF;
    /* Verknüpfe den On-Board-Button-Pin mit dem entsprechenden Handler */
    gpio_init_int(BTN0_PIN, BTN0_MODE, GPIO_FALLING, _toggle_dino, NULL);
    /* Initialisiere den Dino-Motor-Pin als ausgehenden Pin */
    gpio_init(DINO_MOVE_PIN, GPIO_OUT);
    /* Registriere die CoAP-Server Definition */
    gcoap_register_listener(&_listener);

    /* warte ein wenig, bis sich das Netzwerk konfiguriert hat */
    xtimer_sleep(2);

    /* Erstelle einen sock-Endpunkt für die vorkonfigurierte Addresse
     * des Ressourcen-Verzeichnisses */
    if (make_sock_ep(&corerd_server, corerd_server_addr) < 0) {
        puts("Can not parse CORERD_SERVER_ADDR");
    }
    /* Registriere den CoAP-Server im Ressourcen-Verzeichnis */
    cord_ep_register(&corerd_server, NULL);
    /* wir müchten nicht terminieren */
    while (1) { /* Endlos-Schleife */ }
    return 0;
}
コード例 #5
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;
}
コード例 #6
0
static void *reg_runner(void *arg)
{
    (void)arg;

    /* wait some seconds to give the address configuration some time to settle */
    xtimer_sleep(RDCLI_STARTUP_DELAY);

    while (1) {
        if (rdcli_simple_register() != RDCLI_SIMPLE_OK) {
            /* if this fails once, it will always fail, so we might as well
             * quit now */
            LOG_ERROR("[rdcli_simple] error: unable to send registration\n");
            break;
        }
        xtimer_sleep(RDCLI_UPDATE_INTERVAL);
    }

    return NULL;
}
コード例 #7
0
ファイル: main.c プロジェクト: nikosft/libcoap
int main(void)
{
    puts("RIOT libcoap example application");
    puts("Waiting for address autoconfiguration...");
    xtimer_sleep(3);
    puts("Configured network interfaces:");
    _netif_config(0, NULL);
    puts("CoAP server will be initialized");
    coap_server_loop();
    return 0;
}
コード例 #8
0
ファイル: main.c プロジェクト: miri64/RIOT_playground
int main(void)
{
    ip6_addr_t addr;
    struct netconn *conn;
    struct netbuf *buf;

    xtimer_sleep(5U);   /* wait 5 sec to bootstrap network */

    ip6addr_aton(TCP_SERVER_ADDR, &addr);
    conn = netconn_new(NETCONN_TYPE_IPV6 | NETCONN_TCP);
    netconn_connect(conn, &addr, TCP_SERVER_PORT);
    puts("Kill TCP server now");
    netconn_recv(conn, &buf);

    return 0;
}
コード例 #9
0
ファイル: main.c プロジェクト: A-Paul/RIOT
int main(void)
{
    lsm6dsl_t dev;
    int16_t temp_value;
    lsm6dsl_3d_data_t mag_value;
    lsm6dsl_3d_data_t acc_value;

    puts("LSM6DSL test application");
    printf("Initializing LSM6DSL sensor at I2C_%i... ", lsm6dsl_params->i2c);

    if (lsm6dsl_init(&dev, lsm6dsl_params) != LSM6DSL_OK) {
        puts("[ERROR]");
        return 1;
    }
    puts("[SUCCESS]\n");

    puts("Powering down LSM6DSL sensor...");
    if (lsm6dsl_acc_power_down(&dev) != LSM6DSL_OK) {
        puts("[ERROR]");
        return 1;
    }
    if (lsm6dsl_gyro_power_down(&dev) != LSM6DSL_OK) {
        puts("[ERROR]");
        return 1;
    }
    puts("[SUCCESS]\n");

    xtimer_sleep(1);

    puts("Powering up LSM6DSL sensor...");
    if (lsm6dsl_acc_power_up(&dev) != LSM6DSL_OK) {
        puts("[ERROR]");
        return 1;
    }
    if (lsm6dsl_gyro_power_up(&dev) != LSM6DSL_OK) {
        puts("[ERROR]");
        return 1;
    }
    puts("[SUCCESS]\n");

    while (1) {
        if (lsm6dsl_read_acc(&dev, &acc_value) == LSM6DSL_OK) {
            printf("Accelerometer x: %i y: %i z: %i\n", acc_value.x,
                                                        acc_value.y,
                                                        acc_value.z);
        }
        else {
            puts("[ERROR] reading accelerometer!\n");
        }

        if (lsm6dsl_read_gyro(&dev, &mag_value) == LSM6DSL_OK) {
            printf("Gyroscope x: %i y: %i z: %i\n", mag_value.x,
                                                    mag_value.y,
                                                    mag_value.z);
        }
        else {
            puts("[ERROR] reading gyroscope!\n");
        }

        if (lsm6dsl_read_temp(&dev, &temp_value) == LSM6DSL_OK) {
            printf("Temperature [in °C x 100]: %i \n", temp_value);
        }
        else {
            puts("[ERROR] reading temperature!\n");
        }

        puts("");
        xtimer_usleep(SLEEP);
    }

    return 0;
}
コード例 #10
0
ファイル: main.c プロジェクト: ryankurte/RIOT
void *srv_thread(void *arg)
{
    int tid = (int) arg;
    uint32_t cycles = 0;
    uint32_t cycles_ok = 0;
    uint32_t failed_payload_verifications = 0;

    /* Transmission control block */
    gnrc_tcp_tcb_t tcb;

    /* Connection handling code */
    printf("Server running: TID=%d\n", tid);
    while (cycles < CYCLES) {
        /* Initialize TCB struct */
        gnrc_tcp_tcb_init(&tcb);

        /* Connect to peer */
        int ret = gnrc_tcp_open_passive(&tcb, AF_INET6, NULL, LOCAL_PORT);
        switch (ret) {
            case 0:
                DEBUG("TID=%d : gnrc_tcp_open_passive() : 0 : ok\n", tid);
                break;

            case -EISCONN:
                printf("TID=%d : gnrc_tcp_open_passive() : -EISCONN\n", tid);
                return 0;

            case -EINVAL:
                printf("TID=%d : gnrc_tcp_open_passive() : -EINVAL\n", tid);
                return 0;

            case -EAFNOSUPPORT:
                printf("TID=%d : gnrc_tcp_open_passive() : -EAFNOSUPPORT\n", tid);
                return 0;

            case -ENOMEM:
                printf("TID=%d : gnrc_tcp_open_passive() : -ENOMEM\n", tid);
                return 0;

            default:
                printf("TID=%d : gnrc_tcp_open_passive() : %d\n", tid, ret);
                return 0;
        }

        /* Receive data, stop if errors were found */
        for (size_t rcvd = 0; rcvd < sizeof(bufs[tid]) && ret >= 0; rcvd += ret) {
            ret = gnrc_tcp_recv(&tcb, (void *) (bufs[tid] + rcvd), sizeof(bufs[tid]) - rcvd,
                                GNRC_TCP_CONNECTION_TIMEOUT_DURATION);
            switch (ret) {
                case -ENOTCONN:
                    printf("TID=%d : gnrc_tcp_rcvd() : -ENOTCONN\n", tid);
                    break;

                case -EAGAIN:
                    printf("TID=%d : gnrc_tcp_rcvd() : -EAGAIN : retry after 10sec\n", tid);
                    ret = 0;
                    xtimer_sleep(10);
                    break;

                case -ECONNABORTED:
                    printf("TID=%d : gnrc_tcp_rcvd() : -ECONNABORTED\n", tid);
                    break;

                case -ECONNRESET:
                    printf("TID=%d : gnrc_tcp_rcvd() : -ECONNRESET\n", tid);
                    break;

                case -ETIMEDOUT:
                    printf("TID=%d : gnrc_tcp_rcvd() : -ETIMEDOUT\n", tid);
                    break;

                default:
                    if (ret >= 0) {
                        DEBUG("TID=%d : gnrc_tcp_rcvd() : %d Bytes read\n", tid, ret);
                    }
                    else {
                        printf("TID=%d : gnrc_tcp_rcvd() : %d\n", tid, ret);
                        return 0;
                    }
              }
        }

        /* Check received pattern */
       for (size_t i = 0; i < sizeof(bufs[tid]); ++i) {
             if (bufs[tid][i] != TEST_PATERN_CLI) {
                printf("TID=%d : Payload verfication failed\n", tid);
                failed_payload_verifications += 1;
                break;
            }
        }

        /* Fill buffer with a test pattern */
        for (size_t i = 0; i < sizeof(bufs[tid]); ++i) {
            bufs[tid][i] = TEST_PATERN_SRV;
        }

        /* Send data, stop if errors were found */
        for (size_t sent = 0; sent < sizeof(bufs[tid]) && ret >= 0; sent += ret) {
            ret = gnrc_tcp_send(&tcb, bufs[tid] + sent, sizeof(bufs[tid]) - sent, 0);
            switch (ret) {
                case -ENOTCONN:
                    printf("TID=%d : gnrc_tcp_send() : -ENOTCONN\n", tid);
                    break;

                case -ECONNABORTED:
                    printf("TID=%d : gnrc_tcp_send() : -ECONNABORTED\n", tid);
                    break;

                case -ETIMEDOUT:
                    printf("TID=%d : gnrc_tcp_send() : -ETIMEDOUT\n", tid);
                    break;

                case -ECONNRESET:
                    printf("TID=%d : gnrc_tcp_send() : -ECONNRESET\n", tid);
                    break;

                default:
                    if (ret >= 0) {
                        DEBUG("TID=%d : gnrc_tcp_send() : %d Bytes sent.\n", tid, ret);
                    }
                    else {
                        printf("TID=%d : gnrc_tcp_send() : %d\n", tid, ret);
                        return 0;
                    }
              }
        }

        /* Close connection */
        gnrc_tcp_close(&tcb);

        /* Gather data */
        cycles += 1;
        if (ret >= 0) {
            cycles_ok += 1;
        }
        printf("TID=%d : %"PRIi32" test cycles completed. %"PRIi32" ok, %"PRIi32" faulty",
               tid, cycles, cycles_ok, cycles - cycles_ok);
        printf(", %"PRIi32" failed payload verifications\n", failed_payload_verifications);
    }
    printf("server thread terminating: TID=%d\n", tid);
    return 0;
}
コード例 #11
0
ファイル: main.c プロジェクト: arvindpdmn/RIOT
int main(void)
{
    uint32_t i;
    nvram_spi_params_t spi_params = {
        .spi = TEST_NVRAM_SPI_DEV,
        .cs = TEST_NVRAM_SPI_CS,
        .address_count = TEST_NVRAM_SPI_ADDRESS_COUNT,
    };
    nvram_t dev;
    uint32_t start_delay = 10;

    puts("NVRAM SPI test application starting...");
    printf("Initializing SPI_%i... ", TEST_NVRAM_SPI_DEV);
    if (spi_init_master(TEST_NVRAM_SPI_DEV, SPI_CONF, SPI_SPEED_10MHZ) == 0) {
        puts("[OK]");
    }
    else {
        puts("[Failed]\n");
        return 1;
    }

    puts("Initializing NVRAM SPI device descriptor... ");
    if (nvram_spi_init(&dev, &spi_params, TEST_NVRAM_SPI_SIZE) == 0) {
        puts("[OK]");
    }
    else {
        puts("[Failed]\n");
        return 1;
    }

    puts("NVRAM SPI init done.\n");

    puts("!!! This test will erase everything on the NVRAM !!!");
    puts("!!! Unplug/reset/halt device now if this is not acceptable !!!");
    puts("Waiting for 10 seconds before continuing...");
    xtimer_sleep(start_delay);

    puts("Reading current memory contents...");
    for (i = 0; i < TEST_NVRAM_SPI_SIZE; ++i) {
        if (dev.read(&dev, &buf_in[i], i, 1) != 1) {
            puts("[Failed]\n");
            return 1;
        }
    }
    puts("[OK]");
    puts("NVRAM contents before test:");
    print_buffer(buf_in, sizeof(buf_in));

    puts("Writing bytewise 0xFF to device");

    memset(buf_out, 0xff, sizeof(buf_out));
    for (i = 0; i < TEST_NVRAM_SPI_SIZE; ++i) {
        if (dev.write(&dev, &buf_out[i], i, 1) != 1) {
            puts("[Failed]\n");
            return 1;
        }
        if (buf_out[i] != 0xff) {
            puts("nvram_spi_write modified *src!");
            printf(" i = %08lx\n", (unsigned long) i);
            puts("[Failed]\n");
            return 1;
        }
    }

    puts("Reading back blockwise");
    memset(buf_in, 0x00, sizeof(buf_in));
    if (dev.read(&dev, buf_in, 0, TEST_NVRAM_SPI_SIZE) != TEST_NVRAM_SPI_SIZE) {
        puts("[Failed]\n");
        return 1;
    }
    puts("[OK]");
    puts("Verifying contents...");
    if (memcmp(buf_in, buf_out, TEST_NVRAM_SPI_SIZE) != 0) {
        puts("[Failed]\n");
        return 1;
    }
    puts("[OK]");

    puts("Writing blockwise address complement to device");
    for (i = 0; i < TEST_NVRAM_SPI_SIZE; ++i) {
        buf_out[i] = (~(i)) & 0xff;
    }
    if (dev.write(&dev, buf_out, 0, TEST_NVRAM_SPI_SIZE) != TEST_NVRAM_SPI_SIZE) {
        puts("[Failed]\n");
        return 1;
    }
    puts("[OK]");
    puts("buf_out:");
    print_buffer(buf_out, sizeof(buf_out));
    puts("Reading back blockwise");
    memset(buf_in, 0x00, sizeof(buf_in));
    if (dev.read(&dev, buf_in, 0, TEST_NVRAM_SPI_SIZE) != TEST_NVRAM_SPI_SIZE) {
        puts("[Failed]\n");
        return 1;
    }
    puts("[OK]");
    puts("Verifying contents...");
    if (memcmp(buf_in, buf_out, TEST_NVRAM_SPI_SIZE) != 0) {
        puts("buf_in:");
        print_buffer(buf_in, sizeof(buf_in));
        puts("[Failed]\n");
        return 1;
    }
    puts("[OK]");

    puts("Generating pseudo-random test data...");

    for (i = 0; i < TEST_NVRAM_SPI_SIZE; ++i) {
        buf_out[i] = lcg_rand8();
    }

    puts("buf_out:");
    print_buffer(buf_out, sizeof(buf_out));

    puts("Writing blockwise data to device");
    if (dev.write(&dev, buf_out, 0, TEST_NVRAM_SPI_SIZE) != TEST_NVRAM_SPI_SIZE) {
        puts("[Failed]\n");
        return 1;
    }
    puts("[OK]");

    puts("Reading back blockwise");
    memset(buf_in, 0x00, sizeof(buf_in));
    if (dev.read(&dev, buf_in, 0, TEST_NVRAM_SPI_SIZE) != TEST_NVRAM_SPI_SIZE) {
        puts("[Failed]\n");
        return 1;
    }
    puts("[OK]");
    puts("Verifying contents...");
    if (memcmp(buf_in, buf_out, TEST_NVRAM_SPI_SIZE) != 0) {
        puts("buf_in:");
        print_buffer(buf_in, sizeof(buf_in));
        puts("[Failed]\n");
        return 1;
    }
    puts("[OK]");

    puts("All tests passed!");

    while(1);

    return 0;
}
コード例 #12
0
ファイル: main.c プロジェクト: Cr0s/RIOT
int main(void)
{
    uint32_t screen = 0;
    u8g2_t u8g2;

    /* initialize to stdout */
#if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_STDOUT
    puts("initializing to stdout.");

    u8g2_SetupBuffer_Utf8(&u8g2, U8G2_R0);
#endif

    /* initialize to virtual SDL (native only) */
#if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_SDL
    puts("initializing to SDL.");

    u8g2_SetupBuffer_SDL_128x64_4(&u8g2, U8G2_R0);
#endif

    /* initialize to SPI */
#if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_SPI
    puts("initializing to SPI.");

    TEST_U8G2_DISPLAY(&u8g2, U8G2_R0, u8x8_byte_riotos_hw_spi, u8x8_gpio_and_delay_riotos);

    u8g2_SetPins(&u8g2, pins, pins_enabled);
    u8g2_SetDevice(&u8g2, TEST_U8G2_SPI);
#endif

    /* initialize to I2C */
#if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_I2C
    puts("initializing to I2C.");

    TEST_U8G2_DISPLAY(&u8g2, U8G2_R0, u8x8_byte_riotos_hw_i2c, u8x8_gpio_and_delay_riotos);

    u8g2_SetPins(&u8g2, pins, pins_enabled);
    u8g2_SetDevice(&u8g2, TEST_U8G2_I2C);
    u8g2_SetI2CAddress(&u8g2, TEST_U8G2_ADDR);
#endif

    /* initialize the display */
    puts("Initializing display.");

    u8g2_InitDisplay(&u8g2);
    u8g2_SetPowerSave(&u8g2, 0);

    /* start drawing in a loop */
    puts("Drawing on screen.");

    while (true) {
        u8g2_FirstPage(&u8g2);

        do {
            u8g2_SetDrawColor(&u8g2, 1);
            u8g2_SetFont(&u8g2, u8g2_font_helvB12_tf);

            if (screen == 0) {
                u8g2_DrawStr(&u8g2, 12, 22, "THIS");
            } else if (screen == 1) {
                u8g2_DrawStr(&u8g2, 24, 22, "IS");
            } else if (screen == 2) {
                u8g2_DrawBitmap(&u8g2, 0, 0, 8, 32, logo);
            }
        } while (u8g2_NextPage(&u8g2));

#if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_STDOUT
        /* transfer screen buffer to stdout */
        utf8_show();
#endif

        /* show screen in next iteration */
        screen = (screen + 1) % 3;

        /* sleep a little */
        xtimer_sleep(1);
    }

    return 0;
}