Lely core libraries
2.3.4
|
#include "co.h"
#include <lely/can/err.h>
#include <lely/co/crc.h>
#include <lely/co/wtm.h>
#include <lely/util/diag.h>
#include <lely/util/endian.h>
#include <lely/util/time.h>
#include <assert.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
Data Structures | |
struct | co_wtm_can |
A CANopen WTM CAN interface. More... | |
struct | __co_wtm |
A CANopen Wireless Transmission Media (WTM) interface. More... | |
Macros | |
#define | CO_WTM_MAX_NIF 127 |
The maximum value of a CAN/WTM interface indicator. | |
Functions | |
static int | co_wtm_send_diag_can_res (co_wtm_t *wtm, uint_least8_t nif) |
Sends a communication quality response for a CAN interface. | |
static int | co_wtm_send_diag_wtm_res (co_wtm_t *wtm) |
Sends a communication quality response for a WTM interface. | |
static void | co_wtm_diag_ac (co_wtm_t *wtm, uint_least32_t ac) |
Invokes the diagnostic indication function. | |
static void | default_wtm_diag_ac_ind (co_wtm_t *wtm, uint_least32_t ac, void *data) |
The default diagnostic indication function. More... | |
static uint_least32_t | co_wtm_recv_can (co_wtm_t *wtm, const void *buf, size_t nbytes) |
Processes a generic frame containing CAN messages. More... | |
const char * | co_wtm_ac_str (uint_least32_t ac) |
Returns a string describing a CANopen WTM abort code. | |
co_wtm_t * | co_wtm_create (void) |
Creates a new CANopen Wireless Transmission Media (WTM) interface. More... | |
void | co_wtm_destroy (co_wtm_t *wtm) |
Destroys a CANopen Wireless Transmission Media (WTM) interface. More... | |
uint_least8_t | co_wtm_get_nif (const co_wtm_t *wtm) |
Returns the interface indicator of a CANopen WTM interface. More... | |
int | co_wtm_set_nif (co_wtm_t *wtm, uint_least8_t nif) |
Sets the interface indicator of a CANopen WTM interface. More... | |
int | co_wtm_set_diag_can (co_wtm_t *wtm, uint_least8_t nif, uint_least8_t st, uint_least8_t err, uint_least8_t load, uint_least16_t ec, uint_least16_t foc, uint_least16_t coc) |
Sets the diagnostic parameters of a CAN interface. More... | |
int | co_wtm_set_diag_wtm (co_wtm_t *wtm, uint_least8_t quality) |
Sets the diagnostic parameters of a WTM interface. More... | |
void | co_wtm_get_diag_can_con (const co_wtm_t *wtm, co_wtm_diag_can_con_t **pcon, void **pdata) |
Retrieves the confirmation function invoked when a CAN communication quality response is received by a CANopen WTM interface. More... | |
void | co_wtm_set_diag_can_con (co_wtm_t *wtm, co_wtm_diag_can_con_t *con, void *data) |
Sets the confirmation function invoked when a CAN communication quality response is received by a CANopen WTM interface. More... | |
void | co_wtm_get_diag_wtm_con (const co_wtm_t *wtm, co_wtm_diag_wtm_con_t **pcon, void **pdata) |
Retrieves the confirmation function invoked when a WTM communication quality response is received by a CANopen WTM interface. More... | |
void | co_wtm_set_diag_wtm_con (co_wtm_t *wtm, co_wtm_diag_wtm_con_t *con, void *data) |
Sets the confirmation function invoked when a WTM communication quality response is received by a CANopen WTM interface. More... | |
void | co_wtm_get_diag_can_ind (const co_wtm_t *wtm, co_wtm_diag_can_ind_t **pcon, void **pdata) |
Retrieves the indication function invoked when a CAN communication quality reset message is received by a CANopen WTM interface. More... | |
void | co_wtm_set_diag_can_ind (co_wtm_t *wtm, co_wtm_diag_can_ind_t *con, void *data) |
Sets the indication function invoked when a CAN communication quality reset message is received by a CANopen WTM interface. More... | |
void | co_wtm_get_diag_wtm_ind (const co_wtm_t *wtm, co_wtm_diag_wtm_ind_t **pcon, void **pdata) |
Retrieves the indication function invoked when a WTM communication quality reset message is received by a CANopen WTM interface. More... | |
void | co_wtm_set_diag_wtm_ind (co_wtm_t *wtm, co_wtm_diag_wtm_ind_t *con, void *data) |
Sets the indication function invoked when a WTM communication quality reset message is received by a CANopen WTM interface. More... | |
void | co_wtm_get_diag_ac_ind (const co_wtm_t *wtm, co_wtm_diag_ac_ind_t **pind, void **pdata) |
Retrieves the indication function invoked when an abort code is generated or received by a CANopen WTM interface. More... | |
void | co_wtm_set_diag_ac_ind (co_wtm_t *wtm, co_wtm_diag_ac_ind_t *ind, void *data) |
Sets the indication function invoked when an abort code is generated or received by a CANopen WTM interface. More... | |
void | co_wtm_recv (co_wtm_t *wtm, const void *buf, size_t nbytes) |
Receives and processes a byte stream with a CANopen WTM interface. More... | |
void | co_wtm_get_recv_func (const co_wtm_t *wtm, co_wtm_recv_func_t **pfunc, void **pdata) |
Retrieves the callback function invoked when a CAN frame is received by a CANopen WTM interface. More... | |
void | co_wtm_set_recv_func (co_wtm_t *wtm, co_wtm_recv_func_t *func, void *data) |
Sets the callback function invoked when a CAN frame is received by a CANopen WTM interface. More... | |
int | co_wtm_get_time (const co_wtm_t *wtm, uint_least8_t nif, struct timespec *tp) |
Retrieves the current time of a CANopen WTM interface. More... | |
int | co_wtm_set_time (co_wtm_t *wtm, uint_least8_t nif, const struct timespec *tp) |
Sets the current time of a CANopen WTM interface. More... | |
int | co_wtm_send (co_wtm_t *wtm, uint_least8_t nif, const struct can_msg *msg) |
Sends a CAN frame from a CANopen WTM interface. More... | |
int | co_wtm_send_alive (co_wtm_t *wtm) |
Sends a keep-alive message from a CANopen WTM interface. More... | |
int | co_wtm_send_diag_can_req (co_wtm_t *wtm, uint_least8_t nif) |
Sends a CAN communication quality request. More... | |
int | co_wtm_send_diag_wtm_req (co_wtm_t *wtm, uint_least8_t nif) |
Sends a WTM communication quality request. More... | |
int | co_wtm_send_diag_can_rst (co_wtm_t *wtm, uint_least8_t nif) |
Sends a CAN communication quality reset message. More... | |
int | co_wtm_send_diag_wtm_rst (co_wtm_t *wtm, uint_least8_t nif) |
Sends a WTM communication quality reset message. More... | |
int | co_wtm_send_diag_ac (co_wtm_t *wtm, uint_least32_t ac) |
Sends a diagnostic abort message from a CANopen WTM interface. More... | |
int | co_wtm_flush (co_wtm_t *wtm) |
Flushes the current send buffer of a CANopen WTM interface. More... | |
void | co_wtm_get_send_func (const co_wtm_t *wtm, co_wtm_send_func_t **pfunc, void **pdata) |
Retrieves the callback function used to send byte streams from a CANopen WTM interface. More... | |
void | co_wtm_set_send_func (co_wtm_t *wtm, co_wtm_send_func_t *func, void *data) |
Sets the callback function used to send byte streams from a CANopen WTM interface. More... | |
This file is part of the CANopen library; it contains the implementation of the Wireless Transmission Media (WTM) functions.
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 wtm.c.
|
static |
The default diagnostic indication function.
|
static |
co_wtm_t* co_wtm_create | ( | void | ) |
Creates a new CANopen Wireless Transmission Media (WTM) interface.
void co_wtm_destroy | ( | co_wtm_t * | wtm | ) |
Destroys a CANopen Wireless Transmission Media (WTM) interface.
uint_least8_t co_wtm_get_nif | ( | const co_wtm_t * | wtm | ) |
Returns the interface indicator of a CANopen WTM interface.
int co_wtm_set_nif | ( | co_wtm_t * | wtm, |
uint_least8_t | nif | ||
) |
Sets the interface indicator of a CANopen WTM interface.
wtm | a pointer to a CANopen WTM interface. |
nif | the WTM interface indicator (in the range [1..127]). |
int co_wtm_set_diag_can | ( | co_wtm_t * | wtm, |
uint_least8_t | nif, | ||
uint_least8_t | st, | ||
uint_least8_t | err, | ||
uint_least8_t | load, | ||
uint_least16_t | ec, | ||
uint_least16_t | foc, | ||
uint_least16_t | coc | ||
) |
Sets the diagnostic parameters of a CAN interface.
wtm | a pointer to a CANopen WTM interface. |
nif | the local CAN interface indicator (in the range [1..127]). |
st | The current CAN controller status (one of CAN_STATE_ACTIVE , CAN_STATE_PASSIVE or CAN_STATE_BUSOFF , or 0xf if the information is not available). |
err | the last detected error (0 if no error was detected, one of CAN_ERROR_BIT , CAN_ERROR_STUFF , CAN_ERROR_CRC , CAN_ERROR_FORM or CAN_ERROR_ACK in case of an error, or 0xf if the information is not available). |
load | the current busload percentage (in the range [0..100], or 0xff if the information is not available). |
ec | the number of detected errors that led to the increase of one of the CAN controller internal error counters (in the range [0..0xfffe], or 0xffff if the information is not available). |
foc | the FIFO overrun counter (in the range [0..0xfffe], or 0xffff if the information is not available). |
coc | the CAN controller overrun counter (in the range [0..0xfffe], or 0xffff if the information is not available). |
int co_wtm_set_diag_wtm | ( | co_wtm_t * | wtm, |
uint_least8_t | quality | ||
) |
Sets the diagnostic parameters of a WTM interface.
wtm | a pointer to a CANopen WTM interface. |
quality | the link quality percentage (in the range [0..100], or 0xff if the information is not available). |
void co_wtm_get_diag_can_con | ( | const co_wtm_t * | wtm, |
co_wtm_diag_can_con_t ** | pcon, | ||
void ** | pdata | ||
) |
Retrieves the confirmation function invoked when a CAN communication quality response is received by a CANopen WTM interface.
wtm | a pointer to a CANopen WTM interface. |
pcon | the address at which to store a pointer to the confirmation function (can be NULL). |
pdata | the address at which to store a pointer to user-specified data (can be NULL). |
void co_wtm_set_diag_can_con | ( | co_wtm_t * | wtm, |
co_wtm_diag_can_con_t * | con, | ||
void * | data | ||
) |
Sets the confirmation function invoked when a CAN communication quality response is received by a CANopen WTM interface.
wtm | a pointer to a CANopen WTM interface. |
con | a pointer to the function to be invoked. |
data | a pointer to user-specified data (can be NULL). data is passed as the last parameter to con. |
void co_wtm_get_diag_wtm_con | ( | const co_wtm_t * | wtm, |
co_wtm_diag_wtm_con_t ** | pcon, | ||
void ** | pdata | ||
) |
Retrieves the confirmation function invoked when a WTM communication quality response is received by a CANopen WTM interface.
wtm | a pointer to a CANopen WTM interface. |
pcon | the address at which to store a pointer to the confirmation function (can be NULL). |
pdata | the address at which to store a pointer to user-specified data (can be NULL). |
void co_wtm_set_diag_wtm_con | ( | co_wtm_t * | wtm, |
co_wtm_diag_wtm_con_t * | con, | ||
void * | data | ||
) |
Sets the confirmation function invoked when a WTM communication quality response is received by a CANopen WTM interface.
wtm | a pointer to a CANopen WTM interface. |
con | a pointer to the function to be invoked. |
data | a pointer to user-specified data (can be NULL). data is passed as the last parameter to con. |
void co_wtm_get_diag_can_ind | ( | const co_wtm_t * | wtm, |
co_wtm_diag_can_ind_t ** | pcon, | ||
void ** | pdata | ||
) |
Retrieves the indication function invoked when a CAN communication quality reset message is received by a CANopen WTM interface.
wtm | a pointer to a CANopen WTM interface. |
pcon | the address at which to store a pointer to the indication function (can be NULL). |
pdata | the address at which to store a pointer to user-specified data (can be NULL). |
void co_wtm_set_diag_can_ind | ( | co_wtm_t * | wtm, |
co_wtm_diag_can_ind_t * | con, | ||
void * | data | ||
) |
Sets the indication function invoked when a CAN communication quality reset message is received by a CANopen WTM interface.
wtm | a pointer to a CANopen WTM interface. |
con | a pointer to the function to be invoked. |
data | a pointer to user-specified data (can be NULL). data is passed as the last parameter to con. |
void co_wtm_get_diag_wtm_ind | ( | const co_wtm_t * | wtm, |
co_wtm_diag_wtm_ind_t ** | pcon, | ||
void ** | pdata | ||
) |
Retrieves the indication function invoked when a WTM communication quality reset message is received by a CANopen WTM interface.
wtm | a pointer to a CANopen WTM interface. |
pcon | the address at which to store a pointer to the indication function (can be NULL). |
pdata | the address at which to store a pointer to user-specified data (can be NULL). |
void co_wtm_set_diag_wtm_ind | ( | co_wtm_t * | wtm, |
co_wtm_diag_wtm_ind_t * | con, | ||
void * | data | ||
) |
Sets the indication function invoked when a WTM communication quality reset message is received by a CANopen WTM interface.
wtm | a pointer to a CANopen WTM interface. |
con | a pointer to the function to be invoked. |
data | a pointer to user-specified data (can be NULL). data is passed as the last parameter to con. |
void co_wtm_get_diag_ac_ind | ( | const co_wtm_t * | wtm, |
co_wtm_diag_ac_ind_t ** | pind, | ||
void ** | pdata | ||
) |
Retrieves the indication function invoked when an abort code is generated or received by a CANopen WTM interface.
wtm | a pointer to a CANopen WTM interface. |
pind | the address at which to store a pointer to the indication function (can be NULL). |
pdata | the address at which to store a pointer to user-specified data (can be NULL). |
void co_wtm_set_diag_ac_ind | ( | co_wtm_t * | wtm, |
co_wtm_diag_ac_ind_t * | ind, | ||
void * | data | ||
) |
Sets the indication function invoked when an abort code is generated or received by a CANopen WTM interface.
wtm | a pointer to a CANopen WTM interface. |
ind | a pointer to the function to be invoked. If ind is NULL, the default indication function will be used (which invokes diag() ). |
data | a pointer to user-specified data (can be NULL). data is passed as the last parameter to ind. |
void co_wtm_recv | ( | co_wtm_t * | wtm, |
const void * | buf, | ||
size_t | nbytes | ||
) |
Receives and processes a byte stream with a CANopen WTM interface.
This function MAY invoke the callback function specified to co_wtm_set_recv_func() 0 or more times.
wtm | a pointer to a CANopen WTM interface. |
buf | a pointer to the bytes to be processed. |
nbytes | the number of bytes received. |
void co_wtm_get_recv_func | ( | const co_wtm_t * | wtm, |
co_wtm_recv_func_t ** | pfunc, | ||
void ** | pdata | ||
) |
Retrieves the callback function invoked when a CAN frame is received by a CANopen WTM interface.
wtm | a pointer to a CANopen WTM interface. |
pfunc | the address at which to store a pointer to the callback function (can be NULL). |
pdata | the address at which to store a pointer to user-specified data (can be NULL). |
void co_wtm_set_recv_func | ( | co_wtm_t * | wtm, |
co_wtm_recv_func_t * | func, | ||
void * | data | ||
) |
Sets the callback function invoked when a CAN frame is received by a CANopen WTM interface.
wtm | a pointer to a CANopen WTM interface. |
func | a pointer to the function to be invoked by co_wtm_recv(). |
data | a pointer to user-specified data (can be NULL). data is passed as the last parameter to func. |
int co_wtm_get_time | ( | const co_wtm_t * | wtm, |
uint_least8_t | nif, | ||
struct timespec * | tp | ||
) |
Retrieves the current time of a CANopen WTM interface.
wtm | a pointer to a CANopen WTM interface. |
nif | the CAN interface indicator (in the range [1..127]). |
tp | the address at which to store the current time (can be NULL). |
int co_wtm_set_time | ( | co_wtm_t * | wtm, |
uint_least8_t | nif, | ||
const struct timespec * | tp | ||
) |
Sets the current time of a CANopen WTM interface.
This function MAY invoke the callback function set by co_wtm_set_send_func().
wtm | a pointer to a CANopen WTM interface. |
nif | the CAN interface indicator (in the range [1..127]). |
tp | a pointer to the current time. |
Sends a CAN frame from a CANopen WTM interface.
This function MAY invoke the callback function set by co_wtm_set_send_func(). Note that no generic frames are sent until the send buffer is full. Sending a generic frame can be forced with co_wtm_flush().
wtm | a pointer to a CANopen WTM interface. |
nif | the CAN interface indicator (in the range [1..127]). |
msg | a pointer to the CAN frame to be sent. |
int co_wtm_send_alive | ( | co_wtm_t * | wtm | ) |
Sends a keep-alive message from a CANopen WTM interface.
This function MAY invoke the callback function set by co_wtm_set_send_func().
int co_wtm_send_diag_can_req | ( | co_wtm_t * | wtm, |
uint_least8_t | nif | ||
) |
Sends a CAN communication quality request.
The function specified to co_wtm_set_diag_can_con() is invoked if a response is received.
wtm | a pointer to a CANopen WTM interface. |
nif | the remote CAN interface indicator (in the range [1..127]). |
int co_wtm_send_diag_wtm_req | ( | co_wtm_t * | wtm, |
uint_least8_t | nif | ||
) |
Sends a WTM communication quality request.
The function specified to co_wtm_set_diag_wtm_con() is invoked if a response is received.
wtm | a pointer to a CANopen WTM interface. |
nif | the remote WTM interface indicator (in the range [1..127]). |
int co_wtm_send_diag_can_rst | ( | co_wtm_t * | wtm, |
uint_least8_t | nif | ||
) |
Sends a CAN communication quality reset message.
wtm | a pointer to a CANopen WTM interface. |
nif | the remote CAN interface indicator (in the range [1..127]). |
int co_wtm_send_diag_wtm_rst | ( | co_wtm_t * | wtm, |
uint_least8_t | nif | ||
) |
Sends a WTM communication quality reset message.
wtm | a pointer to a CANopen WTM interface. |
nif | the remote WTM interface indicator (in the range [1..127]). |
int co_wtm_send_diag_ac | ( | co_wtm_t * | wtm, |
uint_least32_t | ac | ||
) |
Sends a diagnostic abort message from a CANopen WTM interface.
This function MAY invoke the callback function set by co_wtm_set_send_func().
wtm | a pointer to a CANopen WTM interface. |
ac | the abort code. |
int co_wtm_flush | ( | co_wtm_t * | wtm | ) |
Flushes the current send buffer of a CANopen WTM interface.
This function MAY invoke the callback function set by co_wtm_set_send_func().
void co_wtm_get_send_func | ( | const co_wtm_t * | wtm, |
co_wtm_send_func_t ** | pfunc, | ||
void ** | pdata | ||
) |
Retrieves the callback function used to send byte streams from a CANopen WTM interface.
wtm | a pointer to a CANopen WTM interface. |
pfunc | the address at which to store a pointer to the callback function (can be NULL). |
pdata | the address at which to store a pointer to user-specified data (can be NULL). |
void co_wtm_set_send_func | ( | co_wtm_t * | wtm, |
co_wtm_send_func_t * | func, | ||
void * | data | ||
) |
Sets the callback function used to send byte streams from a CANopen WTM interface.
wtm | a pointer to a CANopen WTM interface. |
func | a pointer to the function to be invoked by co_wtm_send(). |
data | a pointer to user-specified data (can be NULL). data is passed as the last parameter to func. |