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: etisserant@355: //------------------------------------------------------------------------ etisserant@355: extern "C" etisserant@355: UNS8 canReceive_driver(CAN_HANDLE fd0, Message *m) etisserant@355: { etisserant@355: etisserant@355: string l = reinterpret_cast(fd0)->ReceiveLine(); etisserant@355: etisserant@355: 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}}", etisserant@355: &m->cob_id, etisserant@355: &m->rtr, etisserant@355: &m->len, etisserant@355: &m->data[0], etisserant@355: &m->data[1], etisserant@355: &m->data[2], etisserant@355: &m->data[3], etisserant@355: &m->data[4], etisserant@355: &m->data[5], etisserant@355: &m->data[6], etisserant@355: &m->data[7] etisserant@355: ); etisserant@355: etisserant@355: etisserant@355: #if defined DEBUG_MSG_CONSOLE_ON etisserant@355: printf("in : "); etisserant@355: print_message(m); etisserant@355: #endif etisserant@355: etisserant@355: return res==11 ? 0 : 1 ; etisserant@355: } etisserant@355: etisserant@355: extern "C" etisserant@355: UNS8 canSend_driver(CAN_HANDLE fd0, Message *m) etisserant@355: { etisserant@355: char s[1024]; etisserant@355: 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}}", etisserant@355: m->cob_id, etisserant@355: m->rtr, etisserant@355: m->len, etisserant@355: m->data[0], etisserant@355: m->data[1], etisserant@355: m->data[2], etisserant@355: m->data[3], etisserant@355: m->data[4], etisserant@355: m->data[5], etisserant@355: m->data[6], etisserant@355: m->data[7] etisserant@355: ); etisserant@355: etisserant@355: reinterpret_cast(fd0)->SendLine(s); etisserant@355: #if defined DEBUG_MSG_CONSOLE_ON etisserant@355: printf("out : "); etisserant@355: print_message(m); etisserant@355: #endif etisserant@355: return 0; etisserant@355: } etisserant@355: etisserant@355: extern "C" etisserant@355: CAN_HANDLE canOpen_driver(s_BOARD *board) etisserant@355: { etisserant@355: Socket* s; etisserant@355: try { etisserant@355: s = new SocketClient(board->busname, 11898); etisserant@355: etisserant@355: //s.SendLine("GET / HTTP/1.0"); etisserant@355: //s.SendLine("Host: www.google.com"); etisserant@355: } etisserant@355: catch (const char* _s) { etisserant@355: cerr << _s << endl; etisserant@355: return NULL; etisserant@355: } etisserant@355: catch (std::string _s) { etisserant@355: cerr << _s << endl; etisserant@355: return NULL; etisserant@355: } etisserant@355: catch (...) { etisserant@355: cerr << "unhandled exception\n"; etisserant@355: return NULL; etisserant@355: } etisserant@355: return (CAN_HANDLE) s; etisserant@355: } etisserant@355: etisserant@355: extern "C" etisserant@355: int canClose_driver(CAN_HANDLE inst) etisserant@355: { etisserant@355: delete reinterpret_cast(inst); etisserant@355: return 1; etisserant@355: } etisserant@355: