add rfsetings function
This commit is contained in:
parent
25d38eba2c
commit
ecdd101586
|
@ -302,6 +302,11 @@ uint8_t i;
|
|||
NETSTACK_MAC.init();
|
||||
NETSTACK_NETWORK.init();
|
||||
|
||||
if(params_get_macconf() == 1){
|
||||
NETSTACK_MAC.off(1);
|
||||
PRINTA("Switch Reciver always on\n");
|
||||
}
|
||||
|
||||
#if ANNOUNCE_BOOT
|
||||
PRINTA("%s %s, channel %u , check rate %u Hz tx power %u\n",NETSTACK_MAC.name, NETSTACK_RDC.name, rf230_get_channel(),
|
||||
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:NETSTACK_RDC.channel_check_interval()),
|
||||
|
|
|
@ -266,6 +266,7 @@ uint8_t
|
|||
params_get_txpower(void) {
|
||||
uint8_t x;
|
||||
size_t size = 1;
|
||||
PRINTD("params_get_txpower\n",x);
|
||||
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 {
|
||||
|
@ -291,6 +292,32 @@ params_get_ccathresholds(void) {
|
|||
return x;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
params_get_macconf(void) {
|
||||
uint8_t x;
|
||||
size_t size = 1;
|
||||
if (settings_get(SETTINGS_KEY_MAC_CONF, 0,(unsigned char*)&x, &size) == SETTINGS_STATUS_OK) {
|
||||
PRINTD("<-Get macconf of %d (0 -> do nothing)\n",x);
|
||||
} else {
|
||||
x=PARAMS_MACCONF;
|
||||
if (settings_add_uint8(SETTINGS_KEY_MAC_CONF,x)==SETTINGS_STATUS_OK) {
|
||||
PRINTD("->Set EEPROM macconf of %d (0 -> do nothing)\n",x);
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
settings_status_t
|
||||
params_set_macconf(radio_value_t value){
|
||||
settings_status_t rx=SETTINGS_STATUS_OK;
|
||||
PRINTD("%d\n", value);
|
||||
if(settings_set_uint8(SETTINGS_KEY_MAC_CONF, value) != SETTINGS_STATUS_OK) {
|
||||
PRINTD("settings-mac-conf: `save` failed: \n");
|
||||
rx = SETTINGS_STATUS_FAILURE;
|
||||
}
|
||||
return rx;
|
||||
}
|
||||
|
||||
settings_status_t
|
||||
params_save_panid(void) {
|
||||
radio_value_t value;
|
||||
|
@ -298,9 +325,9 @@ params_save_panid(void) {
|
|||
settings_status_t rx=SETTINGS_STATUS_OK;
|
||||
|
||||
if(NETSTACK_RADIO.get_value(RADIO_PARAM_PAN_ID, &value) == RADIO_RESULT_OK) {
|
||||
printf("%d\n", value);
|
||||
PRINTD("%04x\n", value);
|
||||
if(settings_set_uint16(SETTINGS_KEY_PAN_ID, value) != SETTINGS_STATUS_OK) {
|
||||
printf("settings-panid: `save` failed: \n");
|
||||
PRINTD("settings-panid: `save` failed: \n");
|
||||
rx = SETTINGS_STATUS_FAILURE;
|
||||
}
|
||||
} else {
|
||||
|
@ -315,9 +342,9 @@ params_save_channel(void) {
|
|||
settings_status_t rx=SETTINGS_STATUS_OK;
|
||||
|
||||
if(NETSTACK_RADIO.get_value(RADIO_PARAM_CHANNEL, &value) == RADIO_RESULT_OK) {
|
||||
printf("%d\n", value);
|
||||
PRINTD("%d\n", value);
|
||||
if(settings_set_uint8(SETTINGS_KEY_CHANNEL, value) != SETTINGS_STATUS_OK) {
|
||||
printf("settings-channel: `save` failed: \n");
|
||||
PRINTD("settings-channel: `save` failed: \n");
|
||||
rx = SETTINGS_STATUS_FAILURE;
|
||||
}
|
||||
} else {
|
||||
|
@ -332,9 +359,9 @@ params_save_txpower(void) {
|
|||
settings_status_t rx=SETTINGS_STATUS_OK;
|
||||
|
||||
if(NETSTACK_RADIO.get_value(RADIO_PARAM_TXPOWER, &value) == RADIO_RESULT_OK) {
|
||||
printf("%d\n", value);
|
||||
PRINTD("%d\n", value);
|
||||
if(settings_set_uint8(SETTINGS_KEY_TXPOWER, value) != SETTINGS_STATUS_OK) {
|
||||
printf("settings-txpower: `save` failed: \n");
|
||||
PRINTD("settings-txpower: `save` failed: \n");
|
||||
rx = SETTINGS_STATUS_FAILURE;
|
||||
}
|
||||
} else {
|
||||
|
@ -343,4 +370,71 @@ params_save_txpower(void) {
|
|||
return rx;
|
||||
}
|
||||
|
||||
settings_status_t
|
||||
params_save_macconf(void) {
|
||||
radio_value_t value;
|
||||
settings_status_t rx=SETTINGS_STATUS_OK;
|
||||
|
||||
value = params_get_macconf();
|
||||
PRINTD("%d\n", value);
|
||||
if(settings_set_uint8(SETTINGS_KEY_MAC_CONF, value) != SETTINGS_STATUS_OK) {
|
||||
PRINTD("settings-mac-conf: `save` failed: \n");
|
||||
rx = SETTINGS_STATUS_FAILURE;
|
||||
}
|
||||
return rx;
|
||||
}
|
||||
|
||||
radio_result_t
|
||||
get_param(radio_param_t param, radio_value_t *value)
|
||||
{
|
||||
radio_result_t rv;
|
||||
|
||||
rv = NETSTACK_RADIO.get_value(param, value);
|
||||
|
||||
switch(rv) {
|
||||
case RADIO_RESULT_ERROR:
|
||||
printf("Radio returned an error\n");
|
||||
break;
|
||||
case RADIO_RESULT_INVALID_VALUE:
|
||||
printf("Value %d is invalid\n", *value);
|
||||
break;
|
||||
case RADIO_RESULT_NOT_SUPPORTED:
|
||||
printf("Param %u not supported\n", param);
|
||||
break;
|
||||
case RADIO_RESULT_OK:
|
||||
break;
|
||||
default:
|
||||
printf("Unknown return value\n");
|
||||
break;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
radio_result_t
|
||||
set_param(radio_param_t param, radio_value_t value)
|
||||
{
|
||||
radio_result_t rv;
|
||||
|
||||
rv = NETSTACK_RADIO.set_value(param, value);
|
||||
|
||||
switch(rv) {
|
||||
case RADIO_RESULT_ERROR:
|
||||
printf("Radio returned an error\n");
|
||||
break;
|
||||
case RADIO_RESULT_INVALID_VALUE:
|
||||
printf("Value %d is invalid\n", value);
|
||||
break;
|
||||
case RADIO_RESULT_NOT_SUPPORTED:
|
||||
printf("Param %u not supported\n", param);
|
||||
break;
|
||||
case RADIO_RESULT_OK:
|
||||
break;
|
||||
default:
|
||||
printf("Unknown return value\n");
|
||||
break;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
#endif /* CONTIKI_CONF_SETTINGS_MANAGER */
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
*
|
||||
* Note the parameters in this file can be changed without forcing a complete rebuild.
|
||||
*/
|
||||
#include "dev/radio.h"
|
||||
|
||||
// default settings
|
||||
#define CHANNEL_802_15_4 25 // default frequency (11-26)
|
||||
|
||||
|
@ -79,6 +81,9 @@ extern uint8_t eemem_domain_name[30];
|
|||
#else
|
||||
#define PARAMS_TXPOWER 0
|
||||
#endif
|
||||
#ifdef NETSTACK_CONF_RDC
|
||||
#define PARAMS_MACCONF 0
|
||||
#endif
|
||||
#ifdef EUI64_ADDRESS
|
||||
#define PARAMS_EUI64ADDR EUI64_ADDRESS
|
||||
#else
|
||||
|
@ -104,6 +109,7 @@ uint8_t params_get_eui64(uint8_t *eui64);
|
|||
#define params_get_panid(...) PARAMS_PANID
|
||||
#define params_get_panaddr(...) PARAMS_PANADDR
|
||||
#define params_get_txpower(...) PARAMS_TXPOWER
|
||||
#define params_get_macconf(...) PARAMS_MACCONF
|
||||
#else
|
||||
/* Parameters stored in eeprom */
|
||||
uint16_t params_get_nodeid(void);
|
||||
|
@ -111,11 +117,16 @@ uint8_t params_get_channel(void);
|
|||
uint16_t params_get_panid(void);
|
||||
uint16_t params_get_panaddr(void);
|
||||
uint8_t params_get_txpower(void);
|
||||
uint8_t params_get_macconf(void);
|
||||
settings_status_t params_set_macconf(radio_value_t value);
|
||||
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);
|
||||
settings_status_t params_save_macconf(void);
|
||||
radio_result_t get_param(radio_param_t param, radio_value_t *value);
|
||||
radio_result_t set_param(radio_param_t param, radio_value_t value);
|
||||
#endif
|
||||
|
||||
#endif /* PARAMS_H_ */
|
||||
|
|
Loading…
Reference in a new issue