AGHAF  4.5.1
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__) || defined(__NT__))
15 # define AGHAF_OS_WIN
16 # define AGHAF_OS_WIN32
17 #elif defined(__ANDROID__) || defined(ANDROID)
18 # define AGHAF_OS_ANDROID
19 # define AGHAF_OS_LINUX
20 #elif (defined(__linux__) || defined(__linux))
21 # define AGHAF_OS_LINUX
22 #endif
23 
24 # if (defined(__aarch64__) || defined(__aarch64__) || defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64))
25 # define AGHAF_PTR_SIZE 8
26 #else
27 # define AGHAF_PTR_SIZE 4
28 #endif
29 
30 #if ((defined(__SUNPRO_C) && __SUNPRO_C >= 0x570) || (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (__GNUC__ > 3 || defined(_STDINT_H) || defined(_STDINT_H_) || defined (__UINT_FAST64_TYPE__)) ))
31 # include <stdint.h>
32 #else
33  typedef unsigned char uint8_t;
34  typedef unsigned short uint16_t;
35  typedef unsigned int uint32_t;
36  typedef unsigned long long uint64_t;
37 # ifndef __BORLANDC__
38  typedef signed char int8_t;
39 # endif
40  typedef short int16_t;
41  typedef int int32_t;
42  typedef long long int64_t;
43 # if AGHAF_PTR_SIZE == 8
44  typedef uint64_t uintptr_t;
45  typedef int64_t intptr_t;
46 # elif AGHAF_PTR_SIZE == 4
47  typedef uint32_t uintptr_t;
48  typedef int32_t intptr_t;
49 # else
50 # error Unsupported pointer size
51 # endif
52 #endif
53 
54 #if defined(AGHAF_OS_WIN32) && !defined(AGHAF_OS_WIN64)
55 # define AGHAF_API __cdecl
56 #else
57 # define AGHAF_API
58 #endif
59 
60 // Macros used to declare public functions
61 #define AGHAF_PUBLIC_FUNCTION(ret, name, params ) AGHAF_IMPORTEXPORT ret AGHAF_API name params
62 
63 #if defined(AGHAF_OS_WIN)
64 # ifdef AGHAF_LIBRARY
65 # define AGHAF_IMPORTEXPORT __declspec(dllexport)
66 # else
67 # ifdef AGHAF_DYNAMIC_LIBRARY
68 # ifdef AGHAF_DYNAMIC_LIBRARY_INIT
69 # define AGHAF_DYNAMIC_EXTERN
70 # define AGHAF_DYNAMIC_NULL = NULL
71 # else
72 # define AGHAF_DYNAMIC_EXTERN extern
73 # define AGHAF_DYNAMIC_NULL
74 # endif
75 # define AGHAF_IMPORTEXPORT typedef
76 # undef AGHAF_PUBLIC_FUNCTION
77 # define AGHAF_PUBLIC_FUNCTION(ret, name, params) AGHAF_IMPORTEXPORT ret(AGHAF_API * t ## name) params; AGHAF_DYNAMIC_EXTERN t ## name name AGHAF_DYNAMIC_NULL
78 # else
79 # define AGHAF_IMPORTEXPORT __declspec(dllimport)
80 # endif
81 # endif
82 #else
83 # define AGHAF_IMPORTEXPORT
84 #endif
85 
86 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
87 #define AGHAF_DEPRECATED_FOR(f) \
88  __attribute__((deprecated(#f "is deprecated.")))
89 #else
90 #define AGHAF_DEPRECATED_FOR(f)
91 #endif /* __GNUC__ */
92 
93 #ifdef __cplusplus
94 extern "C" {
95 #endif
96 
99 
101 typedef enum
102 {
104  AGHAF_TRUE = 1
106 
108 typedef enum
109 {
132  AGHAF_ERROR_NO_DATA = 0xff
134 
136 typedef enum
137 {
140  AGHAF_ETH
142 
143 
145 typedef void * AGHAF_Device;
146 
148 typedef void * AGHAF_Event;
149 
157 typedef void (*AGHAF_Callback)(AGHAF_Event event, void *userContext);
158 
160 typedef enum
161 {
167 
169 typedef enum
170 {
177 
179 typedef enum AGHAF_DeviceState
180 {
185 
187 typedef struct AGHAF_DeviceInfo
188 {
189  char name[64];
190  char productNo[64];
191  char serialNo[64];
192  uint16_t bootVersion;
193  uint16_t firmwareVersion;
194  char hardwareVersion[64];
196  uint8_t hardwareUniqueID[16];
198 
200 typedef struct AGHAF_EventInfo
201 {
203  uint32_t event;
204  uint64_t timestamp;
208 
209 AGHAF_PUBLIC_FUNCTION(uint32_t, AGHAF_getVersion, (void));
210 AGHAF_PUBLIC_FUNCTION(const char*, AGHAF_getVersionString, (void));
211 AGHAF_PUBLIC_FUNCTION(uint32_t, AGHAF_getServiceVersion, (void));
212 AGHAF_PUBLIC_FUNCTION(AGHAF_BOOL, AGHAF_isServiceRunning, (void));
213 
214 AGHAF_PUBLIC_FUNCTION(char const*, AGHAF_DeviceEvent_getProductName, (AGHAF_Event event));
215 AGHAF_PUBLIC_FUNCTION(char const*, AGHAF_DeviceEvent_getProductNumber, (AGHAF_Event event));
216 AGHAF_PUBLIC_FUNCTION(char const*, AGHAF_DeviceEvent_getSerialNumber, (AGHAF_Event event));
217 AGHAF_PUBLIC_FUNCTION(uint8_t const*, AGHAF_DeviceEvent_getHardwareUniqueId, (AGHAF_Event event));
218 
219 AGHAF_PUBLIC_FUNCTION(uint32_t, AGHAF_getDeviceCount, (void));
220 AGHAF_PUBLIC_FUNCTION(AGHAF_Status, AGHAF_getDeviceList, (AGHAF_DeviceInfo **devices, uint32_t *size));
221 AGHAF_PUBLIC_FUNCTION(void, AGHAF_freeDeviceList, (AGHAF_DeviceInfo *devices));
222 AGHAF_PUBLIC_FUNCTION(AGHAF_Status, AGHAF_refreshDeviceList, (void));
223 AGHAF_PUBLIC_FUNCTION(AGHAF_Device, AGHAF_getDeviceBySN, (const char *productNumber, const char *serialNumber));
224 AGHAF_PUBLIC_FUNCTION(AGHAF_Device, AGHAF_getDeviceByHardID, (uint8_t const* hardwareID));
225 AGHAF_PUBLIC_FUNCTION(AGHAF_Status, AGHAF_getDeviceInfo, (AGHAF_Device device, AGHAF_DeviceInfo *deviceInfo));
226 
227 AGHAF_PUBLIC_FUNCTION(AGHAF_ConnectionMode, AGHAF_Device_getConnectionMode, (AGHAF_Device device));
228 AGHAF_PUBLIC_FUNCTION(void, AGHAF_Device_getFriendlyNameEthCard, (AGHAF_Device device, char **name));
229 AGHAF_PUBLIC_FUNCTION(void, AGHAF_Device_freeFriendlyName, (char *friendlyName));
230 AGHAF_PUBLIC_FUNCTION(AGHAF_Status, AGHAF_Device_getUsbInfo, (AGHAF_Device device, uint16_t *vid, uint16_t *pid, uint16_t *rev));
231 
232 AGHAF_PUBLIC_FUNCTION(AGHAF_Status, AGHAF_openDevice, (AGHAF_Device device));
233 AGHAF_PUBLIC_FUNCTION(AGHAF_Status, AGHAF_closeDevice, (AGHAF_Device device));
234 AGHAF_PUBLIC_FUNCTION(AGHAF_Status, AGHAF_Device_getTimestamp, (AGHAF_Device device, uint64_t *timestamp));
235 AGHAF_PUBLIC_FUNCTION(AGHAF_Status, AGHAF_Event_getInfo, (AGHAF_Event event, AGHAF_EventInfo *info));
236 AGHAF_PUBLIC_FUNCTION(void, AGHAF_registerCallback, (AGHAF_Callback callback, void * userContext));
237 AGHAF_PUBLIC_FUNCTION(void, AGHAF_deregisterCallback, (AGHAF_Callback callback));
238 
240 
241 #ifdef __cplusplus
242 }
243 #endif
244 
245 
246 #endif // EXXOTEST_AGHAF_GLOBAL_H
@ AGHAF_ERROR_BUSY
busy
Definition: aghaf_global.h:128
@ AGHAF_ERROR_SEQUENCE
sequence of function call is wrong
Definition: aghaf_global.h:125
@ AGHAF_ERROR_UNKNOWN
unknown error, contact your provider
Definition: aghaf_global.h:130
@ AGHAF_STATUS_OK
The operation succeeded.
Definition: aghaf_global.h:110
@ AGHAF_ERROR_NO_DATA
This error happens when a problem occur between this library and service.
Definition: aghaf_global.h:132
@ AGHAF_ERROR_OUT_OF_MEMORY
This is an internal error meaning that the library or its underlying elements have run out of memory.
Definition: aghaf_global.h:113
@ AGHAF_DEPRECATED
This error happens when a function is deprecated.
Definition: aghaf_global.h:124
@ AGHAF_ERROR_NOT_IMPLEMENTED
The function is not yet implemented. This error probably means that you are using an unstable develop...
Definition: aghaf_global.h:114
@ AGHAF_ERROR_NOT_ENOUGH_MEMORY
Not enough memory. Generally means that the output buffer of a function is too small to hold all the ...
Definition: aghaf_global.h:112
@ AGHAF_ERROR_NOT_ENOUGH_BUS
This error happens when user try to access a wrong AGHAF_DoCAN_Bus.
Definition: aghaf_global.h:121
@ AGHAF_WRONG_SERVICE_VERSION
This error happens when the service is not compatible with the version of this library.
Definition: aghaf_global.h:122
@ AGHAF_TIMEOUT_COM
This error happens when service take too long time to response.
Definition: aghaf_global.h:123
@ AGHAF_ERROR_PARAM
One or more parameters are invalid.
Definition: aghaf_global.h:111
@ AGHAF_ERROR_END_REACHED
There was not enough elements left and the end has been reached. This error happens when trying to ac...
Definition: aghaf_global.h:115
@ AGHAF_ERROR_WRONG_STATE
This error happens when user call function in wrong state.
Definition: aghaf_global.h:120
@ AGHAF_ERROR_ALREADY_OPEN
device already opened
Definition: aghaf_global.h:127
@ AGHAF_ERROR_WRONG_SESSION_TYPE
the type of the session does not match the function called
Definition: aghaf_global.h:131
@ AGHAF_ERROR_FIFOFULL
intern fifo if full
Definition: aghaf_global.h:126
@ AGHAF_ERROR_BUS_NOT_FOUND
This error happens when trying to access a bus or device with a invalid handle.
Definition: aghaf_global.h:118
@ AGHAF_INTERNAL_ERROR
There was an error in internal object management.
Definition: aghaf_global.h:116
@ AGHAF_ERROR_CONNECTION
This error happens when communication with service is lost.
Definition: aghaf_global.h:117
@ AGHAF_ERROR_PENDING
Internal use only.
Definition: aghaf_global.h:119
@ AGHAF_ERROR_NOMORECHANNEL
no more do can channels are available
Definition: aghaf_global.h:129
@ 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_Device_Present
A device was present.
Definition: aghaf_global.h:165
@ AGHAF_Device_Leave
A device was disconnected from this PC.
Definition: aghaf_global.h:164
@ AGHAF_Device_Arrival
A device was connected to this PC.
Definition: aghaf_global.h:163
@ AGHAF_Device_noEvent
No event. Event is invalid.
Definition: aghaf_global.h:162
@ AGHAF_DeviceState_ready
Device is ready to use.
Definition: aghaf_global.h:183
@ AGHAF_DeviceState_error
No state. Information is invalid.
Definition: aghaf_global.h:181
@ AGHAF_DeviceState_boot
Device is in boot state. no firmware detected.
Definition: aghaf_global.h:182
@ AGHAF_OFFLINE
The device is disconnected.
Definition: aghaf_global.h:138
@ AGHAF_ETH
The device is connected over a network (Ethernet of WiFi)
Definition: aghaf_global.h:140
@ AGHAF_USB
The device is connected using USB.
Definition: aghaf_global.h:139
uint32_t AGHAF_getDeviceCount(void)
Return the number of devices onnected.
Definition: aghaf_global.cpp:111
AGHAF_Status AGHAF_Device_getTimestamp(AGHAF_Device device, uint64_t *timestamp)
Return the current timestamp on the device.
Definition: aghaf_global.cpp:278
AGHAF_Status AGHAF_Device_getUsbInfo(AGHAF_Device device, uint16_t *vid, uint16_t *pid, uint16_t *rev)
AGHAF_Device_getUsbInfo.
Definition: aghaf_global.cpp:236
uint32_t AGHAF_getServiceVersion(void)
Return the version from aeds.
Definition: aghaf_global.cpp:34
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
const char * AGHAF_getVersionString(void)
Return the version from Aghaf.
Definition: aghaf_global.cpp:43
AGHAF_TypeEvent
type of event received in a callback
Definition: aghaf_global.h:170
char const * AGHAF_DeviceEvent_getProductName(AGHAF_Event event)
return the product name from the device which emitted the device event
Definition: aghaf_global.cpp:68
void AGHAF_Device_getFriendlyNameEthCard(AGHAF_Device device, char **name)
AGHAF_Device_getFriendlyNameEthCard.
Definition: aghaf_global.cpp:210
void AGHAF_deregisterCallback(AGHAF_Callback callback)
Deregister a callback.
Definition: aghaf_global.cpp:311
AGHAF_Device AGHAF_getDeviceBySN(const char *productNumber, const char *serialNumber)
Return the handle on the specified device.
Definition: aghaf_global.cpp:156
AGHAF_DeviceEvent
device event fot hotplug management
Definition: aghaf_global.h:161
void * AGHAF_Event
Typedef of a native event handle that can be used to wait for events.
Definition: aghaf_global.h:148
AGHAF_ConnectionMode AGHAF_Device_getConnectionMode(AGHAF_Device device)
AGHAF_Device_getConnectionMode.
Definition: aghaf_global.cpp:197
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:170
AGHAF_BOOL
enumerator to get a bool definition
Definition: aghaf_global.h:102
void AGHAF_Device_freeFriendlyName(char *friendlyName)
Free the memory allocated with AGHAF_Device_getFriendlyNameEthCard.
Definition: aghaf_global.cpp:223
AGHAF_BOOL AGHAF_isServiceRunning(void)
Inform if ghaston is running or not.
Definition: aghaf_global.cpp:58
void AGHAF_freeDeviceList(AGHAF_DeviceInfo *devices)
Free the memory allocated with AGHAF_getDeviceList.
Definition: aghaf_global.cpp:135
AGHAF_Status AGHAF_getDeviceInfo(AGHAF_Device device, AGHAF_DeviceInfo *deviceInfo)
Return the informations from a device.
Definition: aghaf_global.cpp:183
AGHAF_Status AGHAF_refreshDeviceList(void)
Call the device event callbacks with the devices connected.
Definition: aghaf_global.cpp:144
void * AGHAF_Device
handle on an exxotest device
Definition: aghaf_global.h:145
void AGHAF_registerCallback(AGHAF_Callback callback, void *userContext)
Register a callback for the device event.
Definition: aghaf_global.cpp:302
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:180
char const * AGHAF_DeviceEvent_getSerialNumber(AGHAF_Event event)
return the serial number from the device which emitted the device event
Definition: aghaf_global.cpp:90
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_ConnectionMode
deprecated
Definition: aghaf_global.h:137
void(* AGHAF_Callback)(AGHAF_Event event, void *userContext)
callback for the devices hotplug management
Definition: aghaf_global.h:157
char const * AGHAF_DeviceEvent_getProductNumber(AGHAF_Event event)
return the product number from the device which emitted the device event
Definition: aghaf_global.cpp:79
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:101
uint32_t AGHAF_getVersion(void)
Return the version from Aghaf.
Definition: aghaf_global.cpp:18
@ AGHAF_FALSE
false
Definition: aghaf_global.h:103
@ AGHAF_TRUE
true
Definition: aghaf_global.h:104
structure containing the informtions about a device
Definition: aghaf_global.h:188
char name[64]
Device name.
Definition: aghaf_global.h:189
char serialNo[64]
Serial number.
Definition: aghaf_global.h:191
uint16_t firmwareVersion
Firmware version. Value was coded in BCD. sample : 0x0224 : V2.24.
Definition: aghaf_global.h:193
char hardwareVersion[64]
Hardware version. in ASCII format.
Definition: aghaf_global.h:194
AGHAF_DeviceState deviceState
State of device.
Definition: aghaf_global.h:195
char productNo[64]
Product number (PPF).
Definition: aghaf_global.h:190
uint8_t hardwareUniqueID[16]
unique hardware id of the device.
Definition: aghaf_global.h:196
uint16_t bootVersion
Boot firmware version. Value was coded in BCD. sample : 0x0113 : V1.13.
Definition: aghaf_global.h:192
generic stucture to read an event in a callback
Definition: aghaf_global.h:201
uint64_t timestamp
Timestamp at which the event happened.
Definition: aghaf_global.h:204
AGHAF_TypeEvent type
Type information. Provide information about origin (device, can, ethernet...).
Definition: aghaf_global.h:202
uint32_t event
Event information. Provide information about event type ( event tx, event rx, device connected....
Definition: aghaf_global.h:203
uint32_t timestampPrecision
Precision of timestamp.
Definition: aghaf_global.h:205
AGHAF_BOOL absolute
Define if the timestamp are absolute or relative.
Definition: aghaf_global.h:206