📄 objdict.h
字号:
/***************************************************************************
objdict.h - description
-------------------
begin : Fri May 17 2002
copyright : (C) 2002 by Raphael Zulliger
email : zulli@hsr.ch
***************************************************************************/
/***************************************************************************
* *
* This library is Copyright (c) by Raphael Zulliger <zulli@gmx.net>. *
* It is licensed under the GNU Library General Public License (LGPL). *
* *
***************************************************************************/
/** \file
* \brief Instanciates all needed variables and defining the needed defines
* for the object dictionary.
*
* In this file you'll find some definitions, variables, ... which are
* needed to create/accessing the object dictionary.
* For creating your own CANopen SlaveLib, you have to adapt several
* variables and defines here.
* \warning Only the basic entries of an object dictionary are included
* at the moment.
*/
#ifndef __objdict_h__
#define __objdict_h__
#include <def.h>
/** This macro helps creating the object dictionary entries. by calling this macro
* it creates an entry in form of: 7 of entries, pointer to the entry. This
* macro was sponsered by Edouard Tisserant: thanks!
*/
#define DeclareIndexTableEntry(entryname) { (subindex*)entryname,sizeof(entryname)/sizeof(entryname[0])}
/** this are static defined datatypes taken fCODE the canopen standard. They
* are located at index 0x0001 to 0x001B. As described in the standard, they
* are in the object dictionary for definition purpose only. a device does not
* to support all of this datatypes.
*/
#define boolean 0x01
#define int8 0x02
#define int16 0x03
#define int32 0x04
#define uint8 0x05
#define uint16 0x06
#define uint32 0x07
#define real32 0x08
#define visible_string 0x09
#define octet_string 0x0A
#define unicode_string 0x0B
#define time_of_day 0x0C
#define time_difference 0x0D
#define domain 0x0F
#define int24 0x10
#define real64 0x11
#define int40 0x12
#define int48 0x13
#define int56 0x14
#define int64 0x15
#define uint24 0x16
#define uint40 0x18
#define uint48 0x19
#define uint56 0x1A
#define uint64 0x1B
#define pdo_communication_parameter 0x20
#define pdo_mapping 0x21
#define sdo_parameter 0x22
#define identity 0x23
/** real used datatypes for different object dictionary things. I know,
* some of this definitions are done in def.h, but i thought it would be
* useful if the datatype names (e.g. UNSIGNED8) has the same names as
* mentioned in the CANopen standard. so instead of using BYTE, you can
* use UNSIGNED8, although both are 'unsigned char'... maybe this should
* be changed...
*/
#define INTEGER8
#define INTEGER16
#define INTEGER32
#define UNSIGNED8 unsigned char
#define UNSIGNED16 unsigned short
#define UNSIGNED32 unsigned long
#define REAL32
#define VISIBLE_STRING
#define OCTET_STRING
#define UNICODE_STRING
#define TIME_OF_DAY
#define TIME_DIFFERENCE
#define INTEGER24
#define REAL64
#define INTEGER40
#define INTEGER48
#define INTEGER56
#define INTEGER64
#define UNSIGNED24
#define UNSIGNED40
#define UNSINGED48
#define UNSINGED56
#define UNSIGNED64
/** Below follows some more datatypes (complex ones) defined by the CANopen
* standard.
*/
/** This is the datatype for the communication parameter of PDOs defined
* by the CANopen standard
*/
typedef struct td_s_pdo_communication_parameter // Index: 0x20
{
/** number of supported entries
*/
UNSIGNED8 count;
/** COB-ID
*/
UNSIGNED32 cob_id;
/** transmission type: only type 255 (0xFF) supported yet
*/
UNSIGNED8 type;
/** inhibit time: not supported yet.
*/
UNSIGNED16 inhibit_time;
/** reserved (by CANopen standard)
*/
UNSIGNED8 reserved;
/** event timer: not supported yet.
*/
UNSIGNED16 event_timer;
} s_pdo_communication_parameter;
/** adjust this value, if you need more or less PDO mapping entries. (up to 64 are possible)
*/
#define COUNT_OF_PDO_MAPPING_PARAMETER 4
/** Struct needed for setting up PDO mapping parameter. Defined by the
* CANopen standard
*/
typedef struct td_s_pdo_mapping_parameter // Index: 0x21
{
/** count of mapping entries
*/
UNSIGNED8 count;
/** mapping entries itself.
*/
UNSIGNED32 object[COUNT_OF_PDO_MAPPING_PARAMETER];
} s_pdo_mapping_parameter;
/** Struct needed for SDO parameter. Defined by the CANopen standard
*/
typedef struct td_s_sdo_parameter // Index: 0x22
{
/** number of supported entries
*/
UNSIGNED8 count;
/** COB-ID client->server
*/
UNSIGNED32 cob_id_client;
/** COB-ID server->client
*/
UNSIGNED32 cob_id_server;
/** node ID of SDO's client resp. server
*/
UNSIGNED8 node_id;
} s_sdo_parameter;
/** Struct needed for the idendity of a CANopen device. Defined
* by the CANopen standard
*/
typedef struct td_s_identity // Index: 0x23
{
/** number of supported entries
*/
UNSIGNED8 count;
/** Vendor-ID (given by the CAN-CIA)
*/
UNSIGNED32 vendor_id;
/** Product code
*/
UNSIGNED32 product_code;
/** Revision number
*/
UNSIGNED32 revision_number;
/** Serial number of this device
*/
UNSIGNED32 serial_number;
} s_identity;
/** Each entry of the object dictionary can be READONLY (RO), READ/WRITE (RW),
* WRITE-ONLY (WO), OR CONSTANT (CONST)
* At the moment SDO-Transfer is not implemented, and therefore the functions
* which accesses the object dictionary do not care about this acces-types.
* Of course this is topic to change!
*/
enum e_accessAttribute { RW, WO, RO, CONST };
/** Each entry of the object dictionary can be a different object. this objects
* are defined by the CANopen standard. see standard for more information.
* At the moment the object dictionary does not really care about this
* different types. this is topic to change!
*/
enum objectDefinition { DOMAIN=2, DEFTYPE=5, DEFSTRUCT=6, VAR=7, ARRAY=8, RECORD=9 };
/** This are some structs which are neccessary for creating the entries
* of the object dictionary.
*/
typedef struct td_subindex
{
enum e_accessAttribute bAccessType; // Access type (RO, RW, ...)
BYTE bDataType; // Defines of what datatype the entry is
DWORD size; // The size (in Byte) of the variable
void* pObject; // This is the pointer of the Variable
} subindex;
/** Struct for creating entries in the communictaion profile
*/
typedef struct td_indextable
{
subindex* pSubindex; // Pointer to the subindex
UNSIGNED8 bSubCount; // the count of valid entries in for this subindex
// note: this count can differ fCODE the count defined
// in some object dictionary entries (in subindex 0).
// this count here defines how many memory has been
// allocated. this memory does not have to be used.
} indextable;
/** In order to perform lifeguarding of devices, there are two different systems:
* a device sends itself Heratbeat packages in predefined time-spaces (e.g. every
* 10 seconds) or the other possibility is, that a node (e.g. the master) "asks"
* each client about the state of the node (this is called node guarding).
* Of course also a client can be a heartbeat-consumer (this means it consumes
* the heartbeats of a device (e.g. it checks, wheter the master is still
* alive or not). The definition below tells the object dictionary how many
* heartbeats this node does consumes
*/
#define COUNT_OF_HEARTBEAT_CONSUMER 1
/*************************************************************************
* This is the part of the object directory which contains the
* communication profile...
*************************************************************************/
/** defines the last available entry of the communication profile
* area. Adjust this var, if you have additional enties.
*/
#define COMM_PROFILE_LAST 0x1018
/** This var holds the pointers to the entries of the communication
* profile area.
*/
extern const CODE indextable FAR CommunicationProfileArea[];
/*************************************************************************
* This is the part of the object directory which contains the
* PDO Parameters
*************************************************************************/
/** Entries for the PDO Parameters (such as transmission type,
* cob-id, inhibit time, ...
*/
extern const CODE indextable FAR receivePDOParameter[];
/** This is the last defined entry for pdo-paramters (rx).
* This means: this is the last entry for which memory
* has been allocated. Adjust this value if you need more
* or less entries.
*/
#define RECEIVE_PDO_LAST 0x1400
/** autogenerated value: indicates the count of defined PDOs
*/
#define MAX_COUNT_OF_PDO (RECEIVE_PDO_LAST - 0x13FF)
/** The transmitPDOParameter array. As the name indicates: this array
* is needed to store PDO(tx) PDO parameters
*/
extern const CODE indextable FAR transmitPDOParameter[];
/** This is the last defined entry for pdo-paramters (tx).
* This means: this is the last entry for which memory
* has been allocated. Adjust this value if you need more
* or less entries.
*/
#define TRANSMIT_PDO_LAST 0x1800
/*************************************************************************
* This is the part of the object directory which contains the
* PDO Mapping parameters
*************************************************************************/
/** Each pdo can map up to 64 vars (8 vars per 8bit, and 8 * 1Byte = 64 possibilities
* "normally" i think you need a maximum of 8 time 1 Byte, so 8 mapping entries
* should be sufficient. note: for each PDO a PDO-mapping is mandatory!
*/
#define MAPPING_PARAMETER_COUNT 8
/** This variable indexes all entries neccessary for pdo-mapping for
* receiving PDOs
*/
extern const CODE indextable FAR RxPDOMappingTable[ ];
/** This is the last PDO-Mapping parameter (rx) for which memory
* has been allocated
*/
#define RECEIVE_PDO_MAPPING_LAST 0x1600
/** This variable indexes all entries neccessary for pdo-mapping for
* transmitting PDOs
*/
extern const CODE indextable FAR TxPDOMappingTable[ ];
/** This is the last PDO-Mapping parameter (tx) for which memory
* has been allocated
*/
#define TRANSMIT_PDO_MAPPING_LAST 0x1A00
/*************************************************************************
* DS-401: digital&analog input/output device
*************************************************************************/
/** This variable indexes all entries which are responsible for digital
* inputs. (input means: a value which is captured by this node and sent to another node
* e.g. the state of a port is sent to the server )
*/
extern const CODE indextable FAR digitalInputTable[];
/** The count of digital inputs for which memory has been allocated
*/
#define COUNT_OF_DIGITAL_INPUT 3
/** This variable indexes all entries which are responsible for digital
* outputs.
*/
extern const CODE indextable FAR digitalOutputTable[];
/** The count of digital outputs for which memory has been allocated
*/
#define COUNT_OF_DIGITAL_OUTPUT 1
#endif // __objdict_h__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -