Skip to content

Commit cb4eb97

Browse files
modules: environmental: channel def in module header
Environmental channel definition into dedicated header. Signed-off-by: Giacomo Dematteis <giacomo.dematteis@nordicsemi.no>
1 parent a5141eb commit cb4eb97

File tree

13 files changed

+93
-42
lines changed

13 files changed

+93
-42
lines changed

app/src/common/message_channel.c

-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ ZBUS_CHAN_DEFINE(TRIGGER_CHAN,
1818
ZBUS_MSG_INIT(0)
1919
);
2020

21-
ZBUS_CHAN_DEFINE(ENVIRONMENTAL_CHAN,
22-
struct environmental_msg,
23-
NULL,
24-
NULL,
25-
ZBUS_OBSERVERS_EMPTY,
26-
ZBUS_MSG_INIT(0)
27-
);
28-
2921
ZBUS_CHAN_DEFINE(ERROR_CHAN,
3022
enum error_type,
3123
NULL,

app/src/common/message_channel.h

-34
Original file line numberDiff line numberDiff line change
@@ -48,39 +48,6 @@ extern "C" {
4848
k_sleep(K_SECONDS(10)); \
4949
} while (0)
5050

51-
/** ENVIRONMENTAL MODULE */
52-
53-
enum environmental_msg_type {
54-
/* Output message types */
55-
56-
/* Response message to a request for current environmental sensor values.
57-
* The sampled values are found in the respective fields of the message structure.
58-
*/
59-
ENVIRONMENTAL_SENSOR_SAMPLE_RESPONSE = 0x1,
60-
61-
/* Input message types */
62-
63-
/* Request to sample the current environmental sensor values.
64-
* The response is sent as a ENVIRONMENTAL_SENSOR_SAMPLE_RESPONSE message.
65-
*/
66-
ENVIRONMENTAL_SENSOR_SAMPLE_REQUEST,
67-
};
68-
69-
struct environmental_msg {
70-
enum environmental_msg_type type;
71-
72-
/** Contains the current temperature in celsius. */
73-
double temperature;
74-
75-
/** Contains the current humidity in percentage. */
76-
double humidity;
77-
78-
/** Contains the current pressure in Pa. */
79-
double pressure;
80-
};
81-
82-
#define MSG_TO_ENVIRONMENTAL_MSG(_msg) (*(const struct environmental_msg *)_msg)
83-
8451
enum trigger_type {
8552
TRIGGER_POLL_SHADOW = 0x1,
8653
TRIGGER_FOTA_POLL,
@@ -124,7 +91,6 @@ ZBUS_CHAN_DECLARE(
12491
CONFIG_CHAN,
12592
ERROR_CHAN,
12693
TIME_CHAN,
127-
ENVIRONMENTAL_CHAN,
12894
TRIGGER_CHAN
12995
);
13096

app/src/modules/app/app.c

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "message_channel.h"
1616
#include "button.h"
1717
#include "network.h"
18+
#include "environmental.h"
1819

1920
#if defined(CONFIG_APP_BATTERY)
2021
#include "battery.h"

app/src/modules/cloud/cloud_module.c

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#if defined(CONFIG_APP_BATTERY)
2424
#include "battery.h"
2525
#endif /* CONFIG_APP_BATTERY */
26+
#include "environmental.h"
2627

2728
/* Register log module */
2829
LOG_MODULE_REGISTER(cloud, CONFIG_APP_CLOUD_LOG_LEVEL);

app/src/modules/environmental/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
target_sources_ifdef(CONFIG_APP_ENVIRONMENTAL app PRIVATE
88
${CMAKE_CURRENT_SOURCE_DIR}/environmental.c
99
)
10+
target_include_directories(app PRIVATE .)

app/src/modules/environmental/environmental.c

+10
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,20 @@
1515

1616
#include "message_channel.h"
1717
#include "modules_common.h"
18+
#include "environmental.h"
1819

1920
/* Register log module */
2021
LOG_MODULE_REGISTER(environmental_module, CONFIG_APP_ENVIRONMENTAL_LOG_LEVEL);
2122

23+
/* Define channels provided by this module */
24+
ZBUS_CHAN_DEFINE(ENVIRONMENTAL_CHAN,
25+
struct environmental_msg,
26+
NULL,
27+
NULL,
28+
ZBUS_OBSERVERS_EMPTY,
29+
ZBUS_MSG_INIT(0)
30+
);
31+
2232
/* Register subscriber */
2333
ZBUS_MSG_SUBSCRIBER_DEFINE(environmental);
2434

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef _ENVIRONMENTAL_H_
8+
#define _ENVIRONMENTAL_H_
9+
10+
#include <zephyr/kernel.h>
11+
#include <zephyr/zbus/zbus.h>
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
18+
/* Channels provided by this module */
19+
ZBUS_CHAN_DECLARE(
20+
ENVIRONMENTAL_CHAN
21+
);
22+
23+
enum environmental_msg_type {
24+
/* Output message types */
25+
26+
/* Response message to a request for current environmental sensor values.
27+
* The sampled values are found in the respective fields of the message structure.
28+
*/
29+
ENVIRONMENTAL_SENSOR_SAMPLE_RESPONSE = 0x1,
30+
31+
/* Input message types */
32+
33+
/* Request to sample the current environmental sensor values.
34+
* The response is sent as a ENVIRONMENTAL_SENSOR_SAMPLE_RESPONSE message.
35+
*/
36+
ENVIRONMENTAL_SENSOR_SAMPLE_REQUEST,
37+
};
38+
39+
struct environmental_msg {
40+
enum environmental_msg_type type;
41+
42+
/** Contains the current temperature in celsius. */
43+
double temperature;
44+
45+
/** Contains the current humidity in percentage. */
46+
double humidity;
47+
48+
/** Contains the current pressure in Pa. */
49+
double pressure;
50+
};
51+
52+
#define MSG_TO_ENVIRONMENTAL_MSG(_msg) (*(const struct environmental_msg *)_msg)
53+
54+
55+
#ifdef __cplusplus
56+
}
57+
#endif
58+
59+
#endif /* _ENVIRONMENTAL_H_ */

tests/module/app/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ zephyr_include_directories(../../../app/src/modules/cloud)
2828
zephyr_include_directories(../../../app/src/modules/battery)
2929
zephyr_include_directories(../../../app/src/modules/button)
3030
zephyr_include_directories(../../../app/src/modules/network)
31+
zephyr_include_directories(../../../app/src/modules/environmental)
32+
3133

3234
target_link_options(app PRIVATE --whole-archive)
3335

tests/module/app/src/main.c

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "message_channel.h"
1616
#include "battery.h"
1717
#include "network.h"
18+
#include "environmental.h"
1819

1920
#include "checks.h"
2021

@@ -47,6 +48,13 @@ ZBUS_CHAN_DEFINE(CLOUD_CHAN,
4748
ZBUS_OBSERVERS_EMPTY,
4849
ZBUS_MSG_INIT(CLOUD_DISCONNECTED)
4950
);
51+
ZBUS_CHAN_DEFINE(ENVIRONMENTAL_CHAN,
52+
struct environmental_msg,
53+
NULL,
54+
NULL,
55+
ZBUS_OBSERVERS_EMPTY,
56+
ZBUS_MSG_INIT(0)
57+
);
5058

5159
DEFINE_FFF_GLOBALS;
5260

tests/module/cloud/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ zephyr_include_directories(../../../app/src/modules/cloud)
2424
zephyr_include_directories(../../../app/src/common)
2525
zephyr_include_directories(../../../app/src/modules/battery)
2626
zephyr_include_directories(../../../app/src/modules/network)
27+
zephyr_include_directories(../../../app/src/modules/environmental)
2728
zephyr_include_directories(${NRF_DIR}/subsys/net/lib/nrf_cloud/include)
2829
zephyr_include_directories(${NRF_DIR}/../modules/lib/cjson)
2930

tests/module/cloud/src/cloud_module_test.c

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "message_channel.h"
1010
#include "battery.h"
1111
#include "network.h"
12+
#include "environmental.h"
1213
#include <zephyr/task_wdt/task_wdt.h>
1314

1415
DEFINE_FFF_GLOBALS;
@@ -28,6 +29,13 @@ ZBUS_CHAN_DEFINE(NETWORK_CHAN,
2829
ZBUS_OBSERVERS_EMPTY,
2930
ZBUS_MSG_INIT(.type = NETWORK_DISCONNECTED)
3031
);
32+
ZBUS_CHAN_DEFINE(ENVIRONMENTAL_CHAN,
33+
struct environmental_msg,
34+
NULL,
35+
NULL,
36+
ZBUS_OBSERVERS_EMPTY,
37+
ZBUS_MSG_INIT(0)
38+
);
3139

3240
FAKE_VALUE_FUNC(int, task_wdt_feed, int);
3341
FAKE_VALUE_FUNC(int, task_wdt_add, uint32_t, task_wdt_callback_t, void *);

tests/module/environmental/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ zephyr_include_directories(${ZEPHYR_BASE}/include/zephyr/)
2525
zephyr_include_directories(${ZEPHYR_BASE}/subsys/testsuite/include)
2626
zephyr_include_directories(../../../app/src/common)
2727
zephyr_include_directories(../../../app/src/modules/cloud)
28+
zephyr_include_directories(../../../app/src/modules/environmental)
2829

2930
target_link_options(app PRIVATE --whole-archive)
3031
# Options that cannot be passed through Kconfig fragments

tests/module/environmental/src/main.c

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <zephyr/logging/log.h>
1212

1313
#include "message_channel.h"
14+
#include "environmental.h"
1415

1516
DEFINE_FFF_GLOBALS;
1617

0 commit comments

Comments
 (0)