194 for (index = 0; index < br_lut_size; ++index) |
194 for (index = 0; index < br_lut_size; ++index) |
195 { |
195 { |
196 if (::strcmp(br_lut[index].baud_rate,baud_rate)==0) |
196 if (::strcmp(br_lut[index].baud_rate,baud_rate)==0) |
197 break; |
197 break; |
198 } |
198 } |
199 if (index == br_lut_size) |
199 if (index == br_lut_size) |
|
200 { |
|
201 MSG_ERR_DRV("IXXAT::open: The given baudrate %s is invalid.", baud_rate); |
200 return false; |
202 return false; |
|
203 } |
201 // close existing board |
204 // close existing board |
202 close(); |
205 close(); |
203 // init IXXAT board |
206 // init IXXAT board |
204 unsigned long board_type = VCI_GetBrdTypeByName(const_cast<char*>(board_name)); |
207 unsigned long board_type = VCI_GetBrdTypeByName(const_cast<char*>(board_name)); |
205 long res = VCI2_PrepareBoard( board_type, // board type |
208 long res = VCI2_PrepareBoard( board_type, // board type |
208 0, // length of additional info buffer |
211 0, // length of additional info buffer |
209 message_handler, // pointer to msg-callbackhandler |
212 message_handler, // pointer to msg-callbackhandler |
210 receive_queuedata_handler, // pointer to receive-callbackhandler |
213 receive_queuedata_handler, // pointer to receive-callbackhandler |
211 exception_handler); // pointer to exception-callbackhandler |
214 exception_handler); // pointer to exception-callbackhandler |
212 if (res < 0) |
215 if (res < 0) |
|
216 { |
|
217 MSG_ERR_DRV("IXXAT::open: VCI2_PrepareBoard failed with code '%d'.", res); |
213 return false; |
218 return false; |
|
219 } |
214 m_BoardHdl = (UINT16)res; |
220 m_BoardHdl = (UINT16)res; |
215 |
221 |
216 VCI_ResetBoard(m_BoardHdl); |
222 VCI_ResetBoard(m_BoardHdl); |
217 |
223 |
218 // init CAN parameters |
224 // init CAN parameters |
265 m_callbackPtr->receive_queuedata(que_hdl, count, p_obj); |
271 m_callbackPtr->receive_queuedata(que_hdl, count, p_obj); |
266 } |
272 } |
267 |
273 |
268 void VCI_CALLBACKATTR IXXAT::message_handler(char *msg_str) |
274 void VCI_CALLBACKATTR IXXAT::message_handler(char *msg_str) |
269 { |
275 { |
270 char buf[200]; |
276 MSG_ERR_DRV("IXXAT Message: [%s]\n", msg_str); |
271 ::sprintf(buf,"IXXAT Message: [%s]\n", msg_str); |
|
272 ::OutputDebugString(buf); |
|
273 } |
277 } |
274 |
278 |
275 void VCI_CALLBACKATTR IXXAT::exception_handler(VCI_FUNC_NUM func_num, INT32 err_code, UINT16 ext_err, char* err_str) |
279 void VCI_CALLBACKATTR IXXAT::exception_handler(VCI_FUNC_NUM func_num, INT32 err_code, UINT16 ext_err, char* err_str) |
276 { |
280 { |
277 static const char* Num2Function[] = |
281 static const char* Num2Function[] = |
303 "VCI_TransmitObj", |
307 "VCI_TransmitObj", |
304 "VCI_RequestObj", |
308 "VCI_RequestObj", |
305 "VCI_UpdateBufObj", |
309 "VCI_UpdateBufObj", |
306 "VCI_CciReqData" |
310 "VCI_CciReqData" |
307 }; |
311 }; |
308 char buf[200]; |
312 |
309 ::sprintf(buf, "IXXAT Exception: %s (%i / %u) [%s]\n", Num2Function[func_num], err_code, ext_err, err_str); |
313 MSG_ERR_DRV("IXXAT Exception: %s (%i / %u) [%s]\n", Num2Function[func_num], err_code, ext_err, err_str); |
310 ::OutputDebugString(buf); |
|
311 } |
314 } |
312 |
315 |
313 void IXXAT::watchdog() |
316 void IXXAT::watchdog() |
314 { |
317 { |
315 VCI_CAN_STS sts; |
318 VCI_CAN_STS sts; |
316 long res = VCI_ReadCanStatus(m_BoardHdl, CAN_NUM, &sts); |
319 long res = VCI_ReadCanStatus(m_BoardHdl, CAN_NUM, &sts); |
317 |
320 |
318 if (res < 0) |
321 if (res < 0) |
319 { |
322 { |
320 char buf[200]; |
323 MSG_ERR_DRV("\nIXXAT canBusWatchdog: ERROR: Reading the can state failed!\n"); |
321 ::sprintf(buf, "\nIXXAT canBusWatchdog: ERROR: Reading the can state failed!\n"); |
|
322 ::OutputDebugString(buf); |
|
323 } |
324 } |
324 else |
325 else |
325 { |
326 { |
326 if (sts.sts & (STS_CAN_BUS_OFF | STS_CAN_DATA_OVERRUN | STS_REMOTE_QUEUE_OVERRUN)) |
327 if (sts.sts & (STS_CAN_BUS_OFF | STS_CAN_DATA_OVERRUN | STS_REMOTE_QUEUE_OVERRUN)) |
327 { |
328 { |
328 if (sts.sts & STS_CAN_BUS_OFF) |
329 if (sts.sts & STS_CAN_BUS_OFF) |
329 { |
330 { |
330 ::OutputDebugString("\nIXXAT canBusWatchdog: CAN bus off detected!\n"); |
331 MSG_ERR_DRV("\nIXXAT canBusWatchdog: CAN bus off detected!\n"); |
331 } |
332 } |
332 if (sts.sts & STS_CAN_DATA_OVERRUN) |
333 if (sts.sts & STS_CAN_DATA_OVERRUN) |
333 { |
334 { |
334 ::OutputDebugString("\nIXXAT canBusWatchdog: CAN data overrun detected!\n"); |
335 MSG_ERR_DRV("\nIXXAT canBusWatchdog: CAN data overrun detected!\n"); |
335 } |
336 } |
336 if (sts.sts & STS_REMOTE_QUEUE_OVERRUN) |
337 if (sts.sts & STS_REMOTE_QUEUE_OVERRUN) |
337 { |
338 { |
338 ::OutputDebugString("\nIXXAT canBusWatchdog: Remote queue overrun detected!\n"); |
339 MSG_ERR_DRV("\nIXXAT canBusWatchdog: Remote queue overrun detected!\n"); |
339 } |
340 } |
340 |
341 |
341 res = VCI_ResetCan(m_BoardHdl, CAN_NUM); |
342 res = VCI_ResetCan(m_BoardHdl, CAN_NUM); |
342 if (res <= 0) |
343 if (res <= 0) |
343 { |
344 { |
344 char buf[200]; |
345 MSG_ERR_DRV("\nIXXAT canBusWatchdog: ERROR: Resetting the can module failed with code '%d'!\n", res); |
345 ::sprintf(buf, "\nIXXAT canBusWatchdog: ERROR: Resetting the can module failed with code '%d'!\n", res); |
|
346 ::OutputDebugString(buf); |
|
347 } |
346 } |
348 |
347 |
349 res = VCI_StartCan(m_BoardHdl, CAN_NUM); |
348 res = VCI_StartCan(m_BoardHdl, CAN_NUM); |
350 if (res <= 0) |
349 if (res <= 0) |
351 { |
350 { |
352 char buf[200]; |
351 MSG_ERR_DRV("\nIXXAT canBusWatchdog: ERROR: Restaring the can module failed with code '%d'!\n", res); |
353 ::sprintf(buf, "\nIXXAT canBusWatchdog: ERROR: Restaring the can module failed with code '%d'!\n", res); |
|
354 ::OutputDebugString(buf); |
|
355 } |
352 } |
356 } |
353 } |
357 } |
354 } |
358 |
355 |
359 if (SetTimer(NULL, m_watchdogTimerId, IXXAT::CAN_BUS_WATCHDOG_INTERVAL_MSEC, IXXAT::canBusWatchdog) == 0) |
356 if (SetTimer(NULL, m_watchdogTimerId, IXXAT::CAN_BUS_WATCHDOG_INTERVAL_MSEC, IXXAT::canBusWatchdog) == 0) |
360 { |
357 { |
361 char buf[200]; |
358 MSG_ERR_DRV("\nIXXAT canBusWatchdog: ERROR: Creation of the watchdog timer failed!\n"); |
362 ::sprintf(buf, "\nIXXAT canBusWatchdog: ERROR: Creation of the watchdog timer failed!\n"); |
|
363 ::OutputDebugString(buf); |
|
364 } |
359 } |
365 } |
360 } |
366 |
361 |
367 void CALLBACK IXXAT::canBusWatchdog(HWND hwnd, UINT msg, UINT_PTR idEvent, DWORD dwTime) |
362 void CALLBACK IXXAT::canBusWatchdog(HWND hwnd, UINT msg, UINT_PTR idEvent, DWORD dwTime) |
368 { |
363 { |