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