add shell save parameter txpower, channel, panid

This commit is contained in:
Harald Pichler 2017-09-07 11:44:54 +02:00
parent f368875ea2
commit a2f8424b74
5 changed files with 115 additions and 199 deletions

View file

@ -50,8 +50,10 @@
#include "sys/node-id.h"
#include "lib/settings.h"
#include "extended-rf-api.h"
#include "params.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h> /* strtol */
/*---------------------------------------------------------------------------*/
PROCESS(shell_txpower_process, "txpower");
@ -59,6 +61,11 @@ SHELL_COMMAND(txpower_command,
"txpower",
"txpower <power>: change transmission power 0 (3dbm, default) to 15 (-17.2dbm)",
&shell_txpower_process);
PROCESS(shell_panid_process, "panid");
SHELL_COMMAND(panid_command,
"panid",
"panid <0xabcd>: change panid (default 0xabcd)",
&shell_panid_process);
PROCESS(shell_rfchannel_process, "rfchannel");
SHELL_COMMAND(rfchannel_command,
"rfchannel",
@ -72,7 +79,7 @@ SHELL_COMMAND(ccathresholds_command,
PROCESS(shell_saveparam_process, "saveparam");
SHELL_COMMAND(saveparam_command,
"saveparam",
"saveparam <> save parameters to eeprom settingsmanager",
"saveparam <> save parameters txpower, channel, panid to eeprom settingsmanager",
&shell_saveparam_process);
/*---------------------------------------------------------------------------*/
@ -151,19 +158,43 @@ PROCESS_THREAD(shell_ccathresholds_process, ev, data)
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_saveparam_process, ev, data)
PROCESS_THREAD(shell_panid_process, ev, data)
{
radio_value_t value;
char buf[20];
const char *newptr;
char *newptr;
PROCESS_BEGIN();
value = strtol(data, &newptr, 0);
/* If no channel was given on the command line, we print out the
current channel. */
if(newptr == data) {
if(get_param(RADIO_PARAM_PAN_ID, &value) == RADIO_RESULT_OK) {
}
} else {
set_param(RADIO_PARAM_PAN_ID, value);
}
snprintf(buf, sizeof(buf),"0x%02x%02x\n", (value >> 8) & 0xFF, value & 0xFF);
shell_output_str(&panid_command, "panid: ", buf);
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_saveparam_process, ev, data)
{
PROCESS_BEGIN();
/* Save txpower */
params_save_channel();
params_save_txpower();
/* Save rfchannel */
params_save_channel();
/* Save ccathresholds */
// todo
/* Save panid */
params_save_panid();
shell_output_str(&rfchannel_command, "saveparam done ", 0);
@ -176,7 +207,7 @@ shell_merkur_init(void)
shell_register_command(&txpower_command);
shell_register_command(&rfchannel_command);
shell_register_command(&ccathresholds_command);
// shell_register_command(&panid_command);
shell_register_command(&panid_command);
shell_register_command(&saveparam_command);
}

View file

@ -27,205 +27,22 @@ uint8_t led_pin=4;
uint8_t led_status;
}
settings_status_t status;
uint16_t panid;
char hostname[30];
uint16_t channel;
struct rf_consts {
radio_value_t channel_min;
radio_value_t channel_max;
radio_value_t txpower_min;
radio_value_t txpower_max;
};
//static struct rf_consts consts;
static radio_value_t value;
static uint8_t ext_addr[8];
/*---------------------------------------------------------------------------*/
static void
print_rf_values(void)
{
printf("====================================\n");
printf("RF Values\n");
printf("Power: ");
if(get_param(RADIO_PARAM_POWER_MODE, &value) == RADIO_RESULT_OK) {
if(value == RADIO_POWER_MODE_ON) {
printf("On\n");
} else if(value == RADIO_POWER_MODE_OFF) {
printf("Off\n");
}
}
printf("Channel: ");
if(get_param(RADIO_PARAM_CHANNEL, &value) == RADIO_RESULT_OK) {
printf("%d\n", value);
}
printf("PAN ID: ");
if(get_param(RADIO_PARAM_PAN_ID, &value) == RADIO_RESULT_OK) {
printf("0x%02x%02x\n", (value >> 8) & 0xFF, value & 0xFF);
}
printf("16-bit Address: ");
if(get_param(RADIO_PARAM_16BIT_ADDR, &value) == RADIO_RESULT_OK) {
printf("0x%02x%02x\n", (value >> 8) & 0xFF, value & 0xFF);
}
printf("64-bit Address: ");
if(get_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8) == RADIO_RESULT_OK) {
print_64bit_addr(ext_addr);
}
printf("RX Mode: ");
if(get_param(RADIO_PARAM_RX_MODE, &value) == RADIO_RESULT_OK) {
printf("Address Filtering is ");
if(value & RADIO_RX_MODE_ADDRESS_FILTER) {
printf("On, ");
} else {
printf("Off, ");
}
printf("Auto ACK is ");
if(value & RADIO_RX_MODE_AUTOACK) {
printf("On, ");
} else {
printf("Off, ");
}
printf("(value=%d)\n", value);
}
printf("TX Mode: ");
if(get_param(RADIO_PARAM_TX_MODE, &value) == RADIO_RESULT_OK) {
printf("%d\n", value);
}
printf("TX Power: ");
if(get_param(RADIO_PARAM_TXPOWER, &value) == RADIO_RESULT_OK) {
printf("%d dBm [0x%04x]\n", value, (uint16_t)value);
}
printf("CCA Threshold: ");
if(get_param(RADIO_PARAM_CCA_THRESHOLD, &value) == RADIO_RESULT_OK) {
printf("%d dBm [0x%04x]\n", value, (uint16_t)value);
}
printf("RSSI: ");
if(get_param(RADIO_PARAM_RSSI, &value) == RADIO_RESULT_OK) {
printf("%d dBm [0x%04x]\n", value, (uint16_t)value);
}
}
void setup (void)
{
settings_iter_t iter;
int i;
// switch off the led
pinMode(led_pin, OUTPUT);
digitalWrite(led_pin, HIGH);
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");
// }
/*************************************************************************/
/* Adding multiple values with the same key */
// 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");
// }
// }
/*************************************************************************/
/* 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);
uint8_t byte;
union {
settings_key_t key;
char bytes[0];
} u;
u.key = settings_iter_get_key(iter);
if(u.bytes[0] >= 32 && u.bytes[0] < 127
&& u.bytes[1] >= 32 && u.bytes[1] < 127
) {
printf("settings-example: [%c%c] = <",u.bytes[0],u.bytes[1]);
} else {
printf("settings-example: <0x%04X> = <",u.key);
}
for(; len; len--, addr++) {
eeprom_read(addr, &byte, 1);
printf("%02X", byte);
if(len != 1) {
printf(" ");
}
}
printf(">\n");
}
*/
printf("settings-example: Done.\n");
// Seriell Shell
serial_shell_init();
// shell_blink_init();
shell_ps_init();
shell_reboot_init();
// shell_text_init();
// shell_time_init();
shell_merkur_init();
shell_merkur_init();
#if COFFEE
shell_coffee_init();
shell_file_init();
shell_coffee_init();
shell_file_init();
#endif
// get_rf_consts();
print_rf_values();
// init coap resourcen
rest_init_engine ();
#pragma GCC diagnostic ignored "-Wwrite-strings"

View file

@ -284,6 +284,7 @@ uint8_t i;
rf230_set_pan_addr(params_get_panid(),params_get_panaddr(),(uint8_t *)&addr.u8);
rf230_set_channel(params_get_channel());
rf230_set_txpower(params_get_txpower());
// rf230_set_cca_threshold(params_get_txpower());
#if NETSTACK_CONF_WITH_IPV6
PRINTA("EUI-64 MAC: %x-%x-%x-%x-%x-%x-%x-%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]);

View file

@ -276,19 +276,72 @@ params_get_txpower(void) {
}
return x;
}
uint8_t
params_get_ccathresholds(void) {
uint8_t x;
size_t size = 1;
if (settings_get(SETTINGS_KEY_TXPOWER, 0,(unsigned char*)&x, &size) == SETTINGS_STATUS_OK) {
PRINTD("<-Get tx power of %d (0=max)\n",x);
} else {
x=PARAMS_TXPOWER;
if (settings_add_uint8(SETTINGS_KEY_TXPOWER,x)==SETTINGS_STATUS_OK) {
PRINTD("->Set EEPROM tx power of %d (0=max)\n",x);
}
}
return x;
}
settings_status_t
params_save_panid(void) {
radio_value_t value;
size_t size = 2;
settings_status_t rx=SETTINGS_STATUS_OK;
if(NETSTACK_RADIO.get_value(RADIO_PARAM_PAN_ID, &value) == RADIO_RESULT_OK) {
printf("%d\n", value);
if(settings_set_uint16(SETTINGS_KEY_PAN_ID, value) != SETTINGS_STATUS_OK) {
printf("settings-panid: `save` failed: \n");
rx = SETTINGS_STATUS_FAILURE;
}
} else {
rx = SETTINGS_STATUS_FAILURE;
}
return rx;
}
settings_status_t
params_save_channel(void) {
radio_value_t value;
settings_status_t x=SETTINGS_STATUS_OK;
settings_status_t rx=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;
printf("settings-channel: `save` failed: \n");
rx = SETTINGS_STATUS_FAILURE;
}
} else {
rx = SETTINGS_STATUS_FAILURE;
}
return x;
return rx;
}
settings_status_t
params_save_txpower(void) {
radio_value_t value;
settings_status_t rx=SETTINGS_STATUS_OK;
if(NETSTACK_RADIO.get_value(RADIO_PARAM_TXPOWER, &value) == RADIO_RESULT_OK) {
printf("%d\n", value);
if(settings_set_uint8(SETTINGS_KEY_TXPOWER, value) != SETTINGS_STATUS_OK) {
printf("settings-txpower: `save` failed: \n");
rx = SETTINGS_STATUS_FAILURE;
}
} else {
rx = SETTINGS_STATUS_FAILURE;
}
return rx;
}
#endif /* CONTIKI_CONF_SETTINGS_MANAGER */

