Commit 23ce4009 authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Implement routine for CANopen HB Consumer (plus visual delegate)

parent 69a1cd3f
...@@ -172,6 +172,7 @@ Project { ...@@ -172,6 +172,7 @@ Project {
"components/DelegateRawNodeTable.qml", "components/DelegateRawNodeTable.qml",
"components/DelegateRoutineOnCanFrame.qml", "components/DelegateRoutineOnCanFrame.qml",
"components/DelegateRoutineOnCanOpenBootUp.qml", "components/DelegateRoutineOnCanOpenBootUp.qml",
"components/DelegateRoutineOnCanOpenHeartbeatConsumer.qml",
"components/DelegateRoutineOnCanOpenNmtStateChange.qml", "components/DelegateRoutineOnCanOpenNmtStateChange.qml",
"components/DelegateRoutineOnCanOpenObdValChange.qml", "components/DelegateRoutineOnCanOpenObdValChange.qml",
"components/DelegateRoutineOnCanOpenSdoReadReply.qml", "components/DelegateRoutineOnCanOpenSdoReadReply.qml",
......
...@@ -289,6 +289,8 @@ void Manager::deinit (void) { ...@@ -289,6 +289,8 @@ void Manager::deinit (void) {
m_routinesOnCanOpenObdValChange.clear (); m_routinesOnCanOpenObdValChange.clear ();
m_routinesOnCanOpenSdoReadReply.clear (); m_routinesOnCanOpenSdoReadReply.clear ();
m_routinesOnCanOpenSdoWriteRequest.clear (); m_routinesOnCanOpenSdoWriteRequest.clear ();
m_routinesOnCanOpenBootUp.clear ();
m_routinesOnCanOpenHeartbeatConsumer.clear ();
m_links.clear (); m_links.clear ();
m_linksAnalogActuatorToPhysicalValue.clear (); m_linksAnalogActuatorToPhysicalValue.clear ();
m_linksAnalogOutputToAnalogActuator.clear (); m_linksAnalogOutputToAnalogActuator.clear ();
...@@ -864,6 +866,12 @@ void Manager::doInitObjects (void) { ...@@ -864,6 +866,12 @@ void Manager::doInitObjects (void) {
else if (RoutineOnCanOpenSdoWriteRequest * routineOnCanOpenSdoWriteRequest = routine->as<RoutineOnCanOpenSdoWriteRequest> ()) { else if (RoutineOnCanOpenSdoWriteRequest * routineOnCanOpenSdoWriteRequest = routine->as<RoutineOnCanOpenSdoWriteRequest> ()) {
m_routinesOnCanOpenSdoWriteRequest.append (routineOnCanOpenSdoWriteRequest); m_routinesOnCanOpenSdoWriteRequest.append (routineOnCanOpenSdoWriteRequest);
} }
else if (RoutineOnCanOpenBootUp * routineOnCanOpenBootUp = routine->as<RoutineOnCanOpenBootUp> ()) {
m_routinesOnCanOpenBootUp.append (routineOnCanOpenBootUp);
}
else if (RoutineOnCanOpenHeartbeatConsumer * routineOnCanOpenHeartbeatConsumer = routine->as<RoutineOnCanOpenHeartbeatConsumer> ()) {
m_routinesOnCanOpenBootUp.append (routineOnCanOpenHeartbeatConsumer);
}
else { } else { }
usePath = true; usePath = true;
} }
......
...@@ -98,6 +98,8 @@ class Manager : public QObject { ...@@ -98,6 +98,8 @@ class Manager : public QObject {
QML_REFLIST_PROPERTY (RoutineOnCanOpenObdValChange, routinesOnCanOpenObdValChange, 100) QML_REFLIST_PROPERTY (RoutineOnCanOpenObdValChange, routinesOnCanOpenObdValChange, 100)
QML_REFLIST_PROPERTY (RoutineOnCanOpenSdoReadReply, routinesOnCanOpenSdoReadReply, 20) QML_REFLIST_PROPERTY (RoutineOnCanOpenSdoReadReply, routinesOnCanOpenSdoReadReply, 20)
QML_REFLIST_PROPERTY (RoutineOnCanOpenSdoWriteRequest, routinesOnCanOpenSdoWriteRequest, 20) QML_REFLIST_PROPERTY (RoutineOnCanOpenSdoWriteRequest, routinesOnCanOpenSdoWriteRequest, 20)
QML_REFLIST_PROPERTY (RoutineOnCanOpenBootUp, routinesOnCanOpenBootUp, 5)
QML_REFLIST_PROPERTY (RoutineOnCanOpenHeartbeatConsumer, routinesOnCanOpenHeartbeatConsumer, 5)
QML_REFLIST_PROPERTY (PhysicalValue, physicalValues, 500) QML_REFLIST_PROPERTY (PhysicalValue, physicalValues, 500)
QML_REFLIST_PROPERTY (PhysicalBlock, physicalBlocks, 10) QML_REFLIST_PROPERTY (PhysicalBlock, physicalBlocks, 10)
QML_REFLIST_PROPERTY (PhysicalMarker, physicalMarkers, 20) QML_REFLIST_PROPERTY (PhysicalMarker, physicalMarkers, 20)
......
...@@ -385,7 +385,7 @@ RoutineOnCanOpenBootUp::~RoutineOnCanOpenBootUp (void) { ...@@ -385,7 +385,7 @@ RoutineOnCanOpenBootUp::~RoutineOnCanOpenBootUp (void) {
void RoutineOnCanOpenBootUp::prepare (void) { void RoutineOnCanOpenBootUp::prepare (void) {
if (get_canOpen () && !m_canMgr) { if (get_canOpen () && !m_canMgr) {
if ((m_canMgr = get_canOpen ()->getProtocolManager ())) { if ((m_canMgr = get_canOpen ()->getProtocolManager ())) {
connect (m_canMgr.data (), &CanOpenProtocolManager::recvNodeHeartBeat, this, &RoutineOnCanOpenBootUp::onRecvHeartbeatState, Qt::UniqueConnection); connect (m_canMgr.data (), &CanOpenProtocolManager::remoteNodeStateChanged, this, &RoutineOnCanOpenBootUp::onRecvHeartbeatState);
} }
} }
} }
...@@ -442,3 +442,53 @@ void RoutineOnSerialFrame::updateSubscription (void) { ...@@ -442,3 +442,53 @@ void RoutineOnSerialFrame::updateSubscription (void) {
void RoutineOnSerialFrame::trigger (void) { void RoutineOnSerialFrame::trigger (void) {
emit triggered (); emit triggered ();
} }
RoutineOnCanOpenHeartbeatConsumer::RoutineOnCanOpenHeartbeatConsumer(QObject * parent)
: AbstractCanOpenRoutine (Triggers::CANOPEN_HB_CONSUMER, parent)
, m_canMgr (Q_NULLPTR)
, m_currNodeId (0)
, m_currState (CanOpenHeartBeatStates::Initializing)
, m_currAlive (false)
{
Manager::instance ().registerObject (this);
}
RoutineOnCanOpenHeartbeatConsumer::~RoutineOnCanOpenHeartbeatConsumer (void) {
Manager::instance ().unregisterObject (this);
}
void RoutineOnCanOpenHeartbeatConsumer::prepare (void) {
if (get_canOpen () && !m_canMgr) {
if ((m_canMgr = get_canOpen ()->getProtocolManager ())) {
connect (m_canMgr.data (), &CanOpenProtocolManager::remoteNodeAliveChanged,
this, &RoutineOnCanOpenHeartbeatConsumer::onRemoteNodeAliveChanged);
connect (m_canMgr.data (), &CanOpenProtocolManager::remoteNodeStateChanged,
this, &RoutineOnCanOpenHeartbeatConsumer::onRemoteNodeStateChanged);
}
}
}
void RoutineOnCanOpenHeartbeatConsumer::cleanup (void) {
if (m_canMgr) {
disconnect (m_canMgr.data (), Q_NULLPTR, this, Q_NULLPTR);
m_canMgr.clear ();
}
}
void RoutineOnCanOpenHeartbeatConsumer::trigger (void) {
if (m_canMgr) {
emit triggered (m_currNodeId, m_currAlive, m_currState);
}
}
void RoutineOnCanOpenHeartbeatConsumer::onRemoteNodeStateChanged (const CanOpenNodeId nodeId, const CanOpenHeartBeatState state) {
m_currNodeId = nodeId;
m_currState = state;
execute ();
}
void RoutineOnCanOpenHeartbeatConsumer::onRemoteNodeAliveChanged (const CanOpenNodeId nodeId, const bool alive) {
m_currNodeId = nodeId;
m_currAlive = alive;
execute ();
}
...@@ -24,6 +24,7 @@ QML_ENUM_CLASS (Triggers, ...@@ -24,6 +24,7 @@ QML_ENUM_CLASS (Triggers,
CANOPEN_SDO_READ_REPLY, CANOPEN_SDO_READ_REPLY,
CANOPEN_SDO_WRITE_REQUEST, CANOPEN_SDO_WRITE_REQUEST,
CANOPEN_BOOTUP, CANOPEN_BOOTUP,
CANOPEN_HB_CONSUMER,
SERIAL_FRAME_RECV, SERIAL_FRAME_RECV,
NB_TRIGGERS) NB_TRIGGERS)
...@@ -283,7 +284,7 @@ private: ...@@ -283,7 +284,7 @@ private:
ByteArrayWrapper * m_currBuffer; ByteArrayWrapper * m_currBuffer;
}; };
class RoutineOnCanOpenBootUp : public AbstractCanOpenRoutine { class RoutineOnCanOpenBootUp : public AbstractCanOpenRoutine { // DEPRECATED, use RoutineOnCanOpenHeartbeatConsumer
Q_OBJECT Q_OBJECT
public: public:
...@@ -307,4 +308,34 @@ private: ...@@ -307,4 +308,34 @@ private:
QPointer<CanOpenProtocolManager> m_canMgr; QPointer<CanOpenProtocolManager> m_canMgr;
CanOpenNodeId m_currNodeId; CanOpenNodeId m_currNodeId;
}; };
class RoutineOnCanOpenHeartbeatConsumer : public AbstractCanOpenRoutine {
Q_OBJECT
public:
explicit RoutineOnCanOpenHeartbeatConsumer (QObject * parent = Q_NULLPTR);
virtual ~RoutineOnCanOpenHeartbeatConsumer (void);
void prepare (void) Q_DECL_FINAL;
void cleanup (void) Q_DECL_FINAL;
protected:
void trigger (void) Q_DECL_FINAL;
signals:
void triggered (const int nodeId, const bool alive, const int state);
protected slots:
void onRemoteNodeStateChanged (const CanOpenNodeId nodeId,
const CanOpenHeartBeatState state);
void onRemoteNodeAliveChanged (const CanOpenNodeId nodeId,
const bool alive);
private:
QPointer<CanOpenProtocolManager> m_canMgr;
CanOpenNodeId m_currNodeId;
CanOpenHeartBeatState m_currState;
bool m_currAlive;
};
#endif // ABSTRACTROUTINE_H #endif // ABSTRACTROUTINE_H
...@@ -209,6 +209,7 @@ void SharedObject::registerQmlTypes (QQmlEngine * qmlEngine) { ...@@ -209,6 +209,7 @@ void SharedObject::registerQmlTypes (QQmlEngine * qmlEngine) {
qmlRegisterType<RoutineOnCanOpenSdoReadReply> (uri, maj, min, "RoutineOnCanOpenSdoReadReply"); qmlRegisterType<RoutineOnCanOpenSdoReadReply> (uri, maj, min, "RoutineOnCanOpenSdoReadReply");
qmlRegisterType<RoutineOnCanOpenSdoWriteRequest> (uri, maj, min, "RoutineOnCanOpenSdoWriteRequest"); qmlRegisterType<RoutineOnCanOpenSdoWriteRequest> (uri, maj, min, "RoutineOnCanOpenSdoWriteRequest");
qmlRegisterType<RoutineOnCanOpenBootUp> (uri, maj, min, "RoutineOnCanOpenBootUp"); qmlRegisterType<RoutineOnCanOpenBootUp> (uri, maj, min, "RoutineOnCanOpenBootUp");
qmlRegisterType<RoutineOnCanOpenHeartbeatConsumer> (uri, maj, min, "RoutineOnCanOpenHeartbeatConsumer");
qmlRegisterType<SerialBus> (uri, maj, min, "SerialBus"); qmlRegisterType<SerialBus> (uri, maj, min, "SerialBus");
qmlRegisterType<AffineTransformer> (uri, maj, min, "AffineTransformer"); qmlRegisterType<AffineTransformer> (uri, maj, min, "AffineTransformer");
qmlRegisterType<CustomTransformer> (uri, maj, min, "CustomTransformer"); qmlRegisterType<CustomTransformer> (uri, maj, min, "CustomTransformer");
......
...@@ -31,6 +31,7 @@ QtObject { ...@@ -31,6 +31,7 @@ QtObject {
readonly property Component delegateRoutineOnCanFrame : Component { DelegateRoutineOnCanFrame { } } readonly property Component delegateRoutineOnCanFrame : Component { DelegateRoutineOnCanFrame { } }
readonly property Component delegateRoutineOnSerialFrame : Component { DelegateRoutineOnSerialFrame { } } readonly property Component delegateRoutineOnSerialFrame : Component { DelegateRoutineOnSerialFrame { } }
readonly property Component delegateRoutineOnCanOpenBootUp : Component { DelegateRoutineOnCanOpenBootUp { } } readonly property Component delegateRoutineOnCanOpenBootUp : Component { DelegateRoutineOnCanOpenBootUp { } }
readonly property Component delegateRoutineOnCanOpenHeartbeatConsumer : Component { DelegateRoutineOnCanOpenHeartbeatConsumer { } }
readonly property Component delegateRoutineOnCanOpenObdValChange : Component { DelegateRoutineOnCanOpenObdValChange { } } readonly property Component delegateRoutineOnCanOpenObdValChange : Component { DelegateRoutineOnCanOpenObdValChange { } }
readonly property Component delegateRoutineOnCanOpenNmtStateChange : Component { DelegateRoutineOnCanOpenNmtStateChange { } } readonly property Component delegateRoutineOnCanOpenNmtStateChange : Component { DelegateRoutineOnCanOpenNmtStateChange { } }
readonly property Component delegateRoutineOnCanOpenSdoReadReply : Component { DelegateRoutineOnCanOpenSdoReadReply { } } readonly property Component delegateRoutineOnCanOpenSdoReadReply : Component { DelegateRoutineOnCanOpenSdoReadReply { } }
......
import QtQuick 2.1;
import QtQmlTricks.UiElements 2.0;
import QtCAN.CanTestBench 2.0;
AbstractDelegateRoutine {
id: base;
property RoutineOnCanOpenHeartbeatConsumer routineOnCanOpenHeartbeatConsumer : null;
property alias routine : base.routineOnCanOpenHeartbeatConsumer;
StretchRowContainer {
spacing: Style.spacingNormal;
TextLabel {
text: (routineOnCanOpenHeartbeatConsumer ? routineOnCanOpenHeartbeatConsumer.uid : "");
emphasis: true;
anchors.verticalCenter: parent.verticalCenter;
}
TextLabel {
text: (routineOnCanOpenHeartbeatConsumer ? "(" + routineOnCanOpenHeartbeatConsumer.title + ")" : "");
visible: (text !== "" && text !== "()");
anchors.verticalCenter: parent.verticalCenter;
}
Stretcher { }
}
StretchRowContainer {
spacing: Style.spacingNormal;
TextLabel {
text: qsTr ("triggered on CANopen Heartbeat Consumer change");
anchors.verticalCenter: parent.verticalCenter;
}
}
}
...@@ -1240,6 +1240,8 @@ Item { ...@@ -1240,6 +1240,8 @@ Item {
return Components.delegateRoutineOnCanOpenSdoWriteRequest; return Components.delegateRoutineOnCanOpenSdoWriteRequest;
case Triggers.CANOPEN_BOOTUP: case Triggers.CANOPEN_BOOTUP:
return Components.delegateRoutineOnCanOpenBootUp; return Components.delegateRoutineOnCanOpenBootUp;
case Triggers.CANOPEN_HB_CONSUMER:
return Components.delegateRoutineOnCanOpenHeartbeatConsumer;
} }
return null; return null;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment