AGHAF  4.5.5
Annecy electronique Generic Hardware Access Framework
DoCan_v2_FD/main.cpp
#include <iostream>
#include <vector>
#define AGHAF_DYNAMIC_LIBRARY_INIT
#include <aghaf.h>
void onMessageTx(uint64_t timestamp, uint32_t canIdent, uint8_t canFlags,
uint32_t dataLen, uint8_t const *data, void *userContext) {
(void)timestamp;
(void)canIdent;
(void)canFlags;
(void)dataLen;
(void)data;
(void)userContext;
}
void onMessageTxError(uint64_t timestamp, AGHAF_DoCan_Error error,
void *userContext) {
(void)timestamp;
(void)error;
(void)userContext;
}
void onMessageRx(uint64_t timestamp, uint32_t canIdent, uint8_t canFlags,
uint32_t dataLen, uint8_t const *data, void *userContext) {
(void)timestamp;
(void)canIdent;
(void)canFlags;
(void)dataLen;
(void)data;
(void)userContext;
}
void onMessageRxFF(uint64_t timestamp, uint32_t canIdent, uint8_t canFlags,
void *userContext) {
(void)timestamp;
(void)canIdent;
(void)canFlags;
(void)userContext;
}
void onMessageRxError(uint64_t timestamp, AGHAF_DoCan_Error error,
void *userContext) {
(void)timestamp;
(void)error;
(void)userContext;
}
int main() {
#ifdef _WIN32
AGHAF_loadLibrary(AGHAF_DEFAULT_FILENAME);
#endif
if (AGHAF_getDeviceCount() > 0) {
AGHAF_DeviceInfo *devicesInfo = nullptr;
uint32_t deviceInfoNumber = 0;
AGHAF_getDeviceList(&devicesInfo, &deviceInfoNumber);
AGHAF_Device device =
AGHAF_getDeviceBySN(devicesInfo[0].productNo, devicesInfo[0].serialNo);
AGHAF_freeDeviceList(devicesInfo);
if (AGHAF_CAN_v2_getCount(device) > 0) {
AGHAF_CAN can = AGHAF_CAN_v2_get(device, 0);
// BUS CAN FD -------------------------------
// --------------------------------------------
AGHAF_DoCAN_v2_setOnMessageTxCallback(channel, &onMessageTx, nullptr);
AGHAF_DoCAN_v2_setOnMessageTxErrorCallback(channel, &onMessageTxError,
nullptr);
AGHAF_DoCAN_v2_setOnMessageRxCallback(channel, &onMessageRx, nullptr);
AGHAF_DoCAN_v2_setOnMessageRxFFCallback(channel, &onMessageRxFF,
nullptr);
AGHAF_DoCAN_v2_setOnMessageRxErrorCallback(channel, &onMessageRxError,
nullptr);
std::vector<uint8_t> data;
data.push_back(0x01);
AGHAF_DoCAN_v2_Channel_send(channel, static_cast<uint32_t>(data.size()),
data.data());
} else {
std::cerr << "no CAN on this device" << '\n';
}
} else {
std::cerr << "device is used by another application" << '\n';
}
} else {
std::cerr << "no exxotest device connected" << '\n';
}
#ifdef _WIN32
AGHAF_unloadLibrary();
#endif
return 0;
}
@ CAN_PARAM_TERMINATION
Definition: aghaf_can_enums.h:184
@ CAN_PARAM_LISTEN_ONLY
Definition: aghaf_can_enums.h:178
@ CAN_PARAM_MODE
Definition: aghaf_can_enums.h:140
@ CAN_PARAM_BAUDRATE_FD
Definition: aghaf_can_enums.h:150
@ CAN_PARAM_BAUDRATE
Definition: aghaf_can_enums.h:145
@ AGHAF_CAN_MODE_FD
Definition: aghaf_can_enums.h:122
@ AGHAF_DoCAN_ID_FMT_XTD
Extended identifier (29-bit CAN ID)
Definition: aghaf_docan_enums.h:75
@ AGHAF_DoCAN_TX_DL_CLASSIC_CAN
CAN CC, TX_DL = 8.
Definition: aghaf_docan_enums.h:59
@ AGHAF_DoCAN_ADDR_MODE_PHYS
Physical.
Definition: aghaf_docan_enums.h:34
@ AGHAF_DoCAN_CHANNEL_DIR_2WAY
2-way channel
Definition: aghaf_docan_enums.h:42
@ AGHAF_DoCAN_CHANNEL_PARAM_TIMING_AR
Definition: aghaf_docan_enums.h:128
@ AGHAF_DoCAN_CHANNEL_PARAM_TIMING_BS
Definition: aghaf_docan_enums.h:133
@ AGHAF_DoCAN_CHANNEL_PARAM_TIMING_AS
Definition: aghaf_docan_enums.h:122
@ AGHAF_DoCAN_CHANNEL_PARAM_PAD_HANDLING
Definition: aghaf_docan_enums.h:103
@ AGHAF_DoCAN_CHANNEL_PARAM_TXDL
Definition: aghaf_docan_enums.h:98
@ AGHAF_DoCAN_CHANNEL_PARAM_REQ_ID_VALUE
Definition: aghaf_docan_enums.h:170
@ AGHAF_DoCAN_CHANNEL_PARAM_REQ_ID_FMT
Definition: aghaf_docan_enums.h:165
@ AGHAF_DoCAN_CHANNEL_PARAM_TIMING_STMIN
Definition: aghaf_docan_enums.h:160
@ AGHAF_DoCAN_CHANNEL_PARAM_ADDRMODE
Definition: aghaf_docan_enums.h:116
@ AGHAF_DoCAN_CHANNEL_PARAM_TIMING_BR
Definition: aghaf_docan_enums.h:139
@ AGHAF_DoCAN_CHANNEL_PARAM_BLOCKSIZE
Definition: aghaf_docan_enums.h:208
@ AGHAF_DoCAN_CHANNEL_PARAM_DIRECTION
Definition: aghaf_docan_enums.h:91
@ AGHAF_DoCAN_CHANNEL_PARAM_RESP_ID_VALUE
Definition: aghaf_docan_enums.h:189
@ AGHAF_DoCAN_CHANNEL_PARAM_RESP_ID_FMT
Definition: aghaf_docan_enums.h:180
@ AGHAF_DoCAN_CHANNEL_PARAM_TIMING_CR
Definition: aghaf_docan_enums.h:151
@ AGHAF_DoCAN_CHANNEL_PARAM_WAITFRAME
Definition: aghaf_docan_enums.h:200
@ AGHAF_DoCAN_CHANNEL_PARAM_PAD_VALUE
Definition: aghaf_docan_enums.h:110
@ AGHAF_DoCAN_CHANNEL_PARAM_MAXDATALEN
Definition: aghaf_docan_enums.h:213
@ AGHAF_DoCAN_CHANNEL_PARAM_TIMING_CS
Definition: aghaf_docan_enums.h:146
@ AGHAF_DoCAN_CHANNEL_PARAM_RESP_ID_AE
Definition: aghaf_docan_enums.h:194
@ AGHAF_DoCAN_CHANNEL_PARAM_REQ_ID_AE
Definition: aghaf_docan_enums.h:175
@ AGHAF_DoCAN_PAD_ENABLE
Enable padding handling.
Definition: aghaf_docan_enums.h:53
@ AGHAF_STATUS_OK
The operation succeeded.
Definition: aghaf_global.h:121
AGHAF_Status AGHAF_CAN_v2_setParam(AGHAF_CAN can, AGHAF_CAN_Param param, uint32_t value)
Set the value from a CAN parameter.
Definition: aghaf_can_v2.cpp:165
AGHAF_Status AGHAF_CAN_v2_activate(AGHAF_CAN can)
activate a CAN bus
Definition: aghaf_can_v2.cpp:116
AGHAF_CAN AGHAF_CAN_v2_get(AGHAF_Device device, uint8_t index)
return the CAN bus at index in parameter
Definition: aghaf_can_v2.cpp:86
uint8_t AGHAF_CAN_v2_getCount(AGHAF_Device device)
return the number of CAN bus from a device
Definition: aghaf_can_v2.cpp:106
void * AGHAF_CAN
handle on CAN
Definition: aghaf_can_v2.h:15
void AGHAF_CAN_v2_useAPI()
Inform the library tu use the V2 CAN API.
Definition: aghaf_can_v2.cpp:12
AGHAF_Status AGHAF_CAN_v2_deactivate(AGHAF_CAN can)
deactivate a CAN bus
Definition: aghaf_can_v2.cpp:126
void AGHAF_DoCAN_v2_setOnMessageRxErrorCallback(AGHAF_DoCAN_v2_Channel channel, AGHAF_DoCAN_onMessageRxError callback, void *userContext)
set the callback called on a reception error event
Definition: aghaf_docan_v2.cpp:70
AGHAF_Status AGHAF_DoCAN_v2_Channel_start(AGHAF_DoCAN_v2_Channel channel)
Start a channel.
Definition: aghaf_docan_v2.cpp:182
AGHAF_Status AGHAF_DoCAN_v2_Channel_setParam(AGHAF_DoCAN_v2_Channel channel, AGHAF_DoCAN_ChannelParam param, uint32_t value)
Set the parameter from a channel.
Definition: aghaf_docan_v2.cpp:154
void * AGHAF_DoCAN_v2_Channel
Handle to a DoCAN channel.
Definition: aghaf_docan_v2.h:23
AGHAF_Status AGHAF_DoCAN_v2_Channel_send(AGHAF_DoCAN_v2_Channel channel, uint32_t dataLen, uint8_t const *data)
Send on the DoCAN channel in parameter.
Definition: aghaf_docan_v2.cpp:206
void AGHAF_DoCAN_v2_setOnMessageTxErrorCallback(AGHAF_DoCAN_v2_Channel channel, AGHAF_DoCAN_onMessageTxError callback, void *userContext)
set the callback called on a transmission error event
Definition: aghaf_docan_v2.cpp:28
void AGHAF_DoCAN_v2_setOnMessageRxFFCallback(AGHAF_DoCAN_v2_Channel channel, AGHAF_DoCAN_onMessageRxFF callback, void *userContext)
set the callback called on the reception from a first frame event
Definition: aghaf_docan_v2.cpp:56
AGHAF_Status AGHAF_DoCAN_v2_releaseChannel(AGHAF_DoCAN_v2_Channel channel)
Release the channel.
Definition: aghaf_docan_v2.cpp:115
void AGHAF_DoCAN_v2_setOnMessageTxCallback(AGHAF_DoCAN_v2_Channel channel, AGHAF_DoCAN_onMessageTx callback, void *userContext)
set the callback called on a transmission event
Definition: aghaf_docan_v2.cpp:14
void AGHAF_DoCAN_v2_setOnMessageRxCallback(AGHAF_DoCAN_v2_Channel channel, AGHAF_DoCAN_onMessageRx callback, void *userContext)
set the callback called on a reception event
Definition: aghaf_docan_v2.cpp:42
AGHAF_Status AGHAF_DoCAN_v2_Channel_stop(AGHAF_DoCAN_v2_Channel channel)
Stop a channel.
Definition: aghaf_docan_v2.cpp:193
AGHAF_DoCan_Error
enumerator to describe the error on the bus
Definition: aghaf_docan_enums.h:16
AGHAF_DoCAN_Channel AGHAF_DoCAN_createChannel(AGHAF_DoCAN_Bus bus)
Create a channel.
Definition: aghaf_docan.cpp:81
uint32_t AGHAF_getDeviceCount()
Return the number of devices onnected.
Definition: aghaf_global.cpp:105
AGHAF_Status AGHAF_getDeviceList(AGHAF_DeviceInfo **devices, uint32_t *size)
Provide the list of devices connected.
Definition: aghaf_global.cpp:117
AGHAF_Device AGHAF_getDeviceBySN(const char *productNumber, const char *serialNumber)
Return the handle on the specified device.
Definition: aghaf_global.cpp:145
void AGHAF_freeDeviceList(AGHAF_DeviceInfo *devices)
Free the memory allocated with AGHAF_getDeviceList.
Definition: aghaf_global.cpp:126
void * AGHAF_Device
handle on an exxotest device
Definition: aghaf_global.h:175
AGHAF_Status AGHAF_closeDevice(AGHAF_Device device)
close the device
Definition: aghaf_global.cpp:241
AGHAF_Status AGHAF_openDevice(AGHAF_Device device)
Open a device.
Definition: aghaf_global.cpp:231
@ AGHAF_FALSE
false
Definition: aghaf_global.h:115
structure containing the informtions about a device
Definition: aghaf_global.h:215