#include "PhaseDataDto.h"

PhaseDataDto::PhaseDataDto(QObject *parent) : QObject(parent)
{

}

QJsonObject PhaseDataDto::toJSON(int i)
{
    QJsonObject jsonObj;

    QJsonObject dataObj;
    dataObj.insert("dataValue", this->channelDataStr.at(i));
    dataObj.insert("rawValue", channelRawDataStr.at(i));
    dataObj.insert("frameId", this->frameId);

    jsonObj.insert("channelNo", (i + 1));
    jsonObj.insert("ts", (this->milisecond / 1000) * 1000);
    jsonObj.insert("data", dataObj);

    return jsonObj;
}

QJsonObject PhaseDataDto::toStatusJSON()
{
    QJsonObject jsonObj;

    QJsonObject dataObj;
    QJsonArray channelActiveArray;
    for (int i = 0; i < channelActive.size(); i++)
    {
        channelActiveArray.append(channelActive.at(i));
    }
    dataObj.insert("channelActive", channelActiveArray);
    dataObj.insert("devStatus", "1");

    jsonObj.insert("ts", (this->milisecond / 1000) * 1000);
    jsonObj.insert("frameType", "0201");
    jsonObj.insert("data", dataObj);

    return jsonObj;
}
