LoraModuleInterface dev.

This commit is contained in:
jfmartel 2023-03-26 15:28:31 -04:00
parent 526f4f76d8
commit 181334f059
17 changed files with 435 additions and 31 deletions

Binary file not shown.

View File

@ -55,7 +55,10 @@ HEADERS += \
Sources/Ispindel/IspindelDataLogger.h \
Sources/Ispindel/IspindelInterface.h \
Sources/Gui/LoraSettingsGui.h \
Sources/LoraModuleInterface/LoraModuleInterface.h
Sources/LoraModuleInterface/LoraModuleInterface.h \
Sources/NetworkCommIFSurrogate.h \
Sources/LoraModuleInterface/LoraModuleInterfaceData.h \
Sources/LoraModuleInterface/LoraModuleInterfaceInterface.h
SOURCES += \
Sources/Chalet/ChaletData.cpp \
@ -103,7 +106,10 @@ SOURCES += \
Sources/Ispindel/IspindelDataLogger.cpp \
Sources/Ispindel/IspindelInterface.cpp \
Sources/Gui/LoraSettingsGui.cpp \
Sources/LoraModuleInterface/LoraModuleInterface.cpp
Sources/LoraModuleInterface/LoraModuleInterface.cpp \
Sources/NetworkCommIFSurrogate.cpp \
Sources/LoraModuleInterface/LoraModuleInterfaceData.cpp \
Sources/LoraModuleInterface/LoraModuleInterfaceInterface.cpp
DEFINES -= Q_OS_UNIX

View File

