Skip to content

Commit 1bef075

Browse files
authored
Merge pull request #364 from eduazocar/feature/storage_sc
firmware/sys/shell_extended: Added `stg` commands functions and `se_*` fixes
2 parents 73b9a25 + 1ddc0fb commit 1bef075

10 files changed

Lines changed: 111 additions & 26 deletions

File tree

examples/shell_extended/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
rsource "../../firmware/sys/Kconfig"
1+
rsource "../../firmware/Kconfig.debug"

examples/shell_extended/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ include ../Makefile.common
44

55
# Include the shell extended module, shell and shell commands modules
66
# will be implicitly included.
7+
USEMODULE += shell_commands
78
USEMODULE += shell_extended
9+
# USEMODULE+= border_router
810

911
# Include desired modules where shell extended is enabled.
12+
USEMODULE += radio
1013
USEMODULE += uniqueid
1114
USEMODULE += net_tools
15+
USEMODULE += storage
1216

1317
include $(RIOTBASE)/Makefile.include

firmware/default_params.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ typedef struct {
6363
uint16_t freq;
6464
} settings_ifaces_t;
6565

66-
#define IF_KEY ("IFKEY")
66+
#define IF_KEY (uint8_t*)("IFKEY")
6767

6868
/**
6969
* @name storage address this address will be the storage keys

firmware/sys/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2+
rsource "../../firmware/Kconfig.debug"
3+
14
menu "System"
25
rsource "uniqueid/Kconfig"
36
rsource "serialization/Kconfig"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
USEMODULE_INCLUDES_shell_extended := $(LAST_MAKEFILEDIR)/include
22
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_shell_extended)
3+
ifneq (,$(filter storage,$(USEMODULE)))
4+
USEMODULE_INCLUDES += $(RIOTBASE)/../firmware
5+
endif

firmware/sys/shell_extended/se_net_tools.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
/**
17-
* @brief Extends the shell functionality for uniqueid
17+
* @brief Extends the shell functionality for net_tools
1818
* @author Luis A. Ruiz <luisan00@hotmail.com>
1919
* @author Eduardo Azócar <eduazocarv@gmail.com>
2020
*/
@@ -46,11 +46,11 @@ void net_tools_usage(void) {
4646
int net_tools_cmd(int argc, char **argv) {
4747
(void)argc;
4848
(void)argv;
49-
50-
if ((strcmp(argv[1], "help") == 0)) {
49+
if ((argc < 3) || (argc > 6) || (strcmp(argv[1], "help") == 0)) {
5150
net_tools_usage();
5251
return 0;
5352
}
53+
5454
if ((strcmp(argv[2], "add") == 0)) {
5555
int if_idx = atoi(argv[1]);
5656
char ip[40] = "";
@@ -62,13 +62,16 @@ int net_tools_cmd(int argc, char **argv) {
6262
}
6363
#if MODULE_UNIQUEID
6464
if (strcmp(argv[3], "ipuid") == 0) {
65+
if (argc < 6) {
66+
net_tools_usage();
67+
return -1;
68+
}
6569
check_inp_addr(argv[4], &addr, &prefix);
6670
if ((strcmp(argv[5], "static") == 0)) {
6771
set_ipv6_by_uid(if_idx, &addr, prefix, UNIQUEID_STATIC_MODE);
6872
DEBUG("ipv6 address: %s\n", ipv6_addr_to_str(ip, &addr, sizeof(ip)));
6973
return 0;
70-
}
71-
if ((strcmp(argv[5], "random") == 0)) {
74+
} else if ((strcmp(argv[5], "random") == 0)) {
7275
set_ipv6_by_uid(if_idx, &addr, prefix, UNIQUEID_RANDOM_MODE);
7376
DEBUG("ipv6 address: %s\n", ipv6_addr_to_str(ip, &addr, sizeof(ip)));
7477
return 0;
@@ -91,14 +94,10 @@ int net_tools_cmd(int argc, char **argv) {
9194
}
9295
show_iface_info(if_idx);
9396
return 0;
94-
}
95-
96-
if ((argc < 5) || (argc > 5)) {
97-
puts("net-tools command needs at least one argument");
97+
} else {
9898
net_tools_usage();
99-
return 1;
99+
return 0;
100100
}
101-
return 0;
102101
}
103102

104103
void show_iface_info(kernel_pid_t iface_idx) {

firmware/sys/shell_extended/se_storage.c

Lines changed: 86 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,120 @@
1414
* limitations under the License.
1515
*/
1616
/**
17-
* @brief Extends the shell functionality for uniqueid
17+
* @brief Extends the shell functionality for storage
1818
* @author Luis A. Ruiz <luisan00@hotmail.com>
1919
* @author Eduardo Azócar <eduazocarv@gmail.com>
2020
*/
2121

2222
#include <stdio.h>
2323
#include <string.h>
2424
#include "storage.h"
25-
26-
#if MODULE_RADIO
25+
#include "storage_register.h"
26+
#include "default_params.h"
2727
#include "radio.h"
28-
#endif
2928
#if MODULE_RPL_PROTOCOL
3029
#include "rpl_protocol.h"
3130
#endif
31+
int8_t stg_save_if_settings(void);
32+
int8_t stg_del_if_settings(void);
33+
int8_t stg_load_if_settings(void);
34+
void build_if_settings(settings_ifaces_t *if_sets, uint8_t num_ifaces);
3235

3336
void storage_usage(void) {
3437
puts("Storage tool");
3538
puts("Usage: stg [save|load|show]");
39+
puts("\t\t\t->[iface]");
40+
printf("%" PRIu16 " Bytes. \n", sizeof(settings_ifaces_t));
3641
puts("");
3742
}
3843

3944
int storage_cmd(int argc, char **argv) {
4045
(void)argc;
4146
(void)argv;
42-
4347
if ((argc < 2) || (argc > 2) || (strcmp(argv[1], "help") == 0)) {
44-
void storage_usage(void);
48+
storage_usage();
4549
return 0;
4650
}
47-
4851
if (strcmp(argv[1], "save") == 0) {
49-
puts("ToDo: Save all firmware params in mtd storage");
52+
stg_save_if_settings();
5053
} else if (strcmp(argv[1], "load") == 0) {
51-
puts("Todo: Load firmware params from mtd storage and are processed");
54+
stg_load_if_settings();
5255
} else if (strcmp(argv[1], "show") == 0) {
5356
puts("Todo: show all firmware params saved in mtd storage");
57+
} else if (strcmp(argv[1], "del") == 0) {
58+
stg_del_if_settings();
5459
}
55-
5660
return 0;
5761
}
62+
63+
int8_t stg_save_if_settings(void) {
64+
int8_t ret = 0;
65+
uint8_t ifaces = gnrc_netif_numof();
66+
settings_ifaces_t settings_if[ifaces];
67+
build_if_settings(settings_if, ifaces);
68+
mtd_reg_del(IF_KEY, sizeof(settings_if));
69+
ret = mtd_save_reg(settings_if, IF_KEY, sizeof(settings_if));
70+
if (ret < 0) {
71+
printf("Failed saving/overwriting the register\n");
72+
return ret;
73+
}
74+
return ret;
75+
}
76+
77+
int8_t stg_del_if_settings(void) {
78+
int8_t ret = 0;
79+
uint8_t ifaces = gnrc_netif_numof();
80+
ret = mtd_reg_del(IF_KEY, ifaces * sizeof(settings_ifaces_t));
81+
return ret;
82+
}
83+
84+
int8_t stg_load_if_settings(void) {
85+
int8_t ret = 0;
86+
uint8_t ifaces = gnrc_netif_numof();
87+
settings_ifaces_t settings_if[ifaces];
88+
ret = mtd_load_reg(settings_if, IF_KEY, sizeof(settings_if));
89+
if (ret < 0) {
90+
printf("The register doesn't exists, first you need to save the interface info\n");
91+
return ret;
92+
}
93+
for (size_t i = 0; i < ifaces; i++) {
94+
printf("Netif_id: %" PRId16 "\n", settings_if[i].id);
95+
if (settings_if[i].type == 1) {
96+
if (set_netopt_tx_power(settings_if[i].tx_power) < 0) {
97+
printf("Failed: loading radio settings [tx_power]\n");
98+
}
99+
if (set_netopt_channel(settings_if[i].channel) < 0) {
100+
printf("Failed: loading radio settings [channel]\n");
101+
}
102+
printf("Type: Radio iface\n");
103+
printf("id: %" PRId16 "\n", settings_if[i].id);
104+
printf("Tx power %" PRId16 "\n", settings_if[i].tx_power);
105+
printf("Channel: %" PRIu16 "\n", settings_if[i].channel);
106+
}
107+
}
108+
return ret;
109+
}
110+
111+
void build_if_settings(settings_ifaces_t *if_sets, uint8_t num_ifaces) {
112+
gnrc_netif_t *netif = NULL;
113+
for (uint8_t i = 0; i < num_ifaces; i++) {
114+
netif = gnrc_netif_iter(netif);
115+
if (netif->ops != NULL) {
116+
if_sets[i].id = netif->pid;
117+
}
118+
switch (netif->device_type) {
119+
case NETDEV_TYPE_IEEE802154:
120+
if_sets[i].type = 1;
121+
if (get_netopt_tx_power(&if_sets[i].tx_power) < 0) {
122+
puts("Err Loading Tx_power");
123+
}
124+
if (get_netopt_channel(&if_sets[i].channel) < 0) {
125+
puts("Err Loading ");
126+
}
127+
break;
128+
default:
129+
if_sets[i].type = 0;
130+
break;
131+
}
132+
}
133+
}

firmware/sys/storage/storage_internal.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "mtd.h"
2828
#include "storage_internal.h"
2929

30-
3130
#if (CONFIG_DEBUG_STORAGE) || (DOXYGEN)
3231
/**
3332
* @brief KCONFIG_PARAMETER TO SET DEBUG MODE
@@ -146,4 +145,4 @@ int8_t mtd_dump(void) {
146145
return -1;
147146
}
148147
return 0;
149-
}
148+
}

tests/driver_radio/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void test_set_netopt_tx_power(void) {
3939

4040
void test_get_netopt_tx_power(void) {
4141
int16_t txpower=0;
42+
xtimer_sleep(5);
4243
int8_t err = get_netopt_tx_power(&txpower);
4344
printf("Tx Power: %"PRId16"\n", txpower);
4445
TEST_ASSERT_EQUAL_INT(0, err);

tests/net_net_tools/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void test_rm_global_addr(void) {
7777
TEST_ASSERT_EQUAL_INT(0, err);
7878
}
7979

80-
test_set_ipv6(void) {
80+
void test_set_ipv6(void) {
8181
ipv6_addr_t ip;
8282
int err = 0;
8383
uint8_t iface = get_wired_iface();

0 commit comments

Comments
 (0)