Skip to content

Commit

Permalink
Merge pull request #95 from scop/net-mode-more
Browse files Browse the repository at this point in the history
More net mode setting improvements
  • Loading branch information
Salamek authored Dec 22, 2020
2 parents 8d445d6 + 4b4bf4f commit 89c574e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 11 deletions.
22 changes: 11 additions & 11 deletions huawei_lte_api/api/Net.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@
from huawei_lte_api.Connection import GetResponseType, SetResponseType


ALL_BANDS = '7fffffffffffffff'


class Net(ApiGroup):
def current_plmn(self) -> GetResponseType:
return self._connection.get('net/current-plmn')

def net_mode(self) -> GetResponseType:
return self._connection.get('net/net-mode')

def set_net_mode(self, lteband: str, networkband: str, networkmode: Union[NetworkModeEnum, str]) -> SetResponseType:
def set_net_mode(self, lteband: Union[str, int], networkband: Union[int, str], networkmode: Union[NetworkModeEnum, str]) -> SetResponseType:
"""
:param lteband: bitmask of per band ints or'd together, where each band N is represented as 2**(N-1), in hex
without leading '0x'. For example B1,B3,B20: hex(2**(1-1) | 2**(3-1) | 2**(20-1))[2:] = '80005'.
Use ALL_BANDS to indicate all bands. All values or combinations of them may not be supported.
:param networkband:
:param networkmode: network mode, see NetworkModeEnum; str supported for deprecated backwards compatiblity
:param lteband: bitmask of LTE band ints or'd together, where each band N is represented as 2**(N-1), as int,
or hex str without leading '0x'. For example B1,B3,B20: 2**(1-1) | 2**(3-1) | 2**(20-1) = 0x80005.
Use ALL for all or when not applicable (not 4G mode). All values or combinations of them may not be
supported.
:param networkband: bitmask of 3G network band ints or'd together, as int, or hex str without leading '0x'.
See NetworkBandEnum, use ALL for all or when not applicable (not 3G mode). All values or combinations
of them may not be supported.
:param networkmode: network mode, see NetworkModeEnum; str supported for deprecated backwards compatibility
:return:
"""
return self._connection.post_set('net/net-mode', OrderedDict((
('NetworkMode', networkmode if isinstance(networkmode, str) else networkmode.value),
('NetworkBand', networkband),
('LTEBand', lteband)
('NetworkBand', networkband if isinstance(networkband, str) else hex(networkband)[2:]),
('LTEBand', lteband if isinstance(lteband, str) else hex(lteband)[2:]),
)))

def network(self) -> GetResponseType:
Expand Down
38 changes: 38 additions & 0 deletions huawei_lte_api/enums/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,41 @@ class NetworkModeEnum(enum.Enum):
MODE_3G_ONLY = '02'
MODE_4G_ONLY = '03'
MODE_4G_3G_AUTO = '0302'


@enum.unique
class NetworkBandEnum(enum.IntEnum):
BC0A = 0x01
BC0B = 0x02
BC1 = 0x04
BC2 = 0x08
BC3 = 0x10
BC4 = 0x20
BC5 = 0x40
GSM1800 = 0x80
GSM900 = 0x300
BC6 = 0x400
BC7 = 0x800
BC8 = 0x1000
BC9 = 0x2000
BC10 = 0x4000
BC11 = 0x8000
GSM850 = 0x80000
GSM1900 = 0x200000
UMTS_B1_2100 = 0x400000
UMTS_B2_1900 = 0x800000
BC12 = 0x10000000
BC13 = 0x20000000
UMTS_B5_850 = 0x4000000
BC14 = 0x80000000
UMTS_B8_900 = 0x2000000000000

ALL = 0x3fffffff
"""Use alone, do not 'or' this with others."""


@enum.unique
class LTEBandEnum(enum.IntEnum):
"""For other values besides ALL, see set_net_mode docs."""
ALL = 0x7fffffffffffffff
"""Use alone, do not 'or' this with others."""

0 comments on commit 89c574e

Please sign in to comment.