// 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
#include "serialportqml.h"

SerialPortQml::SerialPortQml(QObject *parent, BytranCore *inCore) : QObject(parent)
{
    // Trasfering the core object into the internal variable
    core = inCore;

    // Saving the default serial port configuration parameters into the local variables
    m_portIndex = core->getRemoteControl()->getSerialPort()->getPortIndex();
    m_baudRate = core->getRemoteControl()->getSerialPort()->getBaudRate();
    m_parity = core->getRemoteControl()->getSerialPort()->getParity();
    m_stopBits = core->getRemoteControl()->getSerialPort()->getStopBits();
    m_dataBits = core->getRemoteControl()->getSerialPort()->getDataBits();
}

int SerialPortQml::portIndex() const { return core->getRemoteControl()->getSerialPort()->getPortIndex(); }
void SerialPortQml::setPortIndex(const int portIndex)
{
    if (portIndex != m_portIndex)
    {
        m_portIndex = portIndex;
        core->getRemoteControl()->getSerialPort()->setPortIndex(m_portIndex);
        emit portIndexChanged();
    }
}

int SerialPortQml::baudRate() const { return core->getRemoteControl()->getSerialPort()->getBaudRate(); }
void SerialPortQml::setBaudRate(const int baudRate)
{
    if (baudRate != m_baudRate)
    {
        m_baudRate = baudRate;
        core->getRemoteControl()->getSerialPort()->setBaudRate(m_baudRate);
        emit baudRateChanged();
    }
}

int SerialPortQml::parity() const { return core->getRemoteControl()->getSerialPort()->getParity(); }
void SerialPortQml::setParity(const int parity)
{
    if (parity != m_parity)
    {
        m_parity = parity;
        core->getRemoteControl()->getSerialPort()->setParity(m_parity);
        emit parityChanged();
    }
}

int SerialPortQml::dataBits() const { return core->getRemoteControl()->getSerialPort()->getDataBits(); }
void SerialPortQml::setDataBits(const int dataBits)
{
    if (dataBits != m_dataBits)
    {
        m_dataBits = dataBits;
        core->getRemoteControl()->getSerialPort()->setDataBits(m_dataBits);
        emit dataBitsChanged();
    }
}

int SerialPortQml::stopBits() const { return core->getRemoteControl()->getSerialPort()->getStopBits(); }
void SerialPortQml::setStopBits(const int stopBits)
{
    if (stopBits != m_stopBits)
    {
        m_stopBits = stopBits;
        core->getRemoteControl()->getSerialPort()->setStopBits(m_stopBits);
        emit stopBitsChanged();
    }
}
