Lely core libraries  2.2.5
nmt_hb.c File Reference

This file is part of the CANopen library; it contains the implementation of the NMT heartbeat consumer functions. More...

#include "nmt_hb.h"
#include "co.h"
#include <lely/co/dev.h>
#include <lely/util/diag.h>
#include <assert.h>
#include <stdlib.h>
Include dependency graph for nmt_hb.c:

Go to the source code of this file.

Data Structures

struct  __co_nmt_hb
 A CANopen NMT heartbeat consumer. More...
 

Functions

static int co_nmt_hb_recv (const struct can_msg *msg, void *data)
 The CAN receive callback function for a heartbeat consumer. More...
 
static int co_nmt_hb_timer (const struct timespec *tp, void *data)
 The CAN timer callback function for a heartbeat consumer. More...
 
co_nmt_hb_tco_nmt_hb_create (can_net_t *net, co_nmt_t *nmt)
 Creates a new CANopen NMT heartbeat consumer service. More...
 
void co_nmt_hb_destroy (co_nmt_hb_t *hb)
 Destroys a CANopen NMT heartbeat consumer service. More...
 
void co_nmt_hb_set_1016 (co_nmt_hb_t *hb, co_unsigned8_t id, co_unsigned16_t ms)
 Processes the value of CANopen object 1016 (Consumer heartbeat time) for the specified heartbeat consumer. More...
 
void co_nmt_hb_set_st (co_nmt_hb_t *hb, co_unsigned8_t st)
 Sets the expected state of a remote NMT node. More...
 

Detailed Description

This file is part of the CANopen library; it contains the implementation of the NMT heartbeat consumer functions.

See also
src/nmt_ec.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 nmt_hb.c.

Function Documentation

◆ co_nmt_hb_recv()

static int co_nmt_hb_recv ( const struct can_msg msg,
void *  data 
)
static

The CAN receive callback function for a heartbeat consumer.

See also
can_recv_func_t

Definition at line 203 of file nmt_hb.c.

◆ co_nmt_hb_timer()

static int co_nmt_hb_timer ( const struct timespec *  tp,
void *  data 
)
static

The CAN timer callback function for a heartbeat consumer.

See also
can_timer_func_t

Definition at line 252 of file nmt_hb.c.

◆ co_nmt_hb_create()

co_nmt_hb_t* co_nmt_hb_create ( can_net_t net,
co_nmt_t nmt 
)

Creates a new CANopen NMT heartbeat consumer service.

Parameters
neta pointer to a CAN network.
nmta pointer to an NMT master/slave service.
Returns
a pointer to a new heartbeat consumer service, or NULL on error. In the latter case, the error number can be obtained with get_errc().
See also
co_nmt_hb_destroy()

Definition at line 135 of file nmt_hb.c.

◆ co_nmt_hb_destroy()

void co_nmt_hb_destroy ( co_nmt_hb_t hb)

Destroys a CANopen NMT heartbeat consumer service.

See also
co_nmt_hb_create()

Definition at line 160 of file nmt_hb.c.

◆ co_nmt_hb_set_1016()

void co_nmt_hb_set_1016 ( co_nmt_hb_t hb,
co_unsigned8_t  id,
co_unsigned16_t  ms 
)

Processes the value of CANopen object 1016 (Consumer heartbeat time) for the specified heartbeat consumer.

If the node-ID is valid and the heartbeat time is non-zero, the heartbeat consumer is activated. Note that this only activates the CAN frame receiver for heartbeat messages. The CAN timer for heartbeat events is not activated until the first heartbeat message is received or co_nmt_hb_set_st() is invoked.

Parameters
hba pointer to a heartbeat consumer service.
idthe node-ID.
msthe heartbeat time (in milliseconds).

Definition at line 169 of file nmt_hb.c.

◆ co_nmt_hb_set_st()

void co_nmt_hb_set_st ( co_nmt_hb_t hb,
co_unsigned8_t  st 
)

Sets the expected state of a remote NMT node.

If the heartbeat consumer is active, invocation of this function is equivalent to reception of a heartbeat message with the specified state and will (re)activate the CAN timer for heartbeat events.

Parameters
hba pointer to a heartbeat consumer service.
stthe state of the node (excluding the toggle bit).

Definition at line 190 of file nmt_hb.c.