Skip to content

Commit f87765f

Browse files
authored
Merge pull request #171 from epage/signal_cleanup
Signal cleanup
2 parents 458b2ec + 326f3bb commit f87765f

File tree

3 files changed

+59
-59
lines changed

3 files changed

+59
-59
lines changed

nixnet/_session/frames.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,22 @@ def __repr__(self):
5252

5353
def read_bytes(
5454
self,
55-
num_bytes_to_read,
55+
num_bytes,
5656
timeout=constants.TIMEOUT_NONE):
5757
# type: (int, float) -> bytes
5858
"""Read data as a list of raw bytes (frame data).
5959
6060
The raw bytes encode one or more frames using the Raw Frame Format.
6161
6262
Args:
63-
num_bytes_to_read(int): The number of bytes to read.
63+
num_bytes(int): The number of bytes to read.
6464
timeout(float): The time in seconds to wait for number to read
6565
frame bytes to become available.
6666
6767
To avoid returning a partial frame, even when
68-
'num_bytes_to_read' are available from the hardware, this
68+
'num_bytes' are available from the hardware, this
6969
read may return fewer bytes in buffer. For example, assume you
70-
pass 'num_bytes_to_read' 70 bytes and 'timeout' of 10
70+
pass 'num_bytes' 70 bytes and 'timeout' of 10
7171
seconds. During the read, two frames are received, the first 24
7272
bytes in size, and the second 56 bytes in size, for a total of
7373
80 bytes. The read returns after the two frames are received,
@@ -78,48 +78,48 @@ def read_bytes(
7878
buffer.
7979
8080
If 'timeout' is positive, this function waits for
81-
'num_bytes_to_read' frame bytes to be received, then
81+
'num_bytes' frame bytes to be received, then
8282
returns complete frames up to that number. If the bytes do not
8383
arrive prior to the 'timeout', an error is returned.
8484
8585
If 'timeout' is 'constants.TIMEOUT_INFINITE', this
86-
function waits indefinitely for 'num_bytes_to_read' frame bytes.
86+
function waits indefinitely for 'num_bytes' frame bytes.
8787
8888
If 'timeout' is 'constants.TIMEOUT_NONE', this
8989
function does not wait and immediately returns all available
90-
frame bytes up to the limit 'num_bytes_to_read' specifies.
90+
frame bytes up to the limit 'num_bytes' specifies.
9191
9292
Returns:
9393
A list of raw bytes representing the data.
9494
"""
95-
buffer, number_of_bytes_returned = _funcs.nx_read_frame(self._handle, num_bytes_to_read, timeout)
95+
buffer, number_of_bytes_returned = _funcs.nx_read_frame(self._handle, num_bytes, timeout)
9696
return buffer[0:number_of_bytes_returned]
9797

9898
def read(
9999
self,
100-
num_frames_to_read,
100+
num_frames,
101101
timeout=constants.TIMEOUT_NONE,
102102
frame_type=types.XnetFrame):
103103
# type: (int, float, typing.Type[types.FrameFactory]) -> typing.Iterable[types.Frame]
104104
"""Read raw CAN frames.
105105
106106
Args:
107-
num_frames_to_read(int): Number of raw CAN frames
107+
num_frames(int): Number of raw CAN frames
108108
to read.
109109
timeout(float): The time in seconds to wait for number to read
110110
frame bytes to become available.
111111
112112
If 'timeout' is positive, this function waits for
113-
'num_frames_to_read' frames to be received, then
113+
'num_frames' frames to be received, then
114114
returns complete frames up to that number. If the frames do not
115115
arrive prior to the 'timeout', an error is returned.
116116
117117
If 'timeout' is 'constants.TIMEOUT_INFINITE', this function
118-
waits indefinitely for 'num_frames_to_read' frames.
118+
waits indefinitely for 'num_frames' frames.
119119
120120
If 'timeout' is 'constants.TIMEOUT_NONE', this function does not
121121
wait and immediately returns all available frames up to the
122-
limit 'num_frames_to_read' specifies.
122+
limit 'num_frames' specifies.
123123
frame_type(:any:`nixnet.types.FrameFactory`): A factory for the
124124
desired frame formats.
125125
@@ -128,9 +128,9 @@ def read(
128128
"""
129129
from_raw = typing.cast(typing.Callable[[types.RawFrame], types.Frame], frame_type.from_raw)
130130
# NOTE: If the frame payload exceeds the base unit, this will return
131-
# less than num_frames_to_read
132-
num_bytes_to_read = num_frames_to_read * _frames.nxFrameFixed_t.size
133-
buffer = self.read_bytes(num_bytes_to_read, timeout)
131+
# less than num_frames
132+
num_bytes = num_frames * _frames.nxFrameFixed_t.size
133+
buffer = self.read_bytes(num_bytes, timeout)
134134
for frame in _frames.iterate_frames(buffer):
135135
yield from_raw(frame)
136136

@@ -143,19 +143,19 @@ def __repr__(self):
143143

