1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 """
21 Support for dive computers, dive data loggers and other measurment devices
22 used in diving.
23
24 The module specifies set of interfaces to be implemented by device drivers.
25 """
26
27 import logging
28
29 import kenozooid.component as kc
30
31 log = logging.getLogger('kenozooid.driver')
34 """
35 Device driver interface.
36
37 Every device driver implementation has to implement at least this
38 interface.
39
40 Software using this interface shall get driver instance using
41 `DeviceDriver.scan` method.
42
43 There is only one known method for platform independent device scanning
44 and it applies to USB devices only. Library pyUSB can be used to find
45 devices, i.e.::
46
47 import usb.core
48 dev = usb.core.find(idVendor=0x0403, idProduct=0x6001)
49 dev.write(...)
50 dev.read(...)
51
52 Above code uses not released yet pyUSB 1.0 interfaces. Device's `write`
53 and `read' methods can be used to communicate with a device. It is not yet
54 possible to determine port of a device (i.e. /dev/ttyUSB0, COM1, etc.),
55 so it is not possible to bind this method with pySerial usage when
56 required.
57 """
58 @staticmethod
59 - def scan(port=None):
60 """
61 Scan for connected devices and return device driver instances.
62
63 Each connected dive computer should get one device driver instance.
64
65 If port is specified, then a driver instance should be returned,
66 which connects to the port.
67 """
68
70 """
71 Get model and firmware version information about connected dive
72 computer.
73 """
74
77 """
78 Diving computer dive simulation interface.
79 """
80 driver = None
81
83 """
84 Start dive simulation on dive computer.
85 """
86 pass
87
88
90 """
91 Stop dive simulation on dive computer.
92 """
93 pass
94
95
97 """
98 Send simulated depth to a dive computer.
99 """
100 pass
101
105 """
106 Diving computer data parser interface.
107
108 Depending on dive computer firmware capabilities, driver implementing
109 the interface shall dump all possible data from dive computer like
110
111 - dive computer settings
112 - all entries from dive logbook
113 - battery information
114 """
115 driver = None
116
118 """
119 Get raw data from dive computer.
120 """
121
123 """
124 Parse dive data from raw data.
125
126 Iterator of dives is returned.
127
128 :Parameters:
129 data
130 Raw dive computer data.
131 """
132
133
135 """
136 Get list of gases per dive.
137
138 Iterator of tuples of gases is returned. A tuple of gases is list
139 of gases used during a dive.
140
141 :Parameters:
142 data
143 Raw dive computer data.
144 """
145
146
148 """
149 Extract model and version information from dive computer raw data.
150
151 :Parameters:
152 data
153 Raw dive computer data.
154 """
155
158 """
159 Device communication error.
160 """
161
164 """
165 Find device driver implementing an interface.
166
167 Query parameter is used to find driver by its id or device model.
168 Device error exception is raised if driver is not found.
169
170 If device driver does not support functionality specified by an
171 interface, then None is returned.
172
173 :Parameters:
174 iface
175 Interface of functionality.
176 query
177 Device driver id or device model string.
178 port
179 Device port (i.e. /dev/ttyUSB0, COM1).
180 """
181 found = False
182 for cls in kc.query(DeviceDriver):
183 p = kc.params(cls)
184 id = p['id']
185 models = p['models']
186 if id == query or any(query == m for m in models):
187 found = True
188 log.debug('found device driver for query: {0}'.format(query))
189 break
190
191 if not found:
192 raise DeviceError('Device driver not found, query: {0}'.format(query))
193
194
195 try:
196 drv = next(cls.scan(port))
197 except StopIteration as ex:
198 raise DeviceError('Driver "{}" cannot communicate with a device at'
199 ' port "{}"'.format(id, port))
200
201
202 try:
203 cls = next(kc.query(iface, id=id))
204 obj = cls()
205 obj.driver = drv
206 return obj
207 except StopIteration as ex:
208 return None
209
210
211
212