Lely core libraries 2.3.4
gw_txt.c File Reference

This file is part of the CANopen library; it contains the implementation of the ASCII gateway functions. More...

#include "co.h"
#include <lely/co/dev.h>
#include <lely/co/gw_txt.h>
#include <lely/co/nmt.h>
#include <lely/co/pdo.h>
#include <lely/co/sdo.h>
#include <lely/co/val.h>
#include <lely/libc/stdio.h>
#include <lely/libc/strings.h>
#include <lely/util/diag.h>
#include <lely/util/lex.h>
#include <lely/util/print.h>
#include <assert.h>
#include <inttypes.h>
#include <stdlib.h>
Include dependency graph for gw_txt.c:

Go to the source code of this file.

Data Structures

struct  __co_gw_txt
 A CANopen ASCII gateway. More...
 

Functions

static int co_gw_txt_recv_con (co_gw_txt_t *gw, co_unsigned32_t seq, const struct co_gw_con *con)
 Processes a confirmation.
 
static int co_gw_txt_recv_sdo_up (co_gw_txt_t *gw, co_unsigned32_t seq, const struct co_gw_con_sdo_up *con)
 Processes an 'SDO upload' confirmation.
 
static int co_gw_txt_recv_pdo_read (co_gw_txt_t *gw, co_unsigned32_t seq, const struct co_gw_con_pdo_read *con)
 Processes a 'Read PDO data' confirmation.
 
static int co_gw_txt_recv_get_version (co_gw_txt_t *gw, co_unsigned32_t seq, const struct co_gw_con_get_version *con)
 Processes a 'Get version' confirmation.
 
static int co_gw_txt_recv_lss_get_lssid (co_gw_txt_t *gw, co_unsigned32_t seq, const struct co_gw_con_lss_get_lssid *con)
 Processes an 'Inquire LSS address' confirmation.
 
static int co_gw_txt_recv_lss_get_id (co_gw_txt_t *gw, co_unsigned32_t seq, const struct co_gw_con_lss_get_id *con)
 Processes an 'LSS inquire node-ID' confirmation.
 
static int co_gw_txt_recv__lss_scan (co_gw_txt_t *gw, co_unsigned32_t seq, const struct co_gw_con__lss_scan *con)
 Processes an 'LSS Slowscan/Fastscan' confirmation.
 
static int co_gw_txt_recv_err (co_gw_txt_t *gw, co_unsigned32_t seq, int iec, co_unsigned32_t ac)
 Processes a confirmation with a non-zero internal error code or SDO abort code.
 
static int co_gw_txt_recv_rpdo (co_gw_txt_t *gw, const struct co_gw_ind_rpdo *ind)
 Processes an 'RPDO received' indication.
 
static int co_gw_txt_recv_ec (co_gw_txt_t *gw, const struct co_gw_ind_ec *ind)
 Processes an 'Error control event received' indication.
 
static int co_gw_txt_recv_emcy (co_gw_txt_t *gw, const struct co_gw_ind_emcy *ind)
 Processes an 'Emergency event received' indication.
 
static int co_gw_txt_recv_sdo (co_gw_txt_t *gw, const struct co_gw_ind_sdo *ind)
 Processes an 'CiA 301 progress indication download' indication.
 
static int co_gw_txt_recv__boot (co_gw_txt_t *gw, const struct co_gw_ind__boot *ind)
 Processes a 'Boot slave process completed' indication.
 
static int co_gw_txt_recv_fmt (co_gw_txt_t *gw, const char *format,...)
 Formats a received indication or confirmation and invokes the callback function to process it. More...
 
static int co_gw_txt_recv_txt (co_gw_txt_t *gw, const char *txt)
 Invokes the callback function to process a received indication or confirmation.
 
static size_t co_gw_txt_print_val (char **pbegin, char *end, co_unsigned16_t type, const void *val)
 Prints a CANopen value.
 