@ -208,6 +208,20 @@ void CEthernetNetworkServer::DeviceSocketDataAvail()
}
break;
}
case ID_LORA_INTERFACE_INTERFACE:
{
if(mDevicesMgrHandle->CreateNewLoraInterfaceInterface(DeviceAddress,(CAbstractNetworkCommIF*)NetworkIF) == RET_OK)
{
Result = RES_CREATION_SUCCESS;
qDebug("Created new Lora Interface Interface in ethernet server");
}
else
{
Result = RES_CREATION_FAILED;
qDebug("Could not create Lora Interface Interface in ethernet server");
}
break;
}
default:
{
Result = RES_CREATION_UNKNOWN_DEVICE;
@ -342,7 +356,7 @@ void CEthernetNetworkServer::DeviceSocketDataAvail()
{
break;
}
case PROTOCOL_RET_OK_BAD_HEADER:
case PROTOCOL_RET_ERROR_BAD_HEADER:
{
break;
}

View File

@ -1,4 +1,6 @@
#include "LoraModuleInterface.h"
#include <QDataStream>
CLoraModuleInterface::CLoraModuleInterface()
{
@ -9,12 +11,21 @@ CLoraModuleInterface::CLoraModuleInterface()
mLoraModuleIFStatusTimer->setInterval(1000);
mLoraModuleIFStatusTimer->start();
connect(mLoraModuleIFStatusTimer,SIGNAL(timeout()),this,SLOT(LoraModuleStatusTimerExpired()));
mLoraDeviceCommSurrogate = new CNetworkCommIFSurrogate;
mLoraDeviceCommSurrogate->mMyNetworkAddress = 1;
mLoraDeviceCommSurrogate->mMyNetworkID = ID_MASTER;
connect(mLoraDeviceCommSurrogate,&CNetworkCommIFSurrogate::ValidFrameReady,this,&CLoraModuleInterface::LoraRemoteDeviceDataReceived);
connect(mLoraModuleIFStatusTimer,&QTimer::timeout,this,&CLoraModuleInterface::LoraModuleStatusTimerExpired);
}
CLoraModuleInterface::~CLoraModuleInterface()
{
delete mLoraModuleIFStatusTimer;
delete mLoraDeviceCommSurrogate;
}
@ -25,8 +36,10 @@ int CLoraModuleInterface::NewFrameReceived(int DeviceID, int DeviceAddress, int
{
case LORA_IF_GET_STATUS_RESPONSE:
{
unsigned char model = Data.at(0);
qDebug("LoraModuleInterface status received : %d",model);
QDataStream Strm(Data);
Strm >> mLoraModuleStatus;
qDebug("Lora device status received");
break;
}
case LORA_IF_SEND_FRAME_RESPONSE:
@ -36,22 +49,27 @@ int CLoraModuleInterface::NewFrameReceived(int DeviceID, int DeviceAddress, int
}
case LORA_IF_NEW_FRAME_RESPONSE: //LoraInterface received a message from the Lora end point (chalet for example). Let's decode it and send it to the destination device
{
CNetworkProtocol *mTempProtocol = new CNetworkProtocol; //Let's instanciate a temp protocol class to avoid messing with our own derived class...
int FwdDeviceID;
int FwdDeviceAddress;
int FwdMessageID;
int FwdDataSize;
QByteArray FwdData;
if(mTempProtocol->ProtocolAnalyseBufferStatically(Data,FwdDeviceID,FwdDeviceAddress,FwdMessageID,FwdDataSize,FwdData) == PROTOCOL_RET_OK_PACKET_COMPLETE)
{
mDevicePtr->NewDeviceFrameReceived(FwdDeviceID,FwdDeviceAddress,FwdMessageID,FwdDataSize,FwdData);
}
else
{
qDebug("LoraModuleInterface received an invalid packet from end Lora device in NewFrameReceived");
}
delete mTempProtocol;
//Use the surrogate to analyse the buffer. When frame is complete it will trigger a signal.
mLoraDeviceCommSurrogate->AnalyzeRxBuffer(Data);
// CNetworkProtocol *mTempProtocol = new CNetworkProtocol; //Let's instanciate a temp protocol class to avoid messing with our own derived class...
// int FwdDeviceID;
// int FwdDeviceAddress;
// int FwdMessageID;
// int FwdDataSize;
// QByteArray FwdData;
// if(mTempProtocol->ProtocolAnalyseBufferStatically(Data,FwdDeviceID,FwdDeviceAddress,FwdMessageID,FwdDataSize,FwdData) == PROTOCOL_RET_OK_PACKET_COMPLETE)
// {
// mDevicePtr->NewDeviceFrameReceived(FwdDeviceID,FwdDeviceAddress,FwdMessageID,FwdDataSize,FwdData);
// }
// else
// {
// qDebug("LoraModuleInterface received an invalid packet from end Lora device in NewFrameReceived");
// }
// delete mTempProtocol;
break;
}
case LORA_IF_GET_MODULE_CONFIG_RESPONSE:
@ -86,6 +104,21 @@ int CLoraModuleInterface::NewFrameReceived(int DeviceID, int DeviceAddress, int
int CLoraModuleInterface::SendNetworkMessage(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray *Data)
{
qDebug("LoraInterfce: New frame received from MasterCtrl class");
//Get the payload by building the Msg packet
QByteArray Payload = GetTxPacket(MessageID,0,Data->data(),DataSize,DeviceAddress,DeviceID);
//Prepend the destination lora address & channel
Payload.prepend(mLoraPreamble);
// Payload.prepend(mDestLoraAddress);
// Payload.prepend((char)(mDestLoraChannel &0x00FF));
// Payload.prepend((char)((mDestLoraAddress >>8)));
//Now get the packet to communicate with LoraInterface uC
QByteArray Packet = GetTxPacket(LORA_IF_SEND_FRAME_REQUEST,0,Payload,Payload.size(),1,ID_LORA_INTERFACE_DEVICE);
mLoraModuleIFSerialPort.write(Packet);
mLoraModuleIFSerialPort.waitForBytesWritten(500);
return RET_OK;
}
@ -93,7 +126,7 @@ int CLoraModuleInterface::SendNetworkMessage(int DeviceID, int DeviceAddress, in
void CLoraModuleInterface::LoraModuleStatusTimerExpired()
{
QByteArray Packet = GetTxPacket(LORA_IF_GET_STATUS_REQUEST,0,0,0,1,ID_LORA_INTERFACE);
QByteArray Packet = GetTxPacket(LORA_IF_GET_STATUS_REQUEST,0,0,0,1,ID_LORA_INTERFACE_DEVICE);
mLoraModuleIFSerialPort.write(Packet);
mLoraModuleIFSerialPort.waitForBytesWritten(500);
}
@ -130,9 +163,37 @@ int CLoraModuleInterface::SetLoraModuleInterfaceParameters(QString ComPort, qint
return RET_OK;
}
int CLoraModuleInterface::SetLoraDestinationAddress(quint16 Address, quint8 Channel)
{
mDestLoraAddress = Address;
mDestLoraChannel = Channel;
mLoraPreamble.clear();
mLoraPreamble.append(mDestLoraChannel);
mLoraPreamble.prepend((char)(mDestLoraAddress &0x00FF));
mLoraPreamble.prepend((char)((mDestLoraAddress >>8)));
return RET_OK;
}
void CLoraModuleInterface::NewLoraModuleIFDataReady()
{
QByteArray NewData = mLoraModuleIFSerialPort.readAll();
AnalyzeRxBuffer(NewData);
}
void CLoraModuleInterface::LoraRemoteDeviceDataReceived(int FwdDeviceID, int FwdDeviceAddress, int FwdMessageID, int FwdDataSize, QByteArray FwdData)
{
//Multiple devices could be connected to the interface. Find the sender
//NOTE: This needs a major rework of the inheritance scheme!
QObject *SenderObj = QObject::sender();
if(SenderObj == mLoraDeviceCommSurrogate)
{
mDevicePtr->NewDeviceFrameReceived(FwdDeviceID,FwdDeviceAddress,FwdMessageID,FwdDataSize,FwdData);
}
}
void CLoraModuleInterface::LoraRemoteDeviceReceiveError(CNetworkProtocol::ProtocolRetValues RetID)
{
}

View File

@ -10,6 +10,9 @@
#include <QTimer>
#include <QSerialPort>
#include <QByteArrayList>
#include "NetworkCommIFSurrogate.h"
#include "LoraModuleInterfaceData.h"
class CLoraModuleInterface : public QObject, public CNetworkProtocol, public CAbstractNetworkCommIF
{
@ -20,13 +23,19 @@ public:
virtual ~CLoraModuleInterface();
int SetLoraModuleInterfaceParameters(QString ComPort,qint32 BaudRate);
int SetLoraDestinationAddress(quint16 Address, quint8 Channel);
CLoraModuleInterfaceStatus GetModuleIFStatus() {return mLoraModuleStatus;}
QTimer *mLoraModuleIFStatusTimer;
QSerialPort mLoraModuleIFSerialPort;
QString mLoraModuleIFComPortName;
qint32 mLoraModuleIFComPortBaudRate;
CNetworkCommIFSurrogate *mLoraDeviceCommSurrogate;
unsigned short mDestLoraAddress;
unsigned char mDestLoraChannel;
QByteArray mLoraPreamble;
CLoraModuleInterfaceStatus mLoraModuleStatus;
@ -39,6 +48,9 @@ public:
public slots:
void LoraModuleStatusTimerExpired();
void NewLoraModuleIFDataReady();
void LoraRemoteDeviceDataReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);
void LoraRemoteDeviceReceiveError(CNetworkProtocol::ProtocolRetValues RetID);
};
#endif // LORAMODULEINTERFACE_H

View File

@ -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;
}

View File

@ -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

View File

@ -0,0 +1,39 @@
#include "LoraModuleInterfaceInterface.h"
CLoraModuleInterfaceInterface::CLoraModuleInterfaceInterface(int Address, CAbstractNetworkCommIF *NetworkInterface, CLoraModuleInterface *DevicePtr):
CNetworkDevice(ID_LORA_INTERFACE_INTERFACE,Address,NetworkInterface)
{
mLoraModuleIFPtr = DevicePtr;
}
int CLoraModuleInterfaceInterface::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 LORA_MODULE_IF_INTERFACE_ACK:
{
break;
}
case LORA_MODULE_IF_INTERFACE_GENERAL_STATUS_REQUEST:
{
QByteArray StatusData;
QDataStream Strm(&StatusData,QIODevice::WriteOnly);
Strm << mLoraModuleIFPtr->GetModuleIFStatus();
mNetworkInterfacePtr->SendNetworkMessage(ID_LORA_INTERFACE_INTERFACE,mDeviceAddress,LORA_MODULE_IF_INTERFACE_GENERAL_STATUS_RESPONSE,StatusData.size(),&StatusData);
break;
}
case LORA_MODULE_IF_INTERFACE_GENERAL_STATUS_RESPONSE:
{
qDebug("CLoraModuleInterfaceInterface : Received an invalid command from remote");
break;
}
}
return RET_OK;
}

View File

@ -0,0 +1,22 @@
#ifndef LORAMODULEINTERFACEINTERFACE_H
#define LORAMODULEINTERFACEINTERFACE_H
#include <QObject>
#include "NetworkDevice.h"
#include "LoraModuleInterface.h"
class CLoraModuleInterfaceInterface: public QObject, public CNetworkDevice
{
Q_OBJECT
public:
explicit CLoraModuleInterfaceInterface(int Address, CAbstractNetworkCommIF *NetworkInterface, CLoraModuleInterface *DevicePtr);
virtual int NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);
CLoraModuleInterface *mLoraModuleIFPtr;
signals:
public slots:
};
#endif // LORAMODULEINTERFACEINTERFACE_H