View file

@ -59,6 +59,16 @@ extern uint8_t eemem_domain_name[30];
#else
#define PARAMS_NODEID 0
#endif
#ifdef CHANNEL_802_15_4
#define PARAMS_CHANNEL CHANNEL_802_15_4
#else
#define PARAMS_CHANNEL 26
#endif
#ifdef IEEE802154_PANID
#define PARAMS_PANID IEEE802154_PANID
#else
#define PARAMS_PANID 0xABCD
#endif
#ifdef IEEE802154_PANADDR
#define PARAMS_PANADDR IEEE802154_PANADDR
#else
@ -90,8 +100,8 @@ uint8_t params_get_eui64(uint8_t *eui64);
/* Hard coded program flash parameters */
#define params_get_servername(...)
#define params_get_nodeid(...) PARAMS_NODEID
#define params_get_channel(...) CHANNEL_802_15_4
#define params_get_panid(...) IEEE802154_PANID
#define params_get_channel(...) PARAMS_CHANNEL
#define params_get_panid(...) PARAMS_PANID
#define params_get_panaddr(...) PARAMS_PANADDR
#define params_get_txpower(...) PARAMS_TXPOWER
#else
@ -101,7 +111,11 @@ 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_nodeid(void);
settings_status_t params_save_channel(void);
settings_status_t params_save_panid(void);
settings_status_t params_save_panaddr(void);
settings_status_t params_save_txpower(void);
#endif
#endif /* PARAMS_H_ */