Skip to content

Commit 581b40a

Browse files
committed
modules: storage: Include network data type
Fix bug where network data type was not correctly included because wron Kconfig option was used in ifdef. Signed-off-by: Jan Tore Guggedal <jantore.guggedal@nordicsemi.no>
1 parent 6bae1af commit 581b40a

6 files changed

Lines changed: 264 additions & 10 deletions

File tree

app/src/modules/storage/storage_data_types.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "storage.h"
1111
#include "storage_data_types.h"
12+
#include "network.h"
1213

1314
#ifdef CONFIG_APP_POWER
1415
#include "power.h"
@@ -22,8 +23,6 @@
2223
#include "location.h"
2324
#endif
2425

25-
#include "network.h"
26-
2726
/**
2827
* @brief Register all enabled data types with the storage module
2928
*

tests/module/storage/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ zephyr_include_directories(../../../app/src/modules/storage)
2626
zephyr_include_directories(../../../app/src/modules/storage/backends)
2727
zephyr_include_directories(../../../app/src/common)
2828
zephyr_include_directories(../../../app/src/modules/power)
29+
zephyr_include_directories(../../../app/src/modules/network)
2930
zephyr_include_directories(../../../app/src/modules/environmental)
3031
zephyr_include_directories(../../../app/src/modules/location)
3132
zephyr_include_directories(${ZEPHYR_BASE}/../nrfxlib/nrf_modem/include)
@@ -40,7 +41,7 @@ zephyr_compile_definitions(UNITY_INCLUDE_DOUBLE)
4041
# Options that cannot be passed through Kconfig fragments
4142
target_compile_definitions(app PRIVATE
4243
-DCONFIG_APP_STORAGE_INITIAL_MODE_BUFFER=1
43-
-DCONFIG_APP_STORAGE_MAX_TYPES=3
44+
-DCONFIG_APP_STORAGE_MAX_TYPES=4
4445
-DCONFIG_APP_STORAGE_MAX_RECORDS_PER_TYPE=100
4546
-DCONFIG_APP_STORAGE_MESSAGE_QUEUE_SIZE=10
4647
-DCONFIG_APP_STORAGE_THREAD_STACK_SIZE=2048
@@ -55,4 +56,5 @@ target_compile_definitions(app PRIVATE
5556
-DCONFIG_LOCATION_METHOD_CELLULAR=1
5657
-DCONFIG_LOCATION_METHOD_WIFI=1
5758
-DCONFIG_LOCATION_METHODS_LIST_SIZE=3
59+
-DCONFIG_LTE_LC_CONN_EVAL_MODULE=1
5860
)

tests/module/storage/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ CONFIG_ZBUS_OBSERVER_NAME=y
1212
CONFIG_ZBUS_CHANNEL_NAME=y
1313
CONFIG_ZBUS_MSG_SUBSCRIBER=y
1414
CONFIG_ZBUS_RUNTIME_OBSERVERS=y
15-
# CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_POOL_SIZE=128
1615
CONFIG_CBPRINTF_FP_SUPPORT=y
1716
CONFIG_HEAP_MEM_POOL_SIZE=80000
1817

tests/module/storage/src/storage_module_test.c

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <unity.h>
1313
#include <zephyr/fff.h>
14+
#include <zephyr/kernel.h>
1415
#include <zephyr/zbus/zbus.h>
1516
#include <zephyr/task_wdt/task_wdt.h>
1617
#include <zephyr/smf.h>
@@ -22,6 +23,7 @@
2223
#include "power.h"
2324
#include "environmental.h"
2425
#include "location.h"
26+
#include "network.h"
2527
#include "app_common.h"
2628
#include "test_samples.h"
2729

@@ -55,6 +57,14 @@ ZBUS_CHAN_DEFINE(LOCATION_CHAN,
5557
ZBUS_MSG_INIT(0)
5658
);
5759

60+
ZBUS_CHAN_DEFINE(NETWORK_CHAN,
61+
struct network_msg,
62+
NULL,
63+
NULL,
64+
ZBUS_OBSERVERS_EMPTY,
65+
ZBUS_MSG_INIT(0)
66+
);
67+
5868
/* Forward declarations */
5969
static void dummy_cb(const struct zbus_channel *chan);
6070
static void storage_chan_cb(const struct zbus_channel *chan);
@@ -65,12 +75,14 @@ ZBUS_LISTENER_DEFINE(storage_test_listener, storage_chan_cb);
6575
ZBUS_LISTENER_DEFINE(power_test_listener, dummy_cb);
6676
ZBUS_LISTENER_DEFINE(environmental_test_listener, dummy_cb);
6777
ZBUS_LISTENER_DEFINE(location_test_listener, dummy_cb);
78+
ZBUS_LISTENER_DEFINE(network_test_listener, dummy_cb);
6879

