Lely core libraries  2.3.4
gw.c File Reference

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

#include "co.h"
#include <lely/co/csdo.h>
#include <lely/co/dev.h>
#include <lely/util/errnum.h>
#include <lely/co/emcy.h>
#include <lely/co/gw.h>
#include <lely/co/lss.h>
#include <lely/co/nmt.h>
#include <lely/co/obj.h>
#include <lely/co/rpdo.h>
#include <lely/co/sdo.h>
#include <lely/co/sync.h>
#include <lely/co/time.h>
#include <lely/co/tpdo.h>
#include <assert.h>
#include <stdlib.h>
Include dependency graph for gw.c:

Go to the source code of this file.

Data Structures

struct  co_gw_net
 A CANopen network. More...
 
struct  co_gw_job
 A CANopen gateway network job. More...
 
struct  __co_gw
 A CANopen gateway. More...
 

Macros

#define CO_GW_JOB_SIZE   offsetof(struct co_gw_job, req)
 The minimum size (in bytes) of a CANopen gateway network job.
 

Functions

static struct co_gw_netco_gw_net_create (co_gw_t *gw, co_unsigned16_t id, co_nmt_t *nmt)
 Creates a new CANopen network. More...
 
static void co_gw_net_destroy (struct co_gw_net *net)
 Destroys a CANopen network. More...
 
static void co_gw_net_cs_ind (co_nmt_t *nmt, co_unsigned8_t cs, void *data)
 The callback function invoked when an NMT command is received by a CANopen gateway. More...
 
static void co_gw_net_ng_ind (co_nmt_t *nmt, co_unsigned8_t id, int state, int reason, void *data)
 The callback function invoked when a node guarding event occurs for a node on a CANopen network. More...
 
static void co_gw_net_lg_ind (co_nmt_t *nmt, int state, void *data)
 The callback function invoked when a life guarding event occurs for a CANopen gateway. More...
 
static void co_gw_net_hb_ind (co_nmt_t *nmt, co_unsigned8_t id, int state, int reason, void *data)
 The callback function invoked when a heartbeat event occurs for a node on a CANopen network. More...
 
static void co_gw_net_st_ind (co_nmt_t *nmt, co_unsigned8_t id, co_unsigned8_t st, void *data)
 The callback function invoked when a boot-up event or state change is detected for a node on a CANopen network. More...
 
static void co_gw_net_boot_ind (co_nmt_t *nmt, co_unsigned8_t id, co_unsigned8_t st, char es, void *data)
 The callback function invoked when the 'boot slave' process completes for a node on a CANopen network. More...
 
static void co_gw_net_dn_ind (co_nmt_t *nmt, co_unsigned8_t id, co_unsigned16_t idx, co_unsigned8_t subidx, size_t size, size_t nbyte, void *data)
 The callback function invoked to notify the user of the progress of an SDO download request during the 'boot slave' process of a node on a CANopen network. More...
 
static void co_gw_net_up_ind (co_nmt_t *nmt, co_unsigned8_t id, co_unsigned16_t idx, co_unsigned8_t subidx, size_t size, size_t nbyte, void *data)
 The callback function invoked to notify the user of the progress of an SDO upload request during the 'boot slave' process of a node on a CANopen network. More...
 
static void co_gw_net_sync_ind (co_sync_t *sync, co_unsigned8_t cnt, void *data)
 The callback function invoked when a SYNC message is received from a node on a CANopen network.
 
static void co_gw_net_time_ind (co_time_t *time, const struct timespec *tp, void *data)
 The callback function invoked when a TIME message is received from a node on a CANopen network.
 
static void co_gw_net_emcy_ind (co_emcy_t *emcy, co_unsigned8_t id, co_unsigned16_t ec, co_unsigned8_t er, co_unsigned8_t msef[5], void *data)
 The callback function invoked when an EMCY message is received from a node on a CANopen network.
 
static void co_gw_net_rpdo_ind (co_rpdo_t *pdo, co_unsigned32_t ac, const void *ptr, size_t n, void *data)
 The callback function invoked when a PDO is received from a node on a CANopen network.
 
