AGHAF  4.5.4
Annecy electronique Generic Hardware Access Framework
Can_FD/main.cpp
#include <vector>
#define AGHAF_DYNAMIC_LIBRARY_INIT
#include <aghaf.h>
void canBus_callback(AGHAF_CAN_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) {
break;
AGHAF_CAN_Frame_id(frame, &id);
int64_t size = AGHAF_CAN_Frame_dataSize(frame);
auto *data = new uint8_t[size];
AGHAF_CAN_Frame_data(frame, data, size);
delete[] data;
} break;
}
} break;
}
}
}
int main() {
#ifdef _WIN32
AGHAF_loadLibrary(AGHAF_DEFAULT_FILENAME);
#endif
uint32_t count = AGHAF_getDeviceCount();
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_CAN_registerCallback(canBus, &canBus_callback, nullptr);
// BUS CAN FD -------------------------------
// --------------------------------------------
std::vector<uint8_t> dataToSend;
dataToSend.push_back(0x01);
identifier.type = AGHAF_CAN_IdStd;
identifier.id.std = 0x100;
AGHAF_CAN_Frame_setId(frameToSend, &identifier);
AGHAF_CAN_Frame_setData(frameToSend, dataToSend.data(),
static_cast<uint32_t>(dataToSend.size()));
AGHAF_CAN_sendFrame(canBus, frameToSend);
AGHAF_CAN_Frame_delete(frameToSend);
AGHAF_CAN_deregisterCallback(canBus, &canBus_callback);
}
#ifdef _WIN32
AGHAF_unloadLibrary();
#endif
return 0;
}
@ AGHAF_CAN_EVENT_BUSCHANGE
Chip state has chaged active or passive error ou bus off.
Definition: aghaf_can.h:49
@ AGHAF_CAN_EVENT_ERROR
Bus error.
Definition: aghaf_can.h:48
@ AGHAF_CAN_EVENT_MSGRX
Message has been received.
Definition: aghaf_can.h:47
@ AGHAF_CAN_EVENT_BUSLOAD
Bus load information.
Definition: aghaf_can.h:51
@ AGHAF_CAN_EVENT_MSGTX
End of transmission.
Definition: aghaf_can.h:46
@ AGHAF_CAN_EVENT_UNKNOW
Unknown type of event.
Definition: aghaf_can.h:45
@ 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_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_CAN_Frame AGHAF_CAN_Frame_new()
Return a handle on a CAN frame.
Definition: aghaf_can.cpp:355
AGHAF_Status AGHAF_CAN_Bus_deactivate(AGHAF_CAN_Bus bus)
deactivate a CAN bus
Definition: aghaf_can.cpp:175
void AGHAF_CAN_deregisterCallback(AGHAF_CAN_Bus bus, AGHAF_CAN_Callback callback)
deregister a callback
Definition: aghaf_can.cpp:57
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
AGHAF_Status AGHAF_CAN_Frame_data(AGHAF_CAN_Frame frame, void *data, int64_t size)
Provide the data contained in a frame.
Definition: aghaf_can.cpp:486
AGHAF_CAN_EventType
enumerator to tell the type of the event
Definition: aghaf_can.h:44
AGHAF_CAN_Frame AGHAF_CAN_Event_frame(AGHAF_CAN_Event event)
return the frame contained in an event
Definition: aghaf_can.cpp:554
void AGHAF_CAN_registerCallback(AGHAF_CAN_Bus bus, AGHAF_CAN_Callback callback, void *userContext)
Register a callback for the CAN events from a bus.
Definition: aghaf_can.cpp:46
AGHAF_Status AGHAF_CAN_sendFrame(AGHAF_CAN_Bus bus, AGHAF_CAN_Frame frame)
send a frame on a CAN bus
Definition: aghaf_can.cpp:515
AGHAF_Status AGHAF_CAN_Frame_setId(AGHAF_CAN_Frame frame, AGHAF_CAN_Identifier *identifier)
Set the identifier from a CAN frame.
Definition: aghaf_can.cpp:372
AGHAF_Status AGHAF_CAN_Frame_setData(AGHAF_CAN_Frame frame, const void *data, int64_t size)
Set the data from a frame.
Definition: aghaf_can.cpp:469
AGHAF_Status AGHAF_CAN_Frame_id(AGHAF_CAN_Frame frame, AGHAF_CAN_Identifier *identifier)
Get the identifier from a CAN frame.
Definition: aghaf_can.cpp:385
void AGHAF_CAN_Frame_delete(AGHAF_CAN_Frame frame)
Free the memory from a CAN frame.
Definition: aghaf_can.cpp:361
int64_t AGHAF_CAN_Frame_dataSize(AGHAF_CAN_Frame frame)
return the size from the data
Definition: aghaf_can.cpp:504
AGHAF_Status AGHAF_CAN_Frame_setFDF(AGHAF_CAN_Frame frame, AGHAF_BOOL fdf, AGHAF_BOOL esi, AGHAF_BOOL brs)
AGHAF_CAN_Frame_setFDF.
Definition: aghaf_can.cpp:424
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_CAN_EventType AGHAF_CAN_typeEvent(AGHAF_EventInfo event)
return the type from the event
Definition: aghaf_can.cpp:564
AGHAF_Status AGHAF_CAN_Bus_activate(AGHAF_CAN_Bus bus)
activate a CAN bus
Definition: aghaf_can.cpp:165
void * AGHAF_CAN_Frame
Handle to a CAN frame.
Definition: aghaf_can.h:92
@ AGHAF_CAN_IdStd
Standard 11 bit identifier.
Definition: aghaf_can.h:23
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
@ AGHAF_TRUE
true
Definition: aghaf_global.h:116
structure to represent an indentifier CAN in the AGHAF library
Definition: aghaf_can.h:115
union AGHAF_CAN_Identifier::@0 id
Identifier.
uint16_t std
Standard identifier.
Definition: aghaf_can.h:118
AGHAF_CAN_IdentifierType type
Identifier type.
Definition: aghaf_can.h:116
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