OpcUaCanOpen
CANopen OPC-UA server
STCanScan Class Reference

#include <stcan.h>

Inherits CanModule::CCanAccess, CanModule::CCanAccess, and CanModule::CCanAccess.

Public Member Functions

 STCanScan ()
 
virtual ~STCanScan ()
 
virtual bool createBUS (const char *, const char *)
 
virtual bool sendMessage (short cobID, unsigned char len, unsigned char *message)
 
virtual bool sendRemoteRequest (short cobID)
 
virtual bool getErrorMessage (long error, char message[])
 
 STCanScan ()
 
virtual ~STCanScan ()
 
virtual bool createBUS (const char *, const char *)
 
virtual bool sendMessage (short cobID, unsigned char len, unsigned char *message)
 
virtual bool sendRemoteRequest (short cobID)
 
virtual bool getErrorMessage (long error, char **message)
 
bool sendErrorCode (long)
 
 STCanScan ()
 
 STCanScan (STCanScan const &other)=delete
 
STCanScanoperator= (STCanScan const &other)=delete
 
virtual ~STCanScan ()
 
virtual bool createBus (const string name, const string parameters)
 Method that initialises a CAN bus channel for systec. 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...
 
virtual bool sendRemoteRequest (short cobID)
 
virtual void getStatistics (CanStatistics &result)
 
Log::LogComponentHandle logItHandle ()
 
- Public Member Functions inherited from CanModule::CCanAccess
 CCanAccess ()
 
virtual bool sendMessage (CanMessage *canm)
 
std::string & getBusName ()
 
virtual ~CCanAccess ()
 
bool initialiseLogging (LogItInstance *remoteInstance)
 
LogItInstancegetLogItInstance ()
 the LogIt instance is NOT shared by inheritance in windows, the instance has to be passed explicitly from the parent More...
 
vector< string > parseNameAndParameters (string name, string parameters)
 

Private Member Functions

string getNamePort ()
 
bool sendErrorCode (long)
 
bool configureCanboard (char *, char *, tUcanHandle &)
 
string getNamePort ()
 
bool configureCanboard (const char *, const char *)
 
bool sendErrorCode (long)
 
int configureCanBoard (const string name, const string parameters)
 
int openCanPort (tUcanInitCanParam initializationParameters)
 Obtains a Systec canport and opens it. More...
 
bool errorCodeToString (long error, char message[])
 

Static Private Member Functions

static DWORD WINAPI CanScanControlThread (LPVOID pCanScan)
 thread to supervise port activity More...
 
static void setInUse (int n, bool t)
 
static bool isInUse (int n)
 
static void setCanHandle (int n, tUcanHandle tU)
 
static tUcanHandle getCanHandle (int n)
 
static DWORD WINAPI CanScanControlThread (LPVOID pCanScan)
 
static void setCanHandleInUse (int n, bool t)
 
static bool isCanHandleInUse (int n)
 
static void setCanHandle (int n, tUcanHandle tU)
 
static tUcanHandle getCanHandle (int n)
 

Private Attributes

int numModule
 
int numChannel
 
int numCanHandle
 
tUcanHandle m_UcanHandle
 
DWORD bus_status
 
bool run_can
 
string canName
 
HANDLE m_hCanScanThread
 
DWORD m_idCanScanThread
 
long BaudRate
 
int m_moduleNumber
 
int m_channelNumber
 
int m_canHandleNumber
 
CanStatistics m_statistics
 
unsigned int m_baudRate
 
Log::LogComponentHandle m_logItHandleSt
 
DWORD m_busStatus
 
bool m_CanScanThreadShutdownFlag
 

Static Private Attributes

static tUcanHandle canHandle [256]
 
static bool inUse [256]
 
static tUcanHandle s_canHandleArray [256]
 
static bool s_isCanHandleInUseArray [256]
 © Copyright CERN, 2015. More...
 

Additional Inherited Members

- Public Attributes inherited from CanModule::CCanAccess
boost::signals2::signal< void(const CanMessage &) > canMessageCame
 
boost::signals2::signal< void(const int, const char *, timeval &) > canMessageError
 
- Protected Attributes inherited from CanModule::CCanAccess
string m_sBusName
 
CanParameters m_CanParameters
 

Detailed Description

Definition at line 24 of file stcan.h.

Constructor & Destructor Documentation

◆ STCanScan() [1/4]

STCanScan::STCanScan ( )

Definition at line 39 of file stcan.cpp.

◆ ~STCanScan() [1/3]

STCanScan::~STCanScan ( )
virtual

Definition at line 81 of file stcan.cpp.

◆ STCanScan() [2/4]

STCanScan::STCanScan ( )

◆ ~STCanScan() [2/3]

virtual STCanScan::~STCanScan ( )
virtual

◆ STCanScan() [3/4]

STCanScan::STCanScan ( )

◆ STCanScan() [4/4]

STCanScan::STCanScan ( STCanScan const &  other)
delete

◆ ~STCanScan() [3/3]

virtual STCanScan::~STCanScan ( )
virtual

Member Function Documentation

◆ CanScanControlThread() [1/2]

