IoT::CANopen

class SDO

File Information

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

Description

This class implements the CANopen SDO (Service Data Object) protocol for clients and servers.

Member Summary

Member Functions: abort, allocTransferState, download, downloadSegment, findRequestTransferState, findResponseTransferState, freeTransferState, mapCOBIDs, onFrameReceived, serverDownloadInitiate, serverDownloadSegment, serverUploadInitiate, serverUploadSegment, unmapCOBIDs, upload, uploadSegment

Nested Classes

struct SDOTransfer

 

struct SDOTransferState protected

 

Types

SDOTransferStates protected

typedef std::vector < SDOTransferState > SDOTransferStates;

Enumerations

AbortCode

SDO Error and Abort Codes.

SDO_SUCCESS = 0x00000000

Special non-standard code to indicate success.

SDO_TIMEOUT = 0xFFFFFFFF

Special non-standard code to indicate timeout of a synchronous upload or download.

SDO_ABORT_TOGGLE_BIT = 0x05030000

Toggle bit not alternated.

SDO_ABORT_PROTOCOL_TIMEOUT = 0x05040000

SDO protocol timed out.

SDO_ABORT_INVALID_COMMAND = 0x05040001

Client/server command specifier not valid or unknown.

SDO_ABORT_INVALID_BLOCKSIZE = 0x05040002

Invalid block size (block mode only).

SDO_ABORT_INVALID_SEQNUM = 0x05040003

Invalid sequence number (block mode only).

SDO_ABORT_CRC_ERROR = 0x05040004

CRC error (block mode only).

SDO_ABORT_OUT_OF_MEMORY = 0x05040005

Out of memory.

SDO_ABORT_INVALID_ACCESS = 0x06010000

Unsupported access to an object.

SDO_ABORT_WRITE_ONLY = 0x06010001

Attempt to read a write only object.

SDO_ABORT_READ_ONLY = 0x06010002

Attempt to write a read only object.

SDO_ABORT_UNKNOWN_OBJECT = 0x06020000

Object does not exist in the object dictionary.

SDO_ABORT_CANNOT_MAP_PDO = 0x06040041

Object cannot be mapped to the PDO.

SDO_ABORT_PDO_LENGTH = 0x06040042

The number and length of the objects to be mapped would exceed PDO length.

SDO_ABORT_PARAMETER = 0x06040043

General parameter incompatibility reason.

SDO_ABORT_INCOMPATIBLE = 0x06040047

General internal incompatibility in the device.

SDO_ABORT_HARDWARE_FAILURE = 0x06060000

Access failed due to an hardware error.

SDO_ABORT_TYPE_MISMATCH = 0x06070010

Data type does not match, length of service parameter does not match.

SDO_ABORT_LENGTH_TOO_HIGH = 0x06070012

Data type does not match, length of service parameter too high.

SDO_ABORT_LENGTH_TOO_LOW = 0x06070013

Data type does not match, length of service parameter too low.

SDO_ABORT_SUBINDEX_RANGE = 0x06090011

Sub-index does not exist.

SDO_ABORT_INVALID_VALUE = 0x06090030

Invalid value for parameter (download only).

SDO_ABORT_VALUE_TOO_HIGH = 0x06090031

Value of parameter written too high (download only).

SDO_ABORT_VALUE_TOO_LOW = 0x06090032

Value of parameter written too low (download only).

SDO_ABORT_VALUE_RANGE = 0x06090036

Maximum value is less than minimum value.

SDO_ABORT_NOT_AVAILABLE = 0x060A0023

Resource not available: SDO connection.

SDO_ABORT_GENERAL_ERROR = 0x08000000

General error.

SDO_ABORT_TRANSFER = 0x08000020

Data cannot be transferred or stored to the application.

SDO_ABORT_TRANSFER_LOCAL = 0x08000021

Data cannot be transferred or stored to the application because of local control.

SDO_ABORT_TRANSFER_STATE = 0x08000022

Data cannot be transferred or stored to the application because of the present device state.

SDO_ABORT_NO_OBJECT_DICT = 0x08000023

Object dictionary dynamic generation fails or no object dictionary is present (e.g. object dictionary is generated from file and generation fails because of an file error).

