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>
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 */
5969static void dummy_cb (const struct zbus_channel * chan );
6070static void storage_chan_cb (const struct zbus_channel * chan );
@@ -65,12 +75,14 @@ ZBUS_LISTENER_DEFINE(storage_test_listener, storage_chan_cb);
6575ZBUS_LISTENER_DEFINE (power_test_listener , dummy_cb );
6676ZBUS_LISTENER_DEFINE (environmental_test_listener , dummy_cb );
6777ZBUS_LISTENER_DEFINE (location_test_listener , dummy_cb );
78+ ZBUS_LISTENER_DEFINE (network_test_listener , dummy_cb );
6879
6980ZBUS_CHAN_ADD_OBS (STORAGE_CHAN , storage_test_listener , 0 );
7081ZBUS_CHAN_ADD_OBS (STORAGE_DATA_CHAN , storage_test_listener , 0 );
7182ZBUS_CHAN_ADD_OBS (POWER_CHAN , power_test_listener , 0 );
7283ZBUS_CHAN_ADD_OBS (ENVIRONMENTAL_CHAN , environmental_test_listener , 0 );
7384ZBUS_CHAN_ADD_OBS (LOCATION_CHAN , location_test_listener , 0 );
85+ ZBUS_CHAN_ADD_OBS (NETWORK_CHAN , network_test_listener , 0 );
7486
7587static double received_battery_samples [ARRAY_SIZE (battery_samples )];
7688static uint8_t received_battery_samples_count ;
@@ -81,6 +93,9 @@ static uint8_t received_env_samples_count;
8193static struct location_msg received_location_samples [ARRAY_SIZE (location_samples )];
8294static 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 */
85100static struct storage_msg received_msg ;
86101
@@ -106,11 +121,13 @@ static void populate_env_message(size_t i, struct environmental_msg *env_msg)
106121
107122static 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
116133static 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