Skip to content

Commit

Permalink
Add support for the GET_FLOW_CONTROL_TYPE XNCP command
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Oct 15, 2024
1 parent 087a96a commit 0084b8e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
7 changes: 6 additions & 1 deletion bellows/ezsp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from bellows.exception import EzspError, InvalidCommandError
from bellows.ezsp import xncp
from bellows.ezsp.config import DEFAULT_CONFIG, RuntimeConfig, ValueConfig
from bellows.ezsp.xncp import FirmwareFeatures
from bellows.ezsp.xncp import FirmwareFeatures, FlowControlType
import bellows.types as t
import bellows.uart

Expand Down Expand Up @@ -709,3 +709,8 @@ async def xncp_get_build_string(self) -> bytes:
"""Get build string."""
rsp = await self.send_xncp_frame(xncp.GetBuildStringReq())
return rsp.build_string.decode("utf-8")

async def xncp_get_flow_control_type(self) -> FlowControlType:
"""Get flow control type."""
rsp = await self.send_xncp_frame(xncp.GetFlowControlTypeReq())
return rsp.flow_control_type
20 changes: 20 additions & 0 deletions bellows/ezsp/xncp.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ class XncpCommandId(t.enum16):
SET_SOURCE_ROUTE_REQ = 0x0001
GET_MFG_TOKEN_OVERRIDE_REQ = 0x0002
GET_BUILD_STRING_REQ = 0x0003
GET_FLOW_CONTROL_TYPE_REQ = 0x0004

GET_SUPPORTED_FEATURES_RSP = GET_SUPPORTED_FEATURES_REQ | 0x8000
SET_SOURCE_ROUTE_RSP = SET_SOURCE_ROUTE_REQ | 0x8000
GET_MFG_TOKEN_OVERRIDE_RSP = GET_MFG_TOKEN_OVERRIDE_REQ | 0x8000
GET_BUILD_STRING_RSP = GET_BUILD_STRING_REQ | 0x8000
GET_FLOW_CONTROL_TYPE_RSP = GET_FLOW_CONTROL_TYPE_REQ | 0x8000

UNKNOWN = 0xFFFF

Expand Down Expand Up @@ -104,11 +106,19 @@ class FirmwareFeatures(t.bitmap32):
# The firmware contains a free-form build string
BUILD_STRING = 1 << 3

# The flow control type (software or hardware) can be queried
FLOW_CONTROL_TYPE = 1 << 4


class XncpCommandPayload(t.Struct):
pass


class FlowControlType(t.enum8):
Software = 0x00
Hardware = 0x01


@register_command(XncpCommandId.GET_SUPPORTED_FEATURES_REQ)
class GetSupportedFeaturesReq(XncpCommandPayload):
pass
Expand Down Expand Up @@ -148,3 +158,13 @@ class GetBuildStringReq(XncpCommandPayload):
@register_command(XncpCommandId.GET_BUILD_STRING_RSP)
class GetBuildStringRsp(XncpCommandPayload):
build_string: Bytes


@register_command(XncpCommandId.GET_FLOW_CONTROL_TYPE_REQ)
class GetFlowControlTypeReq(XncpCommandPayload):
pass


@register_command(XncpCommandId.GET_FLOW_CONTROL_TYPE_RSP)
class GetFlowControlTypeRsp(XncpCommandPayload):
flow_control_type: FlowControlType
15 changes: 14 additions & 1 deletion bellows/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
CONF_USE_THREAD,
CONFIG_SCHEMA,
)
from bellows.exception import ControllerError, EzspError, StackAlreadyRunning
from bellows.exception import (
ControllerError,
EzspError,
InvalidCommandError,
StackAlreadyRunning,
)
import bellows.ezsp
from bellows.ezsp.xncp import FirmwareFeatures
import bellows.multicast
Expand Down Expand Up @@ -295,6 +300,11 @@ async def load_network_info(self, *, load_devices=False) -> None:
can_burn_userdata_custom_eui64 = await ezsp.can_burn_userdata_custom_eui64()
can_rewrite_custom_eui64 = await ezsp.can_rewrite_custom_eui64()

try:
flow_control = await self._ezsp.xncp_get_flow_control_type()
except InvalidCommandError:
flow_control = None

self.state.network_info = zigpy.state.NetworkInfo(
source=f"bellows@{LIB_VERSION}",
extended_pan_id=zigpy.types.ExtendedPanId(nwk_params.extendedPanId),
Expand All @@ -315,6 +325,9 @@ async def load_network_info(self, *, load_devices=False) -> None:
"stack_version": ezsp.ezsp_version,
"can_burn_userdata_custom_eui64": can_burn_userdata_custom_eui64,
"can_rewrite_custom_eui64": can_rewrite_custom_eui64,
"flow_control": (
flow_control.name.lower() if flow_control is not None else None
),
}
},
)
Expand Down

0 comments on commit 0084b8e

Please sign in to comment.