OpcUaCanOpen
CANopen OPC-UA server
|
#include <SockCanScan.h>
Inherits CCanAccess, CCanAccess, and CCanAccess.
Public Member Functions | |
CSockCanScan () | |
virtual | ~CSockCanScan () |
virtual bool | sendMessage (short cobID, unsigned char len, unsigned char *message) |
virtual bool | sendRemoteRequest (short cobID) |
Method that sends a remote request trough the can bus channel. More... | |
virtual bool | createBUS (const char *name, const char *parameters) |
string & | getNamePort () |
int | getHandler () |
string & | getChannel () |
CSockCanScan () | |
CSockCanScan (CSockCanScan const &other)=delete | |
CSockCanScan & | operator= (CSockCanScan const &other)=delete |
virtual | ~CSockCanScan () |
virtual bool | sendRemoteRequest (short cobID) |
virtual bool | createBus (const string name, string parameters) |
Method that initializes a can bus channel. More... | |
virtual bool | sendMessage (short cobID, unsigned char len, unsigned char *message, bool rtr=false) |
Method that sends a message trough the can bus channel. More... | |
int | getHandler () |
Returns socket handler. More... | |
virtual void | getStatistics (CanStatistics &result) |
Returns the instance of the CanStatistics object. More... | |
Log::LogComponentHandle | logItHandle () |
CSockCanScan () | |
int | FinalConstruct (const char *port, const char *parameters, CCanCallback *) |
string & | getNamePort () |
int | getHandler () |
int | sendErrorCode (int) |
virtual | ~CSockCanScan () |
virtual bool | sendMessage (short cobID, unsigned char len, unsigned char *message) |
virtual bool | sendRemoteRequest (short cobID) |
virtual bool | createBUS (const char *name, const char *parameters, CCanCallback *callback) |
![]() | |
CCanAccess () | |
std::string & | getBusName () |
void | setBusName (std::string &name) |
virtual | ~CCanAccess () |
CCanAccess () | |
virtual void | setCallBack (CCanCallback *callback) |
virtual bool | getErrorMessage (long, char **) |
int | getCanBusHandler () |
void | setCanBusHandler (int h) |
char * | getBusName () |
virtual | ~CCanAccess () |
Static Public Member Functions | |
static can_frame | emptyCanFrame (void) |
produce and empty can frame More... | |
Public Attributes | |
int | numModule |
int | numChannel |
int | numCanHandle |
CCanCallback * | cb |
![]() | |
boost::signals2::signal< void(const canMessage &) > | canMessageCame |
boost::signals2::signal< void(const int, const char *, timeval &) > | canMessageError |
Static Public Attributes | |
static std::map< string, string > | m_busMap |
© Copyright CERN, 2015. More... | |
Private Member Functions | |
void | sendErrorMessage (const char *) |
void | sendErrorMessage (const struct can_frame *) |
void | clearErrorMessage () |
int | configureCanboard (const char *, const char *) |
int | openCanPort () |
stop, set bitrate, start a CAN port, open a socket for it, set the socket to CAN, bind it and check any errors More... | |
void | waitCanDriver () |
bool | stopBus () |
notify the main thread to finish and delete the bus from the map of connections More... | |
void | updateInitialError () |
void | sendErrorMessage (const char *) |
void | clearErrorMessage () |
int | configureCanBoard (const string name, const string parameters) |
int | openCanPort () |
Obtains a SocketCAN socket and opens it. More... | |
int | configureCanboard (const char *, const char *) |
Static Private Member Functions | |
static void * | CanScanControlThread (void *) |
reading from socket, and supervising thread for monitoring the sockets/CAN buses. More... | |
static std::string | errorFrameToString (const struct can_frame &f) |
static void * | CanScanControlThread (void *) |
static void * | CanScanControlThread (void *) |
Private Attributes | |
bool | run_can |
int | sock |
pthread_t | m_hCanScanThread |
int | m_idCanScanThread |
string | name_of_port |
string | channelName |
string | param |
volatile bool | m_CanScanThreadRunEnableFlag |
int | m_sock |
CanStatistics | m_statistics |
int | m_errorCode |
std::string | m_channelName |
std::string | m_busName |
Log::LogComponentHandle | m_logItHandleSock |
Additional Inherited Members | |
![]() | |
char * | busName |
int | handler |
CCanCallback * | cb |
Definition at line 21 of file SockCanScan.h.
|
inline |
Definition at line 25 of file SockCanScan.h.
|
virtual |
Definition at line 148 of file SockCanScan.cpp.
CSockCanScan::CSockCanScan | ( | ) |
|
delete |
|
virtual |
|
inline |
Definition at line 23 of file SockCanScan.h.
|
virtual |
|
staticprivate |
|
staticprivate |
reading from socket, and supervising thread for monitoring the sockets/CAN buses.
It takes an object reference (cast) and listens with a select call on that socket/object. The select runs with 1Hz, and if there is nothing to receive it should timeout.
the select failed. that is very bad, system problem, but let's continue nevertheless. There is not much we can do
select returned, either on the timeout or with something on that socket/object. Assumption: at this moment sock holds meaningful value. Now select result >=0 so it was either nothing received (timeout) or something received
The preceding call took either 'timeout' time, or there is frame received – perfect time to attempt to clean error frame.
select reports that it has got something, so no timeout in this case
try to re-open the socket. only reopen the socket if we still need it. If we need to shutdown the thread, leave it closed and terminate main loop.
if we have an open socket again, and we can read numberOfReadBytes >=0 we should be fine again and continue the thread execution normally
we have a CAN message, error free, lets digest it
reformat and buffer the message from the socket. this actually should exclude more bits
the select got nothing to read, this was just a timeout.
Definition at line 48 of file SockCanScan.cpp.
|
staticprivate |
|
private |
Definition at line 472 of file SockCanScan.cpp.
|
private |
|
private |
|
private |
Definition at line 161 of file SockCanScan.cpp.
|
private |
Definition at line 311 of file SockCanScan.cpp.
|
virtual |
Implements CCanAccess.
Definition at line 354 of file SockCanScan.cpp.
|
virtual |
Implements CCanAccess.
Definition at line 206 of file SockCanScan.cpp.
|
virtual |
Method that initializes a can bus channel.
The following methods called upon the same object will be using this initialized channel.
name | = 2 parameters separated by ":", like "n0:n1"
|
parameters | one parameter: "p0", positive integer
|
dont create a main thread for the same bus twice: if it exists already, just configure the board again this protects agains having multiple threads if a given port ports is opened several times: protects against erro/unusual runtime. If the connection is closed, it's main thread is stopped and joined, and the port is erased from the connection map. when the same port is opened again later on, a (new) main thread is created, and the connection is again added to the map.
Definition at line 540 of file SockCanScan.cpp.
|
inlinestatic |
produce and empty can frame
Definition at line 72 of file SockCanScan.h.
|
staticprivate |
Definition at line 585 of file SockCanScan.cpp.
int CSockCanScan::FinalConstruct | ( | const char * | port, |
const char * | parameters, | ||
CCanCallback * | callb | ||
) |
Definition at line 71 of file SockCanScan.cpp.
|
inline |
Definition at line 35 of file SockCanScan.h.
|
inline |
Definition at line 26 of file SockCanScan.h.
|
inline |
Definition at line 34 of file SockCanScan.h.
|
inline |
Returns socket handler.
Definition at line 62 of file SockCanScan.h.
|
inline |
Definition at line 25 of file SockCanScan.h.
|
inline |
Definition at line 33 of file SockCanScan.h.
|
virtual |
Returns the instance of the CanStatistics object.
Definition at line 703 of file SockCanScan.cpp.
|
inline |
Definition at line 82 of file SockCanScan.h.
|
private |
stop, set bitrate, start a CAN port, open a socket for it, set the socket to CAN, bind it and check any errors
Definition at line 180 of file SockCanScan.cpp.
|
private |
Obtains a SocketCAN socket and opens it.
The name of the port and parameters should have been specified by preceding call to configureCanboard()
|
delete |
int CSockCanScan::sendErrorCode | ( | int | status | ) |
Definition at line 155 of file SockCanScan.cpp.
|
private |
Definition at line 484 of file SockCanScan.cpp.
|
private |
Definition at line 369 of file SockCanScan.cpp.
|
private |
|
virtual |
Implements CCanAccess.
Definition at line 271 of file SockCanScan.cpp.
|
virtual |
Implements CCanAccess.
|
virtual |
Method that sends a message trough the can bus channel.
If the method createBUS was not called before this, sendMessage will fail, as there is no can bus channel to send a message through.
cobID | Identifier that will be used for the message. |
len | Length of the message. If the message is bigger than 8 characters, it will be split into separate 8 characters messages. |
message | Message to be sent trough the can bus. |
rtr | is the message a remote transmission request? |
Definition at line 409 of file SockCanScan.cpp.
|
virtual |
Method that sends a remote request trough the can bus channel.
If the method createBUS was not called before this, sendMessage will fail, as there is no can bus channel to send the request trough. Similar to sendMessage, but it sends an special message reserved for requests.
cobID | Identifier that will be used for the request. |
that is not tested or used until now, and I am not sure it works
Implements CCanAccess.
Definition at line 319 of file SockCanScan.cpp.
|
virtual |
Implements CCanAccess.
|
virtual |
Implements CCanAccess.
|
private |
notify the main thread to finish and delete the bus from the map of connections
Definition at line 679 of file SockCanScan.cpp.
|
private |
Definition at line 710 of file SockCanScan.cpp.
|
private |
Definition at line 495 of file SockCanScan.cpp.
CCanCallback* CSockCanScan::cb |
Definition at line 40 of file SockCanScan.h.
|
private |
Definition at line 55 of file SockCanScan.h.
|
static |
© Copyright CERN, 2015.
All rights not expressly granted are reserved.
SockCanScan.cpp
Created on: Jul 21, 2011 Based on work by vfilimon Rework and logging done by Piotr Nikiel piotr mludwig at cern dot ch @nik iel.i nfo
This file is part of Quasar.
Quasar is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public Licence as published by the Free Software Foundation, either version 3 of the Licence.
Quasar 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 Licence for more details.
You should have received a copy of the GNU Lesser General Public License along with Quasar. If not, see http://www.gnu.org/licenses/.
Definition at line 81 of file SockCanScan.h.
|
private |
Definition at line 93 of file SockCanScan.h.
|
private |
Definition at line 85 of file SockCanScan.h.
|
private |
Definition at line 92 of file SockCanScan.h.
|
private |
Definition at line 91 of file SockCanScan.h.
|
private |
Definition at line 42 of file SockCanScan.h.
|
private |
Definition at line 43 of file SockCanScan.h.
|
private |
Definition at line 95 of file SockCanScan.h.
|
private |
Definition at line 87 of file SockCanScan.h.
|
private |
Definition at line 88 of file SockCanScan.h.
|
private |
Definition at line 54 of file SockCanScan.h.
int CSockCanScan::numCanHandle |
Definition at line 37 of file SockCanScan.h.
int CSockCanScan::numChannel |
Definition at line 36 of file SockCanScan.h.
int CSockCanScan::numModule |
Definition at line 35 of file SockCanScan.h.
|
private |
Definition at line 56 of file SockCanScan.h.
|
private |
Definition at line 38 of file SockCanScan.h.
|
private |
Definition at line 39 of file SockCanScan.h.