Contiki-Inga 3.x
settings_delete.c
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 #include "contiki.h"
33 #include "contiki-lib.h"
34 #include "settings.h"
35 #include <stdio.h>
36 
37 #include "settings_delete.h"
38 
39 #define PRINTF printf
40 
41 /**
42  * Deletes settings depending on defines and terminates.
43  */
44 PROCESS(settings_delete_process, "Settings delete Process");
45 
46 //static void _do_delete(char* descr, settings_key_t key) {
47 // uint8_t ret = settings_delete(key, 0);
48 // PRINTF("[APP.settings-delete] %s delete status: %s\n", descr, ret ? "OK" : "FAILED");
49 //}
50 /*---------------------------------------------------------------------------*/
51 PROCESS_THREAD(settings_delete_process, ev, data)
52 {
53  PROCESS_BEGIN();
54 
55 #if (APP_SETTINGS_DELETE == 1)
56  // Delete all Settings if no value is defined
57 #if 1 || !defined(NODE_CONF_ID) && !defined(RADIO_CONF_PAN_ID) && !defined(RADIO_CONF_CHANNEL) && !defined(RADIO_CONF_TX_POWER) && !defined(NODE_CONF_EUI64)
58  PRINTF("Wiping settings...");
59  settings_wipe();
60  PRINTF("done.\n");
61 #else /* !defined(NODE_CONF_ID) && !defined(RADIO_CONF_PAN_ID) && !defined(RADIO_CONF_CHANNEL) && !defined(RADIO_CONF_TX_POWER) && !defined(NODE_CONF_EUI64) */
62 // NOTE: currently deleting single items is disabled as the library does not provide it!
63 // TODO: Check Roberts implementation for delete function
64 #error Settings manager does not support deleting single items yet. Try wipe instead.
65 #ifdef NODE_CONF_ID
66  PRINTF("[APP.settings-delete] node id delete status: %s\n", settings_delete(SETTINGS_KEY_PAN_ADDR, 0) == SETTINGS_STATUS_OK ? "OK" : "FAILED");
67  //_do_delete("node id", SETTINGS_KEY_PAN_ADDR);
68 #endif
69 #ifdef RADIO_CONF_PAN_ID
70  PRINTF("[APP.settings-delete] pan id delete status: %d\n", settings_delete(SETTINGS_KEY_PAN_ID, 0) == SETTINGS_STATUS_OK ? 1 : 0);
71 #endif
72 #ifdef RADIO_CONF_CHANNEL
73  PRINTF("[APP.settings-delete] channel delete status: %d\n", settings_delete(SETTINGS_KEY_CHANNEL, 0) == SETTINGS_STATUS_OK ? 1 : 0);
74 #endif
75 #ifdef RADIO_CONF_TX_POWER
76  PRINTF("[APP.settings-delete] tx power delete status: %d\n", settings_delete(SETTINGS_KEY_TXPOWER, 0) == SETTINGS_STATUS_OK ? 1 : 0);
77 #endif
78 #ifdef NODE_CONF_EUI64
79  PRINTF("[APP.settings-delete] EUI64 delete status: %d\n", settings_delete(SETTINGS_KEY_EUI64, 0) == SETTINGS_STATUS_OK ? 1 : 0);
80 #endif
81 #endif /* !defined(NODE_CONF_ID) && !defined(RADIO_CONF_PAN_ID) && !defined(RADIO_CONF_CHANNEL) && !defined(RADIO_CONF_TX_POWER) && !defined(NODE_CONF_EUI64) */
82 
83 #endif /* (APP_SETTINGS_DELETE == 1) */
84 
85  PROCESS_END();
86 }