ProtocolDevice.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 SCHUNK GmbH & Co. KG
3  * Copyright (c) 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include "ProtocolDevice.h"
19 
20 // ========================================================================== ;
21 // ;
22 // ---- private auxiliary functions ----------------------------------------- ;
23 // ;
24 // ========================================================================== ;
25 
26 // ========================================================================== ;
27 // ;
28 // ---- protected auxiliary functions --------------------------------------- ;
29 // ;
30 // ========================================================================== ;
31 
32 int CProtocolDevice::write8Bytes(int iModuleId, bool bAck, void* pBytes )
33 {
34  EnterCriticalSection(&m_csDevice);
35  m_iErrorState = 0;
36  static CProtocolMessage clWrite, clRead;
37 
38  clWrite.m_uiMessageId = MSGID_SET + iModuleId;
39  memcpy( clWrite.m_aucMessageData, pBytes, 8 );
40  clWrite.m_ucMessageLength = 8;
41  clWrite.m_iModuleId = iModuleId;
42  clRead = clWrite;
43 
44 // warning("Sending %03x %02x %02x %02x %02x %02x %02x %02x %02x", clWrite.m_uiMessageId,
45 // clWrite.m_aucMessageData[0], clWrite.m_aucMessageData[1], clWrite.m_aucMessageData[2], clWrite.m_aucMessageData[3],
46 // clWrite.m_aucMessageData[4], clWrite.m_aucMessageData[5], clWrite.m_aucMessageData[6], clWrite.m_aucMessageData[7] );
47 
48  m_iErrorState = writeDevice(clWrite);
49  if(m_iErrorState != 0)
50  {
51  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
52  LeaveCriticalSection(&m_csDevice);
53  return m_iErrorState;
54  }
55 
56  if( bAck )
57  {
58  m_iErrorState = readDevice(clRead);
59  if(m_iErrorState != 0)
60  {
61  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
62  LeaveCriticalSection(&m_csDevice);
63  return m_iErrorState;
64  }
65  memcpy( pBytes, clRead.m_aucMessageData, clRead.m_ucMessageLength );
66  }
67  LeaveCriticalSection(&m_csDevice);
68  return m_iErrorState;
69 }
70 
71 int CProtocolDevice::getUnsignedLong(int iModuleId, unsigned long* puiData)
72 {
73  EnterCriticalSection(&m_csDevice);
74  m_iErrorState = 0;
75  bool bRecieved = false;
76  static CProtocolMessage clRead;
77  static CProtocolData clData;
78  *puiData = 0;
79 
80  do
81  {
82  m_iErrorState = readDevice(clRead);
83  if(m_iErrorState != 0)
84  {
85  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
86  LeaveCriticalSection(&m_csDevice);
87  return m_iErrorState;
88  }
89  bRecieved = true;
90  if(clRead.m_uiMessageId != MSGID_STATE + iModuleId)
91  {
92  debug(1, "getUnsignedLong: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_STATE + iModuleId );
93  bRecieved = false;
94  }
95  }
96  while(!bRecieved);
97  clData.aucData[0] = clRead.m_aucMessageData[0];
98  clData.aucData[1] = clRead.m_aucMessageData[1];
99  clData.aucData[2] = clRead.m_aucMessageData[2];
100  clData.aucData[3] = clRead.m_aucMessageData[3];
101  *puiData = clData.uiData;
102 
103  LeaveCriticalSection(&m_csDevice);
104  return m_iErrorState;
105 }
106 
107 int CProtocolDevice::readChar(int iModuleId, int iCommandId, int iParameterId, char* pcData)
108 {
109  EnterCriticalSection(&m_csDevice);
110  m_iErrorState = 0;
111  bool bRecieved = false;
112  static CProtocolMessage clWrite, clRead;
113 
114  clWrite.m_uiMessageId = MSGID_GET + iModuleId;
115  clWrite.m_aucMessageData[0] = iCommandId;
116  clWrite.m_aucMessageData[1] = iParameterId;
117  clWrite.m_ucMessageLength = 2;
118  clWrite.m_iModuleId = iModuleId;
119  clRead = clWrite;
120 
121  m_iErrorState = writeDevice(clWrite);
122  if(m_iErrorState != 0)
123  {
124  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
125  LeaveCriticalSection(&m_csDevice);
126  return m_iErrorState;
127  }
128 
129  do
130  {
131  m_iErrorState = readDevice(clRead);
132  if(m_iErrorState != 0)
133  {
134  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
135  LeaveCriticalSection(&m_csDevice);
136  return m_iErrorState;
137  }
138  bRecieved = true;
139  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
140  {
141  debug(1, "readChar: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
142  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
143  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
144  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
145  debug(2,"read MessageId %x", clRead.m_uiMessageId);
146  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
147  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
148  bRecieved = false;
149  }
150  if(clRead.m_aucMessageData[0] != iCommandId)
151  {
152  debug(1,"readChar: wrong command ID");
153  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
154  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
155  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
156  debug(2,"read MessageId %x", clRead.m_uiMessageId);
157  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
158  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
159  bRecieved = false;
160  }
161  if(clRead.m_aucMessageData[1] != iParameterId)
162  {
163  debug(1,"readChar: wrong parameter ID");
164  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
165  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
166  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
167  debug(2,"read MessageId %x", clRead.m_uiMessageId);
168  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
169  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
170  bRecieved = false;
171  }
172  }
173  while(!bRecieved);
174 
175  *pcData = clRead.m_aucMessageData[2];
176  LeaveCriticalSection(&m_csDevice);
177 
178  return m_iErrorState;
179 }
180 
181 int CProtocolDevice::readUnsignedChar(int iModuleId, int iCommandId, int iParameterId, unsigned char* pucData)
182 {
183  EnterCriticalSection(&m_csDevice);
184  m_iErrorState = 0;
185  bool bRecieved = false;
186  static CProtocolMessage clWrite, clRead;
187 
188  clWrite.m_uiMessageId = MSGID_GET + iModuleId;
189  clWrite.m_aucMessageData[0] = iCommandId;
190  clWrite.m_aucMessageData[1] = iParameterId;
191  clWrite.m_ucMessageLength = 2;
192  clWrite.m_iModuleId = iModuleId;
193  clRead = clWrite;
194 
195  m_iErrorState = writeDevice(clWrite);
196  if(m_iErrorState != 0)
197  {
198  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
199  LeaveCriticalSection(&m_csDevice);
200  return m_iErrorState;
201  }
202 
203  do
204  {
205  m_iErrorState = readDevice(clRead);
206  if(m_iErrorState != 0)
207  {
208  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
209  LeaveCriticalSection(&m_csDevice);
210  return m_iErrorState;
211  }
212  bRecieved = true;
213  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
214  {
215  debug(1,"readUnsignedChar: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
216  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
217  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
218  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
219  debug(2,"read MessageId %x", clRead.m_uiMessageId);
220  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
221  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
222  bRecieved = false;
223  }
224  if(clRead.m_aucMessageData[0] != iCommandId)
225  {
226  debug(1,"readUnsignedChar: wrong command ID");
227  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
228  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
229  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
230  debug(2,"read MessageId %x", clRead.m_uiMessageId);
231  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
232  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
233  bRecieved = false;
234  }
235  if(clRead.m_aucMessageData[1] != iParameterId)
236  {
237  debug(1,"readUnsignedChar: wrong parameter ID");
238  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
239  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
240  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
241  debug(2,"read MessageId %x", clRead.m_uiMessageId);
242  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
243  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
244  bRecieved = false;
245  }
246  }
247  while(!bRecieved);
248 
249  *pucData = clRead.m_aucMessageData[2];
250  LeaveCriticalSection(&m_csDevice);
251 
252  return m_iErrorState;
253 }
254 
255 int CProtocolDevice::readShort(int iModuleId, int iCommandId, int iParameterId, short* piData)
256 {
257  EnterCriticalSection(&m_csDevice);
258  m_iErrorState = 0;
259  bool bRecieved = false;
260  static CProtocolMessage clWrite, clRead;
261  static CProtocolData clData;
262 
263  clWrite.m_uiMessageId = MSGID_GET + iModuleId;
264  clWrite.m_aucMessageData[0] = iCommandId;
265  clWrite.m_aucMessageData[1] = iParameterId;
266  clWrite.m_ucMessageLength = 2;
267  clWrite.m_iModuleId = iModuleId;
268  clRead = clWrite;
269 
270  m_iErrorState = writeDevice(clWrite);
271  if(m_iErrorState != 0)
272  {
273  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
274  LeaveCriticalSection(&m_csDevice);
275  return m_iErrorState;
276  }
277 
278  do
279  {
280  m_iErrorState = readDevice(clRead);
281  if(m_iErrorState != 0)
282  {
283  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
284  LeaveCriticalSection(&m_csDevice);
285  return m_iErrorState;
286  }
287  bRecieved = true;
288  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
289  {
290  debug(1,"readShort: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
291  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
292  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
293  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
294  debug(2,"read MessageId %x", clRead.m_uiMessageId);
295  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
296  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
297  bRecieved = false;
298  }
299  if(clRead.m_aucMessageData[0] != iCommandId)
300  {
301  debug(1,"readShort: wrong command ID");
302  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
303  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
304  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
305  debug(2,"read MessageId %x", clRead.m_uiMessageId);
306  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
307  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
308  bRecieved = false;
309  }
310  if(clRead.m_aucMessageData[1] != iParameterId)
311  {
312  debug(1,"readShort: wrong parameter ID");
313  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
314  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
315  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
316  debug(2,"read MessageId %x", clRead.m_uiMessageId);
317  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
318  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
319  bRecieved = false;
320  }
321  }
322  while(!bRecieved);
323 
324  clData.aucData[0] = clRead.m_aucMessageData[2];
325  clData.aucData[1] = clRead.m_aucMessageData[3];
326  *piData = clData.aiData[0];
327  LeaveCriticalSection(&m_csDevice);
328 
329  return m_iErrorState;
330 }
331 
332 int CProtocolDevice::readUnsignedShort(int iModuleId, int iCommandId, int iParameterId, unsigned short* puiData)
333 {
334  EnterCriticalSection(&m_csDevice);
335  m_iErrorState = 0;
336  bool bRecieved = false;
337  static CProtocolMessage clWrite, clRead;
338  static CProtocolData clData;
339 
340  clWrite.m_uiMessageId = MSGID_GET + iModuleId;
341  clWrite.m_aucMessageData[0] = iCommandId;
342  clWrite.m_aucMessageData[1] = iParameterId;
343  clWrite.m_ucMessageLength = 2;
344  clWrite.m_iModuleId = iModuleId;
345  clRead = clWrite;
346 
347  m_iErrorState = writeDevice(clWrite);
348  if(m_iErrorState != 0)
349  {
350  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
351  LeaveCriticalSection(&m_csDevice);
352  return m_iErrorState;
353  }
354 
355  do
356  {
357  m_iErrorState = readDevice(clRead);
358  if(m_iErrorState != 0)
359  {
360  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
361  LeaveCriticalSection(&m_csDevice);
362  return m_iErrorState;
363  }
364  bRecieved = true;
365  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
366  {
367  debug(1,"readUnsignedShort: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
368  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
369  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
370  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
371  debug(2,"read MessageId %x", clRead.m_uiMessageId);
372  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
373  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
374  bRecieved = false;
375  }
376  if(clRead.m_aucMessageData[0] != iCommandId)
377  {
378  debug(1,"readUnsignedShort: wrong command ID");
379  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
380  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
381  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
382  debug(2,"read MessageId %x", clRead.m_uiMessageId);
383  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
384  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
385  bRecieved = false;
386  }
387  if(clRead.m_aucMessageData[1] != iParameterId)
388  {
389  debug(1,"readUnsignedShort: wrong parameter ID");
390  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
391  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
392  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
393  debug(2,"read MessageId %x", clRead.m_uiMessageId);
394  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
395  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
396  bRecieved = false;
397  }
398  }
399  while(!bRecieved);
400 
401  clData.aucData[0] = clRead.m_aucMessageData[2];
402  clData.aucData[1] = clRead.m_aucMessageData[3];
403  *puiData = clData.auiData[0];
404  LeaveCriticalSection(&m_csDevice);
405 
406  return m_iErrorState;
407 }
408 
409 int CProtocolDevice::readLong(int iModuleId, int iCommandId, int iParameterId, long* piData)
410 {
411  EnterCriticalSection(&m_csDevice);
412  m_iErrorState = 0;
413  bool bRecieved = false;
414  static CProtocolMessage clWrite, clRead;
415  static CProtocolData clData;
416 
417  clWrite.m_uiMessageId = MSGID_GET + iModuleId;
418  clWrite.m_aucMessageData[0] = iCommandId;
419  clWrite.m_aucMessageData[1] = iParameterId;
420  clWrite.m_ucMessageLength = 2;
421  clWrite.m_iModuleId = iModuleId;
422  clRead = clWrite;
423 
424  m_iErrorState = writeDevice(clWrite);
425  if(m_iErrorState != 0)
426  {
427  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
428  LeaveCriticalSection(&m_csDevice);
429  return m_iErrorState;
430  }
431 
432  do
433  {
434  m_iErrorState = readDevice(clRead);
435  if(m_iErrorState != 0)
436  {
437  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
438  LeaveCriticalSection(&m_csDevice);
439  return m_iErrorState;
440  }
441  bRecieved = true;
442  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
443  {
444  debug(1,"readLong: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
445  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
446  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
447  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
448  debug(2,"read MessageId %x", clRead.m_uiMessageId);
449  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
450  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
451  bRecieved = false;
452  }
453  if(clRead.m_aucMessageData[0] != iCommandId)
454  {
455  debug(1,"readLong: wrong command ID");
456  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
457  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
458  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
459  debug(2,"read MessageId %x", clRead.m_uiMessageId);
460  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
461  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
462  bRecieved = false;
463  }
464  if(clRead.m_aucMessageData[1] != iParameterId)
465  {
466  debug(1,"readLong: wrong parameter ID");
467  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
468  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
469  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
470  debug(2,"read MessageId %x", clRead.m_uiMessageId);
471  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
472  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
473  bRecieved = false;
474  }
475  }
476  while(!bRecieved);
477 
478  clData.aucData[0] = clRead.m_aucMessageData[2];
479  clData.aucData[1] = clRead.m_aucMessageData[3];
480  clData.aucData[2] = clRead.m_aucMessageData[4];
481  clData.aucData[3] = clRead.m_aucMessageData[5];
482  *piData = clData.iData;
483  LeaveCriticalSection(&m_csDevice);
484 
485  return m_iErrorState;
486 }
487 
488 int CProtocolDevice::readUnsignedLong(int iModuleId, int iCommandId, int iParameterId, unsigned long* puiData)
489 {
490  EnterCriticalSection(&m_csDevice);
491  m_iErrorState = 0;
492  bool bRecieved = false;
493  static CProtocolMessage clWrite, clRead;
494  static CProtocolData clData;
495 
496  clWrite.m_uiMessageId = MSGID_GET + iModuleId;
497  clWrite.m_aucMessageData[0] = iCommandId;
498  clWrite.m_aucMessageData[1] = iParameterId;
499  clWrite.m_ucMessageLength = 2;
500  clWrite.m_iModuleId = iModuleId;
501  clRead = clWrite;
502 
503  m_iErrorState = writeDevice(clWrite);
504  if(m_iErrorState != 0)
505  {
506  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
507  LeaveCriticalSection(&m_csDevice);
508  return m_iErrorState;
509  }
510  do
511  {
512  m_iErrorState = readDevice(clRead);
513  if(m_iErrorState != 0)
514  {
515  //warning( "wrong readDevice ErrorCode %i", m_iErrorState );
516  LeaveCriticalSection(&m_csDevice);
517  return m_iErrorState;
518  }
519  bRecieved = true;
520  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
521  {
522  debug(1,"readUnsignedLong: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
523  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
524  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
525  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
526  debug(2,"read MessageId %x", clRead.m_uiMessageId);
527  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
528  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
529  bRecieved = false;
530  }
531 
532  if(clRead.m_aucMessageData[0] != iCommandId)
533  {
534  debug(1,"readUnsignedLong: wrong command ID");
535  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
536  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
537  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
538  debug(2,"read MessageId %x", clRead.m_uiMessageId);
539  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
540  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
541  bRecieved = false;
542  }
543 
544  if(clRead.m_aucMessageData[1] != iParameterId)
545  {
546  debug(1,"readUnsignedLong: wrong parameter ID");
547  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
548  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
549  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
550  debug(2,"read MessageId %x", clRead.m_uiMessageId);
551  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
552  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
553  bRecieved = false;
554  }
555  }
556  while(!bRecieved);
557 
558  clData.aucData[0] = clRead.m_aucMessageData[2];
559  clData.aucData[1] = clRead.m_aucMessageData[3];
560  clData.aucData[2] = clRead.m_aucMessageData[4];
561  clData.aucData[3] = clRead.m_aucMessageData[5];
562  *puiData = clData.uiData;
563  LeaveCriticalSection(&m_csDevice);
564 
565  return m_iErrorState;
566 }
567 
568 int CProtocolDevice::readFloat(int iModuleId, int iCommandId, int iParameterId, float* pfData)
569 {
570  EnterCriticalSection(&m_csDevice);
571  m_iErrorState = 0;
572  bool bRecieved = false;
573  static CProtocolMessage clWrite, clRead;
574  static CProtocolData clData;
575 
576  clWrite.m_uiMessageId = MSGID_GET + iModuleId;
577  clWrite.m_aucMessageData[0] = iCommandId;
578  clWrite.m_aucMessageData[1] = iParameterId;
579  clWrite.m_ucMessageLength = 2;
580  clWrite.m_iModuleId = iModuleId;
581  clRead = clWrite;
582 
583  m_iErrorState = writeDevice(clWrite);
584  if(m_iErrorState != 0)
585  {
586  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
587  LeaveCriticalSection(&m_csDevice);
588  return m_iErrorState;
589  }
590 
591  do
592  {
593  m_iErrorState = readDevice(clRead);
594  if(m_iErrorState != 0)
595  {
596 // warning("wrong readDevice ErrorCode %i", m_iErrorState);
597  LeaveCriticalSection(&m_csDevice);
598  return m_iErrorState;
599  }
600  bRecieved = true;
601  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
602  {
603  debug(1,"readFloat: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
604  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
605  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
606  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
607  debug(2,"read MessageId %x", clRead.m_uiMessageId);
608  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
609  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
610  bRecieved = false;
611  }
612  if(clRead.m_aucMessageData[0] != iCommandId)
613  {
614  debug(1,"readFloat: wrong command ID");
615  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
616  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
617  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
618  debug(2,"read MessageId %x", clRead.m_uiMessageId);
619  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
620  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
621  bRecieved = false;
622  }
623  if(clRead.m_aucMessageData[1] != iParameterId)
624  {
625  debug(1,"readFloat: wrong parameter ID");
626  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
627  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
628  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
629  debug(2,"read MessageId %x", clRead.m_uiMessageId);
630  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
631  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
632  bRecieved = false;
633  }
634  }while(!bRecieved);
635 
636  clData.aucData[0] = clRead.m_aucMessageData[2];
637  clData.aucData[1] = clRead.m_aucMessageData[3];
638  clData.aucData[2] = clRead.m_aucMessageData[4];
639  clData.aucData[3] = clRead.m_aucMessageData[5];
640  *pfData = clData.fData;
641  LeaveCriticalSection(&m_csDevice);
642 
643  return m_iErrorState;
644 }
645 
646 int CProtocolDevice::readLongUnsignedChars(int iModuleId, int iCommandId, int iParameterId, long* piData, unsigned char* pucData1, unsigned char* pucData2)
647 {
648  EnterCriticalSection(&m_csDevice);
649  m_iErrorState = 0;
650  bool bRecieved = false;
651  static CProtocolMessage clWrite, clRead;
652  static CProtocolData clData;
653 
654  clWrite.m_uiMessageId = MSGID_GET + iModuleId;
655  clWrite.m_aucMessageData[0] = iCommandId;
656  clWrite.m_aucMessageData[1] = iParameterId;
657  clWrite.m_ucMessageLength = 2;
658  clWrite.m_iModuleId = iModuleId;
659  clRead = clWrite;
660 
661  m_iErrorState = writeDevice(clWrite);
662  if(m_iErrorState != 0)
663  {
664  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
665  LeaveCriticalSection(&m_csDevice);
666  return m_iErrorState;
667  }
668 
669  do
670  {
671  m_iErrorState = readDevice(clRead);
672  if(m_iErrorState != 0)
673  {
674  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
675  LeaveCriticalSection(&m_csDevice);
676  return m_iErrorState;
677  }
678  bRecieved = true;
679  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
680  {
681  debug(1,"readLongUnsignedChars: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
682  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
683  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
684  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
685  debug(2,"read MessageId %x", clRead.m_uiMessageId);
686  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
687  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
688  bRecieved = false;
689  }
690  if(clRead.m_aucMessageData[0] != iCommandId)
691  {
692  debug(1,"readLongUnsignedChars: wrong command ID");
693  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
694  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
695  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
696  debug(2,"read MessageId %x", clRead.m_uiMessageId);
697  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
698  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
699  bRecieved = false;
700  }
701  if(clRead.m_aucMessageData[1] != iParameterId)
702  {
703  debug(1,"readLongUnsignedChars: wrong parameter ID");
704  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
705  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
706  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
707  debug(2,"read MessageId %x", clRead.m_uiMessageId);
708  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
709  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
710  bRecieved = false;
711  }
712  }
713  while(!bRecieved);
714 
715  clData.aucData[0] = clRead.m_aucMessageData[2];
716  clData.aucData[1] = clRead.m_aucMessageData[3];
717  clData.aucData[2] = clRead.m_aucMessageData[4];
718  clData.aucData[3] = clRead.m_aucMessageData[5];
719  *piData = clData.iData;
720  *pucData1 = clRead.m_aucMessageData[6];
721  *pucData2 = clRead.m_aucMessageData[7];
722  LeaveCriticalSection(&m_csDevice);
723 
724  return m_iErrorState;
725 }
726 
727 int CProtocolDevice::readFloatUnsignedChars(int iModuleId, int iCommandId, int iParameterId, float* pfData, unsigned char* pucData1, unsigned char* pucData2)
728 {
729  EnterCriticalSection(&m_csDevice);
730  m_iErrorState = 0;
731  bool bRecieved = false;
732  static CProtocolMessage clWrite, clRead;
733  static CProtocolData clData;
734 
735  clWrite.m_uiMessageId = MSGID_GET + iModuleId;
736  clWrite.m_aucMessageData[0] = iCommandId;
737  clWrite.m_aucMessageData[1] = iParameterId;
738  clWrite.m_ucMessageLength = 2;
739  clWrite.m_iModuleId = iModuleId;
740  clRead = clWrite;
741 
742  m_iErrorState = writeDevice(clWrite);
743  if(m_iErrorState != 0)
744  {
745  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
746  LeaveCriticalSection(&m_csDevice);
747  return m_iErrorState;
748  }
749 
750  do
751  {
752  m_iErrorState = readDevice(clRead);
753  if(m_iErrorState != 0)
754  {
755  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
756  LeaveCriticalSection(&m_csDevice);
757  return m_iErrorState;
758  }
759  bRecieved = true;
760  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
761  {
762  debug(1,"readFloatUnsignedChars: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
763  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
764  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
765  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
766  debug(2,"read MessageId %x", clRead.m_uiMessageId);
767  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
768  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
769  bRecieved = false;
770  }
771  if(clRead.m_aucMessageData[0] != iCommandId)
772  {
773  debug(1,"readFloatUnsignedChars: wrong command ID");
774  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
775  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
776  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
777  debug(2,"read MessageId %x", clRead.m_uiMessageId);
778  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
779  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
780  bRecieved = false;
781  }
782  if(clRead.m_aucMessageData[1] != iParameterId)
783  {
784  debug(1,"readFloatUnsignedChars: wrong parameter ID");
785  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
786  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
787  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
788  debug(2,"read MessageId %x", clRead.m_uiMessageId);
789  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
790  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
791  bRecieved = false;
792  }
793  }
794  while(!bRecieved);
795 
796  clData.aucData[0] = clRead.m_aucMessageData[2];
797  clData.aucData[1] = clRead.m_aucMessageData[3];
798  clData.aucData[2] = clRead.m_aucMessageData[4];
799  clData.aucData[3] = clRead.m_aucMessageData[5];
800  *pfData = clData.fData;
801  *pucData1 = clRead.m_aucMessageData[6];
802  *pucData2 = clRead.m_aucMessageData[7];
803  LeaveCriticalSection(&m_csDevice);
804 
805  return m_iErrorState;
806 }
807 
808 int CProtocolDevice::writeChar(int iModuleId, int iCommandId, int iParameterId, char cData)
809 {
810  EnterCriticalSection(&m_csDevice);
811  m_iErrorState = 0;
812  bool bRecieved = false;
813  static CProtocolMessage clWrite, clRead;
814 
815  clWrite.m_uiMessageId = MSGID_SET + iModuleId;
816  clWrite.m_aucMessageData[0] = iCommandId;
817  clWrite.m_aucMessageData[1] = iParameterId;
818  clWrite.m_aucMessageData[2] = cData;
819  clWrite.m_ucMessageLength = 3;
820  clWrite.m_iModuleId = iModuleId;
821  clRead = clWrite;
822 
823  m_iErrorState = writeDevice(clWrite);
824  if(m_iErrorState != 0)
825  {
826  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
827  LeaveCriticalSection(&m_csDevice);
828  return m_iErrorState;
829  }
830 
831  do
832  {
833  m_iErrorState = readDevice(clRead);
834  if(m_iErrorState != 0)
835  {
836  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
837  LeaveCriticalSection(&m_csDevice);
838  return m_iErrorState;
839  }
840  bRecieved = true;
841  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
842  {
843  debug(1,"writeChar: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
844  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
845  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
846  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
847  debug(2,"read MessageId %x", clRead.m_uiMessageId);
848  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
849  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
850  bRecieved = false;
851  }
852  if(clRead.m_aucMessageData[0] != iCommandId)
853  {
854  debug(1,"writeChar: wrong command ID");
855  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
856  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
857  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
858  debug(2,"read MessageId %x", clRead.m_uiMessageId);
859  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
860  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
861  bRecieved = false;
862  }
863  if(clRead.m_aucMessageData[1] != iParameterId)
864  {
865  debug(1,"writeChar: wrong parameter ID");
866  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
867  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
868  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
869  debug(2,"read MessageId %x", clRead.m_uiMessageId);
870  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
871  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
872  bRecieved = false;
873  }
874  }
875  while(!bRecieved);
876  LeaveCriticalSection(&m_csDevice);
877 
878  return m_iErrorState;
879 }
880 
881 int CProtocolDevice::writeUnsignedChar(int iModuleId, int iCommandId, int iParameterId, unsigned char ucData)
882 {
883  EnterCriticalSection(&m_csDevice);
884  m_iErrorState = 0;
885  bool bRecieved = false;
886  static CProtocolMessage clWrite, clRead;
887 
888  clWrite.m_uiMessageId = MSGID_SET + iModuleId;
889  clWrite.m_aucMessageData[0] = iCommandId;
890  clWrite.m_aucMessageData[1] = iParameterId;
891  clWrite.m_aucMessageData[2] = ucData;
892  clWrite.m_ucMessageLength = 3;
893  clWrite.m_iModuleId = iModuleId;
894  clRead = clWrite;
895 
896  m_iErrorState = writeDevice(clWrite);
897  if(m_iErrorState != 0)
898  {
899  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
900  LeaveCriticalSection(&m_csDevice);
901  return m_iErrorState;
902  }
903 
904  do
905  {
906  m_iErrorState = readDevice(clRead);
907  if(m_iErrorState != 0)
908  {
909  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
910  LeaveCriticalSection(&m_csDevice);
911  return m_iErrorState;
912  }
913  bRecieved = true;
914  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
915  {
916  debug(1,"writeUnsignedChar: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
917  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
918  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
919  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
920  debug(2,"read MessageId %x", clRead.m_uiMessageId);
921  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
922  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
923  bRecieved = false;
924  }
925  if(clRead.m_aucMessageData[0] != iCommandId)
926  {
927  debug(1,"writeUnsignedChar: wrong command ID");
928  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
929  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
930  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
931  debug(2,"read MessageId %x", clRead.m_uiMessageId);
932  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
933  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
934  bRecieved = false;
935  }
936  if(clRead.m_aucMessageData[1] != iParameterId)
937  {
938  debug(1,"writeUnsignedChar: wrong parameter ID");
939  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
940  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
941  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
942  debug(2,"read MessageId %x", clRead.m_uiMessageId);
943  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
944  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
945  bRecieved = false;
946  }
947  }
948  while(!bRecieved);
949  LeaveCriticalSection(&m_csDevice);
950 
951  return m_iErrorState;
952 }
953 
954 int CProtocolDevice::writeShort(int iModuleId, int iCommandId, int iParameterId, short iData)
955 {
956  EnterCriticalSection(&m_csDevice);
957  m_iErrorState = 0;
958  bool bRecieved = false;
959  static CProtocolMessage clWrite, clRead;
960  static CProtocolData clData;
961 
962  clData.aiData[0] = iData;
963  clWrite.m_uiMessageId = MSGID_SET + iModuleId;
964  clWrite.m_aucMessageData[0] = iCommandId;
965  clWrite.m_aucMessageData[1] = iParameterId;
966  clWrite.m_aucMessageData[2] = clData.aucData[0];
967  clWrite.m_aucMessageData[3] = clData.aucData[1];
968  clWrite.m_ucMessageLength = 4;
969  clWrite.m_iModuleId = iModuleId;
970  clRead = clWrite;
971 
972  m_iErrorState = writeDevice(clWrite);
973  if(m_iErrorState != 0)
974  {
975  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
976  LeaveCriticalSection(&m_csDevice);
977  return m_iErrorState;
978  }
979 
980  do
981  {
982  m_iErrorState = readDevice(clRead);
983  if(m_iErrorState != 0)
984  {
985  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
986  LeaveCriticalSection(&m_csDevice);
987  return m_iErrorState;
988  }
989  bRecieved = true;
990  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
991  {
992  debug(1,"writeShort: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
993  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
994  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
995  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
996  debug(2,"read MessageId %x", clRead.m_uiMessageId);
997  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
998  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
999  bRecieved = false;
1000  }
1001  if(clRead.m_aucMessageData[0] != iCommandId)
1002  {
1003  debug(1,"writeShort: wrong command ID");
1004  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1005  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1006  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1007  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1008  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1009  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1010  bRecieved = false;
1011  }
1012  if(clRead.m_aucMessageData[1] != iParameterId)
1013  {
1014  debug(1,"writeShort: wrong parameter ID");
1015  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1016  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1017  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1018  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1019  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1020  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1021  bRecieved = false;
1022  }
1023  }
1024  while(!bRecieved);
1025  LeaveCriticalSection(&m_csDevice);
1026 
1027  return m_iErrorState;
1028 }
1029 
1030 int CProtocolDevice::writeUnsignedShort(int iModuleId, int iCommandId, int iParameterId, unsigned short uiData)
1031 {
1032  EnterCriticalSection(&m_csDevice);
1033  m_iErrorState = 0;
1034  bool bRecieved = false;
1035  static CProtocolMessage clWrite, clRead;
1036  static CProtocolData clData;
1037 
1038  clData.auiData[0] = uiData;
1039  clWrite.m_uiMessageId = MSGID_SET + iModuleId;
1040  clWrite.m_aucMessageData[0] = iCommandId;
1041  clWrite.m_aucMessageData[1] = iParameterId;
1042  clWrite.m_aucMessageData[2] = clData.aucData[0];
1043  clWrite.m_aucMessageData[3] = clData.aucData[1];
1044  clWrite.m_ucMessageLength = 4;
1045  clWrite.m_iModuleId = iModuleId;
1046  clRead = clWrite;
1047 
1048  m_iErrorState = writeDevice(clWrite);
1049  if(m_iErrorState != 0)
1050  {
1051  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
1052  LeaveCriticalSection(&m_csDevice);
1053  return m_iErrorState;
1054  }
1055 
1056  do
1057  {
1058  m_iErrorState = readDevice(clRead);
1059  if(m_iErrorState != 0)
1060  {
1061  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
1062  LeaveCriticalSection(&m_csDevice);
1063  return m_iErrorState;
1064  }
1065  bRecieved = true;
1066  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
1067  {
1068  debug(1,"writeUnsignedShort: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
1069  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1070  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1071  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1072  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1073  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1074  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1075  bRecieved = false;
1076  }
1077  if(clRead.m_aucMessageData[0] != iCommandId)
1078  {
1079  debug(1,"writeUnsignedShort: wrong command ID");
1080  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1081  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1082  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1083  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1084  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1085  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1086  bRecieved = false;
1087  }
1088  if(clRead.m_aucMessageData[1] != iParameterId)
1089  {
1090  debug(1,"writeUnsignedShort: wrong parameter ID");
1091  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1092  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1093  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1094  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1095  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1096  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1097  bRecieved = false;
1098  }
1099  }
1100  while(!bRecieved);
1101  LeaveCriticalSection(&m_csDevice);
1102 
1103  return m_iErrorState;
1104 }
1105 
1106 int CProtocolDevice::writeLong(int iModuleId, int iCommandId, int iParameterId, long iData)
1107 {
1108  EnterCriticalSection(&m_csDevice);
1109  m_iErrorState = 0;
1110  bool bRecieved = false;
1111  static CProtocolMessage clWrite, clRead;
1112  static CProtocolData clData;
1113 
1114  clData.iData = iData;
1115  clWrite.m_uiMessageId = MSGID_SET + iModuleId;
1116  clWrite.m_aucMessageData[0] = iCommandId;
1117  clWrite.m_aucMessageData[1] = iParameterId;
1118  clWrite.m_aucMessageData[2] = clData.aucData[0];
1119  clWrite.m_aucMessageData[3] = clData.aucData[1];
1120  clWrite.m_aucMessageData[4] = clData.aucData[2];
1121  clWrite.m_aucMessageData[5] = clData.aucData[3];
1122  clWrite.m_ucMessageLength = 6;
1123  clWrite.m_iModuleId = iModuleId;
1124  clRead = clWrite;
1125 
1126  m_iErrorState = writeDevice(clWrite);
1127  if(m_iErrorState != 0)
1128  {
1129  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
1130  LeaveCriticalSection(&m_csDevice);
1131  return m_iErrorState;
1132  }
1133 
1134  do
1135  {
1136  m_iErrorState = readDevice(clRead);
1137  if(m_iErrorState != 0)
1138  {
1139  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
1140  LeaveCriticalSection(&m_csDevice);
1141  return m_iErrorState;
1142  }
1143  bRecieved = true;
1144  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
1145  {
1146  debug(1,"writeLong: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
1147  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1148  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1149  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1150  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1151  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1152  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1153  bRecieved = false;
1154  }
1155  if(clRead.m_aucMessageData[0] != iCommandId)
1156  {
1157  debug(1,"writeLong: wrong command ID");
1158  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1159  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1160  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1161  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1162  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1163  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1164  bRecieved = false;
1165  }
1166  if(clRead.m_aucMessageData[1] != iParameterId)
1167  {
1168  debug(1,"writeLong: wrong parameter ID");
1169  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1170  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1171  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1172  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1173  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1174  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1175  bRecieved = false;
1176  }
1177  }
1178  while(!bRecieved);
1179  LeaveCriticalSection(&m_csDevice);
1180 
1181  return m_iErrorState;
1182 }
1183 
1184 int CProtocolDevice::writeUnsignedLong(int iModuleId, int iCommandId, int iParameterId, unsigned long uiData)
1185 {
1186  EnterCriticalSection(&m_csDevice);
1187  m_iErrorState = 0;
1188  bool bRecieved = false;
1189  static CProtocolMessage clWrite, clRead;
1190  static CProtocolData clData;
1191 
1192  clData.uiData = uiData;
1193  clWrite.m_uiMessageId = MSGID_SET + iModuleId;
1194  clWrite.m_aucMessageData[0] = iCommandId;
1195  clWrite.m_aucMessageData[1] = iParameterId;
1196  clWrite.m_aucMessageData[2] = clData.aucData[0];
1197  clWrite.m_aucMessageData[3] = clData.aucData[1];
1198  clWrite.m_aucMessageData[4] = clData.aucData[2];
1199  clWrite.m_aucMessageData[5] = clData.aucData[3];
1200  clWrite.m_ucMessageLength = 6;
1201  clWrite.m_iModuleId = iModuleId;
1202  clRead = clWrite;
1203 
1204  m_iErrorState = writeDevice(clWrite);
1205  if(m_iErrorState != 0)
1206  {
1207  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
1208  LeaveCriticalSection(&m_csDevice);
1209  return m_iErrorState;
1210  }
1211 
1212  do
1213  {
1214  m_iErrorState = readDevice(clRead);
1215  if(m_iErrorState != 0)
1216  {
1217  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
1218  LeaveCriticalSection(&m_csDevice);
1219  return m_iErrorState;
1220  }
1221  bRecieved = true;
1222  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
1223  {
1224  debug(1,"writeUnsignedLong: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
1225  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1226  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1227  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1228  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1229  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1230  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1231  bRecieved = false;
1232  }
1233  if(clRead.m_aucMessageData[0] != iCommandId)
1234  {
1235  debug(1,"writeUnsignedLong: wrong command ID");
1236  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1237  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1238  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1239  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1240  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1241  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1242  bRecieved = false;
1243  }
1244  if(clRead.m_aucMessageData[1] != iParameterId)
1245  {
1246  debug(1,"writeUnsignedLong: wrong parameter ID");
1247  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1248  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1249  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1250  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1251  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1252  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1253  bRecieved = false;
1254  }
1255  }
1256  while(!bRecieved);
1257  LeaveCriticalSection(&m_csDevice);
1258 
1259  return m_iErrorState;
1260 }
1261 
1262 int CProtocolDevice::writeFloat(int iModuleId, int iCommandId, int iParameterId, float fData)
1263 {
1264  EnterCriticalSection(&m_csDevice);
1265  m_iErrorState = 0;
1266  bool bRecieved = false;
1267  static CProtocolMessage clWrite, clRead;
1268  static CProtocolData clData;
1269 
1270  clData.fData = fData;
1271  clWrite.m_uiMessageId = MSGID_SET + iModuleId;
1272  clWrite.m_aucMessageData[0] = iCommandId;
1273  clWrite.m_aucMessageData[1] = iParameterId;
1274  clWrite.m_aucMessageData[2] = clData.aucData[0];
1275  clWrite.m_aucMessageData[3] = clData.aucData[1];
1276  clWrite.m_aucMessageData[4] = clData.aucData[2];
1277  clWrite.m_aucMessageData[5] = clData.aucData[3];
1278  clWrite.m_ucMessageLength = 6;
1279  clWrite.m_iModuleId = iModuleId;
1280  clRead = clWrite;
1281 
1282  m_iErrorState = writeDevice(clWrite);
1283  if(m_iErrorState != 0)
1284  {
1285  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
1286  LeaveCriticalSection(&m_csDevice);
1287  return m_iErrorState;
1288  }
1289 
1290  do
1291  {
1292  m_iErrorState = readDevice(clRead);
1293  if(m_iErrorState != 0)
1294  {
1295  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
1296  LeaveCriticalSection(&m_csDevice);
1297  return m_iErrorState;
1298  }
1299  bRecieved = true;
1300  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
1301  {
1302  debug(1,"writeFloat: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
1303  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1304  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1305  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1306  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1307  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1308  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1309  bRecieved = false;
1310  }
1311  if(clRead.m_aucMessageData[0] != iCommandId)
1312  {
1313  debug(1,"writeFloat: wrong command ID");
1314  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1315  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1316  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1317  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1318  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1319  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1320  bRecieved = false;
1321  }
1322  if(clRead.m_aucMessageData[1] != iParameterId)
1323  {
1324  debug(1,"writeFloat: wrong parameter ID");
1325  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1326  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1327  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1328  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1329  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1330  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1331  bRecieved = false;
1332  }
1333  }
1334  while(!bRecieved);
1335  LeaveCriticalSection(&m_csDevice);
1336 
1337  return m_iErrorState;
1338 }
1339 
1340 int CProtocolDevice::writeAll(int iCommandId, int iParameterId)
1341 {
1342  EnterCriticalSection(&m_csDevice);
1343  m_iErrorState = 0;
1344  static CProtocolMessage clWrite, clRead;
1345 
1346  clWrite.m_uiMessageId = MSGID_ALL;
1347  clWrite.m_aucMessageData[0] = iCommandId;
1348  clWrite.m_aucMessageData[1] = iParameterId;
1349  clWrite.m_ucMessageLength = 2;
1350  clWrite.m_iModuleId = 0;
1351 
1352  m_iErrorState = writeDevice(clWrite);
1353  if(m_iErrorState != 0)
1354  {
1355  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
1356  LeaveCriticalSection(&m_csDevice);
1357  return m_iErrorState;
1358  }
1359 
1360  LeaveCriticalSection(&m_csDevice);
1361 
1362  return m_iErrorState;
1363 }
1364 
1365 int CProtocolDevice::writeCommand(int iModuleId, int iCommandId)
1366 {
1367  EnterCriticalSection(&m_csDevice);
1368  m_iErrorState = 0;
1369  bool bRecieved = false;
1370  static CProtocolMessage clWrite, clRead;
1371 
1372  clWrite.m_uiMessageId = MSGID_SET + iModuleId;
1373  clWrite.m_aucMessageData[0] = iCommandId;
1374  clWrite.m_ucMessageLength = 1;
1375  clWrite.m_iModuleId = iModuleId;
1376  clRead = clWrite;
1377 
1378  m_iErrorState = writeDevice(clWrite);
1379  if(m_iErrorState != 0)
1380  {
1381  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
1382  LeaveCriticalSection(&m_csDevice);
1383  return m_iErrorState;
1384  }
1385 
1386  do
1387  {
1388  m_iErrorState = readDevice(clRead);
1389  if(m_iErrorState != 0)
1390  {
1391  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
1392  LeaveCriticalSection(&m_csDevice);
1393  return m_iErrorState;
1394  }
1395  bRecieved = true;
1396  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
1397  {
1398  debug(1,"writeCommand: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
1399  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1400  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1401  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1402  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1403  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1404  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1405  bRecieved = false;
1406  }
1407  if(clRead.m_aucMessageData[0] != iCommandId)
1408  {
1409  debug(1,"writeCommand: wrong command ID");
1410  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1411  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1412  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1413  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1414  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1415  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1416  bRecieved = false;
1417  }
1418  }
1419  while(!bRecieved);
1420  LeaveCriticalSection(&m_csDevice);
1421 
1422  return m_iErrorState;
1423 }
1424 
1425 int CProtocolDevice::writeLongShort(int iModuleId, int iCommandId, int iParameterId, long iData, short iTime)
1426 {
1427  EnterCriticalSection(&m_csDevice);
1428  m_iErrorState = 0;
1429  bool bRecieved = false;
1430  static CProtocolMessage clWrite, clRead;
1431  static CProtocolData clData;
1432 
1433  clWrite.m_uiMessageId = MSGID_SET + iModuleId;
1434  clWrite.m_aucMessageData[0] = iCommandId;
1435  clWrite.m_aucMessageData[1] = iParameterId;
1436  clData.iData = iData;
1437  clWrite.m_aucMessageData[2] = clData.aucData[0];
1438  clWrite.m_aucMessageData[3] = clData.aucData[1];
1439  clWrite.m_aucMessageData[4] = clData.aucData[2];
1440  clWrite.m_aucMessageData[5] = clData.aucData[3];
1441  clData.aiData[0] = iTime;
1442  clWrite.m_aucMessageData[6] = clData.aucData[0];
1443  clWrite.m_aucMessageData[7] = clData.aucData[1];
1444  clWrite.m_ucMessageLength = 8;
1445  clWrite.m_iModuleId = iModuleId;
1446  clRead = clWrite;
1447 
1448  m_iErrorState = writeDevice(clWrite);
1449  if(m_iErrorState != 0)
1450  {
1451  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
1452  LeaveCriticalSection(&m_csDevice);
1453  return m_iErrorState;
1454  }
1455 
1456  do
1457  {
1458  m_iErrorState = readDevice(clRead);
1459  if(m_iErrorState != 0)
1460  {
1461  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
1462  LeaveCriticalSection(&m_csDevice);
1463  return m_iErrorState;
1464  }
1465  bRecieved = true;
1466  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
1467  {
1468  debug(1,"writeLongShort: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
1469  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1470  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1471  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1472  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1473  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1474  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1475  bRecieved = false;
1476  }
1477  if(clRead.m_aucMessageData[0] != iCommandId)
1478  {
1479  debug(1,"writeLongShort: wrong command ID");
1480  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1481  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1482  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1483  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1484  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1485  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1486  bRecieved = false;
1487  }
1488  if(clRead.m_aucMessageData[1] != iParameterId)
1489  {
1490  debug(1,"writeLongShort: wrong parameter ID");
1491  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1492  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1493  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1494  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1495  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1496  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1497  bRecieved = false;
1498  }
1499  }
1500  while(!bRecieved);
1501  LeaveCriticalSection(&m_csDevice);
1502 
1503  return m_iErrorState;
1504 }
1505 
1506 int CProtocolDevice::writeFloatShort(int iModuleId, int iCommandId, int iParameterId, float fData, short iData)
1507 {
1508  EnterCriticalSection(&m_csDevice);
1509  m_iErrorState = 0;
1510  bool bRecieved = false;
1511  static CProtocolMessage clWrite, clRead;
1512  static CProtocolData clData;
1513 
1514  clWrite.m_uiMessageId = MSGID_SET + iModuleId;
1515  clWrite.m_aucMessageData[0] = iCommandId;
1516  clWrite.m_aucMessageData[1] = iParameterId;
1517  clData.fData = fData;
1518  clWrite.m_aucMessageData[2] = clData.aucData[0];
1519  clWrite.m_aucMessageData[3] = clData.aucData[1];
1520  clWrite.m_aucMessageData[4] = clData.aucData[2];
1521  clWrite.m_aucMessageData[5] = clData.aucData[3];
1522  clData.aiData[0] = iData;
1523  clWrite.m_aucMessageData[6] = clData.aucData[0];
1524  clWrite.m_aucMessageData[7] = clData.aucData[1];
1525  clWrite.m_ucMessageLength = 8;
1526  clWrite.m_iModuleId = iModuleId;
1527  clRead = clWrite;
1528 
1529  m_iErrorState = writeDevice(clWrite);
1530  if(m_iErrorState != 0)
1531  {
1532  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
1533  LeaveCriticalSection(&m_csDevice);
1534  return m_iErrorState;
1535  }
1536 
1537  do
1538  {
1539  m_iErrorState = readDevice(clRead);
1540  if(m_iErrorState != 0)
1541  {
1542  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
1543  LeaveCriticalSection(&m_csDevice);
1544  return m_iErrorState;
1545  }
1546  bRecieved = true;
1547  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
1548  {
1549  debug(1,"writeFloatShort: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
1550  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1551  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1552  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1553  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1554  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1555  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1556  bRecieved = false;
1557  }
1558  if(clRead.m_aucMessageData[0] != iCommandId)
1559  {
1560  debug(1,"writeFloatShort: wrong command ID");
1561  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1562  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1563  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1564  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1565  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1566  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1567  bRecieved = false;
1568  }
1569  if(clRead.m_aucMessageData[1] != iParameterId)
1570  {
1571  debug(1,"writeFloatShort: wrong parameter ID");
1572  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1573  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1574  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1575  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1576  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1577  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1578  bRecieved = false;
1579  }
1580  }
1581  while(!bRecieved);
1582  LeaveCriticalSection(&m_csDevice);
1583 
1584  return m_iErrorState;
1585 }
1586 
1587 int CProtocolDevice::writeShortReadLongUnsignedChars(int iModuleId, int iCommandId, int iParameterId, short iData, long* piData, unsigned char* pucData1, unsigned char* pucData2)
1588 {
1589  EnterCriticalSection(&m_csDevice);
1590  m_iErrorState = 0;
1591  bool bRecieved = false;
1592  static CProtocolMessage clWrite, clRead;
1593  static CProtocolData clData;
1594 
1595  clData.aiData[0] = iData;
1596  clWrite.m_uiMessageId = MSGID_SET + iModuleId;
1597  clWrite.m_aucMessageData[0] = iCommandId;
1598  clWrite.m_aucMessageData[1] = iParameterId;
1599  clWrite.m_aucMessageData[2] = clData.aucData[0];
1600  clWrite.m_aucMessageData[3] = clData.aucData[1];
1601  clWrite.m_ucMessageLength = 4;
1602  clWrite.m_iModuleId = iModuleId;
1603  clRead = clWrite;
1604 
1605  m_iErrorState = writeDevice(clWrite);
1606  if(m_iErrorState != 0)
1607  {
1608  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
1609  LeaveCriticalSection(&m_csDevice);
1610  return m_iErrorState;
1611  }
1612 
1613  do
1614  {
1615  m_iErrorState = readDevice(clRead);
1616  if(m_iErrorState != 0)
1617  {
1618  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
1619  LeaveCriticalSection(&m_csDevice);
1620  return m_iErrorState;
1621  }
1622  bRecieved = true;
1623  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
1624  {
1625  debug(1,"writeShortReadUnsignedLongChars: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
1626  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1627  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1628  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1629  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1630  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1631  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1632  bRecieved = false;
1633  }
1634  if(clRead.m_aucMessageData[0] != iCommandId)
1635  {
1636  debug(1,"writeShortReadUnsignedLongChars: wrong command ID");
1637  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1638  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1639  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1640  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1641  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1642  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1643  bRecieved = false;
1644  }
1645  if(clRead.m_aucMessageData[1] != iParameterId)
1646  {
1647  debug(1,"writeShortReadUnsignedLongChars: wrong parameter ID");
1648  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1649  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1650  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1651  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1652  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1653  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1654  bRecieved = false;
1655  }
1656  }
1657  while(!bRecieved);
1658 
1659  clData.aucData[0] = clRead.m_aucMessageData[2];
1660  clData.aucData[1] = clRead.m_aucMessageData[3];
1661  clData.aucData[2] = clRead.m_aucMessageData[4];
1662  clData.aucData[3] = clRead.m_aucMessageData[5];
1663  *piData = clData.iData;
1664  *pucData1 = clRead.m_aucMessageData[6];
1665  *pucData2 = clRead.m_aucMessageData[7];
1666  LeaveCriticalSection(&m_csDevice);
1667 
1668  return m_iErrorState;
1669 }
1670 
1671 int CProtocolDevice::writeLongReadLongUnsignedChars(int iModuleId, int iCommandId, int iParameterId, long iData, long* piData, unsigned char* pucData1, unsigned char* pucData2)
1672 {
1673  EnterCriticalSection(&m_csDevice);
1674  m_iErrorState = 0;
1675  bool bRecieved = false;
1676  static CProtocolMessage clWrite, clRead;
1677  static CProtocolData clData;
1678 
1679  clData.iData = iData;
1680  clWrite.m_uiMessageId = MSGID_SET + iModuleId;
1681  clWrite.m_aucMessageData[0] = iCommandId;
1682  clWrite.m_aucMessageData[1] = iParameterId;
1683  clWrite.m_aucMessageData[2] = clData.aucData[0];
1684  clWrite.m_aucMessageData[3] = clData.aucData[1];
1685  clWrite.m_aucMessageData[4] = clData.aucData[2];
1686  clWrite.m_aucMessageData[5] = clData.aucData[3];
1687  clWrite.m_ucMessageLength = 6;
1688  clWrite.m_iModuleId = iModuleId;
1689  clRead = clWrite;
1690 
1691  m_iErrorState = writeDevice(clWrite);
1692  if(m_iErrorState != 0)
1693  {
1694  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
1695  LeaveCriticalSection(&m_csDevice);
1696  return m_iErrorState;
1697  }
1698 
1699  do
1700  {
1701  m_iErrorState = readDevice(clRead);
1702  if(m_iErrorState != 0)
1703  {
1704  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
1705  LeaveCriticalSection(&m_csDevice);
1706  return m_iErrorState;
1707  }
1708  bRecieved = true;
1709  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
1710  {
1711  debug(1,"writeLongReadUnsignedLongChars: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
1712  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1713  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1714  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1715  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1716  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1717  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1718  bRecieved = false;
1719  }
1720  if(clRead.m_aucMessageData[0] != iCommandId)
1721  {
1722  debug(1,"writeLongReadUnsignedLongChars: wrong command ID");
1723  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1724  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1725  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1726  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1727  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1728  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1729  bRecieved = false;
1730  }
1731  if(clRead.m_aucMessageData[1] != iParameterId)
1732  {
1733  debug(1,"writeLongReadUnsignedLongChars: wrong parameter ID");
1734  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1735  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1736  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1737  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1738  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1739  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1740  bRecieved = false;
1741  }
1742  }
1743  while(!bRecieved);
1744 
1745  clData.aucData[0] = clRead.m_aucMessageData[2];
1746  clData.aucData[1] = clRead.m_aucMessageData[3];
1747  clData.aucData[2] = clRead.m_aucMessageData[4];
1748  clData.aucData[3] = clRead.m_aucMessageData[5];
1749  *piData = clData.iData;
1750  *pucData1 = clRead.m_aucMessageData[6];
1751  *pucData2 = clRead.m_aucMessageData[7];
1752  LeaveCriticalSection(&m_csDevice);
1753 
1754  return m_iErrorState;
1755 }
1756 
1757 int CProtocolDevice::writeLongShortReadLongUnsignedChars(int iModuleId, int iCommandId, int iParameterId, long iData1, short iData2, long* piData, unsigned char* pucData1, unsigned char* pucData2)
1758 {
1759  EnterCriticalSection(&m_csDevice);
1760  m_iErrorState = 0;
1761  bool bRecieved = false;
1762  static CProtocolMessage clWrite, clRead;
1763  static CProtocolData clData;
1764 
1765  clWrite.m_uiMessageId = MSGID_SET + iModuleId;
1766  clWrite.m_aucMessageData[0] = iCommandId;
1767  clWrite.m_aucMessageData[1] = iParameterId;
1768  clData.iData = iData1;
1769  clWrite.m_aucMessageData[2] = clData.aucData[0];
1770  clWrite.m_aucMessageData[3] = clData.aucData[1];
1771  clWrite.m_aucMessageData[4] = clData.aucData[2];
1772  clWrite.m_aucMessageData[5] = clData.aucData[3];
1773  clData.aiData[0] = iData2;
1774  clWrite.m_aucMessageData[6] = clData.aucData[0];
1775  clWrite.m_aucMessageData[7] = clData.aucData[1];
1776  clWrite.m_ucMessageLength = 8;
1777  clWrite.m_iModuleId = iModuleId;
1778  clRead = clWrite;
1779 
1780  m_iErrorState = writeDevice(clWrite);
1781  if(m_iErrorState != 0)
1782  {
1783  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
1784  LeaveCriticalSection(&m_csDevice);
1785  return m_iErrorState;
1786  }
1787 
1788  do
1789  {
1790  m_iErrorState = readDevice(clRead);
1791  if(m_iErrorState != 0)
1792  {
1793  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
1794  LeaveCriticalSection(&m_csDevice);
1795  return m_iErrorState;
1796  }
1797  bRecieved = true;
1798  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
1799  {
1800  debug(1,"writeLongShortReadUnsignedLongChars: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
1801  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1802  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1803  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1804  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1805  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1806  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1807  bRecieved = false;
1808  }
1809  if(clRead.m_aucMessageData[0] != iCommandId)
1810  {
1811  debug(1,"writeLongShortReadUnsignedLongChars: wrong command ID");
1812  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1813  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1814  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1815  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1816  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1817  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1818  bRecieved = false;
1819  }
1820  if(clRead.m_aucMessageData[1] != iParameterId)
1821  {
1822  debug(1,"writeLongShortReadUnsignedLongChars: wrong parameter ID");
1823  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1824  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1825  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1826  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1827  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1828  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1829  bRecieved = false;
1830  }
1831  }
1832  while(!bRecieved);
1833 
1834  clData.aucData[0] = clRead.m_aucMessageData[2];
1835  clData.aucData[1] = clRead.m_aucMessageData[3];
1836  clData.aucData[2] = clRead.m_aucMessageData[4];
1837  clData.aucData[3] = clRead.m_aucMessageData[5];
1838  *piData = clData.iData;
1839  *pucData1 = clRead.m_aucMessageData[6];
1840  *pucData2 = clRead.m_aucMessageData[7];
1841  LeaveCriticalSection(&m_csDevice);
1842 
1843  return m_iErrorState;
1844 }
1845 
1846 int CProtocolDevice::writeFloatReadFloatUnsignedChars(int iModuleId, int iCommandId, int iParameterId, float fData, float* pfData, unsigned char* pucData1, unsigned char* pucData2)
1847 {
1848  EnterCriticalSection(&m_csDevice);
1849  m_iErrorState = 0;
1850  bool bRecieved = false;
1851  static CProtocolMessage clWrite, clRead;
1852  static CProtocolData clData;
1853 
1854  clData.fData = fData;
1855  clWrite.m_uiMessageId = MSGID_SET + iModuleId;
1856  clWrite.m_aucMessageData[0] = iCommandId;
1857  clWrite.m_aucMessageData[1] = iParameterId;
1858  clWrite.m_aucMessageData[2] = clData.aucData[0];
1859  clWrite.m_aucMessageData[3] = clData.aucData[1];
1860  clWrite.m_aucMessageData[4] = clData.aucData[2];
1861  clWrite.m_aucMessageData[5] = clData.aucData[3];
1862  clWrite.m_ucMessageLength = 6;
1863  clWrite.m_iModuleId = iModuleId;
1864  clRead = clWrite;
1865 
1866  m_iErrorState = writeDevice(clWrite);
1867  if(m_iErrorState != 0)
1868  {
1869  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
1870  LeaveCriticalSection(&m_csDevice);
1871  return m_iErrorState;
1872  }
1873 
1874  do
1875  {
1876  m_iErrorState = readDevice(clRead);
1877  if(m_iErrorState != 0)
1878  {
1879  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
1880  LeaveCriticalSection(&m_csDevice);
1881  return m_iErrorState;
1882  }
1883  bRecieved = true;
1884  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
1885  {
1886  debug(1,"writeFloatReadUnsignedLongChars: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
1887  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1888  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1889  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1890  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1891  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1892  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1893  bRecieved = false;
1894  }
1895  if(clRead.m_aucMessageData[0] != iCommandId)
1896  {
1897  debug(1,"writeFloatReadUnsignedLongChars: wrong command ID");
1898  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1899  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1900  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1901  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1902  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1903  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1904  bRecieved = false;
1905  }
1906  if(clRead.m_aucMessageData[1] != iParameterId)
1907  {
1908  debug(1,"writeFloatReadUnsignedLongChars: wrong parameter ID");
1909  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1910  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1911  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1912  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1913  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1914  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1915  bRecieved = false;
1916  }
1917  }
1918  while(!bRecieved);
1919 
1920  clData.aucData[0] = clRead.m_aucMessageData[2];
1921  clData.aucData[1] = clRead.m_aucMessageData[3];
1922  clData.aucData[2] = clRead.m_aucMessageData[4];
1923  clData.aucData[3] = clRead.m_aucMessageData[5];
1924  *pfData = clData.fData;
1925  *pucData1 = clRead.m_aucMessageData[6];
1926  *pucData2 = clRead.m_aucMessageData[7];
1927  LeaveCriticalSection(&m_csDevice);
1928 
1929  return m_iErrorState;
1930 }
1931 
1932 int CProtocolDevice::writeFloatShortReadFloatUnsignedChars(int iModuleId, int iCommandId, int iParameterId, float fData, short iData, float* pfData, unsigned char* pucData1, unsigned char* pucData2)
1933 {
1934  EnterCriticalSection(&m_csDevice);
1935  m_iErrorState = 0;
1936  bool bRecieved = false;
1937  static CProtocolMessage clWrite, clRead;
1938  static CProtocolData clData;
1939 
1940  clWrite.m_uiMessageId = MSGID_SET + iModuleId;
1941  clWrite.m_aucMessageData[0] = iCommandId;
1942  clWrite.m_aucMessageData[1] = iParameterId;
1943  clData.fData = fData;
1944  clWrite.m_aucMessageData[2] = clData.aucData[0];
1945  clWrite.m_aucMessageData[3] = clData.aucData[1];
1946  clWrite.m_aucMessageData[4] = clData.aucData[2];
1947  clWrite.m_aucMessageData[5] = clData.aucData[3];
1948  clData.aiData[0] = iData;
1949  clWrite.m_aucMessageData[6] = clData.aucData[0];
1950  clWrite.m_aucMessageData[7] = clData.aucData[1];
1951  clWrite.m_ucMessageLength = 8;
1952  clWrite.m_iModuleId = iModuleId;
1953  clRead = clWrite;
1954 
1955  m_iErrorState = writeDevice(clWrite);
1956  if(m_iErrorState != 0)
1957  {
1958  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
1959  LeaveCriticalSection(&m_csDevice);
1960  return m_iErrorState;
1961  }
1962 
1963  do
1964  {
1965  m_iErrorState = readDevice(clRead);
1966  if(m_iErrorState != 0)
1967  {
1968  //warning("wrong readDevice ErrorCode %i", m_iErrorState);
1969  LeaveCriticalSection(&m_csDevice);
1970  return m_iErrorState;
1971  }
1972  bRecieved = true;
1973  if(clRead.m_uiMessageId != MSGID_ACK + iModuleId)
1974  {
1975  debug(1,"writeFloatShortReadUnsignedLongChars: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_ACK + iModuleId );
1976  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1977  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1978  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1979  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1980  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1981  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1982  bRecieved = false;
1983  }
1984  if(clRead.m_aucMessageData[0] != iCommandId)
1985  {
1986  debug(1,"writeFloatShortReadUnsignedLongChars: wrong command ID");
1987  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1988  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
1989  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
1990  debug(2,"read MessageId %x", clRead.m_uiMessageId);
1991  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
1992  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
1993  bRecieved = false;
1994  }
1995  if(clRead.m_aucMessageData[1] != iParameterId)
1996  {
1997  debug(1,"writeFloatShortReadUnsignedLongChars: wrong parameter ID");
1998  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
1999  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
2000  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
2001  debug(2,"read MessageId %x", clRead.m_uiMessageId);
2002  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
2003  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
2004  bRecieved = false;
2005  }
2006  }
2007  while(!bRecieved);
2008 
2009  clData.aucData[0] = clRead.m_aucMessageData[2];
2010  clData.aucData[1] = clRead.m_aucMessageData[3];
2011  clData.aucData[2] = clRead.m_aucMessageData[4];
2012  clData.aucData[3] = clRead.m_aucMessageData[5];
2013  *pfData = clData.fData;
2014  *pucData1 = clRead.m_aucMessageData[6];
2015  *pucData2 = clRead.m_aucMessageData[7];
2016  LeaveCriticalSection(&m_csDevice);
2017 
2018  return m_iErrorState;
2019 }
2020 
2021 // ========================================================================== ;
2022 // ;
2023 // ---- constructors / destructor ------------------------------------------- ;
2024 // ;
2025 // ========================================================================== ;
2026 
2027 CProtocolDevice::CProtocolDevice() //: m_iEMSModuleCount(0), m_iEMSModuleCountMax(31)
2028 {
2029 }
2030 
2032 {
2033  error(-1, "Sorry constructor is not implemented");
2034 }
2035 
2037 {
2038 }
2039 
2040 // ========================================================================== ;
2041 // ;
2042 // ---- operators ----------------------------------------------------------- ;
2043 // ;
2044 // ========================================================================== ;
2045 
2047 {
2048  error(-1, "Sorry operator= is not implemented");
2049  return *this;
2050 }
2051 
2052 // ========================================================================== ;
2053 // ;
2054 // ---- query functions ----------------------------------------------------- ;
2055 // ;
2056 // ========================================================================== ;
2057 
2058 int CProtocolDevice::getDataDLR_FTS(std::vector<float>& rafData, long* piState)
2059 {
2060  EnterCriticalSection(&m_csDevice);
2061  m_iErrorState = 0;
2062  bool bRecieved = false;
2063  static CProtocolMessage clWrite, clRead;
2064  static CProtocolData clData;
2065  if(m_bInitFlag == false)
2066  {
2067  warning("device not initialized");
2069  return m_iErrorState;
2070  }
2071 
2072  rafData.resize(6);
2074  clWrite.m_aucMessageData[0] = CMDID_DLR_DATA_GET;
2075  clWrite.m_aucMessageData[1] = PARID_DLR_DATA_GET;
2076  clWrite.m_ucMessageLength = 2;
2077 
2078  m_iErrorState = writeDevice(clWrite);
2079  if(m_iErrorState != 0)
2080  {
2081  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
2082  LeaveCriticalSection(&m_csDevice);
2083  return m_iErrorState;
2084  }
2085  do
2086  {
2087  m_iErrorState = readDevice(clRead);
2088  if(m_iErrorState != 0)
2089  {
2090  //warning("wrong 1. readDevice ErrorCode %i", m_iErrorState);
2091  clearReadQueue();
2092  LeaveCriticalSection(&m_csDevice);
2093  return m_iErrorState;
2094  }
2095  bRecieved = true;
2096  if(clRead.m_uiMessageId != MSGID_DLR_DATA_ACK)
2097  {
2098  debug(1,"getDataDLR_FTS: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_DLR_DATA_ACK );
2099  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
2100  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
2101  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
2102  debug(2,"read MessageId %x", clRead.m_uiMessageId);
2103  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
2104  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
2105  bRecieved = false;
2106  }
2107  if(clRead.m_aucMessageData[0] != CMDID_DLR_DATA_ACK0)
2108  {
2109  debug(1,"getDataDLR_FTS: wrong command ID %x, expected %x", clRead.m_aucMessageData[0], CMDID_DLR_DATA_ACK0);
2110  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
2111  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
2112  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
2113  debug(2,"read MessageId %x", clRead.m_uiMessageId);
2114  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
2115  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
2116  bRecieved = false;
2117  }
2118  }
2119  while(!bRecieved);
2120  clData.aucData[0] = clRead.m_aucMessageData[1];
2121  clData.aucData[1] = clRead.m_aucMessageData[2];
2122  clData.aucData[2] = clRead.m_aucMessageData[3];
2123  clData.aucData[3] = clRead.m_aucMessageData[4];
2124  rafData[0] = clData.fData;
2125  clData.aucData[0] = clRead.m_aucMessageData[5];
2126  clData.aucData[1] = clRead.m_aucMessageData[6];
2127  clData.aucData[2] = clRead.m_aucMessageData[7];
2128 
2129  bRecieved = false;
2130  do
2131  {
2132  m_iErrorState = readDevice(clRead);
2133  if(m_iErrorState != 0)
2134  {
2135  //warning("wrong 2. readDevice ErrorCode %i", m_iErrorState);
2136  clearReadQueue();
2137  LeaveCriticalSection(&m_csDevice);
2138  return m_iErrorState;
2139  }
2140  bRecieved = true;
2141  if(clRead.m_uiMessageId != MSGID_DLR_DATA_ACK)
2142  {
2143  debug(1,"getDataDLR_FTS: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_DLR_DATA_ACK );
2144  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
2145  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
2146  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
2147  debug(2,"read MessageId %x", clRead.m_uiMessageId);
2148  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
2149  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
2150  bRecieved = false;
2151  }
2152  if(clRead.m_aucMessageData[0] != CMDID_DLR_DATA_ACK1)
2153  {
2154  debug(1,"getDataDLR_FTS: wrong command ID %x, expected %x", clRead.m_aucMessageData[0], CMDID_DLR_DATA_ACK1);
2155  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
2156  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
2157  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
2158  debug(2,"read MessageId %x", clRead.m_uiMessageId);
2159  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
2160  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
2161  bRecieved = false;
2162  }
2163  }
2164  while(!bRecieved);
2165  clData.aucData[3] = clRead.m_aucMessageData[1];
2166  rafData[1] = clData.fData;
2167  clData.aucData[0] = clRead.m_aucMessageData[2];
2168  clData.aucData[1] = clRead.m_aucMessageData[3];
2169  clData.aucData[2] = clRead.m_aucMessageData[4];
2170  clData.aucData[3] = clRead.m_aucMessageData[5];
2171  rafData[2] = clData.fData;
2172  clData.aucData[0] = clRead.m_aucMessageData[6];
2173  clData.aucData[1] = clRead.m_aucMessageData[7];
2174 
2175  bRecieved = false;
2176  do
2177  {
2178  m_iErrorState = readDevice(clRead);
2179  if(m_iErrorState != 0)
2180  {
2181  //warning("wrong 3. readDevice ErrorCode %i", m_iErrorState);
2182  clearReadQueue();
2183  LeaveCriticalSection(&m_csDevice);
2184  return m_iErrorState;
2185  }
2186  bRecieved = true;
2187  if(clRead.m_uiMessageId != MSGID_DLR_DATA_ACK)
2188  {
2189  debug(1,"getDataDLR_FTS: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_DLR_DATA_ACK );
2190  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
2191  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
2192  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
2193  debug(2,"read MessageId %x", clRead.m_uiMessageId);
2194  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
2195  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
2196  bRecieved = false;
2197  }
2198  if(clRead.m_aucMessageData[0] != CMDID_DLR_DATA_ACK2)
2199  {
2200  debug(1,"getDataDLR_FTS: wrong command ID %x, expected %x", clRead.m_aucMessageData[0], CMDID_DLR_DATA_ACK2);
2201  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
2202  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
2203  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
2204  debug(2,"read MessageId %x", clRead.m_uiMessageId);
2205  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
2206  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
2207  bRecieved = false;
2208  }
2209  }
2210  while(!bRecieved);
2211  clData.aucData[2] = clRead.m_aucMessageData[1];
2212  clData.aucData[3] = clRead.m_aucMessageData[2];
2213  rafData[3] = clData.fData;
2214  clData.aucData[0] = clRead.m_aucMessageData[3];
2215  clData.aucData[1] = clRead.m_aucMessageData[4];
2216  clData.aucData[2] = clRead.m_aucMessageData[5];
2217  clData.aucData[3] = clRead.m_aucMessageData[6];
2218  rafData[4] = clData.fData;
2219  clData.aucData[0] = clRead.m_aucMessageData[7];
2220 
2221  bRecieved = false;
2222  do
2223  {
2224  m_iErrorState = readDevice(clRead);
2225  if(m_iErrorState != 0)
2226  {
2227  //warning("wrong 4. readDevice ErrorCode %i", m_iErrorState);
2228  clearReadQueue();
2229  LeaveCriticalSection(&m_csDevice);
2230  return m_iErrorState;
2231  }
2232  bRecieved = true;
2233  if(clRead.m_uiMessageId != MSGID_DLR_DATA_ACK)
2234  {
2235  debug(1,"getDataDLR_FTS: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_DLR_DATA_ACK );
2236  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
2237  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
2238  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
2239  debug(2,"read MessageId %x", clRead.m_uiMessageId);
2240  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
2241  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
2242  bRecieved = false;
2243  }
2244  if(clRead.m_aucMessageData[0] != CMDID_DLR_DATA_ACK3)
2245  {
2246  debug(1,"getDataDLR_FTS: wrong command ID %x, expected %x", clRead.m_aucMessageData[0], CMDID_DLR_DATA_ACK3);
2247  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
2248  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
2249  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
2250  debug(2,"read MessageId %x", clRead.m_uiMessageId);
2251  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
2252  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
2253  bRecieved = false;
2254  }
2255  }
2256  while(!bRecieved);
2257  clData.aucData[1] = clRead.m_aucMessageData[1];
2258  clData.aucData[2] = clRead.m_aucMessageData[2];
2259  clData.aucData[3] = clRead.m_aucMessageData[3];
2260  rafData[5] = clData.fData;
2261  clData.aucData[0] = clRead.m_aucMessageData[4];
2262  clData.aucData[1] = clRead.m_aucMessageData[5];
2263  clData.aucData[2] = clRead.m_aucMessageData[6];
2264  clData.aucData[3] = clRead.m_aucMessageData[7];
2265  *piState = clData.iData;
2266 
2267  LeaveCriticalSection(&m_csDevice);
2268  return m_iErrorState;
2269 }
2270 
2271 int CProtocolDevice::getDataSCHUNK_FTC(int iModuleId, int iChannelTypeId, std::vector<float>& rafData, short* piState)
2272 {
2273  EnterCriticalSection(&m_csDevice);
2274  m_iErrorState = 0;
2275  bool bRecieved = false;
2276  static CProtocolMessage clWrite, clRead;
2277  static CProtocolData clData;
2278  if(m_bInitFlag == false)
2279  {
2280  warning("device not initialized");
2282  return m_iErrorState;
2283  }
2284  if(iModuleId < 1 || iModuleId > MAX_SCHUNK )
2285  {
2286  warning("bad SCHUNK module ID %i", iModuleId);
2288  LeaveCriticalSection(&m_csDevice);
2289  return m_iErrorState;
2290  }
2291 
2292  rafData.resize(6);
2293  clWrite.m_uiMessageId = MSGID_SCHUNK_SEND + iModuleId;
2294  if(iChannelTypeId == 0)
2296  else if(iChannelTypeId == 1)
2298  else
2300  clWrite.m_ucMessageLength = 1;
2301 
2302  m_iErrorState = writeDevice(clWrite);
2303  if(m_iErrorState != 0)
2304  {
2305  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
2306  LeaveCriticalSection(&m_csDevice);
2307  return m_iErrorState;
2308  }
2309  do
2310  {
2311  m_iErrorState = readDevice(clRead);
2312  if(m_iErrorState != 0)
2313  {
2314  warning("wrong 1. readDevice ErrorCode %i", m_iErrorState);
2315  LeaveCriticalSection(&m_csDevice);
2316  return m_iErrorState;
2317  }
2318  bRecieved = true;
2319  if(clRead.m_uiMessageId != MSGID_SCHUNK_RECV + iModuleId)
2320  {
2321  debug(1,"getDataSCHUNK_FTS: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_SCHUNK_RECV + iModuleId );
2322  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
2323  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
2324  debug(2,"read MessageId %x", clRead.m_uiMessageId);
2325  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
2326  bRecieved = false;
2327  }
2328  if(iChannelTypeId == 0)
2329  {
2330  if(clRead.m_aucMessageData[0] != CMDID_SCHUNK_GET_FTI + 1)
2331  {
2332  debug(1,"getDataSCHUNK_FTS: wrong command ID %x, expected %x", clRead.m_aucMessageData[0], CMDID_SCHUNK_GET_FTI + 1);
2333  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
2334  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
2335  debug(2,"read MessageId %x", clRead.m_uiMessageId);
2336  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
2337  bRecieved = false;
2338  }
2339  }
2340  else if(iChannelTypeId == 1)
2341  {
2342  if(clRead.m_aucMessageData[0] != CMDID_SCHUNK_GET_TRI + 1)
2343  {
2344  debug(1,"getDataSCHUNK_FTS: wrong command ID %x, expected %x", clRead.m_aucMessageData[0], CMDID_SCHUNK_GET_TRI + 1);
2345  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
2346  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
2347  debug(2,"read MessageId %x", clRead.m_uiMessageId);
2348  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
2349  bRecieved = false;
2350  }
2351  }
2352  else
2353  {
2354  if(clRead.m_aucMessageData[0] != CMDID_SCHUNK_GET_TEI + 1)
2355  {
2356  debug(1,"getDataSCHUNK_FTS: wrong command ID %x, expected %x", clRead.m_aucMessageData[0], CMDID_SCHUNK_GET_TEI + 1);
2357  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
2358  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
2359  debug(2,"read MessageId %x", clRead.m_uiMessageId);
2360  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
2361  bRecieved = false;
2362  }
2363  }
2364  }
2365  while(!bRecieved);
2366  clData.aucData[0] = clRead.m_aucMessageData[1];
2367  clData.aucData[1] = clRead.m_aucMessageData[2];
2368  clData.aucData[2] = clRead.m_aucMessageData[3];
2369  clData.aucData[3] = clRead.m_aucMessageData[4];
2370  if(iChannelTypeId == 0)
2371  {
2372  rafData[0] = clData.aiData[0] / 32.;
2373  rafData[1] = clData.aiData[1] / 32.;
2374  }
2375  else if(iChannelTypeId == 1)
2376  {
2377  rafData[0] = clData.aiData[0] / 4096000.;
2378  rafData[1] = clData.aiData[1] / 4096000.;
2379  }
2380  else
2381  {
2382  rafData[0] = clData.aiData[0];
2383  rafData[1] = clData.aiData[1];
2384  }
2385  clData.aucData[0] = clRead.m_aucMessageData[5];
2386  clData.aucData[1] = clRead.m_aucMessageData[6];
2387  clData.aucData[2] = clRead.m_aucMessageData[7];
2388  if(iChannelTypeId == 0)
2389  {
2390  rafData[2] = clData.aiData[0] / 32.;
2391  }
2392  else if(iChannelTypeId == 1)
2393  {
2394  rafData[2] = clData.aiData[0] / 4096000.;
2395  }
2396  else
2397  {
2398  rafData[2] = clData.aiData[0];
2399  }
2400 
2401  bRecieved = false;
2402  do
2403  {
2404  m_iErrorState = readDevice(clRead);
2405  if(m_iErrorState != 0)
2406  {
2407  warning("wrong 2. readDevice ErrorCode %i", m_iErrorState);
2408  LeaveCriticalSection(&m_csDevice);
2409  return m_iErrorState;
2410  }
2411  bRecieved = true;
2412  if(clRead.m_uiMessageId != MSGID_SCHUNK_RECV + iModuleId)
2413  {
2414  debug(1,"getDataSCHUNK_FTS: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_SCHUNK_RECV + iModuleId );
2415  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
2416  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
2417  debug(2,"read MessageId %x", clRead.m_uiMessageId);
2418  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
2419  bRecieved = false;
2420  }
2421  if(clRead.m_aucMessageData[0] != 0x01)
2422  {
2423  debug(1,"getDataSCHUNK_FTS: wrong command ID %x, expected %x", clRead.m_aucMessageData[0], 0x01);
2424  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
2425  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
2426  debug(2,"read MessageId %x", clRead.m_uiMessageId);
2427  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
2428  bRecieved = false;
2429  }
2430  }
2431  while(!bRecieved);
2432  clData.aucData[3] = clRead.m_aucMessageData[1];
2433  if(iChannelTypeId == 0)
2434  {
2435  rafData[3] = clData.aiData[1] / 1024.;
2436  }
2437  else if(iChannelTypeId == 1)
2438  {
2439  rafData[3] = clData.aiData[1] / 65536.;
2440  }
2441  else
2442  {
2443  rafData[3] = clData.aiData[1];
2444  }
2445  clData.aucData[0] = clRead.m_aucMessageData[2];
2446  clData.aucData[1] = clRead.m_aucMessageData[3];
2447  clData.aucData[2] = clRead.m_aucMessageData[4];
2448  clData.aucData[3] = clRead.m_aucMessageData[5];
2449  if(iChannelTypeId == 0)
2450  {
2451  rafData[4] = clData.aiData[0] / 1024.;
2452  rafData[5] = clData.aiData[1] / 1024.;
2453  }
2454  else if(iChannelTypeId == 1)
2455  {
2456  rafData[4] = clData.aiData[0] / 65536.;
2457  rafData[5] = clData.aiData[1] / 65536.;
2458  }
2459  else
2460  {
2461  rafData[4] = clData.aiData[0];
2462  rafData[5] = clData.aiData[1];
2463  }
2464  clData.aucData[0] = clRead.m_aucMessageData[6];
2465  clData.aucData[1] = clRead.m_aucMessageData[7];
2466 
2467  *piState = clData.aiData[0];
2468 
2469  LeaveCriticalSection(&m_csDevice);
2470  return m_iErrorState;
2471 }
2472 
2473 int CProtocolDevice::getDataMP55_IO(int iModuleId, float* pfData)
2474 {
2475  EnterCriticalSection(&m_csDevice);
2476  m_iErrorState = 0;
2477 
2478  bool bRecieved = false;
2479  static CProtocolMessage clWrite, clRead;
2480  static CProtocolData clData;
2481  if(m_bInitFlag == false)
2482  {
2483  warning("device not initialized");
2485  return m_iErrorState;
2486  }
2487  if(iModuleId < 0 || iModuleId > MAX_MP55 )
2488  {
2489  warning("bad MP55 module ID %i", iModuleId);
2491  LeaveCriticalSection(&m_csDevice);
2492  return m_iErrorState;
2493  }
2494  *pfData = 0;
2495 
2496  clWrite.m_uiMessageId = MSGID_MP55_SEND + iModuleId;
2497  clWrite.m_bRTRFlag = false;
2498  clWrite.m_aucMessageData[0] = 0x40;
2499  clWrite.m_aucMessageData[1] = 0x01;
2500  clWrite.m_aucMessageData[2] = 0x30;
2501  clWrite.m_aucMessageData[3] = 0x01;
2502  clWrite.m_aucMessageData[4] = 0x00;
2503  clWrite.m_aucMessageData[5] = 0x00;
2504  clWrite.m_aucMessageData[6] = 0x00;
2505  clWrite.m_aucMessageData[7] = 0x00;
2506  clWrite.m_ucMessageLength = 8;
2507 
2508  m_iErrorState = writeDevice(clWrite);
2509  if(m_iErrorState != 0)
2510  {
2511  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
2512  LeaveCriticalSection(&m_csDevice);
2513  return m_iErrorState;
2514  }
2515 
2516  do
2517  {
2518  m_iErrorState = readDevice(clRead);
2519  if(m_iErrorState != 0)
2520  {
2521  LeaveCriticalSection(&m_csDevice);
2522  return m_iErrorState;
2523  }
2524  bRecieved = true;
2525  if(clRead.m_uiMessageId != MSGID_MP55_RECV + iModuleId)
2526  {
2527  debug(1,"getDataMP55_IO: received CAN-ID %x, expected %x", clRead.m_uiMessageId, 0x580 + iModuleId);
2528  bRecieved = false;
2529  }
2530  }
2531  while(!bRecieved);
2532 
2533  clData.aucData[0] = clRead.m_aucMessageData[4];
2534  clData.aucData[1] = clRead.m_aucMessageData[5];
2535  clData.aucData[2] = clRead.m_aucMessageData[6];
2536  clData.aucData[3] = clRead.m_aucMessageData[7];
2537 
2538  *pfData = clData.fData;
2539 
2540  LeaveCriticalSection(&m_csDevice);
2541  return m_iErrorState;
2542 }
2543 
2544 int CProtocolDevice::getDataMP55_IO_fast(int iModuleId, float* pfData)
2545 {
2546  EnterCriticalSection(&m_csDevice);
2547  m_iErrorState = 0;
2548 
2549  bool bRecieved = false;
2550  static CProtocolMessage clWrite, clRead;
2551  static CProtocolData clData;
2552  if(m_bInitFlag == false)
2553  {
2554  warning("device not initialized");
2556  return m_iErrorState;
2557  }
2558  if(iModuleId < 0 || iModuleId > MAX_MP55 )
2559  {
2560  warning("bad MP55 module ID %i", iModuleId);
2562  LeaveCriticalSection(&m_csDevice);
2563  return m_iErrorState;
2564  }
2565  *pfData = 0;
2566 
2567  // Send SYNC
2568  clWrite.m_uiMessageId = 0x80;
2569  clWrite.m_bRTRFlag = false;
2570  clWrite.m_aucMessageData[0] = iModuleId;
2571  clWrite.m_ucMessageLength = 1;
2572 
2573  m_iErrorState = writeDevice(clWrite);
2574 
2575  // Read PDO
2576  do
2577  {
2578  m_iErrorState = readDevice(clRead);
2579  if(m_iErrorState != 0)
2580  {
2581  LeaveCriticalSection(&m_csDevice);
2582 // printf( "read PDO: %d\n", m_iErrorState );
2583  return m_iErrorState;
2584  }
2585  bRecieved = true;
2586  if(clRead.m_uiMessageId != 0x180 + iModuleId)
2587  {
2588 // printf("getDataMP55_IO: received CAN-ID %x, expected %x, len= %d\n", clRead.m_uiMessageId, 0x180 + iModuleId, clRead.m_ucMessageLength);
2589 // for( int i = 0; i < clRead.m_ucMessageLength; i++ )
2590 // printf( "data[%d]=%x\n", i, clRead.m_aucMessageData[i] );
2591  bRecieved = false;
2592  }
2593  Sleep( 1 );
2594  }
2595  while(!bRecieved);
2596 // printf( "getData PDO: error state %x\n", m_iErrorState );
2597 // printf( "getData PDO: received CAN-ID %x, expected %x\n", clRead.m_uiMessageId, 0x180 + iModuleId);
2598 
2599  clData.aucData[0] = clRead.m_aucMessageData[0];
2600  clData.aucData[1] = clRead.m_aucMessageData[1];
2601  clData.aucData[2] = clRead.m_aucMessageData[2];
2602  clData.aucData[3] = clRead.m_aucMessageData[3];
2603 
2604  //*pfData = ((float)clData.iData)/100000.0;
2605  *pfData = clData.fData;
2606 
2607  LeaveCriticalSection(&m_csDevice);
2608  return m_iErrorState;
2609 }
2610 
2611 int CProtocolDevice::getCanOpenRawAbsEnc(int iModuleId, short* piValue)
2612 {
2613  EnterCriticalSection(&m_csDevice);
2614  m_iErrorState = 0;
2615 
2616  bool bRecieved = false;
2617  static CProtocolMessage clWrite, clRead;
2618  static CProtocolData clData;
2619  if(m_bInitFlag == false)
2620  {
2621  warning("device not initialized");
2623  return m_iErrorState;
2624  }
2625  if(iModuleId < 0 || iModuleId > MAX_MP55 )
2626  {
2627  warning("bad CanOpen module ID %i", iModuleId);
2629  LeaveCriticalSection(&m_csDevice);
2630  return m_iErrorState;
2631  }
2632  *piValue = 0;
2633 
2634  clWrite.m_uiMessageId = MSGID_MP55_SEND + iModuleId;
2635  clWrite.m_bRTRFlag = false;
2636  clWrite.m_aucMessageData[0] = 0x40;
2637  clWrite.m_aucMessageData[1] = 0x04;
2638  clWrite.m_aucMessageData[2] = 0x60;
2639  clWrite.m_aucMessageData[3] = 0x00;
2640  clWrite.m_aucMessageData[4] = 0x00;
2641  clWrite.m_aucMessageData[5] = 0x00;
2642  clWrite.m_aucMessageData[6] = 0x00;
2643  clWrite.m_aucMessageData[7] = 0x00;
2644  clWrite.m_ucMessageLength = 4;
2645 
2646  m_iErrorState = writeDevice(clWrite);
2647  if(m_iErrorState != 0)
2648  {
2649  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
2650  LeaveCriticalSection(&m_csDevice);
2651  return m_iErrorState;
2652  }
2653 
2654  do
2655  {
2656  m_iErrorState = readDevice(clRead);
2657  if(m_iErrorState != 0)
2658  {
2659  printf( "wrong readDevice %d\n", m_iErrorState );
2660  LeaveCriticalSection(&m_csDevice);
2661  return m_iErrorState;
2662  }
2663  bRecieved = true;
2664  if(clRead.m_uiMessageId != MSGID_MP55_RECV + iModuleId)
2665  {
2666  printf("getCanOpenRawAbsEnc: received CAN-ID %lu, expected %x \n", clRead.m_uiMessageId, 0x580 + iModuleId);
2667  bRecieved = false;
2668  }
2669  }
2670  while(!bRecieved);
2671 
2672  clData.aucData[0] = clRead.m_aucMessageData[4];
2673  clData.aucData[1] = clRead.m_aucMessageData[5];
2674  clData.aucData[2] = clRead.m_aucMessageData[6];
2675  clData.aucData[3] = clRead.m_aucMessageData[7];
2676 
2677  *piValue = clData.aiData[0];
2678 
2679  LeaveCriticalSection(&m_csDevice);
2680  return m_iErrorState;
2681 }
2682 
2683 
2684 // ========================================================================== ;
2685 // ;
2686 // ---- modify functions ---------------------------------------------------- ;
2687 // ;
2688 // ========================================================================== ;
2689 
2690 int CProtocolDevice::setNullSCHUNK_FTC(int iModuleId, short* piState)
2691 {
2692  EnterCriticalSection(&m_csDevice);
2693  m_iErrorState = 0;
2694  bool bRecieved = false;
2695  static CProtocolMessage clWrite, clRead;
2696  static CProtocolData clData;
2697  if(m_bInitFlag == false)
2698  {
2699  warning("device not initialized");
2701  return m_iErrorState;
2702  }
2703  if(iModuleId < 1 || iModuleId > MAX_SCHUNK )
2704  {
2705  warning("bad SCHUNK module ID %i", iModuleId);
2707  LeaveCriticalSection(&m_csDevice);
2708  return m_iErrorState;
2709  }
2710 
2711  clWrite.m_uiMessageId = MSGID_SCHUNK_SEND + iModuleId;
2713  clWrite.m_ucMessageLength = 1;
2714 
2715  m_iErrorState = writeDevice(clWrite);
2716  if(m_iErrorState != 0)
2717  {
2718  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
2719  LeaveCriticalSection(&m_csDevice);
2720  return m_iErrorState;
2721  }
2722  do
2723  {
2724  m_iErrorState = readDevice(clRead);
2725  if(m_iErrorState != 0)
2726  {
2727  warning("wrong 1. readDevice ErrorCode %i", m_iErrorState);
2728  LeaveCriticalSection(&m_csDevice);
2729  return m_iErrorState;
2730  }
2731  bRecieved = true;
2732  if(clRead.m_uiMessageId != MSGID_SCHUNK_RECV + iModuleId)
2733  {
2734  debug(1,"setNullSCHUNK_FTS: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_SCHUNK_RECV + iModuleId );
2735  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
2736  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
2737  debug(2,"read MessageId %x", clRead.m_uiMessageId);
2738  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
2739  bRecieved = false;
2740  }
2741  if(clRead.m_aucMessageData[0] != CMDID_SCHUNK_SET_NULL + 1)
2742  {
2743  debug(1,"setNullSCHUNK_FTS: wrong command ID %x, expected %x", clRead.m_aucMessageData[0], CMDID_SCHUNK_SET_NULL + 1);
2744  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
2745  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
2746  debug(2,"read MessageId %x", clRead.m_uiMessageId);
2747  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
2748  bRecieved = false;
2749  }
2750  }
2751  while(!bRecieved);
2752  if(clRead.m_aucMessageData[1] != 'O' || clRead.m_aucMessageData[2] != 'K')
2753  {
2754  debug(1,"setNullSCHUNK_FTS: wrong answer '%c%c', expected 'OK'", clRead.m_aucMessageData[1], clRead.m_aucMessageData[2]);
2755  }
2756  clData.aucData[0] = clRead.m_aucMessageData[3];
2757  clData.aucData[1] = clRead.m_aucMessageData[4];
2758 
2759  *piState = clData.aiData[0];
2760  LeaveCriticalSection(&m_csDevice);
2761  return m_iErrorState;
2762 }
2763 
2764 int CProtocolDevice::setTaraMP55_IO(int iModuleId, float fTara)
2765 {
2766  EnterCriticalSection(&m_csDevice);
2767  m_iErrorState = 0;
2768 
2769  bool bRecieved = false;
2770  static CProtocolMessage clWrite, clRead;
2771  static CProtocolData clData;
2772 
2773  if(m_bInitFlag == false)
2774  {
2775  warning("device not initialized");
2777  return m_iErrorState;
2778  }
2779  if(iModuleId < 0 || iModuleId > MAX_MP55 )
2780  {
2781  warning("bad MP55 module ID %i", iModuleId);
2783  LeaveCriticalSection(&m_csDevice);
2784  return m_iErrorState;
2785  }
2786 
2787  clData.iData = fTara * 1000.0;
2788 
2789  clWrite.m_uiMessageId = 0x600 + iModuleId;
2790  clWrite.m_bRTRFlag = false;
2791  clWrite.m_aucMessageData[0] = 0x23;
2792  clWrite.m_aucMessageData[1] = 0x80;
2793  clWrite.m_aucMessageData[2] = 0x21;
2794  clWrite.m_aucMessageData[3] = 0x01;
2795  clWrite.m_aucMessageData[4] = clData.aucData[0];
2796  clWrite.m_aucMessageData[5] = clData.aucData[1];
2797  clWrite.m_aucMessageData[6] = clData.aucData[2];
2798  clWrite.m_aucMessageData[7] = clData.aucData[3];
2799  clWrite.m_ucMessageLength = 8;
2800 
2801  m_iErrorState = writeDevice(clWrite);
2802  if(m_iErrorState != 0)
2803  {
2804  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
2805  LeaveCriticalSection(&m_csDevice);
2806  return m_iErrorState;
2807  }
2808 
2809  do
2810  {
2811  m_iErrorState = readDevice(clRead);
2812  if(m_iErrorState != 0)
2813  {
2814  warning("wrong readDevice ErrorCode %i", m_iErrorState);
2815  LeaveCriticalSection(&m_csDevice);
2816  return m_iErrorState;
2817  }
2818  bRecieved = true;
2819  if(clRead.m_uiMessageId != 0x580 + iModuleId)
2820  {
2821  debug(1,"setTaraMP55_FS: received CAN-ID %x, expected %x", clRead.m_uiMessageId, 0x580 + iModuleId);
2822  bRecieved = false;
2823  }
2824  }
2825  while(!bRecieved);
2826 
2827  LeaveCriticalSection(&m_csDevice);
2828  return m_iErrorState;
2829 }
2830 
2832 {
2833  EnterCriticalSection(&m_csDevice);
2834  m_iErrorState = 0;
2835 
2836  bool bRecieved = false;
2837  static CProtocolMessage clWrite, clRead;
2838  static CProtocolData clData;
2839 
2840  if(m_bInitFlag == false)
2841  {
2842  warning("device not initialized");
2844  return m_iErrorState;
2845  }
2846  if(iModuleId < 0 || iModuleId > MAX_MP55 )
2847  {
2848  warning("bad MP55 module ID %i", iModuleId);
2850  LeaveCriticalSection(&m_csDevice);
2851  return m_iErrorState;
2852  }
2853 
2854  // Init MP55: Stop Operational Mode
2855  clWrite.m_uiMessageId = 0x000;
2856  clWrite.m_bRTRFlag = false;
2857  clWrite.m_aucMessageData[0] = 0x80;
2858  clWrite.m_aucMessageData[1] = 0x00;
2859  clWrite.m_ucMessageLength = 2;
2860 
2861  m_iErrorState = writeDevice(clWrite);
2862 
2863 // printf( "written Start Operational\n" );
2864  Sleep( 20 );
2865 
2866  // Init MP55: Set TPDO on SYNC (object 1800)
2867  clWrite.m_uiMessageId = 0x600 + iModuleId;
2868  clWrite.m_bRTRFlag = false;
2869  clWrite.m_aucMessageData[0] = 0x2F;
2870  clWrite.m_aucMessageData[1] = 0x00;
2871  clWrite.m_aucMessageData[2] = 0x18;
2872  clWrite.m_aucMessageData[3] = 0x02;
2873  clWrite.m_aucMessageData[4] = 0x01;
2874  clWrite.m_aucMessageData[5] = 0x00;
2875  clWrite.m_aucMessageData[6] = 0x00;
2876  clWrite.m_aucMessageData[7] = 0x00;
2877  clWrite.m_ucMessageLength = 8;
2878 
2879  m_iErrorState = writeDevice(clWrite);
2880 
2881  int end = 0;
2882  do
2883  {
2884  m_iErrorState = readDevice(clRead);
2885  bRecieved = true;
2886  if(clRead.m_uiMessageId != 0x580 + iModuleId)
2887  {
2888 // printf( "setTaraMP55_FS: received CAN-ID %x, expected %x\n", clRead.m_uiMessageId, 0x580 + iModuleId);
2889  bRecieved = false;
2890  }
2891  else
2892  { if( clRead.m_aucMessageData[0] != 0x60 )
2893  bRecieved = false;
2894  else
2895  { if( clRead.m_aucMessageData[1] != 0x00 )
2896  bRecieved = false;
2897  else
2898  { if( clRead.m_aucMessageData[1] != 0x18 )
2899  bRecieved = false;
2900  }
2901  }
2902  }
2903  end++;
2904  }
2905  while(!bRecieved && end < 10);
2906 
2907 // printf( "setTara obj 1800: received CAN-ID %x, expected %x\n", clRead.m_uiMessageId, 0x580 + iModuleId);
2908 // for( int i = 0; i < clRead.m_ucMessageLength; i++ )
2909 // printf( "data[%d]=%x\n", i, clRead.m_aucMessageData[i] );
2910 
2911 
2912  // Init MP55: Set TPDO to one message (object 1801)
2913  clWrite.m_uiMessageId = 0x600 + iModuleId;
2914  clWrite.m_bRTRFlag = false;
2915  clWrite.m_aucMessageData[0] = 0x2F;
2916  clWrite.m_aucMessageData[1] = 0x01;
2917  clWrite.m_aucMessageData[2] = 0x18;
2918  clWrite.m_aucMessageData[3] = 0x02;
2919  clWrite.m_aucMessageData[4] = 0xFF;
2920  clWrite.m_aucMessageData[5] = 0x00;
2921  clWrite.m_aucMessageData[6] = 0x00;
2922  clWrite.m_aucMessageData[7] = 0x00;
2923  clWrite.m_ucMessageLength = 8;
2924 
2925  m_iErrorState = writeDevice(clWrite);
2926 
2927 // printf( "written obj 1801\n" );
2928  Sleep( 10 );
2929  end = 0;
2930  do
2931  {
2932  m_iErrorState = readDevice(clRead);
2933  bRecieved = true;
2934  if(clRead.m_uiMessageId != 0x580 + iModuleId)
2935  {
2936 // printf( "setTaraMP55_FS: received CAN-ID %x, expected %x\n", clRead.m_uiMessageId, 0x580 + iModuleId);
2937  bRecieved = false;
2938  }
2939  else
2940  { if( clRead.m_aucMessageData[0] != 0x60 )
2941  bRecieved = false;
2942  else
2943  { if( clRead.m_aucMessageData[1] != 0x01 )
2944  bRecieved = false;
2945  else
2946  { if( clRead.m_aucMessageData[1] != 0x18 )
2947  bRecieved = false;
2948  }
2949  }
2950  }
2951  end++;
2952  }
2953  while(!bRecieved && end < 10);
2954 
2955 // printf( "setTara obj 1801: received CAN-ID %x, expected %x\n", clRead.m_uiMessageId, 0x580 + iModuleId);
2956 // for( i = 0; i < clRead.m_ucMessageLength; i++ )
2957 // printf( "data[%d]=%x\n", i, clRead.m_aucMessageData[i] );
2958 
2959  Sleep( 10 );
2960 
2961  // Init MP55: Set to Operational Mode
2962  clWrite.m_uiMessageId = 0x000;
2963  clWrite.m_bRTRFlag = false;
2964  clWrite.m_aucMessageData[0] = 0x01;
2965  clWrite.m_aucMessageData[1] = 0x00;
2966  clWrite.m_ucMessageLength = 2;
2967 
2968  m_iErrorState = writeDevice(clWrite);
2969 
2970 // printf( "written Start Operational\n" );
2971  Sleep( 10 );
2972 
2973  LeaveCriticalSection(&m_csDevice);
2974  return m_iErrorState;
2975 }
2976 
2977 // ========================================================================== ;
2978 // ;
2979 // ---- I/O functions ------------------------------------------------------- ;
2980 // ;
2981 // ========================================================================== ;
2982 
2983 // ========================================================================== ;
2984 // ;
2985 // ---- exec functions ------------------------------------------------------ ;
2986 // ;
2987 // ========================================================================== ;
2988 
2990 {
2991  EnterCriticalSection(&m_csDevice);
2992  m_iErrorState = 0;
2993  bool bRecieved = false;
2994  static CProtocolMessage clWrite, clRead;
2995 
2996  if(m_bInitFlag == false)
2997  {
2998  warning("device not initialized");
3000  return m_iErrorState;
3001  }
3003  if(m_iErrorState != 0)
3004  {
3005  warning("wrong setMessageId");
3006  LeaveCriticalSection(&m_csDevice);
3007  return m_iErrorState;
3008  }
3010  if(m_iErrorState != 0)
3011  {
3012  warning("wrong setMessageId");
3013  LeaveCriticalSection(&m_csDevice);
3014  return m_iErrorState;
3015  }
3016  clWrite.m_uiMessageId = MSGID_DLR_INIT_0;
3017  clWrite.m_aucMessageData[0] = 0;
3018  clWrite.m_aucMessageData[1] = 0x4b;
3019  clWrite.m_aucMessageData[2] = 0x3;
3020  clWrite.m_aucMessageData[3] = 0x1;
3021  clWrite.m_aucMessageData[4] = 0x3;
3022  clWrite.m_aucMessageData[5] = 0;
3023  clWrite.m_ucMessageLength = 6;
3024 
3025  m_iErrorState = writeDevice(clWrite);
3026  if(m_iErrorState != 0)
3027  {
3028  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
3029  LeaveCriticalSection(&m_csDevice);
3030  return m_iErrorState;
3031  }
3032 
3033  do
3034  {
3035  m_iErrorState = readDevice(clRead);
3036  if(m_iErrorState != 0)
3037  {
3038  warning("wrong MSGID_DLR_INIT_0 readDevice ErrorCode %i", m_iErrorState);
3039  LeaveCriticalSection(&m_csDevice);
3040  return m_iErrorState;
3041  }
3042  bRecieved = true;
3043  if(clRead.m_uiMessageId != MSGID_DLR_INIT_ACK)
3044  {
3045  debug(1,"initDLR_FTS: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_DLR_INIT_ACK );
3046  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
3047  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
3048  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
3049  debug(2,"read MessageId %x", clRead.m_uiMessageId);
3050  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
3051  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
3052  bRecieved = false;
3053  }
3054  }
3055  while(!bRecieved);
3056 
3057  clWrite.m_uiMessageId = MSGID_DLR_INIT_1;
3058  clWrite.m_aucMessageData[0] = 0x40;
3059  clWrite.m_aucMessageData[1] = 0x10;
3060  clWrite.m_aucMessageData[2] = 0x5;
3061  clWrite.m_aucMessageData[3] = 0x1;
3062  clWrite.m_aucMessageData[4] = 0x9;
3063  clWrite.m_aucMessageData[5] = 0;
3064  clWrite.m_aucMessageData[6] = 0;
3065  clWrite.m_ucMessageLength = 7;
3066 
3067  m_iErrorState = writeDevice(clWrite);
3068  if(m_iErrorState != 0)
3069  {
3070  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
3071  LeaveCriticalSection(&m_csDevice);
3072  return m_iErrorState;
3073  }
3074 
3075  bRecieved = false;
3076  do
3077  {
3078  m_iErrorState = readDevice(clRead);
3079  if(m_iErrorState != 0)
3080  {
3081  warning("wrong MSGID_DLR_INIT_1 readDevice ErrorCode %i", m_iErrorState);
3082  LeaveCriticalSection(&m_csDevice);
3083  return m_iErrorState;
3084  }
3085  bRecieved = true;
3086  if(clRead.m_uiMessageId != MSGID_DLR_INIT_ACK)
3087  {
3088  debug(1,"initDLR_FTS: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_DLR_INIT_ACK );
3089  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
3090  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
3091  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
3092  debug(2,"read MessageId %x", clRead.m_uiMessageId);
3093  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
3094  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
3095  bRecieved = false;
3096  }
3097  }
3098  while(!bRecieved);
3099 
3100  clWrite.m_uiMessageId = MSGID_DLR_INIT_2;
3101  clWrite.m_aucMessageData[0] = 0;
3102  clWrite.m_aucMessageData[1] = 0x10;
3103  clWrite.m_aucMessageData[2] = 0x5;
3104  clWrite.m_aucMessageData[3] = 0x2;
3105  clWrite.m_aucMessageData[4] = 0x9;
3106  clWrite.m_aucMessageData[5] = 0x10;
3107  clWrite.m_aucMessageData[6] = 0x27;
3108  clWrite.m_ucMessageLength = 7;
3109 
3110  m_iErrorState = writeDevice(clWrite);
3111  if(m_iErrorState != 0)
3112  {
3113  warning("wrong writeDevice ErrorCode %i", m_iErrorState);
3114  LeaveCriticalSection(&m_csDevice);
3115  return m_iErrorState;
3116  }
3117 
3118  bRecieved = false;
3119  do
3120  {
3121  m_iErrorState = readDevice(clRead);
3122  if(m_iErrorState != 0)
3123  {
3124  warning("wrong MSGID_DLR_INIT_2 readDevice ErrorCode %i", m_iErrorState);
3125  LeaveCriticalSection(&m_csDevice);
3126  return m_iErrorState;
3127  }
3128  bRecieved = true;
3129  if(clRead.m_uiMessageId != MSGID_DLR_INIT_ACK)
3130  {
3131  debug(1,"initDLR_FTS: received CAN-ID %x, expected %x", clRead.m_uiMessageId, MSGID_DLR_INIT_ACK );
3132  debug(2,"write MessageId %x", clWrite.m_uiMessageId);
3133  debug(2,"write CommandId %x", clWrite.m_aucMessageData[0]);
3134  debug(2,"write ParameterId %x", clWrite.m_aucMessageData[1]);
3135  debug(2,"read MessageId %x", clRead.m_uiMessageId);
3136  debug(2,"read CommandId %x", clRead.m_aucMessageData[0]);
3137  debug(2,"read ParameterId %x", clRead.m_aucMessageData[1]);
3138  bRecieved = false;
3139  }
3140  }
3141  while(!bRecieved);
3142 
3143  LeaveCriticalSection(&m_csDevice);
3144  return m_iErrorState;
3145 }
3146 
3147 int CProtocolDevice::printMessage(CProtocolMessage & rclProtocolMessage, bool read)
3148 {
3149 
3150  char readWrite[10];
3151  if (read)
3152  sprintf(readWrite,"read");
3153  else
3154  sprintf(readWrite,"write");
3155 
3156  if (rclProtocolMessage.m_ucMessageLength == 8)
3157  {
3158  debug(2,"%s CAN message Id 0x%02x, Command Id 0x%02x, ParameterId 0x%02x, Data: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x",readWrite,
3159  rclProtocolMessage.m_uiMessageId,
3160  rclProtocolMessage.m_aucMessageData[0],
3161  rclProtocolMessage.m_aucMessageData[1],
3162  rclProtocolMessage.m_aucMessageData[2],
3163  rclProtocolMessage.m_aucMessageData[3],
3164  rclProtocolMessage.m_aucMessageData[4],
3165  rclProtocolMessage.m_aucMessageData[5],
3166  rclProtocolMessage.m_aucMessageData[6],
3167  rclProtocolMessage.m_aucMessageData[7]);
3168  }
3169  else if (rclProtocolMessage.m_ucMessageLength == 7)
3170  {
3171  debug(2,"%s CAN message Id 0x%02x, Command Id 0x%02x, ParameterId 0x%02x, Data: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x",readWrite,
3172  rclProtocolMessage.m_uiMessageId,
3173  rclProtocolMessage.m_aucMessageData[0],
3174  rclProtocolMessage.m_aucMessageData[1],
3175  rclProtocolMessage.m_aucMessageData[2],
3176  rclProtocolMessage.m_aucMessageData[3],
3177  rclProtocolMessage.m_aucMessageData[4],
3178  rclProtocolMessage.m_aucMessageData[5],
3179  rclProtocolMessage.m_aucMessageData[6]);
3180  }
3181  else if (rclProtocolMessage.m_ucMessageLength == 6)
3182  {
3183  debug(2,"%s CAN message Id 0x%02x, Command Id 0x%02x, ParameterId 0x%02x, Data: 0x%02x 0x%02x 0x%02x 0x%02x",readWrite,
3184  rclProtocolMessage.m_uiMessageId,
3185  rclProtocolMessage.m_aucMessageData[0],
3186  rclProtocolMessage.m_aucMessageData[1],
3187  rclProtocolMessage.m_aucMessageData[2],
3188  rclProtocolMessage.m_aucMessageData[3],
3189  rclProtocolMessage.m_aucMessageData[4],
3190  rclProtocolMessage.m_aucMessageData[5]);
3191  }
3192  else if (rclProtocolMessage.m_ucMessageLength == 5)
3193  {
3194  debug(2,"%s CAN message Id 0x%02x, Command Id 0x%02x, ParameterId 0x%02x, Data: 0x%02x 0x%02x 0x%02x",readWrite,
3195  rclProtocolMessage.m_uiMessageId,
3196  rclProtocolMessage.m_aucMessageData[0],
3197  rclProtocolMessage.m_aucMessageData[1],
3198  rclProtocolMessage.m_aucMessageData[2],
3199  rclProtocolMessage.m_aucMessageData[3],
3200  rclProtocolMessage.m_aucMessageData[4]);
3201  }
3202  else if (rclProtocolMessage.m_ucMessageLength == 4)
3203  {
3204  debug(2,"%s CAN message Id 0x%02x, Command Id 0x%02x, ParameterId 0x%02x, Data: 0x%02x 0x%02x",readWrite,
3205  rclProtocolMessage.m_uiMessageId,
3206  rclProtocolMessage.m_aucMessageData[0],
3207  rclProtocolMessage.m_aucMessageData[1],
3208  rclProtocolMessage.m_aucMessageData[2],
3209  rclProtocolMessage.m_aucMessageData[3]);
3210  }
3211  else if (rclProtocolMessage.m_ucMessageLength == 3)
3212  {
3213  debug(2,"%s CAN message Id 0x%02x, Command Id 0x%02x, ParameterId 0x%02x, Data: 0x%02x",readWrite,
3214  rclProtocolMessage.m_uiMessageId,
3215  rclProtocolMessage.m_aucMessageData[0],
3216  rclProtocolMessage.m_aucMessageData[1],
3217  rclProtocolMessage.m_aucMessageData[2]);
3218  }
3219  else if (rclProtocolMessage.m_ucMessageLength == 2)
3220  {
3221  debug(2,"%s CAN message Id 0x%02x, Command Id 0x%02x, ParameterId 0x%02x",readWrite,
3222  rclProtocolMessage.m_uiMessageId,
3223  rclProtocolMessage.m_aucMessageData[0],
3224  rclProtocolMessage.m_aucMessageData[1]);
3225  }
3226 
3227  return 0;
3228 
3229 
3230 }
virtual int readDevice(CProtocolMessage &rclProtocolMessage)=0
int readFloatUnsignedChars(int iModuleId, int iCommandId, int iParameterId, float *pfData, unsigned char *pucData1, unsigned char *pucData2)
#define MSGID_MP55_RECV
int getDataSCHUNK_FTC(int iModuleId, int iChannelTypeId, std::vector< float > &rafData, short *piState)
#define MSGID_SCHUNK_RECV
unsigned char m_aucMessageData[8]
#define CMDID_SCHUNK_SET_NULL
#define MSGID_ACK
#define CMDID_DLR_DATA_ACK1
#define CMDID_DLR_DATA_ACK3
int writeLong(int iModuleId, int iCommandId, int iParameterId, long iData)
#define MSGID_DLR_INIT_0
unsigned char aucData[4]
int setInitMP55_IO_fast(int iModuleId)
#define ERRID_DEV_WRONGSCHUNKMODULEID
Definition: m5apiw32.h:231
CRITICAL_SECTION m_csDevice
int getUnsignedLong(int iModuleId, unsigned long *puiData)
int readUnsignedShort(int iModuleId, int iCommandId, int iParameterId, unsigned short *puiData)
void error(const int iErrorCode, const char *pcErrorMessage,...) const
Definition: Message.cpp:204
int writeLongShortReadLongUnsignedChars(int iModuleId, int iCommandId, int iParameterId, long iData1, short iData2, long *piData, unsigned char *pucData1, unsigned char *pucData2)
int getDataMP55_IO_fast(int iModuleId, float *pfData)
int readLongUnsignedChars(int iModuleId, int iCommandId, int iParameterId, long *piData, unsigned char *pucData1, unsigned char *pucData2)
#define MSGID_MP55_SEND
#define CMDID_SCHUNK_GET_TEI
int writeAll(int iCommandId, int iParameterId)
int setNullSCHUNK_FTC(int iModuleId, short *piState)
CProtocolDevice()
default constructor
#define MSGID_SET
#define ERRID_DEV_NOTINITIALIZED
Definition: m5apiw32.h:211
#define MSGID_DLR_DATA_GET
int writeFloatReadFloatUnsignedChars(int iModuleId, int iCommandId, int iParameterId, float fData, float *pfData, unsigned char *pucData1, unsigned char *pucData2)
#define MSGID_GET
unsigned char m_ucMessageLength
int writeChar(int iModuleId, int iCommandId, int iParameterId, char cData)
int printMessage(CProtocolMessage &rclProtocolMessage, bool read)
int readFloat(int iModuleId, int iCommandId, int iParameterId, float *pfData)
int writeUnsignedLong(int iModuleId, int iCommandId, int iParameterId, unsigned long uiData)
int readUnsignedLong(int iModuleId, int iCommandId, int iParameterId, unsigned long *puiData)
virtual int clearReadQueue()=0
#define MSGID_DLR_INIT_ACK
#define MAX_MP55
unsigned long m_uiMessageId
#define MSGID_STATE
#define CMDID_SCHUNK_GET_FTI
CProtocolDevice & operator=(const CProtocolDevice &rclProtocolDevice)
#define MAX_SCHUNK
virtual ~CProtocolDevice()
destructor
void warning(const char *pcWarningMessage,...) const
Definition: Message.cpp:257
unsigned long uiData
#define MSGID_SCHUNK_SEND
bool m_bInitFlag
Definition: Device.h:40
int getDataDLR_FTS(std::vector< float > &rafData, long *piState)
int getCanOpenRawAbsEnc(int iModuleId, short *piValue)
#define MSGID_ALL
int writeLongReadLongUnsignedChars(int iModuleId, int iCommandId, int iParameterId, long iData, long *piData, unsigned char *pucData1, unsigned char *pucData2)
void debug(const int iDebugLevel, const char *pcDebugMessage,...) const
Definition: Message.cpp:332
int writeUnsignedShort(int iModuleId, int iCommandId, int iParameterId, unsigned short uiData)
#define PARID_DLR_DATA_GET
#define MSGID_DLR_INIT_2
int writeShort(int iModuleId, int iCommandId, int iParameterId, short iData)
#define CMDID_DLR_DATA_GET
unsigned short auiData[2]
int readLong(int iModuleId, int iCommandId, int iParameterId, long *piData)
int write8Bytes(int iModuleId, bool bAck, void *pBytes)
#define MSGID_DLR_DATA_ACK
#define CMDID_DLR_DATA_ACK0
int readUnsignedChar(int iModuleId, int iCommandId, int iParameterId, unsigned char *pucData)
int m_iErrorState
Definition: Device.h:50
int readShort(int iModuleId, int iCommandId, int iParameterId, short *piData)
int writeUnsignedChar(int iModuleId, int iCommandId, int iParameterId, unsigned char ucData)
int writeShortReadLongUnsignedChars(int iModuleId, int iCommandId, int iParameterId, short iData, long *piData, unsigned char *pucData1, unsigned char *pucData2)
int writeFloat(int iModuleId, int iCommandId, int iParameterId, float fData)
int readChar(int iModuleId, int iCommandId, int iParameterId, char *pcData)
virtual int writeDevice(CProtocolMessage &rclProtocolMessage)=0
#define ERRID_DEV_WRONGMP55MODULEID
Definition: m5apiw32.h:230
int writeFloatShortReadFloatUnsignedChars(int iModuleId, int iCommandId, int iParameterId, float fData, short iData, float *pfData, unsigned char *pucData1, unsigned char *pucData2)
int writeCommand(int iModuleId, int iCommandId)
virtual int setMessageId(unsigned long uiMessageId)=0
int getDataMP55_IO(int iModuleId, float *pfData)
int writeLongShort(int iModuleId, int iCommandId, int iParameterId, long iData1, short iData2)
#define CMDID_DLR_DATA_ACK2
#define MSGID_DLR_INIT_1
#define CMDID_SCHUNK_GET_TRI
int setTaraMP55_IO(int iModuleId, float fTara)
int writeFloatShort(int iModuleId, int iCommandId, int iParameterId, float fData, short iData)


schunk_libm5api
Author(s): Florian Weisshardt
autogenerated on Mon Nov 25 2019 03:48:19