etisserant@355: /* etisserant@355: This file is part of CanFestival, a library implementing CanOpen Stack. etisserant@355: etisserant@355: Copyright (C): Edouard TISSERANT etisserant@355: etisserant@355: See COPYING file for copyrights details. etisserant@355: etisserant@355: This library is free software; you can redistribute it and/or etisserant@355: modify it under the terms of the GNU Lesser General Public etisserant@355: License as published by the Free Software Foundation; either etisserant@355: version 2.1 of the License, or (at your option) any later version. etisserant@355: etisserant@355: This library is distributed in the hope that it will be useful, etisserant@355: but WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@355: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU etisserant@355: Lesser General Public License for more details. etisserant@355: etisserant@355: You should have received a copy of the GNU Lesser General Public etisserant@355: License along with this library; if not, write to the Free Software etisserant@355: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@355: */ etisserant@355: etisserant@355: #include "Socket.h" etisserant@355: etisserant@355: #include etisserant@355: etisserant@355: using namespace std; etisserant@355: etisserant@355: extern "C" { etisserant@355: #include "can_driver.h" etisserant@355: etisserant@355: //------------------------------------------------------------------------ Edouard@774: UNS8 LIBAPI canReceive_driver(CAN_HANDLE fd0, Message *m) Edouard@774: { etisserant@355: Edouard@774: string l = reinterpret_cast(fd0)->ReceiveLine(); etisserant@355: Edouard@774: int res = sscanf(l.c_str(), Edouard@774: "{0x%3hx,%1hhd,%1hhd,{0x%2hhx,0x%2hhx,0x%2hhx,0x%2hhx,0x%2hhx,0x%2hhx,0x%2hhx,0x%2hhx}}", Edouard@774: &m->cob_id, Edouard@774: &m->rtr, Edouard@774: &m->len, Edouard@774: &m->data[0], Edouard@774: &m->data[1], Edouard@774: &m->data[2], Edouard@774: &m->data[3], Edouard@774: &m->data[4], Edouard@774: &m->data[5], Edouard@774: &m->data[6], Edouard@774: &m->data[7] Edouard@774: ); etisserant@355: etisserant@355: etisserant@355: #if defined DEBUG_MSG_CONSOLE_ON Edouard@774: printf("in : "); Edouard@774: print_message(m); etisserant@355: #endif etisserant@355: Edouard@774: return res==11 ? 0 : 1 ; Edouard@774: } Edouard@774: Edouard@774: UNS8 LIBAPI canSend_driver(CAN_HANDLE fd0, Message const *m) Edouard@774: { Edouard@774: char s[1024]; Edouard@774: 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}}", Edouard@774: m->cob_id, Edouard@774: m->rtr, Edouard@774: m->len, Edouard@774: m->data[0], Edouard@774: m->data[1], Edouard@774: m->data[2], Edouard@774: m->data[3], Edouard@774: m->data[4], Edouard@774: m->data[5], Edouard@774: m->data[6], Edouard@774: m->data[7] Edouard@774: ); Edouard@774: Edouard@774: reinterpret_cast(fd0)->SendLine(s); etisserant@355: #if defined DEBUG_MSG_CONSOLE_ON Edouard@774: printf("out : "); Edouard@774: print_message(m); etisserant@355: #endif Edouard@774: return 0; Edouard@774: } etisserant@355: Edouard@774: CAN_HANDLE LIBAPI canOpen_driver(s_BOARD *board) Edouard@774: { Edouard@777: char *dst = "127.0.0.1"; Edouard@777: if(!strlen(board->busname)){ Edouard@777: dst=board->busname; Edouard@777: } Edouard@774: try { Edouard@777: CAN_HANDLE res = (CAN_HANDLE) new SocketClient(dst, 11898); Edouard@777: return res; Edouard@774: } Edouard@774: catch (...) { Edouard@777: cerr << "can_tcp_win32: couldn't connect to" << dst << endl; Edouard@774: return NULL; Edouard@774: } Edouard@774: } etisserant@355: Edouard@774: int LIBAPI canClose_driver(CAN_HANDLE inst) Edouard@774: { Edouard@774: delete reinterpret_cast(inst); Edouard@774: return 1; Edouard@774: } Edouard@774: Edouard@774: UNS8 LIBAPI canChangeBaudRate_driver( CAN_HANDLE fd, char* baud) Edouard@774: { Edouard@774: cerr << "canChangeBaudRate not yet supported by this driver\n"; Edouard@774: return 0; Edouard@774: } Edouard@774: }