AGHAF  4.5.4
Annecy electronique Generic Hardware Access Framework
DoCan_FD/main.cpp
#include <iostream>
#include <vector>
#define AGHAF_DYNAMIC_LIBRARY_INIT
#include <aghaf.h>
void doCanBus_1_callback(AGHAF_DoCAN_Event event, void *userContext) {
(void)userContext;
AGHAF_Status status = AGHAF_Event_getInfo(event, &info);
if (status == AGHAF_STATUS_OK) {
switch (info.type) {
break;
switch (eventType) {
std::cout << __FUNCTION__ << "AGHAF_DOCAN_EVENT_MSGTX"
<< reinterpret_cast<std::size_t>(channel) << std::endl;
break;
std::cout << __FUNCTION__ << "AGHAF_DoCAN_EVENT_MSGTXERR"
<< reinterpret_cast<std::size_t>(channel) << std::endl;
uint8_t error = AGHAF_DoCAN_Event_getError(event);
std::cout << static_cast<int>(error) << std::endl;
} break;
std::cout << __FUNCTION__ << "AGHAF_DoCAN_EVENT_MSGRX"
<< reinterpret_cast<std::size_t>(channel) << std::endl;
uint32_t size = AGHAF_DoCAN_Event_getDataSize(event);
auto *data = new uint8_t[size];
AGHAF_DoCAN_Event_getData(event, data, &size);
delete[] data;
} break;
std::cout << __FUNCTION__ << "AGHAF_DoCAN_MSGRXFF" << std::endl;
break;
std::cout << __FUNCTION__ << "AGHAF_DoCAN_EVENT_MSGRXERR"
<< reinterpret_cast<std::size_t>(channel) << std::endl;
uint8_t error = AGHAF_DoCAN_Event_getError(event);
std::cout << static_cast<int>(error) << std::endl;
} break;
}
} break;
}
}
}
void doCanBus_2_callback(AGHAF_CAN_Event event, void *userContext) {
(void)event;
(void)userContext;
}
int main() {
#ifdef _WIN32
AGHAF_loadLibrary(AGHAF_DEFAULT_FILENAME);
#endif
uint32_t count = AGHAF_getDeviceCount();
std::cout << count << std::endl;
if (count > 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);
AGHAF_CAN_Bus canBus = AGHAF_CAN_getBus(device, 0);
AGHAF_DoCAN_Bus doCanbus = AGHAF_DoCAN_getBus(device, 0);
// BUS CAN FD -------------------------------
// --------------------------------------------
AGHAF_DoCAN_registerCallback(doCanbus, &doCanBus_1_callback, nullptr);
0x06);
1000);
2500);
0);
1000);
0);
1000);
0);
0);
0);
0);
65537);
std::vector<uint8_t> data;
data.push_back(0x01);
AGHAF_DoCAN_Channel_send(channel, static_cast<uint32_t>(data.size()),
data.data());
AGHAF_DoCAN_deregisterCallback(doCanbus, &doCanBus_1_callback);
}
#ifdef _WIN32
AGHAF_unloadLibrary();
#endif
return 0;
}
@ CAN_PARAM_TERMINATION
Definition: aghaf_can_enums.h:123
@ CAN_PARAM_LISTEN_ONLY
Definition: aghaf_can_enums.h:117
@ CAN_PARAM_MODE
Definition: aghaf_can_enums.h:79
@ CAN_PARAM_BAUDRATE_FD
Definition: aghaf_can_enums.h:89
@ CAN_PARAM_BAUDRATE
Definition: aghaf_can_enums.h:84
@ AGHAF_CAN_MODE_FD
Definition: aghaf_can_enums.h:61
@ 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_TypeCanEvent
Event from CAN.
Definition: aghaf_global.h:202
@ AGHAF_TypeEthernetEvent
Event from Ethernet.
Definition: aghaf_global.h:201
@ AGHAF_TypeDoCanEvent
Event from DOCAN.
Definition: aghaf_global.h:203
@ AGHAF_TypeNoEvent
No event. Event is invalid.
Definition: aghaf_global.h:199
@ AGHAF_TypeDeviceEvent
Event from Device.
Definition: aghaf_global.h:200
AGHAF_Status AGHAF_CAN_Bus_deactivate(AGHAF_CAN_Bus bus)
deactivate a CAN bus
Definition: aghaf_can.cpp:175
void * AGHAF_CAN_Bus
handle to a CAN bus
Definition: aghaf_can.h:89
AGHAF_CAN_Bus AGHAF_CAN_getBus(AGHAF_Device device, uint8_t index)
return the CAN bus at index in parameter
Definition: aghaf_can.cpp:15
void * AGHAF_CAN_Event
Handle to a CAN event.
Definition: aghaf_can.h:95
AGHAF_Status AGHAF_CAN_Bus_setParam(AGHAF_CAN_Bus bus, AGHAF_CAN_Param param, uint32_t value)
Set the value from a CAN parameter.
Definition: aghaf_can.cpp:107
AGHAF_Status AGHAF_CAN_Bus_activate(AGHAF_CAN_Bus bus)
activate a CAN bus
Definition: aghaf_can.cpp:165
void * AGHAF_DoCAN_Bus
Handle to a DoCAN bus.
Definition: aghaf_docan.h:32
AGHAF_Status AGHAF_DoCAN_Channel_setParam(AGHAF_DoCAN_Channel channel, AGHAF_DoCAN_ChannelParam param, uint32_t value)
Set the parameter from a channel.
Definition: aghaf_docan.cpp:130
AGHAF_DoCAN_EventType
enumerator to tell the type of the event
Definition: aghaf_docan.h:23
AGHAF_DoCAN_Bus AGHAF_DoCAN_getBus(AGHAF_Device device, uint8_t index)
return the DoCAN bus at index in parameter
Definition: aghaf_docan.cpp:14
AGHAF_Status AGHAF_DoCAN_releaseChannel(AGHAF_DoCAN_Channel channel)
Release the channel.
Definition: aghaf_docan.cpp:91
void * AGHAF_DoCAN_Channel
Handle to a DoCAN channel.
Definition: aghaf_docan.h:38
uint32_t AGHAF_DoCAN_Event_getDataSize(AGHAF_DoCAN_Event event)
return the size from the datas in the event
Definition: aghaf_docan.cpp:225
AGHAF_Status AGHAF_DoCAN_Channel_stop(AGHAF_DoCAN_Channel channel)
Stop a channel.
Definition: aghaf_docan.cpp:169
AGHAF_DoCAN_EventType AGHAF_DoCAN_Event_type(AGHAF_EventInfo event)
return the type from the event
Definition: aghaf_docan.cpp:206
void AGHAF_DoCAN_deregisterCallback(AGHAF_DoCAN_Bus bus, AGHAF_DoCAN_Callback callback)
deregister a callback
Definition: aghaf_docan.cpp:47
AGHAF_DoCAN_Channel AGHAF_DoCAN_Event_getChannel(AGHAF_DoCAN_Event event)
Return the channel on which occured the event.
Definition: aghaf_docan.cpp:268
AGHAF_Status AGHAF_DoCAN_Channel_send(AGHAF_DoCAN_Channel channel, uint32_t dataLen, uint8_t const *data)
Send on the DoCAN channel in parameter.
Definition: aghaf_docan.cpp:182
void * AGHAF_DoCAN_Event
Handle to a DoCAN event.
Definition: aghaf_docan.h:35
AGHAF_Status AGHAF_DoCAN_Event_getData(AGHAF_DoCAN_Event event, uint8_t *data, uint32_t *size)
Provide the datas received in the event.
Definition: aghaf_docan.cpp:237
AGHAF_DoCAN_Channel AGHAF_DoCAN_createChannel(AGHAF_DoCAN_Bus bus)
Create a channel.
Definition: aghaf_docan.cpp:81
uint8_t AGHAF_DoCAN_Event_getError(AGHAF_DoCAN_Event event)
Return the error value from the event.
Definition: aghaf_docan.cpp:258
AGHAF_Status AGHAF_DoCAN_Channel_start(AGHAF_DoCAN_Channel channel)
Start a channel.
Definition: aghaf_docan.cpp:158
void AGHAF_DoCAN_registerCallback(AGHAF_DoCAN_Bus bus, AGHAF_DoCAN_Callback callback, void *userContext)
Register a callback for the DoCAN events from a bus.
Definition: aghaf_docan.cpp:35
@ AGHAF_DoCAN_EVENT_MSGRXFF
First Frame has been received.
Definition: aghaf_docan.h:27
@ AGHAF_DoCAN_EVENT_MSGRXERR
Reception error.
Definition: aghaf_docan.h:28
@ AGHAF_DoCAN_EVENT_MSGTX
End of transmission.
Definition: aghaf_docan.h:24
@ AGHAF_DoCAN_EVENT_MSGTXERR
Transmission Error.
Definition: aghaf_docan.h:25
@ AGHAF_DoCAN_EVENT_MSGRX
Message has been received.
Definition: aghaf_docan.h:26
uint32_t AGHAF_getDeviceCount()
Return the number of devices onnected.
Definition: aghaf_global.cpp:105
AGHAF_Status
enumerator to define the error type in aghaf functions
Definition: aghaf_global.h:120
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_Event_getInfo(AGHAF_Event event, AGHAF_EventInfo *info)
AGHAF_Event_getInfo.
Definition: aghaf_global.cpp:260
AGHAF_Status AGHAF_closeDevice(AGHAF_Device device)
close the device
Definition: aghaf_global.cpp:237
AGHAF_Status AGHAF_openDevice(AGHAF_Device device)
Open a device.
Definition: aghaf_global.cpp:227
@ AGHAF_FALSE
false
Definition: aghaf_global.h:115
structure containing the informtions about a device
Definition: aghaf_global.h:215
generic stucture to read an event in a callback
Definition: aghaf_global.h:229
AGHAF_TypeEvent type
Definition: aghaf_global.h:230