Beaucoup de dev... début de LoraModuleInterface
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "AVReceiverDevice.h"
|
||||
#include "GlobalDefine.h"
|
||||
#include "ProtocolDefs.h"
|
||||
#include <QDataStream>
|
||||
|
||||
|
||||
/**
|
||||
@@ -46,7 +47,8 @@ CAVReceiverDevice::CAVReceiverDevice()
|
||||
CAVReceiverDevice::~CAVReceiverDevice()
|
||||
{
|
||||
mReceiverSocket->disconnectFromHost();
|
||||
mReceiverSocket->waitForDisconnected();
|
||||
mReceiverSocket->waitForDisconnected(100);
|
||||
|
||||
delete mReceiverSocket;
|
||||
delete mDisconnectTimer;
|
||||
delete mStateRequestTimer;
|
||||
@@ -113,27 +115,36 @@ int CAVReceiverDevice::AnalyseRxData(QByteArray data)
|
||||
int CAVReceiverDevice::UpdateReceiverStateParam(QString SubUnit, QString Fcn, QString Param)
|
||||
{
|
||||
static bool AllValid = false;
|
||||
|
||||
CAvReceiverMainStatus *UnitStatus = 0;
|
||||
if(SubUnit == "MAIN")
|
||||
{
|
||||
UnitStatus = &mReceiverStatus;
|
||||
}
|
||||
else if(SubUnit == "ZONE2")
|
||||
{
|
||||
UnitStatus = &mZone2Status;
|
||||
}
|
||||
|
||||
if(UnitStatus != 0)
|
||||
{
|
||||
if(Fcn == "PWR")
|
||||
{
|
||||
if(Param == "On")
|
||||
{
|
||||
mReceiverStatus.mMainPwrStatus = true;
|
||||
UnitStatus->mMainPwrStatus = true;
|
||||
}
|
||||
else
|
||||
mReceiverStatus.mMainPwrStatus = false;
|
||||
UnitStatus->mMainPwrStatus = false;
|
||||
}
|
||||
if(Fcn == "SLEEP")
|
||||
{
|
||||
if(Param == "On")
|
||||
{
|
||||
mReceiverStatus.mMainSleepStatus = true;
|
||||
UnitStatus->mMainSleepStatus = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mReceiverStatus.mMainSleepStatus = false;
|
||||
UnitStatus->mMainSleepStatus = false;
|
||||
}
|
||||
}
|
||||
else if(Fcn == "VOL")
|
||||
@@ -142,53 +153,31 @@ int CAVReceiverDevice::UpdateReceiverStateParam(QString SubUnit, QString Fcn, QS
|
||||
float Vol = Param.toFloat(&OK);
|
||||
if(OK)
|
||||
{
|
||||
mReceiverStatus.mMainVolume = Vol;
|
||||
UnitStatus->mMainVolume = Vol;
|
||||
}
|
||||
else
|
||||
{
|
||||
mReceiverStatus.mMainPwrStatus = 0xDEADBEEF;
|
||||
UnitStatus->mMainPwrStatus = 0xDEADBEEF;
|
||||
}
|
||||
}
|
||||
else if(Fcn == "MUTE")
|
||||
{
|
||||
if(Param == "On")
|
||||
{
|
||||
mReceiverStatus.mIsMute = true;
|
||||
UnitStatus->mIsMute = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mReceiverStatus.mIsMute = false;
|
||||
UnitStatus->mIsMute = false;
|
||||
}
|
||||
}
|
||||
else if (Fcn == "INP")
|
||||
{
|
||||
mReceiverStatus.mInput = Param;
|
||||
UnitStatus->mInput = Param;
|
||||
}
|
||||
else if (Fcn == "SOUNDPRG")
|
||||
{
|
||||
mReceiverStatus.mProgram = Param;
|
||||
}
|
||||
else if(Fcn == "SPEAKERA")
|
||||
{
|
||||
if(Param == "On")
|
||||
{
|
||||
mReceiverStatus.mSpeakerAState = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mReceiverStatus.mSpeakerAState = false;
|
||||
}
|
||||
}
|
||||
else if(Fcn == "SPEAKERB")
|
||||
{
|
||||
if(Param == "On")
|
||||
{
|
||||
mReceiverStatus.mSpeakerBState = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mReceiverStatus.mSpeakerBState = false;
|
||||
}
|
||||
UnitStatus->mProgram = Param;
|
||||
}
|
||||
}
|
||||
return RET_OK;
|
||||
@@ -197,9 +186,10 @@ int CAVReceiverDevice::UpdateReceiverStateParam(QString SubUnit, QString Fcn, QS
|
||||
int CAVReceiverDevice::SendReceiverCommand(QString Command)
|
||||
{
|
||||
//Make sure the escape sequence is correct.
|
||||
Command.remove("\r");
|
||||
Command.remove("\n");
|
||||
Command.append("\r\n");
|
||||
// Command.remove("\r");
|
||||
// Command.remove("\n");
|
||||
// Command.append("\r\n");
|
||||
|
||||
|
||||
if(mReceiverSocket->state() == QAbstractSocket::ConnectedState)
|
||||
{
|
||||
@@ -265,7 +255,7 @@ void CAVReceiverDevice::StateRequestTimerExpired()
|
||||
{
|
||||
if(mReceiverSocket->state() != QAbstractSocket::ConnectedState)
|
||||
{
|
||||
SendReceiverCommand("@MAIN:BASIC=?");
|
||||
SendReceiverCommand("@MAIN:BASIC=?\r\n@ZONE2:BASIC=?\r\n");
|
||||
mStateRequestTimer->start(RECEIVER_STATE_UPDATE_TIMEOUT);
|
||||
DisconnectReceiverDelayed(1000);
|
||||
}
|
||||
@@ -278,30 +268,30 @@ void CAVReceiverDevice::StateRequestTimerExpired()
|
||||
|
||||
////// Network Interface Implementation
|
||||
|
||||
int CAVReceiverDevice::SetSpeakerB(bool OnOff)
|
||||
int CAVReceiverDevice::SetZone2(bool OnOff)
|
||||
{
|
||||
QString Cmd = "@MAIN:SPEAKERB=";
|
||||
QString Cmd = "@ZONE2:PWR=";
|
||||
if(OnOff)
|
||||
{
|
||||
Cmd += "On";
|
||||
Cmd += "On\r\n";
|
||||
}
|
||||
else
|
||||
Cmd += "Off";
|
||||
Cmd += "Standby\r\n";
|
||||
|
||||
SendReceiverCommand(Cmd);
|
||||
DisconnectReceiverDelayed();
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CAVReceiverDevice::SetSpeakerA(bool OnOff)
|
||||
int CAVReceiverDevice::SetMainZone(bool OnOff)
|
||||
{
|
||||
QString Cmd = "@MAIN:SPEAKERA=";
|
||||
QString Cmd = "@MAIN:PWR=";
|
||||
if(OnOff)
|
||||
{
|
||||
Cmd += "On";
|
||||
Cmd += "On\r\n";
|
||||
}
|
||||
else
|
||||
Cmd += "Off";
|
||||
Cmd += "Standby\r\n";
|
||||
|
||||
SendReceiverCommand(Cmd);
|
||||
DisconnectReceiverDelayed();
|
||||
@@ -315,22 +305,22 @@ int CAVReceiverDevice::SetSpeakers(int SpeakerA, int SpeakerB)
|
||||
QString Cmd = "@MAIN:SPEAKERA=";
|
||||
if(SpeakerA == RECEIVER_SET_SPK_ON)
|
||||
{
|
||||
Cmd += "On";
|
||||
Cmd += "On\r\n";
|
||||
}
|
||||
else if(SpeakerA == RECEIVER_SET_SPK_OFF)
|
||||
{
|
||||
Cmd += "Off";
|
||||
Cmd += "Off\r\n";
|
||||
}
|
||||
else if(SpeakerA == RECEVIVER_TOGGLE_SPK)
|
||||
{
|
||||
if(mReceiverStatus.mSpeakerAState == true)
|
||||
{
|
||||
Cmd += "Off";
|
||||
}
|
||||
else
|
||||
{
|
||||
Cmd += "On";
|
||||
}
|
||||
// if(mReceiverStatus.mSpeakerAState == true)
|
||||
// {
|
||||
// Cmd += "Off";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Cmd += "On";
|
||||
// }
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -354,14 +344,14 @@ int CAVReceiverDevice::SetSpeakers(int SpeakerA, int SpeakerB)
|
||||
}
|
||||
else if(SpeakerB == RECEVIVER_TOGGLE_SPK)
|
||||
{
|
||||
if(mReceiverStatus.mSpeakerAState == true)
|
||||
{
|
||||
Cmd += "Off";
|
||||
}
|
||||
else
|
||||
{
|
||||
Cmd += "On";
|
||||
}
|
||||
// if(mReceiverStatus.mSpeakerAState == true)
|
||||
// {
|
||||
// Cmd += "Off";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Cmd += "On";
|
||||
// }
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -382,3 +372,16 @@ int CAVReceiverDevice::SendRawCommand(QString Cmd)
|
||||
|
||||
}
|
||||
|
||||
QByteArray CAVReceiverDevice::GetReceiverStatus()
|
||||
{
|
||||
QByteArray StatusArray;
|
||||
QDataStream Strm(&StatusArray,QIODevice::WriteOnly | QIODevice::Unbuffered);
|
||||
Strm.device()->seek(0);
|
||||
|
||||
Strm << mReceiverStatus
|
||||
<< mZone2Status ;
|
||||
|
||||
|
||||
return StatusArray;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,17 +67,18 @@ private:
|
||||
|
||||
public:
|
||||
//Network Interface Implementation
|
||||
int SetSpeakerB(bool OnOff);
|
||||
int SetSpeakerA(bool OnOff);
|
||||
int SetZone2(bool OnOff);
|
||||
int SetMainZone(bool OnOff);
|
||||
int SetSpeakers(int SpeakerA, int SpeakerB);
|
||||
int SendRawCommand(QString Cmd);
|
||||
CAvReceiverMainStatus GetReceiverStatus(){return mReceiverStatus;}
|
||||
QByteArray GetReceiverStatus();
|
||||
|
||||
private:
|
||||
QTcpSocket *mReceiverSocket;
|
||||
int AnalyseRxData(QByteArray data);
|
||||
QTimer *mDisconnectTimer, *mStateRequestTimer;
|
||||
CAvReceiverMainStatus mReceiverStatus;
|
||||
CAvReceiverMainStatus mZone2Status;
|
||||
|
||||
bool mIsConnected;
|
||||
QString mPendingCommand;
|
||||
|
||||
@@ -20,8 +20,6 @@ QByteArray CAvReceiverMainStatus::ToByteArray()
|
||||
Strm << mIsMute;
|
||||
Strm << mInput;
|
||||
Strm << mProgram;
|
||||
Strm << mSpeakerAState;
|
||||
Strm << mSpeakerBState;
|
||||
|
||||
Strm << mDataValid;
|
||||
Strm << mReceiverOnline;
|
||||
@@ -41,8 +39,6 @@ int CAvReceiverMainStatus::FromByteArray(QByteArray Data)
|
||||
Strm >> mIsMute;
|
||||
Strm >> mInput;
|
||||
Strm >> mProgram;
|
||||
Strm >> mSpeakerAState;
|
||||
Strm >> mSpeakerBState;
|
||||
|
||||
Strm >> mDataValid;
|
||||
Strm >> mReceiverOnline;
|
||||
@@ -50,3 +46,29 @@ int CAvReceiverMainStatus::FromByteArray(QByteArray Data)
|
||||
return RET_OK;
|
||||
|
||||
}
|
||||
QDataStream &operator<<(QDataStream &out, const CAvReceiverMainStatus &source)
|
||||
{
|
||||
out << source.mMainPwrStatus
|
||||
<< source.mMainSleepStatus
|
||||
<< source.mMainVolume
|
||||
<< source.mIsMute
|
||||
<< source.mInput
|
||||
<< source.mProgram
|
||||
<< source.mDataValid
|
||||
<< source.mReceiverOnline;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &in, CAvReceiverMainStatus &dest)
|
||||
{
|
||||
in >> dest.mMainPwrStatus
|
||||
>> dest.mMainSleepStatus
|
||||
>> dest.mMainVolume
|
||||
>> dest.mIsMute
|
||||
>> dest.mInput
|
||||
>> dest.mProgram
|
||||
>> dest.mDataValid
|
||||
>> dest.mReceiverOnline;
|
||||
return in;
|
||||
}
|
||||
|
||||
@@ -19,12 +19,13 @@ public:
|
||||
bool mIsMute;
|
||||
QString mInput;
|
||||
QString mProgram;
|
||||
bool mSpeakerAState;
|
||||
bool mSpeakerBState;
|
||||
|
||||
bool mDataValid;
|
||||
bool mReceiverOnline;
|
||||
|
||||
};
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const CAvReceiverMainStatus &source);
|
||||
QDataStream &operator>>(QDataStream &in, CAvReceiverMainStatus &dest);
|
||||
|
||||
#endif // AVRECEIVERDATA_H
|
||||
|
||||
@@ -23,7 +23,7 @@ int CAvReceiverInterface::NewDeviceFrameReceived(int DeviceID, int DeviceAddress
|
||||
}
|
||||
case AV_RECEIVER_INTERFACE_GENERAL_STATUS_REQUEST:
|
||||
{
|
||||
QByteArray data = mAvReceiverDevice->GetReceiverStatus().ToByteArray();
|
||||
QByteArray data = mAvReceiverDevice->GetReceiverStatus();
|
||||
mNetworkInterfacePtr->SendNetworkMessage(ID_AVRECEIVER_INTERFACE,mDeviceAddress,AV_RECEIVER_INTERFACE_GENERAL_STATUS_RESPONSE,data.size(),&data);
|
||||
break;
|
||||
}
|
||||
@@ -32,16 +32,16 @@ int CAvReceiverInterface::NewDeviceFrameReceived(int DeviceID, int DeviceAddress
|
||||
{
|
||||
break;
|
||||
}
|
||||
case AV_RECEIVER_INTERFACE_SET_SPEAKERB_REQUEST:
|
||||
case AV_RECEIVER_INTERFACE_SET_ZONE2_REQUEST:
|
||||
{
|
||||
bool SpkStatus = (bool)Data[0];
|
||||
mAvReceiverDevice->SetSpeakerB(SpkStatus);
|
||||
mAvReceiverDevice->SetZone2(SpkStatus);
|
||||
break;
|
||||
}
|
||||
case AV_RECEIVER_INTERFACE_SET_SPEAKERA_REQUEST:
|
||||
case AV_RECEIVER_INTERFACE_SET_MAIN_ZONE_REQUEST:
|
||||
{
|
||||
bool SpkStatus = (bool)Data[0];
|
||||
mAvReceiverDevice->SetSpeakerA(SpkStatus);
|
||||
mAvReceiverDevice->SetMainZone(SpkStatus);
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -55,10 +55,10 @@ int CAvReceiverInterface::NewDeviceFrameReceived(int DeviceID, int DeviceAddress
|
||||
}
|
||||
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_SET_ZONE2_RESPONSE:
|
||||
case AV_RECEIVER_INTERFACE_SEND_DIRECT_CMD_RESPONSE:
|
||||
case AV_RECEIVER_INTERFACE_SET_SPEAKERS_RESPONSE:
|
||||
case AV_RECEIVER_INTERFACE_SET_SPEAKERA_RESPONSE:
|
||||
case AV_RECEIVER_INTERFACE_SET_MAIN_ZONE_RESPONSE:
|
||||
default:
|
||||
{
|
||||
qDebug("Received invalid msg from Sprinkler Interface");
|
||||
|
||||
Reference in New Issue
Block a user