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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
#include "configuredivecomputerthreads.h"
#include "libdivecomputer/hw.h"
#include <QDebug>
#include <QDateTime>
#include <QStringList>
ReadSettingsThread::ReadSettingsThread(QObject *parent, device_data_t *data)
: QThread(parent), m_data(data)
{
}
void ReadSettingsThread::run()
{
bool supported = false;
dc_status_t rc;
rc = rc = dc_device_open(&m_data->device, m_data->context, m_data->descriptor, m_data->devname);
if (rc == DC_STATUS_SUCCESS) {
DeviceDetails *m_deviceDetails = new DeviceDetails(0);
switch (dc_device_get_type(m_data->device)) {
case DC_FAMILY_HW_OSTC3:
supported = true;
m_deviceDetails->setBrightness(0);
m_deviceDetails->setCustomText("");
m_deviceDetails->setDateFormat(0);
m_deviceDetails->setDiveModeColor(0);
m_deviceDetails->setFirmwareVersion("");
m_deviceDetails->setLanguage(0);
m_deviceDetails->setLastDeco(0);
m_deviceDetails->setSerialNo("");
m_deviceDetails->setCompassGain(0);
m_deviceDetails->setSalinity(0);
m_deviceDetails->setSamplingRate(0);
m_deviceDetails->setUnits(0);
//Gread gas mixes
gas gas1;
gas gas2;
gas gas3;
gas gas4;
gas gas5;
//Gas 1
unsigned char gasData[4] = {0,0,0,0};
rc = hw_ostc3_device_config_read(m_data->device, 0x10, gasData, sizeof(gasData));
if (rc == DC_STATUS_SUCCESS) {
//Gas data read successful
gas1.depth = gasData[3];
gas1.oxygen = gasData[0];
gas1.helium = gasData[1];
gas1.type = gasData[2];
}
//Gas 2
rc = hw_ostc3_device_config_read(m_data->device, 0x11, gasData, sizeof(gasData));
if (rc == DC_STATUS_SUCCESS) {
//Gas data read successful
gas2.depth = gasData[3];
gas2.oxygen = gasData[0];
gas2.helium = gasData[1];
gas2.type = gasData[2];
}
//Gas 3
rc = hw_ostc3_device_config_read(m_data->device, 0x12, gasData, sizeof(gasData));
if (rc == DC_STATUS_SUCCESS) {
//Gas data read successful
gas3.depth = gasData[3];
gas3.oxygen = gasData[0];
gas3.helium = gasData[1];
gas3.type = gasData[2];
}
//Gas 4
rc = hw_ostc3_device_config_read(m_data->device, 0x13, gasData, sizeof(gasData));
if (rc == DC_STATUS_SUCCESS) {
//Gas data read successful
gas4.depth = gasData[3];
gas4.oxygen = gasData[0];
gas4.helium = gasData[1];
gas4.type = gasData[2];
}
//Gas 5
rc = hw_ostc3_device_config_read(m_data->device, 0x14, gasData, sizeof(gasData));
if (rc == DC_STATUS_SUCCESS) {
//Gas data read successful
gas5.depth = gasData[3];
gas5.oxygen = gasData[0];
gas5.helium = gasData[1];
gas5.type = gasData[2];
}
m_deviceDetails->setGas1(gas1);
m_deviceDetails->setGas2(gas2);
m_deviceDetails->setGas3(gas3);
m_deviceDetails->setGas4(gas4);
m_deviceDetails->setGas5(gas5);
//Read other settings
unsigned char uData[1] = {0};
//DiveMode
rc = hw_ostc3_device_config_read(m_data->device, 0x20, uData, sizeof(uData));
if (rc == DC_STATUS_SUCCESS)
m_deviceDetails->setDiveMode(uData[0]);
//Saturation
rc = hw_ostc3_device_config_read(m_data->device, 0x2A, uData, sizeof(uData));
if (rc == DC_STATUS_SUCCESS)
m_deviceDetails->setSaturation(uData[0]);
//LastDeco
rc = hw_ostc3_device_config_read(m_data->device, 0x2D, uData, sizeof(uData));
if (rc == DC_STATUS_SUCCESS)
m_deviceDetails->setLastDeco(uData[0]);
//Brightness
rc = hw_ostc3_device_config_read(m_data->device, 0x2D, uData, sizeof(uData));
if (rc == DC_STATUS_SUCCESS)
m_deviceDetails->setBrightness(uData[0]);
//Units
rc = hw_ostc3_device_config_read(m_data->device, 0x2E, uData, sizeof(uData));
if (rc == DC_STATUS_SUCCESS)
m_deviceDetails->setUnits(uData[0]);
//Sampling Rate
rc = hw_ostc3_device_config_read(m_data->device, 0x2F, uData, sizeof(uData));
if (rc == DC_STATUS_SUCCESS)
m_deviceDetails->setSamplingRate(uData[0]);
//Salinity
rc = hw_ostc3_device_config_read(m_data->device, 0x30, uData, sizeof(uData));
if (rc == DC_STATUS_SUCCESS)
m_deviceDetails->setSalinity(uData[0]);
//Dive mode colour
rc = hw_ostc3_device_config_read(m_data->device, 0x31, uData, sizeof(uData));
if (rc == DC_STATUS_SUCCESS)
m_deviceDetails->setDiveModeColor(uData[0]);
//Language
rc = hw_ostc3_device_config_read(m_data->device, 0x32, uData, sizeof(uData));
if (rc == DC_STATUS_SUCCESS)
m_deviceDetails->setLanguage(uData[0]);
//Date Format
rc = hw_ostc3_device_config_read(m_data->device, 0x33, uData, sizeof(uData));
if (rc == DC_STATUS_SUCCESS)
m_deviceDetails->setDateFormat(uData[0]);
//read firmware settings
unsigned char fData[64] = {0};
rc = hw_ostc3_device_version (m_data->device, fData, sizeof (fData));
if (rc == DC_STATUS_SUCCESS) {
int serial = fData[0] + (fData[1] << 8);
m_deviceDetails->setSerialNo(QString::number(serial));
int fw = (fData[2] << 8) + fData[3];
m_deviceDetails->setFirmwareVersion(QString::number(fw));
QByteArray ar((char *)fData + 4, 60);
m_deviceDetails->setCustomText(ar.trimmed());
}
emit devicedetails(m_deviceDetails);
break;
}
dc_device_close(m_data->device);
if (!supported) {
lastError = tr("This feature is not yet available for the selected dive computer.");
emit error(lastError);
}
}
else {
lastError = tr("Could not a establish connection to the dive computer.");
emit error(lastError);
}
}
WriteSettingsThread::WriteSettingsThread(QObject *parent, device_data_t *data)
: QThread(parent), m_data(data) {
}
void WriteSettingsThread::setDeviceDetails(DeviceDetails *details)
{
m_deviceDetails = details;
}
void WriteSettingsThread::run()
{
bool supported = false;
dc_status_t rc;
rc = rc = dc_device_open(&m_data->device, m_data->context, m_data->descriptor, m_data->devname);
if (rc == DC_STATUS_SUCCESS) {
switch (dc_device_get_type(m_data->device)) {
case DC_FAMILY_HW_OSTC3:
supported = true;
//write general settings
//custom text
hw_ostc3_device_customtext(m_data->device, m_deviceDetails->customText().toUtf8().data());
unsigned char data[1] = {0};
//dive mode
data[0] = m_deviceDetails->diveMode();
hw_ostc3_device_config_write(m_data->device, 0x20, data, sizeof(data));
//saturation
data[0] = m_deviceDetails->saturation();
hw_ostc3_device_config_write(m_data->device, 0x2A, data, sizeof(data));
//last deco
data[0] = m_deviceDetails->lastDeco();
hw_ostc3_device_config_write(m_data->device, 0x2C, data, sizeof(data));
//brightness
data[0] = m_deviceDetails->brightness();
hw_ostc3_device_config_write(m_data->device, 0x2D, data, sizeof(data));
//units
data[0] = m_deviceDetails->units();
hw_ostc3_device_config_write(m_data->device, 0x2E, data, sizeof(data));
//sampling rate
data[0] = m_deviceDetails->samplingRate();
hw_ostc3_device_config_write(m_data->device, 0x2F, data, sizeof(data));
//salinity
data[0] = m_deviceDetails->salinity();
hw_ostc3_device_config_write(m_data->device, 0x30, data, sizeof(data));
//dive mode colour
data[0] = m_deviceDetails->diveModeColor();
hw_ostc3_device_config_write(m_data->device, 0x31, data, sizeof(data));
//language
data[0] = m_deviceDetails->language();
hw_ostc3_device_config_write(m_data->device, 0x32, data, sizeof(data));
//date format
data[0] = m_deviceDetails->dateFormat();
hw_ostc3_device_config_write(m_data->device, 0x33, data, sizeof(data));
//compass gain
data[0] = m_deviceDetails->compassGain();
hw_ostc3_device_config_write(m_data->device, 0x34, data, sizeof(data));
//sync date and time
if (m_deviceDetails->syncTime()) {
QDateTime timeToSet = QDateTime::currentDateTime();
dc_datetime_t time;
time.year = timeToSet.date().year();
time.month = timeToSet.date().month();
time.day = timeToSet.date().day();
time.hour = timeToSet.time().hour();
time.minute = timeToSet.time().minute();
time.second = timeToSet.time().second();
hw_ostc3_device_clock(m_data->device, &time);
}
break;
}
dc_device_close(m_data->device);
if (!supported) {
lastError = tr("This feature is not yet available for the selected dive computer.");
emit error(lastError);
}
}
else {
lastError = tr("Could not a establish connection to the dive computer.");
emit error(lastError);
}
}
|