SDO_ABORT_NO_DATA = 0x08000024

No data available.

TransferType protected

XFER_UNUSED = 0

XFER_CLIENT_UPLOAD = 1

XFER_CLIENT_DOWNLOAD = 2

XFER_SERVER_UPLOAD = 3

XFER_SERVER_DOWNLOAD = 4

Constructors

SDO

SDO(
    CANBus & canBus,
    Poco::Timespan protocolTimeout = Poco::Timespan (2, 0),
    int maxTransfers = 8
);

Creates the PDO object using the given CANBus object. The given maximum number of simultaneous SDO transfers (uploads and downloads) will be supported.

Destructor

~SDO

~SDO();

Destroys the Time object.

Member Functions

abort

void abort(
    Poco::UInt32 cobID,
    AbortCode abortCode
);

Aborts an asynchronous transfer by sending an abort message.

download

void download(
    Poco::UInt32 requestCOBID,
    Poco::UInt32 responseCOBID,
    Poco::UInt16 index,
    Poco::UInt8 subIndex,
    const std::vector < char > & data
);

Initiates an asynchronous SDO download to the server. In CANopen terms, a SDO download transfers data from the client to the server.

The SDO download is performed asynchronously. When the download has completed successfully, this is indicated by firing the downloadCompleted event. If the download has been aborted by the server, this is reported by firing the downloadAborted event.

download

AbortCode download(
    Poco::UInt32 requestCOBID,
    Poco::UInt32 responseCOBID,
    Poco::UInt16 index,
    Poco::UInt8 subIndex,
    const std::vector < char > & data,
    Poco::Timespan timeout
);

Initiates a synchronous SDO download by the server. In CANopen terms, a SDO download transfers data from the client to the server.

If the download completes successfully within the given timeout, zero (SDO_SUCCESS) is returned. If the server aborts the transfer, a non-zero abort code is returned. If no response is received within the given timeout, SDO_TIMEOUT is returned.

mapCOBIDs

void mapCOBIDs(
    Poco::UInt32 firstRequestCOBID,
    Poco::UInt32 firstResponseCOBID,
    Poco::UInt32 count = 1
);

Maps a range of request COB-IDs to response COB-IDs for incoming SDO upload or download requests.

Mapping request COB-IDs to response COB-IDs is required for servers wanting to receive serverUploadInitiated and serverDownloadInitiated events.

unmapCOBIDs

void unmapCOBIDs(
    Poco::UInt32 firstRequestCOBID,
    Poco::UInt32 count = 1
);

Unmaps a range of request COB-IDs.

upload

void upload(
    Poco::UInt32 requestCOBID,
    Poco::UInt32 responseCOBID,
    Poco::UInt16 index,
    Poco::UInt8 subIndex
);

Initiates an asynchronous SDO upload by the server. In CANopen terms, a SDO upload transfers data from the server to the client.

The SDO upload is performed asynchronously. When the upload has completed successfully, the data is reported by firing the uploadCompleted event. If the upload has been aborted by the server, this is reported by firing the uploadAborted event.

upload

AbortCode upload(
    Poco::UInt32 requestCOBID,
    Poco::UInt32 responseCOBID,
    Poco::UInt16 index,
    Poco::UInt8 subIndex,
    std::vector < char > & data,
    Poco::Timespan timeout
);

Initiates a synchronous SDO upload by the server. In CANopen terms, a SDO upload transfers data from the server to the client.

If the upload completes successfully within the given timeout, zero (SDO_SUCCESS) is returned and the received data is copied to the given vector. If the server aborts the transfer, a non-zero abort code is returned and the vector is left unchanged. If no response is received within the given timeout, SDO_TIMEOUT is returned.

abort protected

void abort(
    SDOTransferState & state
);

Aborts the given transfer, using the abortCode stored in the state.

abort protected

void abort(
    Poco::UInt32 cobID
);

Aborts the transfer identified by cobID silently, without sending an abort message.

allocTransferState protected

SDOTransferState & allocTransferState(
    Poco::UInt32 requestCOBID,
    Poco::UInt32 responseCOBID,
    Poco::UInt16 index,
    Poco::UInt8 subIndex,
    TransferType type
);

