Interface chalet LTE fonctionnelle

This commit is contained in:
jfmartel 2025-01-02 09:04:49 -05:00
parent 3fb8de2ea7
commit bf31303763
16 changed files with 97 additions and 50 deletions

Binary file not shown.

View File

@ -8,7 +8,6 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
HEADERS += \
Sources/Chalet/ChaletData.h \
Sources/Chalet/ChaletInterface.h \
Sources/Chalet/ChaletLoraDevice.h \
Sources/Ispindel/IspindelData.h \
Sources/LoraNetworkCommIF.h \
Sources/MasterCtrl.h \
@ -58,12 +57,12 @@ HEADERS += \
Sources/LoraModuleInterface/LoraModuleInterface.h \
Sources/NetworkCommIFSurrogate.h \
Sources/LoraModuleInterface/LoraModuleInterfaceData.h \
Sources/LoraModuleInterface/LoraModuleInterfaceInterface.h
Sources/LoraModuleInterface/LoraModuleInterfaceInterface.h \
Sources/Chalet/ChaletDevice.h
SOURCES += \
Sources/Chalet/ChaletData.cpp \
Sources/Chalet/ChaletInterface.cpp \
Sources/Chalet/ChaletLoraDevice.cpp \
Sources/Ispindel/IspindelData.cpp \
Sources/LoraNetworkCommIF.cpp \
Sources/main.cpp \
@ -109,7 +108,8 @@ SOURCES += \
Sources/LoraModuleInterface/LoraModuleInterface.cpp \
Sources/NetworkCommIFSurrogate.cpp \
Sources/LoraModuleInterface/LoraModuleInterfaceData.cpp \
Sources/LoraModuleInterface/LoraModuleInterfaceInterface.cpp
Sources/LoraModuleInterface/LoraModuleInterfaceInterface.cpp \
Sources/Chalet/ChaletDevice.cpp
DEFINES -= Q_OS_UNIX

View File

