comparison HardwareOperations.h @ 11:6fba58c4964b

Minor changes done by automatic style checker
author Ideenmodellierer
date Mon, 12 Jan 2026 13:57:24 +0000
parents 115cfa4a3239
children
comparison
equal deleted inserted replaced
10:9a3c1a6f9833 11:6fba58c4964b
43 #ifndef HARDWARE_OPERATIONS_H 43 #ifndef HARDWARE_OPERATIONS_H
44 #define HARDWARE_OPERATIONS_H 44 #define HARDWARE_OPERATIONS_H
45 45
46 #include <QDateTime> 46 #include <QDateTime>
47 #include <QImage> 47 #include <QImage>
48 #include <QRegularExpression>
49 #include <QSize>
48 #include <QString> 50 #include <QString>
49 #include <QStringList> 51 #include <QStringList>
50 #include <QSize>
51 #include <QRegularExpression>
52 52
53 #ifdef TEST_MODE 53 #ifdef TEST_MODE
54 # include "test/SerialTest.h" 54 #include "test/SerialTest.h"
55 #else 55 #else
56 # include "Serial.h" 56 #include "Serial.h"
57 #endif 57 #endif
58 58
59 class HexFile; 59 class HexFile;
60 60
61 ////////////////////////////////////////////////////////////////////////////// 61 //////////////////////////////////////////////////////////////////////////////
73 class HardwareOperations 73 class HardwareOperations
74 { 74 {
75 protected: 75 protected:
76 #ifdef TEST_MODE 76 #ifdef TEST_MODE
77 /// \brief Fake communication port used for mockup operations. 77 /// \brief Fake communication port used for mockup operations.
78 SerialTest _serial; 78 SerialTest _serial;
79 #else 79 #else
80 /// \brief Communication port used for all I/O operations. 80 /// \brief Communication port used for all I/O operations.
81 /// 81 ///
82 /// Note that in *emulation mode*, aka TEST_MODE, this is replaced by 82 /// Note that in *emulation mode*, aka TEST_MODE, this is replaced by
83 /// an instance of SerialTest. 83 /// an instance of SerialTest.
84 Serial _serial; 84 Serial _serial;
85 #endif 85 #endif
86 86
87 public: 87 public:
88 ////////////////////////////////////////////////////////////////////////// 88 //////////////////////////////////////////////////////////////////////////
89 /// \name Class management 89 /// \name Class management
102 virtual QString model() const = 0; 102 virtual QString model() const = 0;
103 103
104 //------------------------------------------------------------------------ 104 //------------------------------------------------------------------------
105 /// \brief Gives access to serial port in use. 105 /// \brief Gives access to serial port in use.
106 /// Used for other high and low level operations, eg. in *OSTC Planner*. 106 /// Used for other high and low level operations, eg. in *OSTC Planner*.
107 inline Serial& serial() { return _serial; } 107 inline Serial &serial() { return _serial; }
108 108
109 /// \} 109 /// \}
110 ////////////////////////////////////////////////////////////////////////// 110 //////////////////////////////////////////////////////////////////////////
111 /// \name Introspection 111 /// \name Introspection
112 /// \{ 112 /// \{
118 /// \brief Optional features present in the dive computer hardware. 118 /// \brief Optional features present in the dive computer hardware.
119 /// 119 ///
120 /// 8 bit mask. See HardwareDescriptor for known combinations. 120 /// 8 bit mask. See HardwareDescriptor for known combinations.
121 /// 121 ///
122 enum HardwareOption { 122 enum HardwareOption {
123 HW_CHARGEABLE_BATTERY= 0x01, ///< Recharge option. 123 HW_CHARGEABLE_BATTERY = 0x01, ///< Recharge option.
124 HW_LIGHT_SENSOR = 0x02, ///< Detects light level, and tune screen. 124 HW_LIGHT_SENSOR = 0x02, ///< Detects light level, and tune screen.
125 HW_S8_COM = 0x04, ///< Analog connector to O2 cells. 125 HW_S8_COM = 0x04, ///< Analog connector to O2 cells.
126 HW_OPTICAL_COM = 0x08, ///< Digital connector to O2 cells. 126 HW_OPTICAL_COM = 0x08, ///< Digital connector to O2 cells.
127 HW_BLUETOOTH_COM = 0x10, ///< Bluetooth, hence no USB connection. 127 HW_BLUETOOTH_COM = 0x10, ///< Bluetooth, hence no USB connection.
128 HW_DUALCORE = 0x20, ///< Dual core processor. 128 HW_DUALCORE = 0x20, ///< Dual core processor.
129 }; 129 };
130 130
131 ///----------------------------------------------------------------------- 131 ///-----------------------------------------------------------------------
132 /// \brief Dive computer set of features. 132 /// \brief Dive computer set of features.
133 /// 133 ///
136 /// is not a uniq mapping of a given feature set to a dive computer 136 /// is not a uniq mapping of a given feature set to a dive computer
137 /// (eg. 0x13 is ambiguous). 137 /// (eg. 0x13 is ambiguous).
138 /// 138 ///
139 enum HardwareDescriptor { 139 enum HardwareDescriptor {
140 HW_UNKNOWN_OSTC = 0, 140 HW_UNKNOWN_OSTC = 0,
141 HW_Frog = HW_BLUETOOTH_COM, 141 HW_Frog = HW_BLUETOOTH_COM,
142 HW_OSTCSport_a = HW_LIGHT_SENSOR | HW_BLUETOOTH_COM, 142 HW_OSTCSport_a = HW_LIGHT_SENSOR | HW_BLUETOOTH_COM,
143 HW_OSTCSport_b = HW_OSTCSport_a | HW_CHARGEABLE_BATTERY, 143 HW_OSTCSport_b = HW_OSTCSport_a | HW_CHARGEABLE_BATTERY,
144 HW_OSTC2c = HW_CHARGEABLE_BATTERY, 144 HW_OSTC2c = HW_CHARGEABLE_BATTERY,
145 HW_OSTC2_a = HW_CHARGEABLE_BATTERY | HW_BLUETOOTH_COM, 145 HW_OSTC2_a = HW_CHARGEABLE_BATTERY | HW_BLUETOOTH_COM,
146 HW_OSTC2_b = HW_OSTCSport_b, 146 HW_OSTC2_b = HW_OSTCSport_b,
147 HW_OSTC2_c = HW_OSTC2_b | HW_OPTICAL_COM, 147 HW_OSTC2_c = HW_OSTC2_b | HW_OPTICAL_COM,
148 HW_OSTC3 = HW_LIGHT_SENSOR | HW_OPTICAL_COM, 148 HW_OSTC3 = HW_LIGHT_SENSOR | HW_OPTICAL_COM,
149 HW_OSTC3p_a = HW_LIGHT_SENSOR | HW_OPTICAL_COM | HW_BLUETOOTH_COM, 149 HW_OSTC3p_a = HW_LIGHT_SENSOR | HW_OPTICAL_COM | HW_BLUETOOTH_COM,
150 HW_OSTC3p_b = HW_OSTCSport_b, 150 HW_OSTC3p_b = HW_OSTCSport_b,
151 HW_OSTCcR_a = HW_CHARGEABLE_BATTERY | HW_S8_COM, 151 HW_OSTCcR_a = HW_CHARGEABLE_BATTERY | HW_S8_COM,
152 HW_OSTCcR_b = HW_OSTCcR_a | HW_LIGHT_SENSOR, 152 HW_OSTCcR_b = HW_OSTCcR_a | HW_LIGHT_SENSOR,
153 HW_OSTC4 = HW_DUALCORE|HW_BLUETOOTH_COM| 153 HW_OSTC4 = HW_DUALCORE | HW_BLUETOOTH_COM | HW_OPTICAL_COM | HW_LIGHT_SENSOR
154 HW_OPTICAL_COM|HW_LIGHT_SENSOR|HW_CHARGEABLE_BATTERY 154 | HW_CHARGEABLE_BATTERY
155 }; 155 };
156 156
157 //------------------------------------------------------------------------ 157 //------------------------------------------------------------------------
158 /// \brief Ask the connect device for its hardware options. 158 /// \brief Ask the connect device for its hardware options.
159 /// 159 ///
165 /// 165 ///
166 /// Each driver (instance of this class) is requested to tell *Companion* 166 /// Each driver (instance of this class) is requested to tell *Companion*
167 /// what are the supported command. 167 /// what are the supported command.
168 /// 168 ///
169 enum CompanionFeature { 169 enum CompanionFeature {
170 PARAMETERS = (1<<0), ///< Download/Edit/Upload various parameters. 170 PARAMETERS = (1 << 0), ///< Download/Edit/Upload various parameters.
171 DATE = (1<<1), ///< Set date & time. 171 DATE = (1 << 1), ///< Set date & time.
172 NAME = (1<<2), ///< Set custom text displayed on main screen. 172 NAME = (1 << 2), ///< Set custom text displayed on main screen.
173 ICON = (1<<3), ///< Set custom image displayed on main screen. 173 ICON = (1 << 3), ///< Set custom image displayed on main screen.
174 DUMPSCREEN = (1<<4), ///< Makes copy of current screen. 174 DUMPSCREEN = (1 << 4), ///< Makes copy of current screen.
175 FIRMWARE = (1<<5), ///< Do firmware upgrades. 175 FIRMWARE = (1 << 5), ///< Do firmware upgrades.
176 HELIUM_DIVE = (1<<6), ///< Computes deco stops for trimix dives. 176 HELIUM_DIVE = (1 << 6), ///< Computes deco stops for trimix dives.
177 CCR_DIVE = (1<<7), ///< Computes deco stops for rebreather dives. 177 CCR_DIVE = (1 << 7), ///< Computes deco stops for rebreather dives.
178 BLUETOOTH = (1<<8), ///< Use Bluetooh communication (instead of USB) 178 BLUETOOTH = (1 << 8), ///< Use Bluetooh communication (instead of USB)
179 VPM_MODEL = (1<<9), ///< Also propose VPM deco stops. 179 VPM_MODEL = (1 << 9), ///< Also propose VPM deco stops.
180 SIGNAL_CHECK = (1<<10) ///< Echo signal quality for bluetooth computer 180 SIGNAL_CHECK = (1 << 10) ///< Echo signal quality for bluetooth computer
181 }; 181 };
182 Q_DECLARE_FLAGS(CompanionFeatures, CompanionFeature) 182 Q_DECLARE_FLAGS(CompanionFeatures, CompanionFeature)
183 /// \brief Tells what is supported for a given computer. 183 /// \brief Tells what is supported for a given computer.
184 virtual CompanionFeatures supported() const = 0; 184 virtual CompanionFeatures supported() const = 0;
185 185
203 /// 203 ///
204 /// History is a bit complex here, and the published firmware have 204 /// History is a bit complex here, and the published firmware have
205 /// different file formats (due to support tool, and/or need for 205 /// different file formats (due to support tool, and/or need for
206 /// encryption). 206 /// encryption).
207 /// So each driver have to implement its specific loader. 207 /// So each driver have to implement its specific loader.
208 virtual void loadFirmware(HexFile&, const QString& fileName) const = 0; 208 virtual void loadFirmware(HexFile &, const QString &fileName) const = 0;
209 209
210 //------------------------------------------------------------------------ 210 //------------------------------------------------------------------------
211 /// \brief Regular expression to filter *USB* or *Bluetooth* port names. 211 /// \brief Regular expression to filter *USB* or *Bluetooth* port names.
212 /// 212 ///
213 /// Used to propose only the list of ports that matches the serial ports 213 /// Used to propose only the list of ports that matches the serial ports
214 /// compatible with USB/Bluetooth emulation and the connected dive 214 /// compatible with USB/Bluetooth emulation and the connected dive
215 /// computer. 215 /// computer.
216 // virtual QRegExp portTemplate() const = 0; 216 // virtual QRegExp portTemplate() const = 0;
217 virtual QRegularExpression portTemplate() const = 0; 217 virtual QRegularExpression portTemplate() const = 0;
218 /// \} 218 /// \}
219 ////////////////////////////////////////////////////////////////////////// 219 //////////////////////////////////////////////////////////////////////////
220 /// \name High level commands 220 /// \name High level commands
221 /// \{ 221 /// \{
250 /// \brief Echo a message on the connected device screen. 250 /// \brief Echo a message on the connected device screen.
251 /// 251 ///
252 /// Used on most devices to display commands as they are processed, 252 /// Used on most devices to display commands as they are processed,
253 /// so the user can see *OSTC Companion* is working properly, by seeing 253 /// so the user can see *OSTC Companion* is working properly, by seeing
254 /// progress on the dive computer itself. 254 /// progress on the dive computer itself.
255 virtual void writeText(const QString& msg) = 0; 255 virtual void writeText(const QString &msg) = 0;
256 256
257 //------------------------------------------------------------------------ 257 //------------------------------------------------------------------------
258 /// \brief Set HW dive computer date and time. 258 /// \brief Set HW dive computer date and time.
259 virtual void setDate(const QDateTime& date) = 0; 259 virtual void setDate(const QDateTime &date) = 0;
260 260
261 //------------------------------------------------------------------------ 261 //------------------------------------------------------------------------
262 /// \brief Set HW dive computer user text. 262 /// \brief Set HW dive computer user text.
263 virtual void setName(const QString& newName) = 0; 263 virtual void setName(const QString &newName) = 0;
264 264
265 //------------------------------------------------------------------------ 265 //------------------------------------------------------------------------
266 /// \brief Display signal quality at OSTC. 266 /// \brief Display signal quality at OSTC.
267 virtual void getSignal() = 0; 267 virtual void getSignal() = 0;
268 268
269 //------------------------------------------------------------------------ 269 //------------------------------------------------------------------------
270 /// \brief Read all header from OSTC 270 /// \brief Read all header from OSTC
271 virtual void getAllHeader(unsigned char* pBuffer) = 0; 271 virtual void getAllHeader(unsigned char *pBuffer) = 0;
272 272
273 //------------------------------------------------------------------------ 273 //------------------------------------------------------------------------
274 /// \brief Write all header from OSTC 274 /// \brief Write all header from OSTC
275 virtual void writeAllHeader(unsigned char* pBuffer) = 0; 275 virtual void writeAllHeader(unsigned char *pBuffer) = 0;
276
277 276
278 //------------------------------------------------------------------------ 277 //------------------------------------------------------------------------
279 /// \brief Read all samples from OSTC 278 /// \brief Read all samples from OSTC
280 virtual void getAllSamples(unsigned char* pBuffer) = 0; 279 virtual void getAllSamples(unsigned char *pBuffer) = 0;
281 280
282 //------------------------------------------------------------------------ 281 //------------------------------------------------------------------------
283 /// \brief Write all samples to OSTC 282 /// \brief Write all samples to OSTC
284 virtual void writeAllSamples(unsigned char* pBuffer) = 0; 283 virtual void writeAllSamples(unsigned char *pBuffer) = 0;
285 284
286 //------------------------------------------------------------------------ 285 //------------------------------------------------------------------------
287 /// \brief Set HW dive computer icon set 286 /// \brief Set HW dive computer icon set
288 /// 287 ///
289 /// *Currently only supported by Frog dive computer*. 288 /// *Currently only supported by Frog dive computer*.
290 virtual void setIcons(const QString& fileName) = 0; 289 virtual void setIcons(const QString &fileName) = 0;
291 290
292 //------------------------------------------------------------------------ 291 //------------------------------------------------------------------------
293 /// \brief Take a snapshot of the connected computer's screen. 292 /// \brief Take a snapshot of the connected computer's screen.
294 /// 293 ///
295 /// *Currently only supported by OSTC mk2/2n/2c dive computers*. 294 /// *Currently only supported by OSTC mk2/2n/2c dive computers*.
298 //------------------------------------------------------------------------ 297 //------------------------------------------------------------------------
299 /// \brief Upgrade HW dive computer firmware. 298 /// \brief Upgrade HW dive computer firmware.
300 /// 299 ///
301 /// \note needs service mode connection. 300 /// \note needs service mode connection.
302 /// \sa connectServiceMode(). 301 /// \sa connectServiceMode().
303 virtual void upgradeFW(const QString& fileName) = 0; 302 virtual void upgradeFW(const QString &fileName) = 0;
304 303
305 //------------------------------------------------------------------------ 304 //------------------------------------------------------------------------
306 /// \brief Close connection. 305 /// \brief Close connection.
307 /// 306 ///
308 /// Exit service mode, and close everything. 307 /// Exit service mode, and close everything.
336 /// \param [in,out] serial: the connected port to use. 335 /// \param [in,out] serial: the connected port to use.
337 /// \param [in] cmd: command byte to send. 336 /// \param [in] cmd: command byte to send.
338 /// \param [in] retries: Optional max number of retries. Default to 10. 337 /// \param [in] retries: Optional max number of retries. Default to 10.
339 /// 338 ///
340 /// \returns the ack byte (if any), or 0xFF if never received. 339 /// \returns the ack byte (if any), or 0xFF if never received.
341 static unsigned char retryCommand(Serial& serial, 340 static unsigned char retryCommand(Serial &serial, unsigned char cmd, int retries = 10);
342 unsigned char cmd,
343 int retries = 10);
344 341
345 //------------------------------------------------------------------------ 342 //------------------------------------------------------------------------
346 /// \brief Read and check connected dive computer identity. 343 /// \brief Read and check connected dive computer identity.
347 /// 344 ///
348 /// Read fw's version, serial number and custom text from connected computer. 345 /// Read fw's version, serial number and custom text from connected computer.
393 /// \brief List serial ports for USB based devices. 390 /// \brief List serial ports for USB based devices.
394 /// 391 ///
395 /// Ask *OS* for the list of USB serial emulation currently connected whose name 392 /// Ask *OS* for the list of USB serial emulation currently connected whose name
396 /// matches the portTemplate() regular expression. 393 /// matches the portTemplate() regular expression.
397 QStringList listUSBPorts() const; 394 QStringList listUSBPorts() const;
398
399 }; 395 };
400 396
401 #endif // COMPUTEROPERATIONS_H 397 #endif // COMPUTEROPERATIONS_H