Skip to content

Commit

Permalink
Merge pull request #35 from JPHutchins/feature/more-groups
Browse files Browse the repository at this point in the history
Feature/more groups
  • Loading branch information
JPHutchins authored Sep 21, 2024
2 parents aed28e6 + 6ade167 commit d8d0635
Show file tree
Hide file tree
Showing 7 changed files with 596 additions and 1 deletion.
18 changes: 17 additions & 1 deletion smp/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ class ImageManagement(IntEnum):
CORELOAD = 4
ERASE = 5

@unique
class StatisticsManagement(IntEnum):
GROUP_DATA = 0
LIST_OF_GROUPS = 1

@unique
class SettingsManagement(IntEnum):
READ_WRITE_SETTING = 0
DELETE_SETTING = 1
COMMIT_SETTINGS = 2
LOAD_SAVE_SETTINGS = 3

@unique
class ShellManagement(IntEnum):
EXECUTE = 0
Expand All @@ -44,6 +56,10 @@ class FileManagement(IntEnum):
SUPPORTED_FILE_HASH_CHECKSUM_TYPES = 3
FILE_CLOSE = 4

@unique
class ZephyrManagement(IntEnum):
ERASE_STORAGE = 0

@unique
class Intercreate(IntEnum):
UPLOAD = 1
Expand All @@ -64,7 +80,7 @@ class GroupId(IntEnum):
TEST_CRASH = 7
FILE_MANAGEMENT = 8
SHELL_MANAGEMENT = 9
ZEPHYR = 63
ZEPHYR_MANAGEMENT = 63


class UserGroupId(IntEnum):
Expand Down
162 changes: 162 additions & 0 deletions smp/settings_management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
"""The Simple Management Protocol (SMP) Settings Management group."""

from __future__ import annotations

from enum import IntEnum, unique

import smp.error as smperr
import smp.header as smphdr
import smp.message as smpmsg


class ReadSettingRequest(smpmsg.ReadRequest):
"""Read setting."""

_GROUP_ID = smphdr.GroupId.SETTINGS_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.SettingsManagement.READ_WRITE_SETTING

name: str
"""The name of the setting to read."""

max_size: int | None = None
"""The maximum size of the data to read."""


class ReadSettingResponse(smpmsg.ReadResponse):
"""Read setting success response."""

_GROUP_ID = smphdr.GroupId.SETTINGS_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.SettingsManagement.READ_WRITE_SETTING

val: bytes
"""Binary string of the returned data.
Note that the underlying data type cannot be specified through this and must
be known by the client.
"""

max_size: int | None = None
"""The SMP server supports a smaller size than requested.
Will be set if the maximum supported data size is smaller than the maximum
requested data size, and contains the maximum data size which the device
supports, equivalent to `CONFIG_MCUMGR_GRP_SETTINGS_NAME_LEN`.
"""


class WriteSettingRequest(smpmsg.WriteRequest):
"""Write setting."""

_GROUP_ID = smphdr.GroupId.SETTINGS_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.SettingsManagement.READ_WRITE_SETTING

name: str
"""The name of the setting to write."""

val: bytes
"""Binary data to write."""


class WriteSettingResponse(smpmsg.WriteResponse):
"""Write setting success response."""

_GROUP_ID = smphdr.GroupId.SETTINGS_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.SettingsManagement.READ_WRITE_SETTING


class DeleteSettingRequest(smpmsg.WriteRequest):
"""Delete setting."""

_GROUP_ID = smphdr.GroupId.SETTINGS_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.SettingsManagement.DELETE_SETTING

name: str
"""The name of the setting to delete."""


class DeleteSettingResponse(smpmsg.WriteResponse):
"""Delete setting success response."""

_GROUP_ID = smphdr.GroupId.SETTINGS_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.SettingsManagement.DELETE_SETTING


class CommitSettingsRequest(smpmsg.WriteRequest):
"""Commit pending settings.
Commit settings command allows committing all settings that have been set
but not yet applied on a device.
"""

_GROUP_ID = smphdr.GroupId.SETTINGS_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.SettingsManagement.COMMIT_SETTINGS


class CommitSettingsResponse(smpmsg.WriteResponse):
"""Commit pending settings success response."""

_GROUP_ID = smphdr.GroupId.SETTINGS_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.SettingsManagement.COMMIT_SETTINGS


class LoadSettingsRequest(smpmsg.ReadRequest):
"""Load settings from persistent storage."""

_GROUP_ID = smphdr.GroupId.SETTINGS_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.SettingsManagement.LOAD_SAVE_SETTINGS


class LoadSettingsResponse(smpmsg.ReadResponse):
"""Load settings from persistent storage success response."""

_GROUP_ID = smphdr.GroupId.SETTINGS_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.SettingsManagement.LOAD_SAVE_SETTINGS


class SaveSettingsRequest(smpmsg.WriteRequest):
"""Save settings to persistent storage."""

_GROUP_ID = smphdr.GroupId.SETTINGS_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.SettingsManagement.LOAD_SAVE_SETTINGS


