AGHAF 5.0.9
Annecy electronique Generic Hardware Access Framework
Loading...
Searching...
No Matches
Can_FD/main.cpp
#define AGHAF_DYNAMIC_LIBRARY_INIT
#include <aghaf.h>
#include <iostream>
#include <vector>
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);
std::vector<uint8_t> data(size);
AGHAF_CAN_Frame_data(frame, data.data(), size);
} break;
}
} break;
}
}
}
int main() {
#ifdef _WIN32
AGHAF_loadLibrary(AGHAF_DEFAULT_FILENAME);
#endif
uint32_t deviceCount = 0;
AGHAF_getDeviceCount(&deviceCount);
if (deviceCount > 0) {
AGHAF_DeviceInfo* devicesInfo = nullptr;
uint32_t deviceInfoNumber = 0;
AGHAF_getDeviceList(&devicesInfo, &deviceInfoNumber);
AGHAF_Device device = nullptr;
AGHAF_getDeviceBySN(devicesInfo[0].productNo, devicesInfo[0].serialNo,
&device);
AGHAF_freeDeviceList(devicesInfo);
if (AGHAF_CAN_getBusCount(device) > 0) {
AGHAF_CAN_Bus can = AGHAF_CAN_getBus(device, 0);
AGHAF_CAN_registerCallback(can, &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(can, frameToSend);
AGHAF_CAN_Frame_delete(frameToSend);
AGHAF_CAN_deregisterCallback(can, &canBus_callback);
} else {
std::cerr << "no CAN on this device" << '\n';
}
} else {
std::cout << "device is used by another application" << '\n';
}
} else {
std::cerr << "no exxotest device connected" << '\n';
}
#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:48
@ AGHAF_CAN_EVENT_ERROR
Bus error.
Definition aghaf_can.h:47
@ AGHAF_CAN_EVENT_MSGRX
Message has been received.
Definition aghaf_can.h:46
@ AGHAF_CAN_EVENT_BUSLOAD
Bus load information.
Definition aghaf_can.h:50
@ AGHAF_CAN_EVENT_MSGTX
End of transmission.
Definition aghaf_can.h:45
@ AGHAF_CAN_EVENT_UNKNOW
Unknown type of event.
Definition aghaf_can.h:44
@ 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_STATUS_OK
The operation succeeded.
Definition aghaf_global.h:29
@ AGHAF_TypeCanEvent
Event from CAN.
Definition aghaf_global.h:114
@ AGHAF_TypeEthernetEvent
Event from Ethernet.
Definition aghaf_global.h:113
@ AGHAF_TypeDoCanEvent
Event from DOCAN.
Definition aghaf_global.h:115
@ AGHAF_TypeNoEvent
No event. Event is invalid.
Definition aghaf_global.h:111
@ AGHAF_TypeDeviceEvent
Event from Device.
Definition aghaf_global.h:112
AGHAF_Status AGHAF_CAN_Bus_deactivate(AGHAF_CAN_Bus bus)
deactivate a CAN bus
void AGHAF_CAN_deregisterCallback(AGHAF_CAN_Bus bus, AGHAF_CAN_Callback callback)
deregister a callback
void * AGHAF_CAN_Bus
handle to a CAN bus
Definition aghaf_can.h:54
AGHAF_CAN_Bus AGHAF_CAN_getBus(AGHAF_Device device, uint8_t index)
return the CAN bus at index in parameter
AGHAF_Status AGHAF_CAN_Frame_data(AGHAF_CAN_Frame frame, void *data, int64_t size)
Provide the data contained in a frame.
AGHAF_Status AGHAF_CAN_Bus_setParam(AGHAF_CAN_Bus bus, AGHAF_CAN_Param type, uint32_t value)
Set the value from a CAN parameter.
AGHAF_CAN_EventType
enumerator to tell the type of the event
Definition aghaf_can.h:43
AGHAF_CAN_Frame AGHAF_CAN_Event_frame(AGHAF_CAN_Event event)
return the frame contained in an event
void AGHAF_CAN_registerCallback(AGHAF_CAN_Bus bus, AGHAF_CAN_Callback callback, void *userContext)
Register a callback for the CAN events from a bus.
AGHAF_Status AGHAF_CAN_sendFrame(AGHAF_CAN_Bus bus, AGHAF_CAN_Frame frame)
send a frame on a CAN bus
AGHAF_Status AGHAF_CAN_Frame_setId(AGHAF_CAN_Frame frame, AGHAF_CAN_Identifier *identifier)
Set the identifier from a CAN frame.
AGHAF_CAN_Frame AGHAF_CAN_Frame_new(void)
Return a handle on a CAN frame.
AGHAF_Status AGHAF_CAN_Frame_setData(AGHAF_CAN_Frame frame, const void *data, int64_t size)
Set the data from a frame.
uint8_t AGHAF_CAN_getBusCount(AGHAF_Device device)
return the number of CAN bus from a device
AGHAF_Status AGHAF_CAN_Frame_id(AGHAF_CAN_Frame frame, AGHAF_CAN_Identifier *identifier)
Get the identifier from a CAN frame.
void AGHAF_CAN_Frame_delete(AGHAF_CAN_Frame frame)
Free the memory from a CAN frame.
int64_t AGHAF_CAN_Frame_dataSize(AGHAF_CAN_Frame frame)
return the size from the data
AGHAF_Status AGHAF_CAN_Frame_setFDF(AGHAF_CAN_Frame frame, AGHAF_BOOL fdf, AGHAF_BOOL esi, AGHAF_BOOL brs)
AGHAF_CAN_Frame_setFDF.
void * AGHAF_CAN_Event
Handle to a CAN event.
Definition aghaf_can.h:60
AGHAF_CAN_EventType AGHAF_CAN_typeEvent(AGHAF_EventInfo event)
return the type from the event
AGHAF_Status AGHAF_CAN_Bus_activate(AGHAF_CAN_Bus bus)
activate a CAN bus
void * AGHAF_CAN_Frame
Handle to a CAN frame.
Definition aghaf_can.h:57
@ AGHAF_CAN_IdStd
Standard 11 bit identifier.
Definition aghaf_can.h:22
AGHAF_Status AGHAF_getDeviceCount(uint32_t *count)
Return the number of devices onnected.
AGHAF_Status
enumerator to define the error type in aghaf functions
Definition aghaf_global.h:28
AGHAF_Status AGHAF_getDeviceList(AGHAF_DeviceInfo **devices, uint32_t *size)
Provide the list of devices connected.
void AGHAF_uninitialize(void)
Uninitialize Aghaf library.
void AGHAF_freeDeviceList(AGHAF_DeviceInfo *devices)
Free the memory allocated with AGHAF_getDeviceList.
void * AGHAF_Device
handle on an exxotest device
Definition aghaf_global.h:87
void AGHAF_initialize(void)
Initialize Aghaf library.
AGHAF_Status AGHAF_getDeviceBySN(char const *productNumber, char const *serialNumber, AGHAF_Device *device)
Return the handle on the specified device.
AGHAF_Status AGHAF_Event_getInfo(AGHAF_Event event, AGHAF_EventInfo *info)
AGHAF_Event_getInfo.
AGHAF_Status AGHAF_closeDevice(AGHAF_Device device)
close the device
AGHAF_Status AGHAF_openDevice(AGHAF_Device device)
Open a device.
@ AGHAF_FALSE
false
Definition aghaf_global.h:23
@ AGHAF_TRUE
true
Definition aghaf_global.h:24
structure to represent an indentifier CAN in the AGHAF library
Definition aghaf_can.h:80
union AGHAF_CAN_Identifier::@0 id
Identifier.
uint16_t std
Standard identifier.
Definition aghaf_can.h:83
AGHAF_CAN_IdentifierType type
Identifier type.
Definition aghaf_can.h:81
structure containing the informtions about a device
Definition aghaf_global.h:127
generic stucture to read an event in a callback
Definition aghaf_global.h:141
AGHAF_TypeEvent type
Definition aghaf_global.h:142