Dev.
This commit is contained in:
parent
17738c5b5d
commit
f4fc549a8a
@ -11,7 +11,6 @@ HEADERS += \
|
||||
Sources/DeadboltDevice.h \
|
||||
Sources/AVReceiverDevice.h \
|
||||
Sources/VoipSMS/VoipMsSMSClient.h \
|
||||
Sources/VoipSMS/CSMSMessage.h \
|
||||
Sources/Gui/SystemTrayManager.h \
|
||||
Sources/Gui/SettingsWindow.h \
|
||||
Sources/ProgramSettings.h \
|
||||
@ -21,7 +20,8 @@ HEADERS += \
|
||||
Sources/NetworkDevicesMgr.h \
|
||||
Sources/SMSDevice.h \
|
||||
Sources/NetworkDevice.h \
|
||||
Sources/AbstractNetworkInterface.h
|
||||
Sources/AbstractNetworkInterface.h \
|
||||
Sources/VoipSMS/SMSMessage.h
|
||||
|
||||
SOURCES += \
|
||||
Sources/main.cpp \
|
||||
@ -33,7 +33,6 @@ SOURCES += \
|
||||
Sources/DeadboltDevice.cpp \
|
||||
Sources/AVReceiverDevice.cpp \
|
||||
Sources/VoipSMS/VoipMsSMSClient.cpp \
|
||||
Sources/VoipSMS/CSMSMessage.cpp \
|
||||
Sources/Gui/SystemTrayManager.cpp \
|
||||
Sources/Gui/SettingsWindow.cpp \
|
||||
Sources/ProgramSettings.cpp \
|
||||
@ -41,7 +40,8 @@ SOURCES += \
|
||||
Sources/EthernetNetworkServer.cpp \
|
||||
Sources/NetworkDevicesMgr.cpp \
|
||||
Sources/SMSDevice.cpp \
|
||||
Sources/NetworkDevice.cpp
|
||||
Sources/NetworkDevice.cpp \
|
||||
Sources/VoipSMS/SMSMessage.cpp
|
||||
|
||||
|
||||
#win32:SOURCES += $$PWD/Source/qextserialport/win_qextserialport.cpp \
|
||||
|
||||
@ -22,6 +22,8 @@ int C232NetworkCommIF::NewFrameReceived(int DeviceID, int DeviceAddress, int Mes
|
||||
return RET_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
//int C232NetworkCommIF::SendNetworkMessage(unsigned char MessageID, unsigned char Flags, unsigned char *Data, int Size)
|
||||
@ -32,5 +34,11 @@ int C232NetworkCommIF::NewFrameReceived(int DeviceID, int DeviceAddress, int Mes
|
||||
|
||||
int C232NetworkCommIF::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;
|
||||
}
|
||||
|
||||
@ -12,6 +12,12 @@ C485NetworkCommIF::~C485NetworkCommIF()
|
||||
|
||||
int C485NetworkCommIF::NewFrameReceived(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;
|
||||
}
|
||||
|
||||
@ -24,5 +30,11 @@ int C485NetworkCommIF::RegisterNewDevice(CNetworkDevice *NewDevice)
|
||||
|
||||
int C485NetworkCommIF::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;
|
||||
}
|
||||
|
||||
@ -370,7 +370,7 @@ int CAVReceiverDevice::AnalyseRxData(QByteArray data)
|
||||
QString Data(data);
|
||||
if(data == "\r\n")
|
||||
{
|
||||
qDebug("AV Receiver: Heartbeat received");
|
||||
// qDebug("AV Receiver: Heartbeat received");
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
@ -535,7 +535,7 @@ int CAVReceiverDevice::AnalyseRxData(QByteArray data)
|
||||
else if(CurCmd.contains("FL"))
|
||||
{
|
||||
CurCmd.remove("FL");
|
||||
int DisplayFlags = CurCmd.left(2).toInt(0,16);
|
||||
// int DisplayFlags = CurCmd.left(2).toInt(0,16);
|
||||
CurCmd.remove(0,2);
|
||||
int StrLength = CurCmd.size()/2;
|
||||
QString FlString = "";
|
||||
|
||||
@ -11,13 +11,16 @@ CDeadboltDevice::CDeadboltDevice(int Address, CAbstractNetworkCommIF *NetworkInt
|
||||
|
||||
CDeadboltDevice::~CDeadboltDevice()
|
||||
{
|
||||
delete mNetworkCommInterface;
|
||||
}
|
||||
|
||||
int CDeadboltDevice::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data)
|
||||
{
|
||||
Q_UNUSED(DeviceID)
|
||||
Q_UNUSED(DeviceAddress)
|
||||
Q_UNUSED(DataSize)
|
||||
Q_UNUSED(Data)
|
||||
|
||||
return RET_OK;
|
||||
|
||||
switch(MessageID)
|
||||
{
|
||||
|
||||
@ -14,8 +14,6 @@ public:
|
||||
|
||||
virtual int NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);
|
||||
|
||||
|
||||
CAbstractNetworkCommIF *mNetworkCommInterface;
|
||||
};
|
||||
|
||||
#endif // DEADBOLTDEVICE_H
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
#include "EthernetNetworkCommIF.h"
|
||||
#include "NetworkDevice.h"
|
||||
|
||||
|
||||
|
||||
CEthernetNetworkCommIF::CEthernetNetworkCommIF(QTcpSocket *Socket)
|
||||
{
|
||||
mTCPSocket = Socket;
|
||||
@ -9,20 +11,47 @@ CEthernetNetworkCommIF::CEthernetNetworkCommIF(QTcpSocket *Socket)
|
||||
connect(mTCPSocket,SIGNAL(readyRead()),this,SLOT(SocketDataAvailable()));
|
||||
}
|
||||
|
||||
CEthernetNetworkCommIF::~CEthernetNetworkCommIF()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
int CEthernetNetworkCommIF::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)
|
||||
|
||||
QByteArray Packet = GetTxPacket(MessageID,0,Data.data(),DataSize,DeviceAddress,DeviceID);
|
||||
mTCPSocket->write(Packet);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CEthernetNetworkCommIF::NewFrameReceived(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)
|
||||
|
||||
mDevicePtr->NewDeviceFrameReceived(DeviceID,DeviceAddress,MessageID,DataSize,Data);
|
||||
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void CEthernetNetworkCommIF::SocketDataAvailable()
|
||||
{
|
||||
|
||||
AnalyzeRxBuffer(mTCPSocket->readAll());
|
||||
}
|
||||
|
||||
void CEthernetNetworkCommIF::SocketDisconnected()
|
||||
{
|
||||
mTCPSocket->close();
|
||||
delete mTCPSocket;
|
||||
// delete mTCPSocket;
|
||||
emit EthernetInterfaceSocketDisconnected(mDevicePtr);
|
||||
}
|
||||
|
||||
@ -21,10 +21,10 @@ public:
|
||||
QTcpSocket* mTCPSocket;
|
||||
|
||||
//CNetworkCommIF implementation
|
||||
virtual int SendNetworkMessage(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data) = 0;
|
||||
virtual int SendNetworkMessage(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);
|
||||
|
||||
//CNetworkProtocol implementation
|
||||
virtual int NewFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data) = 0;
|
||||
virtual int NewFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);
|
||||
|
||||
public slots:
|
||||
void SocketDataAvailable();
|
||||
|
||||
@ -1,75 +1,103 @@
|
||||
#include "EthernetNetworkServer.h"
|
||||
#include "MasterCtrl.h"
|
||||
#include "EthernetNetworkCommIF.h"
|
||||
|
||||
|
||||
CEthernetNetworkServer::CEthernetNetworkServer()
|
||||
{
|
||||
mProgramHandle = 0;
|
||||
mDevicesMgrHandle = 0;
|
||||
|
||||
SetManualPacketReset(true);
|
||||
}
|
||||
|
||||
CEthernetNetworkServer::~CEthernetNetworkServer()
|
||||
{
|
||||
CloseServer();
|
||||
}
|
||||
|
||||
int CEthernetNetworkServer::StartServer(int port)
|
||||
{
|
||||
mEthernetNetworkServer = new QTcpServer;
|
||||
connect(mEthernetNetworkServer,SIGNAL(newConnection()),this,SLOT(EthernetNetworkServerConnected()));
|
||||
mEthernetNetworkServer->listen(QHostAddress::Any,80);
|
||||
if(mEthernetNetworkServer->listen(QHostAddress::Any,port) == true)
|
||||
{
|
||||
qDebug("Ethernet Network Server listening on port %d", port);
|
||||
return RET_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return RET_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int CEthernetNetworkServer::NewFrameReceived(QByteArray Frame)
|
||||
int CEthernetNetworkServer::CloseServer()
|
||||
{
|
||||
Q_UNUSED(Frame)
|
||||
mEthernetNetworkServer->close();
|
||||
// mEthernetNetworkServer->deleteLater();
|
||||
qDebug("Ethernet Network server closed");
|
||||
|
||||
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++)
|
||||
// CEthernetDeviceConnection *NewConnection = new CEthernetDeviceConnection;
|
||||
// NewConnection->mConnectionSocket = EthernetDeviceSocket;
|
||||
// mEthernetDeviceConnections.append(NewConnection);
|
||||
if(EthernetDeviceSocket != 0)
|
||||
{
|
||||
if(Socket == mEthernetDeviceConnections.at(i)->mConnectionSocket)
|
||||
{
|
||||
return mEthernetDeviceConnections.at(i);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
connect(EthernetDeviceSocket,SIGNAL(readyRead()),this,SLOT(DeviceSocketDataAvail()));
|
||||
connect(EthernetDeviceSocket,SIGNAL(disconnected()),this,SLOT(DeviceSocketDisconnected()));
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
int CEthernetNetworkServer::FindConnection(CEthernetDeviceConnection* Connection)
|
||||
{
|
||||
for(int i = 0; i < mEthernetDeviceConnections.size(); i++)
|
||||
{
|
||||
if(Connection == mEthernetDeviceConnections.at(i))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
//CEthernetDeviceConnection * CEthernetNetworkServer::FindConnection(QTcpSocket *Socket)
|
||||
//{
|
||||
// for(int i = 0; i < mEthernetDeviceConnections.size(); i++)
|
||||
// {
|
||||
// if(Socket == mEthernetDeviceConnections.at(i)->mConnectionSocket)
|
||||
// {
|
||||
// return mEthernetDeviceConnections.at(i);
|
||||
// }
|
||||
// }
|
||||
|
||||
return -1;
|
||||
}
|
||||
// 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);
|
||||
|
||||
//CEthernetDeviceConnection *DeviceConnection = FindConnection(DeviceSocket);
|
||||
|
||||
|
||||
int ret = AnalyzeRxBuffer(Packet);
|
||||
|
||||
|
||||
bool CloseSocket = false;
|
||||
// if(DeviceConnection == 0)
|
||||
// {
|
||||
@ -85,39 +113,77 @@ void CEthernetNetworkServer::DeviceSocketDataAvail()
|
||||
{
|
||||
if(ProtocolGetCmd() == ETH_NETWK_DEVICE_INFO_RESPONSE)
|
||||
{
|
||||
|
||||
CEthernetNetworkCommIF *NetworkIF = new CEthernetNetworkCommIF(DeviceSocket);
|
||||
QByteArray Data = ProtocolGetData();
|
||||
char DeviceID,DeviceAddress;
|
||||
|
||||
DeviceID = Data.at(0);
|
||||
DeviceAddress = Data.at(1);
|
||||
|
||||
if(IsDeviceRegistered(DeviceID) == true)
|
||||
if(DeviceID == ID_SMS_CLIENT)
|
||||
{
|
||||
DeviceConnection->mConnectedDevice->mDeviceID = (int)DeviceID;
|
||||
DeviceConnection->mConnectedDevice->mDeviceAddress = (int)DeviceAddress;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug("Rx device info from unregistered device");
|
||||
CloseSocket = true;
|
||||
if(mDevicesMgrHandle != 0)
|
||||
{
|
||||
if(mDevicesMgrHandle->CreateNewSMSDevice(DeviceAddress,(CAbstractNetworkCommIF*)NetworkIF) == RET_OK)
|
||||
{
|
||||
//All OK.
|
||||
|
||||
//Redirect signals.
|
||||
DeviceSocket->disconnect();
|
||||
// disconnect(DeviceSocket,SIGNAL(readyRead()),this,SLOT(DeviceSocketDataAvail()));
|
||||
connect(DeviceSocket,SIGNAL(readyRead()),NetworkIF,SLOT(SocketDataAvailable()));
|
||||
connect(DeviceSocket,SIGNAL(disconnected()),NetworkIF,SLOT(SocketDisconnected()));
|
||||
connect(NetworkIF,SIGNAL(EthernetInterfaceSocketDisconnected(CNetworkDevice*)),mDevicesMgrHandle,SLOT(EthernetNetworkDeviceDisconnected(CNetworkDevice*)));
|
||||
|
||||
//Inform device that it is connected
|
||||
QByteArray Frame = GetTxPacket((unsigned char)ETH_NETWK_SET_DEVICE_INFO_ACK,0,0,0,DeviceAddress,(unsigned char)ID_ETHERNET_VIRTUAL);
|
||||
DeviceSocket->write(Frame);
|
||||
qDebug("Created new SMS device");
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug("Could not create SMS device in ethernet server");
|
||||
QByteArray Frame = GetTxPacket((unsigned char)ETH_NETWK_CONNECTION_REFUSED,0,0,0,DeviceAddress,(unsigned char)ID_ETHERNET_VIRTUAL);
|
||||
DeviceSocket->write(Frame);
|
||||
CloseSocket = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug("Invalid DevicesMgrHandle in ethernet server");
|
||||
CloseSocket = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
qDebug("Received protocol data in ethernet server");
|
||||
// if(DeviceConnection != 0)
|
||||
// {
|
||||
// DeviceConnection->mConnectedDevice->NewDeviceFrameReceived(ProtocolGetSenderID(),ProtocolGetSenderAddress(),ProtocolGetCmd(),ProtocolGetDataSize(),ProtocolGetData());
|
||||
// PrepareForNewPacket();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// qDebug("Rx from invalid device connection pointer!");
|
||||
// CloseSocket = true;
|
||||
// }
|
||||
}
|
||||
|
||||
PrepareForNewPacket();
|
||||
break;
|
||||
}
|
||||
case PROTOCOL_RET_OK_PACKET_INCOMPLETE:
|
||||
@ -130,36 +196,41 @@ void CEthernetNetworkServer::DeviceSocketDataAvail()
|
||||
}
|
||||
case PROTOCOL_RET_ERROR_INVALID_TARGET_DEVICE:
|
||||
{
|
||||
qDebug("Bad target device received on Ethernet network");
|
||||
qDebug("Bad target device received on Ethernet server");
|
||||
PrepareForNewPacket();
|
||||
break;
|
||||
}
|
||||
case PROTOCOL_RET_ERROR_INVALID_TARGET_ADDRESS:
|
||||
{
|
||||
qDebug("Bad target address received on Ethernet network");
|
||||
qDebug("Bad target address received on Ethernet server");
|
||||
PrepareForNewPacket();
|
||||
break;
|
||||
}
|
||||
case PROTOCOL_RET_ERROR_BAD_CRC:
|
||||
{
|
||||
qDebug("Bad target CRC on Ethernet network");
|
||||
qDebug("Bad target CRC on Ethernet server");
|
||||
PrepareForNewPacket();
|
||||
break;
|
||||
}
|
||||
case PROTOCOL_RET_ERROR_SM_LOGIC:
|
||||
{
|
||||
qDebug("LOGIC ERROR!!! on Ethernet network protocol");
|
||||
qDebug("LOGIC ERROR!!! on Ethernet server protocol");
|
||||
PrepareForNewPacket();
|
||||
break;
|
||||
}
|
||||
case PROTOCOL_RET_ERROR_EMPTY_BUFFER:
|
||||
{
|
||||
qDebug("Trying to analyze an empty buffer on Ethernet server");
|
||||
PrepareForNewPacket();
|
||||
}
|
||||
}
|
||||
|
||||
if(CloseSocket == true)
|
||||
{
|
||||
if(CloseConnection(DeviceConnection) != RET_OK)
|
||||
// if(CloseConnection(DeviceConnection) != RET_OK)
|
||||
{
|
||||
DeviceSocket->close();
|
||||
delete DeviceSocket;
|
||||
//delete DeviceSocket;
|
||||
}
|
||||
PrepareForNewPacket();
|
||||
}
|
||||
@ -169,47 +240,131 @@ void CEthernetNetworkServer::DeviceSocketDataAvail()
|
||||
|
||||
void CEthernetNetworkServer::DeviceSocketDisconnected()
|
||||
{
|
||||
|
||||
qDebug("Socket disconnected...");
|
||||
}
|
||||
|
||||
int CEthernetNetworkServer::CloseConnection(CEthernetDeviceConnection *Connection)
|
||||
//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;
|
||||
//}
|
||||
int CEthernetNetworkServer::NewFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data)
|
||||
{
|
||||
if(Connection != 0)
|
||||
{
|
||||
int index = FindConnection(Connection);
|
||||
if(index != -1)
|
||||
{
|
||||
Connection->mConnectionSocket->close();
|
||||
mEthernetDeviceConnections.removeAt(index);
|
||||
delete Connection;
|
||||
return RET_OK;
|
||||
}
|
||||
}
|
||||
Q_UNUSED(DeviceAddress)
|
||||
Q_UNUSED(DataSize)
|
||||
Q_UNUSED(Data)
|
||||
Q_UNUSED(MessageID)
|
||||
Q_UNUSED(DeviceID)
|
||||
|
||||
return RET_ERROR;
|
||||
}
|
||||
// if(DeviceID == ID_ETHERNET_VIRTUAL)
|
||||
// {
|
||||
// if(MessageID == ETH_NETWK_DEVICE_INFO_RESPONSE)
|
||||
// {
|
||||
|
||||
int CEthernetNetworkServer::RegisterNewDevice(CNetworkDevice *Device)
|
||||
{
|
||||
if(IsDeviceRegistered(Device->GetDeviceID()))
|
||||
{
|
||||
qDebug("Device already registered");
|
||||
return RET_ERROR;
|
||||
}
|
||||
// CEthernetNetworkCommIF *NetworkIF = new CEthernetNetworkCommIF(DeviceSocket);
|
||||
// QByteArray Data = ProtocolGetData();
|
||||
// char DeviceID,DeviceAddress;
|
||||
|
||||
// RemoteDeviceID = Data.at(0);
|
||||
// RemoteDeviceAddress = Data.at(1);
|
||||
|
||||
// if(RemoteDeviceID == ID_SMS_CLIENT)
|
||||
// {
|
||||
// if(mDevicesMgrHandle != 0)
|
||||
// {
|
||||
// if(mDevicesMgrHandle->CreateNewSMSDevice(RemoteDeviceAddress,(CAbstractNetworkCommIF*)NetworkIF) == RET_OK)
|
||||
// {
|
||||
// //All OK.
|
||||
|
||||
// //Redirect signals.
|
||||
// DeviceSocket->disconnect();
|
||||
// // disconnect(DeviceSocket,SIGNAL(readyRead()),this,SLOT(DeviceSocketDataAvail()));
|
||||
// connect(DeviceSocket,SIGNAL(readyRead()),NetworkIF,SLOT(SocketDataAvailable()));
|
||||
// connect(DeviceSocket,SIGNAL(disconnected()),NetworkIF,SLOT(SocketDisconnected()));
|
||||
// connect(NetworkIF,SIGNAL(EthernetInterfaceSocketDisconnected(CNetworkDevice*)),mDevicesMgrHandle,SLOT(EthernetNetworkDeviceDisconnected(CNetworkDevice*)));
|
||||
|
||||
// //Inform device that it is connected
|
||||
// QByteArray Frame = GetTxPacket((unsigned char)ETH_NETWK_SET_DEVICE_INFO_ACK,0,0,0,RemoteDeviceAddress,(unsigned char)ID_ETHERNET_VIRTUAL);
|
||||
// DeviceSocket->write(Frame);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// qDebug("Could not create SMS device in ethernet server");
|
||||
// QByteArray Frame = GetTxPacket((unsigned char)ETH_NETWK_CONNECTION_REFUSED,0,0,0,RemoteDeviceAddress,(unsigned char)ID_ETHERNET_VIRTUAL);
|
||||
// DeviceSocket->write(Frame);
|
||||
// CloseSocket = true;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// qDebug("Invalid DevicesMgrHandle in ethernet server");
|
||||
// CloseSocket = true;
|
||||
// }
|
||||
// }
|
||||
|
||||
//// 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
|
||||
// {
|
||||
// qDebug("Received protocol data in ethernet server");
|
||||
//// if(DeviceConnection != 0)
|
||||
//// {
|
||||
//// DeviceConnection->mConnectedDevice->NewDeviceFrameReceived(ProtocolGetSenderID(),ProtocolGetSenderAddress(),ProtocolGetCmd(),ProtocolGetDataSize(),ProtocolGetData());
|
||||
//// PrepareForNewPacket();
|
||||
//// }
|
||||
//// else
|
||||
//// {
|
||||
//// qDebug("Rx from invalid device connection pointer!");
|
||||
//// CloseSocket = true;
|
||||
//// }
|
||||
// }
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -9,6 +9,9 @@
|
||||
#include <QList>
|
||||
#include <NetworkDevice.h>
|
||||
|
||||
|
||||
class CMasterCtrl;
|
||||
class CNetworkDevicesMgr;
|
||||
class CEthernetDeviceConnection
|
||||
{
|
||||
public:
|
||||
@ -23,23 +26,31 @@ class CEthernetNetworkServer : public QObject, CNetworkProtocol
|
||||
Q_OBJECT
|
||||
public:
|
||||
CEthernetNetworkServer();
|
||||
~CEthernetNetworkServer();
|
||||
|
||||
QTcpServer *mEthernetNetworkServer;
|
||||
CMasterCtrl *mProgramHandle;
|
||||
CNetworkDevicesMgr *mDevicesMgrHandle;
|
||||
|
||||
//NetworkProtocol implementation
|
||||
virtual int NewFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);
|
||||
|
||||
|
||||
|
||||
QList<CNetworkDevice*> mNetworkDevices;
|
||||
QList<CEthernetDeviceConnection*> mEthernetDeviceConnections;
|
||||
// QList<CNetworkDevice*> mNetworkDevices;
|
||||
// QList<CEthernetDeviceConnection*> mEthernetDeviceConnections;
|
||||
|
||||
|
||||
|
||||
virtual int NewFrameReceived(QByteArray Frame);
|
||||
bool IsDeviceRegistered(int DeviceID);
|
||||
int RegisterNewDevice(CNetworkDevice* Device);
|
||||
|
||||
// bool IsDeviceRegistered(int DeviceID);
|
||||
// int RegisterNewDevice(CNetworkDevice* Device);
|
||||
int StartServer(int port);
|
||||
int CloseServer();
|
||||
|
||||
private:
|
||||
int FindConnection(CEthernetDeviceConnection* Connection);
|
||||
CEthernetDeviceConnection *FindConnection(QTcpSocket* socket);
|
||||
// int FindConnection(CEthernetDeviceConnection* Connection);
|
||||
// CEthernetDeviceConnection *FindConnection(QTcpSocket* socket);
|
||||
int CloseConnection(CEthernetDeviceConnection *Connection);
|
||||
|
||||
public slots:
|
||||
|
||||
@ -6,4 +6,6 @@
|
||||
#define RET_OK 1
|
||||
#define RET_ERROR 0
|
||||
|
||||
#define ETHERNET_NETWORK_STATUS_TIMEOUT 5000
|
||||
|
||||
#endif // GLOBALDEFINE_H
|
||||
|
||||
@ -14,6 +14,8 @@ CAppIconWidget::CAppIconWidget()
|
||||
|
||||
void CAppIconWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
QRectF Rect(100,100,100,100);
|
||||
QPainter Painter(this);
|
||||
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
#include "MasterCtrl.h"
|
||||
#include <QApplication>
|
||||
|
||||
|
||||
// #include <QByteArray>
|
||||
//#include <QBuffer>
|
||||
|
||||
CMasterCtrl::CMasterCtrl()
|
||||
{
|
||||
qDebug("Creation...");
|
||||
@ -11,6 +15,10 @@ CMasterCtrl::CMasterCtrl()
|
||||
mSystemTrayManager->mProgramHandle = this;
|
||||
mSettingsWindow = new CSettingsWindow();
|
||||
mSettingsWindow->mProgramHandle = this;
|
||||
|
||||
mEthernetNetworkServer = new CEthernetNetworkServer;
|
||||
mNetworkDevicesManager = new CNetworkDevicesMgr;
|
||||
|
||||
// mMasterCtrlSettings = new CSettings;
|
||||
}
|
||||
|
||||
@ -23,6 +31,8 @@ CMasterCtrl::~CMasterCtrl()
|
||||
delete mVoipMsSMSClient;
|
||||
delete mSystemTrayManager;
|
||||
delete mSettingsWindow;
|
||||
delete mNetworkDevicesManager;
|
||||
delete mEthernetNetworkServer;
|
||||
// delete mMasterCtrlSettings;
|
||||
}
|
||||
|
||||
@ -31,6 +41,20 @@ void CMasterCtrl::Start()
|
||||
qDebug("Started!");
|
||||
|
||||
|
||||
// QByteArray FrameData;
|
||||
// QBuffer FrameBuffer(&FrameData);
|
||||
// QDataStream *FrameDataStrm = new QDataStream(&FrameData,QIODevice::ReadWrite);
|
||||
|
||||
// QString DID = "Salut";
|
||||
// *FrameDataStrm << DID;
|
||||
|
||||
// FrameBuffer.seek(0);
|
||||
|
||||
|
||||
mNetworkDevicesManager->mVoipMSInterfaceHandle = mVoipMsSMSClient;
|
||||
mNetworkDevicesManager->mProgramHandle = this;
|
||||
mEthernetNetworkServer->mDevicesMgrHandle = mNetworkDevicesManager;
|
||||
mEthernetNetworkServer->mProgramHandle = this;
|
||||
connect(mVoipMsSMSClient,SIGNAL(DIDSFetched(QStringList)),mSettingsWindow,SLOT(DIDsListFetched(QStringList)));
|
||||
|
||||
mAVReceiverDevice->ConnectToReceiver();
|
||||
@ -40,6 +64,9 @@ void CMasterCtrl::Start()
|
||||
mVoipMsSMSClient->SetVOIPMsSettings(&mMasterCtrlSettings.mVoipMSSettings);
|
||||
mVoipMsSMSClient->DownloadSMSFromServer();
|
||||
|
||||
mNetworkDevicesManager->InitNetworkDevices();
|
||||
mEthernetNetworkServer->StartServer(2182);
|
||||
|
||||
// mAppWidget.show();
|
||||
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include "SettingsWindow.h"
|
||||
#include "ProgramSettings.h"
|
||||
#include "NetworkDevicesMgr.h"
|
||||
#include "EthernetNetworkServer.h"
|
||||
//#include "AppIconWidget.h"
|
||||
|
||||
class CMasterCtrl : public QObject
|
||||
@ -25,7 +26,8 @@ public:
|
||||
CSystemTrayManager *mSystemTrayManager;
|
||||
CSettingsWindow *mSettingsWindow;
|
||||
CProgramSettings mSettingsManager;
|
||||
CNetworkDevicesMgr mNetworkDevicesManager;
|
||||
CNetworkDevicesMgr *mNetworkDevicesManager;
|
||||
CEthernetNetworkServer *mEthernetNetworkServer;
|
||||
// CAppIconWidget mAppWidget;
|
||||
|
||||
|
||||
@ -39,6 +41,11 @@ public:
|
||||
unsigned int SettingsWindowClosed();
|
||||
|
||||
|
||||
//Modules requests...
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
CSettings mMasterCtrlSettings;
|
||||
|
||||
@ -6,6 +6,7 @@ CNetworkDevice::CNetworkDevice(int DeviceID, int DeviceAddress, CAbstractNetwork
|
||||
mDeviceAddress = DeviceAddress;
|
||||
mDeviceID = DeviceID;
|
||||
SetNetworkInterface(Interface);
|
||||
mIsOnline = false;
|
||||
}
|
||||
|
||||
CNetworkDevice::~CNetworkDevice()
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
#include <QByteArray>
|
||||
#include "AbstractNetworkInterface.h"
|
||||
|
||||
|
||||
|
||||
class CNetworkDevice
|
||||
{
|
||||
public:
|
||||
@ -15,6 +17,7 @@ public:
|
||||
|
||||
int mDeviceID;
|
||||
int mDeviceAddress;
|
||||
bool mIsOnline;
|
||||
CAbstractNetworkCommIF *mNetworkInterfacePtr;
|
||||
|
||||
};
|
||||
|
||||
@ -2,12 +2,14 @@
|
||||
#include "232NetworkCommIF.h"
|
||||
#include "485NetworkCommIF.h"
|
||||
#include "EthernetNetworkCommIF.h"
|
||||
#include "MasterCtrl.h"
|
||||
|
||||
|
||||
|
||||
CNetworkDevicesMgr::CNetworkDevicesMgr()
|
||||
{
|
||||
|
||||
mVoipMSInterfaceHandle = 0;
|
||||
mProgramHandle = 0;
|
||||
}
|
||||
|
||||
CNetworkDevicesMgr::~CNetworkDevicesMgr()
|
||||
@ -31,9 +33,15 @@ int CNetworkDevicesMgr::InitNetworkDevices()
|
||||
|
||||
int CNetworkDevicesMgr::CreateNewSMSDevice(int Address, CAbstractNetworkCommIF *NetworkIF)
|
||||
{
|
||||
CSMSDevice *SMSDevice = new CSMSDevice(Address,NetworkIF);
|
||||
if(mVoipMSInterfaceHandle == 0)
|
||||
{
|
||||
return RET_ERROR;
|
||||
}
|
||||
|
||||
mNetworkDevicesList.append(SMSDevice);
|
||||
|
||||
CSMSDevice *SMSDevice = new CSMSDevice(Address,NetworkIF,mVoipMSInterfaceHandle);
|
||||
|
||||
mNetworkDevicesList.append((CNetworkDevice*)SMSDevice);
|
||||
|
||||
|
||||
return RET_OK;
|
||||
@ -41,6 +49,7 @@ int CNetworkDevicesMgr::CreateNewSMSDevice(int Address, CAbstractNetworkCommIF *
|
||||
|
||||
void CNetworkDevicesMgr::EthernetNetworkDeviceDisconnected(CNetworkDevice *Device)
|
||||
{
|
||||
qDebug("Device disconnected. ID: %d, Address: %d",Device->GetDeviceID(),Device->GetDeviceAddress());
|
||||
int index = FindDeviceByPtr(Device);
|
||||
if(index != -1)
|
||||
{
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
#include "QList"
|
||||
#include <QObject>
|
||||
|
||||
class CVoipMsSMSClient;
|
||||
class CMasterCtrl;
|
||||
class CNetworkDevicesMgr: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -23,6 +25,9 @@ public:
|
||||
int FindDeviceByPtr(CNetworkDevice *Device);
|
||||
CNetworkDevice *GetDevice(int DeviceID, int Address);
|
||||
|
||||
CVoipMsSMSClient *mVoipMSInterfaceHandle;
|
||||
CMasterCtrl *mProgramHandle;
|
||||
|
||||
private:
|
||||
|
||||
QList<CNetworkDevice*> mNetworkDevicesList;
|
||||
|
||||
@ -38,7 +38,7 @@ QByteArray CNetworkProtocol::GetTxPacket(unsigned char MessageID, unsigned char
|
||||
|
||||
QByteArray Frame;
|
||||
Frame.clear();
|
||||
int FrameSize = Size + 9; //Add header data...
|
||||
int FrameSize = Size + 11; //Add header data...
|
||||
|
||||
Frame.append(FRAME_HEADER); //header
|
||||
Frame.append(SenderAddress); //Device address (default = MasterCtrl)
|
||||
@ -47,8 +47,10 @@ QByteArray CNetworkProtocol::GetTxPacket(unsigned char MessageID, unsigned char
|
||||
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((Size & 0xFF000000) >> 24);
|
||||
Frame.append((Size & 0x00FF0000) >> 16);
|
||||
Frame.append((Size & 0x0000FF00) >> 8);
|
||||
Frame.append(Size & 0x000000FF);
|
||||
Frame.append(Data,Size);
|
||||
char CRC = CalcCRC(Frame.data(),FrameSize);
|
||||
Frame.append(CRC);
|
||||
@ -193,7 +195,7 @@ int CNetworkProtocol::RxStateMachine(unsigned char Data)
|
||||
case RxMyID:
|
||||
{
|
||||
|
||||
if(Data != ID_PC && Data != 0xFF) //Message is not for a console and it's not a broadcast
|
||||
if(Data != ID_MASTER && Data != 0xFF) //Message is not for Master and it's not a broadcast
|
||||
{
|
||||
ResetRxStateMachine();
|
||||
ret = PROTOCOL_RET_ERROR_INVALID_TARGET_DEVICE;
|
||||
@ -247,8 +249,29 @@ int CNetworkProtocol::RxStateMachine(unsigned char Data)
|
||||
CRC ^= Data;
|
||||
break;
|
||||
}
|
||||
|
||||
case RxSize2: //Data size LSB
|
||||
case RxSize2: //Data size MSB
|
||||
{
|
||||
RxSize |= (unsigned int)Data;
|
||||
RxSize <<= 8;
|
||||
mRxData[BufPtr++] = Data;
|
||||
|
||||
|
||||
RxState = RxSize3;
|
||||
CRC ^= Data;
|
||||
break;
|
||||
}
|
||||
case RxSize3: //Data size MSB
|
||||
{
|
||||
RxSize |= (unsigned int)Data;
|
||||
RxSize <<= 8;
|
||||
mRxData[BufPtr++] = Data;
|
||||
|
||||
|
||||
RxState = RxSize4;
|
||||
CRC ^= Data;
|
||||
break;
|
||||
}
|
||||
case RxSize4: //Data size LSB
|
||||
{
|
||||
RxSize |= (unsigned int)Data;
|
||||
mRxData[BufPtr++] = Data;
|
||||
@ -261,9 +284,11 @@ int CNetworkProtocol::RxStateMachine(unsigned char Data)
|
||||
CRC ^= Data;
|
||||
break;
|
||||
}
|
||||
|
||||
case RxData:
|
||||
{
|
||||
mRxData[BufPtr++] = Data;
|
||||
//mRxData[BufPtr++] = Data;
|
||||
mDataBuffer.append(Data);
|
||||
CRC ^= Data;
|
||||
DataCnt++;
|
||||
|
||||
@ -282,10 +307,10 @@ int CNetworkProtocol::RxStateMachine(unsigned char Data)
|
||||
break;
|
||||
}
|
||||
|
||||
mDataBuffer = QByteArray(&mRxData[DATA_START],RxSize);
|
||||
// mDataBuffer = QByteArray(&mRxData[DATA_START],RxSize);
|
||||
NewFrameReceived(SenderID,SenderAddress,RxCmd,RxSize,mDataBuffer);
|
||||
ret = PROTOCOL_RET_OK_PACKET_COMPLETE;
|
||||
if(mIsResetManual)
|
||||
if(mIsResetManual == false)
|
||||
{
|
||||
ResetRxStateMachine();
|
||||
}
|
||||
|
||||
@ -59,6 +59,8 @@ private:
|
||||
RxCMD,
|
||||
RxSize1,
|
||||
RxSize2,
|
||||
RxSize3,
|
||||
RxSize4,
|
||||
RxData,
|
||||
RxCRC
|
||||
};
|
||||
@ -67,7 +69,7 @@ private:
|
||||
|
||||
|
||||
char *RxBuff;
|
||||
char mRxData[MAX_MESSAGE_SIZE+10];
|
||||
char mRxData[MAX_MESSAGE_SIZE];
|
||||
|
||||
int RxState;
|
||||
int RxSize;
|
||||
|
||||
@ -20,7 +20,7 @@ jean-francois.martel@polymtl.ca
|
||||
#define MAX_MESSAGE_SIZE 0xFFFF
|
||||
|
||||
#define FRAME_HEADER 0x8A
|
||||
#define DATA_START 0x09
|
||||
#define DATA_START 11
|
||||
#define ACK 0xA3;
|
||||
#define NAK 0x90;
|
||||
#define BROADCAST_VALUE 0xFF
|
||||
@ -36,6 +36,8 @@ enum eFrameIndex
|
||||
FRAME_COMMAND_INDEX,
|
||||
FRAME_SIZE1_INDEX,
|
||||
FRAME_SIZE2_INDEX,
|
||||
FRAME_SIZE3_INDEX,
|
||||
FRAME_SIZE4_INDEX,
|
||||
FRAME_DATA_INDEX
|
||||
};
|
||||
|
||||
@ -119,12 +121,22 @@ enum IR_REMOTE_CMDS
|
||||
|
||||
enum SMS_CLIENT_CMDS
|
||||
{
|
||||
SMS_CLIENT_DEVICE_ACK = 1,
|
||||
SMS_CLIENT_DEVICE_STATUS_REQUEST,
|
||||
SMS_CLIENT_DEVICE_STATUS_RESPONSE,
|
||||
SMS_CLIENT_DEVICE_DID_INFO_REQUEST,
|
||||
SMS_CLIENT_DEVICE_DID_INFO_RESPONSE,
|
||||
SMS_CLIENT_DEVICE_GET_ALL_MSG_REQUEST,
|
||||
SMS_CLIENT_DEVICE_GET_ALL_MSG_RESPONSE,
|
||||
SMS_CLIENT_DEVICE_NEW_MSG_NOTIFICATION,
|
||||
|
||||
SMS_CLIENT_DEVICE_MAX_MSG
|
||||
|
||||
};
|
||||
|
||||
enum DEADBOLT_CMDS
|
||||
{
|
||||
DEADBOLT_DEVICE_ACK,
|
||||
DEADBOLT_DEVICE_ACK = 1,
|
||||
DEADBOLT_DEVICE_STATUS_REQUEST,
|
||||
DEADBOLT_DEVICE_STATUS_RESPONSE,
|
||||
|
||||
@ -133,9 +145,10 @@ enum DEADBOLT_CMDS
|
||||
|
||||
enum ETHERNET_NETWORK_VIRTUAL_CMDS
|
||||
{
|
||||
ETH_NETWK_DEVICE_INFO_REQUEST = 0xD000,
|
||||
ETH_NETWK_DEVICE_INFO_REQUEST = 0xD0,
|
||||
ETH_NETWK_DEVICE_INFO_RESPONSE,
|
||||
ETH_NETWK_SET_DEVICE_INFO_ACK,
|
||||
ETH_NETWK_CONNECTION_REFUSED,
|
||||
|
||||
MAX_ETHERNET_NETWORK_VIRTUAL_CMDS
|
||||
|
||||
|
||||
@ -1,18 +1,116 @@
|
||||
#include "SMSDevice.h"
|
||||
#include "ProtocolDefs.h"
|
||||
#include <QBuffer>
|
||||
|
||||
|
||||
CSMSDevice::CSMSDevice(int Address, CAbstractNetworkCommIF *NetworkInterface):
|
||||
CSMSDevice::CSMSDevice(int Address, CAbstractNetworkCommIF *NetworkInterface, CVoipMsSMSClient *VoipMsIFPtr):
|
||||
CNetworkDevice(ID_SMS_CLIENT,Address,NetworkInterface)
|
||||
{
|
||||
mStatusRequestsCount = 0;
|
||||
mVoipMsInterfaceHandle = VoipMsIFPtr;
|
||||
mStatusRequestTimer = new QTimer;
|
||||
mStatusRequestTimer->setInterval(ETHERNET_NETWORK_STATUS_TIMEOUT);
|
||||
mStatusRequestTimer->setSingleShot(true);
|
||||
connect(mStatusRequestTimer,SIGNAL(timeout()),this,SLOT(StatusReqTimerExpired()));
|
||||
// mStatusRequestTimer->start();
|
||||
}
|
||||
|
||||
CSMSDevice::~CSMSDevice()
|
||||
{
|
||||
|
||||
delete mStatusRequestTimer;
|
||||
}
|
||||
|
||||
int CSMSDevice::NewDeviceFrameReceived(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)
|
||||
|
||||
|
||||
mStatusRequestTimer->stop();
|
||||
|
||||
if(DeviceAddress != GetDeviceAddress())
|
||||
{
|
||||
return RET_ERROR;
|
||||
}
|
||||
|
||||
switch(MessageID)
|
||||
{
|
||||
case SMS_CLIENT_DEVICE_ACK:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case SMS_CLIENT_DEVICE_STATUS_RESPONSE:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case SMS_CLIENT_DEVICE_DID_INFO_REQUEST:
|
||||
{
|
||||
QByteArray FrameData;
|
||||
QBuffer FrameBuffer(&FrameData);
|
||||
FrameBuffer.open(QIODevice::ReadWrite);
|
||||
QDataStream *FrameDataStrm = new QDataStream(&FrameBuffer);
|
||||
// QDataStream *FrameDataStrm = new QDataStream(&FrameData,QIODevice::ReadWrite);
|
||||
|
||||
QString DID = mVoipMsInterfaceHandle->GetDefaultDID();
|
||||
*FrameDataStrm << DID;
|
||||
|
||||
FrameBuffer.seek(0);
|
||||
mNetworkInterfacePtr->SendNetworkMessage(mDeviceID,mDeviceAddress,SMS_CLIENT_DEVICE_DID_INFO_RESPONSE,FrameData.size(),FrameData);
|
||||
delete FrameDataStrm;
|
||||
|
||||
break;
|
||||
}
|
||||
case SMS_CLIENT_DEVICE_GET_ALL_MSG_REQUEST:
|
||||
{
|
||||
QByteArray FrameData;
|
||||
QBuffer FrameBuffer(&FrameData);
|
||||
FrameBuffer.open(QIODevice::ReadWrite);
|
||||
QDataStream *FrameDataStrm = new QDataStream(&FrameBuffer);
|
||||
|
||||
QList<CSMSMessage> *SMSList = mVoipMsInterfaceHandle->GetSMSList();
|
||||
*FrameDataStrm << SMSList->size();
|
||||
for(int i = 0; i < SMSList->size(); i++)
|
||||
{
|
||||
*FrameDataStrm << SMSList->at(i);
|
||||
}
|
||||
|
||||
FrameBuffer.seek(0);
|
||||
mNetworkInterfacePtr->SendNetworkMessage(mDeviceID,mDeviceAddress,SMS_CLIENT_DEVICE_GET_ALL_MSG_RESPONSE,FrameData.size(),FrameData);
|
||||
break;
|
||||
}
|
||||
case SMS_CLIENT_DEVICE_STATUS_REQUEST:
|
||||
case SMS_CLIENT_DEVICE_DID_INFO_RESPONSE:
|
||||
case SMS_CLIENT_DEVICE_NEW_MSG_NOTIFICATION:
|
||||
case SMS_CLIENT_DEVICE_GET_ALL_MSG_RESPONSE:
|
||||
default:
|
||||
{
|
||||
qDebug("SMSDevice Rx invalid MSG %d",MessageID);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
mIsOnline = true;
|
||||
mStatusRequestTimer->start();
|
||||
mStatusRequestsCount = 0;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void CSMSDevice::RequestStatus()
|
||||
{
|
||||
mNetworkInterfacePtr->SendNetworkMessage(mDeviceID,mDeviceAddress,SMS_CLIENT_DEVICE_STATUS_REQUEST,0,QByteArray());
|
||||
}
|
||||
|
||||
void CSMSDevice::StatusReqTimerExpired()
|
||||
{
|
||||
if(++mStatusRequestsCount > 3)
|
||||
{
|
||||
mIsOnline = false;
|
||||
qDebug("SMS Device offline,Address: %d",mDeviceAddress);
|
||||
}
|
||||
// RequestStatus();
|
||||
mStatusRequestTimer->start();
|
||||
}
|
||||
|
||||
@ -3,17 +3,29 @@
|
||||
|
||||
#include "GlobalDefine.h"
|
||||
#include "NetworkDevice.h"
|
||||
#include "VoipMsSMSClient.h"
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class CSMSDevice: public CNetworkDevice
|
||||
class CSMSDevice: public QObject, CNetworkDevice
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CSMSDevice(int Address, CAbstractNetworkCommIF *NetworkInterface);
|
||||
CSMSDevice(int Address, CAbstractNetworkCommIF *NetworkInterface, CVoipMsSMSClient *VoipMsIFPtr);
|
||||
virtual ~CSMSDevice();
|
||||
|
||||
//CAbstractNetworkDevice implementation
|
||||
virtual int NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);
|
||||
|
||||
CVoipMsSMSClient *mVoipMsInterfaceHandle;
|
||||
QTimer *mStatusRequestTimer;
|
||||
int mStatusRequestsCount;
|
||||
|
||||
private:
|
||||
void RequestStatus();
|
||||
public slots:
|
||||
void StatusReqTimerExpired();
|
||||
|
||||
};
|
||||
|
||||
#endif // CSMSDEVICE_H
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
#include "CSMSMessage.h"
|
||||
|
||||
|
||||
|
||||
CSMSMessage::CSMSMessage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
38
Sources/VoipSMS/SMSMessage.cpp
Normal file
38
Sources/VoipSMS/SMSMessage.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "SMSMessage.h"
|
||||
#include <QDataStream>
|
||||
|
||||
|
||||
|
||||
CSMSMessage::CSMSMessage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const CSMSMessage &source)
|
||||
{
|
||||
|
||||
out << source.mDID
|
||||
<< source.mDateTime
|
||||
<< source.mMessageText
|
||||
<< source.mContact
|
||||
<< (qint32)source.mType
|
||||
<< source.mVOIPMSDatabaseID;
|
||||
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &in, CSMSMessage &dest)
|
||||
{
|
||||
qint32 temp;
|
||||
in >> dest.mDID
|
||||
>> dest.mDateTime
|
||||
>> dest.mMessageText
|
||||
>> dest.mContact
|
||||
>> temp
|
||||
>> dest.mVOIPMSDatabaseID;
|
||||
|
||||
dest.mType = (eSMSType)temp;
|
||||
|
||||
return in;
|
||||
}
|
||||
@ -33,4 +33,7 @@ public:
|
||||
|
||||
};
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const CSMSMessage &source);
|
||||
QDataStream &operator>>(QDataStream &in, CSMSMessage &dest);
|
||||
|
||||
#endif // CSMSOBJECT_H
|
||||
@ -56,7 +56,7 @@ int CVoipMsSMSClient::SendSMSDownloadRequest(QDate StartDate, QDate EndDate)
|
||||
Url.clear();
|
||||
QTextStream UrlStream(&Url);
|
||||
|
||||
qDebug() << "Sending request for dates from: " << StartDate.toString("yyyy-MM-dd") << " to: " << EndDate.toString("yyyy-MM-dd");
|
||||
// qDebug() << "Sending request for dates from: " << StartDate.toString("yyyy-MM-dd") << " to: " << EndDate.toString("yyyy-MM-dd");
|
||||
|
||||
// Url = "https://www.voip.ms/api/v1/rest.php?api_username=jean-francois.martel@polymtl.ca&api_password=Pentium2&method=getSMS&from=2015-11-01&to=2015-11-11&did=5143606463&limit=50";
|
||||
|
||||
@ -69,7 +69,7 @@ int CVoipMsSMSClient::SendSMSDownloadRequest(QDate StartDate, QDate EndDate)
|
||||
<< "did=" << mVOIPMsSettings.mDefaultDID << "&"
|
||||
<< "limit=" << VOIP_MS_SMS_MAX_COUNT;
|
||||
|
||||
qDebug() << "Cmd: " << Url;
|
||||
// qDebug() << "Cmd: " << Url;
|
||||
mVOIPMSSocket->get(QNetworkRequest(Url));
|
||||
mCurStartDate = EndDate;
|
||||
|
||||
@ -166,7 +166,7 @@ unsigned int CVoipMsSMSClient::SMSReceived(QJsonArray *SMSArray)
|
||||
}
|
||||
|
||||
NBMsgReceived = NewMessages.size();
|
||||
qDebug() << "Received " << NBMsgReceived << "messages";
|
||||
// qDebug() << "Received " << NBMsgReceived << "messages";
|
||||
|
||||
|
||||
if(mSMSMessagesList.size() >0 && NewMessages.size() > 0)
|
||||
@ -198,7 +198,7 @@ unsigned int CVoipMsSMSClient::SMSReceived(QJsonArray *SMSArray)
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
if(mFirstDownloadDone == true)
|
||||
if(mFirstDownloadDone == true && NewMessages.size() > 0)
|
||||
{
|
||||
qDebug() << "Added " << NewMessages.size() << " new SMS messages";
|
||||
qDebug("-----------------------------------------------------------------------");
|
||||
@ -238,7 +238,7 @@ unsigned int CVoipMsSMSClient::SMSReceived(QJsonArray *SMSArray)
|
||||
}
|
||||
}
|
||||
mSMSMessagesList.append(NewMessages);
|
||||
if(mFirstDownloadDone == true)
|
||||
if(mFirstDownloadDone == true && NewMessages.size() > 0)
|
||||
{
|
||||
qDebug() << "Added " << NewMessages.size() << " new SMS messages";
|
||||
qDebug("-----------------------------------------------------------------------");
|
||||
@ -271,15 +271,15 @@ unsigned int CVoipMsSMSClient::SMSReceived(QJsonArray *SMSArray)
|
||||
{
|
||||
if(mFirstDownloadDone == false)
|
||||
{
|
||||
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(" ");
|
||||
// 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;
|
||||
@ -383,6 +383,21 @@ void CVoipMsSMSClient::CheckNewSMSTimerExpired()
|
||||
CheckForNewSMS();
|
||||
}
|
||||
|
||||
QList<CSMSMessage> *CVoipMsSMSClient::GetSMSList()
|
||||
{
|
||||
return &mSMSMessagesList;
|
||||
}
|
||||
|
||||
int CVoipMsSMSClient::GetSMSCount()
|
||||
{
|
||||
return mSMSMessagesList.size();
|
||||
}
|
||||
|
||||
QString CVoipMsSMSClient::GetDefaultDID()
|
||||
{
|
||||
return mVOIPMsSettings.mDefaultDID;
|
||||
}
|
||||
|
||||
|
||||
//https://www.voip.ms/api/v1/rest.php?api_username=jean-francois.martel@polymtl.ca&api_password=Pentium2&method=getBalance&advanced=True
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
#include <QNetworkReply>
|
||||
#include "GlobalDefine.h"
|
||||
#include <QList>
|
||||
#include "CSMSMessage.h"
|
||||
#include "SMSMessage.h"
|
||||
#include <QStringList>
|
||||
#include <QJsonArray>
|
||||
#include "ProgramSettings.h"
|
||||
@ -46,6 +46,11 @@ public:
|
||||
|
||||
|
||||
|
||||
QList<CSMSMessage> *GetSMSList();
|
||||
int GetSMSCount();
|
||||
QString GetDefaultDID();
|
||||
|
||||
|
||||
private:
|
||||
QNetworkAccessManager *mVOIPMSSocket;
|
||||
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
#include <QFont>
|
||||
#include <stdio.h>
|
||||
#include "MasterCtrl.h"
|
||||
#include <QLoggingCategory>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -40,6 +41,8 @@ int main(int argc, char *argv[])
|
||||
QApplication::setFont(serifFont);
|
||||
QApplication::setQuitOnLastWindowClosed(false);
|
||||
|
||||
QLoggingCategory::setFilterRules("qt.network.ssl.warning=false");
|
||||
|
||||
|
||||
//Create program instance
|
||||
CMasterCtrl MasterCtrl;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user