static void co_gw_txt_send_req (co_gw_txt_t *gw, const struct co_gw_req *req)
 Invokes the callback function to send a request.
 
static size_t co_gw_txt_send_sdo_up (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, co_unsigned8_t node, const char *begin, const char *end, struct floc *at)
 Sends an 'SDO upload' request after parsing its parameters.
 
static size_t co_gw_txt_send_sdo_dn (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, co_unsigned8_t node, const char *begin, const char *end, struct floc *at)
 Sends an 'SDO download' request after parsing its parameters.
 
static size_t co_gw_txt_send_set_sdo_timeout (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends a 'Configure SDO time-out' request after parsing its parameters.
 
static size_t co_gw_txt_send_set_rpdo (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends a 'Configure RPDO' request after parsing its parameters.
 
static size_t co_gw_txt_send_set_tpdo (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends a 'Configure TPDO' request after parsing its parameters.
 
static size_t co_gw_txt_send_pdo_read (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends a 'Read PDO data' request after parsing its parameters.
 
static size_t co_gw_txt_send_pdo_write (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends a 'Write PDO data' request after parsing its parameters.
 
static size_t co_gw_txt_send_nmt_set_ng (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, co_unsigned8_t node, const char *begin, const char *end, struct floc *at)
 Sends an 'Enable node guarding' request after parsing its parameters.
 
static size_t co_gw_txt_send_nmt_set_hb (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, co_unsigned8_t node, const char *begin, const char *end, struct floc *at)
 Sends a 'Start heartbeat consumer' request after parsing its parameters.
 
static size_t co_gw_txt_send_init (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends an 'Initialize gateway' request after parsing its parameters.
 
static size_t co_gw_txt_send_set_hb (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends a 'Set heartbeat producer' request after parsing its parameters.
 
static size_t co_gw_txt_send_set_id (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends a 'Set node-ID' request after parsing its parameters.
 
static size_t co_gw_txt_send_set_cmd_timeout (co_gw_txt_t *gw, int srv, void *data, const char *begin, const char *end, struct floc *at)
 Sends a 'Set command time-out' request after parsin gits parameters.
 
static size_t co_gw_txt_send_set_bootup_ind (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends a 'Boot-up forwarding' request after parsing its parameters.
 
static size_t co_gw_txt_send_set_net (co_gw_txt_t *gw, int srv, void *data, const char *begin, const char *end, struct floc *at)
 Sends a 'Set default network' request after parsing its parameters.
 
static size_t co_gw_txt_send_set_node (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends a 'Set default node-ID' request after parsing its parameters.
 
static size_t co_gw_txt_send_set_cmd_size (co_gw_txt_t *gw, int srv, void *data, const char *begin, const char *end, struct floc *at)
 Sends a 'Set command size' request after parsing its parameters.
 
static size_t co_gw_txt_send_lss_switch (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends an 'LSS switch state global' request after parsing its parameters.
 
static size_t co_gw_txt_send_lss_switch_sel (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends an 'LSS switch state selective' request after parsing its parameters.
 
static size_t co_gw_txt_send_lss_set_id (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends an 'LSS configure node-ID' request after parsing its parameters.
 
static size_t co_gw_txt_send_lss_set_rate (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends an 'LSS configure bit-rate' request after parsing its parameters.
 
static size_t co_gw_txt_send_lss_switch_rate (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends an 'LSS activate new bit-rate' request after parsing its parameters.
 
static size_t co_gw_txt_send_lss_get_lssid (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends an 'Inquire LSS address' request after parsing its parameters.
 
static size_t co_gw_txt_send_lss_id_slave (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends an 'LSS identify remote slave' request after parsing its parameters.
 
static size_t co_gw_txt_send__lss_slowscan (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends an 'LSS Slowscan' request after parsing its parameters.
 
static size_t co_gw_txt_send__lss_fastscan (co_gw_txt_t *gw, int srv, void *data, co_unsigned16_t net, const char *begin, const char *end, struct floc *at)
 Sends an 'LSS Fastscan' request after parsing its parameters.
 
static size_t co_gw_txt_lex_prefix (const char *begin, const char *end, struct floc *at, co_unsigned32_t *pseq, co_unsigned16_t *pnet, co_unsigned8_t *pnode)
 Lexes the prefix (sequence number and optional network and node-ID) of a request.
 
static size_t co_gw_txt_lex_srv (const char *begin, const char *end, struct floc *at, int *psrv)
 Lexes the service number of a request.
 
static size_t co_gw_txt_lex_cmd (const char *begin, const char *end, struct floc *at)
 Lexes a single command.
 
static size_t co_gw_txt_lex_sdo (const char *begin, const char *end, struct floc *at, co_unsigned16_t *pidx, co_unsigned8_t *psubidx, co_unsigned16_t *ptype)
 Lexes the multiplexer and data type of an SDO upload/download request.
 
static size_t co_gw_txt_lex_pdo (const char *begin, const char *end, struct floc *at, int ext, co_unsigned16_t *pnum, struct co_pdo_comm_par *pcomm, struct co_pdo_map_par *pmap)
 Lexes the communication and mapping parameters of a configure PDO request.
 
static size_t co_gw_txt_lex_type (const char *begin, const char *end, struct floc *at, co_unsigned16_t *ptype)
 Lexes a data type.
 
static size_t co_gw_txt_lex_val (const char *begin, const char *end, struct floc *at, co_unsigned16_t type, void *val)
 Lexes a value for an SDO download request.
 
static size_t co_gw_txt_lex_vs (const char *begin, const char *end, struct floc *at, char *s, size_t *pn)
 Lexes an array of visible characters (CO_DEFTYPE_VISIBLE_STRING), excluding the delimiting quotes, for an SDO download request.
 
static size_t co_gw_txt_lex_trans (const char *begin, const char *end, struct floc *at, co_unsigned8_t *ptrans)
 Lexes the transmission type of a configure PDO request.
 
static size_t co_gw_txt_lex_id (const char *begin, const char *end, struct floc *at, struct co_id *pid)
 Lexes an LSS address.
 
static size_t co_gw_txt_lex_id_sel (const char *begin, const char *end, struct floc *at, struct co_id *plo, struct co_id *phi)
 Lexes an LSS address range.
 
co_gw_txt_tco_gw_txt_create (void)
 Creates a new CANopen ASCII gateway. More...
 
void co_gw_txt_destroy (co_gw_txt_t *gw)
 Destroys a CANopen ASCII gateway. More...
 
int co_gw_txt_iec (co_gw_txt_t *gw)
 Returns (and clears) the last internal error code.
 
size_t co_gw_txt_pending (const co_gw_txt_t *gw)
 Returns the number of pending (i.e., unconfirmed) requests.
 
int co_gw_txt_recv (co_gw_txt_t *gw, const struct co_gw_srv *srv)
 Receives and forwards an indication or confirmation from a CANopen gateway. More...
 
void co_gw_txt_get_recv_func (const co_gw_txt_t *gw, co_gw_txt_recv_func_t **pfunc, void **pdata)
 Retrieves the callback function used to forward indications and confirmations received by a CANopen gateway to the user. More...
 
size_t co_gw_txt_send (co_gw_txt_t *gw, const char *begin, const char *end, struct floc *at)
 Sends a user request to a CANopen gateway. More...
 
void co_gw_txt_set_recv_func (co_gw_txt_t *gw, co_gw_txt_recv_func_t *func, void *data)
 Sets the callback function used to forward indications and confirmations received by a CANopen gateway to the user. More...
 
void co_gw_txt_get_send_func (const co_gw_txt_t *gw, co_gw_txt_send_func_t **pfunc, void **pdata)
 Retrieves the callback function used to send requests from the user to a CANopen gateway. More...
 
void co_gw_txt_set_send_func (co_gw_txt_t *gw, co_gw_txt_send_func_t *func, void *data)
 Sets the callback function used to send requests from the user to a CANopen gateway. More...
 

Detailed Description

This file is part of the CANopen library; it contains the implementation of the ASCII gateway functions.

See also
lely/co/gw_txt.h
Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file gw_txt.c.

Function Documentation

◆ co_gw_txt_recv_fmt()

static int co_gw_txt_recv_fmt ( co_gw_txt_t gw,
const char *  format,
  ... 
)
static

Formats a received indication or confirmation and invokes the callback function to process it.

See also
co_gw_txt_recv_txt()

Definition at line 1122 of file gw_txt.c.

◆ co_gw_txt_create()

co_gw_txt_t * co_gw_txt_create ( void  )

Creates a new CANopen ASCII gateway.

See also
co_gw_txt_destroy()

Definition at line 337 of file gw_txt.c.

◆ co_gw_txt_destroy()

void co_gw_txt_destroy ( co_gw_txt_t gw)

Destroys a CANopen ASCII gateway.

See also
co_gw_txt_create()

Definition at line 362 of file gw_txt.c.

◆ co_gw_txt_recv()

int co_gw_txt_recv ( co_gw_txt_t gw,
const struct co_gw_srv srv 
)

Receives and forwards an indication or confirmation from a CANopen gateway.

Parameters
gwa pointer to a CANopen ASCII gateway.
srva pointer to the service parameters.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 389 of file gw_txt.c.

◆ co_gw_txt_get_recv_func()

void co_gw_txt_get_recv_func ( const co_gw_txt_t gw,
co_gw_txt_recv_func_t **  pfunc,
void **  pdata 
)

Retrieves the callback function used to forward indications and confirmations received by a CANopen gateway to the user.

Parameters
gwa pointer to a CANopen ASCII gateway.
pfuncthe address at which to store a pointer to the callback function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
co_gw_txt_set_recv_func()

Definition at line 486 of file gw_txt.c.

◆ co_gw_txt_send()

size_t co_gw_txt_send ( co_gw_txt_t gw,
const char *  begin,
const char *  end,
struct floc at 
)

Sends a user request to a CANopen gateway.

Parameters
gwa pointer to a CANopen ASCII gateway.
begina pointer to the start of the buffer containing the request.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character parsed. On error, *at is left untouched.
Returns
the number of characters read.

Definition at line 498 of file gw_txt.c.

◆ co_gw_txt_set_recv_func()

void co_gw_txt_set_recv_func ( co_gw_txt_t gw,
co_gw_txt_recv_func_t func,
void *  data 
)

Sets the callback function used to forward indications and confirmations received by a CANopen gateway to the user.

Parameters
gwa pointer to a CANopen ASCII gateway.
funca pointer to the function invoked by co_gw_txt_recv().
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to func.
See also
co_gw_txt_get_recv_func()

Definition at line 760 of file gw_txt.c.

◆ co_gw_txt_get_send_func()

void co_gw_txt_get_send_func ( const co_gw_txt_t gw,
co_gw_txt_send_func_t **  pfunc,
void **  pdata 
)

Retrieves the callback function used to send requests from the user to a CANopen gateway.

Parameters
gwa pointer to a CANopen ASCII gateway.
pfuncthe address at which to store a pointer to the callback function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
co_gw_txt_set_send_func()

Definition at line 770 of file gw_txt.c.

◆ co_gw_txt_set_send_func()

void co_gw_txt_set_send_func ( co_gw_txt_t gw,
co_gw_txt_send_func_t func,
void *  data 
)

Sets the callback function used to send requests from the user to a CANopen gateway.

Parameters
gwa pointer to a CANopen ASCII gateway.
funca pointer to the function invoked by co_gw_txt_send().
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to func.
See also
co_gw_txt_get_send_func()

Definition at line 782 of file gw_txt.c.