From f368875ea26f04c30131ddbf568725fc6d1f6101 Mon Sep 17 00:00:00 2001 From: Harald Pichler Date: Wed, 6 Sep 2017 16:54:56 +0200 Subject: [PATCH] add params_save_channel --- .../arduino-settingsmanager/shell-merkur.c | 29 +++++++- .../osd/arduino-settingsmanager/sketch.pde | 74 ++++++++++--------- platform/osd-merkur-256/params.c | 15 ++++ platform/osd-merkur-256/params.h | 1 + 4 files changed, 82 insertions(+), 37 deletions(-) diff --git a/examples/osd/arduino-settingsmanager/shell-merkur.c b/examples/osd/arduino-settingsmanager/shell-merkur.c index 5c75774fb..d45c6d854 100644 --- a/examples/osd/arduino-settingsmanager/shell-merkur.c +++ b/examples/osd/arduino-settingsmanager/shell-merkur.c @@ -69,6 +69,12 @@ SHELL_COMMAND(ccathresholds_command, "ccathresholds", "ccathresholds save parameters to eeprom settingsmanager", + &shell_saveparam_process); + /*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_txpower_process, ev, data) { @@ -145,12 +151,33 @@ PROCESS_THREAD(shell_ccathresholds_process, ev, data) PROCESS_END(); } /*---------------------------------------------------------------------------*/ +PROCESS_THREAD(shell_saveparam_process, ev, data) +{ + radio_value_t value; + char buf[20]; + const char *newptr; + PROCESS_BEGIN(); + /* Save txpower */ + params_save_channel(); + /* Save rfchannel */ + + /* Save ccathresholds */ + + /* Save panid */ + + shell_output_str(&rfchannel_command, "saveparam done ", 0); + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ void shell_merkur_init(void) { shell_register_command(&txpower_command); shell_register_command(&rfchannel_command); - shell_register_command(&ccathresholds_command); + shell_register_command(&ccathresholds_command); // shell_register_command(&panid_command); + shell_register_command(&saveparam_command); + } /*---------------------------------------------------------------------------*/ diff --git a/examples/osd/arduino-settingsmanager/sketch.pde b/examples/osd/arduino-settingsmanager/sketch.pde index 99b63088d..1c18350dc 100644 --- a/examples/osd/arduino-settingsmanager/sketch.pde +++ b/examples/osd/arduino-settingsmanager/sketch.pde @@ -130,52 +130,53 @@ void setup (void) led_status=0; // settings manager /* Basic setting of parameters */ - status = settings_set_uint16(SETTINGS_KEY_PAN_ID, 0xABCD); - if(SETTINGS_STATUS_OK != status) { - printf("settings-example: `set` failed: %d\n", status); - } - status = settings_set_uint8(SETTINGS_KEY_CHANNEL, 11); - if(SETTINGS_STATUS_OK != status) { - printf("settings-example: `set` failed: %d\n", status); - } - status = settings_set_cstr(SETTINGS_KEY_HOSTNAME, "contiki.local"); - if(SETTINGS_STATUS_OK != status) { - printf("settings-example: `set` failed: %d\n", status); - } - /* Basic getting of parameters */ - panid = settings_get_uint16(SETTINGS_KEY_PAN_ID, 0); - if(0xABCD != panid) { - printf("settings-example: `get` failed: value mismatch.\n"); - } - channel = settings_get_uint16(SETTINGS_KEY_CHANNEL, 0); - if(26 != channel) { - printf("settings-example: `get` failed: value mismatch.\n"); - } - if(!settings_get_cstr(SETTINGS_KEY_HOSTNAME, 0, hostname, sizeof(hostname))) { - printf("settings-example: `get` failed: settings_get_cstr returned NULL\n"); - } else if(strcmp(hostname, "contiki.local") != 0) { - printf("settings-example: `get` failed: value mismatch.\n"); - } +// status = settings_set_uint16(SETTINGS_KEY_PAN_ID, 0xABCD); +// if(SETTINGS_STATUS_OK != status) { +// printf("settings-example: `set` failed: %d\n", status); +// } +// status = settings_set_uint8(SETTINGS_KEY_CHANNEL, 11); +// if(SETTINGS_STATUS_OK != status) { +// printf("settings-example: `set` failed: %d\n", status); +// } +// status = settings_set_cstr(SETTINGS_KEY_HOSTNAME, "contiki.local"); +// if(SETTINGS_STATUS_OK != status) { +// printf("settings-example: `set` failed: %d\n", status); +// } + /* Basic getting of parameters */ +// panid = settings_get_uint16(SETTINGS_KEY_PAN_ID, 0); +// if(0xABCD != panid) { +// printf("settings-example: `get` failed: value mismatch.\n"); +// } +// channel = settings_get_uint16(SETTINGS_KEY_CHANNEL, 0); +// if(26 != channel) { +// printf("settings-example: `get` failed: value mismatch.\n"); +// } + +// if(!settings_get_cstr(SETTINGS_KEY_HOSTNAME, 0, hostname, sizeof(hostname))) { +// printf("settings-example: `get` failed: settings_get_cstr returned NULL\n"); +// } else if(strcmp(hostname, "contiki.local") != 0) { +// printf("settings-example: `get` failed: value mismatch.\n"); +// } /*************************************************************************/ /* Adding multiple values with the same key */ - for(i = 0; i < 10; i++) { - settings_add_uint8(TCC('e','x'), i + 20); - } +// for(i = 0; i < 10; i++) { +// settings_add_uint8(TCC('e','x'), i + 20); +// } /*************************************************************************/ /* Reading multiple values with the same key */ - for(i = 0; i < 10; i++) { - if(settings_get_uint8(TCC('e', 'x'), i) != i + 20) { - printf("settings-example: `get` failed: value mismatch.\n"); - } - } +// for(i = 0; i < 10; i++) { +// if(settings_get_uint8(TCC('e', 'x'), i) != i + 20) { +// printf("settings-example: `get` failed: value mismatch.\n"); +// } +// } /*************************************************************************/ /* Iterating thru all settings */ - +/* for(iter = settings_iter_begin(); iter; iter = settings_iter_next(iter)) { settings_length_t len = settings_iter_get_value_length(iter); eeprom_addr_t addr = settings_iter_get_value_addr(iter); @@ -206,6 +207,7 @@ void setup (void) printf(">\n"); } +*/ printf("settings-example: Done.\n"); // Seriell Shell @@ -222,7 +224,7 @@ void setup (void) shell_file_init(); #endif - get_rf_consts(); +// get_rf_consts(); print_rf_values(); // init coap resourcen rest_init_engine (); diff --git a/platform/osd-merkur-256/params.c b/platform/osd-merkur-256/params.c index f9cab9f0e..b7fc324e6 100644 --- a/platform/osd-merkur-256/params.c +++ b/platform/osd-merkur-256/params.c @@ -276,4 +276,19 @@ params_get_txpower(void) { } return x; } + +settings_status_t +params_save_channel(void) { + radio_value_t value; + settings_status_t x=SETTINGS_STATUS_OK; + + if(NETSTACK_RADIO.get_value(RADIO_PARAM_CHANNEL, &value) == RADIO_RESULT_OK) { + printf("%d\n", value); + if(settings_set_uint8(SETTINGS_KEY_CHANNEL, value) != SETTINGS_STATUS_OK) { + printf("settings-example: `set` failed: \n"); + x = SETTINGS_STATUS_FAILURE; + } + } + return x; +} #endif /* CONTIKI_CONF_SETTINGS_MANAGER */ diff --git a/platform/osd-merkur-256/params.h b/platform/osd-merkur-256/params.h index bb647d9c5..baf153a4f 100644 --- a/platform/osd-merkur-256/params.h +++ b/platform/osd-merkur-256/params.h @@ -101,6 +101,7 @@ uint8_t params_get_channel(void); uint16_t params_get_panid(void); uint16_t params_get_panaddr(void); uint8_t params_get_txpower(void); +settings_status_t params_save_channel(void); #endif #endif /* PARAMS_H_ */