Ajout interface LoraModuleInterface

This commit is contained in:
2023-03-26 15:27:55 -04:00
parent 635d754d27
commit 59b07d5db3
15 changed files with 422 additions and 12 deletions
@@ -0,0 +1,68 @@
#include "LoraModuleIFMasterCtrlInterface.h"
#include "LoraModuleInterface.h"
#include "LoraModuleInterfaceData.h"
CLoraModuleIFMasterCtrlInterface::CLoraModuleIFMasterCtrlInterface(CLoraModuleInterface *ProgramHandle)
{
mMyDeviceID = ID_LORA_INTERFACE_INTERFACE;
mNetworkPort = 2182;
mMasterCtrlIPAddress = "127.0.0.1";
mNetworkCommSocket = 0;
mDeviceAddress = 1;
mProgramHandle = ProgramHandle;
}
int CLoraModuleIFMasterCtrlInterface::DeviceFrameReceived(int TargetDeviceID, int TargetDeviceAddress, int SenderID, int SenderAddress, int MessageID, int DataSize, QByteArray Data)
{
Q_UNUSED(DataSize)
Q_UNUSED(SenderID)
Q_UNUSED(SenderAddress)
if(TargetDeviceID == mMyDeviceID && (TargetDeviceAddress == BROADCAST_VALUE || TargetDeviceAddress == mDeviceAddress))
{
switch(MessageID)
{
case LORA_MODULE_IF_INTERFACE_ACK:
{
qDebug("Chalet Interface ACK received");
break;
}
case LORA_MODULE_IF_INTERFACE_GENERAL_STATUS_RESPONSE:
{
// qDebug("Rx Lora Module IF status");
CLoraModuleInterfaceStatus Status;
QDataStream Strm(Data);
Strm >> Status;
mProgramHandle->NewLoraModuleStatusData(Status);
break;
}
case LORA_MODULE_IF_INTERFACE_GENERAL_STATUS_REQUEST:
default:
{
qDebug("CLoraModuleIFMasterCtrlInterface: invalid command received");
break;
}
}
}
return RET_OK;
}
int CLoraModuleIFMasterCtrlInterface::DeviceConnectedToMaster(bool Connected)
{
if(Connected)
{
qDebug("LoraModuleIF Interface connected to Master.");
mProgramHandle->ConnectedToMaster(Connected);
}
else
return RET_ERROR;
return RET_OK;
}
@@ -0,0 +1,19 @@
#ifndef LORAMODULEIFMASTERCTRLINTERFACE_H
#define LORAMODULEIFMASTERCTRLINTERFACE_H
#include "MasterCtrlInterface.h"
class CLoraModuleInterface;
class CLoraModuleIFMasterCtrlInterface: public CMasterCtrlInterface
{
public:
CLoraModuleIFMasterCtrlInterface(CLoraModuleInterface *ProgramHandle);
int DeviceFrameReceived(int TargetDeviceID, int TargetDeviceAddress, int SenderID, int SenderAddress, int MessageID, int DataSize, QByteArray Data);
int DeviceConnectedToMaster(bool Connected = true);
private:
CLoraModuleInterface *mProgramHandle;
};
#endif // LORAMODULEIFMASTERCTRLINTERFACE_H
@@ -0,0 +1,44 @@
#include "LoraModuleInterface.h"
#include "LoraModuleIFMasterCtrlInterface.h"
CLoraModuleInterface::CLoraModuleInterface(CChaletGui *ChaletGuiPtr)
{
mChaletGui = ChaletGuiPtr;
mChaletGui->mLoraModuleIFProgramHandle = this;
mNetworkInterface = new CLoraModuleIFMasterCtrlInterface(this);
mLoraModulePollTimer = new QTimer();
mLoraModulePollTimer->setInterval(1000);
mLoraModulePollTimer->setSingleShot(false);
connect(mLoraModulePollTimer,&QTimer::timeout,this,&CLoraModuleInterface::LoraModulePollTimerExpired);
}
int CLoraModuleInterface::ConnectedToMaster(bool connected)
{
if(connected)
{
mLoraModulePollTimer->start();
}
else
{
mLoraModulePollTimer->stop();
}
return RET_OK;
}
int CLoraModuleInterface::Start()
{
mNetworkInterface->ConnectToMasterCtrl();
return RET_OK;
}
void CLoraModuleInterface::LoraModulePollTimerExpired()
{
mNetworkInterface->SendMasterCtrlCommand(LORA_MODULE_IF_INTERFACE_GENERAL_STATUS_REQUEST,QByteArray());
}
int CLoraModuleInterface::NewLoraModuleStatusData(CLoraModuleInterfaceStatus Data)
{
mChaletGui->UpdateLoraModuleStatus(Data);
}
@@ -0,0 +1,29 @@
#ifndef LORAMODULEINTERFACE_H
#define LORAMODULEINTERFACE_H
#include "ChaletGui.h"
#include <QTimer>
#include "LoraModuleInterfaceData.h"
class CLoraModuleIFMasterCtrlInterface;
class CLoraModuleInterface : public QObject
{
Q_OBJECT
public:
CLoraModuleInterface(CChaletGui *ChaletGuiPtr);
int Start();
int ConnectedToMaster(bool connected);
int NewLoraModuleStatusData(CLoraModuleInterfaceStatus Data);
CLoraModuleIFMasterCtrlInterface *mNetworkInterface;
CChaletGui *mChaletGui;
QTimer *mLoraModulePollTimer;
public slots:
void LoraModulePollTimerExpired();
};
#endif // LORAMODULEINTERFACE_H
@@ -0,0 +1,73 @@
#include "LoraModuleInterfaceData.h"
CLoraModuleInterfaceStatus::CLoraModuleInterfaceStatus()
{
}
CLoraModuleInterfaceStatus& CLoraModuleInterfaceStatus::operator = (const CLoraModuleInterfaceStatus &rhs)
{
if(this == &rhs)
return *this;
mModuleModel = rhs.mModuleModel;
mModuleInternalAddress = rhs.mModuleInternalAddress;
mModuleUARTParity = rhs.mModuleUARTParity;
mModuleUARTRate = rhs.mModuleUARTRate;
mModuleAirRate = rhs.mModuleAirRate;
mModuleSubPacket = rhs.mModuleSubPacket;
mModuleRSSIEnabled = rhs.mModuleRSSIEnabled;
mModuleTxPower = rhs.mModuleTxPower;
mModuleInternalChannel = rhs.mModuleInternalChannel;
mModuleRSSIByteEnabled = rhs.mModuleRSSIByteEnabled;
mModuleTxMethod = rhs.mModuleTxMethod;
mModuleLBTEnabled = rhs.mModuleLBTEnabled;
mModuleWORCycle = rhs.mModuleWORCycle;
mModuleAmbientRSSI = rhs.mModuleAmbientRSSI;
mModuleLastRxRSSI = rhs.mModuleLastRxRSSI;
return *this;
}
QDataStream &operator<<(QDataStream &out, const CLoraModuleInterfaceStatus &source)
{
out << source.mModuleModel
<< source.mModuleInternalAddress
<< source.mModuleUARTParity
<< source.mModuleUARTRate
<< source.mModuleAirRate
<< source.mModuleSubPacket
<< source.mModuleRSSIEnabled
<< source.mModuleTxPower
<< source.mModuleInternalChannel
<< source.mModuleRSSIByteEnabled
<< source.mModuleTxMethod
<< source.mModuleLBTEnabled
<< source.mModuleWORCycle
<< source.mModuleAmbientRSSI
<< source.mModuleLastRxRSSI;
return out;
}
QDataStream &operator>>(QDataStream &in, CLoraModuleInterfaceStatus &dest)
{
in >> dest.mModuleModel
>> dest.mModuleInternalAddress
>> dest.mModuleUARTParity
>> dest.mModuleUARTRate
>> dest.mModuleAirRate
>> dest.mModuleSubPacket
>> dest.mModuleRSSIEnabled
>> dest.mModuleTxPower
>> dest.mModuleInternalChannel
>> dest.mModuleRSSIByteEnabled
>> dest.mModuleTxMethod
>> dest.mModuleLBTEnabled
>> dest.mModuleWORCycle
>> dest.mModuleAmbientRSSI
>> dest.mModuleLastRxRSSI;
return in;
}
@@ -0,0 +1,105 @@
#ifndef LORAMODULEINTERFACEDATA_H
#define LORAMODULEINTERFACEDATA_H
#include <QtGlobal>
#include <QDataStream>
class CLoraModuleInterfaceStatus
{
public:
enum eE220UartRates
{
E220_UART_1200 = 0,
E220_UART_2400,
E220_UART_4800,
E220_UART_9600,
E220_UART_19200,
E220_UART_38400,
E220_UART_57600,
E220_UART_115200
};
enum eE220ParityBit
{
E220_UART_8N1=0,
E220_UART_8O1,
E220_UART_8E1,
E220_UART_8N1_bis
};
enum e220AirDataRates
{
E220_AIR_RATE_24K = 0,
E220_AIR_RATE_24K_1,
E220_AIR_RATE_24K_2,
E220_AIR_RATE_48K,
E220_AIR_RATE_96K,
E220_AIR_RATE_192K,
E220_AIR_RATE_384K,
E220_AIR_RATE_625K
};
enum e220PacketSizes
{
E220_PACKET_200,
E220_PACKET_128,
E220_PACKET_64,
E220_PACKET_32
};
enum e220TransmitPower
{
E220_TX_PWR_30,
E220_TX_PWR_27,
E220_TX_PWR_24,
E220_TX_PWR_21
};
enum e220WORCycles
{
E220_WOR_500MS,
E220_WOR_1000MS,
E220_WOR_1500MS,
E220_WOR_2000MS,
E220_WOR_2500MS,
E220_WOR_3000MS,
E220_WOR_3500MS,
E220_WOR_4000MS
};
CLoraModuleInterfaceStatus();
quint8 mModuleModel;
quint16 mModuleInternalAddress;
quint8 mModuleUARTParity;
quint8 mModuleUARTRate;
quint8 mModuleAirRate;
quint8 mModuleSubPacket;
quint8 mModuleRSSIEnabled;
quint8 mModuleTxPower;
quint8 mModuleInternalChannel;
quint8 mModuleRSSIByteEnabled;
quint8 mModuleTxMethod;
quint8 mModuleLBTEnabled;
quint8 mModuleWORCycle;
quint8 mModuleAmbientRSSI;
quint8 mModuleLastRxRSSI;
CLoraModuleInterfaceStatus& operator=(const CLoraModuleInterfaceStatus &rhs);
};
QDataStream &operator<<(QDataStream &out, const CLoraModuleInterfaceStatus &source);
QDataStream &operator>>(QDataStream &in, CLoraModuleInterfaceStatus &dest);
#endif // LORAMODULEINTERFACEDATA_H