Skip to content

Commit e9e59c5

Browse files
committed
Added BACnet zephyr shell for device datetime and lighting output object.
1 parent aa15a31 commit e9e59c5

File tree

4 files changed

+878
-2
lines changed

4 files changed

+878
-2
lines changed

zephyr/subsys/bacnet_shell/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ zephyr_library_sources_ifdef(CONFIG_BACNETSTACK_BACNET_SHELL
1212
)
1313

1414
zephyr_library_sources_ifdef(CONFIG_BACNETSTACK_BACNET_BASIC_SHELL
15+
bacnet_shell_datetime.c
16+
bacnet_shell_lighting_output.c
1517
bacnet_shell_objects.c
1618
bacnet_shell_packets.c
1719
bacnet_shell_uptime.c
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @file
3+
* @brief BACnet shell commands for debugging and testing date and time
4+
* @author Steve Karg <[email protected]>
5+
* @date September 2025
6+
* @copyright SPDX-License-Identifier: Apache-2.0
7+
*/
8+
#include <stdlib.h>
9+
#include <stdint.h>
10+
#include <errno.h>
11+
#include <zephyr/shell/shell.h>
12+
/* BACnet definitions */
13+
#include "bacnet/bacdef.h"
14+
#include "bacnet/bacdcode.h"
15+
#include "bacnet/bactext.h"
16+
#include "bacnet/datetime.h"
17+
18+
static void cmd_date_time(const struct shell *shell, int argc, char **argv)
19+
{
20+
BACNET_DATE bdate = { 0 };
21+
BACNET_TIME btime = { 0 };
22+
int16_t utc_offset_minutes = 0;
23+
bool dst_active = false;
24+
char date_string[40] = { 0 };
25+
char time_string[40] = { 0 };
26+
27+
if ((argc == 3) || (argc == 1)) {
28+
if (argc == 3) {
29+
/* Set new time */
30+
if (datetime_date_init_ascii(&bdate, argv[1]) &&
31+
datetime_time_init_ascii(&btime, argv[2])) {
32+
datetime_timesync(&bdate, &btime, false);
33+
} else {
34+
shell_print(shell, " date time format: YYYY/MM/DD HH:MM:SS.hh");
35+
return;
36+
}
37+
}
38+
datetime_local(&bdate, &btime, &utc_offset_minutes, &dst_active);
39+
datetime_date_to_ascii(&bdate, date_string, sizeof(date_string));
40+
datetime_time_to_ascii(&btime, time_string, sizeof(time_string));
41+
shell_print(shell, "%s %s", date_string, time_string);
42+
} else {
43+
shell_help(shell);
44+
}
45+
}
46+
47+
SHELL_SUBCMD_ADD(
48+
(bacnet), time, NULL, "BACnet Date Time Command", cmd_date_time, 1, 2);

0 commit comments

Comments
 (0)