CANopenNode
CO_gateway_ascii.h
Go to the documentation of this file.
1 
27 #ifndef CO_GATEWAY_ASCII_H
28 #define CO_GATEWAY_ASCII_H
29 
30 #include "301/CO_driver.h"
31 #include "301/CO_fifo.h"
32 #include "301/CO_SDOclient.h"
33 #include "301/CO_NMT_Heartbeat.h"
34 #include "305/CO_LSSmaster.h"
35 #include "303/CO_LEDs.h"
36 
37 /* default configuration, see CO_config.h */
38 #ifndef CO_CONFIG_GTW
39 #define CO_CONFIG_GTW (0)
40 #endif
41 
42 #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII) || defined CO_DOXYGEN
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
150 #ifndef CO_GTWA_RESP_BUF_SIZE
151 #define CO_GTWA_RESP_BUF_SIZE 200
152 #endif
153 
154 
156 #ifndef CO_GTWA_STATE_TIMEOUT_TIME_US
157 #define CO_GTWA_STATE_TIMEOUT_TIME_US 1200000
158 #endif
159 
160 
165 typedef enum {
223 
224 
228 typedef enum {
257  CO_GTWA_ST_LOG = 0x80U,
263 
264 
265 #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_SDO) || defined CO_DOXYGEN
266 /*
267  * CANopen Gateway-ascii data types structure
268  */
269 typedef struct {
271  char* syntax;
273  size_t length;
278  size_t (*dataTypePrint)(CO_fifo_t *fifo,
279  char *buf,
280  size_t count,
281  bool_t end);
286  size_t (*dataTypeScan)(CO_fifo_t *dest,
287  CO_fifo_t *src,
288  CO_fifo_st *status);
289 } CO_GTWA_dataType_t;
290 #endif /* (CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_SDO */
291 
292 
296 typedef struct {
307  size_t (*readCallback)(void *object,
308  const char *buf,
309  size_t count,
310  uint8_t *connectionOK);
327  char commBuf[CO_CONFIG_GTWA_COMM_BUF_SIZE + 1];
329  char respBuf[CO_GTWA_RESP_BUF_SIZE];
331  size_t respBufCount;
345 #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_SDO) || defined CO_DOXYGEN
346 
357  const CO_GTWA_dataType_t *SDOdataType;
358 #endif
359 #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_NMT) || defined CO_DOXYGEN
360 
362 #endif
363 #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_LSS) || defined CO_DOXYGEN
364 
384 #endif
385 #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_LOG) || defined CO_DOXYGEN
386 
387  char logBuf[CO_CONFIG_GTWA_LOG_BUF_SIZE + 1];
390 #endif
391 #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_PRINT_HELP) || defined CO_DOXYGEN
392 
393  const char *helpString;
394  size_t helpStringOffset;
395 #endif
396 #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_PRINT_LEDS) || defined CO_DOXYGEN
397 
399  uint8_t ledStringPreviousIndex;
400 #endif
401 } CO_GTWA_t;
402 
403 
419 #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_SDO) || defined CO_DOXYGEN
420  CO_SDOclient_t* SDO_C,
421  uint16_t SDOclientTimeoutTime_ms,
422  bool_t SDOclientBlockTransfer,
423 #endif
424 #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_NMT) || defined CO_DOXYGEN
425  CO_NMT_t *NMT,
426 #endif
427 #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_LSS) || defined CO_DOXYGEN
428  CO_LSSmaster_t *LSSmaster,
429 #endif
430 #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_PRINT_LEDS) || defined CO_DOXYGEN
431  CO_LEDs_t *LEDs,
432 #endif
433  uint8_t dummy);
434 
435 
450 void CO_GTWA_initRead(CO_GTWA_t* gtwa,
451  size_t (*readCallback)(void *object,
452  const char *buf,
453  size_t count,
454  uint8_t *connectionOK),
455  void *readCallbackObject);
456 
457 
465 static inline size_t CO_GTWA_write_getSpace(CO_GTWA_t* gtwa) {
466  return CO_fifo_getSpace(&gtwa->commFifo);
467 }
468 
469 
485 static inline size_t CO_GTWA_write(CO_GTWA_t* gtwa,
486  const char *buf,
487  size_t count)
488 {
489  return CO_fifo_write(&gtwa->commFifo, buf, count, NULL);
490 }
491 
492 
493 #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_LOG) || defined CO_DOXYGEN
494 
506 void CO_GTWA_log_print(CO_GTWA_t* gtwa, const char *message);
507 #endif /* (CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_LOG */
508 
509 
525 void CO_GTWA_process(CO_GTWA_t *gtwa,
526  bool_t enable,
527  uint32_t timeDifference_us,
528  uint32_t *timerNext_us);
529  /* CO_CANopen_309_3 */
531 
532 #ifdef __cplusplus
533 }
534 #endif /*__cplusplus*/
535 
536 #endif /* (CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII */
537 
538 #endif /* CO_GATEWAY_ASCII_H */
uint32_t
unsigned long int uint32_t
UNSIGNED32 in CANopen (0007h), 32-bit unsigned integer.
Definition: CO_driver.h:155
CO_GTWA_t::commFifo
CO_fifo_t commFifo
CO_fifo_t object for command (not pointer)
Definition: CO_gateway_ascii.h:325
CO_driver.h
Interface between CAN hardware and CANopenNode.
CO_GTWA_initRead
void CO_GTWA_initRead(CO_GTWA_t *gtwa, size_t(*readCallback)(void *object, const char *buf, size_t count, uint8_t *connectionOK), void *readCallbackObject)
Initialize read callback in Gateway-ascii object.
CO_GTWA_t::NMT
CO_NMT_t * NMT
NMT object from CO_GTWA_init()
Definition: CO_gateway_ascii.h:361
CO_GTWA_t::lssBitrate
uint16_t lssBitrate
LSS bitrate parameter.
Definition: CO_gateway_ascii.h:371
CO_GTWA_respErrorLSSmanufacturer
@ CO_GTWA_respErrorLSSmanufacturer
501 - LSS implementation- / manufacturer-specific error
Definition: CO_gateway_ascii.h:211
CO_LEDs_t
LEDs object, initialized by CO_LEDs_init()
Definition: CO_LEDs.h:93
CO_GTWA_t::node
uint8_t node
Current CANopen Node ID.
Definition: CO_gateway_ascii.h:323
CO_SDOclient_t
SDO client object.
Definition: CO_SDOclient.h:67
CO_GTWA_t::sequence
uint32_t sequence
Sequence number of the command.
Definition: CO_gateway_ascii.h:315
CO_GTWA_write
static size_t CO_GTWA_write(CO_GTWA_t *gtwa, const char *buf, size_t count)
Write command into CO_GTWA_t object.
Definition: CO_gateway_ascii.h:485
uint16_t
unsigned int uint16_t
UNSIGNED16 in CANopen (0006h), 16-bit unsigned integer.
Definition: CO_driver.h:153
CO_GTWA_t::lssNodeCount
uint8_t lssNodeCount
LSS allnodes node count parameter.
Definition: CO_gateway_ascii.h:379
CO_SDOclient.h
CANopen Service Data Object - client protocol.
CO_GTWA_ST_LSS_INQUIRE
@ CO_GTWA_ST_LSS_INQUIRE
LSS 'lss_inquire_addr' or 'lss_get_node'.
Definition: CO_gateway_ascii.h:249
CO_ReturnError_t
CO_ReturnError_t
Return values of some CANopen functions.
Definition: CO_driver.h:488
CO_GTWA_ST_IDLE
@ CO_GTWA_ST_IDLE
Gateway is idle, no command is processing.
Definition: CO_gateway_ascii.h:231
CO_GTWA_ST__LSS_FASTSCAN
@ CO_GTWA_ST__LSS_FASTSCAN
LSS '_lss_fastscan'.
Definition: CO_gateway_ascii.h:253
CO_GTWA_t::helpString
const char * helpString
Offset, when printing help text.
Definition: CO_gateway_ascii.h:393
bool_t
unsigned char bool_t
Boolean data type for general use.
Definition: CO_driver.h:141
CO_GTWA_t::lssSubState
uint8_t lssSubState
LSS allnodes sub state parameter.
Definition: CO_gateway_ascii.h:377
CO_GTWA_t::lssInquireCs
CO_LSS_cs_t lssInquireCs
LSS inquire parameter.
Definition: CO_gateway_ascii.h:373
CO_LSS_cs_t
CO_LSS_cs_t
LSS protocol command specifiers.
Definition: CO_LSS.h:86
CO_LSSmaster.h
CANopen Layer Setting Service - master protocol.
CO_GTWA_t::lssFastscan
CO_LSSmaster_fastscan_t lssFastscan
LSS fastscan parameter.
Definition: CO_gateway_ascii.h:375
int32_t
signed long int int32_t
INTEGER32 in CANopen (0004h), 32-bit signed integer.
Definition: CO_driver.h:147
CO_GTWA_t::respHold
bool_t respHold
See respBufOffset above.
Definition: CO_gateway_ascii.h:338
CO_GTWA_ST_WRITE
@ CO_GTWA_ST_WRITE
SDO 'write' (download)
Definition: CO_gateway_ascii.h:235
CO_GTWA_respErrorHeartbeatStarted
@ CO_GTWA_respErrorHeartbeatStarted
202 - Heartbeat started
Definition: CO_gateway_ascii.h:189
CO_GTWA_respErrorPDOlengthExceeded
@ CO_GTWA_respErrorPDOlengthExceeded
401 - PDO length exceeded
Definition: CO_gateway_ascii.h:209
CO_GTWA_t::readCallbackObject
void * readCallbackObject
Pointer to object, which will be used inside readCallback, from CO_GTWA_init()
Definition: CO_gateway_ascii.h:313
CO_GTWA_t::lssAddress
CO_LSS_address_t lssAddress
128 bit number, uniquely identifying each node
Definition: CO_gateway_ascii.h:367
CO_GTWA_respErrorBusOff
@ CO_GTWA_respErrorBusOff
301 - Bus off
Definition: CO_gateway_ascii.h:199
CO_NMT_t
NMT consumer and Heartbeat producer object.
Definition: CO_NMT_Heartbeat.h:162
CO_GTWA_respErrorLSSnodeIdNotSupported
@ CO_GTWA_respErrorLSSnodeIdNotSupported
502 - LSS node-ID not supported
Definition: CO_gateway_ascii.h:213
CO_GTWA_t::lssStore
bool_t lssStore
LSS allnodes store parameter.
Definition: CO_gateway_ascii.h:381
CO_GTWA_ST_LSS_CONF_BITRATE
@ CO_GTWA_ST_LSS_CONF_BITRATE
LSS 'lss_conf_bitrate'.
Definition: CO_gateway_ascii.h:245
CO_GTWA_write_getSpace
static size_t CO_GTWA_write_getSpace(CO_GTWA_t *gtwa)
Get free write buffer space.
Definition: CO_gateway_ascii.h:465
CO_GTWA_t::LEDs
CO_LEDs_t * LEDs
CO_LEDs_t object for CANopen status LEDs imitation from CO_GTWA_init()
Definition: CO_gateway_ascii.h:398
CO_GTWA_respErrorLostGuardingMessage
@ CO_GTWA_respErrorLostGuardingMessage
200 - Lost guarding message
Definition: CO_gateway_ascii.h:185
CO_GTWA_RESP_BUF_SIZE
#define CO_GTWA_RESP_BUF_SIZE
Size of response string buffer.
Definition: CO_gateway_ascii.h:151
CO_GTWA_t::SDO_C
CO_SDOclient_t * SDO_C
SDO client object from CO_GTWA_init()
Definition: CO_gateway_ascii.h:347
CO_GTWA_respErrorLSSmediaError
@ CO_GTWA_respErrorLSSmediaError
505 - LSS command failed because of media error
Definition: CO_gateway_ascii.h:219
CO_GTWA_respErrorWrongNMTstate
@ CO_GTWA_respErrorWrongNMTstate
204 - Wrong NMT state
Definition: CO_gateway_ascii.h:193
CO_GTWA_t::net
uint16_t net
Current CANopen Net number.
Definition: CO_gateway_ascii.h:321
CO_GTWA_respErrorLostConnection
@ CO_GTWA_respErrorLostConnection
201 - Lost connection
Definition: CO_gateway_ascii.h:187
CO_CONFIG_GTW
#define CO_CONFIG_GTW
Configuration of Gateway ASCII mapping.
Definition: CO_config.h:595
CO_GTWA_t::LSSmaster
CO_LSSmaster_t * LSSmaster
LSSmaster object from CO_GTWA_init()
Definition: CO_gateway_ascii.h:365
CO_GTWA_t::lssNID
uint8_t lssNID
LSS Node-ID parameter.
Definition: CO_gateway_ascii.h:369
CO_GTWA_state_t
CO_GTWA_state_t
Internal states of the Gateway-ascii state machine.
Definition: CO_gateway_ascii.h:228
CO_GTWA_init
CO_ReturnError_t CO_GTWA_init(CO_GTWA_t *gtwa, CO_SDOclient_t *SDO_C, uint16_t SDOclientTimeoutTime_ms, bool_t SDOclientBlockTransfer, CO_NMT_t *NMT, CO_LSSmaster_t *LSSmaster, CO_LEDs_t *LEDs, uint8_t dummy)
Initialize Gateway-ascii object.
CO_GTWA_respErrorNoDefaultNodeSet
@ CO_GTWA_respErrorNoDefaultNodeSet
105 - No default node set
Definition: CO_gateway_ascii.h:179
CO_GTWA_t::lssTimeout_ms
uint16_t lssTimeout_ms
LSS allnodes timeout parameter.
Definition: CO_gateway_ascii.h:383
CO_GTWA_respErrorCANinit
@ CO_GTWA_respErrorCANinit
304 - CAN init
Definition: CO_gateway_ascii.h:203
CO_GTWA_t::SDOdataType
const CO_GTWA_dataType_t * SDOdataType
Data type of variable in current SDO communication.
Definition: CO_gateway_ascii.h:357
CO_GTWA_respErrorSyntax
@ CO_GTWA_respErrorSyntax
101 - Syntax error
Definition: CO_gateway_ascii.h:171
CO_fifo_st
CO_fifo_st
Bitfields for status argument from CO_fifo_cpyTok2U8 function and similar.
Definition: CO_fifo.h:472
CO_LSSmaster_fastscan_t
Parameters for LSS fastscan CO_LSSmaster_IdentifyFastscan.
Definition: CO_LSSmaster.h:407
CO_LSSmaster_t
LSS master object.
Definition: CO_LSSmaster.h:108
CO_GTWA_respErrorNone
@ CO_GTWA_respErrorNone
0 - No error or idle
Definition: CO_gateway_ascii.h:167
CO_GTWA_t::SDOtimeoutTime
uint16_t SDOtimeoutTime
Timeout time for SDO transfer in milliseconds, if no response.
Definition: CO_gateway_ascii.h:349
CO_GTWA_respErrorTimeOut
@ CO_GTWA_respErrorTimeOut
103 - Time-out (where applicable)
Definition: CO_gateway_ascii.h:175
CO_GTWA_respErrorLSSparameterStoringFailed
@ CO_GTWA_respErrorLSSparameterStoringFailed
504 - LSS parameter storing failed
Definition: CO_gateway_ascii.h:217
CO_fifo_t
Fifo object.
Definition: CO_fifo.h:60
CO_GTWA_respErrorErrorPassive
@ CO_GTWA_respErrorErrorPassive
300 - Error passive
Definition: CO_gateway_ascii.h:197
CO_GTWA_ST_LSS_SWITCH_GLOB
@ CO_GTWA_ST_LSS_SWITCH_GLOB
LSS 'lss_switch_glob'.
Definition: CO_gateway_ascii.h:239
CO_GTWA_ST_LSS_STORE
@ CO_GTWA_ST_LSS_STORE
LSS 'lss_store'.
Definition: CO_gateway_ascii.h:247
CO_GTWA_t::node_default
int16_t node_default
Default CANopen Node ID number is undefined (-1) at startup.
Definition: CO_gateway_ascii.h:319
CO_GTWA_ST_LSS_INQUIRE_ADDR_ALL
@ CO_GTWA_ST_LSS_INQUIRE_ADDR_ALL
LSS 'lss_inquire_addr', all parameters.
Definition: CO_gateway_ascii.h:251
CO_GTWA_respErrorUnsupportedNet
@ CO_GTWA_respErrorUnsupportedNet
106 - Unsupported net
Definition: CO_gateway_ascii.h:181
CO_NMT_Heartbeat.h
CANopen Network management and Heartbeat producer protocol.
CO_fifo_write
size_t CO_fifo_write(CO_fifo_t *fifo, const char *buf, size_t count, uint16_t *crc)
Write data into CO_fifo_t object.
int16_t
signed int int16_t
INTEGER16 in CANopen (0003h), 16-bit signed integer.
Definition: CO_driver.h:145
CO_GTWA_process
void CO_GTWA_process(CO_GTWA_t *gtwa, bool_t enable, uint32_t timeDifference_us, uint32_t *timerNext_us)
Process Gateway-ascii object.
CO_GTWA_ST_LED
@ CO_GTWA_ST_LED
print 'status' of the node
Definition: CO_gateway_ascii.h:261
CO_GTWA_respErrorUnsupportedNode
@ CO_GTWA_respErrorUnsupportedNode
107 - Unsupported node
Definition: CO_gateway_ascii.h:183
CO_GTWA_t::stateTimeoutTmr
uint32_t stateTimeoutTmr
Timeout timer for the current state.
Definition: CO_gateway_ascii.h:344
CO_GTWA_respErrorCode_t
CO_GTWA_respErrorCode_t
Response error codes as specified by CiA 309-3.
Definition: CO_gateway_ascii.h:165
CO_GTWA_respErrorReqNotSupported
@ CO_GTWA_respErrorReqNotSupported
100 - Request not supported
Definition: CO_gateway_ascii.h:169
CO_GTWA_respErrorPDOalreadyUsed
@ CO_GTWA_respErrorPDOalreadyUsed
400 - PDO already used
Definition: CO_gateway_ascii.h:207
CO_GTWA_respErrorCANactive
@ CO_GTWA_respErrorCANactive
305 - CAN active (at init or start-up)
Definition: CO_gateway_ascii.h:205
CO_GTWA_respErrorInternalState
@ CO_GTWA_respErrorInternalState
102 - Request not processed due to internal state
Definition: CO_gateway_ascii.h:173
NULL
#define NULL
NULL, for general usage.
Definition: CO_driver.h:135
CO_GTWA_ST_LOG
@ CO_GTWA_ST_LOG
print message 'log'
Definition: CO_gateway_ascii.h:257
CO_CONFIG_GTWA_LOG_BUF_SIZE
#define CO_CONFIG_GTWA_LOG_BUF_SIZE
Size of message log buffer in ASCII gateway object.
Definition: CO_config.h:632
CO_CONFIG_GTWA_COMM_BUF_SIZE
#define CO_CONFIG_GTWA_COMM_BUF_SIZE
Size of command buffer in ASCII gateway object.
Definition: CO_config.h:625
CO_GTWA_ST_WRITE_ABORTED
@ CO_GTWA_ST_WRITE_ABORTED
SDO 'write' (download) - aborted, purging remaining data.
Definition: CO_gateway_ascii.h:237
CO_GTWA_respErrorNoDefaultNetSet
@ CO_GTWA_respErrorNoDefaultNetSet
104 - No default net set
Definition: CO_gateway_ascii.h:177
CO_GTWA_t::respBufOffset
size_t respBufOffset
If only part of data has been successfully written into external application (with readCallback()),...
Definition: CO_gateway_ascii.h:336
CO_GTWA_t::logFifo
CO_fifo_t logFifo
CO_fifo_t object for message log (not pointer)
Definition: CO_gateway_ascii.h:389
CO_GTWA_ST_LSS_SWITCH_SEL
@ CO_GTWA_ST_LSS_SWITCH_SEL
LSS 'lss_switch_sel'.
Definition: CO_gateway_ascii.h:241
CO_fifo.h
FIFO circular buffer.
CO_GTWA_respErrorRunningOutOfMemory
@ CO_GTWA_respErrorRunningOutOfMemory
600 - Running out of memory
Definition: CO_gateway_ascii.h:221
CO_LEDs.h
CANopen Indicator specification (CiA 303-3 v1.4.0)
CO_GTWA_ST_LSS_ALLNODES
@ CO_GTWA_ST_LSS_ALLNODES
LSS 'lss_allnodes'.
Definition: CO_gateway_ascii.h:255
CO_GTWA_t::net_default
int32_t net_default
Default CANopen Net number is undefined (-1) at startup.
Definition: CO_gateway_ascii.h:317
CO_GTWA_t::SDOdataCopyStatus
bool_t SDOdataCopyStatus
Indicate status of data copy from / to SDO buffer.
Definition: CO_gateway_ascii.h:355
CO_GTWA_t::SDOblockTransferEnable
bool_t SDOblockTransferEnable
SDO block transfer enabled?
Definition: CO_gateway_ascii.h:351
CO_GTWA_t::state
CO_GTWA_state_t state
Current state of the gateway object.
Definition: CO_gateway_ascii.h:342
CO_LSS_address_t
The LSS address is a 128 bit number, uniquely identifying each node.
Definition: CO_LSS.h:162
CO_GTWA_respErrorCANbufferOverflow
@ CO_GTWA_respErrorCANbufferOverflow
303 - CAN buffer overflow
Definition: CO_gateway_ascii.h:201
CO_GTWA_t::timeDifference_us_cumulative
uint32_t timeDifference_us_cumulative
Sum of time difference from CO_GTWA_process() in case of respHold.
Definition: CO_gateway_ascii.h:340
CO_GTWA_ST_READ
@ CO_GTWA_ST_READ
SDO 'read' (upload)
Definition: CO_gateway_ascii.h:233
CO_GTWA_respErrorHeartbeatLost
@ CO_GTWA_respErrorHeartbeatLost
203 - Heartbeat lost
Definition: CO_gateway_ascii.h:191
CO_GTWA_log_print
void CO_GTWA_log_print(CO_GTWA_t *gtwa, const char *message)
Print message log string into fifo buffer.
CO_GTWA_ST_HELP
@ CO_GTWA_ST_HELP
print 'help' text
Definition: CO_gateway_ascii.h:259
CO_fifo_getSpace
static size_t CO_fifo_getSpace(CO_fifo_t *fifo)
Get free buffer space in CO_fifo_t object.
Definition: CO_fifo.h:138
CO_GTWA_t
CANopen Gateway-ascii object.
Definition: CO_gateway_ascii.h:296
uint8_t
unsigned char uint8_t
UNSIGNED8 in CANopen (0005h), 8-bit unsigned integer.
Definition: CO_driver.h:151
CO_GTWA_ST_LSS_SET_NODE
@ CO_GTWA_ST_LSS_SET_NODE
LSS 'lss_set_node'.
Definition: CO_gateway_ascii.h:243
CO_GTWA_t::respBufCount
size_t respBufCount
Actual size of data in respBuf.
Definition: CO_gateway_ascii.h:331
CO_GTWA_respErrorBootUp
@ CO_GTWA_respErrorBootUp
205 - Boot-up
Definition: CO_gateway_ascii.h:195
CO_GTWA_respErrorLSSbitRateNotSupported
@ CO_GTWA_respErrorLSSbitRateNotSupported
503 - LSS bit-rate not supported
Definition: CO_gateway_ascii.h:215