author | Edouard Tisserant |
Wed, 13 Apr 2011 16:29:59 +0200 | |
changeset 659 | 1041153c5fd2 |
parent 655 | ea1ddcc77acf |
child 683 | a3ff0e3e9829 |
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: |
|
73 |
bool open(const char* board_name, int board_number, const char* baud_rate); |
|
74 |
bool close(); |
|
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 |
{ |
|
111 |
char busname[100]; |
|
112 |
::strcpy(busname,board->busname); |
|
113 |
char board_name[100]; |
|
114 |
long board_number = 0; |
|
115 |
char *ptr = ::strrchr(busname,':'); |
|
116 |
if (ptr != 0) |
|
117 |
{ |
|
118 |
*ptr = 0; |
|
119 |
::strcpy(board_name,busname); |
|
120 |
if (++ptr - busname < (int)::strlen(board->busname)) |
|
121 |
board_number = ::atoi(ptr); |
|
122 |
} |
|
123 |
if (!open(board_name,board_number,board->baudrate)) |
|
124 |
{ |
|
125 |
close(); |
|
126 |
throw error(); |
|
127 |
} |
|
128 |
m_callbackPtr = this; |
|
129 |
} |
|
130 |
||
131 |
IXXAT::~IXXAT() |
|
132 |
{ |
|
133 |
close(); |
|
134 |
m_callbackPtr = 0; |
|
135 |
} |
|
136 |
||
137 |
bool IXXAT::send(const Message *m) |
|
138 |
{ |
|
139 |
if (m_BoardHdl == 0xFFFF) |
|
267
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
255
diff
changeset
|
140 |
return true; // true -> NOT OK |
252 | 141 |
long res = VCI_ERR; |
142 |
if (m->rtr == NOT_A_REQUEST) |
|
365 | 143 |
res = VCI_TransmitObj(m_BoardHdl, m_TxQueHdl, m->cob_id, m->len, const_cast<unsigned char*>(m->data)); |
252 | 144 |
else |
365 | 145 |
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
|
146 |
|
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 |
return (res == VCI_OK); |
252 | 148 |
} |
149 |
||
150 |
||
151 |
bool IXXAT::receive(Message *m) |
|
152 |
{ |
|
153 |
if (m_BoardHdl == 0xFFFF) |
|
154 |
return false; |
|
155 |
VCI_CAN_OBJ obj; |
|
156 |
if (m_RX_Que.extract_top(obj)) |
|
157 |
{ |
|
646
4177b05ab835
CHANGED: - added explicit cast to remove compiler warning
Christian Taedcke
parents:
645
diff
changeset
|
158 |
m->cob_id = static_cast<UNS16>(obj.id); //valid for 11Bit ids |
252 | 159 |
m->len = obj.len; |
160 |
m->rtr = (obj.rtr == VCI_RX_BUF) ? NOT_A_REQUEST : REQUEST; |
|
161 |
if (m->rtr == NOT_A_REQUEST) |
|
162 |
::memcpy(m->data, obj.a_data, m->len); |
|
163 |
return true; |
|
164 |
} |
|
165 |
return false; |
|
166 |
} |
|
167 |
||
168 |
bool IXXAT::open(const char* board_name, int board_number, const char* baud_rate) |
|
169 |
{ |
|
170 |
// check, if baudrate is supported |
|
171 |
struct IXXAT_baud_rate_param |
|
172 |
{ |
|
173 |
UINT8 bt0; |
|
174 |
UINT8 bt1; |
|
175 |
}; |
|
176 |
struct IXXAT_look_up_table |
|
177 |
{ |
|
178 |
char baud_rate[20]; |
|
179 |
IXXAT_baud_rate_param bt; |
|
180 |
}; |
|
181 |
static const IXXAT_look_up_table br_lut[] = { |
|
182 |
{"10K",{VCI_10KB}}, |
|
183 |
{"20K",{VCI_20KB}}, |
|
184 |
{"50K",{VCI_50KB}}, |
|
185 |
{"100K",{VCI_100KB}}, |
|
186 |
{"125K",{VCI_125KB}}, |
|
187 |
{"250K",{VCI_250KB}}, |
|
188 |
{"500K",{VCI_500KB}}, |
|
189 |
{"800K",{VCI_800KB}}, |
|
190 |
{"1M",{VCI_1000KB}} |
|
191 |
}; |
|
192 |
static const long br_lut_size = sizeof (br_lut)/sizeof(IXXAT_look_up_table); |
|
193 |
int index; |
|
194 |
for (index = 0; index < br_lut_size; ++index) |
|
195 |
{ |
|
196 |
if (::strcmp(br_lut[index].baud_rate,baud_rate)==0) |
|
197 |
break; |
|
198 |
} |
|
199 |
if (index == br_lut_size) |
|
200 |
return false; |
|
201 |
// close existing board |
|
202 |
close(); |
|
203 |
// init IXXAT board |
|
204 |
unsigned long board_type = VCI_GetBrdTypeByName(const_cast<char*>(board_name)); |
|
205 |
long res = VCI2_PrepareBoard( board_type, // board type |
|
206 |
board_number, // unique board index |
|
207 |
NULL, // pointer to buffer for additional info |
|
208 |
0, // length of additional info buffer |
|
209 |
message_handler, // pointer to msg-callbackhandler |
|
210 |
receive_queuedata_handler, // pointer to receive-callbackhandler |
|
211 |
exception_handler); // pointer to exception-callbackhandler |
|
212 |
if (res < 0) |
|
213 |
return false; |
|
214 |
m_BoardHdl = (UINT16)res; |
|
215 |
||
216 |
VCI_ResetBoard(m_BoardHdl); |
|
217 |
||
218 |
// init CAN parameters |
|
219 |
||
220 |
// initialize CAN-Controller |
|
221 |
res = VCI_InitCan(m_BoardHdl, CAN_NUM, br_lut[index].bt.bt0,br_lut[index].bt.bt1, VCI_11B); |
|
222 |
||
223 |
// definition of Acceptance-Mask (define to receive all IDs) |
|
224 |
res = VCI_SetAccMask(m_BoardHdl, CAN_NUM, 0x0UL, 0x0UL); |
|
225 |
||
226 |
// definition of Transmit Queue |
|
227 |
res = VCI_ConfigQueue(m_BoardHdl, CAN_NUM, VCI_TX_QUE, 100 , 0, 0, 0, &m_TxQueHdl); |
|
228 |
||
229 |
// definition of Receive Queue (interrupt mode) |
|
655
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
230 |
res = VCI_ConfigQueue(m_BoardHdl, CAN_NUM, VCI_RX_QUE, 500, 1, 0, 100, &m_RxQueHdl); |
252 | 231 |
|
232 |
// assign the all IDs to the Receive Queue |
|
233 |
res = VCI_AssignRxQueObj(m_BoardHdl, m_RxQueHdl ,VCI_ACCEPT, 0, 0) ; |
|
234 |
||
235 |
// And now start the CAN |
|
236 |
res = VCI_StartCan(m_BoardHdl, CAN_NUM); |
|
655
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
237 |
|
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
238 |
//Start CAN Bus-Off watchdog |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
239 |
m_watchdogTimerId = SetTimer(NULL, NULL, IXXAT::CAN_BUS_WATCHDOG_INTERVAL_MSEC, IXXAT::canBusWatchdog); |
252 | 240 |
|
241 |
return true; |
|
242 |
} |
|
243 |
||
244 |
bool IXXAT::close() |
|
245 |
{ |
|
246 |
if (m_BoardHdl == 0xFFFF) |
|
247 |
return true; |
|
248 |
VCI_ResetBoard(m_BoardHdl); |
|
249 |
VCI_CancelBoard(m_BoardHdl); |
|
250 |
m_BoardHdl = |
|
251 |
m_TxQueHdl = |
|
252 |
m_RxQueHdl = 0xFFFF; |
|
253 |
return true; |
|
254 |
} |
|
255 |
||
256 |
void IXXAT::receive_queuedata(UINT16 que_hdl, UINT16 count, VCI_CAN_OBJ *p_obj) |
|
257 |
{ |
|
258 |
for (int i = 0; i < count; ++i) |
|
259 |
m_RX_Que.append(p_obj[i]); // can packet |
|
260 |
} |
|
261 |
||
262 |
void VCI_CALLBACKATTR IXXAT::receive_queuedata_handler(UINT16 que_hdl, UINT16 count, VCI_CAN_OBJ *p_obj) |
|
263 |
{ |
|
264 |
if (m_callbackPtr != NULL) |
|
265 |
m_callbackPtr->receive_queuedata(que_hdl, count, p_obj); |
|
266 |
} |
|
267 |
||
268 |
void VCI_CALLBACKATTR IXXAT::message_handler(char *msg_str) |
|
269 |
{ |
|
270 |
char buf[200]; |
|
271 |
::sprintf(buf,"IXXAT Message: [%s]\n", msg_str); |
|
272 |
::OutputDebugString(buf); |
|
273 |
} |
|
274 |
||
275 |
void VCI_CALLBACKATTR IXXAT::exception_handler(VCI_FUNC_NUM func_num, INT32 err_code, UINT16 ext_err, char* err_str) |
|
276 |
{ |
|
277 |
static const char* Num2Function[] = |
|
278 |
{ |
|
279 |
"VCI_Init", |
|
280 |
"VCI_Searchboard", |
|
281 |
"VCI_Prepareboard", |
|
282 |
"VCI_Cancel_board", |
|
283 |
"VCI_Testboard", |
|
284 |
"VCI_ReadBoardInfo", |
|
285 |
"VCI_ReadBoardStatus", |
|
286 |
"VCI_Resetboard", |
|
287 |
"VCI_ReadCANInfo", |
|
288 |
"VCI_ReadCANStatus", |
|
289 |
"VCI_InitCAN", |
|
290 |
"VCI_SetAccMask", |
|
291 |
"VCI_ResetCAN", |
|
292 |
"VCI_StartCAN", |
|
293 |
"VCI_ResetTimeStamps", |
|
294 |
"VCI_ConfigQueue", |
|
295 |
"VCI_AssignRxQueObj", |
|
296 |
"VCI_ConfigBuffer", |
|
297 |
"VCI_ReconfigBuffer", |
|
298 |
"VCI_ConfigTimer", |
|
299 |
"VCI_ReadQueStatus", |
|
300 |
"VCI_ReadQueObj", |
|
301 |
"VCI_ReadBufStatus", |
|
302 |
"VCI_ReadBufData", |
|
303 |
"VCI_TransmitObj", |
|
304 |
"VCI_RequestObj", |
|
305 |
"VCI_UpdateBufObj", |
|
306 |
"VCI_CciReqData" |
|
307 |
}; |
|
308 |
char buf[200]; |
|
309 |
::sprintf(buf, "IXXAT Exception: %s (%i / %u) [%s]\n", Num2Function[func_num], err_code, ext_err, err_str); |
|
310 |
::OutputDebugString(buf); |
|
311 |
} |
|
312 |
||
655
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
313 |
void IXXAT::watchdog() |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
314 |
{ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
315 |
VCI_CAN_STS sts; |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
316 |
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
|
317 |
|
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
318 |
if (res < 0) |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
319 |
{ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
320 |
char buf[200]; |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
321 |
::sprintf(buf, "\nIXXAT canBusWatchdog: ERROR: Reading the can state failed!\n"); |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
322 |
::OutputDebugString(buf); |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
323 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
324 |
else |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
325 |
{ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
326 |
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
|
327 |
{ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
328 |
if (sts.sts & STS_CAN_BUS_OFF) |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
329 |
{ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
330 |
::OutputDebugString("\nIXXAT canBusWatchdog: CAN bus off detected!\n"); |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
331 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
332 |
if (sts.sts & STS_CAN_DATA_OVERRUN) |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
333 |
{ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
334 |
::OutputDebugString("\nIXXAT canBusWatchdog: CAN data overrun detected!\n"); |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
335 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
336 |
if (sts.sts & STS_REMOTE_QUEUE_OVERRUN) |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
337 |
{ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
338 |
::OutputDebugString("\nIXXAT canBusWatchdog: Remote queue overrun detected!\n"); |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
339 |
} |
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 |
if (VCI_ResetCan(m_BoardHdl, CAN_NUM) < 0) |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
342 |
{ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
343 |
::OutputDebugString("\nIXXAT canBusWatchdog: ERROR: Resetting the can module failed!\n"); |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
344 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
345 |
|
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
346 |
if (VCI_StartCan(m_BoardHdl, CAN_NUM) < 0) |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
347 |
{ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
348 |
::OutputDebugString("\nIXXAT canBusWatchdog: ERROR: Restaring the can module failed!\n"); |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
349 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
350 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
351 |
} |
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 |
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
|
354 |
{ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
355 |
char buf[200]; |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
356 |
::sprintf(buf, "\nIXXAT canBusWatchdog: ERROR: Creation of the watchdog timer failed!\n"); |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
357 |
::OutputDebugString(buf); |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
358 |
} |
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 |
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
|
362 |
{ |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
363 |
if (m_callbackPtr != NULL) |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
364 |
m_callbackPtr->watchdog(); |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
365 |
} |
ea1ddcc77acf
CHANGED: - canSend message parameter is now a const pointer
Christian Taedcke
parents:
647
diff
changeset
|
366 |
|
252 | 367 |
//------------------------------------------------------------------------ |
368 |
extern "C" |
|
645
93ad82ee0426
FIXED: - added CALLBACK to can callback function prototypes
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents:
631
diff
changeset
|
369 |
UNS8 __stdcall canReceive_driver(CAN_HANDLE inst, Message *m) |
252 | 370 |
{ |
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
|
371 |
return reinterpret_cast<IXXAT*>(inst)->receive(m) ? 0 : 1; |
252 | 372 |
} |
373 |
||
374 |
extern "C" |
|
645
93ad82ee0426
FIXED: - added CALLBACK to can callback function prototypes
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents:
631
diff
changeset
|
375 |
UNS8 __stdcall canSend_driver(CAN_HANDLE inst, Message const *m) |
252 | 376 |
{ |
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
|
377 |
return reinterpret_cast<IXXAT*>(inst)->send(m) ? 0 : 1; |
252 | 378 |
} |
379 |
||
380 |
extern "C" |
|
645
93ad82ee0426
FIXED: - added CALLBACK to can callback function prototypes
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents:
631
diff
changeset
|
381 |
CAN_HANDLE __stdcall canOpen_driver(s_BOARD *board) |
252 | 382 |
{ |
383 |
try |
|
384 |
{ |
|
385 |
return new IXXAT(board); |
|
386 |
} |
|
387 |
catch (IXXAT::error&) |
|
388 |
{ |
|
389 |
return 0; |
|
390 |
} |
|
391 |
} |
|
392 |
||
393 |
extern "C" |
|
645
93ad82ee0426
FIXED: - added CALLBACK to can callback function prototypes
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents:
631
diff
changeset
|
394 |
int __stdcall canClose_driver(CAN_HANDLE inst) |
252 | 395 |
{ |
396 |
delete reinterpret_cast<IXXAT*>(inst); |
|
397 |
return 1; |
|
398 |
} |
|
384 | 399 |
|
400 |
extern "C" |
|
645
93ad82ee0426
FIXED: - added CALLBACK to can callback function prototypes
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents:
631
diff
changeset
|
401 |
UNS8 __stdcall canChangeBaudRate_driver( CAN_HANDLE fd, char* baud) |
384 | 402 |
{ |
403 |
//printf("canChangeBaudRate not yet supported by this driver\n"); |
|
404 |
return 0; |
|
631 | 405 |
} |