DWORD WINAPI STCanScan::CanScanControlThread ( LPVOID  pCanScan)
staticprivate

thread to supervise port activity

Definition at line 44 of file stcan.cpp.

◆ CanScanControlThread() [2/2]

static DWORD WINAPI STCanScan::CanScanControlThread ( LPVOID  pCanScan)
staticprivate

◆ configureCanboard() [1/2]

bool STCanScan::configureCanboard ( const char *  name,
const char *  parameters 
)
private

Definition at line 161 of file stcan.cpp.

◆ configureCanboard() [2/2]

bool STCanScan::configureCanboard ( char *  ,
char *  ,
tUcanHandle &   
)
private

◆ configureCanBoard()

int STCanScan::configureCanBoard ( const string  name,
const string  parameters 
)
private

Definition at line 181 of file STCanScan.cpp.

◆ createBUS() [1/2]

bool STCanScan::createBUS ( const char *  name,
const char *  parameters 
)
virtual

Definition at line 92 of file stcan.cpp.

◆ createBUS() [2/2]

virtual bool STCanScan::createBUS ( const char *  ,
const char *   
)
virtual

◆ createBus()

bool STCanScan::createBus ( const string  name,
const string  parameters 
)
virtual

Method that initialises a CAN bus channel for systec.

All following methods called on the same object will be using this initialized channel.

Parameters
name= 2 parameters separated by ":" like "n0:n1"
  • n0 = "st" for systec
  • n1 = CAN port number on the module, can be prefixed with "can"
  • ex.: "st:can1" speaks to port 1 on systec module at the ip
  • ex.: "st:1" works as well
parametersone parameter: "p0", positive integers
  • "Unspecified" (or empty): using defaults = "125000" // params missing
  • p0: bitrate: 50000, 100000, 125000, 250000, 500000, 1000000 bit/s i.e. "250000"
Returns
was the initialisation process successful?

===note from Piotr=== in the Windows implementation of Systec (hardware component: st): to define the interface naming as canX, where X is a non-negative number note: the SysTec driver for windows expects addressing in terms of module number and channel (e.g. 0:0 is can0, 1:0 is can2, 1:1 is can3, etc) so can0 should open a SysTec interface 0:0 matching "can0" on the box, can1 should open a SysTec interface 0:1 matching "can1" on the box, etc.

Implements CanModule::CCanAccess.

Definition at line 151 of file STCanScan.cpp.

◆ errorCodeToString()

bool STCanScan::errorCodeToString ( long  error,
char  message[] 
)
private

Definition at line 359 of file STCanScan.cpp.

◆ getCanHandle() [1/2]

static tUcanHandle STCanScan::getCanHandle ( int  n)
inlinestaticprivate

Definition at line 65 of file stcan.h.

◆ getCanHandle() [2/2]

static tUcanHandle STCanScan::getCanHandle ( int  n)
inlinestaticprivate

Definition at line 104 of file STCanScan.h.

◆ getErrorMessage() [1/2]

bool STCanScan::getErrorMessage ( long  error,
char  message[] 
)
virtual

Definition at line 234 of file stcan.cpp.

◆ getErrorMessage() [2/2]

bool STCanScan::getErrorMessage ( long  error,
char **  message 
)
virtual

Definition at line 151 of file stcan.cpp.

◆ getNamePort() [1/2]

string STCanScan::getNamePort ( )
inlineprivate

Definition at line 41 of file stcan.h.

◆ getNamePort() [2/2]

string STCanScan::getNamePort ( )
inlineprivate

Definition at line 44 of file stcan.h.

◆ getStatistics()

void STCanScan::getStatistics ( CanStatistics result)
virtual

Implements CanModule::CCanAccess.

Definition at line 369 of file STCanScan.cpp.

◆ isCanHandleInUse()

static bool STCanScan::isCanHandleInUse ( int  n)
inlinestaticprivate

Definition at line 102 of file STCanScan.h.

◆ isInUse()

static bool STCanScan::isInUse ( int  n)
inlinestaticprivate

Definition at line 63 of file stcan.h.

◆ logItHandle()

Log::LogComponentHandle STCanScan::logItHandle ( )
inline

Definition at line 65 of file STCanScan.h.

◆ openCanPort()

int STCanScan::openCanPort ( tUcanInitCanParam  initializationParameters)
private

Obtains a Systec canport and opens it.

The name of the port and parameters should have been specified by preceding call to configureCanboard()

Returns
less than zero in case of error, otherwise success

Definition at line 240 of file STCanScan.cpp.

◆ operator=()

STCanScan& STCanScan::operator= ( STCanScan const &  other)
delete

◆ sendErrorCode() [1/3]

bool STCanScan::sendErrorCode ( long  )

◆ sendErrorCode() [2/3]

bool STCanScan::sendErrorCode ( long  status)
private

Definition at line 176 of file stcan.cpp.

◆ sendErrorCode() [3/3]

bool STCanScan::sendErrorCode ( long  )
private

◆ sendMessage() [1/3]

bool STCanScan::sendMessage ( short  cobID,
unsigned char  len,
unsigned char *  message 
)
virtual

