static void light_sensor() { float value = isl29020_read_sample(); printf("Luminosity measure: %f lux\n", value); }
static char *radio_pkt(uint8_t channel, uint8_t tx_power) { static phy_packet_t tx_pkt = { .data = tx_pkt.raw_data, .length = 125, }; uint16_t i; for (i = 0; i < 125; i++) { tx_pkt.data[i] = i; } int success; char *ret = NULL; xQueueReceive(radio_queue, &success, 0); // cleanup queue phy_idle(platform_phy); /* * config radio */ if (phy_set_channel(platform_phy, channel)) ON_ERROR("err_set_channel", radio_cleanup); if (phy_set_power(platform_phy, tx_power)) ON_ERROR("err_set_power", radio_cleanup); /* * Send packet * * No interlocking because * Current queue is EVENT_QUEUE_APPLI * phy_ handlers are executed by EVENT_QUEUE_NETWORK */ if (phy_tx_now(platform_phy, &tx_pkt, radio_rx_tx_done)) ON_ERROR("err_tx", radio_cleanup); if (pdTRUE != xQueueReceive(radio_queue, &success, ONE_SECOND) || !success) ON_ERROR("tx_failed", radio_cleanup); // SUCCESS radio_cleanup: phy_reset(platform_phy); return ret; } static char *radio_ping_pong(uint8_t channel, uint8_t tx_power) { char *ret = NULL; int success; static phy_packet_t tx_pkt = { .data = tx_pkt.raw_data, .length = sizeof(RADIO_TX_STR), .raw_data = RADIO_TX_STR, }; static phy_packet_t rx_pkt = {.data = rx_pkt.raw_data}; xQueueReceive(radio_queue, &success, 0); // cleanup queue phy_idle(platform_phy); /* config radio */ if (phy_set_channel(platform_phy, channel)) ON_ERROR("err_set_channel", ping_pong_cleanup); if (phy_set_power(platform_phy, tx_power)) ON_ERROR("err_set_power", ping_pong_cleanup); /* * Send packet * * No interlocking because * Current queue is EVENT_QUEUE_APPLI * phy_ handlers are executed by EVENT_QUEUE_NETWORK */ if (phy_tx_now(platform_phy, &tx_pkt, radio_rx_tx_done)) ON_ERROR("err_tx", ping_pong_cleanup); if (pdTRUE != xQueueReceive(radio_queue, &success, ONE_SECOND) || !success) ON_ERROR("tx_failed", ping_pong_cleanup); /* * Wait for answer */ memset(rx_pkt.raw_data, 0, sizeof(rx_pkt.raw_data)); phy_rx_now(platform_phy, &rx_pkt, radio_rx_tx_done); if (pdTRUE != xQueueReceive(radio_queue, &success, ONE_SECOND) || !success) ON_ERROR("rx_timeout", ping_pong_cleanup); // Packet reception if (strcmp("RX_PKT_HELLO_WORLD", (char *)rx_pkt.raw_data)) ON_ERROR("wrong_packet_received", ping_pong_cleanup); // SUCCESS ret = NULL; ping_pong_cleanup: phy_reset(platform_phy); return ret; } #ifdef IOTLAB_M3 //////// static int test_flash_nand() { static uint8_t buf_EE[256] = {[0 ... 255] = 0xEE}; static uint8_t buf[256] = {[0 ... 255] = 0x00}; // Write subsector 200 and re-read it n25xxx_write_enable(); n25xxx_erase_subsector(0x00c80000); n25xxx_write_enable(); n25xxx_write_page(0x00c80000, buf_EE); n25xxx_read(0x00c80000, buf, sizeof(buf)); n25xxx_write_enable(); n25xxx_erase_subsector(0x00c80000); // check read values return memcmp(buf_EE, buf, sizeof(buf)); } //////// static int cmd_get_light(char *command) { if (strcmp(command, "get_light")) return 1; printf("ACK get_light %f lux\n", isl29020_read_sample()); return 0; } static int cmd_get_pressure(char *command) { if (strcmp(command, "get_pressure")) return 1; uint32_t pressure; lps331ap_read_pres(&pressure); printf("ACK get_pressure %f mbar\n", pressure / 4096.0); return 0; } static int cmd_test_flash_nand(char *command) { if (strcmp(command, "test_flash")) return 1; if (test_flash_nand()) printf("NACK test_flash read_different_write\n"); else printf("ACK test_flash\n"); return 0; } #endif // IOTLAB_M3 /* Leds Commands */ static int cmd_leds_on(char *command) { uint8_t leds = 0; if (1 != sscanf(command, "leds_on %u", &leds)) return 1; leds_on(leds); printf("ACK leds_on %x\n", leds); return 0; } static int cmd_leds_off(char *command) { uint8_t leds = 0; if (1 != sscanf(command, "leds_off %u", &leds)) return 1; leds_off(leds); printf("ACK leds_off %x\n", leds); return 0; }