]> rtime.felk.cvut.cz Git - CanFestival-3.git/commitdiff
add anagate device support in CanFestival
authorgreg <greg>
Tue, 8 Jul 2008 13:14:48 +0000 (13:14 +0000)
committergreg <greg>
Tue, 8 Jul 2008 13:14:48 +0000 (13:14 +0000)
configure
drivers/can_anagate_linux/Makefile [new file with mode: 0644]
drivers/can_anagate_linux/Makefile.in [new file with mode: 0644]
drivers/can_anagate_linux/can_anagate_linux.c [new file with mode: 0644]
drivers/can_anagate_win32/Makefile.in [new file with mode: 0644]
drivers/can_anagate_win32/can_anagate_win32.c [new file with mode: 0644]
drivers/can_anagate_win32/can_anagate_win32.def [new file with mode: 0644]
drivers/can_anagate_win32/can_anagate_win32.vcproj [new file with mode: 0644]

index 2779332251869a8dc7a3b9b103fe03911e08bf62..0c62ce38d69f133236f037fa26d66628fb1d47b9 100755 (executable)
--- a/configure
+++ b/configure
@@ -145,6 +145,8 @@ while [ $# -ge 1 ]; do
                echo    "               \"win32\" for win32 systems (native, mingw or VC++)"
                echo    "               \"hcs12\" for HCS12 micro-controller"
                echo    " --can=foo     Use 'foo' as CAN driver"
+               echo    "               \"anagate_linux\" use AnaGate CAN(duo) driver for linux"        
+               echo    "               \"anagate_win32\" use AnaGate CAN(duo) driver for win32"                                
                echo    "               \"peak_linux\" use Linux build host installed Peak driver and library"
                echo    "                 see http://www.peak-system.com/linux/"
                echo    "               \"peak_win32\" use win32 PcanLight Peak driver and library with Cygwin" 
@@ -286,6 +288,9 @@ if [ "$SUB_CAN_DRIVER" = "" ]; then
                elif [ -e /usr/lib/libcanlib.so ]; then 
                        echo "Choosing installed Kvaser driver as CAN driver. (unix)"
                        SUB_CAN_DRIVER=kvaser
+               elif [ -e /usr/local/lib/libAnaGateAPIDLL.so ]; then 
+                       echo "Choosing installed AnaGate driver as CAN driver. (unix)"
+                       SUB_CAN_DRIVER=anagate_linux
                elif [ "$SUB_OS_NAME" = "CYGWIN" -a "$KVASER_DLL_PATH" != "" ]; then
                        echo "Choosing installed Kvaser driver as CAN driver. (cygwin)"
                        SUB_CAN_DRIVER=kvaser
@@ -316,6 +321,14 @@ if [ "$SUB_CAN_DRIVER" = "peak" ]; then
        fi
 fi
 
+# Warn for unstalled peak driver if choosen
+if [ "$SUB_CAN_DRIVER" = "anagate_linux" ]; then
+       if [ ! -e /usr/local/lib/libAnaGateAPIDLL.so ]; then 
+               echo "AnaGateCAN driver hasn't been installed !"
+               exit -1
+       fi
+fi
+
 # Warn for unstalled kvaser driver if choosen
 if [ "$SUB_CAN_DRIVER" = "kvaser" ]; then
        if [ "$SUB_OS_NAME" = "CYGWIN" ]; then
@@ -377,10 +390,20 @@ if [ "$SUB_CAN_DRIVER" = "peak_linux" ]; then
     SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ -lpcan
 fi
 
+if [ "$SUB_CAN_DRIVER" = "anagate_linux" ]; then
+    SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ -lAnaGateAPIDLL
+    SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ -lAnaCommon
+fi
+
+
 if [ "$SUB_CAN_DRIVER" = "vscom" ]; then
     SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ -lvs_can_api
 fi
 
+if [ "$SUB_CAN_DRIVER" = "anagate_win32" ]; then
+    SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ -lAnaGateCan
+fi
+
 PW32DIR=drivers/can_peak_win32
 if [ "$SUB_CAN_DRIVER" = "peak_win32" ]; then
        if [ "$PCAN_HEADER" = "" -o "$PCAN_LIB" = "" ]; then
diff --git a/drivers/can_anagate_linux/Makefile b/drivers/can_anagate_linux/Makefile
new file mode 100644 (file)
index 0000000..3175eac
--- /dev/null
@@ -0,0 +1,68 @@
+#! gmake
+
+#
+# Copyright (C) 2006 Laurent Bessard
+# 
+# This file is part of canfestival, a library implementing the canopen
+# stack
+# 
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+# 
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+# 
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+# 
+
+CC = gcc
+OPT_CFLAGS = -O2
+CFLAGS = $(OPT_CFLAGS)
+PROG_CFLAGS = 
+PREFIX = /usr/local
+TARGET = unix
+CAN_DRIVER = can_anagate_linux
+TIMERS_DRIVER = timers_unix
+ENABLE_DLL_DRIVERS=1
+CAN_DLL_CFLAGS= -lAnaGateAPIDLL -lAnaCommon
+
+INCLUDES = -I../../include -I../../include/$(TARGET) -I../../include/$(CAN_DRIVER)
+
+OBJS = $(CAN_DRIVER).o
+
+ifeq ($(ENABLE_DLL_DRIVERS),1)
+CFLAGS += -fPIC
+DRIVER = libcanfestival_$(CAN_DRIVER).so
+else
+DRIVER = $(OBJS)
+endif
+
+TARGET_SOFILES = $(PREFIX)/lib/$(DRIVER)
+
+all: driver
+
+driver: $(DRIVER)
+
+%o: %c
+       $(CC) $(CFLAGS) $(PROG_CFLAGS) ${PROGDEFINES} $(INCLUDES) -o $@ -c $<
+
+libcanfestival_$(CAN_DRIVER).so: $(OBJS)
+       $(CC) -shared -Wl,-soname,libcanfestival_$(CAN_DRIVER).so $(CAN_DLL_CFLAGS) -o $@ $<
+
+install: libcanfestival_$(CAN_DRIVER).so
+       mkdir -p $(PREFIX)/lib/
+       cp $< $(PREFIX)/lib/
+               
+uninstall:
+       rm -f $(TARGET_SOFILES)
+
+clean:
+       rm -f $(OBJS)
+
+mrproper: clean
diff --git a/drivers/can_anagate_linux/Makefile.in b/drivers/can_anagate_linux/Makefile.in
new file mode 100644 (file)
index 0000000..06f822b
--- /dev/null
@@ -0,0 +1,68 @@
+#! gmake
+
+#
+# Copyright (C) 2006 Laurent Bessard
+# 
+# This file is part of canfestival, a library implementing the canopen
+# stack
+# 
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+# 
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+# 
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+# 
+
+CC = SUB_CC
+OPT_CFLAGS = -O2
+CFLAGS = SUB_OPT_CFLAGS
+PROG_CFLAGS = SUB_PROG_CFLAGS
+PREFIX = SUB_PREFIX
+TARGET = SUB_TARGET
+CAN_DRIVER = SUB_CAN_DRIVER
+TIMERS_DRIVER = SUB_TIMERS_DRIVER
+ENABLE_DLL_DRIVERS=SUB_ENABLE_DLL_DRIVERS
+CAN_DLL_CFLAGS=SUB_CAN_DLL_CFLAGS
+
+INCLUDES = -I../../include -I../../include/$(TARGET) -I../../include/$(CAN_DRIVER)
+
+OBJS = $(CAN_DRIVER).o
+
+ifeq ($(ENABLE_DLL_DRIVERS),1)
+CFLAGS += -fPIC
+DRIVER = libcanfestival_$(CAN_DRIVER).so
+else
+DRIVER = $(OBJS)
+endif
+
+TARGET_SOFILES = $(PREFIX)/lib/$(DRIVER)
+
+all: driver
+
+driver: $(DRIVER)
+
+%o: %c
+       $(CC) $(CFLAGS) $(PROG_CFLAGS) ${PROGDEFINES} $(INCLUDES) -o $@ -c $<
+
+libcanfestival_$(CAN_DRIVER).so: $(OBJS)
+       $(CC) -shared -Wl,-soname,libcanfestival_$(CAN_DRIVER).so $(CAN_DLL_CFLAGS) -o $@ $<
+
+install: libcanfestival_$(CAN_DRIVER).so
+       mkdir -p $(PREFIX)/lib/
+       cp $< $(PREFIX)/lib/
+               
+uninstall:
+       rm -f $(TARGET_SOFILES)
+
+clean:
+       rm -f $(OBJS)
+
+mrproper: clean
diff --git a/drivers/can_anagate_linux/can_anagate_linux.c b/drivers/can_anagate_linux/can_anagate_linux.c
new file mode 100644 (file)
index 0000000..3d25235
--- /dev/null
@@ -0,0 +1,320 @@
+/*
+This file is part of CanFestival, a library implementing CanOpen Stack. 
+
+Copyright (C): Edouard TISSERANT and Francis DUPIN
+
+See COPYING file for copyrights details.
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+
+
+#include "can_driver.h"
+
+struct SAnaGatePort
+{
+   int      hHandle;
+   Message  sMsgBuffer;
+   struct   SAnaGatePort *pNext;
+   struct   SAnaGatePort *pPrev;
+   int      bBufferFull;
+};
+
+
+struct SAnaGatePort *pFistAnaGatePort = NULL;
+
+
+/********* AnaGate API CAN receive callback Funciton  ****************/
+void AnaGateReceiveCallBack (int nIdentifier, const char* pcBuffer, int nBufferLen, int nFlags, int hHandle)
+{
+   int i;
+   struct SAnaGatePort *pAnaGatePort = pFistAnaGatePort;
+   
+   while (pAnaGatePort->hHandle != hHandle )
+   {
+      pAnaGatePort = pAnaGatePort->pNext;
+      if (pAnaGatePort == pFistAnaGatePort )
+      {
+         pAnaGatePort = NULL;
+         printf("AnaGateReceiveCallBack (AnaGate_Linux): ERROR: Can't find AnaGatePort-Objekt to the Received Handle %d\n",hHandle);
+         return;
+      }
+   }
+   while (pAnaGatePort->bBufferFull)
+   {
+      usleep(5000);
+   }
+   pAnaGatePort->sMsgBuffer.cob_id =   nIdentifier;
+   pAnaGatePort->sMsgBuffer.len= nBufferLen;
+   if (nFlags == 2)
+    pAnaGatePort->sMsgBuffer.rtr = 1;
+   else
+    pAnaGatePort->sMsgBuffer.rtr = 0;
+
+   for (i = 0 ; i < nBufferLen; i++)
+   {
+      pAnaGatePort->sMsgBuffer.data[i] = pcBuffer[i];
+   }
+
+   pAnaGatePort->bBufferFull = 1;
+}
+
+
+/*********functions which permit to communicate with the board****************/
+UNS8 canReceive_driver(CAN_HANDLE fd0, Message *m)
+{
+   int i;
+   struct SAnaGatePort*  pAnaGatePort = (struct SAnaGatePort*)fd0;
+
+   while (pAnaGatePort->bBufferFull == 0)
+   {
+      usleep (5000); 
+   }
+   
+   m->cob_id = pAnaGatePort->sMsgBuffer.cob_id;
+   m->len     = pAnaGatePort->sMsgBuffer.len;
+   m->rtr     = pAnaGatePort->sMsgBuffer.rtr;
+   for (i = 0 ; i < pAnaGatePort->sMsgBuffer.len; i++)
+   {
+     m->data[i] = pAnaGatePort->sMsgBuffer.data[i];
+   }
+   
+   pAnaGatePort->bBufferFull = 0;
+   return 0;
+}
+
+/***************************************************************************/
+UNS8 canSend_driver(CAN_HANDLE fd0, Message *m)
+{
+   struct SAnaGatePort*  pAnaCanPort = (struct SAnaGatePort*)fd0;
+   char cErrorMsg[100];
+   int nRetCode;
+   int nMsgTyp;
+
+   if (m->rtr == 0)
+   {
+     nMsgTyp = 0; //Normal;
+   }
+   else
+   {
+     nMsgTyp = 2; //Remote frame;
+   }
+
+   if ( (nRetCode = CANWrite(pAnaCanPort->hHandle , m->cob_id,(const char*) m->data, m->len, nMsgTyp) ) )
+   {
+     CANErrorMessage( nRetCode, cErrorMsg ,100 ); // Convert returncode to error messge
+     fprintf(stderr,"canSend_driver (AnaGate_Linux) %s \n",nRetCode);
+     //printf("canSend_driver (AnaGate_Linux) %s \n",nRetCode);
+     return 1;
+   }
+
+   return 0;
+}
+
+
+/***************************************************************************/
+int TranslateBaudeRate(char* optarg){
+   if(!strcmp( optarg, "1M"))   return 1000000;
+   if(!strcmp( optarg, "800K")) return  800000;
+   if(!strcmp( optarg, "500K")) return  500000;
+   if(!strcmp( optarg, "250K")) return  250000;
+   if(!strcmp( optarg, "125K")) return  125000;
+   if(!strcmp( optarg, "100K")) return  100000;
+   if(!strcmp( optarg, "50K"))  return   50000;
+   if(!strcmp( optarg, "20K"))  return   20000;
+   if(!strcmp( optarg, "10K"))  return   10000;
+   return 0x0000;
+}
+
+/***************************************************************************/
+UNS8 canChangeBaudRate_driver( CAN_HANDLE fd0, char* baud)
+{
+   int nRetCode;
+   char cErrorMsg[100];
+   struct SAnaGatePort*  pAnaGatePort = (struct SAnaGatePort*)fd0;
+   
+   if (nRetCode = CANSetGlobals (pAnaGatePort->hHandle, TranslateBaudeRate(baud), 0, 0, 1) ) 
+   {
+      CANErrorMessage( nRetCode, cErrorMsg ,100 ); // Convert returncode to error messge
+      fprintf(stderr, "canChangeBaudRate_drive (AnaGate_Linux): %s\n", cErrorMsg);
+      //printf("canChangeBaudRate_drive (AnaGate_Linux): %s\n", cErrorMsg);
+      return 1;
+   }
+   return 0;
+}
+
+/***************************************************************************/
+/* To open a connection to AnaGate CAN the s_BOARD board->busname must be 
+ the AnaGate IP-Adresse followed from the CAN-Port (A or B) you want to use 
+ For example "192.168.1.254:A"
+*/
+
+CAN_HANDLE canOpen_driver(s_BOARD *board)
+{
+   int nPortNr;
+   char cErrorMsg[100];
+   int nRetCode;
+   char sIPAddress[16];
+   struct SAnaGatePort *pNewAnaGatePort;
+   unsigned int nBusnameLen;   
+   char bBusnameValid = 1;
+
+
+   ///////////////////////////////////////////
+   // Do some checkings concerning the busname
+   // format should be IP-Adress:Port
+   // e.g. 192.168.1.254:A
+   ///////////////////////////////////////////
+   nBusnameLen = strlen(board->busname);
+   
+   if ( nBusnameLen < strlen( "1.2.3.4:A" ) )         bBusnameValid = 0;  // check minimum length of busname
+   if ( nBusnameLen > strlen( "123.234.345.456:A" ) ) bBusnameValid = 0;  // check maximum length of busname
+   if ( bBusnameValid )
+   {
+      switch (board->busname[nBusnameLen-1])                                 // check Portname of busname
+      {
+         case ('A'): nPortNr = 0; break;
+         case ('B'): nPortNr = 1; break;
+         case ('C'): nPortNr = 2; break;
+         case ('D'): nPortNr = 3; break;
+         default :   bBusnameValid = 0; break;
+      }
+      if (board->busname[nBusnameLen-2] != ':' )    bBusnameValid = 0;   // check Colon before Portname
+   }
+
+   if ( ! bBusnameValid )
+   {
+      fprintf(stderr, "canOpen_driver (AnaGate_Win32): busname (\"%s\") has a wrong format. Use IPAddr:CANPort for example \"192.168.1.254:A\"\n",board->busname);
+      return (CAN_HANDLE) NULL;
+   }
+
+   board->busname[nBusnameLen-2] = 0; // NULL Terminator for IP Address string
+   strcpy (sIPAddress, board->busname);
+   
+   pNewAnaGatePort = (struct SAnaGatePort*) malloc(sizeof (struct SAnaGatePort));
+   if (pFistAnaGatePort == NULL)
+   {
+      pFistAnaGatePort = pNewAnaGatePort;
+      pNewAnaGatePort->pNext =  pNewAnaGatePort;
+      pNewAnaGatePort->pPrev =  pNewAnaGatePort;
+   }
+   else
+   {   pNewAnaGatePort->pNext =  pFistAnaGatePort;
+      pNewAnaGatePort->pPrev =  pFistAnaGatePort->pPrev;
+      pFistAnaGatePort->pPrev->pNext = pNewAnaGatePort;
+      pFistAnaGatePort->pPrev = pNewAnaGatePort;
+
+   }
+
+   // Connect to AnaGate
+   if ( nRetCode = CANOpenDevice (&pNewAnaGatePort->hHandle, 
+                        0,      /*confimation off*/ 
+                        1,      /*Monitor on*/ 
+                        nPortNr,
+                        sIPAddress,
+                        1000   /*TimeOut*/ )  )
+   {
+      CANErrorMessage( nRetCode, cErrorMsg ,100 ); // Convert returncode to error messge
+      fprintf(stderr, "canOpen_driver (AnaGate_Linux): %s @ %s  Port:%d\n", cErrorMsg,sIPAddress,nPortNr);
+      //printf( "canOpen_driver (AnaGate_Linux): %s @ %s Port:%d\n", cErrorMsg,sIPAddress,nPortNr);
+      return (CAN_HANDLE) NULL;
+   }
+   
+   // Inizial Baudrate
+
+   if (nRetCode = CANSetGlobals (pNewAnaGatePort->hHandle, 
+                        TranslateBaudeRate(board->baudrate), 
+                        0,/*OperatingMode = normal*/ 
+                        0,/*CAN-Termination = off*/ 
+                        1 /*HighSpeedMode = on*/) ) 
+   {
+      CANErrorMessage( nRetCode, cErrorMsg ,100 ); // Convert returncode to error messge
+      fprintf(stderr, "canOpen_driver (AnaGate_Linux): %s @ %s\n", cErrorMsg,sIPAddress);
+      //printf("canOpen_driver (AnaGate_Linux): %s @ %s\n", cErrorMsg,sIPAddress);
+      return (CAN_HANDLE) NULL;
+   }
+   
+   // Creat receive and receive-acknoledge event 
+   /*pNewAnaGatePort->hAnaRecEvent = CreateEvent(   
+                                    NULL,  // default security attributes
+                                    FALSE, // manual-reset event
+                                    FALSE, // initial state is nonsignaled
+                                    NULL  // object name
+                                    ); 
+
+   pNewAnaGatePort->hFesticalRecAcknowledge = CreateEvent( 
+                                    NULL,  // default security attributes
+                                    FALSE, // manual-reset event
+                                    FALSE, // initial state is nonsignaled
+                                    NULL   // object name
+                                    ); 
+         */
+   pNewAnaGatePort->bBufferFull = 0;
+   // Install receive callback funktion
+
+   if (nRetCode = CANSetCallback(pNewAnaGatePort->hHandle,  AnaGateReceiveCallBack) ) 
+   {
+      canClose_driver (pNewAnaGatePort);
+      CANErrorMessage( nRetCode, cErrorMsg ,100 ); // Convert returncode to error messge
+      fprintf(stderr, "canOpen_driver (AnaGate_Linux): %s @ %s\n", cErrorMsg,sIPAddress);
+      //printf("canOpen_driver (AnaGate_Linux): %s @ %s\n", cErrorMsg,sIPAddress);
+      return (CAN_HANDLE) NULL;
+   }
+
+
+  return (CAN_HANDLE)pNewAnaGatePort;
+}
+
+/***************************************************************************/
+int canClose_driver(CAN_HANDLE fd0)
+{
+   struct SAnaGatePort*  pAnaGatePort = (struct SAnaGatePort*)fd0;
+   char cErrorMsg[100];
+   int nRetCode;
+
+   pAnaGatePort->bBufferFull = 1;  
+   
+   if ( nRetCode = CANCloseDevice(pAnaGatePort->hHandle) )
+   {
+     CANErrorMessage( nRetCode, cErrorMsg ,100 ); // Convert returncode to error messge
+     fprintf(stderr, "canClose_driver (AnaGate_Linux): %s\n", cErrorMsg);
+     printf("canClose_driver (AnaGate_Linux): %s\n", cErrorMsg);
+   }
+
+   if (pAnaGatePort->pNext == pAnaGatePort)
+   {
+       free (pAnaGatePort);
+       pFistAnaGatePort=NULL;
+   }
+   else
+   {  
+      pAnaGatePort->pNext->pPrev = pAnaGatePort->pPrev;
+      pAnaGatePort->pPrev->pNext = pAnaGatePort->pNext;
+      free (pAnaGatePort);
+   }
+
+   return 0;
+}
diff --git a/drivers/can_anagate_win32/Makefile.in b/drivers/can_anagate_win32/Makefile.in
new file mode 100644 (file)
index 0000000..79274ce
--- /dev/null
@@ -0,0 +1,81 @@
+#! gmake
+
+#
+# Copyright (C) 2006 Edouard TISSERANT
+# 
+# This file is part of canfestival, a library implementing the canopen
+# stack
+# 
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+# 
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+# 
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+# 
+
+CC = SUB_CC
+CXX = SUB_CXX
+LD = SUB_LD
+OPT_CFLAGS = -O2
+CFLAGS = SUB_OPT_CFLAGS
+PROG_CFLAGS = SUB_PROG_CFLAGS
+PREFIX = SUB_PREFIX
+TARGET = SUB_TARGET
+CAN_DRIVER = SUB_CAN_DRIVER
+TIMERS_DRIVER = SUB_TIMERS_DRIVER
+ENABLE_DLL_DRIVERS=SUB_ENABLE_DLL_DRIVERS
+CAN_DLL_CFLAGS=SUB_CAN_DLL_CFLAGS
+
+INCLUDES = -I../../include -I../../include/$(TARGET) -I../../include/$(CAN_DRIVER) -IAnaGateCAN_API
+
+OBJS =  $(CAN_DRIVER).o
+
+ifeq ($(ENABLE_DLL_DRIVERS),1)
+#CFLAGS += -fPIC
+DRIVER = cyg$(CAN_DRIVER).dll
+else
+DRIVER = $(OBJS)
+endif
+
+
+TARGET_SOFILES = $(PREFIX)/lib/$(DRIVER)
+
+all: driver
+
+driver: $(DRIVER)
+
+
+%o: %c
+       $(CC) $(CFLAGS) $(PROG_CFLAGS) ${PROGDEFINES} $(INCLUDES) -o $@ -c $<
+
+%o: %cpp
+       $(CXX) $(CFLAGS) $(PROG_CFLAGS) ${PROGDEFINES} $(INCLUDES) -o $@ -c $<
+
+$(DRIVER): $(OBJS)
+       $(LD) $(PROG_CFLAGS) -shared -o $@ \
+       -Wl,--export-all-symbols \
+       -Wl,--enable-auto-import \
+       -Wl,--whole-archive $^ \
+       -Wl,--no-whole-archive $(CAN_DLL_CFLAGS) \
+        AnaGateCAN_API/AnaGateCANDll.lib \
+       -Wl,--exclude-libs,ALL -lws2_32
+               
+install: libcanfestival_$(CAN_DRIVER).so
+       mkdir -p $(PREFIX)/lib/
+       cp $< $(PREFIX)/lib/
+               
+uninstall:
+       rm -f $(TARGET_SOFILES)
+
+clean:
+       rm -f $(OBJS) $(DRIVER) $(SERVER).exe
+
+mrproper: clean
diff --git a/drivers/can_anagate_win32/can_anagate_win32.c b/drivers/can_anagate_win32/can_anagate_win32.c
new file mode 100644 (file)
index 0000000..9b34e08
--- /dev/null
@@ -0,0 +1,323 @@
+/*
+This file is part of CanFestival, a library implementing CanOpen Stack. 
+
+Copyright (C): Edouard TISSERANT and Francis DUPIN
+
+See COPYING file for copyrights details.
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#if defined(WIN32) && !defined(__CYGWIN__)
+#define usleep(micro) Sleep(micro%1000 ? (micro/1000) + 1 : (micro/1000))
+#define _CRT_SECURE_NO_DEPRECATE
+#else
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#endif
+
+#include "can_driver.h"
+#include "AnaGateDllCan.h"
+
+
+typedef struct SAnaGatePort
+{
+int            hHandle;
+HANDLE hAnaRecEvent;
+HANDLE hFesticalRecAcknowledge;
+Message sMsgBuffer;
+struct SAnaGatePort *pNext;
+struct SAnaGatePort *pPrev;
+} SAnaGatePort;
+
+
+SAnaGatePort *pFirstAnaGatePort=NULL;
+
+
+/********* AnaGate API CAN receive callback Funciton  ****************/
+void WINAPI AnaGateReceiveCallBack (int nIdentifier, const char* pcBuffer, int nBufferLen, int nFlags, int hHandle)
+{
+       SAnaGatePort *pAnaGatePort = pFirstAnaGatePort;
+   int           i;
+       
+       while (pAnaGatePort->hHandle != hHandle )
+       {
+               pAnaGatePort = pAnaGatePort->pNext;
+               if (pAnaGatePort == pFirstAnaGatePort )
+               {
+                       pAnaGatePort = NULL;
+                       printf("AnaGateReceiveCallBack (AnaGate_Win32): ERROR: Can't find AnaGatePort-Objekt to the Received Handle %d\n",hHandle);
+                       return;
+               }
+       }
+       
+       pAnaGatePort->sMsgBuffer.cob_id =   nIdentifier;
+       pAnaGatePort->sMsgBuffer.len= nBufferLen;
+       if (nFlags == 2)
+        pAnaGatePort->sMsgBuffer.rtr = 1;
+       else
+        pAnaGatePort->sMsgBuffer.rtr = 0;
+
+       for (i = 0 ; i < nBufferLen; i++)
+       {
+               pAnaGatePort->sMsgBuffer.data[i] = pcBuffer[i];
+       }
+
+       SetEvent(pAnaGatePort->hAnaRecEvent);
+
+       WaitForSingleObject(pAnaGatePort->hFesticalRecAcknowledge,INFINITE);
+}
+
+
+/*********functions which permit to communicate with the board****************/
+UNS8 canReceive_driver(CAN_HANDLE fd0, Message *m)
+{
+       SAnaGatePort*  pAnaGatePort = (SAnaGatePort*)fd0;
+   int            i;
+
+       WaitForSingleObject(                    // Wait for receive event
+               pAnaGatePort->hAnaRecEvent, // event handle
+               INFINITE);                                  // indefinite wait
+
+
+       m->cob_id = pAnaGatePort->sMsgBuffer.cob_id;
+       m->len    = pAnaGatePort->sMsgBuffer.len;
+       m->rtr    = pAnaGatePort->sMsgBuffer.rtr;
+       for (i = 0 ; i < pAnaGatePort->sMsgBuffer.len; i++)
+       {
+         m->data[i] = pAnaGatePort->sMsgBuffer.data[i];
+       }
+
+       SetEvent(pAnaGatePort->hFesticalRecAcknowledge);        //Set Acknollede event
+
+       return 0;
+}
+
+/***************************************************************************/
+UNS8 canSend_driver(CAN_HANDLE fd0, Message *m)
+{
+       SAnaGatePort*  pAnaCanPort = (SAnaGatePort*)fd0;
+       char cErrorMsg[100];
+       int nRetCode;
+       int nMsgTyp;
+
+       if (m->rtr == 0)
+       {
+         nMsgTyp = 0; //Normal;
+       }
+       else
+       {
+         nMsgTyp = 2; //Remote frame;
+       }
+
+       if ( (nRetCode = CANWrite(pAnaCanPort->hHandle , m->cob_id,(const char*) m->data, m->len, nMsgTyp) ) )
+       {
+         CANErrorMessage( nRetCode, cErrorMsg ,100 ); // Convert returncode to error messge
+         fprintf(stderr,"canSend_driver (AnaGate_Win32) %s \n",nRetCode);
+         //printf("canSend_driver (AnaGate_Win32) %s \n",nRetCode);
+         return 1;
+       }
+
+       return 0;
+}
+
+
+/***************************************************************************/
+int TranslateBaudeRate(char* optarg){
+       if(!strcmp( optarg, "1M"))   return 1000000;
+    if(!strcmp( optarg, "800K")) return  800000;
+    if(!strcmp( optarg, "500K")) return  500000;
+    if(!strcmp( optarg, "250K")) return  250000;
+    if(!strcmp( optarg, "125K")) return  125000;
+       if(!strcmp( optarg, "100K")) return  100000;
+       if(!strcmp( optarg, "50K"))  return   50000;
+       if(!strcmp( optarg, "20K"))  return   20000;
+       if(!strcmp( optarg, "10K"))  return   10000;
+       return 0x0000;
+}
+/****************************************************************************/
+
+UNS8 canChangeBaudRate_driver( CAN_HANDLE fd0, char* baud)
+{
+   int nRetCode;
+   char cErrorMsg[100];
+   struct SAnaGatePort*  pAnaGatePort = (struct SAnaGatePort*)fd0;
+   
+   if (nRetCode = CANSetGlobals (pAnaGatePort->hHandle, TranslateBaudeRate(baud), 0, 0, 1) ) 
+   {
+      CANErrorMessage( nRetCode, cErrorMsg ,100 ); // Convert returncode to error messge
+      fprintf(stderr, "canChangeBaudRate_drive (AnaGate_Win32): %s\n", cErrorMsg);
+      printf("canChangeBaudRate_drive (AnaGate_Win32): %s\n", cErrorMsg);
+      return 1;
+   }
+   return 0;
+}
+
+/***************************************************************************/
+/* To open a connection to AnaGate CAN the s_BOARD board->busname must be 
+ the AnaGate IP-Adresse followed from the CAN-Port (A or B) you want to use 
+ For example "192.168.1.254:A"
+*/
+
+CAN_HANDLE canOpen_driver(s_BOARD *board)
+{
+       int PortNr;
+       char cErrorMsg[100];
+       int nRetCode;
+       char sIPAddress[16];
+       struct SAnaGatePort *pNewAnaGatePort;
+    char bBusnameValid = TRUE;
+       unsigned int nBusnameLen; 
+
+   ///////////////////////////////////////////
+   // Do some checkings concerning the busname
+   // format should be IP-Adress:Port
+   // e.g. 192.168.1.254:A
+   ///////////////////////////////////////////
+   nBusnameLen = strlen(board->busname);
+   
+   if ( nBusnameLen < strlen( "1.2.3.4:A" ) )         bBusnameValid = FALSE;  // check minimum length of busname
+   if ( nBusnameLen > strlen( "123.234.345.456:A" ) ) bBusnameValid = FALSE;  // check maximum length of busname
+   if ( bBusnameValid )
+   {
+      switch (board->busname[nBusnameLen-1])                                 // check Portname of busname
+          {
+                  case ('A'): PortNr = 0; break;
+                  case ('B'): PortNr = 1; break;
+                  case ('C'): PortNr = 2; break;
+                  case ('D'): PortNr = 3; break;
+                  default :   bBusnameValid = FALSE; break;
+          }
+      if (board->busname[nBusnameLen-2] != ':' )    bBusnameValid = FALSE;   // check Colon before Portname
+   }
+
+   if ( ! bBusnameValid )
+   {
+          fprintf(stderr, "canOpen_driver (AnaGate_Win32): busname (\"%s\") has a wrong format. Use IPAddr:CANPort for example \"192.168.1.254:A\"\n",board->busname);
+          return (CAN_HANDLE) NULL;
+   }
+
+   board->busname[nBusnameLen-2] = 0; // NULL Terminator for IP Address string
+       strcpy (sIPAddress, board->busname);
+
+       pNewAnaGatePort = (SAnaGatePort*) malloc(sizeof (struct SAnaGatePort));
+       if (pFirstAnaGatePort == NULL)
+       {
+               pFirstAnaGatePort = pNewAnaGatePort;
+               pNewAnaGatePort->pNext =  pNewAnaGatePort;
+               pNewAnaGatePort->pPrev =  pNewAnaGatePort;
+       }
+       else
+       {   pNewAnaGatePort->pNext =  pFirstAnaGatePort;
+               pNewAnaGatePort->pPrev =  pFirstAnaGatePort->pPrev;
+               pFirstAnaGatePort->pPrev->pNext = pNewAnaGatePort;
+               pFirstAnaGatePort->pPrev = pNewAnaGatePort;
+
+       }
+       // Connect to AnaGate
+       if ( nRetCode = CANOpenDevice (&pNewAnaGatePort->hHandle, 
+                                                               0,              /*confirmation*/ 
+                                                               1,              /*Monitor*/ 
+                                                               PortNr,
+                                                               sIPAddress, 
+                                                               1000    /*TimeOut*/ )  )
+       {
+               CANErrorMessage( nRetCode, cErrorMsg ,100 ); // Convert returncode to error messge
+               fprintf(stderr, "canOpen_driver (AnaGate_Win32): %s @ %s\n", cErrorMsg,sIPAddress);
+               //printf( "canOpen_driver (AnaGate_Win32): %s @ %s\n", cErrorMsg,sIPAddress);
+               return (CAN_HANDLE) NULL;
+       }
+
+       // Inizial Baudrate
+       if (nRetCode = CANSetGlobals (pNewAnaGatePort->hHandle, 
+                                                          TranslateBaudeRate(board->baudrate), 
+                                                          0,/*OperatingMode = normal*/ 
+                                                          0,/*CAN-Termination = off*/ 
+                                                          1 /*HighSpeedMode = on*/) ) 
+       {
+               CANErrorMessage( nRetCode, cErrorMsg ,100 ); // Convert returncode to error messge
+               fprintf(stderr, "canOpen_driver (AnaGate_Win32): %s @ %s\n", cErrorMsg,sIPAddress);
+               //printf("canOpen_driver (AnaGate_Win32): %s @ %s\n", cErrorMsg,sIPAddress);
+               return (CAN_HANDLE) NULL;
+       }
+       
+       // Creat receive and receive-acknoledge event 
+       pNewAnaGatePort->hAnaRecEvent = CreateEvent(    
+                                                                                               NULL,  // default security attributes
+                                                                                               FALSE, // manual-reset event
+                                                                                               FALSE, // initial state is nonsignaled
+                                                                                               NULL  // object name
+                                                                                               ); 
+
+       pNewAnaGatePort->hFesticalRecAcknowledge = CreateEvent( 
+                                                                                               NULL,  // default security attributes
+                                                                                               FALSE, // manual-reset event
+                                                                                               FALSE, // initial state is nonsignaled
+                                                                                               NULL   // object name
+                                                                                               ); 
+
+       // Install receive callback funktion
+       if (nRetCode = CANSetCallback(pNewAnaGatePort->hHandle,  AnaGateReceiveCallBack) ) 
+       {
+               canClose_driver (pNewAnaGatePort);
+               CANErrorMessage( nRetCode, cErrorMsg ,100 ); // Convert returncode to error messge
+               fprintf(stderr, "canOpen_driver (AnaGate_Win32): %s @ %s\n", cErrorMsg,sIPAddress);
+               //printf("canOpen_driver (AnaGate_Win32): %s @ %s\n", cErrorMsg,sIPAddress);
+               return (CAN_HANDLE) NULL;
+       }
+
+  return (CAN_HANDLE)pNewAnaGatePort;
+}
+
+/***************************************************************************/
+int canClose_driver(CAN_HANDLE fd0)
+{
+       SAnaGatePort*  pAnaCanPort = (SAnaGatePort*)fd0;
+       char cErrorMsg[100];
+       int nRetCode;
+
+
+       SetEvent        (pAnaCanPort->hAnaRecEvent);
+       CloseHandle (pAnaCanPort->hAnaRecEvent);
+       CloseHandle (pAnaCanPort->hFesticalRecAcknowledge);
+
+       if ( nRetCode = CANCloseDevice(pAnaCanPort->hHandle) )
+       {
+         CANErrorMessage( nRetCode, cErrorMsg ,100 ); // Convert returncode to error messge
+         fprintf(stderr, "canClose_driver (AnaGate_Linux): %s\n", cErrorMsg);
+         //printf("canClose_driver (AnaGate_Linux): %s\n", cErrorMsg);
+       }
+
+       if (pAnaCanPort->pNext == pAnaCanPort)
+       {
+                free (pAnaCanPort);
+                pFirstAnaGatePort=NULL;
+       }
+       else
+       {   pAnaCanPort->pNext->pPrev = pAnaCanPort->pPrev;
+               pAnaCanPort->pPrev->pNext = pAnaCanPort->pNext;
+               free (pAnaCanPort);
+       }
+
+       return 0;
+}
+
+
+
+
+
diff --git a/drivers/can_anagate_win32/can_anagate_win32.def b/drivers/can_anagate_win32/can_anagate_win32.def
new file mode 100644 (file)
index 0000000..d66324b
--- /dev/null
@@ -0,0 +1,8 @@
+LIBRARY        can_anagate_win32
+
+EXPORTS
+   canReceive_driver
+   canSend_driver
+   canOpen_driver
+   canClose_driver
+   canChangeBaudRate_driver
\ No newline at end of file
diff --git a/drivers/can_anagate_win32/can_anagate_win32.vcproj b/drivers/can_anagate_win32/can_anagate_win32.vcproj
new file mode 100644 (file)
index 0000000..f16b1c6
--- /dev/null
@@ -0,0 +1,207 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+       ProjectType="Visual C++"
+       Version="8,00"
+       Name="can_anagate_win32"
+       ProjectGUID="{2F3E1E68-1518-4829-B543-8DF2987E664B}"
+       RootNamespace="can_anagate_win32"
+       Keyword="Win32Proj"
+       >
+       <Platforms>
+               <Platform
+                       Name="Win32"
+               />
+       </Platforms>
+       <ToolFiles>
+       </ToolFiles>
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       OutputDirectory="../../Debug"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="2"
+                       CharacterSet="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="0"
+                               AdditionalIncludeDirectories="AnaGateCAN_API;../../include;../../include/win32"
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;CAN_ANAGATE_WIN32_EXPORTS"
+                               MinimalRebuild="true"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="3"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               Detect64BitPortabilityProblems="false"
+                               DebugInformationFormat="4"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               AdditionalDependencies="AnaGateCanDll.lib"
+                               LinkIncremental="2"
+                               AdditionalLibraryDirectories="AnaGateCAN_API"
+                               ModuleDefinitionFile="can_anagate_win32.def"
+                               GenerateDebugInformation="true"
+                               SubSystem="2"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCWebDeploymentTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="2"
+                       CharacterSet="1"
+                       WholeProgramOptimization="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;CAN_ANAGATE_WIN32_EXPORTS"
+                               RuntimeLibrary="2"
+                               UsePrecompiledHeader="2"
+                               WarningLevel="3"
+                               Detect64BitPortabilityProblems="true"
+                               DebugInformationFormat="3"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               LinkIncremental="1"
+                               GenerateDebugInformation="true"
+                               SubSystem="2"
+                               OptimizeReferences="2"
+                               EnableCOMDATFolding="2"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCWebDeploymentTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+       </Configurations>
+       <References>
+       </References>
+       <Files>
+               <Filter
+                       Name="Quelldateien"
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+                       >
+                       <File
+                               RelativePath=".\can_anagate_win32.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\can_anagate_win32.def"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Headerdateien"
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+                       >
+                       <File
+                               RelativePath=".\API\include\AnaGateDllCan.h"
+                               >
+                       </File>
+               </Filter>
+               <File
+                       RelativePath=".\ReadMe.txt"
+                       >
+               </File>
+       </Files>
+       <Globals>
+       </Globals>
+</VisualStudioProject>