Skip to content

Commit

Permalink
mgmt: mcumgr: grp: os_mgmt: Add datetime get/set functions
Browse files Browse the repository at this point in the history
Adds datetime set and get functions which allow for setting and
getting the current time to/from the rtc alias device

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
  • Loading branch information
nordicjm committed Nov 8, 2023
1 parent ec52722 commit 23a41ee
Show file tree
Hide file tree
Showing 4 changed files with 328 additions and 21 deletions.
39 changes: 26 additions & 13 deletions include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h
Expand Up @@ -41,9 +41,17 @@ enum os_mgmt_err_code_t {

/** Query was not recognized. */
OS_MGMT_ERR_QUERY_YIELDS_NO_ANSWER,

/** RTC is not set */
OS_MGMT_ERR_RTC_NOT_SET,

/** RTC command failed */
OS_MGMT_ERR_RTC_COMMAND_FAILED,

};

/* Bitmask values used by the os info command handler. Note that the width of this variable is
/**
* Bitmask values used by the os info command handler. Note that the width of this variable is
* 32-bits, allowing 32 flags, custom user-level implementations should start at
* OS_MGMT_INFO_FORMAT_USER_CUSTOM_START and reference that directly as additional format
* specifiers might be added to this list in the future.
Expand All @@ -62,43 +70,48 @@ enum os_mgmt_info_formats {
OS_MGMT_INFO_FORMAT_USER_CUSTOM_START = BIT(9),
};

/* Structure provided in the MGMT_EVT_OP_OS_MGMT_INFO_CHECK notification callback */
/** Structure provided in the MGMT_EVT_OP_OS_MGMT_INFO_CHECK notification callback */
struct os_mgmt_info_check {
/* Input format string from the mcumgr client */
/** Input format string from the mcumgr client */
struct zcbor_string *format;
/* Bitmask of values specifying which outputs should be present */
/** Bitmask of values specifying which outputs should be present */
uint32_t *format_bitmask;
/* Number of valid format characters parsed, must be incremented by 1 for each valid
/**
* Number of valid format characters parsed, must be incremented by 1 for each valid
* character
*/
uint16_t *valid_formats;
/* Needs to be set to true if the OS name is being provided by external code */
/** Needs to be set to true if the OS name is being provided by external code */
bool *custom_os_name;
};

/* Structure provided in the MGMT_EVT_OP_OS_MGMT_INFO_APPEND notification callback */
/** Structure provided in the MGMT_EVT_OP_OS_MGMT_INFO_APPEND notification callback */
struct os_mgmt_info_append {
/* The format bitmask from the processed commands, the bits should be cleared once
/**
* The format bitmask from the processed commands, the bits should be cleared once
* processed, note that if all_format_specified is specified, the corrisponding bits here
* will not be set
*/
uint32_t *format_bitmask;
/* Will be true if the all 'a' specifier was provided */
/** Will be true if the all 'a' specifier was provided */
bool all_format_specified;
/* The output buffer which the responses should be appended to. If prior_output is true, a
/**
* The output buffer which the responses should be appended to. If prior_output is true, a
* space must be added prior to the output response
*/
uint8_t *output;
/* The current size of the output response in the output buffer, must be updated to be the
/**
* The current size of the output response in the output buffer, must be updated to be the
* size of the output response after appending data
*/
uint16_t *output_length;
/* The size of the output buffer, including null terminator character, if the output
/**
* The size of the output buffer, including null terminator character, if the output
* response would exceed this size, the function must abort and return false to return a
* memory error to the client
*/
uint16_t buffer_size;
/* If there has been prior output, must be set to true if a response has been output */
/** If there has been prior output, must be set to true if a response has been output */
bool *prior_output;
};

Expand Down
12 changes: 9 additions & 3 deletions include/zephyr/mgmt/mcumgr/mgmt/callbacks.h
Expand Up @@ -188,15 +188,21 @@ enum img_mgmt_group_events {
* MGMT event opcodes for operating system management group.
*/
enum os_mgmt_group_events {
/** Callback when a reset command has been received, data is os_mgmt_reset_data. */
/** Callback when a reset command has been received, data is os_mgmt_reset_data(). */
MGMT_EVT_OP_OS_MGMT_RESET = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 0),

/** Callback when an info command is processed, data is os_mgmt_info_check. */
/** Callback when an info command is processed, data is os_mgmt_info_check(). */
MGMT_EVT_OP_OS_MGMT_INFO_CHECK = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 1),

/** Callback when an info command needs to output data, data is os_mgmt_info_append. */
/** Callback when an info command needs to output data, data is os_mgmt_info_append(). */
MGMT_EVT_OP_OS_MGMT_INFO_APPEND = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 2),

/** Callback when a datetime get command has been received. */
MGMT_EVT_OP_OS_MGMT_DATETIME_GET = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 3),

/** Callback when a datetime set command has been received, data is struct rtc_time(). */
MGMT_EVT_OP_OS_MGMT_DATETIME_SET = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 4),

/** Used to enable all os_mgmt_group events. */
MGMT_EVT_OP_OS_MGMT_ALL = MGMT_DEF_EVT_OP_ALL(MGMT_EVT_GRP_OS),
};
Expand Down
21 changes: 21 additions & 0 deletions subsys/mgmt/mcumgr/grp/os_mgmt/Kconfig
Expand Up @@ -135,6 +135,27 @@ config MCUMGR_GRP_OS_ECHO
default y
select MCUMGR_SMP_CBOR_MIN_DECODING_LEVEL_2

config MCUMGR_GRP_OS_DATETIME
bool "Support for datetime command"
depends on RTC
depends on $(dt_alias_enabled,rtc)
select MCUMGR_SMP_CBOR_MIN_DECODING_LEVEL_2
help
Enables support for the datetime get and set functions, this allows for using the
`rtc` alias device as a timesource from which the current time can be written or read.

config MCUMGR_GRP_OS_DATETIME_MS
bool "Support millisecond field in datetime commands"
depends on MCUMGR_GRP_OS_DATETIME

config MCUMGR_GRP_OS_DATETIME_HOOK
bool "Datetime hook"
depends on MCUMGR_GRP_OS_DATETIME
depends on MCUMGR_MGMT_NOTIFICATION_HOOKS
help
Allows applications to control and get notifications of when a datetime set/get
command has been issued via an MCUmgr command.

config MCUMGR_GRP_OS_MCUMGR_PARAMS
bool "MCUMGR Parameters retrieval command"

Expand Down

0 comments on commit 23a41ee

Please sign in to comment.