static struct co_gw_jobco_gw_job_create (struct co_gw_job **pself, struct co_gw_net *net, void *data, void(*dtor)(void *data), const struct co_gw_req *req)
 Creates a new CANopen gateway network job. More...
 
static void co_gw_job_destroy (struct co_gw_job *job)
 Destroys a CANopen gateway network job. More...
 
static void co_gw_job_remove (struct co_gw_job *job)
 Removes a CANopen gateway network job from its network.
 
static struct co_gw_jobco_gw_job_create_sdo (struct co_gw_job **pself, struct co_gw_net *net, co_unsigned8_t id, const struct co_gw_req *req)
 Creates a new SDO upload/download job.
 
static void co_gw_job_sdo_dtor (void *data)
 Destroys the Client-SDO service in an SDO upload/download job.
 
static void co_gw_job_sdo_up_con (co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac, const void *ptr, size_t n, void *data)
 The confirmation function for an 'SDO upload' request.
 
static void co_gw_job_sdo_dn_con (co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac, void *data)
 The confirmation function for an 'SDO download' request.
 
static void co_gw_job_sdo_ind (const co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, size_t size, size_t nbyte, void *data)
 The progress indication function for an SDO upload/download job.
 
static struct co_gw_jobco_gw_job_create_lss (struct co_gw_job **pself, struct co_gw_net *net, const struct co_gw_req *req)
 Creates a new LSS job.
 
static void co_gw_job_lss_cs_ind (co_lss_t *lss, co_unsigned8_t cs, void *data)
 The confirmation function for an 'LSS switch state selective', 'LSS identify remote slave' or 'LSS identify non-configured remote slaves' request.
 
static void co_gw_job_lss_err_ind (co_lss_t *lss, co_unsigned8_t cs, co_unsigned8_t err, co_unsigned8_t spec, void *data)
 The confirmation function for an 'LSS configure node-ID', 'LSS configure bit-rate' or 'LSS store configuration' request.
 
static void co_gw_job_lss_lssid_ind (co_lss_t *lss, co_unsigned8_t cs, co_unsigned32_t id, void *data)
 The confirmation function for an 'Inquire LSS address' request.
 
static void co_gw_job_lss_nid_ind (co_lss_t *lss, co_unsigned8_t cs, co_unsigned8_t id, void *data)
 The confirmation function for an 'LSS inquire node-ID' request.
 
static void co_gw_job_lss_scan_ind (co_lss_t *lss, co_unsigned8_t cs, const struct co_id *id, void *data)
 The confirmation function for an 'LSS Slowscan/Fastscan' request.
 
static int co_gw_recv_sdo_up (co_gw_t *gw, co_unsigned16_t net, co_unsigned8_t node, const struct co_gw_req *req)
 Processes an 'SDO upload' request.
 
static int co_gw_recv_sdo_dn (co_gw_t *gw, co_unsigned16_t net, co_unsigned8_t node, const struct co_gw_req *req)
 Processes an 'SDO download' request.
 
