AGHAF  4.5.4
Annecy electronique Generic Hardware Access Framework
aghaf_global.h
Go to the documentation of this file.
1 // Copyright (c) 2019 by ANNECY ELECTRONIQUE, Chavanod, France
2 
6 
7 #ifndef EXXOTEST_AGHAF_GLOBAL_H
8 #define EXXOTEST_AGHAF_GLOBAL_H
9 
10 #if (defined(WIN64) || defined(_WIN64) || defined(__WIN64__))
11 #define AGHAF_OS_WIN
12 #define AGHAF_OS_WIN32
13 #define AGHAF_OS_WIN64
14 #elif (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || \
15  defined(__NT__))
16 #define AGHAF_OS_WIN
17 #define AGHAF_OS_WIN32
18 #elif defined(__ANDROID__) || defined(ANDROID)
19 #define AGHAF_OS_ANDROID
20 #define AGHAF_OS_LINUX
21 #elif (defined(__linux__) || defined(__linux))
22 #define AGHAF_OS_LINUX
23 #endif
24 
25 #if (defined(__aarch64__) || defined(__aarch64__) || defined(__amd64) || \
26  defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || \
27  defined(_M_X64) || defined(_M_AMD64))
28 #define AGHAF_PTR_SIZE 8
29 #else
30 #define AGHAF_PTR_SIZE 4
31 #endif
32 
33 #if ((defined(__SUNPRO_C) && __SUNPRO_C >= 0x570) || \
34  (defined(_MSC_VER) && _MSC_VER >= 1600) || \
35  (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && \
36  __STDC_VERSION__ >= 199901L) || \
37  (defined(__WATCOMC__) && \
38  (defined(_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || \
39  (defined(__GNUC__) && \
40  (__GNUC__ > 3 || defined(_STDINT_H) || defined(_STDINT_H_) || \
41  defined(__UINT_FAST64_TYPE__))))
42 #include <stdint.h>
43 #else
44 typedef unsigned char uint8_t;
45 typedef unsigned short uint16_t;
46 typedef unsigned int uint32_t;
47 typedef unsigned long long uint64_t;
48 #ifndef __BORLANDC__
49 typedef signed char int8_t;
50 #endif
51 typedef short int16_t;
52 typedef int int32_t;
53 typedef long long int64_t;
54 #if AGHAF_PTR_SIZE == 8
55 typedef uint64_t uintptr_t;
56 typedef int64_t intptr_t;
57 #elif AGHAF_PTR_SIZE == 4
58 typedef uint32_t uintptr_t;
59 typedef int32_t intptr_t;
60 #else
61 #error Unsupported pointer size
62 #endif
63 #endif
64 
65 #if defined(AGHAF_OS_WIN32) && !defined(AGHAF_OS_WIN64)
66 #define AGHAF_API __cdecl
67 #else
68 #define AGHAF_API
69 #endif
70 
71 // Macros used to declare public functions
72 #define AGHAF_PUBLIC_FUNCTION(ret, name, params) \
73  AGHAF_IMPORTEXPORT ret AGHAF_API name params
74 
75 #if defined(AGHAF_OS_WIN)
76 #ifdef AGHAF_LIBRARY
77 #define AGHAF_IMPORTEXPORT __declspec(dllexport)
78 #else
79 #ifdef AGHAF_DYNAMIC_LIBRARY
80 #ifdef AGHAF_DYNAMIC_LIBRARY_INIT
81 #define AGHAF_DYNAMIC_EXTERN
82 #define AGHAF_DYNAMIC_NULL = NULL
83 #else
84 #define AGHAF_DYNAMIC_EXTERN extern
85 #define AGHAF_DYNAMIC_NULL
86 #endif
87 #define AGHAF_IMPORTEXPORT typedef
88 #undef AGHAF_PUBLIC_FUNCTION
89 #define AGHAF_PUBLIC_FUNCTION(ret, name, params) \
90  AGHAF_IMPORTEXPORT ret(AGHAF_API *t##name) params; \
91  AGHAF_DYNAMIC_EXTERN t##name name AGHAF_DYNAMIC_NULL
92 #else
93 #define AGHAF_IMPORTEXPORT __declspec(dllimport)
94 #endif
95 #endif
96 #else
97 #define AGHAF_IMPORTEXPORT
98 #endif
99 
100 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
101 #define AGHAF_DEPRECATED_FOR(f) __attribute__((deprecated(#f "is deprecated.")))
102 #else
103 #define AGHAF_DEPRECATED_FOR(f)
104 #endif /* __GNUC__ */
105 
106 #ifdef __cplusplus
107 extern "C" {
108 #endif
109 
112 
114 typedef enum {
116  AGHAF_TRUE = 1
118 
120 typedef enum {
163  AGHAF_ERROR_NO_DATA = 0xff
166 
168 typedef enum {
171  AGHAF_ETH
173 
175 typedef void *AGHAF_Device;
176 
178 typedef void *AGHAF_Event;
179 
187 typedef void (*AGHAF_Callback)(AGHAF_Event event, void *userContext);
188 
190 typedef enum {
196 
198 typedef enum {
205 
208 typedef enum AGHAF_DeviceState {
213 
215 typedef struct AGHAF_DeviceInfo {
216  char name[64];
217  char productNo[64];
218  char serialNo[64];
219  uint16_t bootVersion;
221  uint16_t firmwareVersion;
223  char hardwareVersion[64];
225  uint8_t hardwareUniqueID[16];
227 
229 typedef struct AGHAF_EventInfo {
232  uint32_t event;
234  uint64_t timestamp;
236  AGHAF_BOOL
239 
240 AGHAF_PUBLIC_FUNCTION(uint32_t, AGHAF_getVersion, (void));
241 AGHAF_PUBLIC_FUNCTION(const char *, AGHAF_getVersionString, (void));
242 AGHAF_PUBLIC_FUNCTION(uint32_t, AGHAF_getServiceVersion, (void));
243 AGHAF_PUBLIC_FUNCTION(AGHAF_BOOL, AGHAF_isServiceRunning, (void));
244 
245 AGHAF_PUBLIC_FUNCTION(char const *, AGHAF_DeviceEvent_getProductName,
246  (AGHAF_Event event));
247 AGHAF_PUBLIC_FUNCTION(char const *, AGHAF_DeviceEvent_getProductNumber,
248  (AGHAF_Event event));
249 AGHAF_PUBLIC_FUNCTION(char const *, AGHAF_DeviceEvent_getSerialNumber,
250  (AGHAF_Event event));
251 AGHAF_PUBLIC_FUNCTION(uint8_t const *, AGHAF_DeviceEvent_getHardwareUniqueId,
252  (AGHAF_Event event));
253 
254 AGHAF_PUBLIC_FUNCTION(uint32_t, AGHAF_getDeviceCount, (void));
255 AGHAF_PUBLIC_FUNCTION(AGHAF_Status, AGHAF_getDeviceList,
256  (AGHAF_DeviceInfo * *devices, uint32_t *size));
257 AGHAF_PUBLIC_FUNCTION(void, AGHAF_freeDeviceList, (AGHAF_DeviceInfo * devices));
258 AGHAF_PUBLIC_FUNCTION(AGHAF_Status, AGHAF_refreshDeviceList, (void));
259 AGHAF_PUBLIC_FUNCTION(AGHAF_Device, AGHAF_getDeviceBySN,
260  (const char *productNumber, const char *serialNumber));
261 AGHAF_PUBLIC_FUNCTION(AGHAF_Device, AGHAF_getDeviceByHardID,
262  (uint8_t const *hardwareID));
263 AGHAF_PUBLIC_FUNCTION(AGHAF_Status, AGHAF_getDeviceInfo,
264  (AGHAF_Device device, AGHAF_DeviceInfo *deviceInfo));
265 
267  (AGHAF_Device device));
268 AGHAF_PUBLIC_FUNCTION(void, AGHAF_Device_getFriendlyNameEthCard,
269  (AGHAF_Device device, char **name));
270 AGHAF_PUBLIC_FUNCTION(void, AGHAF_Device_freeFriendlyName,
271  (char *friendlyName));
272 AGHAF_PUBLIC_FUNCTION(AGHAF_Status, AGHAF_Device_getUsbInfo,
273  (AGHAF_Device device, uint16_t *vid, uint16_t *pid,
274  uint16_t *rev));
275 
276 AGHAF_PUBLIC_FUNCTION(AGHAF_Status, AGHAF_openDevice, (AGHAF_Device device));
277 AGHAF_PUBLIC_FUNCTION(AGHAF_Status, AGHAF_closeDevice, (AGHAF_Device device));
278 AGHAF_PUBLIC_FUNCTION(AGHAF_Status, AGHAF_Device_getTimestamp,
279  (AGHAF_Device device, uint64_t *timestamp));
280 AGHAF_PUBLIC_FUNCTION(AGHAF_Status, AGHAF_Event_getInfo,
281  (AGHAF_Event event, AGHAF_EventInfo *info));
282 AGHAF_PUBLIC_FUNCTION(void, AGHAF_registerCallback,
283  (AGHAF_Callback callback, void *userContext));
284 AGHAF_PUBLIC_FUNCTION(void, AGHAF_deregisterCallback,
285  (AGHAF_Callback callback));
286 
288 
289 #ifdef __cplusplus
290 }
291 #endif
292 
293 #endif // EXXOTEST_AGHAF_GLOBAL_H
@ AGHAF_ERROR_BUSY
busy
Definition: aghaf_global.h:158
@ AGHAF_ERROR_SEQUENCE
sequence of function call is wrong
Definition: aghaf_global.h:155
@ AGHAF_ERROR_UNKNOWN
unknown error, contact your provider
Definition: aghaf_global.h:160
@ AGHAF_STATUS_OK
The operation succeeded.
Definition: aghaf_global.h:121
@ AGHAF_ERROR_NO_DATA
Definition: aghaf_global.h:163
@ AGHAF_ERROR_OUT_OF_MEMORY
Definition: aghaf_global.h:126
@ AGHAF_DEPRECATED
This error happens when a function is deprecated.
Definition: aghaf_global.h:154
@ AGHAF_ERROR_NOT_IMPLEMENTED
Definition: aghaf_global.h:129
@ AGHAF_ERROR_NOT_ENOUGH_MEMORY
Definition: aghaf_global.h:123
@ AGHAF_ERROR_NOT_ENOUGH_BUS
Definition: aghaf_global.h:147
@ AGHAF_WRONG_SERVICE_VERSION
Definition: aghaf_global.h:149
@ AGHAF_TIMEOUT_COM
Definition: aghaf_global.h:152
@ AGHAF_ERROR_PARAM
One or more parameters are invalid.
Definition: aghaf_global.h:122
@ AGHAF_ERROR_END_REACHED
Definition: aghaf_global.h:134
@ AGHAF_ERROR_WRONG_STATE
Definition: aghaf_global.h:145
@ AGHAF_ERROR_ALREADY_OPEN
device already opened
Definition: aghaf_global.h:157
@ AGHAF_ERROR_WRONG_SESSION_TYPE
Definition: aghaf_global.h:161
@ AGHAF_ERROR_FIFOFULL
intern fifo if full
Definition: aghaf_global.h:156
@ AGHAF_ERROR_BUS_NOT_FOUND
Definition: aghaf_global.h:142
@ AGHAF_INTERNAL_ERROR
There was an error in internal object management.
Definition: aghaf_global.h:139
@ AGHAF_ERROR_CONNECTION
Definition: aghaf_global.h:140
@ AGHAF_ERROR_PENDING
Internal use only.
Definition: aghaf_global.h:144
@ AGHAF_ERROR_NOMORECHANNEL
no more do can channels are available
Definition: aghaf_global.h:159
@ 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_Device_Present
A device was present.
Definition: aghaf_global.h:194
@ AGHAF_Device_Leave
A device was disconnected from this PC.
Definition: aghaf_global.h:193
@ AGHAF_Device_Arrival
A device was connected to this PC.
Definition: aghaf_global.h:192
@ AGHAF_Device_noEvent
No event. Event is invalid.
Definition: aghaf_global.h:191
@ AGHAF_DeviceState_ready
Device is ready to use.
Definition: aghaf_global.h:211
@ AGHAF_DeviceState_error
No state. Information is invalid.
Definition: aghaf_global.h:209
@ AGHAF_DeviceState_boot
Device is in boot state. no firmware detected.
Definition: aghaf_global.h:210
@ AGHAF_OFFLINE
The device is disconnected.
Definition: aghaf_global.h:169
@ AGHAF_ETH
The device is connected over a network (Ethernet of WiFi)
Definition: aghaf_global.h:171
@ AGHAF_USB
The device is connected using USB.
Definition: aghaf_global.h:170
uint32_t AGHAF_getDeviceCount(void)
Return the number of devices onnected.
Definition: aghaf_global.cpp:105
AGHAF_Status AGHAF_Device_getTimestamp(AGHAF_Device device, uint64_t *timestamp)
Return the current timestamp on the device.
Definition: aghaf_global.cpp:248
AGHAF_Status AGHAF_Device_getUsbInfo(AGHAF_Device device, uint16_t *vid, uint16_t *pid, uint16_t *rev)
AGHAF_Device_getUsbInfo.
Definition: aghaf_global.cpp:212
uint32_t AGHAF_getServiceVersion(void)
Return the version from aeds.
Definition: aghaf_global.cpp:33
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
const char * AGHAF_getVersionString(void)
Return the version from Aghaf.
Definition: aghaf_global.cpp:41
AGHAF_TypeEvent
type of event received in a callback
Definition: aghaf_global.h:198
char const * AGHAF_DeviceEvent_getProductName(AGHAF_Event event)
return the product name from the device which emitted the device event
Definition: aghaf_global.cpp:63
void AGHAF_Device_getFriendlyNameEthCard(AGHAF_Device device, char **name)
AGHAF_Device_getFriendlyNameEthCard.
Definition: aghaf_global.cpp:190
void AGHAF_deregisterCallback(AGHAF_Callback callback)
Deregister a callback.
Definition: aghaf_global.cpp:279
AGHAF_Device AGHAF_getDeviceBySN(const char *productNumber, const char *serialNumber)
Return the handle on the specified device.
Definition: aghaf_global.cpp:145
AGHAF_DeviceEvent
device event fot hotplug management
Definition: aghaf_global.h:190
void * AGHAF_Event
Typedef of a native event handle that can be used to wait for events.
Definition: aghaf_global.h:178
AGHAF_ConnectionMode AGHAF_Device_getConnectionMode(AGHAF_Device device)
AGHAF_Device_getConnectionMode.
Definition: aghaf_global.cpp:179
struct AGHAF_DeviceInfo AGHAF_DeviceInfo
structure containing the informtions about a device
AGHAF_Device AGHAF_getDeviceByHardID(uint8_t const *hardwareID)
AGHAF_getDeviceByHardID.
Definition: aghaf_global.cpp:155
AGHAF_BOOL
enumerator to get a bool definition
Definition: aghaf_global.h:114
void AGHAF_Device_freeFriendlyName(char *friendlyName)
Free the memory allocated with AGHAF_Device_getFriendlyNameEthCard.
Definition: aghaf_global.cpp:200
AGHAF_BOOL AGHAF_isServiceRunning(void)
Inform if ghaston is running or not.
Definition: aghaf_global.cpp:55
void AGHAF_freeDeviceList(AGHAF_DeviceInfo *devices)
Free the memory allocated with AGHAF_getDeviceList.
Definition: aghaf_global.cpp:126
AGHAF_Status AGHAF_getDeviceInfo(AGHAF_Device device, AGHAF_DeviceInfo *deviceInfo)
Return the informations from a device.
Definition: aghaf_global.cpp:167
AGHAF_Status AGHAF_refreshDeviceList(void)
Call the device event callbacks with the devices connected.
Definition: aghaf_global.cpp:134
void * AGHAF_Device
handle on an exxotest device
Definition: aghaf_global.h:175
void AGHAF_registerCallback(AGHAF_Callback callback, void *userContext)
Register a callback for the device event.
Definition: aghaf_global.cpp:271
struct AGHAF_EventInfo AGHAF_EventInfo
generic stucture to read an event in a callback
AGHAF_DeviceState
current state of the device (in the boot or in the application part of the firmware)
Definition: aghaf_global.h:208
char const * AGHAF_DeviceEvent_getSerialNumber(AGHAF_Event event)
return the serial number from the device which emitted the device event
Definition: aghaf_global.cpp:85
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_ConnectionMode
deprecated
Definition: aghaf_global.h:168
void(* AGHAF_Callback)(AGHAF_Event event, void *userContext)
callback for the devices hotplug management
Definition: aghaf_global.h:187
char const * AGHAF_DeviceEvent_getProductNumber(AGHAF_Event event)
return the product number from the device which emitted the device event
Definition: aghaf_global.cpp:74
uint8_t const * AGHAF_DeviceEvent_getHardwareUniqueId(AGHAF_Event event)
return the hardware unique id from the device which emitted the device event
Definition: aghaf_global.cpp:96
uint32_t AGHAF_getVersion(void)
Return the version from Aghaf.
Definition: aghaf_global.cpp:18
@ AGHAF_FALSE
false
Definition: aghaf_global.h:115
@ AGHAF_TRUE
true
Definition: aghaf_global.h:116
structure containing the informtions about a device
Definition: aghaf_global.h:215
char name[64]
Device name.
Definition: aghaf_global.h:216
char serialNo[64]
Serial number.
Definition: aghaf_global.h:218
uint16_t firmwareVersion
Definition: aghaf_global.h:221
char hardwareVersion[64]
Hardware version. in ASCII format.
Definition: aghaf_global.h:223
AGHAF_DeviceState deviceState
State of device.
Definition: aghaf_global.h:224
char productNo[64]
Product number (PPF).
Definition: aghaf_global.h:217
uint8_t hardwareUniqueID[16]
unique hardware id of the device.
Definition: aghaf_global.h:225
uint16_t bootVersion
Definition: aghaf_global.h:219
generic stucture to read an event in a callback
Definition: aghaf_global.h:229
uint64_t timestamp
Timestamp at which the event happened.
Definition: aghaf_global.h:234
AGHAF_TypeEvent type
Definition: aghaf_global.h:230
uint32_t event
Definition: aghaf_global.h:232
uint32_t timestampPrecision
Precision of timestamp.
Definition: aghaf_global.h:235
AGHAF_BOOL absolute
Define if the timestamp are absolute or relative.
Definition: aghaf_global.h:237