@@ -110,29 +110,6 @@ def printMessage(message: Message):
110110
111111datagramService = DatagramService (canLink )
112112canLink .registerMessageReceivedListener (datagramService .process )
113- port = 12021
114- spaces = { # big endian (most significant byte sent first) as per openlcb
115- # 0: bytearray([
116- # 0x01, 0x00, # 0x1000 = 4096 (unsigned int 16)
117- # ])
118- 0 : bytearray (struct .pack (">H" , port )),
119- }
120- # bytearray allows in-place append (from pack bytes does not)
121- # H: short (capitalized means unsigned)
122- # >: big endian (required for openlcb)
123- # e: float16 (IEEE 754 binary16, 2-bytes)
124- # For other symbols see Python documentation or SUBTYPE_FORMATS in cdivar.py.
125-
126- spaces [0 ] += struct .pack (">e" , 0.5 ) # save at address 3 (size 2)
127- # NOTE: 0.5 can be stored precisely, as b'\x008'
128- # but not all numbers can be represented by IEEE float.
129- # For example, 2.4 is stored as b'\xcd@' which is ~2.400390625
130-
131- # Additional pack examples:
132- neg2_float_ba = bytearray (b'\xc0 \x00 ' )
133- neg2_float_b = struct .pack (">e" , - 2 )
134- assert bytes (neg2_float_ba ) == bytes (neg2_float_b ), \
135- f"expected b'\xc0 \x00 ', b'\xc0 \x00 ', got { neg2_float_ba } , { neg2_float_b } "
136113
137114cdi = """<?xml version="1.0" encoding="utf-8"?>
138115<cdi
@@ -169,7 +146,6 @@ def printMessage(message: Message):
169146</cdi>
170147""" # noqa: E501
171148
172-
173149assert_xml (cdi )
174150
175151
@@ -229,20 +205,11 @@ def memoryReadFail(memo):
229205localNode .loadCDIString (cdi , backup_path )
230206# NOTE: loadCDI or loadCDIString sets Element tree and
231207# localNode._segments[MemorySpace.CDI.value]
232- segment = localNode .getSegment (MemorySpace .CDI .value )
233- assert isinstance (segment , Segment )
234- assert isinstance (segment ._data , (bytearray , bytes ))
235- last = localNode .getLast (0xFF )
236- assert last is not None
237- last = localNode .getLast (MemorySpace .CDI )
238- assert last is not None
239208# localNodeProcessor = LocalNodeProcessor(canLink, localNode)
240209# canLink.registerMessageReceivedListener(localNodeProcessor.process)
241210localNodeProcessor = localNode .localNodeProcessor
242- localNode .setInt (0 , 0 , port , 2 , False )
243- localNode .setFloat (0 , 2 , 0.5 , 2 )
244- assert localNode .getSlice (0 , 0 , 2 ) == spaces [0 ][0 :2 ]
245- assert localNode .getSlice (0 , 2 , 2 ) == spaces [0 ][2 :]
211+ localNode .setInt (0 , 0 , settings ['port' ], 2 , False )
212+ localNode .setFloat (0 , 2 , settings ['timeout' ], 2 )
246213
247214
248215def displayOtherNodeIds (message : Message ) :
0 commit comments