Mercurial > public > ostc_companion
comparison OSTC3Operations.h @ 1:0b3630a29ad8
Initial version based on previous repository.
Project was ported to QT6 and in now cmake based.
| author | Ideenmodellierer <tiefenrauscher@web.de> |
|---|---|
| date | Thu, 27 Nov 2025 18:40:28 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:76ccd6ce50c0 | 1:0b3630a29ad8 |
|---|---|
| 1 ////////////////////////////////////////////////////////////////////////////// | |
| 2 /// \file OSTC3Operations.h | |
| 3 /// \brief Implementing various operations for H&W OSTC3 dive computer | |
| 4 /// \author JD Gascuel. | |
| 5 /// \sa HardwareOperations.h | |
| 6 /// | |
| 7 /// \copyright (c) 2011-2016 JD Gascuel. All rights reserved. | |
| 8 /// $Id$ | |
| 9 ////////////////////////////////////////////////////////////////////////////// | |
| 10 // | |
| 11 // BSD 2-Clause License: | |
| 12 // | |
| 13 // Redistribution and use in source and binary forms, with or without | |
| 14 // modification, are permitted provided that the following conditions | |
| 15 // are met: | |
| 16 // | |
| 17 // 1. Redistributions of source code must retain the above copyright notice, | |
| 18 // this list of conditions and the following disclaimer. | |
| 19 // | |
| 20 // 2. Redistributions in binary form must reproduce the above copyright notice, | |
| 21 // this list of conditions and the following disclaimer in the documentation | |
| 22 // and/or other materials provided with the distribution. | |
| 23 // | |
| 24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 25 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 26 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 27 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
| 28 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 29 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 30 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 31 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 32 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 33 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
| 34 // THE POSSIBILITY OF SUCH DAMAGE. | |
| 35 // | |
| 36 ////////////////////////////////////////////////////////////////////////////// | |
| 37 // HISTORY | |
| 38 // 2013-03-17 : [jDG] Creation. | |
| 39 // 2014-07-07 : [jDG] Cleanups for Subsurface google-summer-of-code. | |
| 40 // 2014-07-25 : [jDG] BSD 2-clause license. | |
| 41 | |
| 42 #ifndef OSTC3OPERATIONS_H | |
| 43 #define OSTC3OPERATIONS_H | |
| 44 | |
| 45 #include "HardwareOperations.h" | |
| 46 | |
| 47 ////////////////////////////////////////////////////////////////////////////// | |
| 48 /// \brief Implementing various low-level operations for OSTC3 dive computer | |
| 49 /// | |
| 50 /// \sa OSTCSportOperations, OSTC2Operations, OSTC3pOperations, | |
| 51 /// OSTC4Operations, OSTCcROperations. | |
| 52 class OSTC3Operations | |
| 53 : public HardwareOperations | |
| 54 { | |
| 55 ////////////////////////////////////////////////////////////////////////// | |
| 56 /// \{ \section Configuration management. | |
| 57 | |
| 58 // QRegExp portTemplate() const override; | |
| 59 QRegularExpression portTemplate() const override; | |
| 60 QStringList listPorts() const override; | |
| 61 QString model() const override; | |
| 62 QString description() override; | |
| 63 CompanionFeatures supported() const override; | |
| 64 | |
| 65 /// \} | |
| 66 ////////////////////////////////////////////////////////////////////////// | |
| 67 protected: | |
| 68 | |
| 69 //------------------------------------------------------------------------ | |
| 70 /// \brief Erase OSTC3 PROM memory. | |
| 71 /// PROM memory should be erased beforeprogramming the new firmware. | |
| 72 /// This command is used to erase a set of 4KB pages. | |
| 73 /// \param[in] addr: First address (24bits) to erase. Should be a multiple of 4096. | |
| 74 /// \param[in] size: Number of bytes to erase. Will be rounded (up) to a multiple of 4096. | |
| 75 /// \throws if something goes wrong. | |
| 76 void eraseRange(unsigned int addr, unsigned int size); | |
| 77 | |
| 78 //------------------------------------------------------------------------ | |
| 79 /// \brief Write a big block of bytes to OSTC3 RAM memory. | |
| 80 /// | |
| 81 /// \param[in] addr: First address (24bits) to write to. | |
| 82 /// \param[in] data: Bytes to write. | |
| 83 /// \param[in] size: Number of bytes to write. | |
| 84 /// \throws if something goes wrong. | |
| 85 void writeBlock(unsigned int addr, | |
| 86 const unsigned char *data, unsigned int size); | |
| 87 | |
| 88 //------------------------------------------------------------------------ | |
| 89 /// \brief Read-back a big block of bytes from OSTC3 RAM memory. | |
| 90 /// | |
| 91 /// \param[in] addr: First address (24bits) to read from. | |
| 92 /// \param[in] ptr : Where to store bytes read. | |
| 93 /// \param[in] size: Number of bytes to read. | |
| 94 /// \throws if something goes wrong. | |
| 95 void readBlock (unsigned int addr, unsigned char *ptr, unsigned int size); | |
| 96 | |
| 97 //------------------------------------------------------------------------ | |
| 98 /// \brief Burn firmare. | |
| 99 /// | |
| 100 /// Firmware should be first uploaded to RAM memory (\sa writeBlock() ), | |
| 101 /// in area 0x3E0000 .. 0x3FE000, | |
| 102 /// then the firmware command will tell the OSTC3 to use that to reprogramm | |
| 103 /// itself. | |
| 104 /// A validation checksum is done to make sure a valid data have been | |
| 105 /// uploaded. | |
| 106 /// | |
| 107 /// \param[in] checksum: Adler32 checksum of the new firmware. | |
| 108 /// \throws if something goes wrong. | |
| 109 void upgradeFirmware(unsigned int checksum); | |
| 110 | |
| 111 public: | |
| 112 OSTC3Operations(); | |
| 113 ~OSTC3Operations(); | |
| 114 | |
| 115 /// \brief The fw version found during the last getIdentty(). | |
| 116 int firmware() const override; | |
| 117 | |
| 118 /// \brief The serial number found during the last getIdentty(). | |
| 119 int serialNumber() const override; | |
| 120 | |
| 121 /// \brief The user-defined string found during the last getIdentty(). | |
| 122 QString customText() const override; | |
| 123 | |
| 124 ////////////////////////////////////////////////////////////////////////// | |
| 125 /// \{ \section OSTC3 low-level service mode commands. | |
| 126 /// | |
| 127 /// Low level commands are used to directly speak to the OSTC3 firmware. | |
| 128 /// They all throw an Exception if some error occurs. | |
| 129 | |
| 130 //------------------------------------------------------------------------ | |
| 131 /// \brief Custom text size (lines and columns). | |
| 132 QSize nameSize() const override; | |
| 133 | |
| 134 //------------------------------------------------------------------------ | |
| 135 /// \brief Read OSTC3 computer firmware, serial and custom text. | |
| 136 /// Everything is formated for the description() string. | |
| 137 /// \throws if something goes wrong. | |
| 138 void getIdentity() override; | |
| 139 | |
| 140 //------------------------------------------------------------------------ | |
| 141 /// \brief Display a short text on OSTC3 while on service mode. | |
| 142 /// OSTC3 can handle 16 chars. So the string is automatically | |
| 143 /// padded with spaces to clean any leftover. | |
| 144 /// \throws if something goes wrong. | |
| 145 void writeText(const QString &msg) override; | |
| 146 | |
| 147 QString firmwareTemplate() const override; | |
| 148 | |
| 149 /// \} | |
| 150 ////////////////////////////////////////////////////////////////////////// | |
| 151 /// \{ \section OSTC3 high-level commands. | |
| 152 | |
| 153 bool connect() override; | |
| 154 bool disconnect(bool closing = false) override; | |
| 155 void setDate(const QDateTime& date) override; | |
| 156 void setName(const QString& newName) override; | |
| 157 void getSignal() override; | |
| 158 void getAllHeader(unsigned char* pBuffer) override; | |
| 159 void writeAllHeader(unsigned char* pBuffer) override; | |
| 160 void getAllSamples(unsigned char* pBuffer) override; | |
| 161 void writeAllSamples(unsigned char* pBuffer) override; | |
| 162 void setIcons(const QString& fileName) override; | |
| 163 QImage dumpScreen() const override; | |
| 164 void upgradeFW(const QString& fileName) override; | |
| 165 | |
| 166 void loadFirmware(HexFile& hex, const QString& fileName) const override; | |
| 167 | |
| 168 /// \} | |
| 169 | |
| 170 ////////////////////////////////////////////////////////////////////////// | |
| 171 protected: | |
| 172 QString descriptionString; | |
| 173 QString emulatorName; | |
| 174 char computerText[60]; | |
| 175 | |
| 176 virtual void getCommonIdentity(); | |
| 177 | |
| 178 void connectServiceMode() override; | |
| 179 | |
| 180 ////////////////////////////////////////////////////////////////////////// | |
| 181 private: | |
| 182 unsigned short _computerFirmware; | |
| 183 unsigned short _computerSerial; | |
| 184 | |
| 185 protected: | |
| 186 enum Mode { | |
| 187 CLOSED_MODE = 0, ///< Not yet open. | |
| 188 DOWNLOAD_MODE, ///< Open in normal mode. | |
| 189 SERVICE_MODE ///< Open in FIRMWARE UPGRADE mode. | |
| 190 } _connectMode; | |
| 191 }; | |
| 192 | |
| 193 #endif // OSTC3OPERATIONS_H |
