# HG changeset patch # User Edouard Tisserant # Date 1362556461 -32400 # Node ID 91d708a2cb4e6c851a5ba1852de72ae2607c3534 # Parent c10def4bfbde65b5120578bdeac9cd59d5c08767 Fixed DLL calling convention when build with mingw32 + some re-indenting in can_tcp_win32 diff -r c10def4bfbde -r 91d708a2cb4e drivers/can_tcp_win32/can_tcp_win32.cpp --- a/drivers/can_tcp_win32/can_tcp_win32.cpp Wed Mar 06 13:40:54 2013 +0900 +++ b/drivers/can_tcp_win32/can_tcp_win32.cpp Wed Mar 06 16:54:21 2013 +0900 @@ -28,99 +28,99 @@ extern "C" { #include "can_driver.h" -} //------------------------------------------------------------------------ -extern "C" - UNS8 canReceive_driver(CAN_HANDLE fd0, Message *m) - { +UNS8 LIBAPI canReceive_driver(CAN_HANDLE fd0, Message *m) +{ - string l = reinterpret_cast(fd0)->ReceiveLine(); + string l = reinterpret_cast(fd0)->ReceiveLine(); - int res = sscanf(l.c_str(),"{0x%3hx,%1hhd,%1hhd,{0x%2hhx,0x%2hhx,0x%2hhx,0x%2hhx,0x%2hhx,0x%2hhx,0x%2hhx,0x%2hhx}}", - &m->cob_id, - &m->rtr, - &m->len, - &m->data[0], - &m->data[1], - &m->data[2], - &m->data[3], - &m->data[4], - &m->data[5], - &m->data[6], - &m->data[7] - ); + int res = sscanf(l.c_str(), + "{0x%3hx,%1hhd,%1hhd,{0x%2hhx,0x%2hhx,0x%2hhx,0x%2hhx,0x%2hhx,0x%2hhx,0x%2hhx,0x%2hhx}}", + &m->cob_id, + &m->rtr, + &m->len, + &m->data[0], + &m->data[1], + &m->data[2], + &m->data[3], + &m->data[4], + &m->data[5], + &m->data[6], + &m->data[7] + ); #if defined DEBUG_MSG_CONSOLE_ON - printf("in : "); - print_message(m); + printf("in : "); + print_message(m); #endif - - return res==11 ? 0 : 1 ; - } -extern "C" - UNS8 canSend_driver(CAN_HANDLE fd0, Message const *m) - { - char s[1024]; - sprintf(s,"{0x%3.3x,%1d,%1d,{0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x}}", - m->cob_id, - m->rtr, - m->len, - m->data[0], - m->data[1], - m->data[2], - m->data[3], - m->data[4], - m->data[5], - m->data[6], - m->data[7] - ); - - reinterpret_cast(fd0)->SendLine(s); + return res==11 ? 0 : 1 ; +} + +UNS8 LIBAPI canSend_driver(CAN_HANDLE fd0, Message const *m) +{ + char s[1024]; + sprintf(s,"{0x%3.3x,%1d,%1d,{0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x}}", + m->cob_id, + m->rtr, + m->len, + m->data[0], + m->data[1], + m->data[2], + m->data[3], + m->data[4], + m->data[5], + m->data[6], + m->data[7] + ); + + reinterpret_cast(fd0)->SendLine(s); #if defined DEBUG_MSG_CONSOLE_ON - printf("out : "); - print_message(m); + printf("out : "); + print_message(m); #endif - return 0; - } + return 0; +} -extern "C" - CAN_HANDLE canOpen_driver(s_BOARD *board) - { - Socket* s; - try { - char *dst = "127.0.0.1"; - if(strlen(board->busname)){ - dst=board->busname; - } - s = new SocketClient(dst, 11898); - } - catch (const char* _s) { - cerr << _s << endl; - return NULL; - } - catch (std::string _s) { - cerr << _s << endl; - return NULL; - } - catch (...) { - cerr << "unhandled exception\n"; - return NULL; +CAN_HANDLE LIBAPI canOpen_driver(s_BOARD *board) +{ + Socket* s; + try { + char *dst = "127.0.0.1"; + if(!strlen(board->busname)){ + dst=board->busname; } - return (CAN_HANDLE) s; - } + s = new SocketClient(dst, 11898); + } + catch (const char* _s) { + cerr << "can_tcp_win32 exception :\n"; + cerr << _s << endl; + return NULL; + } + catch (std::string _s) { + cerr << "can_tcp_win32 exception :\n"; + cerr << _s << endl; + return NULL; + } + catch (...) { + cerr << "can_tcp_win32 exception :\n"; + cerr << "unhandled exception\n"; + return NULL; + } + return (CAN_HANDLE) s; +} -extern "C" - int canClose_driver(CAN_HANDLE inst) - { - delete reinterpret_cast(inst); - return 1; - } -extern "C" - UNS8 canChangeBaudRate_driver( CAN_HANDLE fd, char* baud) - { - cerr << "canChangeBaudRate not yet supported by this driver\n"; - return 0; - } +int LIBAPI canClose_driver(CAN_HANDLE inst) +{ + delete reinterpret_cast(inst); + return 1; +} + +UNS8 LIBAPI canChangeBaudRate_driver( CAN_HANDLE fd, char* baud) +{ + cerr << "canChangeBaudRate not yet supported by this driver\n"; + return 0; +} +} diff -r c10def4bfbde -r 91d708a2cb4e drivers/can_tcp_win32/can_tcp_win32_server.cpp --- a/drivers/can_tcp_win32/can_tcp_win32_server.cpp Wed Mar 06 13:40:54 2013 +0900 +++ b/drivers/can_tcp_win32/can_tcp_win32_server.cpp Wed Mar 06 16:54:21 2013 +0900 @@ -69,9 +69,13 @@ "and repeat '\\n' terminated lines \n" "to each connected client\n" "\n" - "Use netcat to monitor trafic\n" + "Use netcat to monitor/log trafic\n" " nc 127.0.0.1 11898\n" + "\n" + "CAN message format:\n" + "{COB_ID,RTR,data_len,{data}}\n" "\n"); + fflush(stdout); SocketServer in(11898,5); diff -r c10def4bfbde -r 91d708a2cb4e drivers/win32/win32.c --- a/drivers/win32/win32.c Wed Mar 06 13:40:54 2013 +0900 +++ b/drivers/win32/win32.c Wed Mar 06 16:54:21 2013 +0900 @@ -99,50 +99,48 @@ */ LIB_HANDLE LoadCanDriver(LPCSTR driver_name) { - // driver module handle - LIB_HANDLE handle = NULL; + // driver module handle + LIB_HANDLE handle = NULL; #ifndef NOT_USE_DYNAMIC_LOADING - if(handle == NULL) - { - handle = LoadLibrary(driver_name); - } - - if (!handle) - { - fprintf (stderr, "%d\n", GetLastError()); - return NULL; - } - - m_canReceive = (CANRECEIVE_DRIVER_PROC)GetProcAddress(handle, myTEXT("canReceive_driver")); - m_canSend = (CANSEND_DRIVER_PROC)GetProcAddress(handle, myTEXT("canSend_driver")); - m_canOpen = (CANOPEN_DRIVER_PROC)GetProcAddress(handle, myTEXT("canOpen_driver")); - m_canClose = (CANCLOSE_DRIVER_PROC)GetProcAddress(handle, myTEXT("canClose_driver")); - m_canChangeBaudRate = (CANCHANGEBAUDRATE_DRIVER_PROC)GetProcAddress(handle, myTEXT("canChangeBaudRate_driver")); - - if(m_canReceive==NULL || m_canSend==NULL || m_canOpen==NULL || m_canClose==NULL || m_canChangeBaudRate==NULL) - { - m_canReceive = NULL; - m_canSend = NULL; - m_canOpen = NULL; - m_canClose = NULL; - m_canChangeBaudRate = NULL; - FreeLibrary(handle); - handle = NULL; - } + handle = LoadLibrary(driver_name); + + if (!handle) + { + fprintf (stderr, "LoadLibrary error : %d\n", GetLastError()); + return NULL; + } + + m_canReceive = (CANRECEIVE_DRIVER_PROC)GetProcAddress(handle, myTEXT("canReceive_driver")); + m_canSend = (CANSEND_DRIVER_PROC)GetProcAddress(handle, myTEXT("canSend_driver")); + m_canOpen = (CANOPEN_DRIVER_PROC)GetProcAddress(handle, myTEXT("canOpen_driver")); + m_canClose = (CANCLOSE_DRIVER_PROC)GetProcAddress(handle, myTEXT("canClose_driver")); + m_canChangeBaudRate = (CANCHANGEBAUDRATE_DRIVER_PROC)GetProcAddress(handle, myTEXT("canChangeBaudRate_driver")); + + if(m_canReceive==NULL || m_canSend==NULL || m_canOpen==NULL || m_canClose==NULL || m_canChangeBaudRate==NULL) + { + m_canReceive = NULL; + m_canSend = NULL; + m_canOpen = NULL; + m_canClose = NULL; + m_canChangeBaudRate = NULL; + FreeLibrary(handle); + fprintf (stderr, "GetProc error : %d\n", GetLastError()); + return NULL; + } #else - //compiled in... - handle = 1; //TODO: remove this hack - - m_canReceive = canReceive_driver; - m_canSend = canSend_driver; - m_canOpen = canOpen_driver; - m_canClose = canClose_driver; - m_canChangeBaudRate = canChangeBaudRate_driver; -#endif - - - return handle; + //compiled in... + handle = 1; //TODO: remove this hack + + m_canReceive = canReceive_driver; + m_canSend = canSend_driver; + m_canOpen = canOpen_driver; + m_canClose = canClose_driver; + m_canChangeBaudRate = canChangeBaudRate_driver; +#endif + + + return handle; } /***************************************************************************/ diff -r c10def4bfbde -r 91d708a2cb4e include/can_driver.h --- a/include/can_driver.h Wed Mar 06 13:40:54 2013 +0900 +++ b/include/can_driver.h Wed Mar 06 16:54:21 2013 +0900 @@ -46,7 +46,8 @@ }; #ifndef DLL_CALL -#if !defined(WIN32) || defined(__CYGWIN__) +#if !defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) +#define LIBAPI #define DLL_CALL(funcname) funcname##_driver #else #define LIBAPI __stdcall