#include "AvReceiverInterface.h"
#include "ProtocolDefs.h"
#include "AVReceiverDevice.h"

CAvReceiverInterface::CAvReceiverInterface(int Address, CAbstractNetworkCommIF *NetworkInterface , CAVReceiverDevice *DevicePtr):
     CNetworkDevice(ID_AVRECEIVER_INTERFACE,Address,NetworkInterface)
{
    mAvReceiverDevice = DevicePtr;
}

int CAvReceiverInterface::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data)
{
    Q_UNUSED(DeviceID)
    Q_UNUSED(DeviceAddress)
    Q_UNUSED(DataSize)
    Q_UNUSED(Data)

      switch(MessageID)
    {
          case AV_RECEIVER_INTERFACE_ACK:
          {
              break;
          }
          case AV_RECEIVER_INTERFACE_GENERAL_STATUS_REQUEST:
          {
              QByteArray data = mAvReceiverDevice->GetReceiverStatus().ToByteArray();
              mNetworkInterfacePtr->SendNetworkMessage(ID_AVRECEIVER_INTERFACE,mDeviceAddress,AV_RECEIVER_INTERFACE_GENERAL_STATUS_RESPONSE,data.size(),data);
              break;
          }

          case AV_RECEIVER_INTERFACE_SET_MAIN_POWER_REQUEST:
          {
              break;
          }
          case AV_RECEIVER_INTERFACE_SET_SPEAKERB_REQUEST:
          {
              bool SpkStatus = (bool)Data[0];
              mAvReceiverDevice->SetSpeakerB(SpkStatus);
              break;
          }
          case AV_RECEIVER_INTERFACE_SET_SPEAKERA_REQUEST:
          {
              bool SpkStatus = (bool)Data[0];
              mAvReceiverDevice->SetSpeakerA(SpkStatus);
              break;

          }
          case AV_RECEIVER_INTERFACE_SET_SPEAKERS_REQUEST:
          {
                break;
          }
          case AV_RECEIVER_INTERFACE_SEND_DIRECT_CMD_REQUEST:
          {
              break;
          }
          case AV_RECEIVER_INTERFACE_GENERAL_STATUS_RESPONSE:
          case AV_RECEIVER_INTERFACE_SET_MAIN_POWER_RESPONSE:
          case AV_RECEIVER_INTERFACE_SET_SPEAKERB_RESPONSE:
          case AV_RECEIVER_INTERFACE_SEND_DIRECT_CMD_RESPONSE:
          case AV_RECEIVER_INTERFACE_SET_SPEAKERS_RESPONSE:
          case AV_RECEIVER_INTERFACE_SET_SPEAKERA_RESPONSE:
          default:
          {
              qDebug("Received invalid msg from Sprinkler Interface");
              break;
          }
      }

    return 0;

}
