OpcUaCanOpen
CANopen OPC-UA server
PKCanScan Class Reference

#include <pkcan.h>

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

Public Member Functions

 PKCanScan ()
 
virtual ~PKCanScan ()
 
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)
 
 PKCanScan ()
 
 PKCanScan (PKCanScan const &other)=delete
 
PKCanScanoperator= (PKCanScan const &other)=delete
 
virtual ~PKCanScan ()
 
virtual bool createBus (const string name, const string parameters)
 Method that initialises a CAN bus channel for peak (using PEAK Basic) All following methods called on the same object will be using this initialized channel. More...
 
virtual bool sendMessage (short cobID, unsigned char len, unsigned char *message, bool rtr=false)
 method to send a CAN message to the peak module. More...
 
virtual bool sendRemoteRequest (short cobID)
 
virtual void getStatistics (CanStatistics &result)
 
bool getErrorMessage (long error, char **message)
 
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)
 

Static Public Attributes

static std::map< string, string > m_busMap
 © Copyright CERN, 2015. More...
 

Private Member Functions

TPCANHandle getHandle (const char *name)
 This method returns a TPCANHandle (which is in fact a specific vendor defined hex value) as a function of a human readable string. More...
 
string getNamePort ()
 
bool sendErrorCode (long)
 
bool configureCanboard (const char *, const char *)
 
TPCANHandle getHandle (const char *name)
 
bool sendErrorCode (long)
 
bool configureCanboard (const string name, const string parameters)
 method to configure peak modules, one channel at a time. More...
 
void stopBus (void)
 notify the main thread to finish and delete the bus from the map of connections More...
 

Static Private Member Functions

static DWORD WINAPI CanScanControlThread (LPVOID pCanScan)
 thread to supervise port activity More...
 
static DWORD WINAPI CanScanControlThread (LPVOID pCanScan)
 

Private Attributes

TPCANStatus bus_status
 
bool run_can
 
int numChannel
 
unsigned int BaudRate
 
string canName
 
TPCANHandle canObjHandler
 
HANDLE m_hCanScanThread
 
HANDLE m_ReadEvent
 
DWORD m_idCanScanThread
 
Log::LogComponentHandle m_logItHandlePk
 
CanStatistics m_statistics
 
TPCANStatus m_busStatus
 
bool m_CanScanThreadRunEnableFlag
 
unsigned int m_baudRate
 
string m_busName
 
string m_busParameters
 
TPCANHandle m_canObjHandler
 

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 26 of file pkcan.h.

Constructor & Destructor Documentation

◆ PKCanScan() [1/3]

PKCanScan::PKCanScan ( )

Definition at line 28 of file pkcan.cpp.

◆ ~PKCanScan() [1/2]

PKCanScan::~PKCanScan ( )
virtual

Definition at line 33 of file pkcan.cpp.

◆ PKCanScan() [2/3]

PKCanScan::PKCanScan ( )

◆ PKCanScan() [3/3]

PKCanScan::PKCanScan ( PKCanScan const &  other)
delete

◆ ~PKCanScan() [2/2]

virtual PKCanScan::~PKCanScan ( )
virtual

Member Function Documentation

◆ CanScanControlThread() [1/2]

DWORD WINAPI PKCanScan::CanScanControlThread ( LPVOID  pCanScan)
staticprivate

thread to supervise port activity

Definition at line 40 of file pkcan.cpp.

◆ CanScanControlThread() [2/2]

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

◆ configureCanboard() [1/2]

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

Definition at line 90 of file pkcan.cpp.

◆ configureCanboard() [2/2]

bool PKCanScan::configureCanboard ( const string  name,
const string  parameters 
)
private

method to configure peak modules, one channel at a time.

We restrict this to USB interfaces and fixed datarate (not FD) modules If needed this can relatively easily be extended to other interfaces and FD mods as well.

FD (flexible datarate) modules. we need to contruct (a complicated) bitrate string in this case, according to PEAK PCAN-Basic Documentation API manual p.82 two data rates, for nominal and data, can be defined. all these parameters have to be passed TPCANStatus tpcanStatus = CAN_InitializeFD(m_canObjHandler, m_baudRate); TPCANBitrateFD br = "f_clock_mhz=20, nom_brp=5, nom_tseg1=2, nom_tseg2=1, nom_sjw=1"; PCAN_BR_CLOCK_MHZ=20, PCAN_BR_NOM_BRP=5, PCAN_BR_DATA_TSEG1=2, PCAN_BR_DATA_TSEG2=1, PCAN_BR_NOM_SJW=1;

fixed datarate modules (classical CAN), plug and play we try 10 times until success, the OS is a bit slow

fixed data rate, non plug-and-play static TPCANStatus Initialize( TPCANHandle Channel, TPCANBaudrate Btr0Btr1, TPCANType HwType, UInt32 IOPort, UInt16 Interrupt);

Definition at line 214 of file pkcan.cpp.

◆ createBUS()

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

Definition at line 193 of file pkcan.cpp.

◆ createBus()

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

Method that initialises a CAN bus channel for peak (using PEAK Basic) All following methods called on the same object will be using this initialized channel.

Only USB interfaces for PEAK modules, and only NON FD modules are supported for now.

Parameters
name= 2 parameters separated by ":" like "n0:n1"
  • n0 = "pk" for peak
  • n1 = CAN port number on the module, can be prefixed with "can": 0..N
  • ex.: "pk:can1" speaks to port 1 (the second port) on peak module
  • ex.: "pk:1" works as well
