Changes in inheritance scheme for network protocol implementation
This commit is contained in:
parent
a955ae9ea8
commit
1a7ca49b7d
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@
|
||||
/Makefile.Release
|
||||
release
|
||||
debug
|
||||
*.autosave
|
||||
|
||||
@ -10,6 +10,8 @@ HEADERS += \
|
||||
Sources/NetworkProtocol.h \
|
||||
Sources/AbstractNetworkInterface.h \
|
||||
Sources/DeadboltDevice.h \
|
||||
Sources/AbstractDevice.h \
|
||||
Sources/ProtocolDefs.h
|
||||
|
||||
SOURCES += \
|
||||
Sources/main.cpp \
|
||||
|
||||
@ -1,19 +1,24 @@
|
||||
#include "232NetworkCommIF.h"
|
||||
|
||||
C232NetworkCommIF::C232NetworkCommIF(CAbstractNetworkCommIF *DeviceHandle)
|
||||
C232NetworkCommIF::C232NetworkCommIF(CAbstractDevice *DeviceHandle)
|
||||
{
|
||||
mDeviceHandle = DeviceHandle;
|
||||
mNetworkProtocol = new CNetworkProtocol(this);
|
||||
// mNetworkProtocol = new CNetworkProtocol(this);
|
||||
}
|
||||
C232NetworkCommIF::~C232NetworkCommIF()
|
||||
{
|
||||
delete mNetworkProtocol;
|
||||
}
|
||||
|
||||
int C232NetworkCommIF::NewFrameReceived(QByteArray Frame)
|
||||
{
|
||||
//FWD to device...
|
||||
//Nothing to do with the data here, up it goes to the device!
|
||||
mDeviceHandle->NewFrameReceived(Frame);
|
||||
//Nothing to do with the data here, up it goes to the device instance!
|
||||
mDeviceHandle->NewDeviceFrameReceived(Frame);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int C232NetworkCommIF::SendNetworkMessage(unsigned char MessageID, unsigned char Flags, unsigned char *Data, int Size)
|
||||
{
|
||||
GetTxPacket(MessageID,Flags,Data,Size,mDeviceHandle->GetDeviceAddress(),mDeviceHandle->GetDeviceID());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -2,21 +2,24 @@
|
||||
#define _232NETWORKCOMMIF_H
|
||||
|
||||
#include "GlobalDefine.h"
|
||||
#include "AbstractNetworkInterface.h"
|
||||
#include "AbstractDevice.h"
|
||||
#include "NetworkProtocol.h"
|
||||
|
||||
class C232NetworkCommIF : public CAbstractNetworkCommIF
|
||||
class C232NetworkCommIF : public CNetworkProtocol
|
||||
{
|
||||
public:
|
||||
C232NetworkCommIF(CAbstractNetworkCommIF *DeviceHandle);
|
||||
C232NetworkCommIF(CAbstractDevice *DeviceHandle);
|
||||
~C232NetworkCommIF();
|
||||
|
||||
int SendNetworkMessage(unsigned char MessageID,unsigned char Flags,unsigned char *Data,int Size/*, unsigned char Address,unsigned char ID*/);
|
||||
|
||||
virtual int NewFrameReceived(QByteArray Frame);
|
||||
|
||||
|
||||
//NetworkProtocol implementation
|
||||
int NewFrameReceived(QByteArray Frame);
|
||||
|
||||
private:
|
||||
CNetworkProtocol *mNetworkProtocol;
|
||||
CAbstractNetworkCommIF *mDeviceHandle;
|
||||
CAbstractDevice *mDeviceHandle;
|
||||
};
|
||||
|
||||
#endif // _232NETWORKCOMMIF_H
|
||||
|
||||
@ -3,3 +3,14 @@
|
||||
C485NetworkCommIF::C485NetworkCommIF()
|
||||
{
|
||||
}
|
||||
|
||||
int C485NetworkCommIF::NewFrameReceived(QByteArray Frame)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int C485NetworkCommIF::RegisterNewDevice(CAbstractDevice *NewDevice)
|
||||
{
|
||||
mDevicesList.append(NewDevice);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1,10 +1,21 @@
|
||||
#ifndef _485NETWORKCOMMIF_H
|
||||
#define _485NETWORKCOMMIF_H
|
||||
#include "NetworkProtocol.h"
|
||||
#include "AbstractDevice.h"
|
||||
|
||||
class C485NetworkCommIF
|
||||
class C485NetworkCommIF : public CNetworkProtocol
|
||||
{
|
||||
public:
|
||||
C485NetworkCommIF();
|
||||
|
||||
|
||||
//NetworkProtocol implementation
|
||||
int NewFrameReceived(QByteArray Frame);
|
||||
|
||||
int RegisterNewDevice(CAbstractDevice *NewDevice);
|
||||
|
||||
private:
|
||||
QList<CAbstractDevice *> mDevicesList;
|
||||
};
|
||||
|
||||
#endif // _485NETWORKCOMMIF_H
|
||||
|
||||
16
Sources/AbstractDevice.h
Normal file
16
Sources/AbstractDevice.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef ABSTRACTDEVICE_H
|
||||
#define ABSTRACTDEVICE_H
|
||||
#include <QByteArray>
|
||||
|
||||
class CAbstractDevice
|
||||
{
|
||||
public:
|
||||
virtual int NewDeviceFrameReceived(QByteArray Frame) = 0;
|
||||
virtual int GetDeviceID(){return mDeviceID;}
|
||||
virtual int GetDeviceAddress(){return mDeviceAddress;}
|
||||
|
||||
int mDeviceID;
|
||||
int mDeviceAddress;
|
||||
|
||||
};
|
||||
#endif // ABSTRACTDEVICE_H
|
||||
@ -1,8 +1,11 @@
|
||||
#include "DeadboltDevice.h"
|
||||
|
||||
CDeadboltDevice::CDeadboltDevice()
|
||||
|
||||
CDeadboltDevice::CDeadboltDevice(int Address)
|
||||
{
|
||||
mNetworkCommInterface = new C232NetworkCommIF(this);
|
||||
mDeviceAddress = Address;
|
||||
mDeviceID = ID_DEADBOLT;
|
||||
}
|
||||
|
||||
CDeadboltDevice::~CDeadboltDevice()
|
||||
@ -10,7 +13,9 @@ CDeadboltDevice::~CDeadboltDevice()
|
||||
delete mNetworkCommInterface;
|
||||
}
|
||||
|
||||
int CDeadboltDevice::NewFrameReceived(QByteArray Frame)
|
||||
int CDeadboltDevice::NewDeviceFrameReceived(QByteArray Frame)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3,15 +3,16 @@
|
||||
|
||||
#include "GlobalDefine.h"
|
||||
#include "232NetworkCommIF.h"
|
||||
//#include "AbstractNetworkInterface.h"
|
||||
#include "AbstractDevice.h"
|
||||
|
||||
|
||||
class CDeadboltDevice: public CAbstractNetworkCommIF
|
||||
class CDeadboltDevice: public CAbstractDevice
|
||||
{
|
||||
public:
|
||||
CDeadboltDevice();
|
||||
CDeadboltDevice(int Address);
|
||||
~CDeadboltDevice();
|
||||
virtual int NewFrameReceived(QByteArray Frame);
|
||||
|
||||
virtual int NewDeviceFrameReceived(QByteArray Frame);
|
||||
|
||||
|
||||
C232NetworkCommIF *mNetworkCommInterface;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
CMasterCtrl::CMasterCtrl()
|
||||
{
|
||||
qDebug("Creation...");
|
||||
mDeadBoltDevice = new CDeadboltDevice;
|
||||
mDeadBoltDevice = new CDeadboltDevice(1);
|
||||
}
|
||||
|
||||
CMasterCtrl::~CMasterCtrl()
|
||||
|
||||
@ -4,9 +4,8 @@
|
||||
#include "QByteArray"
|
||||
|
||||
|
||||
CNetworkProtocol::CNetworkProtocol(CAbstractNetworkCommIF *Parent)
|
||||
CNetworkProtocol::CNetworkProtocol()
|
||||
{
|
||||
mParentHandle = Parent;
|
||||
ResetRxStateMachine();
|
||||
|
||||
}
|
||||
@ -252,7 +251,8 @@ void CNetworkProtocol::RxStateMachine(unsigned char Data)
|
||||
|
||||
//Data is OK... execute
|
||||
// ExecuteCommand();
|
||||
mParentHandle->NewFrameReceived(QByteArray(mRxData,RxSize+10));
|
||||
// mParentHandle->NewFrameReceived(QByteArray(mRxData,RxSize+10));
|
||||
NewFrameReceived(QByteArray(mRxData,RxSize+10));
|
||||
ResetRxStateMachine();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -8,11 +8,12 @@
|
||||
class CNetworkProtocol
|
||||
{
|
||||
public:
|
||||
CNetworkProtocol(CAbstractNetworkCommIF *Parent);
|
||||
CNetworkProtocol();
|
||||
~CNetworkProtocol();
|
||||
CAbstractNetworkCommIF *mParentHandle;
|
||||
QByteArray GetTxPacket(unsigned char MessageID,unsigned char Flags,unsigned char *Data,int Size, unsigned char Address,unsigned char ID);
|
||||
|
||||
virtual int NewFrameReceived(QByteArray Frame) = 0;
|
||||
|
||||
private:
|
||||
void ResetRxStateMachine();
|
||||
unsigned char CalcCRC(char *Buffer, int Size);
|
||||
|
||||
@ -43,6 +43,8 @@ enum DEVICES_IDS
|
||||
ID_PC, //PC
|
||||
ID_AV_MUX, //Audio Video Multiplexer
|
||||
ID_IR_REMOTE, //Infra red transmitter
|
||||
ID_DEADBOLT,
|
||||
ID_RECEIVER_AMP,
|
||||
ID_NB_DEVICE_ID
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user