6980
ZBUS_CHAN_ADD_OBS(STORAGE_CHAN, storage_test_listener, 0);
7081
ZBUS_CHAN_ADD_OBS(STORAGE_DATA_CHAN, storage_test_listener, 0);
7182
ZBUS_CHAN_ADD_OBS(POWER_CHAN, power_test_listener, 0);
7283
ZBUS_CHAN_ADD_OBS(ENVIRONMENTAL_CHAN, environmental_test_listener, 0);
7384
ZBUS_CHAN_ADD_OBS(LOCATION_CHAN, location_test_listener, 0);
85+
ZBUS_CHAN_ADD_OBS(NETWORK_CHAN, network_test_listener, 0);
7486

7587
static double received_battery_samples[ARRAY_SIZE(battery_samples)];
7688
static uint8_t received_battery_samples_count;
@@ -81,6 +93,9 @@ static uint8_t received_env_samples_count;
8193
static struct location_msg received_location_samples[ARRAY_SIZE(location_samples)];
8294
static uint8_t received_location_samples_count;
8395

96+
static struct network_msg received_network_samples[ARRAY_SIZE(network_samples)];
97+
static uint8_t received_network_samples_count;
98+
8499
/* Variables to store received data */
85100
static struct storage_msg received_msg;
86101

@@ -106,11 +121,13 @@ static void populate_env_message(size_t i, struct environmental_msg *env_msg)
106121

107122
static void populate_all_messages(size_t i, struct power_msg *bat_msg,
108123
struct environmental_msg *env_msg,
109-
struct location_msg *loc_msg)
124+
struct location_msg *loc_msg,
125+
struct network_msg *network_msg)
110126
{
111127
bat_msg->percentage = battery_samples[i];
112128
populate_env_message(i, env_msg);
113129
*loc_msg = location_samples[i];
130+
*network_msg = network_samples[i];
114131
}
115132

116133
static void request_batch_and_assert(void)
@@ -159,8 +176,18 @@ static void storage_chan_cb(const struct zbus_channel *chan)
159176
*(const struct environmental_msg *)msg->buffer;
160177
break;
161178
case STORAGE_TYPE_LOCATION:
162-
received_location_samples[received_location_samples_count++] =
163-
*(const struct location_msg *)msg->buffer;
179+
if (received_location_samples_count < ARRAY_SIZE(received_location_samples)) {
180+
memcpy(&received_location_samples[received_location_samples_count++],
181+
msg->buffer,
182+
sizeof(struct location_msg));
183+
}
184+
break;
185+
case STORAGE_TYPE_NETWORK:
186+
if (received_network_samples_count < ARRAY_SIZE(received_network_samples)) {
187+
memcpy(&received_network_samples[received_network_samples_count++],
188+
msg->buffer,
189+
sizeof(struct network_msg));
190+
}
164191
break;
165192
default:
166193
break;
@@ -207,6 +234,13 @@ static size_t read_batch_data(size_t expected_item_count)
207234
tmp.data.LOCATION;
208235
}
209236
break;
237+
case STORAGE_TYPE_NETWORK:
238+
if (received_network_samples_count <
239+
ARRAY_SIZE(received_network_samples)) {
240+
received_network_samples[received_network_samples_count++] =
241+
tmp.data.NETWORK;
242+
}
243+
break;
210244
default:
211245
break;
212246
}
@@ -224,10 +258,12 @@ void setUp(void)
224258
received_battery_samples_count = 0;
225259
received_env_samples_count = 0;
226260
received_location_samples_count = 0;
261+
received_network_samples_count = 0;
227262