class SaveSettingsResponse(smpmsg.WriteResponse):
"""Save settings to persistent storage success response."""

_GROUP_ID = smphdr.GroupId.SETTINGS_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.SettingsManagement.LOAD_SAVE_SETTINGS


@unique
class SETTINGS_MGMT_ERR(IntEnum):
OK = 0
"""No error, this is implied if there is no ret value in the response."""

UNKNOWN = 1
"""Unknown error occurred."""

KEY_TOO_LONG = 2
"""The provided key name is too long to be used."""

KEY_NOT_FOUND = 3
"""The provided key name does not exist."""

READ_NOT_SUPPORTED = 4
"""The provided key name does not support being read."""

ROOT_KEY_NOT_FOUND = 5
"""The provided root key name does not exist."""

WRITE_NOT_SUPPORTED = 6
"""The provided key name does not support being written."""

DELETE_NOT_SUPPORTED = 7
"""The provided key name does not support being deleted."""


class SettingsManagementErrorV1(smperr.ErrorV1):
_GROUP_ID = smphdr.GroupId.SETTINGS_MANAGEMENT


class SettingsManagementErrorV2(smperr.ErrorV2[SETTINGS_MGMT_ERR]):
_GROUP_ID = smphdr.GroupId.SETTINGS_MANAGEMENT
65 changes: 65 additions & 0 deletions smp/statistics_management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""The Simple Management Protocol (SMP) Statistics Management group."""


from enum import IntEnum, unique
from typing import Dict, Tuple

import smp.error as smperr
import smp.header as smphdr
import smp.message as smpmsg


class GroupDataRequest(smpmsg.ReadRequest):
_GROUP_ID = smphdr.GroupId.STATISTICS_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.StatisticsManagement.GROUP_DATA

name: str


class GroupDataResponse(smpmsg.ReadResponse):
_GROUP_ID = smphdr.GroupId.STATISTICS_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.StatisticsManagement.GROUP_DATA

name: str
fields: Dict[str, int]


class ListOfGroupsRequest(smpmsg.ReadRequest):
_GROUP_ID = smphdr.GroupId.STATISTICS_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.StatisticsManagement.LIST_OF_GROUPS


class ListOfGroupsResponse(smpmsg.ReadResponse):
_GROUP_ID = smphdr.GroupId.STATISTICS_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.StatisticsManagement.LIST_OF_GROUPS

stat_list: Tuple[str, ...]


@unique
class STAT_MGMT_ERR(IntEnum):
OK = 0
"""No error, this is implied if there is no ret value in the response."""

UNKNOWN = 1
"""Unknown error occurred."""

ERR_INVALID_GROUP = 2
"""The provided statistic group name was not found."""

ERR_INVALID_STAT_NAME = 3
"""The provided statistic name was not found."""

ERR_INVALID_STAT_SIZE = 4
"""The size of the statistic cannot be handled."""

ERR_WALK_ABORTED = 5
"""Walk through of statistics was aborted."""


class StatisticsManagementErrorV1(smperr.ErrorV1):
_GROUP_ID = smphdr.GroupId.STATISTICS_MANAGEMENT


class StatisticsManagementErrorV2(smperr.ErrorV2[STAT_MGMT_ERR]):
_GROUP_ID = smphdr.GroupId.STATISTICS_MANAGEMENT
44 changes: 44 additions & 0 deletions smp/zephyr_management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""The Simple Management Protocol (SMP) Zephyr Management group."""


from enum import IntEnum, unique

import smp.error as smperr
import smp.header as smphdr
import smp.message as smpmsg


class EraseStorageRequest(smpmsg.WriteRequest):
_GROUP_ID = smphdr.GroupId.ZEPHYR_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.ZephyrManagement.ERASE_STORAGE


class EraseStorageResponse(smpmsg.WriteResponse):
_GROUP_ID = smphdr.GroupId.ZEPHYR_MANAGEMENT
_COMMAND_ID = smphdr.CommandId.ZephyrManagement.ERASE_STORAGE


@unique
class ZEPHYRBASIC_MGMT_ERR(IntEnum):
OK = 0
"""No error, this is implied if there is no ret value in the response"""

UNKNOWN = 1
"""Unknown error occurred."""

FLASH_OPEN_FAILED = 2
"""Opening of the flash area has failed."""

FLASH_CONFIG_QUERY_FAIL = 3
"""Querying the flash area parameters has failed."""

FLASH_ERASE_FAILED = 4
"""Erasing the flash area has failed."""


class ZephyrManagementErrorV1(smperr.ErrorV1):
_GROUP_ID = smphdr.GroupId.ZEPHYR_MANAGEMENT


class ZephyrManagementErrorV2(smperr.ErrorV2[ZEPHYRBASIC_MGMT_ERR]):
_GROUP_ID = smphdr.GroupId.ZEPHYR_MANAGEMENT
Loading

0 comments on commit d8d0635

Please sign in to comment.