CANopenNode
CANopen protocol stack
Loading...
Searching...
No Matches
CO_gateway_ascii.h
Go to the documentation of this file.
1
22#ifndef CO_GATEWAY_ASCII_H
23#define CO_GATEWAY_ASCII_H
24
25#include "301/CO_driver.h"
26#include "301/CO_fifo.h"
27#include "301/CO_SDOclient.h"
29#include "305/CO_LSSmaster.h"
30#include "303/CO_LEDs.h"
31
32/* default configuration, see CO_config.h */
33#ifndef CO_CONFIG_GTW
34#define CO_CONFIG_GTW (0)
35#endif
36
37#if (((CO_CONFIG_GTW)&CO_CONFIG_GTW_ASCII) != 0) || defined CO_DOXYGEN
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
141#ifndef CO_GTWA_RESP_BUF_SIZE
142#define CO_GTWA_RESP_BUF_SIZE 200U
143#endif
144
146#ifndef CO_GTWA_STATE_TIMEOUT_TIME_US
147#define CO_GTWA_STATE_TIMEOUT_TIME_US 1200000U
148#endif
149
154typedef enum {
184
188typedef enum {
204 CO_GTWA_ST_HELP = 0x81U,
207
208#if (((CO_CONFIG_GTW)&CO_CONFIG_GTW_ASCII_SDO) != 0) || defined CO_DOXYGEN
209/*
210 * CANopen Gateway-ascii data types structure
211 */
212typedef struct {
213 char* syntax;
214 size_t length;
218 size_t (*dataTypePrint)(CO_fifo_t* fifo, char* buf, size_t count, bool_t end);
222 size_t (*dataTypeScan)(CO_fifo_t* dest, CO_fifo_t* src, uint8_t* status);
223} CO_GTWA_dataType_t;
224#endif /* (CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_SDO */
225
229typedef struct {
240 size_t (*readCallback)(void* object, const char* buf, size_t count, uint8_t* connectionOK);
241 void* readCallbackObject;
242 uint32_t sequence;
243 int32_t net_default;
244 int16_t node_default;
246 uint8_t node;
247 CO_fifo_t commFifo;
250 char respBuf[CO_GTWA_RESP_BUF_SIZE];
251 size_t respBufCount;
252 size_t respBufOffset;
256 bool_t respHold;
257 uint32_t timeDifference_us_cumulative;
259 uint32_t stateTimeoutTmr;
260#if (((CO_CONFIG_GTW)&CO_CONFIG_GTW_ASCII_SDO) != 0) || defined CO_DOXYGEN
262 uint16_t SDOtimeoutTime;
263 bool_t SDOblockTransferEnable;
264 bool_t SDOdataCopyStatus;
267 const CO_GTWA_dataType_t* SDOdataType;
268#endif
269#if (((CO_CONFIG_GTW)&CO_CONFIG_GTW_ASCII_NMT) != 0) || defined CO_DOXYGEN
270 CO_NMT_t* NMT;
271#endif
272#if (((CO_CONFIG_GTW)&CO_CONFIG_GTW_ASCII_LSS) != 0) || defined CO_DOXYGEN
273 CO_LSSmaster_t* LSSmaster;
274 CO_LSS_address_t lssAddress;
275 uint8_t lssNID;
276 uint16_t lssBitrate;
277 uint8_t lssInquireCs;
279 uint8_t lssSubState;
280 uint8_t lssNodeCount;
281 bool_t lssStore;
282 uint16_t lssTimeout_ms;
283#endif
284#if (((CO_CONFIG_GTW)&CO_CONFIG_GTW_ASCII_LOG) != 0) || defined CO_DOXYGEN
287 CO_fifo_t logFifo;
288#endif
289#if (((CO_CONFIG_GTW)&CO_CONFIG_GTW_ASCII_PRINT_HELP) != 0) || defined CO_DOXYGEN
290 const char* helpString;
291 size_t helpStringOffset;
292#endif
293#if (((CO_CONFIG_GTW)&CO_CONFIG_GTW_ASCII_PRINT_LEDS) != 0) || defined CO_DOXYGEN
294 CO_LEDs_t* LEDs;
295 uint8_t ledStringPreviousIndex;
296#endif
297} CO_GTWA_t;
298
314#if (((CO_CONFIG_GTW)&CO_CONFIG_GTW_ASCII_SDO) != 0) || defined CO_DOXYGEN
315 CO_SDOclient_t* SDO_C, uint16_t SDOclientTimeoutTime_ms, bool_t SDOclientBlockTransfer,
316#endif
317#if (((CO_CONFIG_GTW)&CO_CONFIG_GTW_ASCII_NMT) != 0) || defined CO_DOXYGEN
318 CO_NMT_t* NMT,
319#endif
320#if (((CO_CONFIG_GTW)&CO_CONFIG_GTW_ASCII_LSS) != 0) || defined CO_DOXYGEN
321 CO_LSSmaster_t* LSSmaster,
322#endif
323#if (((CO_CONFIG_GTW)&CO_CONFIG_GTW_ASCII_PRINT_LEDS) != 0) || defined CO_DOXYGEN
324 CO_LEDs_t* LEDs,
325#endif
326 uint8_t dummy);
327
340void CO_GTWA_initRead(CO_GTWA_t* gtwa,
341 size_t (*readCallback)(void* object, const char* buf, size_t count, uint8_t* connectionOK),
342 void* readCallbackObject);
343
351static inline size_t
353 return CO_fifo_getSpace(&gtwa->commFifo);
354}
355
369static inline size_t
370CO_GTWA_write(CO_GTWA_t* gtwa, const char* buf, size_t count) {
371 return CO_fifo_write(&gtwa->commFifo, (const uint8_t*)buf, count, NULL);
372}
373
374#if (((CO_CONFIG_GTW)&CO_CONFIG_GTW_ASCII_LOG) != 0) || defined CO_DOXYGEN
385void CO_GTWA_log_print(CO_GTWA_t* gtwa, const char* message);
386#endif /* (CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_LOG */
387
399void CO_GTWA_process(CO_GTWA_t* gtwa, bool_t enable, uint32_t timeDifference_us, uint32_t* timerNext_us);
400
401 /* CO_CANopen_309_3 */
402
403#ifdef __cplusplus
404}
405#endif /* __cplusplus */
406
407#endif /* (CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII */
408
409#endif /* CO_GATEWAY_ASCII_H */
CANopen Indicator specification (CiA 303-3 v1.4.0)
CANopen Layer Setting Service - master protocol.
CANopen Network management and Heartbeat producer protocol.
CANopen Service Data Object - client protocol.
Interface between CAN hardware and CANopenNode.
FIFO circular buffer.
static size_t CO_fifo_getSpace(CO_fifo_t *fifo)
Get free buffer space in CO_fifo_t object.
Definition CO_fifo.h:123
size_t CO_fifo_write(CO_fifo_t *fifo, const uint8_t *buf, size_t count, uint16_t *crc)
Write data into CO_fifo_t object.
void CO_GTWA_log_print(CO_GTWA_t *gtwa, const char *message)
Print message log string into fifo buffer.
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.
void CO_GTWA_process(CO_GTWA_t *gtwa, bool_t enable, uint32_t timeDifference_us, uint32_t *timerNext_us)
Process Gateway-ascii object.
#define CO_GTWA_RESP_BUF_SIZE
Size of response string buffer.
Definition CO_gateway_ascii.h:141
CO_GTWA_respErrorCode_t
Response error codes as specified by CiA 309-3.
Definition CO_gateway_ascii.h:153
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:369
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.
static size_t CO_GTWA_write_getSpace(CO_GTWA_t *gtwa)
Get free write buffer space.
Definition CO_gateway_ascii.h:351
CO_GTWA_state_t
Internal states of the Gateway-ascii state machine.
Definition CO_gateway_ascii.h:187
@ CO_GTWA_respErrorReqNotSupported
100 - Request not supported
Definition CO_gateway_ascii.h:155
@ CO_GTWA_respErrorCANactive
305 - CAN active (at init or start-up)
Definition CO_gateway_ascii.h:173
@ CO_GTWA_respErrorLostGuardingMessage
200 - Lost guarding message
Definition CO_gateway_ascii.h:163
@ CO_GTWA_respErrorInternalState
102 - Request not processed due to internal state
Definition CO_gateway_ascii.h:157
@ CO_GTWA_respErrorUnsupportedNet
106 - Unsupported net
Definition CO_gateway_ascii.h:161
@ CO_GTWA_respErrorLSSparameterStoringFailed
504 - LSS parameter storing failed
Definition CO_gateway_ascii.h:179
@ CO_GTWA_respErrorNone
0 - No error or idle
Definition CO_gateway_ascii.h:154
@ CO_GTWA_respErrorSyntax
101 - Syntax error
Definition CO_gateway_ascii.h:156
@ CO_GTWA_respErrorLSSnodeIdNotSupported
502 - LSS node-ID not supported
Definition CO_gateway_ascii.h:177
@ CO_GTWA_respErrorErrorPassive
300 - Error passive
Definition CO_gateway_ascii.h:169
@ CO_GTWA_respErrorLSSmanufacturer
501 - LSS implementation- / manufacturer-specific error
Definition CO_gateway_ascii.h:176
@ CO_GTWA_respErrorTimeOut
103 - Time-out (where applicable)
Definition CO_gateway_ascii.h:158
@ CO_GTWA_respErrorCANbufferOverflow
303 - CAN buffer overflow
Definition CO_gateway_ascii.h:171
@ CO_GTWA_respErrorCANinit
304 - CAN init
Definition CO_gateway_ascii.h:172
@ CO_GTWA_respErrorRunningOutOfMemory
600 - Running out of memory
Definition CO_gateway_ascii.h:181
@ CO_GTWA_respErrorLostConnection
201 - Lost connection
Definition CO_gateway_ascii.h:164
@ CO_GTWA_respErrorBootUp
205 - Boot-up
Definition CO_gateway_ascii.h:168
@ CO_GTWA_respErrorHeartbeatLost
203 - Heartbeat lost
Definition CO_gateway_ascii.h:166
@ CO_GTWA_respErrorBusOff
301 - Bus off
Definition CO_gateway_ascii.h:170
@ CO_GTWA_respErrorNoDefaultNodeSet
105 - No default node set
Definition CO_gateway_ascii.h:160
@ CO_GTWA_respErrorLSSmediaError
505 - LSS command failed because of media error
Definition CO_gateway_ascii.h:180
@ CO_GTWA_respErrorPDOalreadyUsed
400 - PDO already used
Definition CO_gateway_ascii.h:174
@ CO_GTWA_respErrorWrongNMTstate
204 - Wrong NMT state
Definition CO_gateway_ascii.h:167
@ CO_GTWA_respErrorNoDefaultNetSet
104 - No default net set
Definition CO_gateway_ascii.h:159
@ CO_GTWA_respErrorLSSbitRateNotSupported
503 - LSS bit-rate not supported
Definition CO_gateway_ascii.h:178
@ CO_GTWA_respErrorPDOlengthExceeded
401 - PDO length exceeded
Definition CO_gateway_ascii.h:175
@ CO_GTWA_respErrorHeartbeatStarted
202 - Heartbeat started
Definition CO_gateway_ascii.h:165
@ CO_GTWA_respErrorUnsupportedNode
107 - Unsupported node
Definition CO_gateway_ascii.h:162
@ CO_GTWA_ST_LSS_INQUIRE_ADDR_ALL
LSS 'lss_inquire_addr', all parameters.
Definition CO_gateway_ascii.h:199
@ CO_GTWA_ST_LSS_SWITCH_SEL
LSS 'lss_switch_sel'.
Definition CO_gateway_ascii.h:194
@ CO_GTWA_ST_LED
print 'status' of the node
Definition CO_gateway_ascii.h:204
@ CO_GTWA_ST_LSS_ALLNODES
LSS 'lss_allnodes'.
Definition CO_gateway_ascii.h:201
@ CO_GTWA_ST_LSS_STORE
LSS 'lss_store'.
Definition CO_gateway_ascii.h:197
@ CO_GTWA_ST_LSS_CONF_BITRATE
LSS 'lss_conf_bitrate'.
Definition CO_gateway_ascii.h:196
@ CO_GTWA_ST_LOG
print message 'log'
Definition CO_gateway_ascii.h:202
@ CO_GTWA_ST_WRITE
SDO 'write' (download)
Definition CO_gateway_ascii.h:191
@ CO_GTWA_ST_IDLE
Gateway is idle, no command is processing.
Definition CO_gateway_ascii.h:188
@ CO_GTWA_ST_READ
SDO 'read' (upload)
Definition CO_gateway_ascii.h:190
@ CO_GTWA_ST_WRITE_ABORTED
SDO 'write' (download) - aborted, purging remaining data.
Definition CO_gateway_ascii.h:192
@ CO_GTWA_ST__LSS_FASTSCAN
LSS '_lss_fastscan'.
Definition CO_gateway_ascii.h:200
@ CO_GTWA_ST_LSS_INQUIRE
LSS 'lss_inquire_addr' or 'lss_get_node'.
Definition CO_gateway_ascii.h:198
@ CO_GTWA_ST_LSS_SET_NODE
LSS 'lss_set_node'.
Definition CO_gateway_ascii.h:195
@ CO_GTWA_ST_HELP
print 'help' text
Definition CO_gateway_ascii.h:203
@ CO_GTWA_ST_LSS_SWITCH_GLOB
LSS 'lss_switch_glob'.
Definition CO_gateway_ascii.h:193
#define CO_CONFIG_GTWA_LOG_BUF_SIZE
Size of message log buffer in ASCII gateway object.
Definition CO_config.h:683
#define CO_CONFIG_GTWA_COMM_BUF_SIZE
Size of command buffer in ASCII gateway object.
Definition CO_config.h:676
#define NULL
NULL, for general usage.
Definition CO_driver.h:123
unsigned int uint16_t
UNSIGNED16 in CANopen (0006h), 16-bit unsigned integer.
Definition CO_driver.h:132
unsigned long int uint32_t
UNSIGNED32 in CANopen (0007h), 32-bit unsigned integer.
Definition CO_driver.h:133
uint_fast8_t bool_t
Boolean data type for general use.
Definition CO_driver.h:126
signed int int16_t
INTEGER16 in CANopen (0003h), 16-bit signed integer.
Definition CO_driver.h:128
unsigned char uint8_t
UNSIGNED8 in CANopen (0005h), 8-bit unsigned integer.
Definition CO_driver.h:131
signed long int int32_t
INTEGER32 in CANopen (0004h), 32-bit signed integer.
Definition CO_driver.h:129
CO_ReturnError_t
Return values of some CANopen functions.
Definition CO_driver.h:449
CANopen Gateway-ascii object.
Definition CO_gateway_ascii.h:228
CO_fifo_t commFifo
CO_fifo_t object for command (not pointer)
Definition CO_gateway_ascii.h:246
LEDs object, initialized by CO_LEDs_init()
Definition CO_LEDs.h:90
Parameters for LSS fastscan CO_LSSmaster_IdentifyFastscan.
Definition CO_LSSmaster.h:323
LSS master object.
Definition CO_LSSmaster.h:95
NMT consumer and Heartbeat producer object.
Definition CO_NMT_Heartbeat.h:136
SDO client object.
Definition CO_SDOclient.h:151
Fifo object.
Definition CO_fifo.h:55
The LSS address is a 128 bit number, uniquely identifying each node.
Definition CO_LSS.h:150