add params_save_channel

This commit is contained in:
Harald Pichler 2017-09-06 16:54:56 +02:00
parent 17e0b6f2cc
commit f368875ea2
4 changed files with 82 additions and 37 deletions

View file

@ -69,6 +69,12 @@ SHELL_COMMAND(ccathresholds_command,
"ccathresholds",
"ccathresholds <threshold: change cca thresholds -91 to -61 dBm (default -77)",
&shell_ccathresholds_process);
PROCESS(shell_saveparam_process, "saveparam");
SHELL_COMMAND(saveparam_command,
"saveparam",
"saveparam <> 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);
}
/*---------------------------------------------------------------------------*/

View file

@ -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 ();

View file

@ -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 */

View file

@ -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_ */