1
0

libant.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except
  4. in compliance with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2016
  6. All rights reserved.
  7. */
  8. #include "types.h"
  9. #include "libant.h"
  10. #if defined(DSI_TYPES_WINDOWS)
  11. #include <windows.h>
  12. #define DYNAMIC_LIB_FILENAME "ANT_DLL.dll"
  13. #define DYNAMIC_LIB_INSTANCE HMODULE
  14. #define DYNAMIC_LIB_LOAD(X) LoadLibraryA(X)
  15. #define DYNAMIC_LIB_LOAD_PROC GetProcAddress
  16. #define DYNAMIC_LIB_CLOSE FreeLibrary
  17. #elif defined(DSI_TYPES_MACINTOSH) || defined(DSI_TYPES_LINUX)
  18. #include <dlfcn.h>
  19. #define DYNAMIC_LIB_FILENAME "libANT.dylib"
  20. #define DYNAMIC_LIB_INSTANCE void*
  21. #define DYNAMIC_LIB_LOAD(X) dlopen(X, RTLD_NOW)
  22. #define DYNAMIC_LIB_LOAD_PROC dlsym
  23. #define DYNAMIC_LIB_CLOSE dlclose
  24. #endif
  25. //////////////////////////////////////////////////////////////////////////////////
  26. // Public Variables
  27. //////////////////////////////////////////////////////////////////////////////////
  28. // Function Pointers
  29. P_ANT_INIT ANT_Init;
  30. P_ANT_INIT_EXT ANT_InitExt;
  31. P_ANT_GETDEVICEUSBINFO ANT_GetDeviceUSBInfo;
  32. P_ANT_GETDEVICEUSBPID ANT_GetDeviceUSBPID;
  33. P_ANT_GETDEVICEUSBVID ANT_GetDeviceUSBVID;
  34. P_ANT_CLOSE ANT_Close;
  35. P_ANT_ARF ANT_AssignResponseFunction;
  36. P_ANT_AEF ANT_AssignChannelEventFunction;
  37. P_ANT_UNASSIGN ANT_UnAssignChannel;
  38. P_ANT_ASSIGN ANT_AssignChannel;
  39. P_ANT_ASSIGN_EXT ANT_AssignChannelExt;
  40. P_ANT_SETID ANT_SetChannelId;
  41. P_ANT_SETPER ANT_SetChannelPeriod;
  42. P_ANT_SETTIME ANT_SetChannelSearchTimeout;
  43. P_ANT_SETFREQ ANT_SetChannelRFFreq;
  44. P_ANT_SETKEY ANT_SetNetworkKey;
  45. P_ANT_SETPWR ANT_SetTransmitPower;
  46. P_ANT_RST ANT_ResetSystem;
  47. P_ANT_OPENCHNL ANT_OpenChannel;
  48. P_ANT_CLOSECHNL ANT_CloseChannel;
  49. P_ANT_REQMSG ANT_RequestMessage;
  50. P_ANT_ENABLEEXT ANT_RxExtMesgsEnable;
  51. P_ANT_TX ANT_SendBroadcastData;
  52. P_ANT_TXA ANT_SendAcknowledgedData;
  53. P_ANT_TXB ANT_SendBurstTransfer;
  54. P_ANT_ADDID ANT_AddChannelID;
  55. P_ANT_CONFIGLIST ANT_ConfigList;
  56. P_ANT_CHANTXPWR ANT_SetChannelTxPower;
  57. P_ANT_LOWPRITIME ANT_SetLowPriorityChannelSearchTimeout;
  58. P_ANT_SERIALID ANT_SetSerialNumChannelId;
  59. P_ANT_SETLED ANT_EnableLED;
  60. P_ANT_SETCRYSTAL ANT_CrystalEnable;
  61. P_ANT_SETAGILITY ANT_ConfigFrequencyAgility;
  62. P_ANT_SETPROX ANT_SetProximitySearch;
  63. P_ANT_SETSCAN ANT_OpenRxScanMode;
  64. P_ANT_SETSLEEP ANT_SleepMessage;
  65. P_ANT_CWINIT ANT_InitCWTestMode;
  66. P_ANT_CWMODE ANT_SetCWTestMode;
  67. P_ANT_TXEXT ANT_SendExtBroadcastData;
  68. P_ANT_TXAEXT ANT_SendExtAcknowledgedData;
  69. P_ANT_TXBEXT ANT_SendExtBurstTransferPacket;
  70. P_ANT_BURSTTFR ANT_SendExtBurstTransfer;
  71. P_ANT_LIBVER ANT_LibVersion;
  72. P_ANT_NAP ANT_Nap;
  73. //////////////////////////////////////////////////////////////////////////////////
  74. // Private Variables
  75. //////////////////////////////////////////////////////////////////////////////////
  76. static DYNAMIC_LIB_INSTANCE hANTdll;
  77. static BOOL bLoaded = FALSE;
  78. //////////////////////////////////////////////////////////////////////////////////
  79. // Public Functions
  80. //////////////////////////////////////////////////////////////////////////////////
  81. ///////////////////////////////////////////////////////////////////////
  82. BOOL ANT_Load(void)
  83. {
  84. if (bLoaded)
  85. return TRUE;
  86. hANTdll = DYNAMIC_LIB_LOAD(DYNAMIC_LIB_FILENAME);
  87. if (hANTdll == NULL)
  88. return FALSE;
  89. ANT_Init = (P_ANT_INIT) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_Init");
  90. ANT_InitExt = (P_ANT_INIT_EXT)DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_InitExt");
  91. ANT_GetDeviceUSBInfo = (P_ANT_GETDEVICEUSBINFO) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_GetDeviceUSBInfo");
  92. ANT_GetDeviceUSBPID = (P_ANT_GETDEVICEUSBPID) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_GetDeviceUSBPID");
  93. ANT_GetDeviceUSBVID = (P_ANT_GETDEVICEUSBVID) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_GetDeviceUSBVID");
  94. ANT_Close = (P_ANT_CLOSE) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_Close");
  95. ANT_AssignResponseFunction = (P_ANT_ARF) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_AssignResponseFunction");
  96. ANT_AssignChannelEventFunction = (P_ANT_AEF) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_AssignChannelEventFunction");
  97. ANT_UnAssignChannel = (P_ANT_UNASSIGN) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_UnAssignChannel");
  98. ANT_AssignChannel = (P_ANT_ASSIGN) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_AssignChannel");
  99. ANT_AssignChannelExt = (P_ANT_ASSIGN_EXT) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_AssignChannelExt");
  100. ANT_SetChannelId =(P_ANT_SETID) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SetChannelId");
  101. ANT_SetChannelPeriod = (P_ANT_SETPER) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SetChannelPeriod");
  102. ANT_SetChannelSearchTimeout = (P_ANT_SETTIME) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SetChannelSearchTimeout");
  103. ANT_SetChannelRFFreq = (P_ANT_SETFREQ) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SetChannelRFFreq");
  104. ANT_SetNetworkKey = (P_ANT_SETKEY) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SetNetworkKey");
  105. ANT_SetTransmitPower = (P_ANT_SETPWR) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SetTransmitPower");
  106. ANT_ResetSystem = (P_ANT_RST) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_ResetSystem");
  107. ANT_OpenChannel = (P_ANT_OPENCHNL) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_OpenChannel");
  108. ANT_CloseChannel = (P_ANT_CLOSECHNL) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_CloseChannel");
  109. ANT_RequestMessage = (P_ANT_REQMSG) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_RequestMessage");
  110. ANT_RxExtMesgsEnable = (P_ANT_ENABLEEXT) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_RxExtMesgsEnable");
  111. ANT_SendBroadcastData = (P_ANT_TX) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SendBroadcastData");
  112. ANT_SendAcknowledgedData = (P_ANT_TXA) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SendAcknowledgedData");
  113. ANT_SendBurstTransfer = (P_ANT_TXB) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SendBurstTransfer");
  114. ANT_AddChannelID = (P_ANT_ADDID) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_AddChannelID");
  115. ANT_ConfigList = (P_ANT_CONFIGLIST) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_ConfigList");
  116. ANT_SetChannelTxPower = (P_ANT_CHANTXPWR) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SetChannelTxPower");
  117. ANT_SetLowPriorityChannelSearchTimeout = (P_ANT_LOWPRITIME) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SetLowPriorityChannelSearchTimeout");
  118. ANT_SetSerialNumChannelId = (P_ANT_SERIALID) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SetSerialNumChannelId");
  119. ANT_EnableLED = (P_ANT_SETLED) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_EnableLED");
  120. ANT_CrystalEnable = (P_ANT_SETCRYSTAL) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_CrystalEnable");
  121. ANT_ConfigFrequencyAgility = (P_ANT_SETAGILITY) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_ConfigFrequencyAgility");
  122. ANT_SetProximitySearch = (P_ANT_SETPROX) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SetProximitySearch");
  123. ANT_OpenRxScanMode = (P_ANT_SETSCAN) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_OpenRxScanMode");
  124. ANT_SleepMessage = (P_ANT_SETSLEEP) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SleepMessage");
  125. ANT_InitCWTestMode = (P_ANT_CWINIT) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_InitCWTestMode");
  126. ANT_SetCWTestMode = (P_ANT_CWMODE) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SetCWTestMode");
  127. ANT_SendExtBroadcastData = (P_ANT_TXEXT) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SendExtBroadcastData");
  128. ANT_SendExtAcknowledgedData = (P_ANT_TXAEXT) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SendExtAcknowledgedData");
  129. ANT_SendExtBurstTransferPacket = (P_ANT_TXBEXT) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SendExtBurstTransferPacket");
  130. ANT_SendExtBurstTransfer = (P_ANT_BURSTTFR) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_SendExtBurstTransfer");
  131. ANT_LibVersion = (P_ANT_LIBVER) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_LibVersion");
  132. ANT_Nap = (P_ANT_NAP) DYNAMIC_LIB_LOAD_PROC(hANTdll, "ANT_Nap");
  133. if (ANT_Init == NULL)
  134. return FALSE;
  135. if (ANT_InitExt == NULL)
  136. return FALSE;
  137. if (ANT_Close == NULL)
  138. return FALSE;
  139. if (ANT_AssignResponseFunction == NULL)
  140. return FALSE;
  141. if (ANT_AssignChannelEventFunction == NULL)
  142. return FALSE;
  143. if (ANT_UnAssignChannel == NULL)
  144. return FALSE;
  145. if (ANT_AssignChannel == NULL)
  146. return FALSE;
  147. if(ANT_AssignChannelExt == NULL)
  148. return FALSE;
  149. if (ANT_SetChannelId == NULL)
  150. return FALSE;
  151. if (ANT_SetChannelPeriod == NULL)
  152. return FALSE;
  153. if (ANT_SetChannelSearchTimeout == NULL)
  154. return FALSE;
  155. if (ANT_SetChannelRFFreq == NULL)
  156. return FALSE;
  157. if (ANT_SetNetworkKey == NULL)
  158. return FALSE;
  159. if (ANT_SetTransmitPower == NULL)
  160. return FALSE;
  161. if (ANT_ResetSystem == NULL)
  162. return FALSE;
  163. if (ANT_OpenChannel == NULL)
  164. return FALSE;
  165. if (ANT_CloseChannel == NULL)
  166. return FALSE;
  167. if (ANT_RequestMessage == NULL)
  168. return FALSE;
  169. if (ANT_SendBroadcastData == NULL)
  170. return FALSE;
  171. if (ANT_SendAcknowledgedData == NULL)
  172. return FALSE;
  173. if (ANT_SendBurstTransfer == NULL)
  174. return FALSE;
  175. if(ANT_RxExtMesgsEnable == NULL)
  176. return FALSE;
  177. if(ANT_AddChannelID == NULL)
  178. return FALSE;
  179. if(ANT_ConfigList == NULL)
  180. return FALSE;
  181. if(ANT_SetChannelTxPower == NULL)
  182. return FALSE;
  183. if(ANT_SetLowPriorityChannelSearchTimeout == NULL)
  184. return FALSE;
  185. if(ANT_SetSerialNumChannelId == NULL)
  186. return FALSE;
  187. if(ANT_EnableLED == NULL)
  188. return FALSE;
  189. if(ANT_CrystalEnable == NULL)
  190. return FALSE;
  191. if(ANT_ConfigFrequencyAgility == NULL)
  192. return FALSE;
  193. if(ANT_SetProximitySearch == NULL)
  194. return FALSE;
  195. if(ANT_OpenRxScanMode == NULL)
  196. return FALSE;
  197. if(ANT_SleepMessage == NULL)
  198. return FALSE;
  199. if(ANT_InitCWTestMode == NULL)
  200. return FALSE;
  201. if(ANT_SetCWTestMode == NULL)
  202. return FALSE;
  203. if(ANT_SendExtBroadcastData == NULL)
  204. return FALSE;
  205. if(ANT_SendExtAcknowledgedData == NULL)
  206. return FALSE;
  207. if(ANT_SendExtBurstTransferPacket == NULL)
  208. return FALSE;
  209. if(ANT_SendExtBurstTransfer == NULL)
  210. return FALSE;
  211. if(ANT_Nap == NULL)
  212. return FALSE;
  213. bLoaded = TRUE;
  214. return TRUE;
  215. }
  216. ///////////////////////////////////////////////////////////////////////
  217. void ANT_UnLoad(void)
  218. {
  219. if (hANTdll != NULL)
  220. {
  221. DYNAMIC_LIB_CLOSE(hANTdll);
  222. }
  223. bLoaded = FALSE;
  224. }
  225. ///////////////////////////////////////////////////////////////////////
  226. BOOL ANT_LibVersionSupport(void)
  227. {
  228. BOOL bLibVer = FALSE;
  229. if(hANTdll != NULL)
  230. {
  231. if(ANT_LibVersion != NULL)
  232. bLibVer = TRUE;
  233. }
  234. return bLibVer;
  235. }