CO_gateway_ascii.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. /**
  2. * CANopen access from other networks - ASCII mapping (CiA 309-3 DS v3.0.0)
  3. *
  4. * @file CO_gateway_ascii.h
  5. * @ingroup CO_CANopen_309_3
  6. * @author Janez Paternoster
  7. * @author Martin Wagner
  8. * @copyright 2020 Janez Paternoster
  9. *
  10. * This file is part of CANopenNode, an opensource CANopen Stack.
  11. * Project home page is <https://github.com/CANopenNode/CANopenNode>.
  12. * For more information on CANopen see <http://www.can-cia.org/>.
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the "License");
  15. * you may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * http://www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. */
  26. #ifndef CO_GATEWAY_ASCII_H
  27. #define CO_GATEWAY_ASCII_H
  28. #include "301/CO_driver.h"
  29. #include "301/CO_fifo.h"
  30. #include "301/CO_SDOclient.h"
  31. #include "301/CO_NMT_Heartbeat.h"
  32. #include "305/CO_LSSmaster.h"
  33. #include "303/CO_LEDs.h"
  34. /* default configuration, see CO_config.h */
  35. #ifndef CO_CONFIG_GTW
  36. #define CO_CONFIG_GTW (0)
  37. #endif
  38. #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII) || defined CO_DOXYGEN
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /**
  43. * @defgroup CO_CANopen_309_3 Gateway ASCII mapping
  44. * @ingroup CO_CANopen_309
  45. * @{
  46. *
  47. * CANopen access from other networks - ASCII mapping (CiA 309-3 DSP v3.0.0)
  48. *
  49. * This module enables ascii command interface (CAN gateway), which can be used
  50. * for master interaction with CANopen network. Some sort of string input/output
  51. * stream can be used, for example serial port + terminal on microcontroller or
  52. * stdio in OS or sockets, etc.
  53. *
  54. * For example, one wants to read 'Heartbeat producer time' parameter (0x1017,0)
  55. * on remote node (with id=4). Parameter is 16-bit integer. He can can enter
  56. * command string: `[1] 4 read 0x1017 0 i16`. CANopenNode will use SDO client,
  57. * send request to remote node via CAN, wait for response via CAN and prints
  58. * `[1] OK` to output stream on success.
  59. *
  60. * This module is usually initialized and processed in CANopen.c file.
  61. * Application should register own callback function for reading the output
  62. * stream. Application writes new commands with CO_GTWA_write().
  63. */
  64. /**
  65. * @defgroup CO_CANopen_309_3_Syntax Command syntax
  66. * @{
  67. *
  68. * @code{.unparsed}
  69. Command strings start with '"["<sequence>"]"' followed by:
  70. [[<net>] <node>] r[ead] <index> <subindex> [<datatype>] # SDO upload.
  71. [[<net>] <node>] w[rite] <index> <subindex> <datatype> <value> # SDO download.
  72. [[<net>] <node>] start # NMT Start node.
  73. [[<net>] <node>] stop # NMT Stop node.
  74. [[<net>] <node>] preop[erational] # NMT Set node to pre-operational.
  75. [[<net>] <node>] reset node # NMT Reset node.
  76. [[<net>] <node>] reset comm[unication] # NMT Reset communication.
  77. [<net>] set network <value> # Set default net.
  78. [<net>] set node <value> # Set default node.
  79. [<net>] set sdo_timeout <value> # Configure SDO time-out.
  80. [<net>] set sdo_block <value> # Enable/disable SDO block transfer.
  81. help [datatype|lss] # Print this or datatype or lss help.
  82. led # Print status LED diodes.
  83. log # Print message log.
  84. Response:
  85. "["<sequence>"]" OK | <value> |
  86. ERROR:<SDO-abort-code> | ERROR:<internal-error-code>
  87. * Every command must be terminated with <CR><LF> ('\\r\\n'). characters. Same
  88. is response. String is not null terminated, <CR> is optional in command.
  89. * Comments started with '#' are ignored. They may be on the beginning of the
  90. line or after the command string.
  91. * 'sdo_timeout' is in milliseconds, 500 by default. Block transfer is
  92. disabled by default.
  93. * If '<net>' or '<node>' is not specified within commands, then value defined
  94. by 'set network' or 'set node' command is used.
  95. Datatypes:
  96. b # Boolean.
  97. i8, i16, i32, i64 # Signed integers.
  98. u8, u16, u32, u64 # Unsigned integers.
  99. x8, x16, x32, x64 # Unsigned integers, displayed as hexadecimal, non-standard.
  100. r32, r64 # Real numbers.
  101. t, td # Time of day, time difference.
  102. vs # Visible string (between double quotes if multi-word).
  103. os, us # Octet, unicode string, (mime-base64 (RFC2045) based, line).
  104. d # domain (mime-base64 (RFC2045) based, one line).
  105. hex # Hexagonal data, optionally space separated, non-standard.
  106. LSS commands:
  107. lss_switch_glob <0|1> # Switch state global command.
  108. lss_switch_sel <vendorID> <product code> \\
  109. <revisionNo> <serialNo> #Switch state selective.
  110. lss_set_node <node> # Configure node-ID.
  111. lss_conf_bitrate <table_selector=0> \\
  112. <table_index> # Configure bit-rate.
  113. lss_activate_bitrate <switch_delay_ms> # Activate new bit-rate.
  114. lss_store # LSS store configuration.
  115. lss_inquire_addr [<LSSSUB=0..3>] # Inquire LSS address.
  116. lss_get_node # Inquire node-ID.
  117. _lss_fastscan [<timeout_ms>] # Identify fastscan, non-standard.
  118. lss_allnodes [<timeout_ms> [<nodeStart=1..127> <store=0|1>\\
  119. [<scanType0> <vendorId> <scanType1> <productCode>\\
  120. <scanType2> <revisionNo> <scanType3> <serialNo>]]]
  121. # Node-ID configuration of all nodes.
  122. * All LSS commands start with '\"[\"<sequence>\"]\" [<net>]'.
  123. * <table_index>: 0=1000 kbit/s, 1=800 kbit/s, 2=500 kbit/s, 3=250 kbit/s,
  124. 4=125 kbit/s, 6=50 kbit/s, 7=20 kbit/s, 8=10 kbit/s, 9=auto
  125. * <scanType>: 0=fastscan, 1=ignore, 2=match value in next parameter
  126. * @endcode
  127. *
  128. * This help text is the same as variable contents in CO_GTWA_helpString.
  129. * @}
  130. */
  131. /** Size of response string buffer. This is intermediate buffer. If there is
  132. * larger amount of data to transfer, then multiple transfers will occur. */
  133. #ifndef CO_GTWA_RESP_BUF_SIZE
  134. #define CO_GTWA_RESP_BUF_SIZE 200
  135. #endif
  136. /** Timeout time in microseconds for some internal states. */
  137. #ifndef CO_GTWA_STATE_TIMEOUT_TIME_US
  138. #define CO_GTWA_STATE_TIMEOUT_TIME_US 1200000
  139. #endif
  140. /**
  141. * Response error codes as specified by CiA 309-3. Values less or equal to 0
  142. * are used for control for some functions and are not part of the standard.
  143. */
  144. typedef enum {
  145. /** 0 - No error or idle */
  146. CO_GTWA_respErrorNone = 0,
  147. /** 100 - Request not supported */
  148. CO_GTWA_respErrorReqNotSupported = 100,
  149. /** 101 - Syntax error */
  150. CO_GTWA_respErrorSyntax = 101,
  151. /** 102 - Request not processed due to internal state */
  152. CO_GTWA_respErrorInternalState = 102,
  153. /** 103 - Time-out (where applicable) */
  154. CO_GTWA_respErrorTimeOut = 103,
  155. /** 104 - No default net set */
  156. CO_GTWA_respErrorNoDefaultNetSet = 104,
  157. /** 105 - No default node set */
  158. CO_GTWA_respErrorNoDefaultNodeSet = 105,
  159. /** 106 - Unsupported net */
  160. CO_GTWA_respErrorUnsupportedNet = 106,
  161. /** 107 - Unsupported node */
  162. CO_GTWA_respErrorUnsupportedNode = 107,
  163. /** 200 - Lost guarding message */
  164. CO_GTWA_respErrorLostGuardingMessage = 200,
  165. /** 201 - Lost connection */
  166. CO_GTWA_respErrorLostConnection = 201,
  167. /** 202 - Heartbeat started */
  168. CO_GTWA_respErrorHeartbeatStarted = 202,
  169. /** 203 - Heartbeat lost */
  170. CO_GTWA_respErrorHeartbeatLost = 203,
  171. /** 204 - Wrong NMT state */
  172. CO_GTWA_respErrorWrongNMTstate = 204,
  173. /** 205 - Boot-up */
  174. CO_GTWA_respErrorBootUp = 205,
  175. /** 300 - Error passive */
  176. CO_GTWA_respErrorErrorPassive = 300,
  177. /** 301 - Bus off */
  178. CO_GTWA_respErrorBusOff = 301,
  179. /** 303 - CAN buffer overflow */
  180. CO_GTWA_respErrorCANbufferOverflow = 303,
  181. /** 304 - CAN init */
  182. CO_GTWA_respErrorCANinit = 304,
  183. /** 305 - CAN active (at init or start-up) */
  184. CO_GTWA_respErrorCANactive = 305,
  185. /** 400 - PDO already used */
  186. CO_GTWA_respErrorPDOalreadyUsed = 400,
  187. /** 401 - PDO length exceeded */
  188. CO_GTWA_respErrorPDOlengthExceeded = 401,
  189. /** 501 - LSS implementation- / manufacturer-specific error */
  190. CO_GTWA_respErrorLSSmanufacturer = 501,
  191. /** 502 - LSS node-ID not supported */
  192. CO_GTWA_respErrorLSSnodeIdNotSupported = 502,
  193. /** 503 - LSS bit-rate not supported */
  194. CO_GTWA_respErrorLSSbitRateNotSupported = 503,
  195. /** 504 - LSS parameter storing failed */
  196. CO_GTWA_respErrorLSSparameterStoringFailed = 504,
  197. /** 505 - LSS command failed because of media error */
  198. CO_GTWA_respErrorLSSmediaError = 505,
  199. /** 600 - Running out of memory */
  200. CO_GTWA_respErrorRunningOutOfMemory = 600
  201. } CO_GTWA_respErrorCode_t;
  202. /**
  203. * Internal states of the Gateway-ascii state machine.
  204. */
  205. typedef enum {
  206. /** Gateway is idle, no command is processing. This state is starting point
  207. * for new commands, which are parsed here. */
  208. CO_GTWA_ST_IDLE = 0x00U,
  209. /** SDO 'read' (upload) */
  210. CO_GTWA_ST_READ = 0x10U,
  211. /** SDO 'write' (download) */
  212. CO_GTWA_ST_WRITE = 0x11U,
  213. /** SDO 'write' (download) - aborted, purging remaining data */
  214. CO_GTWA_ST_WRITE_ABORTED = 0x12U,
  215. /** LSS 'lss_switch_glob' */
  216. CO_GTWA_ST_LSS_SWITCH_GLOB = 0x20U,
  217. /** LSS 'lss_switch_sel' */
  218. CO_GTWA_ST_LSS_SWITCH_SEL = 0x21U,
  219. /** LSS 'lss_set_node' */
  220. CO_GTWA_ST_LSS_SET_NODE = 0x22U,
  221. /** LSS 'lss_conf_bitrate' */
  222. CO_GTWA_ST_LSS_CONF_BITRATE = 0x23U,
  223. /** LSS 'lss_store' */
  224. CO_GTWA_ST_LSS_STORE = 0x24U,
  225. /** LSS 'lss_inquire_addr' or 'lss_get_node' */
  226. CO_GTWA_ST_LSS_INQUIRE = 0x25U,
  227. /** LSS 'lss_inquire_addr', all parameters */
  228. CO_GTWA_ST_LSS_INQUIRE_ADDR_ALL = 0x26U,
  229. /** LSS '_lss_fastscan' */
  230. CO_GTWA_ST__LSS_FASTSCAN = 0x30U,
  231. /** LSS 'lss_allnodes' */
  232. CO_GTWA_ST_LSS_ALLNODES = 0x31U,
  233. /** print message 'log' */
  234. CO_GTWA_ST_LOG = 0x80U,
  235. /** print 'help' text */
  236. CO_GTWA_ST_HELP = 0x81U,
  237. /** print 'status' of the node */
  238. CO_GTWA_ST_LED = 0x82U
  239. } CO_GTWA_state_t;
  240. #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_SDO) || defined CO_DOXYGEN
  241. /*
  242. * CANopen Gateway-ascii data types structure
  243. */
  244. typedef struct {
  245. /** Data type syntax, as defined in CiA309-3 */
  246. char* syntax;
  247. /** Data type length in bytes, 0 if size is not known */
  248. size_t length;
  249. /** Function, which reads data of specific data type from fifo buffer and
  250. * writes them as corresponding ascii string. It is a pointer to
  251. * #CO_fifo_readU82a function or similar and is used with SDO upload. For
  252. * description of parameters see #CO_fifo_readU82a */
  253. size_t (*dataTypePrint)(CO_fifo_t *fifo,
  254. char *buf,
  255. size_t count,
  256. bool_t end);
  257. /** Function, which reads ascii-data of specific data type from fifo buffer
  258. * and copies them to another fifo buffer as binary data. It is a pointer to
  259. * #CO_fifo_cpyTok2U8 function or similar and is used with SDO download. For
  260. * description of parameters see #CO_fifo_cpyTok2U8 */
  261. size_t (*dataTypeScan)(CO_fifo_t *dest,
  262. CO_fifo_t *src,
  263. CO_fifo_st *status);
  264. } CO_GTWA_dataType_t;
  265. #endif /* (CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_SDO */
  266. /**
  267. * CANopen Gateway-ascii object
  268. */
  269. typedef struct {
  270. /** Pointer to external function for reading response from Gateway-ascii
  271. * object. Pointer is initialized in CO_GTWA_initRead().
  272. *
  273. * @param object Void pointer to custom object
  274. * @param buf Buffer from which data can be read
  275. * @param count Count of bytes available inside buffer
  276. * @param [out] connectionOK different than 0 indicates connection is OK.
  277. *
  278. * @return Count of bytes actually transferred.
  279. */
  280. size_t (*readCallback)(void *object,
  281. const char *buf,
  282. size_t count,
  283. uint8_t *connectionOK);
  284. /** Pointer to object, which will be used inside readCallback, from
  285. * CO_GTWA_init() */
  286. void *readCallbackObject;
  287. /** Sequence number of the command */
  288. uint32_t sequence;
  289. /** Default CANopen Net number is undefined (-1) at startup */
  290. int32_t net_default;
  291. /** Default CANopen Node ID number is undefined (-1) at startup */
  292. int16_t node_default;
  293. /** Current CANopen Net number */
  294. uint16_t net;
  295. /** Current CANopen Node ID */
  296. uint8_t node;
  297. /** CO_fifo_t object for command (not pointer) */
  298. CO_fifo_t commFifo;
  299. /** Command buffer of usable size @ref CO_CONFIG_GTWA_COMM_BUF_SIZE */
  300. char commBuf[CO_CONFIG_GTWA_COMM_BUF_SIZE + 1];
  301. /** Response buffer of usable size @ref CO_GTWA_RESP_BUF_SIZE */
  302. char respBuf[CO_GTWA_RESP_BUF_SIZE];
  303. /** Actual size of data in respBuf */
  304. size_t respBufCount;
  305. /** If only part of data has been successfully written into external
  306. * application (with readCallback()), then Gateway-ascii object will stay
  307. * in current state. This situation is indicated with respHold variable and
  308. * respBufOffset indicates offset to untransferred data inside respBuf. */
  309. size_t respBufOffset;
  310. /** See respBufOffset above */
  311. bool_t respHold;
  312. /** Sum of time difference from CO_GTWA_process() in case of respHold */
  313. uint32_t timeDifference_us_cumulative;
  314. /** Current state of the gateway object */
  315. CO_GTWA_state_t state;
  316. /** Timeout timer for the current state */
  317. uint32_t stateTimeoutTmr;
  318. #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_SDO) || defined CO_DOXYGEN
  319. /** SDO client object from CO_GTWA_init() */
  320. CO_SDOclient_t *SDO_C;
  321. /** Timeout time for SDO transfer in milliseconds, if no response */
  322. uint16_t SDOtimeoutTime;
  323. /** SDO block transfer enabled? */
  324. bool_t SDOblockTransferEnable;
  325. /** Indicate status of data copy from / to SDO buffer. If reading, true
  326. * indicates, that response has started. If writing, true indicates, that
  327. * SDO buffer contains only part of data and more data will follow. */
  328. bool_t SDOdataCopyStatus;
  329. /** Data type of variable in current SDO communication */
  330. const CO_GTWA_dataType_t *SDOdataType;
  331. #endif
  332. #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_NMT) || defined CO_DOXYGEN
  333. /** NMT object from CO_GTWA_init() */
  334. CO_NMT_t *NMT;
  335. #endif
  336. #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_LSS) || defined CO_DOXYGEN
  337. /** LSSmaster object from CO_GTWA_init() */
  338. CO_LSSmaster_t *LSSmaster;
  339. /** 128 bit number, uniquely identifying each node */
  340. CO_LSS_address_t lssAddress;
  341. /** LSS Node-ID parameter */
  342. uint8_t lssNID;
  343. /** LSS bitrate parameter */
  344. uint16_t lssBitrate;
  345. /** LSS inquire parameter */
  346. CO_LSS_cs_t lssInquireCs;
  347. /** LSS fastscan parameter */
  348. CO_LSSmaster_fastscan_t lssFastscan;
  349. /** LSS allnodes sub state parameter */
  350. uint8_t lssSubState;
  351. /** LSS allnodes node count parameter */
  352. uint8_t lssNodeCount;
  353. /** LSS allnodes store parameter */
  354. bool_t lssStore;
  355. /** LSS allnodes timeout parameter */
  356. uint16_t lssTimeout_ms;
  357. #endif
  358. #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_LOG) || defined CO_DOXYGEN
  359. /** Message log buffer of usable size @ref CO_CONFIG_GTWA_LOG_BUF_SIZE */
  360. char logBuf[CO_CONFIG_GTWA_LOG_BUF_SIZE + 1];
  361. /** CO_fifo_t object for message log (not pointer) */
  362. CO_fifo_t logFifo;
  363. #endif
  364. #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_PRINT_HELP) || defined CO_DOXYGEN
  365. /** Offset, when printing help text */
  366. const char *helpString;
  367. size_t helpStringOffset;
  368. #endif
  369. #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_PRINT_LEDS) || defined CO_DOXYGEN
  370. /** CO_LEDs_t object for CANopen status LEDs imitation from CO_GTWA_init()*/
  371. CO_LEDs_t *LEDs;
  372. uint8_t ledStringPreviousIndex;
  373. #endif
  374. } CO_GTWA_t;
  375. /**
  376. * Initialize Gateway-ascii object
  377. *
  378. * @param gtwa This object will be initialized
  379. * @param SDO_C SDO client object
  380. * @param SDOclientTimeoutTime_ms Default timeout in milliseconds, 500 typically
  381. * @param SDOclientBlockTransfer If true, block transfer will be set by default
  382. * @param NMT NMT object
  383. * @param LSSmaster LSS master object
  384. * @param LEDs LEDs object
  385. * @param dummy dummy argument, set to 0
  386. *
  387. * @return #CO_ReturnError_t: CO_ERROR_NO or CO_ERROR_ILLEGAL_ARGUMENT
  388. */
  389. CO_ReturnError_t CO_GTWA_init(CO_GTWA_t* gtwa,
  390. #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_SDO) || defined CO_DOXYGEN
  391. CO_SDOclient_t* SDO_C,
  392. uint16_t SDOclientTimeoutTime_ms,
  393. bool_t SDOclientBlockTransfer,
  394. #endif
  395. #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_NMT) || defined CO_DOXYGEN
  396. CO_NMT_t *NMT,
  397. #endif
  398. #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_LSS) || defined CO_DOXYGEN
  399. CO_LSSmaster_t *LSSmaster,
  400. #endif
  401. #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_PRINT_LEDS) || defined CO_DOXYGEN
  402. CO_LEDs_t *LEDs,
  403. #endif
  404. uint8_t dummy);
  405. /**
  406. * Initialize read callback in Gateway-ascii object
  407. *
  408. * Callback will be used for transfer data to output stream of the application.
  409. * It will be called from CO_GTWA_process() zero or multiple times, depending on
  410. * the data available. If readCallback is uninitialized or NULL, then output
  411. * data will be purged.
  412. *
  413. * @param gtwa This object will be initialized
  414. * @param readCallback Pointer to external function for reading response from
  415. * Gateway-ascii object. See #CO_GTWA_t for parameters.
  416. * @param readCallbackObject Pointer to object, which will be used inside
  417. * readCallback
  418. */
  419. void CO_GTWA_initRead(CO_GTWA_t* gtwa,
  420. size_t (*readCallback)(void *object,
  421. const char *buf,
  422. size_t count,
  423. uint8_t *connectionOK),
  424. void *readCallbackObject);
  425. /**
  426. * Get free write buffer space
  427. *
  428. * @param gtwa This object
  429. *
  430. * @return number of available bytes
  431. */
  432. static inline size_t CO_GTWA_write_getSpace(CO_GTWA_t* gtwa) {
  433. return CO_fifo_getSpace(&gtwa->commFifo);
  434. }
  435. /**
  436. * Write command into CO_GTWA_t object.
  437. *
  438. * This function copies ascii command from buf into internal fifo buffer.
  439. * Command must be closed with '\n' character. Function returns number of bytes
  440. * successfully copied. If there is not enough space in destination, not all
  441. * bytes will be copied and data can be refilled later (in case of large SDO
  442. * download).
  443. *
  444. * @param gtwa This object
  445. * @param buf Buffer which will be copied
  446. * @param count Number of bytes in buf
  447. *
  448. * @return number of bytes actually written.
  449. */
  450. static inline size_t CO_GTWA_write(CO_GTWA_t* gtwa,
  451. const char *buf,
  452. size_t count)
  453. {
  454. return CO_fifo_write(&gtwa->commFifo, buf, count, NULL);
  455. }
  456. #if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_LOG) || defined CO_DOXYGEN
  457. /**
  458. * Print message log string into fifo buffer
  459. *
  460. * This function enables recording of system log messages including CANopen
  461. * events. Function can be called by application for recording any message.
  462. * Message is copied to internal fifo buffer. In case fifo is full, old messages
  463. * will be owerwritten. Message log fifo can be read with non-standard command
  464. * "log". After log is read, it is emptied.
  465. *
  466. * @param gtwa This object
  467. * @param message Null terminated string
  468. */
  469. void CO_GTWA_log_print(CO_GTWA_t* gtwa, const char *message);
  470. #endif /* (CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII_LOG */
  471. /**
  472. * Process Gateway-ascii object
  473. *
  474. * This is non-blocking function and must be called cyclically
  475. *
  476. * @param gtwa This object will be initialized.
  477. * @param enable If true, gateway operates normally. If false, gateway is
  478. * completely disabled and no command interaction is possible. Can be connected
  479. * to hardware switch, for example.
  480. * @param timeDifference_us Time difference from previous function call in
  481. * [microseconds].
  482. * @param [out] timerNext_us info to OS - see CO_process().
  483. *
  484. * @return CO_ReturnError_t: CO_ERROR_NO on success or CO_ERROR_ILLEGAL_ARGUMENT
  485. */
  486. void CO_GTWA_process(CO_GTWA_t *gtwa,
  487. bool_t enable,
  488. uint32_t timeDifference_us,
  489. uint32_t *timerNext_us);
  490. /** @} */ /* CO_CANopen_309_3 */
  491. #ifdef __cplusplus
  492. }
  493. #endif /*__cplusplus*/
  494. #endif /* (CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII */
  495. #endif /* CO_GATEWAY_ASCII_H */