Skip to content

Commit a12d173

Browse files
pierreluctgchristiansandberg
authored andcommitted
Now using neovi.GetTimeStampForMsg to get correct time stamp (hardbyte#138)
* Now using neovi.GetTimeStampForMsg since it is now working after commit https://bitbucket.org/Kemp_J/pyneovi/commits/0804ce1c35aef184e32ce063ab5481d086dfde11 in pyneovi. Remove time scaling constant since they are no longer used. Removed win32 check for neovi import since it's not win32 only. * Now using neovi.GetTimeStampForMsg since it is now working after commit https://bitbucket.org/Kemp_J/pyneovi/commits/0804ce1c35aef184e32ce063ab5481d086dfde11 in pyneovi. Remove time scaling constant since they are no longer used. Removed win32 check for neovi import since it's not win32 only.
1 parent aa44f45 commit a12d173

File tree

1 file changed

+12
-44
lines changed

1 file changed

+12
-44
lines changed

can/interfaces/neovi_api/neovi_api.py

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,19 @@
1111

1212
import logging
1313

14-
import sys
15-
1614
logger = logging.getLogger(__name__)
1715

1816
try:
19-
from queue import Queue, Empty
17+
import queue
2018
except ImportError:
21-
from Queue import Queue, Empty
22-
23-
if sys.platform == "win32":
24-
try:
25-
from neovi import neodevice
26-
from neovi import neovi
27-
from neovi.structures import icsSpyMessage
28-
except ImportError as e:
29-
logger.warning("Cannot load pyneovi: %s", e)
30-
else:
31-
# Will not work on other systems, but have it importable anyway for
32-
# tests/sphinx
33-
logger.warning("pyneovi library does not work on %s platform", sys.platform)
19+
import Queue as queue
20+
21+
try:
22+
from neovi import neodevice
23+
from neovi import neovi
24+
from neovi.structures import icsSpyMessage
25+
except ImportError as e:
26+
logger.warning("Cannot load pyneovi: %s", e)
3427

3528
from can import Message
3629
from can.bus import BusABC
@@ -40,21 +33,6 @@
4033
SPY_STATUS_REMOTE_FRAME = 0x08
4134

4235

43-
# For the neoVI hardware, TimeHardware2 is more significant than TimeHardware.
44-
# The resolution of TimeHardware is 1.6us and and TimeHardware2 is 104.8576 ms.
45-
# To calculate the time of the message in seconds use the following formula:
46-
# "Timestamp (sec) = TimeHardware2* 0.1048576 + TimeHardware * 0.0000016".
47-
NEOVI_TIMEHARDWARE_SCALING = 0.0000016
48-
NEOVI_TIMEHARDWARE2_SCALING = 0.1048576
49-
50-
# For the neoVI PRO or ValueCAN hardware, TimeHardware2 is more significant than
51-
# TimeHardware. The resolution of TimeHardware is 1.0us and and TimeHardware2 is
52-
# 65.536 ms. To calculate the time of the message in seconds use the following
53-
# formula: "Timestamp (sec) = TimeHardware2* 0.065536 + TimeHardware * 0.000001"
54-
VALUECAN_TIMEHARDWARE_SCALING = 0.000001
55-
VALUECAN_TIMEHARDWARE2_SCALING = 0.065536
56-
57-
5836
def neo_device_name(device_type):
5937
names = {
6038
neovi.NEODEVICE_BLUE: 'neoVI BLUE',
@@ -95,16 +73,9 @@ def __init__(self, channel=None, can_filters=None, **config):
9573
channel
9674
)
9775

98-
if self.device.get_type() in [neovi.NEODEVICE_DW_VCAN]:
99-
self._time_scaling = (VALUECAN_TIMEHARDWARE_SCALING,
100-
VALUECAN_TIMEHARDWARE2_SCALING)
101-
else:
102-
self._time_scaling = (NEOVI_TIMEHARDWARE_SCALING,
103-
NEOVI_TIMEHARDWARE2_SCALING)
104-
10576
self.sw_filters = None
10677
self.set_filters(can_filters)
107-
self.rx_buffer = Queue()
78+
self.rx_buffer = queue.Queue()
10879

10980
self.network = int(channel) if channel is not None else None
11081
self.device.subscribe_to(self._rx_buffer, network=self.network)
@@ -144,10 +115,7 @@ def _is_filter_match(self, arb_id):
144115

145116
def _ics_msg_to_message(self, ics_msg):
146117
return Message(
147-
timestamp=(
148-
self._time_scaling[1] * ics_msg.TimeHardware2 +
149-
self._time_scaling[0] * ics_msg.TimeHardware
150-
),
118+
timestamp=neovi.GetTimeStampForMsg(self.device.handle, ics_msg)[1],
151119
arbitration_id=ics_msg.ArbIDOrHeader,
152120
data=ics_msg.Data,
153121
dlc=ics_msg.NumberBytesData,
@@ -160,7 +128,7 @@ def _ics_msg_to_message(self, ics_msg):
160128
def recv(self, timeout=None):
161129
try:
162130
ics_msg = self.rx_buffer.get(block=True, timeout=timeout)
163-
except Empty:
131+
except queue.Empty:
164132
pass
165133
else:
166134
if ics_msg.NetworkID == self.network and \

0 commit comments

Comments
 (0)