add radio functions for settings radio parameter

This commit is contained in:
Harald Pichler 2017-09-08 10:39:40 +02:00
parent df282f348c
commit 07c21e6e7d
4 changed files with 95 additions and 5 deletions

View file

@ -182,7 +182,7 @@ typedef unsigned short uip_stats_t;
#define NETSTACK_CONF_FRAMER framer_802154
#define NETSTACK_CONF_RADIO rf230_driver
/* CCA theshold energy -91 to -61 dBm (default -77). Set this smaller than the $ */
#define RF230_CONF_CCA_THRES -90
#define RF230_CONF_CCA_THRES -77
/* AUTOACK receive mode gives better rssi measurements, even if ACK is never requested */
#define RF230_CONF_AUTOACK 1
/* Request 802.15.4 ACK on all packets sent (else autoretry). This is primarily for testing. */
@ -255,7 +255,7 @@ typedef unsigned short uip_stats_t;
/* Long csma backoffs will compromise radio cycling; set to 0 for 1 csma */
#define RF230_CONF_CSMA_RETRIES 0
/* CCA theshold energy -91 to -61 dBm (default -77). Set this smaller than the $ */
#define RF230_CONF_CCA_THRES -90
#define RF230_CONF_CCA_THRES -77
#define SICSLOWPAN_CONF_FRAG 1
#define SICSLOWPAN_CONF_MAXAGE 3
/* 211 bytes per queue buffer. Contikimac burst mode needs 15 for a 1280 byte MTU */

View file

@ -190,7 +190,14 @@ void initialize(void)
/* Redirect stdout */
rs232_redirect_stdout(RS232_PORT_0);
#if 0
/* Do it my way... */
//UBRR0L = 8; UBRR0H = 0; UCSR0A = (0 << U2X0); // 115.2k err=-3.5%
//UBRR0L = 16; UBRR0H = 0; UCSR0A = (1 << U2X0); // 115.2k 2.1%
//UBRR0L = 3; UBRR0H = 0; UCSR0A = (1 << U2X0); // 500k 0%
#endif
rs232_set_input(RS232_PORT_0, serial_line_input_byte);
clock_init();
if(MCUSR & (1<<PORF )) PRINTD("Power-on reset.\n");
@ -276,6 +283,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]);
@ -312,7 +320,7 @@ uint8_t i;
#endif
process_start(&sensors_process, NULL);
serial_line_init();
/* Autostart other processes */
autostart_start(autostart_processes);

View file

@ -276,4 +276,71 @@ 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;
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 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-channel: `save` failed: \n");
rx = SETTINGS_STATUS_FAILURE;
}
} else {
rx = SETTINGS_STATUS_FAILURE;
}
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,6 +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_ */