2 Copyright (C) 2012 Intel Corporation
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "cansocketadapter.h"
20 #include "cansocket.h"
21 #include "canobserver.h"
22 #include "cansocketreader.h"
24 #include "cansocketbcm.h"
25 #include "cansocketraw.h"
27 // TODO: handle socket errors
29 CANSocketAdapter::CANSocketAdapter(CANObserver& observer) :
37 CANSocketAdapter::~CANSocketAdapter()
44 bool CANSocketAdapter::start(const char* ifName)
48 if(!mSocket || !mReader) {
52 if(mSocket && mReader && mSocket->start(ifName) && mReader->start()) {
60 void CANSocketAdapter::stop()
76 bool CANSocketAdapter::sendFrame(const can_frame& frame)
81 CANFrameInfo message(frame);
82 return mSocket->write(message);
87 void CANSocketAdapter::init()
90 mSocket = new CANSocketBCM();
92 mReader = new CANSocketReader(mObserver, *mSocket);
95 bool CANSocketAdapter::registerCyclicMessageForReceive(int canId, double minCycleTime, double maxCycleTime)
98 return mSocket->registerCyclicMessageForReceive(canId, minCycleTime, maxCycleTime);
103 bool CANSocketAdapter::unregisterMessageForReceive(int canId)
106 return mSocket->unregisterMessageForReceive(canId);