Skip to content

Commit

Permalink
expose timeouts via a settings object and make timeouts class a cdef
Browse files Browse the repository at this point in the history
  • Loading branch information
Pol Feliu authored and bnjmnp committed Dec 9, 2024
1 parent a86f724 commit 19dfa12
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/pysoem/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
CdefCoeObjectEntry,
)

# Timeouts:
# Settings:
from pysoem.pysoem import (
TIMEOUTS
settings
)
9 changes: 7 additions & 2 deletions src/pysoem/pysoem.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ECT_COEDET_PDOCONFIG = 0x08
ECT_COEDET_UPLOAD = 0x10
ECT_COEDET_SDOCA = 0x20

cdef class _Timeouts:
cdef class CdefTimeouts:

cdef cpysoem.Ttimeouts* _t

Expand Down Expand Up @@ -108,9 +108,14 @@ cdef class _Timeouts:
def state(self, value: int):
self._t.state = value

TIMEOUTS = _Timeouts()
cdef class CdefSettings:

cdef public CdefTimeouts timeouts

def __init__(self):
self.timeouts = CdefTimeouts()

settings = CdefSettings()

cpdef enum ec_datatype:
ECT_BOOLEAN = 0x0001,
Expand Down
36 changes: 18 additions & 18 deletions tests/pysoem_basic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,26 @@ def test_closed_interface_slave(ifname):


def test_tune_timeouts():
assert pysoem.TIMEOUTS.ret == 2_000
pysoem.TIMEOUTS.ret = 5_000
assert pysoem.TIMEOUTS.ret == 5_000
assert pysoem.settings.timeouts.ret == 2_000
pysoem.settings.timeouts.ret = 5_000
assert pysoem.settings.timeouts.ret == 5_000

assert pysoem.TIMEOUTS.safe == 20_000
pysoem.TIMEOUTS.safe = 70_000
assert pysoem.TIMEOUTS.safe == 70_000
assert pysoem.settings.timeouts.safe == 20_000
pysoem.settings.timeouts.safe = 70_000
assert pysoem.settings.timeouts.safe == 70_000

assert pysoem.TIMEOUTS.eeprom == 20_000
pysoem.TIMEOUTS.eeprom = 30_000
assert pysoem.TIMEOUTS.eeprom == 30_000
assert pysoem.settings.timeouts.eeprom == 20_000
pysoem.settings.timeouts.eeprom = 30_000
assert pysoem.settings.timeouts.eeprom == 30_000

assert pysoem.TIMEOUTS.tx_mailbox == 20_000
pysoem.TIMEOUTS.tx_mailbox = 90_000
assert pysoem.TIMEOUTS.tx_mailbox == 90_000
assert pysoem.settings.timeouts.tx_mailbox == 20_000
pysoem.settings.timeouts.tx_mailbox = 90_000
assert pysoem.settings.timeouts.tx_mailbox == 90_000

assert pysoem.TIMEOUTS.rx_mailbox == 700_000
pysoem.TIMEOUTS.rx_mailbox = 900_000
assert pysoem.TIMEOUTS.rx_mailbox == 900_000
assert pysoem.settings.timeouts.rx_mailbox == 700_000
pysoem.settings.timeouts.rx_mailbox = 900_000
assert pysoem.settings.timeouts.rx_mailbox == 900_000

assert pysoem.TIMEOUTS.state == 2_000_000
pysoem.TIMEOUTS.state = 5_000_000
assert pysoem.TIMEOUTS.state == 5_000_000
assert pysoem.settings.timeouts.state == 2_000_000
pysoem.settings.timeouts.state = 5_000_000
assert pysoem.settings.timeouts.state == 5_000_000

0 comments on commit 19dfa12

Please sign in to comment.