static int co_gw_recv_set_sdo_timeout (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes a 'Configure SDO time-out' request.
 
static int co_gw_recv_set_rpdo (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes a 'Configure RPDO' request. More...
 
static int co_gw_recv_set_tpdo (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes a 'Configure TPDO' request.
 
static int co_gw_recv_pdo_read (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes a 'Read PDO data' request.
 
static int co_gw_recv_pdo_write (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes a 'Write PDO data' request.
 
static int co_gw_recv_nmt_cs (co_gw_t *gw, co_unsigned16_t net, co_unsigned8_t node, co_unsigned8_t cs, const struct co_gw_req *req)
 Processes an NMT request.
 
static int co_gw_recv_nmt_set_ng (co_gw_t *gw, co_unsigned16_t net, co_unsigned8_t node, const struct co_gw_req *req)
 Processes a 'Enable/Disable node guarding' request.
 
static int co_gw_recv_nmt_set_hb (co_gw_t *gw, co_unsigned16_t net, co_unsigned8_t node, const struct co_gw_req *req)
 Processes a 'Start/Disable heartbeat consumer' request.
 
static int co_gw_recv_init (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes an 'Initialize gateway' request.
 
static int co_gw_recv_set_hb (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes a 'Set heartbeat producer' request.
 
static int co_gw_recv_set_id (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes a 'Set node-ID' request.
 
static int co_gw_recv_set_emcy (co_gw_t *gw, co_unsigned16_t net, co_unsigned8_t node, const struct co_gw_req *req)
 Processes a 'Start/Stop emergency consumer' request.
 
static int co_gw_recv_set_cmd_timeout (co_gw_t *gw, const struct co_gw_req *req)
 Processes a 'Set command time-out' request.
 
static int co_gw_recv_set_bootup_ind (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes a 'Boot-up forwarding' request.
 
static int co_gw_recv_set_net (co_gw_t *gw, const struct co_gw_req *req)
 Processes a 'Set default network' request.
 
static int co_gw_recv_set_node (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes a 'Set default node-ID' request.
 
static int co_gw_recv_get_version (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes a 'Get version' request.
 
static int co_gw_recv_lss_switch (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes an 'LSS switch state global' request.
 
static int co_gw_recv_lss_switch_sel (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes an 'LSS switch state selective' request.
 
static int co_gw_recv_lss_set_id (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes an 'LSS configure node-ID' request.
 
static int co_gw_recv_lss_set_rate (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes an 'LSS configure bit-rate' request.
 
static int co_gw_recv_lss_switch_rate (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes an 'LSS activate new bit-rate' request.
 
static int co_gw_recv_lss_store (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes an 'LSS store configuration' request.
 
static int co_gw_recv_lss_get_lssid (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes an 'Inquire LSS address' request.
 
static int co_gw_recv_lss_get_id (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes an 'LSS inquire node-ID' request.
 
static int co_gw_recv_lss_id_slave (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes an 'LSS identify remote slave' request.
 
static int co_gw_recv_lss_id_non_cfg_slave (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes an 'LSS identify non-configured remote slaves' request.
 
static int co_gw_recv__lss_slowscan (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes an 'LSS Slowscan' request.
 
static int co_gw_recv__lss_fastscan (co_gw_t *gw, co_unsigned16_t net, const struct co_gw_req *req)
 Processes an 'LSS Fastscan' request.
 
static int co_gw_send_con (co_gw_t *gw, const struct co_gw_req *req, int iec, co_unsigned32_t ac)
 Sends a confirmation with an internal error code or SDO abort code.
 
static int co_gw_send_ec (co_gw_t *gw, co_unsigned16_t net, co_unsigned8_t node, co_unsigned8_t st, int iec)
 Sends an 'Error control event received' indication.
 
static int co_gw_send_srv (co_gw_t *gw, const struct co_gw_srv *srv)
 Invokes the callback function to send a confirmation or indication.
 
static int errnum2iec (errnum_t errnum)
 Converts an error number to an internal error code.
 
const char * co_gw_iec2str (int iec)
 Returns a string describing an internal error code.
 
co_gw_tco_gw_create (void)
 Creates a new CANopen gateway. More...
 
void co_gw_destroy (co_gw_t *gw)
 Destroys a CANopen gateway. More...
 
int co_gw_init_net (co_gw_t *gw, co_unsigned16_t id, co_nmt_t *nmt)
 Registers a CANopen network with a gateway. More...
 
int co_gw_fini_net (co_gw_t *gw, co_unsigned16_t id)
 Unregisters a CANopen network with a gateway. More...
 
int co_gw_recv (co_gw_t *gw, const struct co_gw_req *req)
 Receives and processes a request with a CANopen gateway. More...
 
void co_gw_get_send_func (const co_gw_t *gw, co_gw_send_func_t **pfunc, void **pdata)
 Retrieves the callback function used to send indications and confirmations from a CANopen gateway. More...
 
void co_gw_set_send_func (co_gw_t *gw, co_gw_send_func_t *func, void *data)
 Sets the callback function used to send indications and confirmations from a CANopen gateway. More...
 
void co_gw_get_rate_func (const co_gw_t *gw, co_gw_rate_func_t **pfunc, void **pdata)
 Retrieves the callback function invoked when a baudrate switch is needed after an 'Initialize gateway' command is received. More...
 
void co_gw_set_rate_func (co_gw_t *gw, co_gw_rate_func_t *func, void *data)
 Sets the callback function invoked when a baudrate switch is needed after an 'Initialize gateway' command is received. More...
 

Detailed Description

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

See also
lely/co/gw.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.c.

Function Documentation

◆ co_gw_net_create()

static struct co_gw_net * co_gw_net_create ( co_gw_t gw,
co_unsigned16_t  id,
co_nmt_t nmt 
)
static

Creates a new CANopen network.

See also
co_gw_net_destroy()

Definition at line 954 of file gw.c.

◆ co_gw_net_destroy()

static void co_gw_net_destroy ( struct co_gw_net net)
static

Destroys a CANopen network.

See also
co_gw_net_create()

Definition at line 1042 of file gw.c.

◆ co_gw_net_cs_ind()

static void co_gw_net_cs_ind ( co_nmt_t nmt,
co_unsigned8_t  cs,
void *  data 
)
static

The callback function invoked when an NMT command is received by a CANopen gateway.

See also
co_nmt_cs_ind_t

Definition at line 1097 of file gw.c.

◆ co_gw_net_ng_ind()

static void co_gw_net_ng_ind ( co_nmt_t nmt,
co_unsigned8_t  id,
int  state,
int  reason,
void *  data 
)
static

The callback function invoked when a node guarding event occurs for a node on a CANopen network.

See also
co_nmt_ng_ind_t

Definition at line 1163 of file gw.c.

◆ co_gw_net_lg_ind()

static void co_gw_net_lg_ind ( co_nmt_t nmt,
int  state,
void *  data 
)
static

The callback function invoked when a life guarding event occurs for a CANopen gateway.

See also
co_nmt_lg_ind_t

Definition at line 1184 of file gw.c.

◆ co_gw_net_hb_ind()

static void co_gw_net_hb_ind ( co_nmt_t nmt,
co_unsigned8_t  id,
int  state,
int  reason,
void *  data 
)
static

The callback function invoked when a heartbeat event occurs for a node on a CANopen network.

See also
co_nmt_hb_ind_t

Definition at line 1201 of file gw.c.

◆ co_gw_net_st_ind()

static void co_gw_net_st_ind ( co_nmt_t nmt,
co_unsigned8_t  id,
co_unsigned8_t  st,
void *  data 
)
static

The callback function invoked when a boot-up event or state change is detected for a node on a CANopen network.

See also
co_nmt_st_ind_t

Definition at line 1221 of file gw.c.

◆ co_gw_net_boot_ind()

static void co_gw_net_boot_ind ( co_nmt_t nmt,
co_unsigned8_t  id,
co_unsigned8_t  st,
char  es,
void *  data 
)
static

The callback function invoked when the 'boot slave' process completes for a node on a CANopen network.

See also
co_nmt_boot_ind_t

Definition at line 1245 of file gw.c.

◆ co_gw_net_dn_ind()

static void co_gw_net_dn_ind ( co_nmt_t nmt,
co_unsigned8_t  id,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
size_t  size,
size_t  nbyte,
void *  data 
)
static

The callback function invoked to notify the user of the progress of an SDO download request during the 'boot slave' process of a node on a CANopen network.

See also
co_nmt_sdo_ind_t

Definition at line 1267 of file gw.c.

◆ co_gw_net_up_ind()

static void co_gw_net_up_ind ( co_nmt_t nmt,
co_unsigned8_t  id,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
size_t  size,
size_t  nbyte,
void *  data 
)
static

The callback function invoked to notify the user of the progress of an SDO upload request during the 'boot slave' process of a node on a CANopen network.

See also
co_nmt_sdo_ind_t

Definition at line 1288 of file gw.c.

◆ co_gw_job_create()

static struct co_gw_job * co_gw_job_create ( struct co_gw_job **  pself,
struct co_gw_net net,
void *  data,
void(*)(void *data)  dtor,
const struct co_gw_req req 
)
static

Creates a new CANopen gateway network job.

See also
co_gw_job_destroy()

Definition at line 1365 of file gw.c.

◆ co_gw_job_destroy()

static void co_gw_job_destroy ( struct co_gw_job job)
static

Destroys a CANopen gateway network job.

See also
co_gw_job_create()

Definition at line 1392 of file gw.c.

◆ co_gw_recv_set_rpdo()

static int co_gw_recv_set_rpdo ( co_gw_t gw,
co_unsigned16_t  net,
const struct co_gw_req req 
)
static

Processes a 'Configure RPDO' request.

LELY_NO_CO_CSDO.

Definition at line 1985 of file gw.c.

◆ co_gw_create()

co_gw_t* co_gw_create ( void  )

Creates a new CANopen gateway.

See also
co_gw_destroy()

Definition at line 549 of file gw.c.

◆ co_gw_destroy()

void co_gw_destroy ( co_gw_t gw)

Destroys a CANopen gateway.

See also
co_gw_create()

Definition at line 574 of file gw.c.

◆ co_gw_init_net()

int co_gw_init_net ( co_gw_t gw,
co_unsigned16_t  id,
co_nmt_t nmt 
)

Registers a CANopen network with a gateway.

Parameters
gwa pointer to a CANopen gateway.
idthe network-ID (in the range [1..127]). If id is 0, the network-ID is obtained from the CANopen device of the NMT service.
nmta pointer to the NMT service of the gateway node in the network.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
co_gw_fini_net()

Definition at line 583 of file gw.c.

◆ co_gw_fini_net()

int co_gw_fini_net ( co_gw_t gw,
co_unsigned16_t  id 
)

Unregisters a CANopen network with a gateway.

Parameters
gwa pointer to a CANopen gateway.
idthe network-ID (in the range [1..127]).
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
co_gw_init_net()

Definition at line 598 of file gw.c.

◆ co_gw_recv()

int co_gw_recv ( co_gw_t gw,
const struct co_gw_req req 
)

Receives and processes a request with a CANopen gateway.

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

Definition at line 614 of file gw.c.

◆ co_gw_get_send_func()

void co_gw_get_send_func ( const co_gw_t gw,
co_gw_send_func_t **  pfunc,
void **  pdata 
)

Retrieves the callback function used to send indications and confirmations from a CANopen gateway.

Parameters
gwa pointer to a CANopen 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_set_send_func()

Definition at line 914 of file gw.c.

◆ co_gw_set_send_func()

void co_gw_set_send_func ( co_gw_t gw,
co_gw_send_func_t func,
void *  data 
)

Sets the callback function used to send indications and confirmations from a CANopen gateway.

Parameters
gwa pointer to a CANopen gateway.
funca pointer to the function to be invoked when an indication or confirmation needs to be sent.
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to func.
See also
co_gw_get_send_func()

Definition at line 925 of file gw.c.

◆ co_gw_get_rate_func()

void co_gw_get_rate_func ( const co_gw_t gw,
co_gw_rate_func_t **  pfunc,
void **  pdata 
)

Retrieves the callback function invoked when a baudrate switch is needed after an 'Initialize gateway' command is received.

Parameters
gwa pointer to a CANopen 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_set_rate_func()

Definition at line 934 of file gw.c.

◆ co_gw_set_rate_func()

void co_gw_set_rate_func ( co_gw_t gw,
co_gw_rate_func_t func,
void *  data 
)

Sets the callback function invoked when a baudrate switch is needed after an 'Initialize gateway' command is received.

Parameters
gwa pointer to a CANopen gateway.
funca pointer to the function to be invoked when an indication or confirmation needs to be sent.
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to func.
See also
co_gw_get_rate_func()

Definition at line 945 of file gw.c.