Contiki-Inga 3.x
settings_set.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, TU Braunschweig
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  */
31 
32 /**
33  * \file
34  * Settings Set Application
35  *
36  * \author
37  * Robert Hartung
38  * Enrico Joerns <e.joerns@tu-bs.de>
39  */
40 
41 #include "contiki.h"
42 #include "contiki-lib.h"
43 #include "lib/settings.h"
44 #include <stdio.h>
45 
46 #define PRINTF printf
47 #define PRINTD printf
48 
49 #include "settings_set.h"
50 
51 /**
52  * Sets settings depending on defines and terminates.
53  */
54 PROCESS(settings_set_process, "Settings Set Process");
55 
56 /*---------------------------------------------------------------------------*/
57 PROCESS_THREAD(settings_set_process, ev, data)
58 {
59  PROCESS_BEGIN();
60 #if (APP_SETTINGS_SET == 1)
61 
62 #ifdef NODE_CONF_ID
63  if (settings_set_uint16(SETTINGS_KEY_PAN_ADDR, (uint16_t) NODE_ID) == SETTINGS_STATUS_OK) {
64  uint16_t settings_nodeid = settings_get_uint16(SETTINGS_KEY_PAN_ADDR, 0);
65  PRINTF("[APP.settings_set] New PAN Addr: 0x%04X\n", settings_nodeid);
66  } else {
67  PRINTD("[APP.settings_set] Error: Failed writing NodeID to EEPROM\n");
68  }
69 #endif /* NODE_CONF_ID */
70 
71 #ifdef RADIO_CONF_PAN_ID
72  if (settings_set_uint16(SETTINGS_KEY_PAN_ID, (uint16_t) RADIO_PAN_ID) == SETTINGS_STATUS_OK) {
73  uint16_t settings_panid = settings_get_uint16(SETTINGS_KEY_PAN_ID, 0);
74  PRINTF("[APP.settings_set] New PAN ID: 0x%04X\n", settings_panid);
75  } else {
76  PRINTD("[APP.settings_set] Error: Failed writing PanID to EEPROM\n");
77  }
78 #endif /* RADIO_CONF_PAN_ID */
79 
80 #ifdef RADIO_CONF_CHANNEL
81  if (settings_set_uint8(SETTINGS_KEY_CHANNEL, (uint8_t) RADIO_CHANNEL) == SETTINGS_STATUS_OK) {
82  uint8_t settings_channel = settings_get_uint8(SETTINGS_KEY_CHANNEL, 0);
83  PRINTF("[APP.settings_set] New channel: 0x%02X\n", settings_channel);
84  } else {
85  PRINTD("[APP.settings_set] Error: Failed writing channel to EEPROM\n");
86  }
87 #endif /* RADIO_CONF_CHANNEL */
88 
89 #ifdef RADIO_CONF_TX_POWER
90  if (settings_set_uint8(SETTINGS_KEY_TXPOWER, (uint8_t) RADIO_TX_POWER) == SETTINGS_STATUS_OK) {
91  uint8_t settings_txpower = settings_get_uint8(SETTINGS_KEY_TXPOWER, 0);
92  PRINTF("[APP.settings_set] New TX power: 0x%02X\n", settings_txpower);
93  } else {
94  PRINTD("[APP.settings_set] Error: Failed writing TX power to EEPROM\n");
95  }
96 #endif /* RADIO_CONF_TX_POWER */
97 
98 #ifdef NODE_CONF_EUI64
99  uint8_t settings_eui64[8] = {NODE_CONF_EUI64};
100  if (settings_set(SETTINGS_KEY_EUI64, settings_eui64, 8) == SETTINGS_STATUS_OK) {
101  settings_get(SETTINGS_KEY_EUI64, 0, settings_eui64, sizeof (settings_eui64));
102  PRINTF("[APP.settings_set] New EUI64: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n\r",
103  settings_eui64[0],
104  settings_eui64[1],
105  settings_eui64[2],
106  settings_eui64[3],
107  settings_eui64[4],
108  settings_eui64[5],
109  settings_eui64[6],
110  settings_eui64[7]);
111  } else {
112  PRINTD("[APP.settings_set] Error: Failed writing EUI64 to EEPROM\n");
113  }
114 #endif /* NODE_CONF_EUI64 */
115 
116 #endif /* (SETTINGS_SET_LOAD == 1) */
117 
118  PROCESS_END();
119 }