From 07c21e6e7d226ed84b813cb45a1e8615e4ccd85a Mon Sep 17 00:00:00 2001 From: Harald Pichler Date: Fri, 8 Sep 2017 10:39:40 +0200 Subject: [PATCH] add radio functions for settings radio parameter --- platform/osd-merkur-128/contiki-conf.h | 4 +- platform/osd-merkur-128/contiki-main.c | 10 +++- platform/osd-merkur-128/params.c | 67 ++++++++++++++++++++++++++ platform/osd-merkur-128/params.h | 19 +++++++- 4 files changed, 95 insertions(+), 5 deletions(-) diff --git a/platform/osd-merkur-128/contiki-conf.h b/platform/osd-merkur-128/contiki-conf.h index 40a9b809b..2b111057b 100644 --- a/platform/osd-merkur-128/contiki-conf.h +++ b/platform/osd-merkur-128/contiki-conf.h @@ -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 */ diff --git a/platform/osd-merkur-128/contiki-main.c b/platform/osd-merkur-128/contiki-main.c index 142d6edd7..e842a023d 100644 --- a/platform/osd-merkur-128/contiki-main.c +++ b/platform/osd-merkur-128/contiki-main.c @@ -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<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 */ diff --git a/platform/osd-merkur-128/params.h b/platform/osd-merkur-128/params.h index a0a00285e..c2ab5e147 100644 --- a/platform/osd-merkur-128/params.h +++ b/platform/osd-merkur-128/params.h @@ -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_ */