@ -1,8 +1,8 @@
#include "ChaletLoraDevice.h"
#include "ChaletDevice.h"
#include "GlobalDefine.h"
CChaletLoraDevice::CChaletLoraDevice(int Address, CAbstractNetworkCommIF *NetworkInterface):
CChaletDevice::CChaletDevice(int Address, CAbstractNetworkCommIF *NetworkInterface):
CNetworkDevice(ID_CHALET_DEVICE,Address,NetworkInterface)
{
NetworkInterface->mDevicePtr = this;
@ -27,12 +27,12 @@ CChaletLoraDevice::CChaletLoraDevice(int Address, CAbstractNetworkCommIF *Networ
ResetCommStats();
}
CChaletLoraDevice::~CChaletLoraDevice()
CChaletDevice::~CChaletDevice()
{
delete mChaletStatusTimer;
}
int CChaletLoraDevice::Start()
int CChaletDevice::Start()
{
ScheduleChaletStatusRequest();
mChaletStatusTimer->start(1000);
@ -40,7 +40,7 @@ int CChaletLoraDevice::Start()
return RET_OK;
}
int CChaletLoraDevice::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data)
int CChaletDevice::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data)
{
Q_UNUSED(DeviceID)
Q_UNUSED(DeviceAddress)
@ -245,7 +245,7 @@ int CChaletLoraDevice::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, i
return RET_OK;
}
void CChaletLoraDevice::CommTimerExpired()
void CChaletDevice::CommTimerExpired()
{
if(mPendingNetworkMsgList.isEmpty())
{
@ -295,7 +295,7 @@ void CChaletLoraDevice::CommTimerExpired()
// SendChaletCommand(CHALET_GENERAL_STATUS_REQUEST,0,QByteArray());
}
int CChaletLoraDevice::SendWiFiModuleSetState(bool State)
int CChaletDevice::SendWiFiModuleSetState(bool State)
{
QByteArray Data;
Data.resize(1);
@ -311,7 +311,7 @@ int CChaletLoraDevice::SendWiFiModuleSetState(bool State)
return ScheduleChaletCommand(CHALET_WIFI_SET_STATE_REQUEST,1,Data);
}
int CChaletLoraDevice::SendInverterPowerRelayState(bool State)
int CChaletDevice::SendInverterPowerRelayState(bool State)
{
QByteArray Data;
Data.resize(1);
@ -327,7 +327,7 @@ int CChaletLoraDevice::SendInverterPowerRelayState(bool State)
return ScheduleChaletCommand(CHALET_AC_POWER_SET_STATE_REQUEST,Data);
}
int CChaletLoraDevice::SendDOHarakiri()
int CChaletDevice::SendDOHarakiri()
{
QByteArray Data; //Magic word...
Data.clear();
@ -339,7 +339,7 @@ int CChaletLoraDevice::SendDOHarakiri()
return ScheduleChaletCommand(CHALET_DO_HARAKIRI_REQUEST,Data);
}
int CChaletLoraDevice::SendRebootCmd()
int CChaletDevice::SendRebootCmd()
{
QByteArray Data; //Magic word...
Data.clear();
@ -350,33 +350,38 @@ int CChaletLoraDevice::SendRebootCmd()
return ScheduleChaletCommand(CHALET_REBOOT_CPU_REQUEST,Data);
}
int CChaletLoraDevice::SendGetWifiParams()
int CChaletDevice::SendGetWifiParams()
{
return ScheduleChaletCommand(CHALET_GET_STORED_WIFI_SETTINGS_REQUEST,QByteArray());
}
int CChaletLoraDevice::SendSetWifiParams(QByteArray Data)
int CChaletDevice::SendSetWifiParams(QByteArray Data)
{
return ScheduleChaletCommand(CHALET_SET_STORED_WIFI_SETTINGS_REQUEST,Data);
}
int CChaletLoraDevice::SendGetFirmwareVersion()
int CChaletDevice::SendGetFirmwareVersion()
{
return ScheduleChaletCommand(CHALET_GET_FIRMWARE_VERSION_REQUEST,QByteArray());
}
int CChaletLoraDevice::SendClearCommStatsRequest()
int CChaletDevice::SendClearCommStatsRequest()
{
return ScheduleChaletCommand(CHALET_CLEAR_COMMS_STATISTICS_REQUEST,QByteArray());
}
int CChaletLoraDevice::SendGetWifiStatusRequest()
int CChaletDevice::SendGetWifiStatusRequest()
{
return ScheduleChaletCommand(CHALET_WIFI_STATUS_REQUEST,QByteArray());
}
int CChaletLoraDevice::SendChaletCommand(int CmdID, int DataSize, QByteArray Data)
int CChaletDevice::SendChaletCommand(int CmdID, int DataSize, QByteArray Data)
{
if(mNetworkInterfacePtr == 0)
{
return RET_ERROR;
}
mNetworkInterfacePtr->SendNetworkMessage(ID_CHALET_DEVICE,mDeviceAddress,CmdID,DataSize,&Data);
mTotalNbRequest++;
mChaletMainStatus.mTotalNbMasterTxCmds++;
@ -384,7 +389,7 @@ int CChaletLoraDevice::SendChaletCommand(int CmdID, int DataSize, QByteArray Dat
return RET_OK;
}
int CChaletLoraDevice::CmdResponseReceived(int CmdID)
int CChaletDevice::CmdResponseReceived(int CmdID)
{
Q_UNUSED(CmdID)
@ -423,12 +428,12 @@ int CChaletLoraDevice::CmdResponseReceived(int CmdID)
int CChaletLoraDevice::ScheduleChaletStatusRequest()
int CChaletDevice::ScheduleChaletStatusRequest()
{
return ScheduleChaletCommand(CHALET_GENERAL_STATUS_REQUEST,0,QByteArray());
}
int CChaletLoraDevice::ScheduleChaletCommand(int CmdID, int DataSize, QByteArray Data)
int CChaletDevice::ScheduleChaletCommand(int CmdID, int DataSize, QByteArray Data)
{
Q_UNUSED(DataSize)
@ -445,7 +450,7 @@ int CChaletLoraDevice::ScheduleChaletCommand(int CmdID, int DataSize, QByteArray
return RET_OK;
}
int CChaletLoraDevice::ScheduleChaletCommand(int CmdID, QByteArray Data)
int CChaletDevice::ScheduleChaletCommand(int CmdID, QByteArray Data)
{
// if(mChaletMainStatus.mIsOnline == false)
// {
@ -471,7 +476,7 @@ int CChaletLoraDevice::ScheduleChaletCommand(int CmdID, QByteArray Data)
return RET_OK;
}
int CChaletLoraDevice::ResetCommStats()
int CChaletDevice::ResetCommStats()
{
mLostRequestPercentage = 0.0;
mTotalNbRequest = 0;
@ -482,7 +487,7 @@ int CChaletLoraDevice::ResetCommStats()
return RET_OK;
}
int CChaletLoraDevice::ComputeCommStats()
int CChaletDevice::ComputeCommStats()
{
mLostRequestPercentage = ((float)mNbLostRequest/(float)mTotalNbRequest)*100;
mChaletMainStatus.mLostRequestPercentage = mLostRequestPercentage;

View File

@ -1,9 +1,9 @@
#ifndef CCHALETLORADEVICE_H
#define CCHALETLORADEVICE_H
#ifndef CCHALETDEVICE_H
#define CCHALETDEVICE_H
#include <QByteArray>
#include <QObject>
#include <QSerialPort>
#include "LoraNetworkCommIF.h"
#include "NetworkProtocol.h"
#include "NetworkDevice.h"
#include <QTimer>
#include "ChaletData.h"
@ -26,16 +26,17 @@
#define LORA_CHALET_STATUS_POWER_RELAY_MASK 0x01
#define LORA_CHALET_STATUS_CUR_SENSOR_MASK 0x02
class CChaletLoraDevice : public QObject, public CNetworkDevice
class CChaletDevice : public QObject, public CNetworkDevice
{
Q_OBJECT
public:
CChaletLoraDevice(int Address,CAbstractNetworkCommIF *NetworkInterface);
~CChaletLoraDevice();
CChaletDevice(int Address,CAbstractNetworkCommIF *NetworkInterface);
~CChaletDevice();
virtual int NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);
QString mChaletName;
QTimer *mChaletStatusTimer;
int Start();
@ -93,4 +94,4 @@ public slots:
};
#endif // CCHALETLORADEVICE_H
#endif // CCHALETDEVICE_H

View File

@ -1,7 +1,7 @@
#include "ChaletInterface.h"
#include "ChaletDataLogger.h"
CChaletInterface::CChaletInterface(int Address, CAbstractNetworkCommIF *NetworkInterface, CChaletLoraDevice *DevicePtr):
CChaletInterface::CChaletInterface(int Address, CAbstractNetworkCommIF *NetworkInterface, CChaletDevice *DevicePtr):
CNetworkDevice(ID_CHALET_INTERFACE,Address,NetworkInterface)
{
mChaletLoraDevice = DevicePtr;

View File

@ -3,19 +3,19 @@
#include "NetworkDevice.h"
#include "ChaletLoraDevice.h"
#include "ChaletDevice.h"
class CChaletInterface: public QObject, public CNetworkDevice
{
Q_OBJECT
public:
CChaletInterface(int Address, CAbstractNetworkCommIF *NetworkInterface, CChaletLoraDevice *DevicePtr);
CChaletInterface(int Address, CAbstractNetworkCommIF *NetworkInterface, CChaletDevice *DevicePtr);
virtual int NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);
void SendChaletCommActivityBeacon();
private:
CChaletLoraDevice *mChaletLoraDevice;
CChaletDevice *mChaletLoraDevice;
CChaletDataLogger *mChaletDataLogger;
public slots:

View File

@ -4,7 +4,7 @@
#include <QObject>
#include <ModbusBackend.h>
class CChaletLoraDevice;
class CChaletDevice;
class CChaletModbusServer : public CModbusBackend
{

View File

@ -2,7 +2,7 @@
#include <QNetworkReply>
#include <QJsonDocument>
#include <QJsonObject>
#include "ChaletLoraDevice.h"
#include "ChaletDevice.h"
CThingsBoardInterface::CThingsBoardInterface()

View File

@ -1,7 +1,7 @@
#ifndef THINGSBOARDINTERFACE_H
#define THINGSBOARDINTERFACE_H
class CChaletLoraDevice;
class CChaletDevice;
#include <QObject>
#include <QNetworkAccessManager>
@ -14,7 +14,7 @@ public:
CThingsBoardInterface();
~CThingsBoardInterface();
CChaletLoraDevice *mChaletLoraDevice;
CChaletDevice *mChaletLoraDevice;
int RegisterThingsboardRPC();
void UpdateChaletVoltage(float Voltage);

View File

@ -24,6 +24,8 @@ int CEthernetNetworkCommIF::SendNetworkMessage(int DeviceID, int DeviceAddress,
// Q_UNUSED(MessageID)
// Q_UNUSED(DataSize)
// Q_UNUSED(Data)
if(mTCPSocket == 0)
return RET_ERROR;
QByteArray Packet;
if(Data != 0)
@ -34,6 +36,7 @@ int CEthernetNetworkCommIF::SendNetworkMessage(int DeviceID, int DeviceAddress,
{
Packet = GetTxPacket(MessageID,0,0,0,DeviceAddress,DeviceID);
}
mTCPSocket->write(Packet);
return RET_OK;

View File

@ -222,6 +222,20 @@ void CEthernetNetworkServer::DeviceSocketDataAvail()
}
break;
}
case ID_CHALET_DEVICE:
{
if(mDevicesMgrHandle->BindNetworkChaletDevice(DeviceAddress,(CAbstractNetworkCommIF*)NetworkIF) == RET_OK)
{
Result = RES_CREATION_SUCCESS;
qDebug("Created new Ethernet (LTE) Chalet Device in ethernet server");
}
else
{
Result = RES_CREATION_FAILED;
qDebug("Could not create Ethernet (LTE) Chalet Device in ethernet server");
}
break;
}
default:
{
Result = RES_CREATION_UNKNOWN_DEVICE;

View File

@ -1,5 +1,6 @@
#include "MasterCtrl.h"
#include <QApplication>
#include "EthernetNetworkCommIF.h"
// #include <QByteArray>
//#include <QBuffer>
@ -28,14 +29,17 @@ CMasterCtrl::CMasterCtrl()
if(mMasterCtrlSettings.mChaletUseLoraIF == true)
{
mChaletLoraModuleInterface = new CLoraModuleInterface(); //JFM LoraInterface Dev
mChaletLoraDevice = new CChaletLoraDevice(1,mChaletLoraModuleInterface); //JFM LoraInterface Dev
mChaletLoraDevice = new CChaletDevice(1,mChaletLoraModuleInterface); //JFM LoraInterface Dev
}
else
{
mChaletLoraNetworkCommInterface = new CLoraNetworkCommIF();//JFM LoraInterface Dev
mChaletLoraDevice = new CChaletLoraDevice(1,mChaletLoraNetworkCommInterface);//JFM LoraInterface Dev
mChaletLoraDevice = new CChaletDevice(1,mChaletLoraNetworkCommInterface);//JFM LoraInterface Dev
}
CEthernetNetworkCommIF *Dummy = new CEthernetNetworkCommIF(NULL); //No memory leak here.. object will be deleted on reasignment.
mChaletLTEDevice = new CChaletDevice(1,(CAbstractNetworkCommIF*)Dummy);
// mChaletLoraInterface = new CChaletLoraInterface(mRooftopTowerLoraDevice);
@ -96,6 +100,7 @@ void CMasterCtrl::Start()
mNetworkDevicesManager->mChaletLoraDevice = mChaletLoraDevice;
mNetworkDevicesManager->mIspindelDevice = mIspindelDevice;
mNetworkDevicesManager->mLoraModuleInterfaceDevice = mChaletLoraModuleInterface;
mNetworkDevicesManager->mChaletLTEDevice = mChaletLTEDevice;
mEthernetNetworkServer->mDevicesMgrHandle = mNetworkDevicesManager;
@ -137,9 +142,14 @@ void CMasterCtrl::Start()
// mChaletLoraNetworkCommInterface->SetLoraSerialPortSettings("COM5",QSerialPort::Baud9600);
mChaletLoraDevice->mChaletName = "Chalet Lora";
mChaletLoraDevice->Start();
mChaletLTEDevice->mChaletName = "Chalet LTE";
mChaletLTEDevice->Start();

View File

@ -12,7 +12,7 @@
#include "EthernetNetworkServer.h"
#include "ContactRepository.h"
#include "SprinklerMgr.h"
#include "ChaletLoraDevice.h"
#include "ChaletDevice.h"
//#include "ChaletLoraInterface.h"
#include "LoraNetworkCommIF.h"
#include "HttpServer.h"
@ -41,7 +41,8 @@ public:
CContactRepository *mContactsRepository;
CSprinklerMgr *mSprinklerManager;
CChaletLoraDevice *mChaletLoraDevice;
CChaletDevice *mChaletLoraDevice;
CChaletDevice *mChaletLTEDevice;
// CChaletLoraInterface *mChaletLoraInterface;
CLoraNetworkCommIF *mChaletLoraNetworkCommInterface;
CLoraModuleInterface *mChaletLoraModuleInterface;

View File

@ -5,8 +5,9 @@ CNetworkDevice::CNetworkDevice(int DeviceID, int DeviceAddress, CAbstractNetwork
{
mDeviceAddress = DeviceAddress;
mDeviceID = DeviceID;
SetNetworkInterface(Interface);
mIsOnline = false;
mNetworkInterfacePtr = 0;
SetNetworkInterface(Interface);
}
CNetworkDevice::~CNetworkDevice()
@ -19,7 +20,9 @@ CNetworkDevice::~CNetworkDevice()
void CNetworkDevice::SetNetworkInterface(CAbstractNetworkCommIF *Interface)
{
mNetworkInterfacePtr = Interface;
if(mNetworkInterfacePtr != 0)
delete mNetworkInterfacePtr;
mNetworkInterfacePtr = Interface;
if(Interface != 0)
{
mNetworkInterfacePtr->mDevicePtr = this;

View File

@ -102,7 +102,8 @@ int CNetworkDevicesMgr::CreateNewChaletInterface(int Address, CAbstractNetworkCo
{
return RET_ERROR;
}
CChaletInterface *ChaletInterface = new CChaletInterface(Address, NetworkIF,mChaletLoraDevice);
// CChaletInterface *ChaletInterface = new CChaletInterface(Address, NetworkIF,mChaletLoraDevice);
CChaletInterface *ChaletInterface = new CChaletInterface(Address, NetworkIF,mChaletLTEDevice);
mNetworkDevicesList.append((CNetworkDevice*)ChaletInterface);
return RET_OK;
}
@ -130,6 +131,13 @@ int CNetworkDevicesMgr::CreateNewLoraInterfaceInterface(int Address, CAbstractNe
return RET_OK;
}
int CNetworkDevicesMgr::BindNetworkChaletDevice(int Address, CAbstractNetworkCommIF *NetworkIF)
{
mChaletLTEDevice->mDeviceAddress = Address;
mChaletLTEDevice->SetNetworkInterface(NetworkIF);
return RET_OK;
}
void CNetworkDevicesMgr::EthernetNetworkDeviceDisconnected(CNetworkDevice *Device)
{
qDebug("Device disconnected. ID: %d, Address: %d",Device->GetDeviceID(),Device->GetDeviceAddress());

View File

@ -19,7 +19,7 @@ class CMasterCtrl;
class CContactRepository;
class CSprinklerMgr;
class CAVReceiverDevice;
class CChaletLoraDevice;
class CChaletDevice;
class CIspindelDevice;
class CLoraModuleInterface;
@ -40,19 +40,21 @@ public:
int CreateNewChaletInterface(int Address, CAbstractNetworkCommIF *NetworkIF);
int CreateNewIspindleInterface(int Address, CAbstractNetworkCommIF *NetworkIF);
int CreateNewLoraInterfaceInterface(int Address, CAbstractNetworkCommIF *NetworkIF);
int BindNetworkChaletDevice(int Address, CAbstractNetworkCommIF *NetworkIF);
int FindDeviceByPtr(CNetworkDevice *Device);
CNetworkDevice *GetDevice(int DeviceID, int Address);
QList<CNetworkDevice*> GetDevices(int DeviceID);
CAVReceiverDevice *mAvReceiverDevice;
CChaletLoraDevice *mChaletLoraDevice;
CChaletDevice *mChaletLoraDevice;
CIspindelDevice *mIspindelDevice;
CVoipMsSMSClient *mVoipMSInterfaceHandle;
CContactRepository *mContactRepositoryHandle;
CMasterCtrl *mProgramHandle;
CSprinklerMgr *mSprinklerMgrHandle;
CLoraModuleInterface *mLoraModuleInterfaceDevice;
CChaletDevice *mChaletLTEDevice;
int NewSMSMessagesReceived(QList<CSMSMessage> NewMessages);