Network & SMS dev
This commit is contained in:
parent
3090a711e8
commit
17738c5b5d
@ -8,10 +8,7 @@ HEADERS += \
|
|||||||
Sources/EthernetNetworkCommIF.h \
|
Sources/EthernetNetworkCommIF.h \
|
||||||
Sources/232NetworkCommIF.h \
|
Sources/232NetworkCommIF.h \
|
||||||
Sources/NetworkProtocol.h \
|
Sources/NetworkProtocol.h \
|
||||||
Sources/AbstractNetworkInterface.h \
|
|
||||||
Sources/DeadboltDevice.h \
|
Sources/DeadboltDevice.h \
|
||||||
Sources/AbstractDevice.h \
|
|
||||||
Sources/ProtocolDefs.h \
|
|
||||||
Sources/AVReceiverDevice.h \
|
Sources/AVReceiverDevice.h \
|
||||||
Sources/VoipSMS/VoipMsSMSClient.h \
|
Sources/VoipSMS/VoipMsSMSClient.h \
|
||||||
Sources/VoipSMS/CSMSMessage.h \
|
Sources/VoipSMS/CSMSMessage.h \
|
||||||
@ -19,7 +16,12 @@ HEADERS += \
|
|||||||
Sources/Gui/SettingsWindow.h \
|
Sources/Gui/SettingsWindow.h \
|
||||||
Sources/ProgramSettings.h \
|
Sources/ProgramSettings.h \
|
||||||
Sources/Gui/AppIconWidget.h \
|
Sources/Gui/AppIconWidget.h \
|
||||||
../../SMSClient/Sources/SMSClient.h
|
Sources/ProtocolDefs.h \
|
||||||
|
Sources/EthernetNetworkServer.h \
|
||||||
|
Sources/NetworkDevicesMgr.h \
|
||||||
|
Sources/SMSDevice.h \
|
||||||
|
Sources/NetworkDevice.h \
|
||||||
|
Sources/AbstractNetworkInterface.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
Sources/main.cpp \
|
Sources/main.cpp \
|
||||||
@ -36,7 +38,10 @@ SOURCES += \
|
|||||||
Sources/Gui/SettingsWindow.cpp \
|
Sources/Gui/SettingsWindow.cpp \
|
||||||
Sources/ProgramSettings.cpp \
|
Sources/ProgramSettings.cpp \
|
||||||
Sources/Gui/AppIconWidget.cpp \
|
Sources/Gui/AppIconWidget.cpp \
|
||||||
../../SMSClient/Sources/SMSClient.cpp
|
Sources/EthernetNetworkServer.cpp \
|
||||||
|
Sources/NetworkDevicesMgr.cpp \
|
||||||
|
Sources/SMSDevice.cpp \
|
||||||
|
Sources/NetworkDevice.cpp
|
||||||
|
|
||||||
|
|
||||||
#win32:SOURCES += $$PWD/Source/qextserialport/win_qextserialport.cpp \
|
#win32:SOURCES += $$PWD/Source/qextserialport/win_qextserialport.cpp \
|
||||||
|
|||||||
@ -1,24 +1,36 @@
|
|||||||
#include "232NetworkCommIF.h"
|
#include "232NetworkCommIF.h"
|
||||||
|
#include "NetworkDevice.h"
|
||||||
|
|
||||||
C232NetworkCommIF::C232NetworkCommIF(CAbstractDevice *DeviceHandle)
|
C232NetworkCommIF::C232NetworkCommIF()
|
||||||
{
|
{
|
||||||
mDeviceHandle = DeviceHandle;
|
|
||||||
// mNetworkProtocol = new CNetworkProtocol(this);
|
|
||||||
}
|
}
|
||||||
C232NetworkCommIF::~C232NetworkCommIF()
|
C232NetworkCommIF::~C232NetworkCommIF()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int C232NetworkCommIF::NewFrameReceived(QByteArray Frame)
|
int C232NetworkCommIF::NewFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data)
|
||||||
{
|
{
|
||||||
//FWD to device...
|
//FWD to device...
|
||||||
//Nothing to do with the data here, up it goes to the device instance!
|
//Nothing to do with the data here, up it goes to the device instance!
|
||||||
mDeviceHandle->NewDeviceFrameReceived(Frame);
|
if(DeviceID == mDeviceHandle->GetDeviceID())
|
||||||
return 1;
|
{
|
||||||
|
if(DeviceAddress == BROADCAST_VALUE ||
|
||||||
|
DeviceAddress == mDeviceHandle->GetDeviceAddress())
|
||||||
|
{
|
||||||
|
mDeviceHandle->NewDeviceFrameReceived(DeviceID,DeviceAddress,MessageID,DataSize,Data);
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int C232NetworkCommIF::SendNetworkMessage(unsigned char MessageID, unsigned char Flags, unsigned char *Data, int Size)
|
//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;
|
||||||
|
//}
|
||||||
|
|
||||||
|
int C232NetworkCommIF::SendNetworkMessage(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data)
|
||||||
{
|
{
|
||||||
GetTxPacket(MessageID,Flags,Data,Size,mDeviceHandle->GetDeviceAddress(),mDeviceHandle->GetDeviceID());
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,24 +2,23 @@
|
|||||||
#define _232NETWORKCOMMIF_H
|
#define _232NETWORKCOMMIF_H
|
||||||
|
|
||||||
#include "GlobalDefine.h"
|
#include "GlobalDefine.h"
|
||||||
#include "AbstractDevice.h"
|
#include "NetworkDevice.h"
|
||||||
#include "NetworkProtocol.h"
|
#include "NetworkProtocol.h"
|
||||||
|
|
||||||
class C232NetworkCommIF : public CNetworkProtocol
|
class C232NetworkCommIF : public CNetworkProtocol, CAbstractNetworkCommIF
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
C232NetworkCommIF(CAbstractDevice *DeviceHandle);
|
C232NetworkCommIF();
|
||||||
virtual ~C232NetworkCommIF();
|
virtual ~C232NetworkCommIF();
|
||||||
|
|
||||||
int SendNetworkMessage(unsigned char MessageID,unsigned char Flags,unsigned char *Data,int Size/*, unsigned char Address,unsigned char ID*/);
|
//NetworkProtocol implementation
|
||||||
|
int NewFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);
|
||||||
|
|
||||||
|
//NetworkCommIF implementation
|
||||||
|
virtual int SendNetworkMessage(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);
|
||||||
//NetworkProtocol implementation
|
|
||||||
int NewFrameReceived(QByteArray Frame);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CAbstractDevice *mDeviceHandle;
|
CNetworkDevice *mDeviceHandle;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _232NETWORKCOMMIF_H
|
#endif // _232NETWORKCOMMIF_H
|
||||||
|
|||||||
@ -1,16 +1,28 @@
|
|||||||
#include "485NetworkCommIF.h"
|
#include "485NetworkCommIF.h"
|
||||||
|
#include "NetworkDevice.h"
|
||||||
|
|
||||||
C485NetworkCommIF::C485NetworkCommIF()
|
C485NetworkCommIF::C485NetworkCommIF()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int C485NetworkCommIF::NewFrameReceived(QByteArray Frame)
|
C485NetworkCommIF::~C485NetworkCommIF()
|
||||||
{
|
{
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int C485NetworkCommIF::RegisterNewDevice(CAbstractDevice *NewDevice)
|
int C485NetworkCommIF::NewFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data)
|
||||||
|
{
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int C485NetworkCommIF::RegisterNewDevice(CNetworkDevice *NewDevice)
|
||||||
{
|
{
|
||||||
mDevicesList.append(NewDevice);
|
mDevicesList.append(NewDevice);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int C485NetworkCommIF::SendNetworkMessage(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -1,21 +1,25 @@
|
|||||||
#ifndef _485NETWORKCOMMIF_H
|
#ifndef _485NETWORKCOMMIF_H
|
||||||
#define _485NETWORKCOMMIF_H
|
#define _485NETWORKCOMMIF_H
|
||||||
#include "NetworkProtocol.h"
|
#include "NetworkProtocol.h"
|
||||||
#include "AbstractDevice.h"
|
#include "NetworkDevice.h"
|
||||||
|
|
||||||
class C485NetworkCommIF : public CNetworkProtocol
|
class C485NetworkCommIF : public CNetworkProtocol, CAbstractNetworkCommIF
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
C485NetworkCommIF();
|
C485NetworkCommIF();
|
||||||
|
~C485NetworkCommIF();
|
||||||
|
|
||||||
|
int RegisterNewDevice(CNetworkDevice *NewDevice);
|
||||||
|
|
||||||
|
|
||||||
//NetworkProtocol implementation
|
//NetworkProtocol implementation
|
||||||
int NewFrameReceived(QByteArray Frame);
|
virtual int NewFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);
|
||||||
|
|
||||||
int RegisterNewDevice(CAbstractDevice *NewDevice);
|
//NetworkCommIF implementation
|
||||||
|
virtual int SendNetworkMessage(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<CAbstractDevice *> mDevicesList;
|
QList<CNetworkDevice *> mDevicesList;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _485NETWORKCOMMIF_H
|
#endif // _485NETWORKCOMMIF_H
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "AVReceiverDevice.h"
|
#include "AVReceiverDevice.h"
|
||||||
#include "GlobalDefine.h"
|
#include "GlobalDefine.h"
|
||||||
|
#include "ProtocolDefs.h"
|
||||||
|
|
||||||
CAVReceiverDevice::CAVReceiverDevice()
|
CAVReceiverDevice::CAVReceiverDevice()
|
||||||
{
|
{
|
||||||
@ -577,4 +578,3 @@ void CAVReceiverDevice::SocketRX()
|
|||||||
AnalyseRxData(mReceiverSocket->readAll());
|
AnalyseRxData(mReceiverSocket->readAll());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include "NetworkDevice.h"
|
||||||
|
|
||||||
#define RECEIVER_PORT 23
|
#define RECEIVER_PORT 23
|
||||||
#define RECEIVER_IP_ADDRESS "192.168.0.104"
|
#define RECEIVER_IP_ADDRESS "192.168.0.104"
|
||||||
@ -27,6 +28,7 @@ public:
|
|||||||
int ConnectToReceiver();
|
int ConnectToReceiver();
|
||||||
int DisconnectReceiver();
|
int DisconnectReceiver();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTcpSocket *mReceiverSocket;
|
QTcpSocket *mReceiverSocket;
|
||||||
int AnalyseRxData(QByteArray data);
|
int AnalyseRxData(QByteArray data);
|
||||||
|
|||||||
@ -1,16 +0,0 @@
|
|||||||
#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,10 +1,18 @@
|
|||||||
#ifndef ABSTRACTNETWORKINTERFACE_H
|
#ifndef ABSTRACTNETWORKINTERFACE_H
|
||||||
#define ABSTRACTNETWORKINTERFACE_H
|
#define ABSTRACTNETWORKINTERFACE_H
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
#include "GlobalDefine.h"
|
||||||
|
|
||||||
|
|
||||||
|
class CNetworkDevice;
|
||||||
class CAbstractNetworkCommIF
|
class CAbstractNetworkCommIF
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual int NewFrameReceived(QByteArray Frame) = 0;
|
|
||||||
|
CNetworkDevice *mDevicePtr;
|
||||||
|
CAbstractNetworkCommIF(){mDevicePtr = 0;}
|
||||||
|
virtual ~CAbstractNetworkCommIF() {}
|
||||||
|
virtual int SendNetworkMessage(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ABSTRACTNETWORKINTERFACE_H
|
#endif // ABSTRACTNETWORKINTERFACE_H
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
#include "DeadboltDevice.h"
|
#include "DeadboltDevice.h"
|
||||||
|
#include "ProtocolDefs.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
|
||||||
CDeadboltDevice::CDeadboltDevice(int Address)
|
CDeadboltDevice::CDeadboltDevice(int Address, CAbstractNetworkCommIF *NetworkInterface):
|
||||||
|
CNetworkDevice(ID_DEADBOLT,Address,NetworkInterface)
|
||||||
{
|
{
|
||||||
mNetworkCommInterface = new C232NetworkCommIF(this);
|
|
||||||
mDeviceAddress = Address;
|
|
||||||
mDeviceID = ID_DEADBOLT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CDeadboltDevice::~CDeadboltDevice()
|
CDeadboltDevice::~CDeadboltDevice()
|
||||||
@ -13,8 +14,29 @@ CDeadboltDevice::~CDeadboltDevice()
|
|||||||
delete mNetworkCommInterface;
|
delete mNetworkCommInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CDeadboltDevice::NewDeviceFrameReceived(QByteArray Frame)
|
int CDeadboltDevice::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(DeviceID)
|
||||||
|
Q_UNUSED(DeviceAddress)
|
||||||
|
|
||||||
|
switch(MessageID)
|
||||||
|
{
|
||||||
|
case DEADBOLT_DEVICE_STATUS_RESPONSE:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DEADBOLT_DEVICE_ACK:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DEADBOLT_DEVICE_STATUS_REQUEST:
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
qDebug("Received invalid msg from Deadbolt Device");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,19 +3,19 @@
|
|||||||
|
|
||||||
#include "GlobalDefine.h"
|
#include "GlobalDefine.h"
|
||||||
#include "232NetworkCommIF.h"
|
#include "232NetworkCommIF.h"
|
||||||
#include "AbstractDevice.h"
|
#include "NetworkDevice.h"
|
||||||
|
|
||||||
|
|
||||||
class CDeadboltDevice: public CAbstractDevice
|
class CDeadboltDevice: public CNetworkDevice
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CDeadboltDevice(int Address);
|
CDeadboltDevice(int Address, CAbstractNetworkCommIF *NetworkInterface);
|
||||||
virtual ~CDeadboltDevice();
|
virtual ~CDeadboltDevice();
|
||||||
|
|
||||||
virtual int NewDeviceFrameReceived(QByteArray Frame);
|
virtual int NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);
|
||||||
|
|
||||||
|
|
||||||
C232NetworkCommIF *mNetworkCommInterface;
|
CAbstractNetworkCommIF *mNetworkCommInterface;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEADBOLTDEVICE_H
|
#endif // DEADBOLTDEVICE_H
|
||||||
|
|||||||
@ -1,5 +1,28 @@
|
|||||||
#include "EthernetNetworkCommIF.h"
|
#include "EthernetNetworkCommIF.h"
|
||||||
|
#include "NetworkDevice.h"
|
||||||
|
|
||||||
CEthernetNetworkCommIF::CEthernetNetworkCommIF()
|
CEthernetNetworkCommIF::CEthernetNetworkCommIF(QTcpSocket *Socket)
|
||||||
{
|
{
|
||||||
|
mTCPSocket = Socket;
|
||||||
|
|
||||||
|
connect(mTCPSocket,SIGNAL(disconnected()),this,SLOT(SocketDisconnected()));
|
||||||
|
connect(mTCPSocket,SIGNAL(readyRead()),this,SLOT(SocketDataAvailable()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int CEthernetNetworkCommIF::SendNetworkMessage(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CEthernetNetworkCommIF::SocketDataAvailable()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CEthernetNetworkCommIF::SocketDisconnected()
|
||||||
|
{
|
||||||
|
mTCPSocket->close();
|
||||||
|
delete mTCPSocket;
|
||||||
|
emit EthernetInterfaceSocketDisconnected(mDevicePtr);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,37 @@
|
|||||||
#ifndef ETHERNETNETWORKCOMMIF_H
|
#ifndef ETHERNETNETWORKCOMMIF_H
|
||||||
#define ETHERNETNETWORKCOMMIF_H
|
#define ETHERNETNETWORKCOMMIF_H
|
||||||
|
|
||||||
class CEthernetNetworkCommIF
|
#include <QObject>
|
||||||
|
#include "NetworkProtocol.h"
|
||||||
|
#include <QTcpServer>
|
||||||
|
#include <QTcpSocket>
|
||||||
|
#include <QList>
|
||||||
|
#include <NetworkDevice.h>
|
||||||
|
#include "AbstractNetworkInterface.h"
|
||||||
|
|
||||||
|
|
||||||
|
class CEthernetNetworkCommIF : public QObject, CNetworkProtocol, CAbstractNetworkCommIF
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
CEthernetNetworkCommIF();
|
|
||||||
|
CEthernetNetworkCommIF(QTcpSocket *Socket);
|
||||||
|
virtual ~CEthernetNetworkCommIF();
|
||||||
|
|
||||||
|
QTcpSocket* mTCPSocket;
|
||||||
|
|
||||||
|
//CNetworkCommIF implementation
|
||||||
|
virtual int SendNetworkMessage(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data) = 0;
|
||||||
|
|
||||||
|
//CNetworkProtocol implementation
|
||||||
|
virtual int NewFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data) = 0;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void SocketDataAvailable();
|
||||||
|
void SocketDisconnected();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void EthernetInterfaceSocketDisconnected(CNetworkDevice *);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ETHERNETNETWORKCOMMIF_H
|
#endif // ETHERNETNETWORKCOMMIF_H
|
||||||
|
|||||||
215
Sources/EthernetNetworkServer.cpp
Normal file
215
Sources/EthernetNetworkServer.cpp
Normal file
@ -0,0 +1,215 @@
|
|||||||
|
#include "EthernetNetworkServer.h"
|
||||||
|
|
||||||
|
|
||||||
|
CEthernetNetworkServer::CEthernetNetworkServer()
|
||||||
|
{
|
||||||
|
|
||||||
|
SetManualPacketReset(true);
|
||||||
|
|
||||||
|
mEthernetNetworkServer = new QTcpServer;
|
||||||
|
connect(mEthernetNetworkServer,SIGNAL(newConnection()),this,SLOT(EthernetNetworkServerConnected()));
|
||||||
|
mEthernetNetworkServer->listen(QHostAddress::Any,80);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int CEthernetNetworkServer::NewFrameReceived(QByteArray Frame)
|
||||||
|
{
|
||||||
|
Q_UNUSED(Frame)
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CEthernetNetworkServer::EthernetNetworkServerConnected()
|
||||||
|
{
|
||||||
|
qDebug("Device Connected");
|
||||||
|
QTcpSocket *EthernetDeviceSocket;
|
||||||
|
|
||||||
|
EthernetDeviceSocket = mEthernetNetworkServer->nextPendingConnection();
|
||||||
|
CEthernetDeviceConnection *NewConnection = new CEthernetDeviceConnection;
|
||||||
|
NewConnection->mConnectionSocket = EthernetDeviceSocket;
|
||||||
|
mEthernetDeviceConnections.append(NewConnection);
|
||||||
|
|
||||||
|
connect(EthernetDeviceSocket,SIGNAL(readyRead()),this,SLOT(DeviceSocketDataAvail()));
|
||||||
|
|
||||||
|
//request device info...
|
||||||
|
QByteArray Frame = GetTxPacket((unsigned char)ETH_NETWK_DEVICE_INFO_REQUEST,0,0,0,BROADCAST_VALUE,(unsigned char)ID_ETHERNET_VIRTUAL);
|
||||||
|
EthernetDeviceSocket->write(Frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
CEthernetDeviceConnection * CEthernetNetworkServer::FindConnection(QTcpSocket *Socket)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < mEthernetDeviceConnections.size(); i++)
|
||||||
|
{
|
||||||
|
if(Socket == mEthernetDeviceConnections.at(i)->mConnectionSocket)
|
||||||
|
{
|
||||||
|
return mEthernetDeviceConnections.at(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CEthernetNetworkServer::FindConnection(CEthernetDeviceConnection* Connection)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < mEthernetDeviceConnections.size(); i++)
|
||||||
|
{
|
||||||
|
if(Connection == mEthernetDeviceConnections.at(i))
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CEthernetNetworkServer::DeviceSocketDataAvail()
|
||||||
|
{
|
||||||
|
QTcpSocket *DeviceSocket = (QTcpSocket*)QObject::sender();
|
||||||
|
QByteArray Packet = DeviceSocket->readAll();
|
||||||
|
CEthernetDeviceConnection *DeviceConnection = FindConnection(DeviceSocket);
|
||||||
|
|
||||||
|
|
||||||
|
int ret = AnalyzeRxBuffer(Packet);
|
||||||
|
bool CloseSocket = false;
|
||||||
|
// if(DeviceConnection == 0)
|
||||||
|
// {
|
||||||
|
// qDebug("Rx from unknown socket!");
|
||||||
|
// CloseSocket = true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
switch(ret)
|
||||||
|
{
|
||||||
|
case PROTOCOL_RET_OK_PACKET_COMPLETE:
|
||||||
|
{
|
||||||
|
if(ProtocolGetSenderID() == ID_ETHERNET_VIRTUAL)
|
||||||
|
{
|
||||||
|
if(ProtocolGetCmd() == ETH_NETWK_DEVICE_INFO_RESPONSE)
|
||||||
|
{
|
||||||
|
QByteArray Data = ProtocolGetData();
|
||||||
|
char DeviceID,DeviceAddress;
|
||||||
|
|
||||||
|
DeviceID = Data.at(0);
|
||||||
|
DeviceAddress = Data.at(1);
|
||||||
|
|
||||||
|
if(IsDeviceRegistered(DeviceID) == true)
|
||||||
|
{
|
||||||
|
DeviceConnection->mConnectedDevice->mDeviceID = (int)DeviceID;
|
||||||
|
DeviceConnection->mConnectedDevice->mDeviceAddress = (int)DeviceAddress;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug("Rx device info from unregistered device");
|
||||||
|
CloseSocket = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(DeviceConnection != 0)
|
||||||
|
{
|
||||||
|
DeviceConnection->mConnectedDevice->NewDeviceFrameReceived(ProtocolGetSenderID(),ProtocolGetSenderAddress(),ProtocolGetCmd(),ProtocolGetDataSize(),ProtocolGetData());
|
||||||
|
PrepareForNewPacket();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug("Rx from invalid device connection pointer!");
|
||||||
|
CloseSocket = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PROTOCOL_RET_OK_PACKET_INCOMPLETE:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PROTOCOL_RET_OK_BAD_HEADER:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PROTOCOL_RET_ERROR_INVALID_TARGET_DEVICE:
|
||||||
|
{
|
||||||
|
qDebug("Bad target device received on Ethernet network");
|
||||||
|
PrepareForNewPacket();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PROTOCOL_RET_ERROR_INVALID_TARGET_ADDRESS:
|
||||||
|
{
|
||||||
|
qDebug("Bad target address received on Ethernet network");
|
||||||
|
PrepareForNewPacket();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PROTOCOL_RET_ERROR_BAD_CRC:
|
||||||
|
{
|
||||||
|
qDebug("Bad target CRC on Ethernet network");
|
||||||
|
PrepareForNewPacket();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PROTOCOL_RET_ERROR_SM_LOGIC:
|
||||||
|
{
|
||||||
|
qDebug("LOGIC ERROR!!! on Ethernet network protocol");
|
||||||
|
PrepareForNewPacket();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(CloseSocket == true)
|
||||||
|
{
|
||||||
|
if(CloseConnection(DeviceConnection) != RET_OK)
|
||||||
|
{
|
||||||
|
DeviceSocket->close();
|
||||||
|
delete DeviceSocket;
|
||||||
|
}
|
||||||
|
PrepareForNewPacket();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CEthernetNetworkServer::DeviceSocketDisconnected()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int CEthernetNetworkServer::CloseConnection(CEthernetDeviceConnection *Connection)
|
||||||
|
{
|
||||||
|
if(Connection != 0)
|
||||||
|
{
|
||||||
|
int index = FindConnection(Connection);
|
||||||
|
if(index != -1)
|
||||||
|
{
|
||||||
|
Connection->mConnectionSocket->close();
|
||||||
|
mEthernetDeviceConnections.removeAt(index);
|
||||||
|
delete Connection;
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return RET_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CEthernetNetworkServer::RegisterNewDevice(CNetworkDevice *Device)
|
||||||
|
{
|
||||||
|
if(IsDeviceRegistered(Device->GetDeviceID()))
|
||||||
|
{
|
||||||
|
qDebug("Device already registered");
|
||||||
|
return RET_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
mNetworkDevices.append(Device);
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CEthernetNetworkServer::IsDeviceRegistered(int DeviceID)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < mNetworkDevices.size(); i++)
|
||||||
|
{
|
||||||
|
if(mNetworkDevices.at(i)->GetDeviceID() == DeviceID)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
51
Sources/EthernetNetworkServer.h
Normal file
51
Sources/EthernetNetworkServer.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#ifndef CETHERNETNETWORKSERVER_H
|
||||||
|
#define CETHERNETNETWORKSERVER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include "NetworkProtocol.h"
|
||||||
|
#include <QTcpServer>
|
||||||
|
#include <QTcpSocket>
|
||||||
|
#include <QList>
|
||||||
|
#include <NetworkDevice.h>
|
||||||
|
|
||||||
|
class CEthernetDeviceConnection
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
QTcpSocket *mConnectionSocket;
|
||||||
|
CNetworkDevice *mConnectedDevice;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class CEthernetNetworkServer : public QObject, CNetworkProtocol
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
CEthernetNetworkServer();
|
||||||
|
|
||||||
|
QTcpServer *mEthernetNetworkServer;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
QList<CNetworkDevice*> mNetworkDevices;
|
||||||
|
QList<CEthernetDeviceConnection*> mEthernetDeviceConnections;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
virtual int NewFrameReceived(QByteArray Frame);
|
||||||
|
bool IsDeviceRegistered(int DeviceID);
|
||||||
|
int RegisterNewDevice(CNetworkDevice* Device);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int FindConnection(CEthernetDeviceConnection* Connection);
|
||||||
|
CEthernetDeviceConnection *FindConnection(QTcpSocket* socket);
|
||||||
|
int CloseConnection(CEthernetDeviceConnection *Connection);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void EthernetNetworkServerConnected();
|
||||||
|
void DeviceSocketDataAvail();
|
||||||
|
void DeviceSocketDisconnected();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CETHERNETNETWORKSERVER_H
|
||||||
@ -48,7 +48,7 @@ CSettingsWindow::CSettingsWindow()
|
|||||||
|
|
||||||
|
|
||||||
mVoipMSCalendar = new QCalendarWidget;
|
mVoipMSCalendar = new QCalendarWidget;
|
||||||
Label = new QLabel("SMS retreival stard date:");
|
Label = new QLabel("SMS retreival start date:");
|
||||||
mSMSPageLayout->addWidget(Label,3,1,1,1);
|
mSMSPageLayout->addWidget(Label,3,1,1,1);
|
||||||
mSMSPageLayout->addWidget(mVoipMSCalendar,4,1,1,4);
|
mSMSPageLayout->addWidget(mVoipMSCalendar,4,1,1,4);
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
CMasterCtrl::CMasterCtrl()
|
CMasterCtrl::CMasterCtrl()
|
||||||
{
|
{
|
||||||
qDebug("Creation...");
|
qDebug("Creation...");
|
||||||
mDeadBoltDevice = new CDeadboltDevice(1);
|
// mDeadBoltDevice = new CDeadboltDevice(1);
|
||||||
mAVReceiverDevice = new CAVReceiverDevice;
|
mAVReceiverDevice = new CAVReceiverDevice;
|
||||||
mVoipMsSMSClient = new CVoipMsSMSClient;
|
mVoipMsSMSClient = new CVoipMsSMSClient;
|
||||||
mSystemTrayManager = new CSystemTrayManager;
|
mSystemTrayManager = new CSystemTrayManager;
|
||||||
@ -18,7 +18,7 @@ CMasterCtrl::~CMasterCtrl()
|
|||||||
{
|
{
|
||||||
mAVReceiverDevice->DisconnectReceiver();
|
mAVReceiverDevice->DisconnectReceiver();
|
||||||
|
|
||||||
delete mDeadBoltDevice;
|
// delete mDeadBoltDevice;
|
||||||
delete mAVReceiverDevice;
|
delete mAVReceiverDevice;
|
||||||
delete mVoipMsSMSClient;
|
delete mVoipMsSMSClient;
|
||||||
delete mSystemTrayManager;
|
delete mSystemTrayManager;
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
#include "SystemTrayManager.h"
|
#include "SystemTrayManager.h"
|
||||||
#include "SettingsWindow.h"
|
#include "SettingsWindow.h"
|
||||||
#include "ProgramSettings.h"
|
#include "ProgramSettings.h"
|
||||||
|
#include "NetworkDevicesMgr.h"
|
||||||
//#include "AppIconWidget.h"
|
//#include "AppIconWidget.h"
|
||||||
|
|
||||||
class CMasterCtrl : public QObject
|
class CMasterCtrl : public QObject
|
||||||
@ -18,12 +19,13 @@ public:
|
|||||||
~CMasterCtrl();
|
~CMasterCtrl();
|
||||||
|
|
||||||
void Start(void);
|
void Start(void);
|
||||||
CDeadboltDevice *mDeadBoltDevice;
|
// CDeadboltDevice *mDeadBoltDevice;
|
||||||
CAVReceiverDevice *mAVReceiverDevice;
|
CAVReceiverDevice *mAVReceiverDevice;
|
||||||
CVoipMsSMSClient *mVoipMsSMSClient;
|
CVoipMsSMSClient *mVoipMsSMSClient;
|
||||||
CSystemTrayManager *mSystemTrayManager;
|
CSystemTrayManager *mSystemTrayManager;
|
||||||
CSettingsWindow *mSettingsWindow;
|
CSettingsWindow *mSettingsWindow;
|
||||||
CProgramSettings mSettingsManager;
|
CProgramSettings mSettingsManager;
|
||||||
|
CNetworkDevicesMgr mNetworkDevicesManager;
|
||||||
// CAppIconWidget mAppWidget;
|
// CAppIconWidget mAppWidget;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
28
Sources/NetworkDevice.cpp
Normal file
28
Sources/NetworkDevice.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "NetworkDevice.h"
|
||||||
|
|
||||||
|
|
||||||
|
CNetworkDevice::CNetworkDevice(int DeviceID, int DeviceAddress, CAbstractNetworkCommIF *Interface)
|
||||||
|
{
|
||||||
|
mDeviceAddress = DeviceAddress;
|
||||||
|
mDeviceID = DeviceID;
|
||||||
|
SetNetworkInterface(Interface);
|
||||||
|
}
|
||||||
|
|
||||||
|
CNetworkDevice::~CNetworkDevice()
|
||||||
|
{
|
||||||
|
if(mNetworkInterfacePtr != 0)
|
||||||
|
{
|
||||||
|
delete mNetworkInterfacePtr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNetworkDevice::SetNetworkInterface(CAbstractNetworkCommIF *Interface)
|
||||||
|
{
|
||||||
|
mNetworkInterfacePtr = Interface;
|
||||||
|
if(Interface != 0)
|
||||||
|
{
|
||||||
|
mNetworkInterfacePtr->mDevicePtr = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
21
Sources/NetworkDevice.h
Normal file
21
Sources/NetworkDevice.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef NETWORKDEVICE_H
|
||||||
|
#define NETWORKDEVICE_H
|
||||||
|
#include <QByteArray>
|
||||||
|
#include "AbstractNetworkInterface.h"
|
||||||
|
|
||||||
|
class CNetworkDevice
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CNetworkDevice(int DeviceID, int DeviceAddress,CAbstractNetworkCommIF *Interface);
|
||||||
|
virtual ~CNetworkDevice();
|
||||||
|
virtual int NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data) = 0;
|
||||||
|
void SetNetworkInterface(CAbstractNetworkCommIF* Interface);
|
||||||
|
int GetDeviceID(){return mDeviceID;}
|
||||||
|
int GetDeviceAddress(){return mDeviceAddress;}
|
||||||
|
|
||||||
|
int mDeviceID;
|
||||||
|
int mDeviceAddress;
|
||||||
|
CAbstractNetworkCommIF *mNetworkInterfacePtr;
|
||||||
|
|
||||||
|
};
|
||||||
|
#endif // NETWORKDEVICE_H
|
||||||
77
Sources/NetworkDevicesMgr.cpp
Normal file
77
Sources/NetworkDevicesMgr.cpp
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
#include "NetworkDevicesMgr.h"
|
||||||
|
#include "232NetworkCommIF.h"
|
||||||
|
#include "485NetworkCommIF.h"
|
||||||
|
#include "EthernetNetworkCommIF.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CNetworkDevicesMgr::CNetworkDevicesMgr()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CNetworkDevicesMgr::~CNetworkDevicesMgr()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < mNetworkDevicesList.size(); i++)
|
||||||
|
{
|
||||||
|
delete mNetworkDevicesList.at(i);
|
||||||
|
}
|
||||||
|
mNetworkDevicesList.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
int CNetworkDevicesMgr::InitNetworkDevices()
|
||||||
|
{
|
||||||
|
|
||||||
|
C232NetworkCommIF *NetworkInterface = new C232NetworkCommIF();
|
||||||
|
CDeadboltDevice *DeadboltDevice = new CDeadboltDevice(1,(CAbstractNetworkCommIF*)NetworkInterface);
|
||||||
|
mNetworkDevicesList.append(DeadboltDevice);
|
||||||
|
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CNetworkDevicesMgr::CreateNewSMSDevice(int Address, CAbstractNetworkCommIF *NetworkIF)
|
||||||
|
{
|
||||||
|
CSMSDevice *SMSDevice = new CSMSDevice(Address,NetworkIF);
|
||||||
|
|
||||||
|
mNetworkDevicesList.append(SMSDevice);
|
||||||
|
|
||||||
|
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNetworkDevicesMgr::EthernetNetworkDeviceDisconnected(CNetworkDevice *Device)
|
||||||
|
{
|
||||||
|
int index = FindDeviceByPtr(Device);
|
||||||
|
if(index != -1)
|
||||||
|
{
|
||||||
|
delete mNetworkDevicesList.at(index);
|
||||||
|
mNetworkDevicesList.removeAt(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int CNetworkDevicesMgr::FindDeviceByPtr(CNetworkDevice *Device)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < mNetworkDevicesList.size(); i++)
|
||||||
|
{
|
||||||
|
if(mNetworkDevicesList.at(i) == Device)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
CNetworkDevice* CNetworkDevicesMgr::GetDevice(int DeviceID, int Address)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < mNetworkDevicesList.size(); i++)
|
||||||
|
{
|
||||||
|
if(mNetworkDevicesList.at(i)->GetDeviceID() == DeviceID &&
|
||||||
|
mNetworkDevicesList.at(i)->GetDeviceAddress() == Address)
|
||||||
|
{
|
||||||
|
return mNetworkDevicesList.at(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
34
Sources/NetworkDevicesMgr.h
Normal file
34
Sources/NetworkDevicesMgr.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#ifndef CNETWORKDEVICESMGR_H
|
||||||
|
#define CNETWORKDEVICESMGR_H
|
||||||
|
|
||||||
|
#include "DeadboltDevice.h"
|
||||||
|
#include "AVReceiverDevice.h"
|
||||||
|
#include "SMSDevice.h"
|
||||||
|
#include "AbstractNetworkInterface.h"
|
||||||
|
#include "QList"
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class CNetworkDevicesMgr: public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
|
||||||
|
CNetworkDevicesMgr();
|
||||||
|
virtual ~CNetworkDevicesMgr();
|
||||||
|
|
||||||
|
int InitNetworkDevices();
|
||||||
|
|
||||||
|
int CreateNewSMSDevice(int Address,CAbstractNetworkCommIF *NetworkIF);
|
||||||
|
|
||||||
|
int FindDeviceByPtr(CNetworkDevice *Device);
|
||||||
|
CNetworkDevice *GetDevice(int DeviceID, int Address);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
QList<CNetworkDevice*> mNetworkDevicesList;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void EthernetNetworkDeviceDisconnected(CNetworkDevice*);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CNETWORKDEVICESMGR_H
|
||||||
19
Sources/NetworkInterface.cpp
Normal file
19
Sources/NetworkInterface.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "NetworkInterface.h"
|
||||||
|
|
||||||
|
|
||||||
|
CNetworkCommIF::CNetworkCommIF()
|
||||||
|
{
|
||||||
|
mDevicePtr = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CNetworkCommIF::SendNetworkMessage(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data)
|
||||||
|
{
|
||||||
|
Q_UNUSED(DeviceID)
|
||||||
|
Q_UNUSED(DeviceAddress)
|
||||||
|
Q_UNUSED(MessageID)
|
||||||
|
Q_UNUSED(DataSize)
|
||||||
|
Q_UNUSED(Data)
|
||||||
|
|
||||||
|
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "NetworkProtocol.h"
|
#include "NetworkProtocol.h"
|
||||||
#include "QByteArray"
|
|
||||||
|
|
||||||
|
|
||||||
CNetworkProtocol::CNetworkProtocol()
|
CNetworkProtocol::CNetworkProtocol()
|
||||||
{
|
{
|
||||||
|
mIsResetManual = false;
|
||||||
ResetRxStateMachine();
|
ResetRxStateMachine();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -32,8 +32,31 @@ unsigned char CNetworkProtocol::CalcCRC(char *Buffer, int Size)
|
|||||||
return CRC;
|
return CRC;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray CNetworkProtocol::GetTxPacket(unsigned char MessageID, unsigned char Flags, unsigned char *Data, int Size, unsigned char Address, unsigned char ID)
|
QByteArray CNetworkProtocol::GetTxPacket(unsigned char MessageID, unsigned char Flags, const char *Data, int Size, unsigned char Address, unsigned char ID, unsigned char SenderDevice, unsigned char SenderAddress)
|
||||||
{
|
{
|
||||||
|
#ifdef USE_BYTEARRAY_IN_SEND
|
||||||
|
|
||||||
|
QByteArray Frame;
|
||||||
|
Frame.clear();
|
||||||
|
int FrameSize = Size + 9; //Add header data...
|
||||||
|
|
||||||
|
Frame.append(FRAME_HEADER); //header
|
||||||
|
Frame.append(SenderAddress); //Device address (default = MasterCtrl)
|
||||||
|
Frame.append(SenderDevice); //Device ID (default = MasterCtrl
|
||||||
|
Frame.append(ID); //destination ID
|
||||||
|
Frame.append(Address); //Destination Address
|
||||||
|
Frame.append(Flags);
|
||||||
|
Frame.append(MessageID); //Cmd
|
||||||
|
Frame.append(((FrameSize - 9) & 0xFF00) >> 8);
|
||||||
|
Frame.append((FrameSize - 9) & 0x00FF);
|
||||||
|
Frame.append(Data,Size);
|
||||||
|
char CRC = CalcCRC(Frame.data(),FrameSize);
|
||||||
|
Frame.append(CRC);
|
||||||
|
|
||||||
|
return Frame;
|
||||||
|
|
||||||
|
|
||||||
|
#else
|
||||||
int toto;
|
int toto;
|
||||||
char temp;
|
char temp;
|
||||||
char OutBuffer[MAX_MESSAGE_SIZE+10];
|
char OutBuffer[MAX_MESSAGE_SIZE+10];
|
||||||
@ -41,13 +64,13 @@ QByteArray CNetworkProtocol::GetTxPacket(unsigned char MessageID, unsigned char
|
|||||||
int FrameSize = Size + 9; //Add header data...
|
int FrameSize = Size + 9; //Add header data...
|
||||||
|
|
||||||
OutBuffer[0] = (char)FRAME_HEADER; //header
|
OutBuffer[0] = (char)FRAME_HEADER; //header
|
||||||
OutBuffer[1] = 1; //MasterCtrl address
|
OutBuffer[1] = SenderAddress; //Device address (default = MasterCtrl)
|
||||||
OutBuffer[2] = ID_MASTER; //MasterCtrl ID
|
OutBuffer[2] = SenderDevice; //Device ID (default = MasterCtrl
|
||||||
OutBuffer[3] = (char)ID; //destination ID
|
OutBuffer[3] = (char)ID; //destination ID
|
||||||
OutBuffer[4] = (char)Address; //Destination Address
|
OutBuffer[4] = (char)Address; //Destination Address
|
||||||
OutBuffer[5] = (char)Flags;
|
OutBuffer[5] = (char)Flags;
|
||||||
OutBuffer[6] = (char)MessageID; //Cmd
|
OutBuffer[6] = (char)MessageID; //Cmd
|
||||||
toto = FrameSize & 0xFF00;
|
// toto = FrameSize & 0xFF00;
|
||||||
temp = FrameSize >> 8;
|
temp = FrameSize >> 8;
|
||||||
OutBuffer[7] = ((FrameSize - 9) & 0xFF00) >> 8;
|
OutBuffer[7] = ((FrameSize - 9) & 0xFF00) >> 8;
|
||||||
OutBuffer[8] = (FrameSize - 9) & 0x00FF;
|
OutBuffer[8] = (FrameSize - 9) & 0x00FF;
|
||||||
@ -64,6 +87,7 @@ QByteArray CNetworkProtocol::GetTxPacket(unsigned char MessageID, unsigned char
|
|||||||
// CSerialComm::instance()->WriteData(&OutBuffer[0],FrameSize+1);
|
// CSerialComm::instance()->WriteData(&OutBuffer[0],FrameSize+1);
|
||||||
|
|
||||||
return QByteArray(OutBuffer,FrameSize);
|
return QByteArray(OutBuffer,FrameSize);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//int CNetworkProtocol::TxData(unsigned char MessageID,unsigned char Flags,unsigned char *Data,int Size, unsigned char Address,unsigned char ID)
|
//int CNetworkProtocol::TxData(unsigned char MessageID,unsigned char Flags,unsigned char *Data,int Size, unsigned char Address,unsigned char ID)
|
||||||
@ -128,8 +152,10 @@ QByteArray CNetworkProtocol::GetTxPacket(unsigned char MessageID, unsigned char
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
void CNetworkProtocol::RxStateMachine(unsigned char Data)
|
int CNetworkProtocol::RxStateMachine(unsigned char Data)
|
||||||
{
|
{
|
||||||
|
int ret = PROTOCOL_RET_OK_PACKET_INCOMPLETE;
|
||||||
|
|
||||||
switch(RxState)
|
switch(RxState)
|
||||||
{
|
{
|
||||||
case RxHeader: //Wait for data header...
|
case RxHeader: //Wait for data header...
|
||||||
@ -143,6 +169,7 @@ void CNetworkProtocol::RxStateMachine(unsigned char Data)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ResetRxStateMachine();
|
ResetRxStateMachine();
|
||||||
|
ret = PROTOCOL_RET_OK_BAD_HEADER;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -169,6 +196,8 @@ void CNetworkProtocol::RxStateMachine(unsigned char Data)
|
|||||||
if(Data != ID_PC && Data != 0xFF) //Message is not for a console and it's not a broadcast
|
if(Data != ID_PC && Data != 0xFF) //Message is not for a console and it's not a broadcast
|
||||||
{
|
{
|
||||||
ResetRxStateMachine();
|
ResetRxStateMachine();
|
||||||
|
ret = PROTOCOL_RET_ERROR_INVALID_TARGET_DEVICE;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mRxData[BufPtr++] = Data;
|
mRxData[BufPtr++] = Data;
|
||||||
@ -181,6 +210,8 @@ void CNetworkProtocol::RxStateMachine(unsigned char Data)
|
|||||||
if(Data != 1 && Data != 0xFF) //Message is not for us and it's not a broadcast
|
if(Data != 1 && Data != 0xFF) //Message is not for us and it's not a broadcast
|
||||||
{
|
{
|
||||||
ResetRxStateMachine();
|
ResetRxStateMachine();
|
||||||
|
ret = PROTOCOL_RET_ERROR_INVALID_TARGET_ADDRESS;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mRxData[BufPtr++] = Data;
|
mRxData[BufPtr++] = Data;
|
||||||
@ -246,23 +277,29 @@ void CNetworkProtocol::RxStateMachine(unsigned char Data)
|
|||||||
if(Data != CRC) //Data corruption
|
if(Data != CRC) //Data corruption
|
||||||
{
|
{
|
||||||
ResetRxStateMachine();
|
ResetRxStateMachine();
|
||||||
|
ret = PROTOCOL_RET_ERROR_BAD_CRC;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Data is OK... execute
|
mDataBuffer = QByteArray(&mRxData[DATA_START],RxSize);
|
||||||
// ExecuteCommand();
|
NewFrameReceived(SenderID,SenderAddress,RxCmd,RxSize,mDataBuffer);
|
||||||
// mParentHandle->NewFrameReceived(QByteArray(mRxData,RxSize+10));
|
ret = PROTOCOL_RET_OK_PACKET_COMPLETE;
|
||||||
NewFrameReceived(QByteArray(mRxData,RxSize+10));
|
if(mIsResetManual)
|
||||||
ResetRxStateMachine();
|
{
|
||||||
|
ResetRxStateMachine();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
ret = PROTOCOL_RET_ERROR_SM_LOGIC;
|
||||||
ResetRxStateMachine();
|
ResetRxStateMachine();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CNetworkProtocol::ResetRxStateMachine(void)
|
void CNetworkProtocol::ResetRxStateMachine(void)
|
||||||
@ -277,96 +314,37 @@ void CNetworkProtocol::ResetRxStateMachine(void)
|
|||||||
BufPtr = 0;
|
BufPtr = 0;
|
||||||
CRC = 0;
|
CRC = 0;
|
||||||
Flags = 0;
|
Flags = 0;
|
||||||
|
mDataBuffer.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
//void CNetworkProtocol::ExecuteCommand()
|
void CNetworkProtocol::PrepareForNewPacket()
|
||||||
//{
|
{
|
||||||
// switch(RxCmd)
|
ResetRxStateMachine();
|
||||||
// {
|
}
|
||||||
// case TX_MASTER_STATUS:
|
|
||||||
// {
|
|
||||||
// mMasterCtrlHandle->MasterCtrlStatusReceived(&mRxData[DATA_START]);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// case TX_MASTER_ACK:
|
|
||||||
// {
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// case TX_MASTER_NET_INFO:
|
|
||||||
// {
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// case TX_MASTER_SEND_DEVICE_CMD_ACK:
|
|
||||||
// {
|
|
||||||
// switch(mRxData[FRAME_DATA_INDEX]) //Device ID responding to request
|
|
||||||
// {
|
|
||||||
// case ID_MASTER: //Master Controller
|
|
||||||
// {
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// case ID_CONSOLE: //LCD Console
|
|
||||||
// {
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// case ID_AV_MUX: //Audio Video Multiplexer
|
|
||||||
// {
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// case ID_IR_REMOTE: //Infra red transmitter
|
|
||||||
// {
|
|
||||||
|
|
||||||
// switch(mRxData[FRAME_DATA_INDEX+2]) //Command to which the device responded
|
int CNetworkProtocol::AnalyzeRxBuffer(QByteArray Buffer)
|
||||||
// {
|
{
|
||||||
|
int ret = PROTOCOL_RET_ERROR_EMPTY_BUFFER;
|
||||||
|
for(int i = 0; i < Buffer.size(); i++)
|
||||||
|
{
|
||||||
|
ret = RxStateMachine(Buffer.at(i));
|
||||||
|
if(ret != PROTOCOL_RET_OK_PACKET_INCOMPLETE)
|
||||||
|
{
|
||||||
|
if(ret == PROTOCOL_RET_OK_BAD_HEADER)
|
||||||
|
{
|
||||||
|
qDebug("Protocol Bad header");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
// case TX_LEARN_IR_CMD_FINISHED:
|
}
|
||||||
// {
|
}
|
||||||
// mMasterCtrlHandle->DeviceAnswerReceived(mRxData[FRAME_DATA_INDEX+3],mRxData[FRAME_DATA_INDEX+4],mRxData[FRAME_DATA_INDEX+5],mRxData[FRAME_DATA_INDEX+6]);
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
// break;
|
void CNetworkProtocol::SetManualPacketReset(bool Manual)
|
||||||
// }
|
{
|
||||||
// case TX_SEND_IR_DATA:
|
mIsResetManual = Manual;
|
||||||
// {
|
}
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// case TX_SEND_IR_CMD:
|
|
||||||
// {
|
|
||||||
// mMasterCtrlHandle->GetIRRemoteCodeReceived(mRxData[FRAME_DATA_INDEX+3],mRxData[FRAME_DATA_INDEX+4]);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//void CNetworkProtocol::SendDeviceCommand(char DeviceID, char DeviceAddress, char DeviceCmd, char *CommandData, char DataSize)
|
|
||||||
//{
|
|
||||||
// unsigned char TempBuf[MAX_MESSAGE_SIZE+5];
|
|
||||||
|
|
||||||
// TempBuf[0] = DeviceID;
|
|
||||||
// TempBuf[1] = DeviceAddress;
|
|
||||||
// TempBuf[2] = DeviceCmd;
|
|
||||||
// TempBuf[3] = DataSize;
|
|
||||||
|
|
||||||
// memcpy(&TempBuf[4],CommandData,DataSize);
|
|
||||||
|
|
||||||
// TxData(RX_MASTER_SEND_DEVICE_CMD,0,TempBuf,DataSize+4,MASTER_CTRL_ADDRESS,ID_MASTER);
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
//void CNetworkProtocol::RequestMasterCtrlStatus(void)
|
|
||||||
//{
|
|
||||||
// TxData(RX_MASTER_GET_STATUS,0,0,0,1,ID_MASTER);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//void CNetworkProtocol::SendMasterCtrlCmd(char MessageID, char *Data, char DataSize)
|
|
||||||
//{
|
|
||||||
// TxData(MessageID,0,(unsigned char*)Data,(int)DataSize,1,ID_MASTER);
|
|
||||||
//}
|
|
||||||
|
|||||||
@ -1,25 +1,50 @@
|
|||||||
#ifndef NETWORKPROTOCOL_H
|
#ifndef NETWORKPROTOCOL_H
|
||||||
#define NETWORKPROTOCOL_H
|
#define NETWORKPROTOCOL_H
|
||||||
|
|
||||||
|
#define USE_BYTEARRAY_IN_SEND
|
||||||
|
|
||||||
#include "GlobalDefine.h"
|
#include "GlobalDefine.h"
|
||||||
#include "ProtocolDefs.h"
|
#include "ProtocolDefs.h"
|
||||||
#include "AbstractNetworkInterface.h"
|
#include "AbstractNetworkInterface.h"
|
||||||
|
#include <QByteArray>
|
||||||
|
|
||||||
class CNetworkProtocol
|
class CNetworkProtocol
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CNetworkProtocol();
|
CNetworkProtocol();
|
||||||
~CNetworkProtocol();
|
~CNetworkProtocol();
|
||||||
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, const char *Data, int Size, unsigned char Address, unsigned char ID, unsigned char SenderDevice = ID_MASTER, unsigned char SenderAddress = 1);
|
||||||
|
int AnalyzeRxBuffer(QByteArray Buffer);
|
||||||
|
void PrepareForNewPacket();
|
||||||
|
void SetManualPacketReset(bool Manual);
|
||||||
|
|
||||||
|
virtual int NewFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data) = 0;
|
||||||
|
|
||||||
|
enum ProtocolRetValues
|
||||||
|
{
|
||||||
|
PROTOCOL_RET_OK_PACKET_COMPLETE,
|
||||||
|
PROTOCOL_RET_OK_PACKET_INCOMPLETE,
|
||||||
|
PROTOCOL_RET_OK_BAD_HEADER,
|
||||||
|
PROTOCOL_RET_ERROR_INVALID_TARGET_DEVICE,
|
||||||
|
PROTOCOL_RET_ERROR_INVALID_TARGET_ADDRESS,
|
||||||
|
PROTOCOL_RET_ERROR_BAD_CRC,
|
||||||
|
PROTOCOL_RET_ERROR_SM_LOGIC,
|
||||||
|
PROTOCOL_RET_ERROR_EMPTY_BUFFER
|
||||||
|
};
|
||||||
|
|
||||||
|
char ProtocolGetSenderID(){return SenderID;}
|
||||||
|
char ProtocolGetSenderAddress(){return SenderAddress;}
|
||||||
|
int ProtocolGetCmd(){return RxCmd;}
|
||||||
|
int ProtocolGetDataSize(){return RxSize;}
|
||||||
|
QByteArray ProtocolGetData(){return mDataBuffer;}
|
||||||
|
|
||||||
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);
|
||||||
// int TxData(unsigned char MessageID,unsigned char Flags,unsigned char *Data,int Size, unsigned char Address,unsigned char ID);
|
// int TxData(unsigned char MessageID,unsigned char Flags,unsigned char *Data,int Size, unsigned char Address,unsigned char ID);
|
||||||
|
|
||||||
void RxStateMachine(unsigned char Data);
|
int RxStateMachine(unsigned char Data);
|
||||||
|
|
||||||
//State Machine states
|
//State Machine states
|
||||||
enum States
|
enum States
|
||||||
@ -38,6 +63,8 @@ private:
|
|||||||
RxCRC
|
RxCRC
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool mIsResetManual;
|
||||||
|
|
||||||
|
|
||||||
char *RxBuff;
|
char *RxBuff;
|
||||||
char mRxData[MAX_MESSAGE_SIZE+10];
|
char mRxData[MAX_MESSAGE_SIZE+10];
|
||||||
@ -54,6 +81,8 @@ private:
|
|||||||
|
|
||||||
unsigned char State;
|
unsigned char State;
|
||||||
|
|
||||||
|
QByteArray mDataBuffer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NETWORKPROTOCOL_H
|
#endif // NETWORKPROTOCOL_H
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
Project: Automatic cat feeder
|
Project: Automatic cat feeder
|
||||||
Date: march 19 2006
|
Date: march 19 2006
|
||||||
Author: Jean-François Martel
|
Author: Jean-François Martel
|
||||||
Target: PIC 18F252
|
Target: PIC 18F252
|
||||||
Compiler: Microchip mcc18
|
Compiler: Microchip mcc18
|
||||||
Filename: Protocol.h
|
Filename: Protocol.h
|
||||||
@ -12,9 +12,12 @@ File description: Communication protocol implementation.
|
|||||||
jean-francois.martel@polymtl.ca
|
jean-francois.martel@polymtl.ca
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
//Protocol buffer specific definitions
|
#ifndef PROTOCOLDEFS_H
|
||||||
|
#define PROTOCOLDEFS_H
|
||||||
|
|
||||||
#define MAX_MESSAGE_SIZE 90
|
//Protocol buffer specific definitionsazsdf
|
||||||
|
|
||||||
|
#define MAX_MESSAGE_SIZE 0xFFFF
|
||||||
|
|
||||||
#define FRAME_HEADER 0x8A
|
#define FRAME_HEADER 0x8A
|
||||||
#define DATA_START 0x09
|
#define DATA_START 0x09
|
||||||
@ -24,98 +27,118 @@ jean-francois.martel@polymtl.ca
|
|||||||
|
|
||||||
enum eFrameIndex
|
enum eFrameIndex
|
||||||
{
|
{
|
||||||
FRAME_HEADER_INDEX,
|
FRAME_HEADER_INDEX,
|
||||||
FRAME_SENDER_ID_INDEX,
|
FRAME_SENDER_ID_INDEX,
|
||||||
FRAME_SENDER_ADDRESS_INDEX,
|
FRAME_SENDER_ADDRESS_INDEX,
|
||||||
FRAME_DEST_ID_INDEX,
|
FRAME_DEST_ID_INDEX,
|
||||||
FRAME_DEST_ADDRESS_INDEX,
|
FRAME_DEST_ADDRESS_INDEX,
|
||||||
FRAME_FLAGS_INDEX,
|
FRAME_FLAGS_INDEX,
|
||||||
FRAME_COMMAND_INDEX,
|
FRAME_COMMAND_INDEX,
|
||||||
FRAME_SIZE1_INDEX,
|
FRAME_SIZE1_INDEX,
|
||||||
FRAME_SIZE2_INDEX,
|
FRAME_SIZE2_INDEX,
|
||||||
FRAME_DATA_INDEX
|
FRAME_DATA_INDEX
|
||||||
};
|
};
|
||||||
|
|
||||||
enum DEVICES_IDS
|
enum DEVICES_IDS
|
||||||
{
|
{
|
||||||
ID_MASTER, //Master Controller
|
ID_MASTER, //Master Controller
|
||||||
ID_CONSOLE, //LCD Console
|
ID_CONSOLE, //LCD Console
|
||||||
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_DEADBOLT,
|
||||||
ID_RECEIVER_AMP,
|
ID_RECEIVER_AMP,
|
||||||
ID_NB_DEVICE_ID
|
ID_SMS_CLIENT,
|
||||||
|
ID_ETHERNET_VIRTUAL,
|
||||||
|
ID_NB_DEVICE_ID
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Commands definitions
|
// Commands definitions
|
||||||
|
|
||||||
enum MASTER_CMD
|
enum MASTER_CMD
|
||||||
{
|
{
|
||||||
RX_MASTER_GET_STATUS,
|
RX_MASTER_GET_STATUS,
|
||||||
TX_MASTER_STATUS,
|
TX_MASTER_STATUS,
|
||||||
TX_MASTER_ACK,
|
TX_MASTER_ACK,
|
||||||
RX_MASTER_SET_NET_INFO,
|
RX_MASTER_SET_NET_INFO,
|
||||||
RX_MASTER_GET_NET_INFO,
|
RX_MASTER_GET_NET_INFO,
|
||||||
TX_MASTER_NET_INFO,
|
TX_MASTER_NET_INFO,
|
||||||
RX_MASTER_SEND_DEVICE_CMD,
|
RX_MASTER_SEND_DEVICE_CMD,
|
||||||
TX_MASTER_SEND_DEVICE_CMD_ACK,
|
TX_MASTER_SEND_DEVICE_CMD_ACK,
|
||||||
RX_MASTER_SET_WEATHER_INFO,
|
RX_MASTER_SET_WEATHER_INFO,
|
||||||
TX_MASTER_SET_WEATHER_INFO_ACK,
|
TX_MASTER_SET_WEATHER_INFO_ACK,
|
||||||
RX_MASTER_SET_MAIL_MSG,
|
RX_MASTER_SET_MAIL_MSG,
|
||||||
TX_MASTER_SET_MAIL_MSG_ACK,
|
TX_MASTER_SET_MAIL_MSG_ACK,
|
||||||
RX_MASTER_NEW_OUTLOOK_EMAILS,
|
RX_MASTER_NEW_OUTLOOK_EMAILS,
|
||||||
TX_MASTER_NEW_OUTLOOK_EMAILS_ACK,
|
TX_MASTER_NEW_OUTLOOK_EMAILS_ACK,
|
||||||
RX_MASTER_TODAYS_EVENTS,
|
RX_MASTER_TODAYS_EVENTS,
|
||||||
TX_MASTER_TODAYS_EVENTS_ACK
|
TX_MASTER_TODAYS_EVENTS_ACK
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//CONSOLE
|
//CONSOLE
|
||||||
enum CONSOLE_CMD
|
enum CONSOLE_CMD
|
||||||
{
|
{
|
||||||
RX_CONSOLE_GET_STATUS,
|
RX_CONSOLE_GET_STATUS,
|
||||||
TX_CONSOLE_STATUS,
|
TX_CONSOLE_STATUS,
|
||||||
TX_CONSOLE_ACK,
|
TX_CONSOLE_ACK,
|
||||||
RX_START_CALIBRATION,
|
RX_START_CALIBRATION,
|
||||||
RX_GET_CONSOLE_EVENT_MSG,
|
RX_GET_CONSOLE_EVENT_MSG,
|
||||||
TX_CONSOLE_EVENT_MSG,
|
TX_CONSOLE_EVENT_MSG,
|
||||||
RX_CONSOLE_SHOW_CALLER_ID,
|
RX_CONSOLE_SHOW_CALLER_ID,
|
||||||
RX_SET_TIME,
|
RX_SET_TIME,
|
||||||
RX_SET_WEATHER,
|
RX_SET_WEATHER,
|
||||||
RX_SEND_NEW_MAIL_MSG,
|
RX_SEND_NEW_MAIL_MSG,
|
||||||
RX_SEND_NEW_MAIL_MSG_ACK,
|
RX_SEND_NEW_MAIL_MSG_ACK,
|
||||||
RX_NEW_OUTLOOK_EMAILS,
|
RX_NEW_OUTLOOK_EMAILS,
|
||||||
TX_NEW_OUTLOOK_EMAILS_ACK,
|
TX_NEW_OUTLOOK_EMAILS_ACK,
|
||||||
RX_TODAYS_EVENTS,
|
RX_TODAYS_EVENTS,
|
||||||
TX_TODAYS_EVENTS_ACK,
|
TX_TODAYS_EVENTS_ACK,
|
||||||
LAST_CONSOLE_CMD
|
LAST_CONSOLE_CMD
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum IR_REMOTE_CMDS
|
enum IR_REMOTE_CMDS
|
||||||
{
|
{
|
||||||
TX_IR_REMOTE_ACK = 1,
|
TX_IR_REMOTE_ACK = 1,
|
||||||
RX_GET_STATUS,
|
RX_GET_STATUS,
|
||||||
TX_REMOTE_STATUS,
|
TX_REMOTE_STATUS,
|
||||||
RX_TRANSMIT_CMD,
|
RX_TRANSMIT_CMD,
|
||||||
RX_LEARN_IR_CMD,
|
RX_LEARN_IR_CMD,
|
||||||
TX_LEARN_IR_CMD_FINISHED,
|
TX_LEARN_IR_CMD_FINISHED,
|
||||||
RX_GET_IR_DATA,
|
RX_GET_IR_DATA,
|
||||||
TX_SEND_IR_DATA,
|
TX_SEND_IR_DATA,
|
||||||
RX_SET_IR_CMD,
|
RX_SET_IR_CMD,
|
||||||
RX_SET_IR_DATA,
|
RX_SET_IR_DATA,
|
||||||
RX_GET_IR_CMD,
|
RX_GET_IR_CMD,
|
||||||
TX_SEND_IR_CMD,
|
TX_SEND_IR_CMD,
|
||||||
MAX_IR_REMOTE_CMD
|
MAX_IR_REMOTE_CMD
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum SMS_CLIENT_CMDS
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
enum DEADBOLT_CMDS
|
||||||
|
{
|
||||||
|
DEADBOLT_DEVICE_ACK,
|
||||||
|
DEADBOLT_DEVICE_STATUS_REQUEST,
|
||||||
|
DEADBOLT_DEVICE_STATUS_RESPONSE,
|
||||||
|
|
||||||
|
MAX_DEADBOLT_DEVICE_CMD
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ETHERNET_NETWORK_VIRTUAL_CMDS
|
||||||
|
{
|
||||||
|
ETH_NETWK_DEVICE_INFO_REQUEST = 0xD000,
|
||||||
|
ETH_NETWK_DEVICE_INFO_RESPONSE,
|
||||||
|
ETH_NETWK_SET_DEVICE_INFO_ACK,
|
||||||
|
|
||||||
|
MAX_ETHERNET_NETWORK_VIRTUAL_CMDS
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
18
Sources/SMSDevice.cpp
Normal file
18
Sources/SMSDevice.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include "SMSDevice.h"
|
||||||
|
#include "ProtocolDefs.h"
|
||||||
|
|
||||||
|
|
||||||
|
CSMSDevice::CSMSDevice(int Address, CAbstractNetworkCommIF *NetworkInterface):
|
||||||
|
CNetworkDevice(ID_SMS_CLIENT,Address,NetworkInterface)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CSMSDevice::~CSMSDevice()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int CSMSDevice::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data)
|
||||||
|
{
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
19
Sources/SMSDevice.h
Normal file
19
Sources/SMSDevice.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef CSMSDEVICE_H
|
||||||
|
#define CSMSDEVICE_H
|
||||||
|
|
||||||
|
#include "GlobalDefine.h"
|
||||||
|
#include "NetworkDevice.h"
|
||||||
|
|
||||||
|
|
||||||
|
class CSMSDevice: public CNetworkDevice
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CSMSDevice(int Address, CAbstractNetworkCommIF *NetworkInterface);
|
||||||
|
virtual ~CSMSDevice();
|
||||||
|
|
||||||
|
//CAbstractNetworkDevice implementation
|
||||||
|
virtual int NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CSMSDEVICE_H
|
||||||
@ -15,6 +15,12 @@ CVoipMsSMSClient::CVoipMsSMSClient()
|
|||||||
connect(mVOIPMsNotificationServer,SIGNAL(newConnection()),this,SLOT(VoipNotificationServerConnected()));
|
connect(mVOIPMsNotificationServer,SIGNAL(newConnection()),this,SLOT(VoipNotificationServerConnected()));
|
||||||
mVOIPMsNotificationServer->listen(QHostAddress::Any,80);
|
mVOIPMsNotificationServer->listen(QHostAddress::Any,80);
|
||||||
|
|
||||||
|
mCheckNewSMSTimer = new QTimer();
|
||||||
|
connect(mCheckNewSMSTimer,SIGNAL(timeout()),this,SLOT(CheckNewSMSTimerExpired()));
|
||||||
|
mCheckNewSMSTimer->setSingleShot(false);
|
||||||
|
|
||||||
|
mFirstDownloadDone = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CVoipMsSMSClient::~CVoipMsSMSClient()
|
CVoipMsSMSClient::~CVoipMsSMSClient()
|
||||||
@ -23,6 +29,8 @@ CVoipMsSMSClient::~CVoipMsSMSClient()
|
|||||||
mSMSMessagesList.clear();
|
mSMSMessagesList.clear();
|
||||||
mVOIPMsNotificationServer->close();
|
mVOIPMsNotificationServer->close();
|
||||||
delete mVOIPMsNotificationServer;
|
delete mVOIPMsNotificationServer;
|
||||||
|
mCheckNewSMSTimer->stop();
|
||||||
|
delete mCheckNewSMSTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CVoipMsSMSClient::SetVOIPMsSettings(CVoipMSSMSSettings *SettingsData)
|
unsigned int CVoipMsSMSClient::SetVOIPMsSettings(CVoipMSSMSSettings *SettingsData)
|
||||||
@ -71,7 +79,21 @@ int CVoipMsSMSClient::SendSMSDownloadRequest(QDate StartDate, QDate EndDate)
|
|||||||
|
|
||||||
int CVoipMsSMSClient::DownloadNewSMS()
|
int CVoipMsSMSClient::DownloadNewSMS()
|
||||||
{
|
{
|
||||||
SendSMSDownloadRequest(QDate::currentDate(),QDate::currentDate());
|
// SendSMSDownloadRequest(QDate::currentDate(),QDate::currentDate());
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CVoipMsSMSClient::CheckForNewSMS()
|
||||||
|
{
|
||||||
|
if(mSMSMessagesList.isEmpty() == true)
|
||||||
|
{
|
||||||
|
return RET_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDate Today = QDate::currentDate();
|
||||||
|
QDate StartDate = mSMSMessagesList.at(0).mDateTime.date();
|
||||||
|
SendSMSDownloadRequest(StartDate,Today);
|
||||||
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CVoipMsSMSClient::GetDidFromUserAccount(const QString username, const QString Password)
|
unsigned int CVoipMsSMSClient::GetDidFromUserAccount(const QString username, const QString Password)
|
||||||
@ -176,9 +198,22 @@ unsigned int CVoipMsSMSClient::SMSReceived(QJsonArray *SMSArray)
|
|||||||
finished = true;
|
finished = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(mFirstDownloadDone == true)
|
||||||
|
{
|
||||||
|
qDebug() << "Added " << NewMessages.size() << " new SMS messages";
|
||||||
|
qDebug("-----------------------------------------------------------------------");
|
||||||
|
qDebug(" ");
|
||||||
|
for(int i = 0; i < NewMessages.size(); i++)
|
||||||
|
{
|
||||||
|
qDebug() << NewMessages.at(i).mDateTime.toString("yyyy-MM-dd hh:mm:ss") << " : " << NewMessages.at(i).mContact << " : " << NewMessages.at(i).mMessageText.toUtf8().data();
|
||||||
|
}
|
||||||
|
qDebug("-----------------------------------------------------------------------");
|
||||||
|
qDebug(" ");
|
||||||
|
}
|
||||||
|
|
||||||
NewMessages.append(mSMSMessagesList);
|
NewMessages.append(mSMSMessagesList);
|
||||||
mSMSMessagesList = NewMessages;
|
mSMSMessagesList = NewMessages;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -203,6 +238,18 @@ unsigned int CVoipMsSMSClient::SMSReceived(QJsonArray *SMSArray)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
mSMSMessagesList.append(NewMessages);
|
mSMSMessagesList.append(NewMessages);
|
||||||
|
if(mFirstDownloadDone == true)
|
||||||
|
{
|
||||||
|
qDebug() << "Added " << NewMessages.size() << " new SMS messages";
|
||||||
|
qDebug("-----------------------------------------------------------------------");
|
||||||
|
qDebug(" ");
|
||||||
|
for(int i = 0; i < NewMessages.size(); i++)
|
||||||
|
{
|
||||||
|
qDebug() << NewMessages.at(i).mDateTime.toString("yyyy-MM-dd hh:mm:ss") << " : " << NewMessages.at(i).mContact << " : " << NewMessages.at(i).mMessageText.toUtf8().data();
|
||||||
|
}
|
||||||
|
qDebug("-----------------------------------------------------------------------");
|
||||||
|
qDebug(" ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -222,15 +269,23 @@ unsigned int CVoipMsSMSClient::SMSReceived(QJsonArray *SMSArray)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qDebug() << "Finished download of " << mSMSMessagesList.size() << " SMS messages";
|
if(mFirstDownloadDone == false)
|
||||||
qDebug("-----------------------------------------------------------------------");
|
|
||||||
qDebug(" ");
|
|
||||||
for(int i = 0; i < mSMSMessagesList.size(); i++)
|
|
||||||
{
|
{
|
||||||
qDebug() << mSMSMessagesList.at(i).mDateTime.toString("yyyy-MM-dd hh:mm:ss") << " : " << mSMSMessagesList.at(i).mContact << " : " << mSMSMessagesList.at(i).mMessageText.toUtf8().data();
|
qDebug() << "Finished download of " << mSMSMessagesList.size() << " SMS messages";
|
||||||
|
qDebug("-----------------------------------------------------------------------");
|
||||||
|
qDebug(" ");
|
||||||
|
for(int i = 0; i < mSMSMessagesList.size(); i++)
|
||||||
|
{
|
||||||
|
qDebug() << mSMSMessagesList.at(i).mDateTime.toString("yyyy-MM-dd hh:mm:ss") << " : " << mSMSMessagesList.at(i).mContact << " : " << mSMSMessagesList.at(i).mMessageText.toUtf8().data();
|
||||||
|
}
|
||||||
|
qDebug("-----------------------------------------------------------------------");
|
||||||
|
qDebug(" ");
|
||||||
|
|
||||||
|
|
||||||
|
mFirstDownloadDone = true;
|
||||||
|
mCheckNewSMSTimer->start(VOIP_MS_SMS_CHECK_TIMEOUT);
|
||||||
|
qDebug("Timer started");
|
||||||
}
|
}
|
||||||
qDebug("-----------------------------------------------------------------------");
|
|
||||||
qDebug(" ");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -323,6 +378,12 @@ void CVoipMsSMSClient::VoipNotificationServerDataAvail()
|
|||||||
NewSMSNotification(Did);
|
NewSMSNotification(Did);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CVoipMsSMSClient::CheckNewSMSTimerExpired()
|
||||||
|
{
|
||||||
|
CheckForNewSMS();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//https://www.voip.ms/api/v1/rest.php?api_username=jean-francois.martel@polymtl.ca&api_password=Pentium2&method=getBalance&advanced=True
|
//https://www.voip.ms/api/v1/rest.php?api_username=jean-francois.martel@polymtl.ca&api_password=Pentium2&method=getBalance&advanced=True
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -11,10 +11,13 @@
|
|||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include "ProgramSettings.h"
|
#include "ProgramSettings.h"
|
||||||
#include <QTcpServer>
|
#include <QTcpServer>
|
||||||
|
#include <QTimer>
|
||||||
|
#include "NetworkDevice.h"
|
||||||
|
|
||||||
#define VOIP_MS_API_URL "https://www.voip.ms/api/v1/rest.php?"
|
#define VOIP_MS_API_URL "https://www.voip.ms/api/v1/rest.php?"
|
||||||
#define VOIP_MS_SMS_DATESPAN 90
|
#define VOIP_MS_SMS_DATESPAN 90
|
||||||
#define VOIP_MS_SMS_MAX_COUNT 500
|
#define VOIP_MS_SMS_MAX_COUNT 800
|
||||||
|
#define VOIP_MS_SMS_CHECK_TIMEOUT 5000 //Check for new SMS every 5 seconds
|
||||||
|
|
||||||
enum VoipMSRetValues
|
enum VoipMSRetValues
|
||||||
{
|
{
|
||||||
@ -33,6 +36,7 @@ public:
|
|||||||
int DownloadSMSFromServer();
|
int DownloadSMSFromServer();
|
||||||
int SendSMSDownloadRequest(QDate StartDate, QDate EndDate);
|
int SendSMSDownloadRequest(QDate StartDate, QDate EndDate);
|
||||||
int DownloadNewSMS();
|
int DownloadNewSMS();
|
||||||
|
int CheckForNewSMS();
|
||||||
|
|
||||||
QList<CSMSMessage> mSMSMessagesList;
|
QList<CSMSMessage> mSMSMessagesList;
|
||||||
|
|
||||||
@ -40,6 +44,8 @@ public:
|
|||||||
unsigned int SetVOIPMsSettings(CVoipMSSMSSettings *SettingsData);
|
unsigned int SetVOIPMsSettings(CVoipMSSMSSettings *SettingsData);
|
||||||
unsigned int NewSMSNotification(QString DID);
|
unsigned int NewSMSNotification(QString DID);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager *mVOIPMSSocket;
|
QNetworkAccessManager *mVOIPMSSocket;
|
||||||
|
|
||||||
@ -52,6 +58,10 @@ private:
|
|||||||
|
|
||||||
QTcpServer *mVOIPMsNotificationServer;
|
QTcpServer *mVOIPMsNotificationServer;
|
||||||
QTcpSocket *mClientConnection;
|
QTcpSocket *mClientConnection;
|
||||||
|
QTimer *mCheckNewSMSTimer;
|
||||||
|
|
||||||
|
bool mFirstDownloadDone;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@ -61,6 +71,7 @@ public slots:
|
|||||||
void VoipServerReplyFinished(QNetworkReply*);
|
void VoipServerReplyFinished(QNetworkReply*);
|
||||||
void VoipNotificationServerConnected();
|
void VoipNotificationServerConnected();
|
||||||
void VoipNotificationServerDataAvail();
|
void VoipNotificationServerDataAvail();
|
||||||
|
void CheckNewSMSTimerExpired();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user