lib_emuc_2.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #ifndef __LIB_EMUC_2_H__
  2. #define __LIB_EMUC_2_H__
  3. #if defined(_WIN32)
  4. #define MAX_COM_NUM 256
  5. #else
  6. #define MAX_COM_NUM 68
  7. #endif
  8. #define VER_LEN 16
  9. #define CAN_NUM 2
  10. #define DATA_LEN 8
  11. #define DATA_LEN_ERR 6
  12. #define TIME_CHAR_NUM 13
  13. /*-----------------------------*/
  14. typedef struct
  15. {
  16. char fw [VER_LEN];
  17. char api [VER_LEN];
  18. char model[VER_LEN];
  19. } VER_INFO;
  20. /*-----------------------------*/
  21. typedef struct
  22. {
  23. int CAN_port;
  24. int flt_type;
  25. unsigned int flt_id;
  26. unsigned int mask;
  27. } FILTER_INFO;
  28. /*-----------------------------*/
  29. typedef struct
  30. {
  31. unsigned char baud [CAN_NUM];
  32. unsigned char mode [CAN_NUM];
  33. unsigned char flt_type[CAN_NUM];
  34. unsigned int flt_id [CAN_NUM];
  35. unsigned int flt_mask[CAN_NUM];
  36. unsigned char err_set;
  37. } CFG_INFO;
  38. /*-----------------------------*/
  39. typedef struct
  40. {
  41. int CAN_port;
  42. int id_type;
  43. int rtr;
  44. int dlc;
  45. int msg_type;
  46. char recv_time[TIME_CHAR_NUM]; /* e.g., 15:30:58:789 (h:m:s:ms) */
  47. unsigned int id;
  48. unsigned char data [DATA_LEN];
  49. unsigned char data_err [CAN_NUM][DATA_LEN_ERR];
  50. } CAN_FRAME_INFO;
  51. /*-----------------------------*/
  52. typedef struct
  53. {
  54. unsigned int cnt;
  55. unsigned int interval; /* [ms] */
  56. CAN_FRAME_INFO *can_frame_info;
  57. } NON_BLOCK_INFO;
  58. /*-----------------------------*/
  59. typedef struct
  60. {
  61. int com_port;
  62. int size_send;
  63. int size_rtn;
  64. unsigned char send_buf[256];
  65. unsigned char rtn_buf [256];
  66. } TEST_INFO;
  67. /* for "CAN_port" */
  68. /*-----------------------------*/
  69. enum
  70. {
  71. EMUC_CAN_1 = 0,
  72. EMUC_CAN_2
  73. };
  74. /* for "baud" */
  75. /*-----------------------------*/
  76. enum
  77. {
  78. EMUC_BAUDRATE_100K = 4,
  79. EMUC_BAUDRATE_125K,
  80. EMUC_BAUDRATE_250K,
  81. EMUC_BAUDRATE_500K,
  82. EMUC_BAUDRATE_800K,
  83. EMUC_BAUDRATE_1M
  84. };
  85. /* for "sts" */
  86. /*-----------------------------*/
  87. enum
  88. {
  89. EMUC_INACTIVE = 0,
  90. EMUC_ACTIVE
  91. };
  92. /* for "mode" */
  93. /*-----------------------------*/
  94. enum
  95. {
  96. EMUC_NORMAL = 0,
  97. EMUC_LISTEN
  98. };
  99. /* for "flt_type" & id_type */
  100. /*-----------------------------*/
  101. enum
  102. {
  103. EMUC_SID = 1,
  104. EMUC_EID
  105. };
  106. /* for "rtr" */
  107. /*-----------------------------*/
  108. enum
  109. {
  110. EMUC_DIS_RTR = 0,
  111. EMUC_EN_RTR
  112. };
  113. /* for "err_type" */
  114. /*-----------------------------*/
  115. enum
  116. {
  117. EMUC_DIS_ALL = 0,
  118. EMUC_EE_ERR,
  119. EMUC_BUS_ERR,
  120. EMUC_EN_ALL = 255
  121. };
  122. /* for "msg_type" */
  123. /*-----------------------------*/
  124. enum
  125. {
  126. EMUC_DATA_TYPE = 0,
  127. EMUC_EEERR_TYPE,
  128. EMUC_BUSERR_TYPE
  129. };
  130. /*-------------------------------------------------------------------------------------------------------*/
  131. #ifdef DEVELOPING_EMUC2
  132. int EMUCOpenDevice (int com_port);
  133. int EMUCCloseDevice (int com_port);
  134. int EMUCShowVer (int com_port, VER_INFO *ver_info);
  135. int EMUCResetCAN (int com_port);
  136. int EMUCClearFilter (int com_port, int CAN_port);
  137. int EMUCInitCAN (int com_port, int CAN1_sts, int CAN2_sts);
  138. int EMUCSetBaudRate (int com_port, int CAN1_baud, int CAN2_baud);
  139. int EMUCSetMode (int com_port, int CAN1_mode, int CAN2_mode);
  140. int EMUCSetFilter (int com_port, FILTER_INFO *filter_info);
  141. int EMUCSetErrorType (int com_port, int err_type);
  142. int EMUCGetCfg (int com_port, CFG_INFO *cfg_info);
  143. int EMUCExpCfg (int com_port, const char *file_name);
  144. int EMUCImpCfg (int com_port, const char *file_name);
  145. int EMUCSend (int com_port, CAN_FRAME_INFO *can_frame_info);
  146. int EMUCReceive (int com_port, CAN_FRAME_INFO *can_frame_info);
  147. int EMUCReceiveNonblock (int com_port, NON_BLOCK_INFO *non_block_info);
  148. #if defined(_WIN32) /* for C# */
  149. int EMUCReceiveNonblockCS (int com_port, unsigned int cnt, unsigned int interval, CAN_FRAME_INFO *can_frame_info);
  150. #endif
  151. /* Internal used */
  152. int EMUCGetCANStatus (int com_port, int *CAN1_sts, int *CAN2_sts);
  153. int EMUCGetBLDID (int com_port, unsigned char *BLD);
  154. int EMUCTesting (int com_port, TEST_INFO *test_info);
  155. #else
  156. #if defined(__linux__) || defined(__QNX__)
  157. extern int EMUCOpenDevice (int com_port);
  158. extern int EMUCCloseDevice (int com_port);
  159. extern int EMUCShowVer (int com_port, VER_INFO *ver_info);
  160. extern int EMUCResetCAN (int com_port);
  161. extern int EMUCClearFilter (int com_port, int CAN_port);
  162. extern int EMUCInitCAN (int com_port, int CAN1_sts, int CAN2_sts);
  163. extern int EMUCSetBaudRate (int com_port, int CAN1_baud, int CAN2_baud);
  164. extern int EMUCSetMode (int com_port, int CAN1_mode, int CAN2_mode);
  165. extern int EMUCSetFilter (int com_port, FILTER_INFO *filter_info);
  166. extern int EMUCSetErrorType (int com_port, int err_type);
  167. extern int EMUCGetCfg (int com_port, CFG_INFO *cfg_info);
  168. extern int EMUCExpCfg (int com_port, const char *file_name);
  169. extern int EMUCImpCfg (int com_port, const char *file_name);
  170. extern int EMUCSend (int com_port, CAN_FRAME_INFO *can_frame_info);
  171. extern int EMUCReceive (int com_port, CAN_FRAME_INFO *can_frame_info);
  172. extern int EMUCReceiveNonblock (int com_port, NON_BLOCK_INFO *non_block_info);
  173. #else
  174. typedef int(*EMUC_OPEN_DEVICE) (int com_port);
  175. typedef int(*EMUC_CLOSE_DEVICE) (int com_port);
  176. typedef int(*EMUC_SHOW_VER) (int com_port, VER_INFO *ver_info);
  177. typedef int(*EMUC_RESET_CAN) (int com_port);
  178. typedef int(*EMUC_CLEAR_FILTER) (int com_port, int CAN_port);
  179. typedef int(*EMUC_INIT_CAN) (int com_port, int CAN1_sts, int CAN2_sts);
  180. typedef int(*EMUC_SET_BAUDRATE) (int com_port, int CAN1_baud, int CAN2_baud);
  181. typedef int(*EMUC_SET_MODE) (int com_port, int CAN1_mode, int CAN2_mode);
  182. typedef int(*EMUC_SET_FILTER) (int com_port, FILTER_INFO *filter_info);
  183. typedef int(*EMUC_SET_ERROR_TYPE) (int com_port, int err_type);
  184. typedef int(*EMUC_GET_CFG) (int com_port, CFG_INFO *cfg_info);
  185. typedef int(*EMUC_EXP_CFG) (int com_port, const char *file_name);
  186. typedef int(*EMUC_IMP_CFG) (int com_port, const char *file_name);
  187. typedef int(*EMUC_SEND) (int com_port, CAN_FRAME_INFO *can_frame_info);
  188. typedef int(*EMUC_RECEIVE) (int com_port, CAN_FRAME_INFO *can_frame_info);
  189. typedef int(*EMUC_RECEIVE_NON_BLOCK)(int com_port, NON_BLOCK_INFO *non_block_info);
  190. EMUC_OPEN_DEVICE EMUCOpenDevice;
  191. EMUC_CLOSE_DEVICE EMUCCloseDevice;
  192. EMUC_SHOW_VER EMUCShowVer;
  193. EMUC_RESET_CAN EMUCResetCAN;
  194. EMUC_CLEAR_FILTER EMUCClearFilter;
  195. EMUC_INIT_CAN EMUCInitCAN;
  196. EMUC_SET_BAUDRATE EMUCSetBaudRate;
  197. EMUC_SET_MODE EMUCSetMode;
  198. EMUC_SET_FILTER EMUCSetFilter;
  199. EMUC_SET_ERROR_TYPE EMUCSetErrorType;
  200. EMUC_GET_CFG EMUCGetCfg;
  201. EMUC_EXP_CFG EMUCExpCfg;
  202. EMUC_IMP_CFG EMUCImpCfg;
  203. EMUC_SEND EMUCSend;
  204. EMUC_RECEIVE EMUCReceive;
  205. EMUC_RECEIVE_NON_BLOCK EMUCReceiveNonblock;
  206. #endif
  207. #endif
  208. /*-------------------------------------------------------------------------------------------------------*/
  209. #endif