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