Allocates a slot in the transfer table for the given COB-ID.

Throws a TooManySDOTransfersException if no free slot is available.

downloadSegment protected

void downloadSegment(
    SDOTransferState & state,
    const CANFrame & frame
);

Transfers the next segment in a client download.

findRequestTransferState protected

SDOTransferState * findRequestTransferState(
    Poco::UInt32 requestCOBID
);

Returns the entry for the given COB-ID in the transfer table, or a null pointer of no such entry exists.

findResponseTransferState protected

SDOTransferState * findResponseTransferState(
    Poco::UInt32 responseCOBID
);

Returns the entry for the given COB-ID in the transfer table, or a null pointer of no such entry exists.

freeTransferState protected

void freeTransferState(
    Poco::UInt32 cobID
);

Frees the entry for the given COB-ID in the transfer table.

onFrameReceived protected

void onFrameReceived(
    const CANFrame & frame
);

Handles SDO frames.

serverDownloadInitiate protected

void serverDownloadInitiate(
    const CANFrame & frame,
    Poco::UInt32 responseCOBID
);

Initiates a server upload.

serverDownloadSegment protected

void serverDownloadSegment(
    SDOTransferState & state,
    const CANFrame & frame
);

Transfers the next segment in a server download.

serverUploadInitiate protected

void serverUploadInitiate(
    const CANFrame & frame,
    Poco::UInt32 responseCOBID
);

Initiates a server upload.

serverUploadSegment protected

void serverUploadSegment(
    SDOTransferState & state,
    const CANFrame & frame
);

Transfers the next segment in a server upload.

uploadSegment protected

void uploadSegment(
    SDOTransferState & state,
    const CANFrame & frame
);

Transfers the next segment in a client upload.

Variables

downloadAborted

Poco::BasicEvent < const SDOTransfer > downloadAborted;

A SDO download has been aborted by the server and the abort code is reported to the client application.

downloadCompleted

Poco::BasicEvent < const SDOTransfer > downloadCompleted;

A SDO download has been completed.

serverDownloadAborted

Poco::BasicEvent < const SDOTransfer > serverDownloadAborted;

Fired when SDO download has been aborted by the client and the abort code is reported to the server application.

serverDownloadCompleted

Poco::BasicEvent < SDOTransfer > serverDownloadCompleted;

Fired when a SDO download from the client been completed and the data is reported to the server application.

If the delegate changes the abort code to anything other than SDO_SUCCESS, an abort message will be sent to the client.

serverDownloadInitiated

Poco::BasicEvent < SDOTransfer > serverDownloadInitiated;

Fired when a SDO download has been initiated by a client. The event delegate can accept the download by leaving the abortCode in the SDOTransfer object as is, or abort the download by setting the abortCode to a non-zero value.

If the download completes successfully, the received data will be reported by firing the serverDownloadCompleted event. If the download has been aborted by the client, this will be reported by firing the serverDownloadAborted event.

serverUploadAborted

Poco::BasicEvent < const SDOTransfer > serverUploadAborted;

Fired when a SDO upload to the client has been aborted by the client and the abort code is reported to the server application.

serverUploadCompleted

Poco::BasicEvent < const SDOTransfer > serverUploadCompleted;

Fired when a SDO upload to the client has been completed.

serverUploadInitiated

Poco::BasicEvent < SDOTransfer > serverUploadInitiated;

Fired when a SDO upload has been initiated by a client. The event delegate must either copy the data into the SDOTransfer object to confirm the transfer, or set the abortCode to a non-zero value to abort the upload.

Successful completion of the upload will be indicated by firing the serverUploadCompleted event. If the client aborts the upload, the serverUploadAborted event will be fired.

uploadAborted

Poco::BasicEvent < const SDOTransfer > uploadAborted;

A SDO upload has been aborted by the server and the abort code is reported to the client application.

uploadCompleted

Poco::BasicEvent < const SDOTransfer > uploadCompleted;

A SDO upload has been completed and the data is reported to the client application.

Securely control IoT edge devices from anywhere   Connect a Device