-
Notifications
You must be signed in to change notification settings - Fork 0
/
devices.cpp
225 lines (204 loc) · 9.08 KB
/
devices.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include "devices.hpp"
#include "interface.hpp"
#include "timing.hpp"
#include <QQueue>
#include <QDataStream>
#include <QDebug>
static QList<CandleApiInterface *> initFunction_ifaces()
{
QList<CandleApiInterface *> _ifaces;
return _ifaces;
}
QList<CandleApiInterface *> CandleApiDevices::_ifaces = initFunction_ifaces();
static QList<CandleApiTiming> initFunction_timings()
{
QList<CandleApiTiming> _timings;
// Timings for 170MHz processors (CANable 2.0)
// Tseg1: 2..256 Tseg2: 2..128 sjw: 1..128 brp: 1..512
// Note: as expressed below, Tseg1 does not include 1 count for prop phase
_timings
<< CandleApiTiming(170000000, 10000, 875, 68, 217, 31)
<< CandleApiTiming(170000000, 20000, 875, 34, 217, 31)
<< CandleApiTiming(170000000, 50000, 875, 17, 173, 25)
<< CandleApiTiming(170000000, 83333, 875, 8, 221, 32)
<< CandleApiTiming(170000000, 100000, 875, 10, 147, 21)
<< CandleApiTiming(170000000, 125000, 875, 8, 147, 21)
<< CandleApiTiming(170000000, 250000, 875, 4, 147, 21)
<< CandleApiTiming(170000000, 500000, 875, 2, 147, 21)
<< CandleApiTiming(170000000, 1000000, 875, 1, 147, 21);
// Timings for 48MHz processors (CANable 0.X)
_timings
// sample point: 50.0%
<< CandleApiTiming(48000000, 10000, 500, 300, 6, 8)
<< CandleApiTiming(48000000, 20000, 500, 150, 6, 8)
<< CandleApiTiming(48000000, 50000, 500, 60, 6, 8)
<< CandleApiTiming(48000000, 83333, 500, 36, 6, 8)
<< CandleApiTiming(48000000, 100000, 500, 30, 6, 8)
<< CandleApiTiming(48000000, 125000, 500, 24, 6, 8)
<< CandleApiTiming(48000000, 250000, 500, 12, 6, 8)
<< CandleApiTiming(48000000, 500000, 500, 6, 6, 8)
<< CandleApiTiming(48000000, 800000, 500, 3, 8, 9)
<< CandleApiTiming(48000000, 1000000, 500, 3, 6, 8)
// sample point: 62.5%
<< CandleApiTiming(48000000, 10000, 625, 300, 8, 6)
<< CandleApiTiming(48000000, 20000, 625, 150, 8, 6)
<< CandleApiTiming(48000000, 50000, 625, 60, 8, 6)
<< CandleApiTiming(48000000, 83333, 625, 36, 8, 6)
<< CandleApiTiming(48000000, 100000, 625, 30, 8, 6)
<< CandleApiTiming(48000000, 125000, 625, 24, 8, 6)
<< CandleApiTiming(48000000, 250000, 625, 12, 8, 6)
<< CandleApiTiming(48000000, 500000, 625, 6, 8, 6)
<< CandleApiTiming(48000000, 800000, 600, 4, 7, 6)
<< CandleApiTiming(48000000, 1000000, 625, 3, 8, 6)
// sample point: 75.0%
<< CandleApiTiming(48000000, 10000, 750, 300, 10, 4)
<< CandleApiTiming(48000000, 20000, 750, 150, 10, 4)
<< CandleApiTiming(48000000, 50000, 750, 60, 10, 4)
<< CandleApiTiming(48000000, 83333, 750, 36, 10, 4)
<< CandleApiTiming(48000000, 100000, 750, 30, 10, 4)
<< CandleApiTiming(48000000, 125000, 750, 24, 10, 4)
<< CandleApiTiming(48000000, 250000, 750, 12, 10, 4)
<< CandleApiTiming(48000000, 500000, 750, 6, 10, 4)
<< CandleApiTiming(48000000, 800000, 750, 3, 13, 5)
<< CandleApiTiming(48000000, 1000000, 750, 3, 10, 4)
// sample point: 87.5%
<< CandleApiTiming(48000000, 10000, 875, 300, 12, 2)
<< CandleApiTiming(48000000, 20000, 875, 150, 12, 2)
<< CandleApiTiming(48000000, 50000, 875, 60, 12, 2)
<< CandleApiTiming(48000000, 83333, 875, 36, 12, 2)
<< CandleApiTiming(48000000, 100000, 875, 30, 12, 2)
<< CandleApiTiming(48000000, 125000, 875, 24, 12, 2)
<< CandleApiTiming(48000000, 250000, 875, 12, 12, 2)
<< CandleApiTiming(48000000, 500000, 875, 6, 12, 2)
<< CandleApiTiming(48000000, 800000, 867, 4, 11, 2)
<< CandleApiTiming(48000000, 1000000, 875, 3, 12, 2);
_timings
// sample point: 50.0%
<< CandleApiTiming(16000000, 10000, 520, 64, 11, 12)
<< CandleApiTiming(16000000, 20000, 500, 50, 6, 8)
<< CandleApiTiming(16000000, 50000, 500, 20, 6, 8)
<< CandleApiTiming(16000000, 83333, 500, 12, 6, 8)
<< CandleApiTiming(16000000, 100000, 500, 10, 6, 8)
<< CandleApiTiming(16000000, 125000, 500, 8, 6, 8)
<< CandleApiTiming(16000000, 250000, 500, 4, 6, 8)
<< CandleApiTiming(16000000, 500000, 500, 2, 6, 8)
<< CandleApiTiming(16000000, 800000, 500, 1, 8, 10)
<< CandleApiTiming(16000000, 1000000, 500, 1, 6, 8)
// sample point: 62.5%
<< CandleApiTiming(16000000, 10000, 625, 64, 14, 9)
<< CandleApiTiming(16000000, 20000, 625, 50, 8, 6)
<< CandleApiTiming(16000000, 50000, 625, 20, 8, 6)
<< CandleApiTiming(16000000, 83333, 625, 12, 8, 6)
<< CandleApiTiming(16000000, 100000, 625, 10, 8, 6)
<< CandleApiTiming(16000000, 125000, 625, 8, 8, 6)
<< CandleApiTiming(16000000, 250000, 625, 4, 8, 6)
<< CandleApiTiming(16000000, 500000, 625, 2, 8, 6)
<< CandleApiTiming(16000000, 800000, 625, 1, 11, 7)
<< CandleApiTiming(16000000, 1000000, 625, 1, 8, 6)
// sample point: 75.0%
<< CandleApiTiming(16000000, 20000, 750, 50, 10, 4)
<< CandleApiTiming(16000000, 50000, 750, 20, 10, 4)
<< CandleApiTiming(16000000, 83333, 750, 12, 10, 4)
<< CandleApiTiming(16000000, 100000, 750, 10, 10, 4)
<< CandleApiTiming(16000000, 125000, 750, 8, 10, 4)
<< CandleApiTiming(16000000, 250000, 750, 4, 10, 4)
<< CandleApiTiming(16000000, 500000, 750, 2, 10, 4)
<< CandleApiTiming(16000000, 800000, 750, 1, 13, 5)
<< CandleApiTiming(16000000, 1000000, 750, 1, 10, 4)
// sample point: 87.5%
<< CandleApiTiming(16000000, 20000, 875, 50, 12, 2)
<< CandleApiTiming(16000000, 50000, 875, 20, 12, 2)
<< CandleApiTiming(16000000, 83333, 875, 12, 12, 2)
<< CandleApiTiming(16000000, 100000, 875, 10, 12, 2)
<< CandleApiTiming(16000000, 125000, 875, 8, 12, 2)
<< CandleApiTiming(16000000, 250000, 875, 4, 12, 2)
<< CandleApiTiming(16000000, 500000, 875, 2, 12, 2)
<< CandleApiTiming(16000000, 800000, 900, 2, 7, 1)
<< CandleApiTiming(16000000, 1000000, 875, 1, 12, 2);
return _timings;
}
QList<CandleApiTiming> CandleApiDevices::_timings = initFunction_timings();
QList<QCanBusDeviceInfo> CandleApiDevices::interfaces()
{
QList<QCanBusDeviceInfo> result;
static QString const description("candleLight_fw compatible device");
static QString const name("gs_usb");
candle_list_handle clist;
uint8_t num_ifaces;
candle_handle dev;
if (candle_list_scan(&clist))
{
if (candle_list_length(clist, &num_ifaces))
{
for (uint8_t cnt = 0; cnt < num_ifaces; cnt++)
{
if (candle_dev_get(clist, cnt, &dev))
{
candle_devstate_t state;
if (candle_dev_get_state(dev, &state))
{
if (state == CANDLE_DEVSTATE_AVAIL)
{
QString dev_name = name + QString::number(cnt);
qDebug() << "Found CandleLight device:" << dev_name;
CandleApiInterface *iface = findInterface(dev);
if (iface == nullptr)
{
iface = new CandleApiInterface(dev, dev_name);
addInterface(iface);
}
else
{
iface->update(dev, dev_name);
}
result.append(
createDeviceInfo(
dev_name,
QString::number(cnt),
description,
0,
false,
false
)
);
}
}
}
}
}
candle_list_free(clist);
}
return result;
}
void CandleApiDevices::addInterface(CandleApiInterface *iface)
{
_ifaces.append(iface);
}
QList<CandleApiInterface *> CandleApiDevices::getInterfaces()
{
return _ifaces;
}
CandleApiInterface *CandleApiDevices::findInterface(candle_handle dev)
{
CandleApiInterface* iface;
foreach (iface, _ifaces)
{
if (iface->getPath() == std::wstring(candle_dev_get_path(dev)))
{
return iface;
}
}
return nullptr;
}
CandleApiInterface *CandleApiDevices::findInterface(QString name)
{
CandleApiInterface* iface;
foreach (iface, _ifaces)
{
if (iface->getName() == name)
{
return iface;
}
}
return nullptr;
}