Correction de la lecture de la date & heure (format BCD) envoyée par le

HPC.
This commit is contained in:
jfmartel 2017-09-27 11:03:22 -04:00 committed by zonetest
parent 442024be91
commit 749b66566c
5 changed files with 56 additions and 8 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/ZT.pro.user.Pj2362
/Escape.ZT
/LOG/LogZT.txt
/ING/IngLog.txt

View File

@ -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

BIN
ZT

Binary file not shown.

View File

@ -140,13 +140,28 @@ void CModbusCCMgr::RegistersDatabaseUpdated(quint16 StartAddress, quint16 Length
QList<qint16> 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);

View File

@ -63,6 +63,8 @@ private:
bool mZTWatchdogEnabled;
int ResetCCRepository();
quint8 BCDToIntByte(const quint8 byte);
quint16 BCDToIntWord(const quint16 word);
signals:
void RepoHasChanged();