author | Edouard Tisserant |
Sat, 21 Jan 2012 19:32:58 +0100 | |
changeset 690 | 1c2cb6088050 |
parent 689 | d6fcd388f2db |
child 726 | b52c951dec63 |
permissions | -rw-r--r-- |
255 | 1 |
/* |
2 |
This file is part of CanFestival, a library implementing CanOpen Stack. |
|
3 |
||
4 |
CanFestival Copyright (C): Edouard TISSERANT and Francis DUPIN |
|
5 |
CanFestival Win32 port Copyright (C) 2007 Leonid Tochinski, ChattenAssociates, Inc. |
|
6 |
||
7 |
See COPYING file for copyrights details. |
|
8 |
||
9 |
This library is free software; you can redistribute it and/or |
|
10 |
modify it under the terms of the GNU Lesser General Public |
|
11 |
License as published by the Free Software Foundation; either |
|
12 |
version 2.1 of the License, or (at your option) any later version. |
|
13 |
||
14 |
This library is distributed in the hope that it will be useful, |
|
15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
17 |
Lesser General Public License for more details. |
|
18 |
||
19 |
You should have received a copy of the GNU Lesser General Public |
|
20 |
License along with this library; if not, write to the Free Software |
|
21 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
22 |
*/ |
|
23 |
// pragma based message |
|
24 |
// http://www.codeproject.com/macro/location_pragma.asp |
|
25 |
#define __STR2__(x) #x |
|
26 |
#define __STR1__(x) __STR2__(x) |
|
27 |
#define __LOC2__ __FILE__ "("__STR1__(__LINE__)") : " |
|
28 |
||
29 |
||
30 |
#pragma message("*********************************************************************************") |
|
31 |
#pragma message(" NOTE: IXXAT Win32 drivers and API should be installed in order to build this project!") |
|
32 |
#pragma message(__LOC2__ "See IXXAT.Cpp header for details.") |
|
33 |
#pragma message("*********************************************************************************") |
|
34 |
||
35 |
||
252 | 36 |
// IXXAT adapter driver for CanFestival-3 Win32 port |
37 |
// |
|
38 |
// Notes |
|
39 |
//-------------------------------------------- |
|
40 |
// For building of this project you will need |
|
41 |
// the following IXXAT API files |
|
42 |
// Vci2.h |
|
43 |
// Vci11un6.lib |
|
44 |
// |
|
45 |
// IXXAT Win32 drivers and API can be downloaded from |
|
46 |
// http://www.ixxat.com/download_vci_en,7547,5873.html |
|
47 |
// |
|
48 |
// Copy Vci2.h & Vci11un6.lib files to can_ixxat_win32 folder of add path to them in Project settings. |
|
49 |
||
255 | 50 |
|
252 | 51 |
#include <stdio.h> |
52 |
extern "C" { |
|
53 |
#include "applicfg.h" |
|
54 |
#include "can_driver.h" |
|
55 |
#include "def.h" |
|
56 |
} |
|
57 |
#include "VCI2.h" |
|
58 |
#include "async_access_que.h" |
|
59 |
||
60 |
#define CAN_NUM 0 |
|
61 |
||
62 |
class IXXAT |
|
63 |
{ |
|
64 |
public: |
|
65 |
class error |
|
66 |
{ |
|
67 |
}; |
|
68 |
IXXAT(s_BOARD *board); |
|
69 |
~IXXAT(); |
|
70 |
bool send(const Message *m); |
|
71 |
bool receive(Message *m); |
|
72 |
private: |
|
689
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
73 |
bool open(int board_number, const char* baud_rate); |
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
74 |
bool close(); |
252 | 75 |
void receive_queuedata(UINT16 que_hdl, UINT16 count, VCI_CAN_OBJ* p_obj); |
76 |
// VCI2 handler |
|
77 |
static void VCI_CALLBACKATTR message_handler(char *msg_str); |
|
78 |
static void VCI_CALLBACKATTR receive_queuedata_handler(UINT16 que_hdl, UINT16 count, VCI_CAN_OBJ* p_obj); |
|
79 |
static void VCI_CALLBACKATTR exception_handler(VCI_FUNC_NUM func_num, INT32 err_code, UINT16 ext_err, char* err_str); |
|
80 |
||
655
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
81 |
static void CALLBACK canBusWatchdog(HWND hwnd, UINT msg, UINT_PTR idEvent, DWORD dwTime); |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
82 |
void watchdog(); |
252 | 83 |
private: |
84 |
UINT16 m_BoardHdl; |
|
85 |
UINT16 m_TxQueHdl; |
|
86 |
UINT16 m_RxQueHdl; |
|
87 |
async_access_que<VCI_CAN_OBJ> m_RX_Que; |
|
88 |
static IXXAT* m_callbackPtr; |
|
655
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
89 |
static UINT_PTR m_watchdogTimerId; |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
90 |
static const unsigned int CAN_BUS_WATCHDOG_INTERVAL_MSEC = 10000; |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
91 |
|
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
92 |
/** Bitmask inside sts from VCI_ReadCanStatus() that defines the can bus off state.*/ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
93 |
static const unsigned char STS_CAN_BUS_OFF = 0x80; |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
94 |
|
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
95 |
/** Bitmask inside sts from VCI_ReadCanStatus() that defines the can data overrun state.*/ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
96 |
static const unsigned char STS_CAN_DATA_OVERRUN = 0x20; |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
97 |
|
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
98 |
/** Bitmask inside sts from VCI_ReadCanStatus() that defines the remote queue overrun state.*/ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
99 |
static const unsigned char STS_REMOTE_QUEUE_OVERRUN = 0x04; |
252 | 100 |
}; |
101 |
||
102 |
IXXAT *IXXAT::m_callbackPtr = NULL; |
|
103 |
||
655
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
104 |
UINT_PTR IXXAT::m_watchdogTimerId = 0; |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
105 |
|
252 | 106 |
IXXAT::IXXAT(s_BOARD *board) : m_BoardHdl(0xFFFF), |
107 |
m_TxQueHdl(0xFFFF), |
|
108 |
m_RxQueHdl(0xFFFF) |
|
109 |
||
110 |
{ |
|
689
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
111 |
if (!board) |
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
112 |
{ |
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
113 |
close(); |
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
114 |
throw error(); |
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
115 |
} |
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
116 |
|
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
117 |
long board_number = 0; |
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
118 |
|
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
119 |
if (board->busname) |
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
120 |
{ |
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
121 |
board_number = atol(board->busname); |
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
122 |
} |
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
123 |
|
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
124 |
if (!open(board_number, board->baudrate)) |
252 | 125 |
{ |
126 |
close(); |
|
127 |
throw error(); |
|
128 |
} |
|
129 |
m_callbackPtr = this; |
|
130 |
} |
|
131 |
||
132 |
IXXAT::~IXXAT() |
|
133 |
{ |
|
134 |
close(); |
|
135 |
m_callbackPtr = 0; |
|
136 |
} |
|
137 |
||
138 |
bool IXXAT::send(const Message *m) |
|
139 |
{ |
|
140 |
if (m_BoardHdl == 0xFFFF) |
|
267
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
255
diff
changeset
|
141 |
return true; // true -> NOT OK |
252 | 142 |
long res = VCI_ERR; |
143 |
if (m->rtr == NOT_A_REQUEST) |
|
365 | 144 |
res = VCI_TransmitObj(m_BoardHdl, m_TxQueHdl, m->cob_id, m->len, const_cast<unsigned char*>(m->data)); |
252 | 145 |
else |
365 | 146 |
res = VCI_RequestObj(m_BoardHdl, m_TxQueHdl, m->cob_id, m->len); |
647
8203ce2b9752
CHANGED: - canReceive and canSend return now 1 on error and 0 on success
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents:
646
diff
changeset
|
147 |
|
8203ce2b9752
CHANGED: - canReceive and canSend return now 1 on error and 0 on success
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents:
646
diff
changeset
|
148 |
return (res == VCI_OK); |
252 | 149 |
} |
150 |
||
151 |
||
152 |
bool IXXAT::receive(Message *m) |
|
153 |
{ |
|
154 |
if (m_BoardHdl == 0xFFFF) |
|
155 |
return false; |
|
156 |
VCI_CAN_OBJ obj; |
|
157 |
if (m_RX_Que.extract_top(obj)) |
|
158 |
{ |
|
646
4177b05ab835
CHANGED: - added explicit cast to remove compiler warning
Christian Taedcke
parents:
645
diff
changeset
|
159 |
m->cob_id = static_cast<UNS16>(obj.id); //valid for 11Bit ids |
252 | 160 |
m->len = obj.len; |
161 |
m->rtr = (obj.rtr == VCI_RX_BUF) ? NOT_A_REQUEST : REQUEST; |
|
162 |
if (m->rtr == NOT_A_REQUEST) |
|
163 |
::memcpy(m->data, obj.a_data, m->len); |
|
164 |
return true; |
|
165 |
} |
|
166 |
return false; |
|
167 |
} |
|
168 |
||
689
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
169 |
bool IXXAT::open(int board_number, const char* baud_rate) |
252 | 170 |
{ |
171 |
// check, if baudrate is supported |
|
172 |
struct IXXAT_baud_rate_param |
|
173 |
{ |
|
174 |
UINT8 bt0; |
|
175 |
UINT8 bt1; |
|
176 |
}; |
|
177 |
struct IXXAT_look_up_table |
|
178 |
{ |
|
179 |
char baud_rate[20]; |
|
180 |
IXXAT_baud_rate_param bt; |
|
181 |
}; |
|
182 |
static const IXXAT_look_up_table br_lut[] = { |
|
183 |
{"10K",{VCI_10KB}}, |
|
184 |
{"20K",{VCI_20KB}}, |
|
185 |
{"50K",{VCI_50KB}}, |
|
186 |
{"100K",{VCI_100KB}}, |
|
187 |
{"125K",{VCI_125KB}}, |
|
188 |
{"250K",{VCI_250KB}}, |
|
189 |
{"500K",{VCI_500KB}}, |
|
190 |
{"800K",{VCI_800KB}}, |
|
191 |
{"1M",{VCI_1000KB}} |
|
192 |
}; |
|
193 |
static const long br_lut_size = sizeof (br_lut)/sizeof(IXXAT_look_up_table); |
|
194 |
int index; |
|
195 |
for (index = 0; index < br_lut_size; ++index) |
|
196 |
{ |
|
197 |
if (::strcmp(br_lut[index].baud_rate,baud_rate)==0) |
|
198 |
break; |
|
199 |
} |
|
685
b38d2d8e291d
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
683
diff
changeset
|
200 |
if (index == br_lut_size) |
b38d2d8e291d
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
683
diff
changeset
|
201 |
{ |
687 | 202 |
MSG_ERR_DRV("IXXAT::open: The given baudrate %S is invalid.", baud_rate); |
252 | 203 |
return false; |
685
b38d2d8e291d
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
683
diff
changeset
|
204 |
} |
252 | 205 |
// close existing board |
206 |
close(); |
|
207 |
// init IXXAT board |
|
689
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
208 |
long res = VCI2_PrepareBoard( 0, // board type, unused in VCI2 |
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
209 |
board_number, // unique board index, see XAT_EnumHwEntry() and XAT_GetConfig() |
252 | 210 |
NULL, // pointer to buffer for additional info |
211 |
0, // length of additional info buffer |
|
212 |
message_handler, // pointer to msg-callbackhandler |
|
213 |
receive_queuedata_handler, // pointer to receive-callbackhandler |
|
214 |
exception_handler); // pointer to exception-callbackhandler |
|
215 |
if (res < 0) |
|
685
b38d2d8e291d
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
683
diff
changeset
|
216 |
{ |
b38d2d8e291d
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
683
diff
changeset
|
217 |
MSG_ERR_DRV("IXXAT::open: VCI2_PrepareBoard failed with code '%d'.", res); |
252 | 218 |
return false; |
685
b38d2d8e291d
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
683
diff
changeset
|
219 |
} |
252 | 220 |
m_BoardHdl = (UINT16)res; |
221 |
||
222 |
VCI_ResetBoard(m_BoardHdl); |
|
223 |
||
224 |
// init CAN parameters |
|
225 |
||
226 |
// initialize CAN-Controller |
|
227 |
res = VCI_InitCan(m_BoardHdl, CAN_NUM, br_lut[index].bt.bt0,br_lut[index].bt.bt1, VCI_11B); |
|
228 |
||
229 |
// definition of Acceptance-Mask (define to receive all IDs) |
|
230 |
res = VCI_SetAccMask(m_BoardHdl, CAN_NUM, 0x0UL, 0x0UL); |
|
231 |
||
232 |
// definition of Transmit Queue |
|
233 |
res = VCI_ConfigQueue(m_BoardHdl, CAN_NUM, VCI_TX_QUE, 100 , 0, 0, 0, &m_TxQueHdl); |
|
234 |
||
235 |
// definition of Receive Queue (interrupt mode) |
|
655
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
236 |
res = VCI_ConfigQueue(m_BoardHdl, CAN_NUM, VCI_RX_QUE, 500, 1, 0, 100, &m_RxQueHdl); |
252 | 237 |
|
238 |
// assign the all IDs to the Receive Queue |
|
689
d6fcd388f2db
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
688
diff
changeset
|
239 |
res = VCI_AssignRxQueObj(m_BoardHdl, m_RxQueHdl ,VCI_ACCEPT, 0, 0); |
252 | 240 |
|
241 |
// And now start the CAN |
|
242 |
res = VCI_StartCan(m_BoardHdl, CAN_NUM); |
|
655
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
243 |
|
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
244 |
//Start CAN Bus-Off watchdog |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
245 |
m_watchdogTimerId = SetTimer(NULL, NULL, IXXAT::CAN_BUS_WATCHDOG_INTERVAL_MSEC, IXXAT::canBusWatchdog); |
252 | 246 |
|
247 |
return true; |
|
248 |
} |
|
249 |
||
250 |
bool IXXAT::close() |
|
251 |
{ |
|
252 |
if (m_BoardHdl == 0xFFFF) |
|
253 |
return true; |
|
254 |
VCI_ResetBoard(m_BoardHdl); |
|
255 |
VCI_CancelBoard(m_BoardHdl); |
|
256 |
m_BoardHdl = |
|
257 |
m_TxQueHdl = |
|
258 |
m_RxQueHdl = 0xFFFF; |
|
259 |
return true; |
|
260 |
} |
|
261 |
||
262 |
void IXXAT::receive_queuedata(UINT16 que_hdl, UINT16 count, VCI_CAN_OBJ *p_obj) |
|
263 |
{ |
|
264 |
for (int i = 0; i < count; ++i) |
|
265 |
m_RX_Que.append(p_obj[i]); // can packet |
|
266 |
} |
|
267 |
||
268 |
void VCI_CALLBACKATTR IXXAT::receive_queuedata_handler(UINT16 que_hdl, UINT16 count, VCI_CAN_OBJ *p_obj) |
|
269 |
{ |
|
270 |
if (m_callbackPtr != NULL) |
|
271 |
m_callbackPtr->receive_queuedata(que_hdl, count, p_obj); |
|
272 |
} |
|
273 |
||
274 |
void VCI_CALLBACKATTR IXXAT::message_handler(char *msg_str) |
|
275 |
{ |
|
688 | 276 |
MSG_ERR_DRV("IXXAT Message: [%S]", msg_str); |
252 | 277 |
} |
278 |
||
279 |
void VCI_CALLBACKATTR IXXAT::exception_handler(VCI_FUNC_NUM func_num, INT32 err_code, UINT16 ext_err, char* err_str) |
|
280 |
{ |
|
281 |
static const char* Num2Function[] = |
|
282 |
{ |
|
283 |
"VCI_Init", |
|
284 |
"VCI_Searchboard", |
|
285 |
"VCI_Prepareboard", |
|
286 |
"VCI_Cancel_board", |
|
287 |
"VCI_Testboard", |
|
288 |
"VCI_ReadBoardInfo", |
|
289 |
"VCI_ReadBoardStatus", |
|
290 |
"VCI_Resetboard", |
|
291 |
"VCI_ReadCANInfo", |
|
292 |
"VCI_ReadCANStatus", |
|
293 |
"VCI_InitCAN", |
|
294 |
"VCI_SetAccMask", |
|
295 |
"VCI_ResetCAN", |
|
296 |
"VCI_StartCAN", |
|
297 |
"VCI_ResetTimeStamps", |
|
298 |
"VCI_ConfigQueue", |
|
299 |
"VCI_AssignRxQueObj", |
|
300 |
"VCI_ConfigBuffer", |
|
301 |
"VCI_ReconfigBuffer", |
|
302 |
"VCI_ConfigTimer", |
|
303 |
"VCI_ReadQueStatus", |
|
304 |
"VCI_ReadQueObj", |
|
305 |
"VCI_ReadBufStatus", |
|
306 |
"VCI_ReadBufData", |
|
307 |
"VCI_TransmitObj", |
|
308 |
"VCI_RequestObj", |
|
309 |
"VCI_UpdateBufObj", |
|
310 |
"VCI_CciReqData" |
|
311 |
}; |
|
685
b38d2d8e291d
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
683
diff
changeset
|
312 |
|
688 | 313 |
MSG_ERR_DRV("IXXAT Exception: %S (%i / %u) [%S]", Num2Function[func_num], err_code, ext_err, err_str); |
252 | 314 |
} |
315 |
||
655
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
316 |
void IXXAT::watchdog() |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
317 |
{ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
318 |
VCI_CAN_STS sts; |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
319 |
long res = VCI_ReadCanStatus(m_BoardHdl, CAN_NUM, &sts); |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
320 |
|
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
321 |
if (res < 0) |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
322 |
{ |
688 | 323 |
MSG_ERR_DRV("IXXAT canBusWatchdog: ERROR: Reading the can state failed!"); |
655
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
324 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
325 |
else |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
326 |
{ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
327 |
if (sts.sts & (STS_CAN_BUS_OFF | STS_CAN_DATA_OVERRUN | STS_REMOTE_QUEUE_OVERRUN)) |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
328 |
{ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
329 |
if (sts.sts & STS_CAN_BUS_OFF) |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
330 |
{ |
688 | 331 |
MSG_ERR_DRV("IXXAT canBusWatchdog: CAN bus off detected!"); |
655
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
332 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
333 |
if (sts.sts & STS_CAN_DATA_OVERRUN) |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
334 |
{ |
688 | 335 |
MSG_ERR_DRV("IXXAT canBusWatchdog: CAN data overrun detected!"); |
655
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
336 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
337 |
if (sts.sts & STS_REMOTE_QUEUE_OVERRUN) |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
338 |
{ |
688 | 339 |
MSG_ERR_DRV("IXXAT canBusWatchdog: Remote queue overrun detected!"); |
655
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
340 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
341 |
|
683
a3ff0e3e9829
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
655
diff
changeset
|
342 |
res = VCI_ResetCan(m_BoardHdl, CAN_NUM); |
a3ff0e3e9829
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
655
diff
changeset
|
343 |
if (res <= 0) |
a3ff0e3e9829
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
655
diff
changeset
|
344 |
{ |
688 | 345 |
MSG_ERR_DRV("IXXAT canBusWatchdog: ERROR: Resetting the can module failed with code '%d'!", res); |
655
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
346 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
347 |
|
683
a3ff0e3e9829
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
655
diff
changeset
|
348 |
res = VCI_StartCan(m_BoardHdl, CAN_NUM); |
a3ff0e3e9829
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
655
diff
changeset
|
349 |
if (res <= 0) |
a3ff0e3e9829
Win32 IXXAT driver:
Christian Taedcke <hacking@taedcke.com>
parents:
655
diff
changeset
|
350 |
{ |
688 | 351 |
MSG_ERR_DRV("IXXAT canBusWatchdog: ERROR: Restaring the can module failed with code '%d'!", res); |
655
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
352 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
353 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
354 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
355 |
|
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
356 |
if (SetTimer(NULL, m_watchdogTimerId, IXXAT::CAN_BUS_WATCHDOG_INTERVAL_MSEC, IXXAT::canBusWatchdog) == 0) |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
357 |
{ |
688 | 358 |
MSG_ERR_DRV("IXXAT canBusWatchdog: ERROR: Creation of the watchdog timer failed!"); |
655
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
359 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
360 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
361 |
|
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
362 |
void CALLBACK IXXAT::canBusWatchdog(HWND hwnd, UINT msg, UINT_PTR idEvent, DWORD dwTime) |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
363 |
{ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
364 |
if (m_callbackPtr != NULL) |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
365 |
m_callbackPtr->watchdog(); |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
366 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
367 |
|
252 | 368 |
//------------------------------------------------------------------------ |
369 |
extern "C" |
|
645
93ad82ee0426
FIXED: - added CALLBACK to can callback function prototypes
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents:
631
diff
changeset
|
370 |
UNS8 __stdcall canReceive_driver(CAN_HANDLE inst, Message *m) |
252 | 371 |
{ |
647
8203ce2b9752
CHANGED: - canReceive and canSend return now 1 on error and 0 on success
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents:
646
diff
changeset
|
372 |
return reinterpret_cast<IXXAT*>(inst)->receive(m) ? 0 : 1; |
252 | 373 |
} |
374 |
||
375 |
extern "C" |
|
645
93ad82ee0426
FIXED: - added CALLBACK to can callback function prototypes
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents:
631
diff
changeset
|
376 |
UNS8 __stdcall canSend_driver(CAN_HANDLE inst, Message const *m) |
252 | 377 |
{ |
647
8203ce2b9752
CHANGED: - canReceive and canSend return now 1 on error and 0 on success
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents:
646
diff
changeset
|
378 |
return reinterpret_cast<IXXAT*>(inst)->send(m) ? 0 : 1; |
252 | 379 |
} |
380 |
||
381 |
extern "C" |
|
645
93ad82ee0426
FIXED: - added CALLBACK to can callback function prototypes
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents:
631
diff
changeset
|
382 |
CAN_HANDLE __stdcall canOpen_driver(s_BOARD *board) |
252 | 383 |
{ |
384 |
try |
|
385 |
{ |
|
386 |
return new IXXAT(board); |
|
387 |
} |
|
388 |
catch (IXXAT::error&) |
|
389 |
{ |
|
390 |
return 0; |
|
391 |
} |
|
392 |
} |
|
393 |
||
394 |
extern "C" |
|
645
93ad82ee0426
FIXED: - added CALLBACK to can callback function prototypes
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents:
631
diff
changeset
|
395 |
int __stdcall canClose_driver(CAN_HANDLE inst) |
252 | 396 |
{ |
397 |
delete reinterpret_cast<IXXAT*>(inst); |
|
398 |
return 1; |
|
399 |
} |
|
384 | 400 |
|
401 |
extern "C" |
|
645
93ad82ee0426
FIXED: - added CALLBACK to can callback function prototypes
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents:
631
diff
changeset
|
402 |
UNS8 __stdcall canChangeBaudRate_driver( CAN_HANDLE fd, char* baud) |
384 | 403 |
{ |
404 |
//printf("canChangeBaudRate not yet supported by this driver\n"); |
|
405 |
return 0; |
|
631 | 406 |
} |