/*
 * SmartHome server: Plug-in x10
 *
 * Copyright (C) 2010 Daniel Pisi <dan.pisi@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License
 * as published by the Free Software Foundation.
 *
 */

/**
 * @file x10packet.h
 * @brief Stores one X10 packet
 * @author Daniel Pisi
 */

#ifndef X10PACKET_H
#define X10PACKET_H

#include <QtCore/QCoreApplication>
#include <QByteArray>
#include <QSharedPointer>

// -----------------------------------------------------------------------------

class X10Packet;

typedef QSharedPointer<X10Packet> X10PacketPtr;

// -----------------------------------------------------------------------------

/**
 * \class X10Packet
 * \brief Stores one X10 packet
 */
class X10Packet
{
public:
    enum X10Function
    {
        fcAllUnitsOff = 0, fcAllLightsOn = 1, fcAllLightsOff = 6,
        fcOn = 2, fcOff = 3,
        fcDim = 4, fcBright = 5,
        fcHailRequest = 8, fcHailAck = 9,
        fcPresetDim1 = 10, fcPresetDim2 = 11,
        fcExCode = 7, fcExData = 12,
        fcStatOn = 13, fcStatOff = 14, fcStatRequest = 15
    };

    X10Packet();

    bool setHousecode(quint8 housecode);
    bool setDevicecode(quint8 devicecode);
    bool setFunction(X10Function function);
    bool setDimAmount(quint8 dim);

    quint8 housecode() { return mHousecode; };
    quint8 dimAmount() { return mDimAmount; };

    QByteArray frameData();
    quint8 checksum();

private:
    quint8 mDimAmount;
    bool   mFa, mEs;
    quint8 mHousecode;
    quint8 mData;
    quint8 mChecksum;
    bool   mModified;
};
// -----------------------------------------------------------------------------

#endif // X10PACKET_H
