11
11
12
12
import logging
13
13
14
- import sys
15
-
16
14
logger = logging .getLogger (__name__ )
17
15
18
16
try :
19
- from queue import Queue , Empty
17
+ import queue
20
18
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 )
34
27
35
28
from can import Message
36
29
from can .bus import BusABC
40
33
SPY_STATUS_REMOTE_FRAME = 0x08
41
34
42
35
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
-
58
36
def neo_device_name (device_type ):
59
37
names = {
60
38
neovi .NEODEVICE_BLUE : 'neoVI BLUE' ,
@@ -95,16 +73,9 @@ def __init__(self, channel=None, can_filters=None, **config):
95
73
channel
96
74
)
97
75
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
-
105
76
self .sw_filters = None
106
77
self .set_filters (can_filters )
107
- self .rx_buffer = Queue ()
78
+ self .rx_buffer = queue . Queue ()
108
79
109
80
self .network = int (channel ) if channel is not None else None
110
81
self .device .subscribe_to (self ._rx_buffer , network = self .network )
@@ -144,10 +115,7 @@ def _is_filter_match(self, arb_id):
144
115
145
116
def _ics_msg_to_message (self , ics_msg ):
146
117
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 ],
151
119
arbitration_id = ics_msg .ArbIDOrHeader ,
152
120
data = ics_msg .Data ,
153
121
dlc = ics_msg .NumberBytesData ,
@@ -160,7 +128,7 @@ def _ics_msg_to_message(self, ics_msg):
160
128
def recv (self , timeout = None ):
161
129
try :
162
130
ics_msg = self .rx_buffer .get (block = True , timeout = timeout )
163
- except Empty :
131
+ except queue . Empty :
164
132
pass
165
133
else :
166
134
if ics_msg .NetworkID == self .network and \
0 commit comments