Repository: incubator-mynewt-core Updated Branches: refs/heads/master ce47d8450 -> 3596d33e1
MYNEWT-739 sensor_test app: improvements - In the app tcs34725_config() was failing which was causing the sensor list to not get populated. Fixing it. - Cleaning up the sensor_test app to remove config, gpio toggle stats, gpio toggle logs from the app Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/3596d33e Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3596d33e Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3596d33e Branch: refs/heads/master Commit: 3596d33e13bd9b08f723102c107255a24f53d758 Parents: ce47d84 Author: Vipul Rahane <[email protected]> Authored: Mon Apr 24 18:22:28 2017 -0700 Committer: Vipul Rahane <[email protected]> Committed: Mon Apr 24 18:28:12 2017 -0700 ---------------------------------------------------------------------- apps/sensors_test/src/main.c | 147 ++++++-------------------------------- 1 file changed, 21 insertions(+), 126 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3596d33e/apps/sensors_test/src/main.c ---------------------------------------------------------------------- diff --git a/apps/sensors_test/src/main.c b/apps/sensors_test/src/main.c index 09f3e40..f6ef755 100755 --- a/apps/sensors_test/src/main.c +++ b/apps/sensors_test/src/main.c @@ -27,7 +27,6 @@ #include <console/console.h> #include <shell/shell.h> #include <log/log.h> -#include <stats/stats.h> #include <config/config.h> #include <sensor/sensor.h> #include <sim/sim_accel.h> @@ -40,8 +39,6 @@ #if MYNEWT_VAL(SPLIT_LOADER) #include "split/split.h" #endif -#include <bootutil/image.h> -#include <bootutil/bootutil.h> #include <assert.h> #include <string.h> #include <flash_test/flash_test.h> @@ -93,44 +90,12 @@ static volatile int g_task1_loops; static struct os_task task2; static volatile int g_task2_loops; -static struct log my_log; - /* Global test semaphore */ static struct os_sem g_test_sem; /* For LED toggling */ static int g_led_pin; -STATS_SECT_START(gpio_stats) -STATS_SECT_ENTRY(toggles) -STATS_SECT_END - -static STATS_SECT_DECL(gpio_stats) g_stats_gpio_toggle; - -static STATS_NAME_START(gpio_stats) -STATS_NAME(gpio_stats, toggles) -STATS_NAME_END(gpio_stats) - -static char *test_conf_get(int argc, char **argv, char *val, int max_len); -static int test_conf_set(int argc, char **argv, char *val); -static int test_conf_commit(void); -static int test_conf_export(void (*export_func)(char *name, char *val), - enum conf_export_tgt tgt); - -static struct conf_handler test_conf_handler = { - .ch_name = "test", - .ch_get = test_conf_get, - .ch_set = test_conf_set, - .ch_commit = test_conf_commit, - .ch_export = test_conf_export -}; - -static uint8_t test8; -static uint8_t test8_shadow; -static char test_str[32]; -static uint32_t cbmem_buf[MAX_CBMEM_BUF]; -static struct cbmem cbmem; - #if MYNEWT_VAL(SENSOR_OIC) && MYNEWT_VAL(SENSOR_BLE) /** @@ -339,56 +304,10 @@ sensor_oic_gap_event(struct ble_gap_event *event, void *arg) } #endif -static char * -test_conf_get(int argc, char **argv, char *buf, int max_len) -{ - if (argc == 1) { - if (!strcmp(argv[0], "8")) { - return conf_str_from_value(CONF_INT8, &test8, buf, max_len); - } else if (!strcmp(argv[0], "str")) { - return test_str; - } - } - return NULL; -} - -static int -test_conf_set(int argc, char **argv, char *val) -{ - if (argc == 1) { - if (!strcmp(argv[0], "8")) { - return CONF_VALUE_SET(val, CONF_INT8, test8_shadow); - } else if (!strcmp(argv[0], "str")) { - return CONF_VALUE_SET(val, CONF_STRING, test_str); - } - } - return OS_ENOENT; -} - -static int -test_conf_commit(void) -{ - test8 = test8_shadow; - - return 0; -} - -static int -test_conf_export(void (*func)(char *name, char *val), enum conf_export_tgt tgt) -{ - char buf[4]; - - conf_str_from_value(CONF_INT8, &test8, buf, sizeof(buf)); - func("test/8", buf); - func("test/str", test_str); - return 0; -} - static void task1_handler(void *arg) { struct os_task *t; - int prev_pin_state, curr_pin_state; /* Set the led pin for the E407 devboard */ g_led_pin = LED_BLINK_PIN; @@ -406,11 +325,7 @@ task1_handler(void *arg) os_time_delay(OS_TICKS_PER_SEC); /* Toggle the LED */ - prev_pin_state = hal_gpio_read(g_led_pin); - curr_pin_state = hal_gpio_toggle(g_led_pin); - LOG_INFO(&my_log, LOG_MODULE_DEFAULT, "GPIO toggle from %u to %u", - prev_pin_state, curr_pin_state); - STATS_INC(g_stats_gpio_toggle, toggles); + (void)hal_gpio_toggle(g_led_pin); /* Release semaphore to task 2 */ os_sem_release(&g_test_sem); @@ -488,8 +403,7 @@ config_sensor(void) rc = tcs34725_config((struct tcs34725 *)dev, &tcscfg); if (rc) { - os_dev_close(dev); - goto err; + console_printf("config_sensor %s failed %d\n", dev->od_name, rc); } os_dev_close(dev); #endif @@ -511,8 +425,7 @@ config_sensor(void) rc = tsl2561_config((struct tsl2561 *)dev, &tslcfg); if (rc) { - os_dev_close(dev); - goto err; + console_printf("config_sensor %s failed %d\n", dev->od_name, rc); } os_dev_close(dev); #endif @@ -535,8 +448,7 @@ config_sensor(void) rc = lsm303dlhc_config((struct lsm303dlhc *) dev, &lsmcfg); if (rc) { - os_dev_close(dev); - goto err; + console_printf("config_sensor %s failed %d\n", dev->od_name, rc); } os_dev_close(dev); #endif @@ -550,7 +462,6 @@ config_sensor(void) rc = bno055_init(dev, NULL); if (rc) { os_dev_close(dev); - assert(0); goto err; } @@ -566,14 +477,17 @@ config_sensor(void) rc = bno055_config((struct bno055 *) dev, &bcfg); if (rc) { - os_dev_close(dev); - goto err; + console_printf("config_sensor %s failed %d\n", dev->od_name, rc); } os_dev_close(dev); #endif - return (0); + return 0; + err: + + console_printf("config_sensor %s init failed %d\n", dev->od_name, rc); + return rc; } @@ -610,6 +524,8 @@ config_sensor(void) return (0); err: + console_printf("config_sensor %s init failed %d\n", dev->od_name, rc); + return (rc); } #endif @@ -692,7 +608,6 @@ ble_oic_log_init(void) int main(int argc, char **argv) { - int rc; #ifdef ARCH_sim mcu_sim_parse_args(argc, argv); @@ -700,47 +615,27 @@ main(int argc, char **argv) /* Initialize OS */ sysinit(); - rc = conf_register(&test_conf_handler); - assert(rc == 0); - - cbmem_init(&cbmem, cbmem_buf, MAX_CBMEM_BUF); - log_register("log", &my_log, &log_cbmem_handler, &cbmem, LOG_SYSLEVEL); - - stats_init(STATS_HDR(g_stats_gpio_toggle), - STATS_SIZE_INIT_PARMS(g_stats_gpio_toggle, STATS_SIZE_32), - STATS_NAME_INIT_PARMS(gpio_stats)); - - stats_register("gpio_toggle", STATS_HDR(g_stats_gpio_toggle)); - + /* Initialize BLE and OIC logs */ ble_oic_log_init(); - flash_test_init(); - + /* Load config */ conf_load(); - reboot_start(hal_reset_cause()); - + /* Initialize tasks */ init_tasks(); - /* If this app is acting as the loader in a split image setup, jump into - * the second stage application instead of starting the OS. - */ -#if MYNEWT_VAL(SPLIT_LOADER) - { - void *entry; - rc = split_app_go(&entry, true); - if(rc == 0) { - hal_system_restart(entry); - } - } -#endif - + /* Sensor device shell init */ sensors_dev_shell_init(); + /* Configure sensors */ config_sensor(); + /* Initialize BLE OIC GATT Server */ sensor_ble_oic_server_init(); + /* log reboot */ + reboot_start(hal_reset_cause()); + /* * As the last thing, process events from default event queue. */