View File

@ -95,6 +95,7 @@ void CMasterCtrl::Start()
mNetworkDevicesManager->mAvReceiverDevice = mAVReceiverDevice;
mNetworkDevicesManager->mChaletLoraDevice = mChaletLoraDevice;
mNetworkDevicesManager->mIspindelDevice = mIspindelDevice;
mNetworkDevicesManager->mLoraModuleInterfaceDevice = mChaletLoraModuleInterface;
mEthernetNetworkServer->mDevicesMgrHandle = mNetworkDevicesManager;
@ -121,6 +122,7 @@ void CMasterCtrl::Start()
if(mMasterCtrlSettings.mChaletUseLoraIF)
{
mChaletLoraModuleInterface->SetLoraModuleInterfaceParameters(mMasterCtrlSettings.mChaletComPort,QSerialPort::Baud9600);
mChaletLoraModuleInterface->SetLoraDestinationAddress(mMasterCtrlSettings.mChaletLoraAddress, 65 /*mMasterCtrlSettings.mChaletLoraChannel*/);
}
else
{
@ -182,6 +184,7 @@ unsigned int CMasterCtrl::SettingsWindowClosed()
if(mChaletLoraModuleInterface != 0)
{
mChaletLoraModuleInterface->SetLoraDestinationAddress(mMasterCtrlSettings.mChaletLoraAddress, 65 /*mMasterCtrlSettings.mChaletLoraChannel*/); //JFM LoraInterface Dev
mChaletLoraModuleInterface->SetLoraModuleInterfaceParameters(mMasterCtrlSettings.mChaletComPort,QSerialPort::Baud9600);
}
if(mChaletLoraNetworkCommInterface != 0)

View File

@ -0,0 +1,13 @@
#include "NetworkCommIFSurrogate.h"
CNetworkCommIFSurrogate::CNetworkCommIFSurrogate()
{
}
int CNetworkCommIFSurrogate:: NewFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data)
{
emit ValidFrameReady(DeviceID, DeviceAddress, MessageID, DataSize, Data);
return RET_OK;
}

