diff --git a/.gitignore b/.gitignore index cb11402..8d96280 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/ZT.pro.user.Pj2362 /Escape.ZT /LOG/LogZT.txt /ING/IngLog.txt diff --git a/Configuration/ZT.cfg b/Configuration/ZT.cfg index 82b9fe4..e35916f 100644 --- a/Configuration/ZT.cfg +++ b/Configuration/ZT.cfg @@ -51,7 +51,7 @@ UTILISER_MODBUS_CC=OUI #Adresse modbus de la ZT MODBUS_CC_DEVID=1 #Port Modbus/TCP -MODBUS_CC_PORT=2183 +MODBUS_CC_PORT=502 #---------------------------------- #Changer cette valeur à OUI ou NON pour activer le diff --git a/ZT b/ZT index 43bbf7d..c8347d8 100755 Binary files a/ZT and b/ZT differ diff --git a/sources/Modbus/ModbusCCMgr.cpp b/sources/Modbus/ModbusCCMgr.cpp index d3a374a..a97989f 100644 --- a/sources/Modbus/ModbusCCMgr.cpp +++ b/sources/Modbus/ModbusCCMgr.cpp @@ -140,13 +140,28 @@ void CModbusCCMgr::RegistersDatabaseUpdated(quint16 StartAddress, quint16 Length QList DateTime = mModbusRepo->GetRegs(MODUBS_CC_CLK_SEC_BASE_REG_ADD,4,&OK); if(OK) { - qint8 Secs, Minutes, Hours, Month, Day; - Secs = (qint8)(DateTime.at(0) >> 8); - Minutes = (qint8)(DateTime.at(1) & 0x00FF); - Hours = (qint8)(DateTime.at(1) >> 8); - Day = (qint8)(DateTime.at(2) & 0x00FF); - Month = (qint8)(DateTime.at(2) >> 8); - qint16 Year = DateTime.at(3); + qDebug("Registres: [%d][%d][%d][%d]",DateTime.at(0),DateTime.at(1),DateTime.at(2),DateTime.at(3)); + quint8 Secs, Minutes, Hours, Month, Day; + quint8 temp; + temp = (quint8)(DateTime.at(0) >> 8); + Secs = BCDToIntByte(temp); + + temp = (quint8)(DateTime.at(1) & 0x00FF); + Minutes = BCDToIntByte(temp); + + temp = (qint8)(DateTime.at(1) >> 8); + Hours = BCDToIntByte(temp); + + temp = (quint8)(DateTime.at(2) & 0x00FF); + Day = BCDToIntByte(temp); + + temp = (quint8)(DateTime.at(2) >> 8); + Month = BCDToIntByte(temp); + + quint16 Year = DateTime.at(3); + Year = BCDToIntWord(Year); + + qDebug("Secs [%d], Minutes[%d], Hours[%d], Month[%d], Day[%d], Year[%d]",Secs,Minutes,Hours,Month,Day,Year); QDateTime NetworkTime; NetworkTime.setTimeSpec(Qt::UTC); @@ -188,6 +203,36 @@ void CModbusCCMgr::RegistersDatabaseUpdated(quint16 StartAddress, quint16 Length emit RepoHasChanged(); } +quint8 CModbusCCMgr::BCDToIntByte(const quint8 byte) +{ + quint8 out = 0; + quint8 temp = 0; + + out += byte & 0x0F; + temp = (byte >> 4) & 0x0F; + out += (temp * 10); + + return out; + +} + +quint16 CModbusCCMgr::BCDToIntWord(const quint16 word) +{ + quint16 out = 0; + quint16 temp = 0; + + out += word & 0x000F; + temp = (word >> 4) & 0x000F; + out += (temp * 10); + temp = (word >> 8) & 0x000F; + out += (temp * 100); + temp = (word >> 12) & 0x000F; + out += (temp * 1000); + + return out; + +} + void CModbusCCMgr::ModbusRequestException(quint8 ExceptionCode, quint8 FctCode) { //qDebug("Modbus CC: Request exception occured. ExceptCode: [%d], FctCode: [%d]",ExceptionCode,FctCode); diff --git a/sources/Modbus/ModbusCCMgr.h b/sources/Modbus/ModbusCCMgr.h index d70906d..766df70 100644 --- a/sources/Modbus/ModbusCCMgr.h +++ b/sources/Modbus/ModbusCCMgr.h @@ -63,6 +63,8 @@ private: bool mZTWatchdogEnabled; int ResetCCRepository(); + quint8 BCDToIntByte(const quint8 byte); + quint16 BCDToIntWord(const quint16 word); signals: void RepoHasChanged();