228263
memset(&received_battery_samples, 0, sizeof(received_battery_samples));
229264
memset(&received_env_samples, 0, sizeof(received_env_samples));
230265
memset(&received_location_samples, 0, sizeof(received_location_samples));
266+
memset(&received_network_samples, 0, sizeof(received_network_samples));
231267
memset(&received_msg, 0, sizeof(received_msg));
232268
}
233269

@@ -313,10 +349,11 @@ void test_receive_mixed_data(void)
313349
struct storage_msg flush_msg = {
314350
.type = STORAGE_FLUSH
315351
};
352+
struct network_msg network_msg = { .type = NETWORK_QUALITY_SAMPLE_RESPONSE };
316353
const uint8_t num_samples = CONFIG_APP_STORAGE_MAX_RECORDS_PER_TYPE;
317354

318355
for (size_t i = 0; i < num_samples; i++) {
319-
populate_all_messages(i, &bat_msg, &env_msg, &loc_msg);
356+
populate_all_messages(i, &bat_msg, &env_msg, &loc_msg, &network_msg);
320357

321358
/* Store battery data */
322359
publish_and_assert(&POWER_CHAN, &bat_msg);
@@ -326,6 +363,9 @@ void test_receive_mixed_data(void)
326363

327364
/* Store location data */
328365
publish_and_assert(&LOCATION_CHAN, &loc_msg);
366+
367+
/* Store network data */
368+
publish_and_assert(&NETWORK_CHAN, &network_msg);
329369
}
330370

331371
err = zbus_chan_pub(&STORAGE_CHAN, &flush_msg, K_SECONDS(1));
@@ -560,10 +600,11 @@ void test_storage_batch_request_mixed_data(void)
560600
struct power_msg bat_msg = { .type = POWER_BATTERY_PERCENTAGE_SAMPLE_RESPONSE };
561601
struct environmental_msg env_msg = { .type = ENVIRONMENTAL_SENSOR_SAMPLE_RESPONSE };
562602
struct location_msg loc_msg = { .type = LOCATION_GNSS_DATA };
603+
struct network_msg network_msg = { .type = NETWORK_QUALITY_SAMPLE_RESPONSE };
563604
struct storage_msg batch_msg = { .type = STORAGE_BATCH_REQUEST, .session_id = 0x12345678 };
564605
struct storage_msg clear_msg = { .type = STORAGE_CLEAR };
565606
const uint8_t num_samples = 30;
566-
const uint8_t data_types_count = 3;
607+
const uint8_t data_types_count = 4;
567608
uint8_t total_samples_expected = num_samples * data_types_count;
568609
uint8_t total_samples_received = 0;
569610
uint8_t total_battery_received = 0;
@@ -576,7 +617,7 @@ void test_storage_batch_request_mixed_data(void)
576617
k_sleep(K_SECONDS(1));
577618

578619
for (size_t i = 0; i < num_samples; i++) {
579-
populate_all_messages(i, &bat_msg, &env_msg, &loc_msg);
620+
populate_all_messages(i, &bat_msg, &env_msg, &loc_msg, &network_msg);
580621

581622
/* Store battery data */
582623
publish_and_assert(&POWER_CHAN, &bat_msg);
@@ -586,6 +627,9 @@ void test_storage_batch_request_mixed_data(void)
586627

587628
/* Store location data */
588629
publish_and_assert(&LOCATION_CHAN, &loc_msg);
630+
631+
/* Store network data */
632+
publish_and_assert(&NETWORK_CHAN, &network_msg);
589633
}
590634

591635
k_sleep(K_SECONDS(10));

0 commit comments

Comments
 (0)