// bytran -|- spectral calculations for portable devices using the HITRAN database
//
// Developed by Dzianis Pliutau (Denis Plutov) and Kostya Roslyakov
// www.bytran.org | bytran@bytran.org
// Copyright (c) 2016 Dzianis Pliutau
// Distributed under the MIT license
//
// The MIT License (MIT)
// Copyright (c) 2016 Dzianis Pliutau
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



// Object to carry out serial port communication with an external device
#ifndef SERIALPORTQML_H
#define SERIALPORTQML_H

#include <QObject>
#include "bytrancore.h"

class SerialPortQml : public QObject
{
    Q_OBJECT

    Q_PROPERTY (int portIndex READ portIndex WRITE setPortIndex NOTIFY portIndexChanged)
    Q_PROPERTY (int baudRate READ baudRate WRITE setBaudRate NOTIFY baudRateChanged)
    Q_PROPERTY (int parity READ parity WRITE setParity NOTIFY parityChanged)
    Q_PROPERTY (int dataBits READ dataBits WRITE setDataBits NOTIFY dataBitsChanged)
    Q_PROPERTY (int stopBits READ stopBits WRITE setStopBits NOTIFY stopBitsChanged)

public:

    explicit SerialPortQml(QObject *parent = nullptr, BytranCore *inCore = 0);

    int portIndex() const;
    void setPortIndex(const int portIndex);
    int baudRate() const;
    void setBaudRate(const int baudRateIndex);
    int parity() const;
    void setParity(const int parity);
    int dataBits() const;
    void setDataBits(const int dataBits);
    int stopBits() const;
    void setStopBits(const int stopBits);

signals:

    void portIndexChanged();
    void baudRateChanged();
    void parityChanged();
    void dataBitsChanged();
    void stopBitsChanged();

public slots:

private:

    // Core object with the calculation logic etc.
    BytranCore *core;

    // Local variables
    int m_portIndex;  // Port index corresponding to the listing of available serial ports
    int m_baudRate;   // Baud rate: 0 - 115200, 1 - 57600, 2 - 38400, 3 - 19200, 4 - 9600, 5 - 4800, 6 - 2400, 7 - 1200
    int m_parity;     // 0 - none, 1 - odd, 2 - even, 3 - mark, 4 - space
    int m_dataBits;   // Number of data bits, 8 is the default
    int m_stopBits;   // Number of stop bits, 0 is the default

};

#endif // SERIALPORTQML_H
