|
| 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