Interface Ispindel + dev ChaletInterface

This commit is contained in:
2021-12-12 12:21:21 -05:00
parent 1dadad4b09
commit 8aafc96dbd
23 changed files with 849 additions and 30 deletions
+11
View File
@@ -8,6 +8,7 @@ CChaletInterface::CChaletInterface(int Address, CAbstractNetworkCommIF *NetworkI
mChaletDataLogger = mChaletLoraDevice->GetDataLoggerHandle();
connect(mChaletLoraDevice,SIGNAL(DeviceWifiStoredParamsReceived()),this,SLOT(DeviceWiFiDataReceived()));
connect(mChaletLoraDevice,SIGNAL(DeviceFirmwareVersionReceived()),this,SLOT(DeviceFirmwareVersionReceived()));
}
@@ -106,6 +107,10 @@ int CChaletInterface::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, in
mChaletLoraDevice->SendSetWifiParams(Data);
break;
}
case CHALET_INTERFACE_GET_FIRMWARE_VERSION_REQUEST:
{
mChaletLoraDevice->SendGetFirmwareVersion();
}
case CHALET_INTERFACE_WIFI_GET_DEVICE_PARAMS_RESPONSE:
case CHALET_INTERFACE_WIFI_SET_DEVICE_PARAMS_RESPONSE:
case CHALET_INTERFACE_GET_DATA_LOG_RESPONSE:
@@ -140,3 +145,9 @@ void CChaletInterface::DeviceWiFiDataReceived()
QByteArray Data = mChaletLoraDevice->GetDeviceWiFiStoredParams();
mNetworkInterfacePtr->SendNetworkMessage(ID_CHALET_INTERFACE,mDeviceAddress,CHALET_INTERFACE_WIFI_GET_DEVICE_PARAMS_RESPONSE,Data.size(),&Data);
}
void CChaletInterface::DeviceFirmwareVersionReceived()
{
QByteArray Data = mChaletLoraDevice->GetDeviceFirmwareVersion();
mNetworkInterfacePtr->SendNetworkMessage(ID_CHALET_INTERFACE,mDeviceAddress,CHALET_INTERFACE_GET_FIRMWARE_VERSION_RESPONSE,Data.size(),&Data);
}
+1
View File
@@ -20,6 +20,7 @@ private:
public slots:
void DeviceWiFiDataReceived();
void DeviceFirmwareVersionReceived();
};
+34 -21
View File
@@ -22,6 +22,7 @@ CChaletLoraDevice::CChaletLoraDevice(int Address, CAbstractNetworkCommIF *Networ
mChaletModbusServer = new CChaletModbusServer(&mChaletModbusRepo,512,1);
mDeviceWiFiParameters.fill(0xFF);
mDeviceFirmwareVersion.fill(0xFF);
ResetCommStats();
}
@@ -56,7 +57,7 @@ int CChaletLoraDevice::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, i
{
float temp;
qint16 temp2;
qDebug("Chalet Status RX");
// qDebug("Chalet Status RX");
char VoltageArray[4];
char TemperatureArray[4];
char SolarPanelCurrentArray[2];
@@ -94,10 +95,10 @@ int CChaletLoraDevice::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, i
mChaletMainStatus.mLastLoraStatus = QDateTime::currentDateTime();
CmdResponseReceived(CHALET_GENERAL_STATUS_REQUEST);
qDebug("voltage: %f",mChaletMainStatus.mBatteryVoltage);
// qDebug("voltage: %f",mChaletMainStatus.mBatteryVoltage);
// qDebug("Current: %d",mChaletMainStatus.mBatteryCurrent);
// qDebug("SOC: %d",mChaletMainStatus.mBatterySOC);
qDebug("Inverter: %d",mChaletMainStatus.mInverterRelayStatus);
// qDebug("Inverter: %d",mChaletMainStatus.mInverterRelayStatus);
mChaletDataLogger.LogChaletLORAData(&mChaletMainStatus);
@@ -114,22 +115,22 @@ int CChaletLoraDevice::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, i
mThingsBoardInterface.UpdateChaletData(&mChaletMainStatus);
mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_ONLINE_STATE_REG,(quint16)mChaletMainStatus.mIsOnline);
mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_WIFI_STATE_REG,(quint16)mChaletMainStatus.mWiFiModuleStatus);
mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_CURRENT_SENSOR_STATE_REG,(quint16)mChaletMainStatus.mCurrentSensorStatus);
mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_HARAKIRI_DONE_REG,(quint16)mChaletMainStatus.mHarakiriDone);
mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_STATUS_TOGGLE_REG,(quint16)mChaletMainStatus.mStatusToggleBit);
//mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_WATCHDOG_STATUS_REG,(quint16),mChaletMainStatus.m)
mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_INVERTER_REG,(quint16)mChaletMainStatus.mInverterRelayStatus);
// mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_ONLINE_STATE_REG,(quint16)mChaletMainStatus.mIsOnline);
// mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_WIFI_STATE_REG,(quint16)mChaletMainStatus.mWiFiModuleStatus);
// mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_CURRENT_SENSOR_STATE_REG,(quint16)mChaletMainStatus.mCurrentSensorStatus);
// mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_HARAKIRI_DONE_REG,(quint16)mChaletMainStatus.mHarakiriDone);
// mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_STATUS_TOGGLE_REG,(quint16)mChaletMainStatus.mStatusToggleBit);
// //mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_WATCHDOG_STATUS_REG,(quint16),mChaletMainStatus.m)
// mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_INVERTER_REG,(quint16)mChaletMainStatus.mInverterRelayStatus);
quint16 TempInt16;
memcpy(&TempInt16,&VoltageArray[0],2);
mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_BATTERY_VOLTAGE_REG_1,TempInt16);
memcpy(&TempInt16,&VoltageArray[2],2);
mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_BATTERY_VOLTAGE_REG_2,TempInt16);
// quint16 TempInt16;
// memcpy(&TempInt16,&VoltageArray[0],2);
// mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_BATTERY_VOLTAGE_REG_1,TempInt16);
// memcpy(&TempInt16,&VoltageArray[2],2);
// mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_BATTERY_VOLTAGE_REG_2,TempInt16);
mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_BATTERY_CURRENT_REG_1,mChaletMainStatus.mBatteryCurrent);
mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_BATTERY_SOC_REG,mChaletMainStatus.mBatterySOC);
// mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_BATTERY_CURRENT_REG_1,mChaletMainStatus.mBatteryCurrent);
// mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_BATTERY_SOC_REG,mChaletMainStatus.mBatterySOC);
break;
}
@@ -141,7 +142,7 @@ int CChaletLoraDevice::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, i
}
case CHALET_AC_POWER_SET_STATE_RESPONSE:
{
qDebug("Lora set Inverter Power response : 0x%d",(int)Data[0]);
// qDebug("Lora set Inverter Power response : 0x%d",(int)Data[0]);
mChaletMainStatus.mInverterRelayStatus = Data[0];
CmdResponseReceived(CHALET_AC_POWER_SET_STATE_REQUEST);
break;
@@ -164,7 +165,7 @@ int CChaletLoraDevice::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, i
}
case CHALET_WIFI_SET_STATE_RESPONSE:
{
qDebug("Lora set WiFi response : 0x%d",(int)Data[0]);
// qDebug("Lora set WiFi response : 0x%d",(int)Data[0]);
mChaletMainStatus.mWiFiModuleStatus = Data[0];
CmdResponseReceived(CHALET_WIFI_SET_STATE_REQUEST);
break;
@@ -210,6 +211,13 @@ int CChaletLoraDevice::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, i
emit DeviceWifiSetParamsResult(Data[0]);
break;
}
case CHALET_GET_FIRMWARE_VERSION_RESPONSE:
{
CmdResponseReceived(CHALET_GET_FIRMWARE_VERSION_REQUEST);
mDeviceFirmwareVersion = Data.left(15);
emit DeviceFirmwareVersionReceived();
break;
}
default:
{
@@ -252,7 +260,7 @@ void CChaletLoraDevice::CommTimerExpired()
ComputeCommStats();
}
qDebug("Sending chalet request 0x%x",mPendingNetworkMsgList.at(0).mMessageID);
// qDebug("Sending chalet request 0x%x",mPendingNetworkMsgList.at(0).mMessageID);
mPendingNetworkMsgList[0].PendingResponse = true;
SendChaletCommand(mPendingNetworkMsgList.at(0).mMessageID,mPendingNetworkMsgList.at(0).mData.size(),mPendingNetworkMsgList.at(0).mData);
@@ -334,6 +342,11 @@ int CChaletLoraDevice::SendSetWifiParams(QByteArray Data)
return ScheduleChaletCommand(CHALET_SET_STORED_WIFI_SETTINGS_REQUEST,Data);
}
int CChaletLoraDevice::SendGetFirmwareVersion()
{
return ScheduleChaletCommand(CHALET_GET_FIRMWARE_VERSION_REQUEST,QByteArray());
}
int CChaletLoraDevice::SendChaletCommand(int CmdID, int DataSize, QByteArray Data)
{
mNetworkInterfacePtr->SendNetworkMessage(ID_CHALET_DEVICE,mDeviceAddress,CmdID,DataSize,&Data);
@@ -352,7 +365,7 @@ int CChaletLoraDevice::CmdResponseReceived(int CmdID)
qDebug("Chalet is ONLINE!");
}
qDebug("Chalet response received from cmd: 0x%x",CmdID);
//qDebug("Chalet response received from cmd: 0x%x",CmdID);
if(mPendingNetworkMsgList.size() == 0)
{
qDebug("Cmd ack received but list is empty!!!");
+6
View File
@@ -41,6 +41,7 @@ public:
CChaletMainStatus GetChaletMainStatus() {return mChaletMainStatus;}
QByteArray GetDeviceWiFiStoredParams() {return mDeviceWiFiParameters;}
QByteArray GetDeviceFirmwareVersion() {return mDeviceFirmwareVersion;}
CBlynkCloudClient mBlynkInterface;
CThingsBoardInterface mThingsBoardInterface;
CChaletModbusServer *mChaletModbusServer;
@@ -57,6 +58,7 @@ public:
CChaletDataLogger *GetDataLoggerHandle() {return &mChaletDataLogger;} //for Interface use...
QByteArray mDeviceWiFiParameters;
QByteArray mDeviceFirmwareVersion;
@@ -69,15 +71,19 @@ public:
int ComputeCommStats();
int SendGetWifiParams();
int SendSetWifiParams(QByteArray Data);
int SendGetFirmwareVersion();
int CmdResponseReceived(int CmdID);
int ScheduleChaletStatusRequest();
int ScheduleChaletCommand(int CmdID, int DataSize, QByteArray Data);
int ScheduleChaletCommand(int CmdID,QByteArray Data);
bool IsInverterON(){return mChaletMainStatus.mInverterRelayStatus == 1;}
signals:
void DeviceWifiStoredParamsReceived();
void DeviceWifiSetParamsResult(char);
void DeviceFirmwareVersionReceived();
public slots:
void CommTimerExpired();
+27 -5
View File
@@ -119,7 +119,7 @@ void CThingsBoardInterface::UpdateChaletData(CChaletMainStatus *Data)
JsonByteArray.append("\"Inverter_State\":");
JsonByteArray.append((QString("%1, ").arg(Data->mInverterRelayStatus)).toUtf8().data());
JsonByteArray = "{\"Temperature_Sensor\":";
JsonByteArray.append("\"Temperature_Sensor\":");
JsonByteArray.append((QString("%1}").arg(Data->mChaletTemperature)).toUtf8().data());
QNetworkRequest Req;
@@ -173,7 +173,7 @@ void CThingsBoardInterface::ThingsBoardRPCFinished(QNetworkReply *NetworkReply)
{
if(mThingsBoardRPCReply->error() != QNetworkReply::NoError)
{
qDebug("Network error (ThingsBoardRPC)... %d", mThingsBoardRPCReply->error());
// qDebug("Network error (ThingsBoardRPC)... %d", mThingsBoardRPCReply->error());
RegisterThingsboardRPC();
return;
}
@@ -204,17 +204,17 @@ void CThingsBoardInterface::ThingsBoardRPCFinished(QNetworkReply *NetworkReply)
if(RequestedState == true)
{
qDebug("Server Inverter TURN ON request received.");
mChaletLoraDevice->SendInverterPowerRelayState(true);
// mChaletLoraDevice->SendInverterPowerRelayState(true);
}
if(RequestedState == false)
{
qDebug("Server Inverter TURN OFF request received.");
mChaletLoraDevice->SendInverterPowerRelayState(false);
// mChaletLoraDevice->SendInverterPowerRelayState(false);
}
}
else if(RequestedCmd.toString().contains("setWiFiState"))
else if(RequestedCmd.toString().contains("setChaletWiFiState"))
{
//Fetch the required state.
QString RequestedState = RPCCmd.value("params").toString();
@@ -227,6 +227,28 @@ void CThingsBoardInterface::ThingsBoardRPCFinished(QNetworkReply *NetworkReply)
qDebug("Server WiFi TURN OFF request received.");
}
}
else if(RequestedCmd.toString().contains("getChaletInverterState"))
{
qDebug("Inverter state request received");
QByteArray JsonByteArray;
int ReqID = RPCCmd.value("id").toInt();
if(mChaletLoraDevice->IsInverterON())
{
JsonByteArray = "{\"InverterSwitchState\":\"1\"}";
}
else
{
JsonByteArray = "{\"InverterSwitchState\":\"0\"}";
}
QNetworkRequest Req;
// QString URL = QString("http://192.168.50.225:8080/api/v1/qpJ6tWCkXHJzDQviDJ64/rpc/%1").arg(ReqID);
QString URL = QString("http://192.168.50.225:8080/api/v1/qpJ6tWCkXHJzDQviDJ64/attributes");
Req.setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
Req.setUrl(QUrl(URL));
mThingsBoardSocket->post(Req,JsonByteArray);
}
else
{
qDebug("Received an unknown RPC call from ThingsBoard server");
+14
View File
@@ -194,6 +194,20 @@ void CEthernetNetworkServer::DeviceSocketDataAvail()
}
break;
}
case ID_ISPINDEL_INTERFACE:
{
if(mDevicesMgrHandle->CreateNewIspindleInterface(DeviceAddress,(CAbstractNetworkCommIF*)NetworkIF) == RET_OK)
{
Result = RES_CREATION_SUCCESS;
qDebug("Created new Ispindel Interface");
}
else
{
Result = RES_CREATION_FAILED;
qDebug("Could not create Ispindel Interface in ethernet server");
}
break;
}
default:
{
Result = RES_CREATION_UNKNOWN_DEVICE;
+54
View File
@@ -0,0 +1,54 @@
#include "IspindelData.h"
CIspindelData::CIspindelData()
{
mIspindelID = mRSSI = mInterval = 0;
mIspindelName = mTemperatureUnits = "";
mAngle = mBattery = mGravity = mTemperature = 0.0;
mSampleDateTime = QDateTime::currentDateTime();
}
QDataStream &operator<<(QDataStream &out, const CIspindelData &source)
{
out << source.mAngle
<< source.mBattery
<< source.mGravity
<< source.mInterval
<< source.mIspindelID
<< source.mIspindelName
<< source.mRSSI
<< source.mTemperature
<< source.mTemperatureUnits
<< source.mSampleDateTime;
return out;
}
QDataStream &operator>>(QDataStream &in, CIspindelData &dest)
{
in >> dest.mAngle
>> dest.mBattery
>> dest.mGravity
>> dest.mInterval
>> dest.mIspindelID
>> dest.mIspindelName
>> dest.mRSSI
>> dest.mTemperature
>> dest.mTemperatureUnits
>> dest.mSampleDateTime;
return in;
}
QByteArray CIspindelData::ToByteArray()
{
QByteArray Array;
QDataStream Strm(&Array,QIODevice::WriteOnly | QIODevice::Unbuffered);
Strm << *this;
return Array;
}
+25
View File
@@ -0,0 +1,25 @@
#ifndef CISPINDELDATA_H
#define CISPINDELDATA_H
#include <QString>
#include <QDataStream>
#include <QDateTime>
class CIspindelData
{
public:
CIspindelData();
int mIspindelID, mRSSI, mInterval;
QString mIspindelName, mTemperatureUnits;
double mAngle, mBattery, mGravity, mTemperature;
QDateTime mSampleDateTime;
QByteArray ToByteArray();
};
QDataStream &operator<<(QDataStream &out, const CIspindelData &source);
QDataStream &operator>>(QDataStream &in, CIspindelData &dest);
#endif // CISPINDELDATA_H
+102
View File
@@ -0,0 +1,102 @@
#include "IspindelDataLogger.h"
#include <QFile>
#include <QDataStream>
#include <GlobalDefine.h>
CIspindelDataLogger::CIspindelDataLogger(QObject *parent) : QObject(parent)
{
}
int CIspindelDataLogger::WriteLogToFile(QList<CIspindelData *> *Data, bool OnlyLastItem)
{
QFile *LogFile;
QString LogFileName(ISPINDEL_LOG_DIR);
LogFileName.append("BrewLog");
LogFileName.append(".blg");
LogFile = new QFile(LogFileName);
if(LogFile->open(QIODevice::ReadWrite|QIODevice::Unbuffered) == false)
{
delete LogFile;
qDebug("Cannot open Ispindel log file for writing...");
return RET_ERROR;
}
QDataStream Strm(LogFile);
//Write header
int FileVer = ISPINDEL_LOG_FILE_VERSION;
int NbItems = Data->size();
LogFile->seek(0);
Strm << FileVer << NbItems;
if(OnlyLastItem)
{
//seek to the end of the file
LogFile->seek(LogFile->size());
//write the last item
Strm << *Data->last();
}
else
{
for(int i = 0; i < Data->size(); i++)
{
Strm << *Data->at(i);
}
}
LogFile->close();
delete LogFile;
return RET_OK;
}
int CIspindelDataLogger::LoadLogData(QList<CIspindelData *> *DataList)
{
QFile *LogFile;
QString LogFileName(ISPINDEL_LOG_DIR);
LogFileName.append("BrewLog");
LogFileName.append(".blg");
LogFile = new QFile(LogFileName);
if(LogFile->open(QIODevice::ReadOnly|QIODevice::Unbuffered) == false)
{
delete LogFile;
qDebug("Cannot open Ispindel log file for loading...");
return RET_ERROR;
}
QDataStream Strm(LogFile);
DataList->clear();
int FileVersion, NbItems;
Strm >> FileVersion;
Strm >> NbItems;
for(int i = 0; i < NbItems; i++)
{
CIspindelData *Data = new CIspindelData;
Strm >> *Data;
DataList->append(Data);
}
LogFile->close();
delete LogFile;
qDebug("Ispindel loaded %d readings",DataList->size());
for(int i = 0; i < DataList->size(); i++)
{
qDebug(qPrintable(DataList->at(i)->mSampleDateTime.toString("yyyy-MM-dd hh:mm:ss")));
}
return RET_OK;
}
+25
View File
@@ -0,0 +1,25 @@
#ifndef ISPINDELDATALOGGER_H
#define ISPINDELDATALOGGER_H
#include <QObject>
#include <QList>
#include "IspindelData.h"
#define ISPINDEL_LOG_FILE_VERSION 1
#define ISPINDEL_LOG_DIR "D:/Main/Brew/Ispindel Logs/"
class CIspindelDataLogger : public QObject
{
Q_OBJECT
public:
explicit CIspindelDataLogger(QObject *parent = 0);
int WriteLogToFile(QList<CIspindelData *> *Data, bool OnlyLastItem = true);
int LoadLogData(QList<CIspindelData *> *DataList);
signals:
public slots:
};
#endif // ISPINDELDATALOGGER_H
+128
View File
@@ -0,0 +1,128 @@
#include "IspindelDevice.h"
#include <QJsonDocument>
#include <QJsonObject>
CIspindelDevice::CIspindelDevice()
{
mISpindelServer = new QTcpServer;
connect(mISpindelServer,SIGNAL(newConnection()),this,SLOT(IspindelClientConnected()));
mISpindelServer->listen(QHostAddress::Any,80);
mIspindelLog.clear();
mDataLogger.LoadLogData(&mIspindelLog);
}
void CIspindelDevice::IspindelClientConnected()
{
mIspindelClientConnection = mISpindelServer->nextPendingConnection();
connect(mIspindelClientConnection,SIGNAL(readyRead()),this,SLOT(IspindelClientDataAvail()));
qDebug("Ispindel connected");
}
void CIspindelDevice::IspindelClientDataAvail()
{
CIspindelData *NewData = new CIspindelData;
QByteArray IspindelData;
if(mIspindelClientConnection->bytesAvailable() > 1)
{
IspindelData = QByteArray(mIspindelClientConnection->readAll());
}
else
{
return;
}
QJsonDocument JsonReply = QJsonDocument::fromJson(IspindelData);
QJsonObject JsonObject = JsonReply.object();
QStringList Keys = JsonObject.keys();
if(Keys.isEmpty())
return;
NewData->mIspindelID = JsonObject["ID"].toInt();
NewData->mRSSI = JsonObject["RSSI"].toInt();
NewData->mAngle = JsonObject["angle"].toDouble();
NewData->mBattery = JsonObject["battery"].toDouble();
NewData->mGravity = JsonObject["gravity"].toDouble();
NewData->mInterval = JsonObject["interval"].toInt();
NewData->mIspindelName = JsonObject["name"].toString();
NewData->mTemperatureUnits = JsonObject["temp_units"].toString();
NewData->mTemperature = JsonObject["temperature"].toDouble();
mIspindelLog.append(NewData);
qDebug("ID : %i",NewData->mIspindelID);
qDebug("RSSI : %i",NewData->mRSSI);
qDebug("Angle : %f",NewData->mAngle);
qDebug("Battery : %f",NewData->mBattery);
qDebug("Gravity : %f",NewData->mGravity);
qDebug("Interval (s): %i",NewData->mInterval);
qDebug("Name : %s",qPrintable(NewData->mIspindelName));
qDebug("Units : %s",qPrintable(NewData->mTemperatureUnits));
qDebug("Temperature : %f",NewData->mTemperature);
mDataLogger.WriteLogToFile(&mIspindelLog);
emit NewIspindelDataReceived();
// "ID" 6913415 QJsonValue (Number)
// "RSSI" -65 QJsonValue (Number)
// "angle" 89.59756 QJsonValue (Number)
// "battery" 4.301355 QJsonValue (Number)
// "gravity" 33.36325 QJsonValue (Number)
// "interval" 10 QJsonValue (Number)
// "name" "iSpindel001" QJsonValue (String)
// "temp_units" "C" QJsonValue (String)
// "temperature" 20.625 QJsonValue (Number)
}
void CIspindelDevice::IspindelClientDisconnected()
{
}
CIspindelDevice::~CIspindelDevice()
{
mISpindelServer->close();
for(int i = 0; i < mIspindelLog.size(); i++)
{
delete mIspindelLog[i];
mIspindelLog.clear();
}
}
CIspindelData *CIspindelDevice::GetLastestIspindelData()
{
if(mIspindelLog.size() > 0)
return mIspindelLog.last();
else
return 0;
}
QByteArray CIspindelDevice::GetAllDataBuffer()
{
QByteArray Array;
QDataStream Strm (&Array,QIODevice::WriteOnly | QIODevice::Unbuffered);
int Size = mIspindelLog.size();
Strm << Size;
for(int i = 0; i < Size; i++)
{
Strm << *mIspindelLog.at(i);
}
return Array;
}
QByteArray CIspindelDevice::GetLastestIspindelDataBuffer()
{
QByteArray Buf;
if(mIspindelLog.size() > 1)
{
Buf= mIspindelLog.last()->ToByteArray();
}
return Buf;
}
+39
View File
@@ -0,0 +1,39 @@
#ifndef ISPINDELDEVICE_H
#define ISPINDELDEVICE_H
#include <QObject>
#include <QTcpServer>
#include <QTcpSocket>
#include "IspindelData.h"
#include "IspindelDataLogger.h"
#include <QList>
class CIspindelDevice: public QObject
{
Q_OBJECT
public:
CIspindelDevice();
~CIspindelDevice();
QTcpServer *mISpindelServer;
QTcpSocket *mIspindelClientConnection;
QList<CIspindelData*> mIspindelLog;
CIspindelDataLogger mDataLogger;
CIspindelData *GetLastestIspindelData();
QList<CIspindelData*> *GetAllData(){return &mIspindelLog;}
QByteArray GetAllDataBuffer();
QByteArray GetLastestIspindelDataBuffer();
public slots:
void IspindelClientConnected();
void IspindelClientDataAvail();
void IspindelClientDisconnected();
signals:
void NewIspindelDataReceived();
};
#endif // ISPINDELDEVICE_H
+44
View File
@@ -0,0 +1,44 @@
#include "IspindelInterface.h"
#include "ProtocolDefs.h"
#include "IspindelData.h"
CIspindelInterface::CIspindelInterface(int Address, CAbstractNetworkCommIF *NetworkInterface, CIspindelDevice *DevicePtr):
CNetworkDevice(ID_ISPINDEL_INTERFACE,Address,NetworkInterface)
{
mISpindelDevice = DevicePtr;
connect(mISpindelDevice,SIGNAL(NewIspindelDataReceived()),this,SLOT(SendLastIspindelData()));
}
int CIspindelInterface::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data)
{
Q_UNUSED(DeviceID)
Q_UNUSED(DeviceAddress)
Q_UNUSED(DataSize)
Q_UNUSED(Data)
switch(MessageID)
{
case ISPINDLE_LATEST_DATA_REQUEST:
{
QByteArray Buf;
break;
}
case ISPINDEL_GET_FULL_DATA_BUFFER_REQUEST:
{
QByteArray Buf = mISpindelDevice->GetAllDataBuffer();
mNetworkInterfacePtr->SendNetworkMessage(ID_ISPINDEL_INTERFACE,mDeviceAddress,ISPINDEL_GET_FULL_DATA_BUFFER_RESPONSE,Buf.size(),&Buf);
break;
}
}
return RET_OK;
}
void CIspindelInterface::SendLastIspindelData()
{
QByteArray Buf = mISpindelDevice->GetLastestIspindelDataBuffer();
mNetworkInterfacePtr->SendNetworkMessage(ID_ISPINDEL_INTERFACE,mDeviceAddress,ISPINDLE_LATEST_DATA_RESPONSE,Buf.size(),&Buf);
qDebug("Sent latest Ispindel data to interface");
}
+22
View File
@@ -0,0 +1,22 @@
#ifndef ISPINDELINTERFACE_H
#define ISPINDELINTERFACE_H
#include "NetworkDevice.h"
#include "IspindelDevice.h"
class CIspindelInterface: public QObject, public CNetworkDevice
{
Q_OBJECT
public:
CIspindelInterface(int Address, CAbstractNetworkCommIF *NetworkInterface, CIspindelDevice *DevicePtr);
virtual int NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);
private:
CIspindelDevice *mISpindelDevice;
public slots:
void SendLastIspindelData();
};
#endif // ISPINDELINTERFACE_H
+4
View File
@@ -21,6 +21,8 @@ CMasterCtrl::CMasterCtrl()
mChaletLoraDevice = new CChaletLoraDevice(1,mChaletLoraNetworkCommInterface);
// mChaletLoraInterface = new CChaletLoraInterface(mRooftopTowerLoraDevice);
mIspindelDevice = new CIspindelDevice;
mEthernetNetworkServer = new CEthernetNetworkServer;
mNetworkDevicesManager = new CNetworkDevicesMgr;
@@ -42,6 +44,7 @@ CMasterCtrl::~CMasterCtrl()
delete mSprinklerManager;
delete mChaletLoraNetworkCommInterface;
delete mChaletLoraDevice;
delete mIspindelDevice;
// delete mMasterCtrlSettings;
}
@@ -69,6 +72,7 @@ void CMasterCtrl::Start()
mNetworkDevicesManager->mSprinklerMgrHandle = mSprinklerManager;
mNetworkDevicesManager->mAvReceiverDevice = mAVReceiverDevice;
mNetworkDevicesManager->mChaletLoraDevice = mChaletLoraDevice;
mNetworkDevicesManager->mIspindelDevice = mIspindelDevice;
mEthernetNetworkServer->mDevicesMgrHandle = mNetworkDevicesManager;
+4 -1
View File
@@ -16,6 +16,7 @@
//#include "ChaletLoraInterface.h"
#include "LoraNetworkCommIF.h"
#include "HttpServer.h"
#include "IspindelDevice.h"
//#include "AppIconWidget.h"
@@ -44,7 +45,9 @@ public:
CLoraNetworkCommIF *mChaletLoraNetworkCommInterface;
// CAppIconWidget mAppWidget;
CHttpServer mHttpServer;
// CHttpServer mHttpServer;
CIspindelDevice *mIspindelDevice;
+12
View File
@@ -14,6 +14,7 @@ CNetworkDevicesMgr::CNetworkDevicesMgr()
mSprinklerMgrHandle = 0;
mAvReceiverDevice = 0;
mChaletLoraDevice = 0;
mIspindelDevice = 0;
}
CNetworkDevicesMgr::~CNetworkDevicesMgr()
@@ -104,6 +105,17 @@ int CNetworkDevicesMgr::CreateNewChaletInterface(int Address, CAbstractNetworkCo
return RET_OK;
}
int CNetworkDevicesMgr::CreateNewIspindleInterface(int Address, CAbstractNetworkCommIF *NetworkIF)
{
if(mIspindelDevice == 0)
{
return RET_ERROR;
}
CIspindelInterface *IspindelInterface = new CIspindelInterface(Address, NetworkIF, mIspindelDevice);
mNetworkDevicesList.append((CNetworkDevice*)IspindelInterface);
return RET_OK;
}
void CNetworkDevicesMgr::EthernetNetworkDeviceDisconnected(CNetworkDevice *Device)
{
qDebug("Device disconnected. ID: %d, Address: %d",Device->GetDeviceID(),Device->GetDeviceAddress());
+4
View File
@@ -8,6 +8,7 @@
#include "AbstractNetworkInterface.h"
#include "AvReceiverInterface.h"
#include "ChaletInterface.h"
#include "IspindelInterface.h"
#include "QList"
#include <QObject>
@@ -18,6 +19,7 @@ class CContactRepository;
class CSprinklerMgr;
class CAVReceiverDevice;
class CChaletLoraDevice;
class CIspindelDevice;
class CNetworkDevicesMgr: public QObject
{
@@ -34,6 +36,7 @@ public:
int CreateNewSprinklerInterface(int Address, CAbstractNetworkCommIF *NetworkIF);
int CreateNewAvReceiverInterface(int Address, CAbstractNetworkCommIF *NetworkIF);
int CreateNewChaletInterface(int Address, CAbstractNetworkCommIF *NetworkIF);
int CreateNewIspindleInterface(int Address, CAbstractNetworkCommIF *NetworkIF);
int FindDeviceByPtr(CNetworkDevice *Device);
CNetworkDevice *GetDevice(int DeviceID, int Address);
@@ -41,6 +44,7 @@ public:
CAVReceiverDevice *mAvReceiverDevice;
CChaletLoraDevice *mChaletLoraDevice;
CIspindelDevice *mIspindelDevice;
CVoipMsSMSClient *mVoipMSInterfaceHandle;
CContactRepository *mContactRepositoryHandle;
CMasterCtrl *mProgramHandle;
+17
View File
@@ -60,6 +60,7 @@ enum DEVICES_IDS
ID_AVRECEIVER_INTERFACE,
ID_CHALET_INTERFACE,
ID_CHALET_DEVICE,
ID_ISPINDEL_INTERFACE,
ID_NB_DEVICE_ID
};
@@ -274,6 +275,9 @@ enum CHALET_INTERFACE_CMDS
CHALET_INTERFACE_WIFI_GET_DEVICE_PARAMS_RESPONSE,
CHALET_INTERFACE_WIFI_SET_DEVICE_PARAMS_REQUEST,
CHALET_INTERFACE_WIFI_SET_DEVICE_PARAMS_RESPONSE,
CHALET_INTERFACE_GET_FIRMWARE_VERSION_REQUEST,
CHALET_INTERFACE_GET_FIRMWARE_VERSION_RESPONSE,
MAX_CHALET_INTERFACE_CMD
@@ -304,9 +308,22 @@ enum CHALET_CMDS
CHALET_GET_STORED_WIFI_SETTINGS_RESPONSE,
CHALET_SET_STORED_WIFI_SETTINGS_REQUEST,
CHALET_SET_STORED_WIFI_SETTINGS_RESPONSE,
CHALET_GET_FIRMWARE_VERSION_REQUEST,
CHALET_GET_FIRMWARE_VERSION_RESPONSE,
MAX_CHALET_CMD
};
enum ISPINDLE_CMDS
{
ISPINDLE_ACK = 1,
ISPINDLE_LATEST_DATA_REQUEST,
ISPINDLE_LATEST_DATA_RESPONSE,
ISPINDEL_GET_FULL_DATA_BUFFER_REQUEST,
ISPINDEL_GET_FULL_DATA_BUFFER_RESPONSE,
MAX_ISPINDLE_CMDS
};
#endif
+1 -1
View File
@@ -16,7 +16,7 @@ CVoipMsSMSClient::CVoipMsSMSClient()
mVOIPMsNotificationServer = new QTcpServer;
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()));