144144
def read_bytes(
145145
self,
146-
num_bytes_to_read):
146+
num_bytes):
147147
# type: (int) -> bytes
148148
"""Read data as a list of raw bytes (frame data).
149149
150150
Args:
151-
num_bytes_to_read(int): Number of bytes to read.
151+
num_bytes(int): Number of bytes to read.
152152
153153
Returns:
154154
bytes: Raw bytes representing the data.
155155
"""
156156
buffer, number_of_bytes_returned = _funcs.nx_read_frame(
157157
self._handle,
158-
num_bytes_to_read,
158+
num_bytes,
159159
constants.TIMEOUT_NONE)
160160
return buffer[0:number_of_bytes_returned]
161161

@@ -174,10 +174,10 @@ def read(
174174
"""
175175
from_raw = typing.cast(typing.Callable[[types.RawFrame], types.Frame], frame_type.from_raw)
176176
# NOTE: If the frame payload exceeds the base unit, this will return
177-
# less than num_frames_to_read
178-
num_frames_to_read = len(self)
179-
num_bytes_to_read = num_frames_to_read * _frames.nxFrameFixed_t.size
180-
buffer = self.read_bytes(num_bytes_to_read)
177+
# less than num_frames
178+
num_frames = len(self)
179+
num_bytes = num_frames * _frames.nxFrameFixed_t.size
180+
buffer = self.read_bytes(num_bytes)
181181
for frame in _frames.iterate_frames(buffer):
182182
yield from_raw(frame)
183183

nixnet/_session/signals.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def read(self):
4545
"""Read data from a Signal Input Single-Point session.
4646
4747
Yields:
48-
A tuple of timestamp (int) and signal values (float).
48+
tuple of int and float: Timestamp and signal
4949
"""
5050
num_signals = len(self)
5151
timestamps, values = _funcs.nx_read_signal_single_point(self._handle, num_signals)
@@ -61,14 +61,14 @@ def __repr__(self):
6161

6262
def write(
6363
self,
64-
value_buffer):
64+
signals):
6565
# type: (typing.Iterable[float]) -> None
6666
"""Write data to a Signal Output Single-Point session.
6767
6868
Args:
69-
value_buffer(list): A list of singal values (float).
69+
signals(list of float): A list of signal values (float).
7070
"""
71-
_funcs.nx_write_signal_single_point(self._handle, list(value_buffer))
71+
_funcs.nx_write_signal_single_point(self._handle, list(signals))
7272

7373

7474
class Signal(collection.Item):

tests/test_signals.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,6 @@ def nixnet_out_interface(request):
2121
return interface
2222

2323

24-
@pytest.mark.integration
25-
def test_singlepoint_loopback(nixnet_in_interface, nixnet_out_interface):
26-
database_name = 'NIXNET_example'
27-
cluster_name = 'CAN_Cluster'
28-
signal_names = ['CANEventSignal1', 'CANEventSignal2']
29-
30-
with nixnet.SignalInSinglePointSession(
31-
nixnet_in_interface,
32-
database_name,
33-
cluster_name,
34-
signal_names) as input_session:
35-
with nixnet.SignalOutSinglePointSession(
36-
nixnet_out_interface,
37-
database_name,
38-
cluster_name,
39-
signal_names) as output_session:
40-
# Start the input session manually to make sure that the first
41-
# frame value sent before the initial read will be received.
42-
input_session.start()
43-
44-
expected_signals = [24.5343, 77.0129]
45-
output_session.signals.write(expected_signals)
46-
47-
# Wait 1 s and then read the received values.
48-
# They should be the same as the ones sent.
49-
time.sleep(1)
50-
51-
actual_signals = list(input_session.signals.read())
52-
for expected, (_, actual) in zip(expected_signals, actual_signals):
53-
assert pytest.approx(expected, rel=1) == actual
54-
55-
5624
@pytest.mark.integration
5725
def test_signals_container(nixnet_in_interface):
5826
database_name = 'NIXNET_example'
@@ -86,3 +54,35 @@ def test_signals_container(nixnet_in_interface):
8654
assert signal == input_session.signals.get(signal_name)
8755
assert input_session.signals.get(1) is None
8856
assert input_session.signals.get("<random>") is None
57+
58+
59+
@pytest.mark.integration
60+
def test_singlepoint_loopback(nixnet_in_interface, nixnet_out_interface):
61+
database_name = 'NIXNET_example'
62+
cluster_name = 'CAN_Cluster'
63+
signal_names = ['CANEventSignal1', 'CANEventSignal2']
64+
65+
with nixnet.SignalInSinglePointSession(
66+
nixnet_in_interface,
67+
database_name,
68+
cluster_name,
69+
signal_names) as input_session:
70+
with nixnet.SignalOutSinglePointSession(
71+
nixnet_out_interface,
72+
database_name,
73+
cluster_name,
74+
signal_names) as output_session:
75+
# Start the input session manually to make sure that the first
76+
# frame value sent before the initial read will be received.
77+
input_session.start()
78+
79+
expected_signals = [24.5343, 77.0129]
80+
output_session.signals.write(expected_signals)
81+
82+
# Wait 1 s and then read the received values.
83+
# They should be the same as the ones sent.
84+
time.sleep(1)
85+
86+
actual_signals = list(input_session.signals.read())
87+
for expected, (_, actual) in zip(expected_signals, actual_signals):
88+
assert pytest.approx(expected, rel=1) == actual

0 commit comments

Comments
 (0)