view OSTC3Operations.h @ 2:177f640940f2

Update exception class and cleanup redifinitions During firmware download and exception caused the application to stop. Rootcause was the defference between QT5 and QT6 exception and string handling which is updated now. In addition some old definitions were removed to avoid compiler warnings.
author Ideenmodellierer
date Fri, 28 Nov 2025 19:57:35 +0100
parents 0b3630a29ad8
children
line wrap: on
line source

//////////////////////////////////////////////////////////////////////////////
/// \file   OSTC3Operations.h
/// \brief  Implementing various operations for H&W OSTC3 dive computer
/// \author JD Gascuel.
/// \sa     HardwareOperations.h
///
/// \copyright (c) 2011-2016 JD Gascuel. All rights reserved.
/// $Id$
//////////////////////////////////////////////////////////////////////////////
//
// BSD 2-Clause License:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
//    this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
// HISTORY
//  2013-03-17 : [jDG] Creation.
//  2014-07-07 : [jDG] Cleanups for Subsurface google-summer-of-code.
//  2014-07-25 : [jDG] BSD 2-clause license.

#ifndef OSTC3OPERATIONS_H
#define OSTC3OPERATIONS_H

#include "HardwareOperations.h"

//////////////////////////////////////////////////////////////////////////////
/// \brief  Implementing various low-level operations for OSTC3 dive computer
///
/// \sa OSTCSportOperations, OSTC2Operations, OSTC3pOperations,
///     OSTC4Operations, OSTCcROperations.
class  OSTC3Operations
  : public HardwareOperations
{
    //////////////////////////////////////////////////////////////////////////
    /// \{ \section Configuration management.

   // QRegExp portTemplate() const override;
    QRegularExpression portTemplate() const override;
    QStringList listPorts() const override;
    QString model() const override;
    QString description() override;
    CompanionFeatures supported() const override;

    /// \}
    //////////////////////////////////////////////////////////////////////////
protected:

    //------------------------------------------------------------------------
    /// \brief Erase OSTC3 PROM memory.
    /// PROM memory should be erased beforeprogramming the new firmware.
    /// This command is used to erase a set of 4KB pages.
    /// \param[in] addr: First address (24bits) to erase. Should be a multiple of 4096.
    /// \param[in] size: Number of bytes to erase. Will be rounded (up) to a multiple of 4096.
    /// \throws if something goes wrong.
    void eraseRange(unsigned int addr, unsigned int size);

    //------------------------------------------------------------------------
    /// \brief Write a big block of bytes to OSTC3 RAM memory.
    ///
    /// \param[in] addr: First address (24bits) to write to.
    /// \param[in] data: Bytes to write.
    /// \param[in] size: Number of bytes to write.
    /// \throws if something goes wrong.
    void writeBlock(unsigned int addr,
                    const unsigned char *data, unsigned int size);

    //------------------------------------------------------------------------
    /// \brief Read-back a big block of bytes from OSTC3 RAM memory.
    ///
    /// \param[in] addr: First address (24bits) to read from.
    /// \param[in] ptr : Where to store bytes read.
    /// \param[in] size: Number of bytes to read.
    /// \throws if something goes wrong.
    void readBlock (unsigned int addr, unsigned char *ptr, unsigned int size);

    //------------------------------------------------------------------------
    /// \brief Burn firmare.
    ///
    /// Firmware should be first uploaded to RAM memory (\sa writeBlock() ),
    /// in area 0x3E0000 .. 0x3FE000,
    /// then the firmware command will tell the OSTC3 to use that to reprogramm
    /// itself.
    /// A validation checksum is done to make sure a valid data have been
    /// uploaded.
    ///
    /// \param[in] checksum: Adler32 checksum of the new firmware.
    /// \throws if something goes wrong.
    void upgradeFirmware(unsigned int checksum);

public:
    OSTC3Operations();
    ~OSTC3Operations();

    /// \brief The fw version found during the last getIdentty().
    int firmware() const override;

    /// \brief The serial number found during the last getIdentty().
    int serialNumber() const override;

    /// \brief The user-defined string found during the last getIdentty().
    QString customText() const override;

    //////////////////////////////////////////////////////////////////////////
    /// \{ \section OSTC3 low-level service mode commands.
    ///
    /// Low level commands are used to directly speak to the OSTC3 firmware.
    /// They all throw an Exception if some error occurs.

    //------------------------------------------------------------------------
    /// \brief Custom text size (lines and columns).
    QSize nameSize() const override;

    //------------------------------------------------------------------------
    /// \brief Read OSTC3 computer firmware, serial and custom text.
    /// Everything is formated for the description() string.
    /// \throws if something goes wrong.
    void getIdentity() override;

    //------------------------------------------------------------------------
    /// \brief Display a short text on OSTC3 while on service mode.
    /// OSTC3 can handle 16 chars. So the string is automatically
    /// padded with spaces to clean any leftover.
    /// \throws if something goes wrong.
    void writeText(const QString &msg) override;

    QString firmwareTemplate() const override;

    /// \}
    //////////////////////////////////////////////////////////////////////////
    /// \{ \section OSTC3 high-level commands.

    bool connect() override;
    bool disconnect(bool closing = false) override;
    void setDate(const QDateTime& date) override;
    void setName(const QString& newName) override;
    void getSignal() override;
    void getAllHeader(unsigned char* pBuffer) override;
    void writeAllHeader(unsigned char* pBuffer) override;
    void getAllSamples(unsigned char* pBuffer) override;
    void writeAllSamples(unsigned char* pBuffer) override;
    void setIcons(const QString& fileName) override;
    QImage dumpScreen() const override;
    void upgradeFW(const QString& fileName) override;

    void loadFirmware(HexFile& hex, const QString& fileName) const override;

    /// \}

    //////////////////////////////////////////////////////////////////////////
protected:
    QString     descriptionString;
    QString     emulatorName;
    char        computerText[60];

    virtual void getCommonIdentity();

    void connectServiceMode() override;

    //////////////////////////////////////////////////////////////////////////
private:
    unsigned short _computerFirmware;
    unsigned short _computerSerial;

protected:
    enum Mode {
        CLOSED_MODE = 0,        ///< Not yet open.
        DOWNLOAD_MODE,          ///< Open in normal mode.
        SERVICE_MODE            ///< Open in FIRMWARE UPGRADE mode.
    } _connectMode;
};

#endif // OSTC3OPERATIONS_H