View File

@ -0,0 +1,21 @@
#ifndef NETWORKCOMMIFSURROGATE_H
#define NETWORKCOMMIFSURROGATE_H
#include "NetworkProtocol.h"
//This class allows to instanciate and manage a NetworkProtocol class to decode network messages behind a proxy like LoraNetworkCommIF.
class CNetworkCommIFSurrogate : public QObject, public CNetworkProtocol
{
Q_OBJECT
public:
CNetworkCommIFSurrogate();
virtual int NewFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);// = 0;
signals:
void ValidFrameReady(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);
void DataReceiveError(CNetworkProtocol::ProtocolRetValues RetID);
};
#endif // NETWORKCOMMIFSURROGATE_H

View File

@ -7,6 +7,7 @@
CNetworkDevicesMgr::CNetworkDevicesMgr()
{
mVoipMSInterfaceHandle = 0;
@ -15,6 +16,7 @@ CNetworkDevicesMgr::CNetworkDevicesMgr()
mAvReceiverDevice = 0;
mChaletLoraDevice = 0;
mIspindelDevice = 0;
mLoraModuleInterfaceDevice = 0;
}
CNetworkDevicesMgr::~CNetworkDevicesMgr()
@ -116,6 +118,18 @@ int CNetworkDevicesMgr::CreateNewIspindleInterface(int Address, CAbstractNetwork
return RET_OK;
}
int CNetworkDevicesMgr::CreateNewLoraInterfaceInterface(int Address, CAbstractNetworkCommIF *NetworkIF)
{
if(mLoraModuleInterfaceDevice == 0)
{
return RET_ERROR;
}
CLoraModuleInterfaceInterface *LoraModuleIFInterface = new CLoraModuleInterfaceInterface(Address,NetworkIF,mLoraModuleInterfaceDevice);
mNetworkDevicesList.append((CNetworkDevice*)LoraModuleIFInterface);
return RET_OK;
}
void CNetworkDevicesMgr::EthernetNetworkDeviceDisconnected(CNetworkDevice *Device)
{
qDebug("Device disconnected. ID: %d, Address: %d",Device->GetDeviceID(),Device->GetDeviceAddress());

View File

@ -9,6 +9,7 @@
#include "AvReceiverInterface.h"
#include "ChaletInterface.h"
#include "IspindelInterface.h"
#include "LoraModuleInterfaceInterface.h"
#include "QList"
#include <QObject>
@ -20,6 +21,7 @@ class CSprinklerMgr;
class CAVReceiverDevice;
class CChaletLoraDevice;
class CIspindelDevice;
class CLoraModuleInterface;
class CNetworkDevicesMgr: public QObject
{
@ -37,6 +39,7 @@ public:
int CreateNewAvReceiverInterface(int Address, CAbstractNetworkCommIF *NetworkIF);
int CreateNewChaletInterface(int Address, CAbstractNetworkCommIF *NetworkIF);
int CreateNewIspindleInterface(int Address, CAbstractNetworkCommIF *NetworkIF);
int CreateNewLoraInterfaceInterface(int Address, CAbstractNetworkCommIF *NetworkIF);
int FindDeviceByPtr(CNetworkDevice *Device);
CNetworkDevice *GetDevice(int DeviceID, int Address);
@ -49,6 +52,7 @@ public:
CContactRepository *mContactRepositoryHandle;
CMasterCtrl *mProgramHandle;
CSprinklerMgr *mSprinklerMgrHandle;
CLoraModuleInterface *mLoraModuleInterfaceDevice;
int NewSMSMessagesReceived(QList<CSMSMessage> NewMessages);

View File

@ -8,6 +8,9 @@ CNetworkProtocol::CNetworkProtocol()
mIsResetManual = false;
ResetRxStateMachine();
mMyNetworkAddress = 1;
mMyNetworkID = ID_MASTER;
}
CNetworkProtocol::~CNetworkProtocol()
@ -172,7 +175,7 @@ int CNetworkProtocol::RxStateMachine(unsigned char Data, bool DoStaticAnalysis)
else
{
ResetRxStateMachine();
ret = PROTOCOL_RET_OK_BAD_HEADER;
ret = PROTOCOL_RET_ERROR_BAD_HEADER;
}
break;
@ -196,7 +199,7 @@ int CNetworkProtocol::RxStateMachine(unsigned char Data, bool DoStaticAnalysis)
case RxMyID:
{
if(Data != ID_MASTER && Data != 0xFF) //Message is not for Master and it's not a broadcast
if(Data != mMyNetworkID && Data != 0xFF) //Message is not for Master and it's not a broadcast
{
ResetRxStateMachine();
ret = PROTOCOL_RET_ERROR_INVALID_TARGET_DEVICE;
@ -210,7 +213,7 @@ int CNetworkProtocol::RxStateMachine(unsigned char Data, bool DoStaticAnalysis)
}
case RxMyAddress:
{
if(Data != 1 && Data != 0xFF) //Message is not for us and it's not a broadcast
if(Data != mMyNetworkAddress && Data != 0xFF) //Message is not for us and it's not a broadcast
{
ResetRxStateMachine();
ret = PROTOCOL_RET_ERROR_INVALID_TARGET_ADDRESS;
@ -361,9 +364,9 @@ int CNetworkProtocol::AnalyzeRxBuffer(QByteArray Buffer)
ret = RxStateMachine(Buffer.at(i));
if(ret != PROTOCOL_RET_OK_PACKET_INCOMPLETE)
{
if(ret == PROTOCOL_RET_OK_BAD_HEADER)
if(ret == PROTOCOL_RET_ERROR_BAD_HEADER)
{
// qDebug("Protocol Bad header");
qDebug("Protocol Bad header");
}
else
{
@ -388,7 +391,7 @@ int CNetworkProtocol::ProtocolAnalyseBufferStatically(QByteArray InputBuffer, in
ret = RxStateMachine(InputBuffer.at(i));
if(ret != PROTOCOL_RET_OK_PACKET_INCOMPLETE)
{
if(ret == PROTOCOL_RET_OK_BAD_HEADER)
if(ret == PROTOCOL_RET_ERROR_BAD_HEADER)
{
qDebug("Protocol Bad header");
}

View File

@ -20,11 +20,14 @@ public:
virtual int NewFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);// = 0;
unsigned char mMyNetworkAddress;
unsigned char mMyNetworkID;
enum ProtocolRetValues
{
PROTOCOL_RET_OK_PACKET_COMPLETE,
PROTOCOL_RET_OK_PACKET_INCOMPLETE,
PROTOCOL_RET_OK_BAD_HEADER,
PROTOCOL_RET_ERROR_BAD_HEADER,
PROTOCOL_RET_ERROR_INVALID_TARGET_DEVICE,
PROTOCOL_RET_ERROR_INVALID_TARGET_ADDRESS,
PROTOCOL_RET_ERROR_BAD_CRC,

View File

@ -61,7 +61,8 @@ enum DEVICES_IDS
ID_CHALET_INTERFACE,
ID_CHALET_DEVICE,
ID_ISPINDEL_INTERFACE,
ID_LORA_INTERFACE,
ID_LORA_INTERFACE_DEVICE,
ID_LORA_INTERFACE_INTERFACE,
ID_NB_DEVICE_ID
};
@ -393,4 +394,14 @@ enum LORA_INTERFACE_CMDS
MAX_LORA_IF_CMD
};
enum LORA_MODULE_IF_INTERFACE_CMDS
{
LORA_MODULE_IF_INTERFACE_ACK = 1,
LORA_MODULE_IF_INTERFACE_GENERAL_STATUS_REQUEST,
LORA_MODULE_IF_INTERFACE_GENERAL_STATUS_RESPONSE,
MAX_LORA_MODULE_IF_INTERFACE_CMD
};
#endif