AGHAF  4.5.1
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);
devicesInfo[0].productNo,
devicesInfo[0].serialNo);
AGHAF_freeDeviceList(devicesInfo);
AGHAF_CAN_Bus canBus = AGHAF_CAN_getBus(device, 0);
&canBus_callback,
nullptr);
// BUS CAN FD -------------------------------
1000000);
5000000);
120);
// --------------------------------------------
std::vector<uint8_t> dataToSend;
dataToSend.push_back(0x01);
identifier.type = AGHAF_CAN_IdStd;
identifier.id.std = 0x100;
AGHAF_CAN_Frame_setId(frameToSend, &identifier);
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:50
@ 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:110
@ CAN_PARAM_LISTEN_ONLY
Definition: aghaf_can_enums.h:104
@ CAN_PARAM_MODE
Definition: aghaf_can_enums.h:66
@ CAN_PARAM_BAUDRATE_FD
Definition: aghaf_can_enums.h:76
@ CAN_PARAM_BAUDRATE
Definition: aghaf_can_enums.h:71
@ AGHAF_CAN_MODE_FD
Definition: aghaf_can_enums.h:48
@ AGHAF_STATUS_OK
The operation succeeded.
Definition: aghaf_global.h:110
@ AGHAF_TypeCanEvent
Event from CAN.
Definition: aghaf_global.h:174
@ AGHAF_TypeEthernetEvent
Event from Ethernet.
Definition: aghaf_global.h:173
@ AGHAF_TypeDoCanEvent
Event from DOCAN.
Definition: aghaf_global.h:175
@ AGHAF_TypeNoEvent
No event. Event is invalid.
Definition: aghaf_global.h:171
@ AGHAF_TypeDeviceEvent
Event from Device.
Definition: aghaf_global.h:172
AGHAF_CAN_Frame AGHAF_CAN_Frame_new()
Return a handle on a CAN frame.
Definition: aghaf_can.cpp:372
AGHAF_Status AGHAF_CAN_Bus_deactivate(AGHAF_CAN_Bus bus)
deactivate a CAN bus
Definition: aghaf_can.cpp:194
void AGHAF_CAN_deregisterCallback(AGHAF_CAN_Bus bus, AGHAF_CAN_Callback callback)
deregister a callback
Definition: aghaf_can.cpp:64
void * AGHAF_CAN_Bus
handle to a CAN bus
Definition: aghaf_can.h:82
AGHAF_CAN_Bus AGHAF_CAN_getBus(AGHAF_Device device, uint8_t index)
return the CAN bus at index in parameter
Definition: aghaf_can.cpp:16
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:509
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:587
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:50
AGHAF_Status AGHAF_CAN_sendFrame(AGHAF_CAN_Bus bus, AGHAF_CAN_Frame frame)
send a frame on a CAN bus
Definition: aghaf_can.cpp:539
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:393
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:492
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:406
void AGHAF_CAN_Frame_delete(AGHAF_CAN_Frame frame)
Free the memory from a CAN frame.
Definition: aghaf_can.cpp:381
int64_t AGHAF_CAN_Frame_dataSize(AGHAF_CAN_Frame frame)
return the size from the data
Definition: aghaf_can.cpp:527
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:445
void * AGHAF_CAN_Event
Handle to a CAN event.
Definition: aghaf_can.h:88
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:123
AGHAF_CAN_EventType AGHAF_CAN_typeEvent(AGHAF_EventInfo event)
return the type from the event
Definition: aghaf_can.cpp:598
AGHAF_Status AGHAF_CAN_Bus_activate(AGHAF_CAN_Bus bus)
activate a CAN bus
Definition: aghaf_can.cpp:183
void * AGHAF_CAN_Frame
Handle to a CAN frame.
Definition: aghaf_can.h:85
@ 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:111
AGHAF_Status
enumerator to define the error type in aghaf functions
Definition: aghaf_global.h:109
AGHAF_Status AGHAF_getDeviceList(AGHAF_DeviceInfo **devices, uint32_t *size)
Provide the list of devices connected.
Definition: aghaf_global.cpp:123
AGHAF_Device AGHAF_getDeviceBySN(const char *productNumber, const char *serialNumber)
Return the handle on the specified device.
Definition: aghaf_global.cpp:156
void AGHAF_freeDeviceList(AGHAF_DeviceInfo *devices)
Free the memory allocated with AGHAF_getDeviceList.
Definition: aghaf_global.cpp:135
void * AGHAF_Device
handle on an exxotest device
Definition: aghaf_global.h:145
AGHAF_Status AGHAF_Event_getInfo(AGHAF_Event event, AGHAF_EventInfo *info)
AGHAF_Event_getInfo.
Definition: aghaf_global.cpp:290
AGHAF_Status AGHAF_closeDevice(AGHAF_Device device)
close the device
Definition: aghaf_global.cpp:266
AGHAF_Status AGHAF_openDevice(AGHAF_Device device)
Open a device.
Definition: aghaf_global.cpp:255
@ AGHAF_FALSE
false
Definition: aghaf_global.h:103
@ AGHAF_TRUE
true
Definition: aghaf_global.h:104
structure to represent an indentifier CAN in the AGHAF library
Definition: aghaf_can.h:108
union AGHAF_CAN_Identifier::@0 id
Identifier.
uint16_t std
Standard identifier.
Definition: aghaf_can.h:111
AGHAF_CAN_IdentifierType type
Identifier type.
Definition: aghaf_can.h:109
structure containing the informtions about a device
Definition: aghaf_global.h:188
generic stucture to read an event in a callback
Definition: aghaf_global.h:201
AGHAF_TypeEvent type
Type information. Provide information about origin (device, can, ethernet...).
Definition: aghaf_global.h:202