Modbus dev...
This commit is contained in:
parent
4e31b27857
commit
dc75fc9313
@ -31,7 +31,9 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QStyleOptionGraphicsItem>
|
#include <QStyleOptionGraphicsItem>
|
||||||
|
|
||||||
CStatusBar::CStatusBar(QGraphicsItem *Parent)
|
CStatusBar::CStatusBar(QGraphicsItem *Parent):
|
||||||
|
mCCModbusONOFF("",this),
|
||||||
|
mSEIModbusONOFF("",this)
|
||||||
{
|
{
|
||||||
|
|
||||||
setParentItem(Parent);
|
setParentItem(Parent);
|
||||||
@ -45,6 +47,16 @@ CStatusBar::CStatusBar(QGraphicsItem *Parent)
|
|||||||
mZT1Status = mZT2Status = SB_ZT_INACTIVE_STATUS;
|
mZT1Status = mZT2Status = SB_ZT_INACTIVE_STATUS;
|
||||||
mCCModbusState = SB_MODBUS_NOT_PRESENT;
|
mCCModbusState = SB_MODBUS_NOT_PRESENT;
|
||||||
mSEIModbusState = SB_MODBUS_NOT_PRESENT;
|
mSEIModbusState = SB_MODBUS_NOT_PRESENT;
|
||||||
|
|
||||||
|
mCCModbusONOFF.setParentItem(this);
|
||||||
|
mCCModbusONOFF.setPos(760,0);
|
||||||
|
mCCModbusONOFF.LedOFF();
|
||||||
|
mCCModbusONOFF.hide();
|
||||||
|
|
||||||
|
mSEIModbusONOFF.setParentItem(this);
|
||||||
|
mSEIModbusONOFF.setPos(845,0);
|
||||||
|
mSEIModbusONOFF.LedOFF();
|
||||||
|
mSEIModbusONOFF.hide();
|
||||||
// QGraphicsRectItem *temprect = new QGraphicsRectItem(this);
|
// QGraphicsRectItem *temprect = new QGraphicsRectItem(this);
|
||||||
// temprect->setRect(boundingRect());
|
// temprect->setRect(boundingRect());
|
||||||
// temprect->show();
|
// temprect->show();
|
||||||
@ -173,7 +185,7 @@ void CStatusBar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
|
|||||||
{
|
{
|
||||||
painter->setPen(Qt::darkGreen);
|
painter->setPen(Qt::darkGreen);
|
||||||
Text.clear();
|
Text.clear();
|
||||||
Text.sprintf("CC[Connecté]");
|
Text.sprintf("CC:");
|
||||||
TextRect.adjust(5,0,0,0);
|
TextRect.adjust(5,0,0,0);
|
||||||
painter->drawText(TextRect, Qt::AlignLeft, Text);
|
painter->drawText(TextRect, Qt::AlignLeft, Text);
|
||||||
TextRect.adjust(painter->fontMetrics().width(Text),0,0,0);
|
TextRect.adjust(painter->fontMetrics().width(Text),0,0,0);
|
||||||
@ -182,7 +194,7 @@ void CStatusBar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
|
|||||||
{
|
{
|
||||||
painter->setPen(Qt::red);
|
painter->setPen(Qt::red);
|
||||||
Text.clear();
|
Text.clear();
|
||||||
Text.sprintf("CC[Déconnecté]");
|
Text.sprintf("CC:");
|
||||||
TextRect.adjust(5,0,0,0);
|
TextRect.adjust(5,0,0,0);
|
||||||
painter->drawText(TextRect, Qt::AlignLeft, Text);
|
painter->drawText(TextRect, Qt::AlignLeft, Text);
|
||||||
TextRect.adjust(painter->fontMetrics().width(Text),0,0,0);
|
TextRect.adjust(painter->fontMetrics().width(Text),0,0,0);
|
||||||
@ -192,8 +204,8 @@ void CStatusBar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
|
|||||||
{
|
{
|
||||||
painter->setPen(Qt::darkGreen);
|
painter->setPen(Qt::darkGreen);
|
||||||
Text.clear();
|
Text.clear();
|
||||||
Text.sprintf("SEI[Connecté]");
|
Text.sprintf("SEI:");
|
||||||
TextRect.adjust(20,0,0,0);
|
TextRect.adjust(50,0,0,0);
|
||||||
painter->drawText(TextRect, Qt::AlignLeft, Text);
|
painter->drawText(TextRect, Qt::AlignLeft, Text);
|
||||||
TextRect.adjust(painter->fontMetrics().width(Text),0,0,0);
|
TextRect.adjust(painter->fontMetrics().width(Text),0,0,0);
|
||||||
}
|
}
|
||||||
@ -201,8 +213,8 @@ void CStatusBar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
|
|||||||
{
|
{
|
||||||
painter->setPen(Qt::red);
|
painter->setPen(Qt::red);
|
||||||
Text.clear();
|
Text.clear();
|
||||||
Text.sprintf("SEI[Déconnecté]");
|
Text.sprintf("SEI:");
|
||||||
TextRect.adjust(20,0,0,0);
|
TextRect.adjust(50,0,0,0);
|
||||||
painter->drawText(TextRect, Qt::AlignLeft, Text);
|
painter->drawText(TextRect, Qt::AlignLeft, Text);
|
||||||
TextRect.adjust(painter->fontMetrics().width(Text),0,0,0);
|
TextRect.adjust(painter->fontMetrics().width(Text),0,0,0);
|
||||||
}
|
}
|
||||||
@ -241,12 +253,43 @@ unsigned int CStatusBar::SetZT2Status(unsigned int Status)
|
|||||||
unsigned int CStatusBar::SetCCModbusState(unsigned int State)
|
unsigned int CStatusBar::SetCCModbusState(unsigned int State)
|
||||||
{
|
{
|
||||||
mCCModbusState = State;
|
mCCModbusState = State;
|
||||||
|
if(State == SB_MODBUS_CONNECTED)
|
||||||
|
{
|
||||||
|
mCCModbusONOFF.LedON();
|
||||||
|
mCCModbusONOFF.show();
|
||||||
|
}
|
||||||
|
else if(State == SB_MODBUS_DISCONNECTED)
|
||||||
|
{
|
||||||
|
mCCModbusONOFF.LedOFF();
|
||||||
|
mCCModbusONOFF.show();
|
||||||
|
}
|
||||||
|
else if(State == SB_MODBUS_NOT_PRESENT)
|
||||||
|
{
|
||||||
|
mCCModbusONOFF.hide();
|
||||||
|
}
|
||||||
|
|
||||||
update(boundingRect());
|
update(boundingRect());
|
||||||
|
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
unsigned int CStatusBar::SetSEIModbusState(unsigned int State)
|
unsigned int CStatusBar::SetSEIModbusState(unsigned int State)
|
||||||
{
|
{
|
||||||
mSEIModbusState = State;
|
mSEIModbusState = State;
|
||||||
|
if(State == SB_MODBUS_CONNECTED)
|
||||||
|
{
|
||||||
|
mSEIModbusONOFF.LedON();
|
||||||
|
mSEIModbusONOFF.show();
|
||||||
|
}
|
||||||
|
else if(State == SB_MODBUS_DISCONNECTED)
|
||||||
|
{
|
||||||
|
mSEIModbusONOFF.LedOFF();
|
||||||
|
mSEIModbusONOFF.show();
|
||||||
|
}
|
||||||
|
else if(State == SB_MODBUS_NOT_PRESENT)
|
||||||
|
{
|
||||||
|
mSEIModbusONOFF.hide();
|
||||||
|
}
|
||||||
|
|
||||||
update(boundingRect());
|
update(boundingRect());
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include "GlobalDefine.h"
|
#include "GlobalDefine.h"
|
||||||
#include <QGraphicsWidget>
|
#include <QGraphicsWidget>
|
||||||
|
#include "LedWidget.h"
|
||||||
|
|
||||||
enum eZTStatus
|
enum eZTStatus
|
||||||
{
|
{
|
||||||
@ -66,6 +67,7 @@ private:
|
|||||||
unsigned int mZT1Status, mZT2Status;
|
unsigned int mZT1Status, mZT2Status;
|
||||||
unsigned int mNbTrainsPass, mNbTriggers;
|
unsigned int mNbTrainsPass, mNbTriggers;
|
||||||
unsigned int mCCModbusState, mSEIModbusState;
|
unsigned int mCCModbusState, mSEIModbusState;
|
||||||
|
CLedWidget mCCModbusONOFF, mSEIModbusONOFF;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // STATUSBAR_H
|
#endif // STATUSBAR_H
|
||||||
|
|||||||
@ -84,10 +84,10 @@
|
|||||||
|
|
||||||
|
|
||||||
//Incoming
|
//Incoming
|
||||||
#define MODBUS_CC_ZTC_ZT1_FLAG_MASK 0x0001
|
#define MODBUS_CC_FCYCLE_ZT1_FLAG_MASK 0x0001
|
||||||
#define MODBUS_CC_ZTC_ZT2_FLAG_MASK 0x0002
|
#define MODBUS_CC_FCYCLE_ZT2_FLAG_MASK 0x0002
|
||||||
#define MODBUS_CC_FCYCLE_ZT1_FLAG_MASK 0x0004
|
#define MODBUS_CC_INHIBIT_ZT1_FLAG_MASK 0x0004
|
||||||
#define MODBUS_CC_FCYCLE_ZT2_FLAG_MASK 0x0008
|
#define MODBUS_CC_INHIBIT_ZT2_FLAG_MASK 0x0008
|
||||||
|
|
||||||
#define MODBUS_CC_DATA_BASE_REG_ADD 2028
|
#define MODBUS_CC_DATA_BASE_REG_ADD 2028
|
||||||
#define MODBUS_CC_TABLE_DATA_SIZE 13 //Taille de la table = 28 registres
|
#define MODBUS_CC_TABLE_DATA_SIZE 13 //Taille de la table = 28 registres
|
||||||
@ -95,11 +95,11 @@
|
|||||||
|
|
||||||
#define MODBUS_CC_WATCHDOG_BASE_REG_ADD 2028
|
#define MODBUS_CC_WATCHDOG_BASE_REG_ADD 2028
|
||||||
#define MODBUS_CC_AN_BASE_REG_ADD 2029
|
#define MODBUS_CC_AN_BASE_REG_ADD 2029
|
||||||
#define MODBUS_CC_CLK_UPDATE_BASE_REG_ADD 2036
|
#define MODBUS_CC_CLK_UPDATE_BASE_REG_ADD 2038
|
||||||
#define MODUBS_CC_CLK_SEC_BASE_REG_ADD 2037
|
#define MODUBS_CC_CLK_SEC_BASE_REG_ADD 2039
|
||||||
#define MODUBS_CC_CLK_HR_MIN_BASE_REG_ADD 2038
|
#define MODUBS_CC_CLK_HR_MIN_BASE_REG_ADD 2040
|
||||||
#define MODUBS_CC_CLK_MNT_DAY_BASE_REG_ADD 2039
|
#define MODUBS_CC_CLK_MNT_DAY_BASE_REG_ADD 2041
|
||||||
#define MODUBS_CC_CLK_YEAR_BASE_REG_ADD 2040
|
#define MODUBS_CC_CLK_YEAR_BASE_REG_ADD 2042
|
||||||
|
|
||||||
|
|
||||||
#endif // PROTOCOLDEFS_H
|
#endif // PROTOCOLDEFS_H
|
||||||
|
|||||||
@ -116,6 +116,8 @@ int CModbusRepository::WriteHRData(quint16 StartAddress, quint16 Length, QByteAr
|
|||||||
}
|
}
|
||||||
mMutex.unlock();
|
mMutex.unlock();
|
||||||
|
|
||||||
|
emit RepoChanged(StartAddress,Length);
|
||||||
|
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +135,8 @@ int CModbusRepository::WriteSingleReg(quint16 Address, quint16 Value)
|
|||||||
mHoldingRegisters[RegisterIndex].mRegistersData[DataIndex] = Value;
|
mHoldingRegisters[RegisterIndex].mRegistersData[DataIndex] = Value;
|
||||||
mMutex.unlock();
|
mMutex.unlock();
|
||||||
|
|
||||||
|
emit RepoChanged(Address,1);
|
||||||
|
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,6 +156,8 @@ int CModbusRepository::WriteMultipleRegs(quint16 StartAddress, QList<qint16> Dat
|
|||||||
mHoldingRegisters[RegisterIndex].mRegistersData[DataIndex++] = Data.at(i);
|
mHoldingRegisters[RegisterIndex].mRegistersData[DataIndex++] = Data.at(i);
|
||||||
}
|
}
|
||||||
mMutex.unlock();
|
mMutex.unlock();
|
||||||
|
|
||||||
|
emit RepoChanged(StartAddress,Data.size());
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,8 +14,9 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CModbusRepository
|
class CModbusRepository : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
CModbusRepository();
|
CModbusRepository();
|
||||||
|
|
||||||
@ -28,11 +29,15 @@ public:
|
|||||||
int WriteHRData(quint16 StartAddress, quint16 Length, QByteArray Data);
|
int WriteHRData(quint16 StartAddress, quint16 Length, QByteArray Data);
|
||||||
int WriteSingleReg(quint16 Address, quint16 Value);
|
int WriteSingleReg(quint16 Address, quint16 Value);
|
||||||
int WriteMultipleRegs(quint16 StartAddress, QList<qint16> Data);
|
int WriteMultipleRegs(quint16 StartAddress, QList<qint16> Data);
|
||||||
|
const QList<CHRDataMap> *GetRepo(){return &mHoldingRegisters;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<CHRDataMap> mHoldingRegisters;
|
QList<CHRDataMap> mHoldingRegisters;
|
||||||
QReadWriteLock mMutex;
|
QReadWriteLock mMutex;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void RepoChanged(quint16 StartAddress, quint16 Length);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MODBUSREPOSITORY_H
|
#endif // MODBUSREPOSITORY_H
|
||||||
|
|||||||
@ -701,6 +701,6 @@ void CModbusTKTransport::ExecZT2SM()
|
|||||||
void CModbusTKTransport::ModbusCCUpdated()
|
void CModbusTKTransport::ModbusCCUpdated()
|
||||||
{
|
{
|
||||||
qint16 ClearReg = mModbusRepo->GetSingleReg(MODBUS_CC_AN_BASE_REG_ADD);
|
qint16 ClearReg = mModbusRepo->GetSingleReg(MODBUS_CC_AN_BASE_REG_ADD);
|
||||||
mZT1Clear = (ClearReg & (MODBUS_CC_FCYCLE_ZT1_FLAG_MASK | MODBUS_CC_ZTC_ZT1_FLAG_MASK)) != 0;
|
mZT1Clear = (ClearReg & (MODBUS_CC_FCYCLE_ZT1_FLAG_MASK)) != 0;
|
||||||
mZT2Clear = (ClearReg & (MODBUS_CC_FCYCLE_ZT2_FLAG_MASK | MODBUS_CC_ZTC_ZT2_FLAG_MASK)) != 0;
|
mZT2Clear = (ClearReg & (MODBUS_CC_FCYCLE_ZT2_FLAG_MASK)) != 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user