IoT::CANopen

class NMT

File Information

Library: IoT/CANopen
Package: CANopen
Header: IoT/CANopen/NMT.h

Description

This class implements the CANopen Network Management (NMT) protocol.

Currently supported features are device state machine, remote commands sent by the master and heartbeat. Guarding is not supported.

Member Summary

Member Functions: changeState, getAutoStartDelay, getHeartbeatInterval, nodeID, onFrameReceived, reset, sendHeartbeat, setAutoStartDelay, setHeartbeatInterval, setUp, start, state, stop

Nested Classes

class AutoStartTask protected

 

struct Heartbeat

 

class HeartbeatTask protected

 

struct StateChange

 

Enumerations

Anonymous

NMT_ID = 1792

Base CAN-ID for NMT/heartbeat messages.

Command

NMT commands sent by master.

NMT_COMMAND_START = 1

NMT_COMMAND_STOP = 2

NMT_COMMAND_ENTER_PRE_OPERATIONAL = 128

NMT_COMMAND_RESET = 129

NMT_COMMAND_RESET_COMM = 130

State

State of the device.

NMT_STATE_INIT = 0

NMT_STATE_STOPPED = 4

NMT_STATE_OPERATIONAL = 5

NMT_STATE_PREOPERATIONAL = 127

Constructors

NMT

NMT(
    CANBus & canBus,
    Poco::UInt8 nodeID,
    Poco::Util::Timer & timer
);

Creates the NMT object using the given CANBus and own node ID, as well as the given timer. The initial device state is NMT_STATE_INIT.

Destructor

~NMT

~NMT();

Destroys the NMT object.

Member Functions

getAutoStartDelay inline

Poco::Timespan getAutoStartDelay() const;

Returns the time interval after which the device will automatically enter operational state, after entering pre-operational state.

getHeartbeatInterval inline

Poco::Timespan getHeartbeatInterval() const;

Returns the heartbeat interval for this node, or 0 if the heartbeat has been disabled.

nodeID inline

Poco::UInt8 nodeID() const;

Returns the node ID.

reset

void reset();

Brings the device into initializing (NMT_STATE_INIT) state.

setAutoStartDelay

void setAutoStartDelay(
    Poco::Timespan delay
);

Sets the time interval after which the device will automatically enter operational state, after entering pre-operational state. If set to 0, the device will not automatically enter operational state.

Must be called while the device is in NMT_STATE_INIT state.

setHeartbeatInterval

void setHeartbeatInterval(
    Poco::Timespan interval
);

Sets the heartbeat interval for heartbeat messages generated by this node. Setting the interval to 0 disables the heartbeat.

Must be called while the device is in NMT_STATE_INIT state.

setUp

void setUp();

Brings the device from any state into pre-operational (NMT_STATE_PREOPERATIONAL) state.

start

void start();

Brings the device into operational (NMT_STATE_OPERATIONAL) state. The device must be in pre-operational or stopped state.

state inline

State state();

Returns the current device state.

stop

void stop();

Brings the device into stopped (NMT_STATE_STOPPED) state. The device must be in pre-operational or operational state.

changeState protected

void changeState(
    State newState
);

Changes the state and fires the respective events.

onFrameReceived protected

void onFrameReceived(
    const CANFrame & frame
);

Handles a NMT command frame (CAN-ID == 0).

sendHeartbeat protected

void sendHeartbeat();

Sends a heartbeat frame.

Variables

commandReceived

Poco::BasicEvent < const Command > commandReceived;

A command has been received from the NMT master.

The delegate should bring the device into the state dictated by command.

heartbeatReceived

Poco::BasicEvent < const Heartbeat > heartbeatReceived;

A heartbeat has been received from another node.

stateChanged

Poco::BasicEvent < const StateChange > stateChanged;

The state has been changed.

stateChanging

Poco::BasicEvent < const StateChange > stateChanging;

The state is changing. The state change can be cancelled by a delegate by throwing an exception.

Securely control IoT edge devices from anywhere   Connect a Device