Definition at line 195 of file stcan.cpp.

◆ sendMessage() [2/3]

virtual bool STCanScan::sendMessage ( short  cobID,
unsigned char  len,
unsigned char *  message 
)
virtual

◆ sendMessage() [3/3]

bool STCanScan::sendMessage ( short  cobID,
unsigned char  len,
unsigned char *  message,
bool  rtr = false 
)
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.

Parameters
cobIDIdentifier that will be used for the message.
lenLength of the message. If the message is bigger than 8 characters, it will be split into separate 8 characters messages.
messageMessage to be sent trough the can bus.
rtris the message a remote transmission request?
Returns
Was the sending process successful?

Implements CanModule::CCanAccess.

Definition at line 305 of file STCanScan.cpp.

◆ sendRemoteRequest() [1/3]

bool STCanScan::sendRemoteRequest ( short  cobID)
virtual

Implements CanModule::CCanAccess.

Definition at line 222 of file stcan.cpp.

◆ sendRemoteRequest() [2/3]

virtual bool STCanScan::sendRemoteRequest ( short  cobID)
virtual

Implements CanModule::CCanAccess.

◆ sendRemoteRequest() [3/3]

virtual bool STCanScan::sendRemoteRequest ( short  cobID)
virtual

Implements CanModule::CCanAccess.

◆ setCanHandle() [1/2]

static void STCanScan::setCanHandle ( int  n,
tUcanHandle  tU 
)
inlinestaticprivate

Definition at line 64 of file stcan.h.

◆ setCanHandle() [2/2]

static void STCanScan::setCanHandle ( int  n,
tUcanHandle  tU 
)
inlinestaticprivate

Definition at line 103 of file STCanScan.h.

◆ setCanHandleInUse()

static void STCanScan::setCanHandleInUse ( int  n,
bool  t 
)
inlinestaticprivate

Definition at line 101 of file STCanScan.h.

◆ setInUse()

static void STCanScan::setInUse ( int  n,
bool  t 
)
inlinestaticprivate

Definition at line 62 of file stcan.h.

Member Data Documentation

◆ BaudRate

long STCanScan::BaudRate
private

Definition at line 48 of file stcan.h.

◆ bus_status

DWORD STCanScan::bus_status
private

Definition at line 44 of file stcan.h.

◆ canHandle

tUcanHandle STCanScan::canHandle
staticprivate

Definition at line 67 of file stcan.h.

◆ canName

string STCanScan::canName
private

Definition at line 47 of file stcan.h.

◆ inUse

bool STCanScan::inUse
staticprivate

Definition at line 68 of file stcan.h.

◆ m_baudRate

unsigned int STCanScan::m_baudRate
private

Definition at line 80 of file STCanScan.h.

◆ m_busStatus

DWORD STCanScan::m_busStatus
private

Definition at line 86 of file STCanScan.h.

◆ m_canHandleNumber

int STCanScan::m_canHandleNumber
private

Definition at line 74 of file STCanScan.h.

◆ m_CanScanThreadShutdownFlag

bool STCanScan::m_CanScanThreadShutdownFlag
private

Definition at line 87 of file STCanScan.h.

◆ m_channelNumber

int STCanScan::m_channelNumber
private

Definition at line 72 of file STCanScan.h.

◆ m_hCanScanThread

HANDLE STCanScan::m_hCanScanThread
private

Definition at line 54 of file stcan.h.

◆ m_idCanScanThread

DWORD STCanScan::m_idCanScanThread
private

Definition at line 57 of file stcan.h.

◆ m_logItHandleSt

Log::LogComponentHandle STCanScan::m_logItHandleSt
private

Definition at line 82 of file STCanScan.h.

◆ m_moduleNumber

int STCanScan::m_moduleNumber
private

Definition at line 70 of file STCanScan.h.

◆ m_statistics

CanStatistics STCanScan::m_statistics
private

Definition at line 78 of file STCanScan.h.

◆ m_UcanHandle

tUcanHandle STCanScan::m_UcanHandle
private

Definition at line 39 of file stcan.h.

◆ numCanHandle

int STCanScan::numCanHandle
private

Definition at line 38 of file stcan.h.

◆ numChannel

int STCanScan::numChannel
private

Definition at line 37 of file stcan.h.

◆ numModule

int STCanScan::numModule
private

Definition at line 36 of file stcan.h.

◆ run_can

bool STCanScan::run_can
private

Definition at line 45 of file stcan.h.

◆ s_canHandleArray

tUcanHandle STCanScan::s_canHandleArray
staticprivate

Definition at line 106 of file STCanScan.h.

◆ s_isCanHandleInUseArray

bool STCanScan::s_isCanHandleInUseArray
staticprivate

© Copyright CERN, 2015.

All rights not expressly granted are reserved.

STCanScap.cpp

Created on: Jul 21, 2011 Based on work by vfilimon Rework and logging done by Piotr Nikiel piotr.nosp@m.@nik.nosp@m.iel.i.nosp@m.nfo mludwig at cern dot ch

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/.The macro below is applicable only to this translation unit

Definition at line 107 of file STCanScan.h.


The documentation for this class was generated from the following files: