diff --git a/Configuration/Contacts.mcc b/Configuration/Contacts.mcc index 123db1f..adb32a6 100644 Binary files a/Configuration/Contacts.mcc and b/Configuration/Contacts.mcc differ diff --git a/MasterCtrl.pro b/MasterCtrl.pro index 3ec32f8..daabd28 100644 --- a/MasterCtrl.pro +++ b/MasterCtrl.pro @@ -9,6 +9,7 @@ HEADERS += \ Sources/Chalet/ChaletData.h \ Sources/Chalet/ChaletInterface.h \ Sources/Chalet/ChaletLoraDevice.h \ + Sources/Ispindel/IspindelData.h \ Sources/LoraNetworkCommIF.h \ Sources/MasterCtrl.h \ Sources/GlobalDefine.h \ @@ -49,12 +50,16 @@ HEADERS += \ Sources/ImageCropper/imagecropper_p.h \ Sources/Modbus/ModbusBackend.h \ Sources/Modbus/ModbusRepository.h \ - Sources/Chalet/ChaletModbusServer.h + Sources/Chalet/ChaletModbusServer.h \ + Sources/Ispindel/IspindelDevice.h \ + Sources/Ispindel/IspindelDataLogger.h \ + Sources/Ispindel/IspindelInterface.h SOURCES += \ Sources/Chalet/ChaletData.cpp \ Sources/Chalet/ChaletInterface.cpp \ Sources/Chalet/ChaletLoraDevice.cpp \ + Sources/Ispindel/IspindelData.cpp \ Sources/LoraNetworkCommIF.cpp \ Sources/main.cpp \ Sources/MasterCtrl.cpp \ @@ -91,7 +96,10 @@ SOURCES += \ Sources/ImageCropper/imagecropper.cpp \ Sources/Modbus/ModbusBackend.cpp \ Sources/Modbus/ModbusRepository.cpp \ - Sources/Chalet/ChaletModbusServer.cpp + Sources/Chalet/ChaletModbusServer.cpp \ + Sources/Ispindel/IspindelDevice.cpp \ + Sources/Ispindel/IspindelDataLogger.cpp \ + Sources/Ispindel/IspindelInterface.cpp DEFINES -= Q_OS_UNIX @@ -111,6 +119,7 @@ INCLUDEPATH += $$PWD/ \ $$PWD/Sources/HttpServer \ $$PWD/blynk-library-master/src/ \ $$PWD/Sources/Modbus \ + $$PWD/Sources/Ispindel \ # $$PWD/Lib/QtHTTPServer/include/ \ LIBS += -L$$PWD/Lib/QtHTTPServer/ -lQt5HttpServer diff --git a/MasterCtrl.pro.user.4.8-pre1 b/MasterCtrl.pro.user.4.8-pre1 new file mode 100644 index 0000000..5cf9af0 --- /dev/null +++ b/MasterCtrl.pro.user.4.8-pre1 @@ -0,0 +1,264 @@ + + + + + + EnvironmentId + {5a351af6-dc3b-4afc-af92-7da5e3a5cd12} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Qt 5.14.2 + Qt 5.14.2 + {dc2b548b-27bc-4e25-8500-cc36640735d8} + 0 + 0 + 0 + + D:/Main/PicDev/Projets/MasterCtrl/Masterctrl + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Main/PicDev/Projets/MasterCtrl/Masterctrl/release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + MasterCtrl + + Qt4ProjectManager.Qt4RunConfiguration:D:/Main/PicDev/Projets/MasterCtrl/Masterctrl/MasterCtrl.pro + true + + MasterCtrl.pro + false + + D:/Main/PicDev/Projets/MasterCtrl/Masterctrl + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/Sources/Chalet/ChaletInterface.cpp b/Sources/Chalet/ChaletInterface.cpp index 720bc2b..79d1b00 100644 --- a/Sources/Chalet/ChaletInterface.cpp +++ b/Sources/Chalet/ChaletInterface.cpp @@ -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); +} diff --git a/Sources/Chalet/ChaletInterface.h b/Sources/Chalet/ChaletInterface.h index cad7551..fd0edf7 100644 --- a/Sources/Chalet/ChaletInterface.h +++ b/Sources/Chalet/ChaletInterface.h @@ -20,6 +20,7 @@ private: public slots: void DeviceWiFiDataReceived(); + void DeviceFirmwareVersionReceived(); }; diff --git a/Sources/Chalet/ChaletLoraDevice.cpp b/Sources/Chalet/ChaletLoraDevice.cpp index dd6f32d..10f6808 100644 --- a/Sources/Chalet/ChaletLoraDevice.cpp +++ b/Sources/Chalet/ChaletLoraDevice.cpp @@ -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!!!"); diff --git a/Sources/Chalet/ChaletLoraDevice.h b/Sources/Chalet/ChaletLoraDevice.h index 792d4e8..2c5bc10 100644 --- a/Sources/Chalet/ChaletLoraDevice.h +++ b/Sources/Chalet/ChaletLoraDevice.h @@ -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(); diff --git a/Sources/Chalet/ThingsBoardInterface.cpp b/Sources/Chalet/ThingsBoardInterface.cpp index 2abb0bd..7004bad 100644 --- a/Sources/Chalet/ThingsBoardInterface.cpp +++ b/Sources/Chalet/ThingsBoardInterface.cpp @@ -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"); diff --git a/Sources/EthernetNetworkServer.cpp b/Sources/EthernetNetworkServer.cpp index ce4f05d..a3403ef 100644 --- a/Sources/EthernetNetworkServer.cpp +++ b/Sources/EthernetNetworkServer.cpp @@ -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; diff --git a/Sources/Ispindel/IspindelData.cpp b/Sources/Ispindel/IspindelData.cpp new file mode 100644 index 0000000..3edd24b --- /dev/null +++ b/Sources/Ispindel/IspindelData.cpp @@ -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; +} + + diff --git a/Sources/Ispindel/IspindelData.h b/Sources/Ispindel/IspindelData.h new file mode 100644 index 0000000..6a4a897 --- /dev/null +++ b/Sources/Ispindel/IspindelData.h @@ -0,0 +1,25 @@ +#ifndef CISPINDELDATA_H +#define CISPINDELDATA_H + +#include +#include +#include + +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 diff --git a/Sources/Ispindel/IspindelDataLogger.cpp b/Sources/Ispindel/IspindelDataLogger.cpp new file mode 100644 index 0000000..2df5201 --- /dev/null +++ b/Sources/Ispindel/IspindelDataLogger.cpp @@ -0,0 +1,102 @@ +#include "IspindelDataLogger.h" +#include +#include +#include + +CIspindelDataLogger::CIspindelDataLogger(QObject *parent) : QObject(parent) +{ + +} + +int CIspindelDataLogger::WriteLogToFile(QList *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 *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; + + +} diff --git a/Sources/Ispindel/IspindelDataLogger.h b/Sources/Ispindel/IspindelDataLogger.h new file mode 100644 index 0000000..08fcb0a --- /dev/null +++ b/Sources/Ispindel/IspindelDataLogger.h @@ -0,0 +1,25 @@ +#ifndef ISPINDELDATALOGGER_H +#define ISPINDELDATALOGGER_H + +#include +#include +#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 *Data, bool OnlyLastItem = true); + int LoadLogData(QList *DataList); + +signals: + +public slots: +}; + +#endif // ISPINDELDATALOGGER_H diff --git a/Sources/Ispindel/IspindelDevice.cpp b/Sources/Ispindel/IspindelDevice.cpp new file mode 100644 index 0000000..8877d79 --- /dev/null +++ b/Sources/Ispindel/IspindelDevice.cpp @@ -0,0 +1,128 @@ +#include "IspindelDevice.h" +#include +#include + +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; +} diff --git a/Sources/Ispindel/IspindelDevice.h b/Sources/Ispindel/IspindelDevice.h new file mode 100644 index 0000000..e769dd9 --- /dev/null +++ b/Sources/Ispindel/IspindelDevice.h @@ -0,0 +1,39 @@ +#ifndef ISPINDELDEVICE_H +#define ISPINDELDEVICE_H + + +#include +#include +#include +#include "IspindelData.h" +#include "IspindelDataLogger.h" +#include + +class CIspindelDevice: public QObject +{ + Q_OBJECT +public: + CIspindelDevice(); + ~CIspindelDevice(); + + QTcpServer *mISpindelServer; + QTcpSocket *mIspindelClientConnection; + QList mIspindelLog; + CIspindelDataLogger mDataLogger; + + CIspindelData *GetLastestIspindelData(); + QList *GetAllData(){return &mIspindelLog;} + QByteArray GetAllDataBuffer(); + QByteArray GetLastestIspindelDataBuffer(); + + +public slots: + void IspindelClientConnected(); + void IspindelClientDataAvail(); + void IspindelClientDisconnected(); + +signals: + void NewIspindelDataReceived(); +}; + +#endif // ISPINDELDEVICE_H diff --git a/Sources/Ispindel/IspindelInterface.cpp b/Sources/Ispindel/IspindelInterface.cpp new file mode 100644 index 0000000..9395452 --- /dev/null +++ b/Sources/Ispindel/IspindelInterface.cpp @@ -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"); + +} diff --git a/Sources/Ispindel/IspindelInterface.h b/Sources/Ispindel/IspindelInterface.h new file mode 100644 index 0000000..9c962a0 --- /dev/null +++ b/Sources/Ispindel/IspindelInterface.h @@ -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 diff --git a/Sources/MasterCtrl.cpp b/Sources/MasterCtrl.cpp index b936fa4..e21c58f 100644 --- a/Sources/MasterCtrl.cpp +++ b/Sources/MasterCtrl.cpp @@ -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; diff --git a/Sources/MasterCtrl.h b/Sources/MasterCtrl.h index eeb4a6a..aeeca3e 100644 --- a/Sources/MasterCtrl.h +++ b/Sources/MasterCtrl.h @@ -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; diff --git a/Sources/NetworkDevicesMgr.cpp b/Sources/NetworkDevicesMgr.cpp index 94d8599..ba7d2f5 100644 --- a/Sources/NetworkDevicesMgr.cpp +++ b/Sources/NetworkDevicesMgr.cpp @@ -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()); diff --git a/Sources/NetworkDevicesMgr.h b/Sources/NetworkDevicesMgr.h index 80536d2..a4e7b37 100644 --- a/Sources/NetworkDevicesMgr.h +++ b/Sources/NetworkDevicesMgr.h @@ -8,6 +8,7 @@ #include "AbstractNetworkInterface.h" #include "AvReceiverInterface.h" #include "ChaletInterface.h" +#include "IspindelInterface.h" #include "QList" #include @@ -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; diff --git a/Sources/ProtocolDefs.h b/Sources/ProtocolDefs.h index 31993e0..36f8198 100644 --- a/Sources/ProtocolDefs.h +++ b/Sources/ProtocolDefs.h @@ -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 diff --git a/Sources/VoipSMS/VoipMsSMSClient.cpp b/Sources/VoipSMS/VoipMsSMSClient.cpp index 280f180..b5e33bf 100644 --- a/Sources/VoipSMS/VoipMsSMSClient.cpp +++ b/Sources/VoipSMS/VoipMsSMSClient.cpp @@ -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()));