parametersone parameter: "p0", positive integer
  • "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?

Implements CanModule::CCanAccess.

Definition at line 159 of file pkcan.cpp.

◆ getErrorMessage() [1/2]

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

Definition at line 202 of file pkcan.cpp.

◆ getErrorMessage() [2/2]

bool PKCanScan::getErrorMessage ( long  error,
char **  message 
)

◆ getHandle() [1/2]

TPCANHandle PKCanScan::getHandle ( const char *  name)
private

This method returns a TPCANHandle (which is in fact a specific vendor defined hex value) as a function of a human readable string.

The human readable string basically codes the intefrace type (USB, ISA, PCI...) and the CAN port (1..8) so that i.e. USB3->0x53 which means USB interface 3rd channel

Definition at line 212 of file pkcan.cpp.

◆ getHandle() [2/2]

TPCANHandle PKCanScan::getHandle ( const char *  name)
private

◆ getNamePort()

string PKCanScan::getNamePort ( )
inlineprivate

Definition at line 38 of file pkcan.h.

◆ getStatistics()

void PKCanScan::getStatistics ( CanStatistics result)
virtual

Implements CanModule::CCanAccess.

Definition at line 474 of file pkcan.cpp.

◆ logItHandle()

Log::LogComponentHandle PKCanScan::logItHandle ( )
inline

Definition at line 63 of file pkcan.h.

◆ operator=()

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

◆ sendErrorCode() [1/2]

bool PKCanScan::sendErrorCode ( long  status)
private

Definition at line 137 of file pkcan.cpp.

◆ sendErrorCode() [2/2]

bool PKCanScan::sendErrorCode ( long  )
private

◆ sendMessage() [1/2]

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

Definition at line 155 of file pkcan.cpp.

◆ sendMessage() [2/2]

bool PKCanScan::sendMessage ( short  cobID,
unsigned char  len,
unsigned char *  message,
bool  rtr = false 
)
virtual

method to send a CAN message to the peak module.

we use the standard API "PCAN-Basic" for this for windows and we talk only over USB to fixed bitrate modules. The flexible bitrate (FD) modules can be implemented later as well: for this we need more parameters to pass and a switch between CAN_Write and CAN_WriteFD.

Implements CanModule::CCanAccess.

Definition at line 359 of file pkcan.cpp.

◆ sendRemoteRequest() [1/2]

bool PKCanScan::sendRemoteRequest ( short  cobID)
virtual

Implements CanModule::CCanAccess.

Definition at line 182 of file pkcan.cpp.

◆ sendRemoteRequest() [2/2]

virtual bool PKCanScan::sendRemoteRequest ( short  cobID)
virtual

Implements CanModule::CCanAccess.

◆ stopBus()

void PKCanScan::stopBus ( void  )
private

notify the main thread to finish and delete the bus from the map of connections

Definition at line 67 of file pkcan.cpp.

Member Data Documentation

◆ BaudRate

unsigned int PKCanScan::BaudRate
private

Definition at line 44 of file pkcan.h.

◆ bus_status

TPCANStatus PKCanScan::bus_status
private

Definition at line 41 of file pkcan.h.

◆ canName

string PKCanScan::canName
private

Definition at line 46 of file pkcan.h.

◆ canObjHandler

TPCANHandle PKCanScan::canObjHandler
private

Definition at line 50 of file pkcan.h.

◆ m_baudRate

unsigned int PKCanScan::m_baudRate
private

Definition at line 79 of file pkcan.h.

◆ m_busMap

std::map< string, string > PKCanScan::m_busMap
static

© Copyright CERN, 2015.

All rights not expressly granted are reserved.

AnaCanScan.cpp

Created on: Mar 17, 2015 Author: pnikiel, vfilimon, quasar team 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/.

PEAK bridge integration for windows

Definition at line 62 of file pkcan.h.

◆ m_busName

string PKCanScan::m_busName
private

Definition at line 80 of file pkcan.h.

◆ m_busParameters

string PKCanScan::m_busParameters
private

Definition at line 81 of file pkcan.h.

◆ m_busStatus

TPCANStatus PKCanScan::m_busStatus
private

Definition at line 76 of file pkcan.h.

◆ m_canObjHandler

TPCANHandle PKCanScan::m_canObjHandler
private

Definition at line 84 of file pkcan.h.

◆ m_CanScanThreadRunEnableFlag

bool PKCanScan::m_CanScanThreadRunEnableFlag
private

Definition at line 77 of file pkcan.h.

◆ m_hCanScanThread

HANDLE PKCanScan::m_hCanScanThread
private

Definition at line 53 of file pkcan.h.

◆ m_idCanScanThread

DWORD PKCanScan::m_idCanScanThread
private

Definition at line 57 of file pkcan.h.

◆ m_logItHandlePk

Log::LogComponentHandle PKCanScan::m_logItHandlePk
private

Definition at line 68 of file pkcan.h.

◆ m_ReadEvent

HANDLE PKCanScan::m_ReadEvent
private

Definition at line 54 of file pkcan.h.

◆ m_statistics

CanStatistics PKCanScan::m_statistics
private

Definition at line 75 of file pkcan.h.

◆ numChannel

int PKCanScan::numChannel
private

Definition at line 43 of file pkcan.h.

◆ run_can

bool PKCanScan::run_can
private

Definition at line 42 of file pkcan.h.


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