Skip to content

Commit

Permalink
Devel 1.1.9.10 (#41)
Browse files Browse the repository at this point in the history
* cleanup LogIt for single component logging
* updated doc
* tested 3 vendors against cc7 and w2016 for logging: OK
  • Loading branch information
meeludwig authored Jan 21, 2020
1 parent 4a2ed03 commit 98d32db
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 64 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
#
cmake_minimum_required(VERSION 3.0)
project( CanModule LANGUAGES C CXX VERSION 1.1.9.9 ) # sets PROJECT_VERSION etc etc
project( CanModule LANGUAGES C CXX VERSION 1.1.9.10 ) # sets PROJECT_VERSION etc etc
message(STATUS " [${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE}]: CanModule version= ${PROJECT_VERSION}" )
file(WRITE CanInterface/include/VERSION.h "// VERSION.h - do not edit\n#define CanModule_VERSION \"${PROJECT_VERSION}\"" )

Expand Down
37 changes: 18 additions & 19 deletions CanInterfaceImplementations/anagate/AnaCanScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ boost::mutex anagateReconnectMutex;

/* static */ bool AnaCanScan::s_isCanHandleInUseArray[256];
/* static */ AnaInt32 AnaCanScan::s_canHandleArray[256];
/* static */ bool AnaCanScan::s_logItRegisteredAnagate = false;
/* static */ Log::LogComponentHandle AnaCanScan::s_logItHandleAnagate = 0;
/* static */ Log::LogComponentHandle AnaCanScan::st_logItHandleAnagate = 0;
/* static */ std::map<string,bool> AnaCanScan::reconnectInProgress_map;

#define MLOGANA(LEVEL,THIS) LOG(Log::LEVEL, AnaCanScan::s_logItHandleAnagate) << __FUNCTION__ << " " << " anagate bus= " << THIS->getBusName() << " "
#define MLOGANA(LEVEL,THIS) LOG(Log::LEVEL, AnaCanScan::st_logItHandleAnagate) << __FUNCTION__ << " " << " anagate bus= " << THIS->getBusName() << " "

/** global map of connection-object-pointers: the map-key is the handle. Since handles are allocated by the OS
* the keys are getting changed as well when we reconnect, so that we do not keep the stale keys(=handles) in
Expand Down Expand Up @@ -249,7 +248,7 @@ bool AnaCanScan::createBus(const string name,const string parameters)
<< " could not get LogIt component handle for " << LogItComponentName << std::endl;

//LOG(Log::TRC, myHandle) << __FUNCTION__ << " " __FILE__ << " " << __LINE__;
AnaCanScan::s_logItHandleAnagate = myHandle;
AnaCanScan::st_logItHandleAnagate = myHandle;
int returnCode = configureCanBoard(name, parameters);
if ( returnCode < 0 ) {
return false;
Expand Down Expand Up @@ -482,9 +481,9 @@ bool AnaCanScan::sendMessage(short cobID, unsigned char len, unsigned char *mess

/* static */ void AnaCanScan::objectMapSize(){
uint32_t size = g_AnaCanScanPointerMap.size();
LOG(Log::TRC, AnaCanScan::s_logItHandleAnagate ) << __FUNCTION__ << " RECEIVE obj. map size= " << size << " : ";
LOG(Log::TRC, AnaCanScan::st_logItHandleAnagate ) << __FUNCTION__ << " RECEIVE obj. map size= " << size << " : ";
for (std::map<AnaInt32, AnaCanScan*>::iterator it=g_AnaCanScanPointerMap.begin(); it!=g_AnaCanScanPointerMap.end(); it++){
LOG(Log::TRC, AnaCanScan::s_logItHandleAnagate ) << __FUNCTION__ << " obj. map "
LOG(Log::TRC, AnaCanScan::st_logItHandleAnagate ) << __FUNCTION__ << " obj. map "
<< " key= " << it->first
<< " ip= " << it->second->ipAdress()
<< " CAN port= " << it->second->canPortNumber()
Expand Down Expand Up @@ -518,7 +517,7 @@ bool AnaCanScan::sendMessage(short cobID, unsigned char len, unsigned char *mess
{
anagateReconnectMutex.lock();
if ( AnaCanScan::isIpReconnectInProgress( ip ) ) {
LOG(Log::WRN, AnaCanScan::s_logItHandleAnagate ) << "reconnecting all ports for ip= " << ip
LOG(Log::WRN, AnaCanScan::st_logItHandleAnagate ) << "reconnecting all ports for ip= " << ip
<< " is already in progress, skipping.";

int us = 10000000;
Expand All @@ -528,7 +527,7 @@ bool AnaCanScan::sendMessage(short cobID, unsigned char len, unsigned char *mess
return(1);
}
AnaCanScan::setIpReconnectInProgress( ip, true );
LOG(Log::TRC, AnaCanScan::s_logItHandleAnagate ) << "reconnecting all ports for ip= " << ip
LOG(Log::TRC, AnaCanScan::st_logItHandleAnagate ) << "reconnecting all ports for ip= " << ip
<< " is now in progress.";
anagateReconnectMutex.unlock();
}
Expand All @@ -542,15 +541,15 @@ bool AnaCanScan::sendMessage(short cobID, unsigned char len, unsigned char *mess
bool reconnectFailed = false;
for (std::map<AnaInt32, AnaCanScan*>::iterator it=g_AnaCanScanPointerMap.begin(); it!=g_AnaCanScanPointerMap.end(); it++){
if ( ip == it->second->ipAdress() ){
LOG(Log::TRC, AnaCanScan::s_logItHandleAnagate ) << __FUNCTION__
LOG(Log::TRC, AnaCanScan::st_logItHandleAnagate ) << __FUNCTION__
<< " key= " << it->first
<< " found ip= " << ip
<< " for CAN port= " << it->second->canPortNumber()
<< " reconnecting...";

ret = it->second->reconnect();
if ( ret ){
LOG(Log::WRN, AnaCanScan::s_logItHandleAnagate) << __FUNCTION__
LOG(Log::WRN, AnaCanScan::st_logItHandleAnagate) << __FUNCTION__
<< " key= " << it->first
<< " found ip= " << ip
<< " for CAN port= " << it->second->canPortNumber()
Expand All @@ -560,16 +559,16 @@ bool AnaCanScan::sendMessage(short cobID, unsigned char len, unsigned char *mess
nbCANportsOnModule++;
}
}
LOG(Log::TRC, AnaCanScan::s_logItHandleAnagate) << " CAN bridge at ip= " << ip << " uses nbCANportsOnModule= " << nbCANportsOnModule;
LOG(Log::TRC, AnaCanScan::st_logItHandleAnagate) << " CAN bridge at ip= " << ip << " uses nbCANportsOnModule= " << nbCANportsOnModule;

if ( reconnectFailed ) {
LOG(Log::WRN, AnaCanScan::s_logItHandleAnagate ) << " Problem reconnecting CAN ports for ip= " << ip
LOG(Log::WRN, AnaCanScan::st_logItHandleAnagate ) << " Problem reconnecting CAN ports for ip= " << ip
<< " last ret= " << ret << ". Just abandoning and trying again in 10 secs, module might not be ready yet.";
int us = 10000000;
boost::this_thread::sleep(boost::posix_time::microseconds( us ));

AnaCanScan::setIpReconnectInProgress( ip, false );
LOG(Log::TRC, AnaCanScan::s_logItHandleAnagate ) << "reconnecting all ports for ip= " << ip
LOG(Log::TRC, AnaCanScan::st_logItHandleAnagate ) << "reconnecting all ports for ip= " << ip
<< " cancel.";
return(-1);
}
Expand All @@ -578,21 +577,21 @@ bool AnaCanScan::sendMessage(short cobID, unsigned char len, unsigned char *mess
std::map<AnaInt32, AnaCanScan*> lmap = g_AnaCanScanPointerMap; // use a local copy of the map, in order
// not to change the map we are iterating on

LOG(Log::TRC, AnaCanScan::s_logItHandleAnagate) << __FUNCTION__ << " " __FILE__ << " " << __LINE__
LOG(Log::TRC, AnaCanScan::st_logItHandleAnagate) << __FUNCTION__ << " " __FILE__ << " " << __LINE__
<< " receive handler map map before reconnect for ip= " << ip;
AnaCanScan::objectMapSize();

for (std::map<AnaInt32, AnaCanScan*>::iterator it=lmap.begin(); it!=lmap.end(); it++){
if ( ip == it->second->ipAdress() ){
anaRet = it->second->connectReceptionHandler();
if ( anaRet != 0 ){
LOG(Log::ERR, AnaCanScan::s_logItHandleAnagate) << __FUNCTION__ << " " __FILE__ << " " << __LINE__
LOG(Log::ERR, AnaCanScan::st_logItHandleAnagate) << __FUNCTION__ << " " __FILE__ << " " << __LINE__
<< " failed to reconnect reception handler for ip= " << ip
<< " handle= " << it->second->handle()
<< " port= " << it->second->canPortNumber()
<< " anaRet= " << anaRet;
} else {
LOG(Log::TRC, AnaCanScan::s_logItHandleAnagate ) << __FUNCTION__ << " " __FILE__ << " " << __LINE__
LOG(Log::TRC, AnaCanScan::st_logItHandleAnagate ) << __FUNCTION__ << " " __FILE__ << " " << __LINE__
<< " reconnect reception handler for ip= " << ip
<< " handle= " << it->second->handle()
<< " looking good= " << anaRet;
Expand All @@ -604,17 +603,17 @@ bool AnaCanScan::sendMessage(short cobID, unsigned char len, unsigned char *mess
* g_AnaCanScanPointerMap[ m_UcanHandle ] = this;
*/
if ( it->first != it->second->handle()){
LOG(Log::TRC, AnaCanScan::s_logItHandleAnagate) << __FUNCTION__ << " " __FILE__ << " " << __LINE__
LOG(Log::TRC, AnaCanScan::st_logItHandleAnagate) << __FUNCTION__ << " " __FILE__ << " " << __LINE__
<< " erasing stale handler " << it->first
<< " for object handle= " << it->second->handle() << " from obj. map";
g_AnaCanScanPointerMap.erase( it->first );
}
AnaCanScan::setIpReconnectInProgress( ip, false ); // all done, may fail another time
LOG(Log::TRC, AnaCanScan::s_logItHandleAnagate ) << "reconnecting all ports for ip= " << ip
LOG(Log::TRC, AnaCanScan::st_logItHandleAnagate ) << "reconnecting all ports for ip= " << ip
<< " is done and OK.";
}
}
LOG(Log::TRC, AnaCanScan::s_logItHandleAnagate) << __FUNCTION__ << " " __FILE__ << " " << __LINE__
LOG(Log::TRC, AnaCanScan::st_logItHandleAnagate) << __FUNCTION__ << " " __FILE__ << " " << __LINE__
<< " receive handler map after reconnect for ip= " << ip;
AnaCanScan::objectMapSize();

Expand Down
13 changes: 11 additions & 2 deletions CanInterfaceImplementations/anagate/AnaCanScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,17 @@ class AnaCanScan: public CanModule::CCanAccess
AnaInt32 m_UcanHandle; //Instance of the can handle
CanStatistics m_statistics; //Instance of Can Statistics
AnaInt32 m_timeout; // connect_wait time
static Log::LogComponentHandle s_logItHandleAnagate;
static bool s_logItRegisteredAnagate;

/**
* we would like to keep logging from a few static methods as well, since one IP
* number corresponds to many ports and some class-level management is going on for
* the connect-reconnect behavior. We definitely need these to be static. So since we
* need the logit handle static there is no point in having it also private. At least the
* cross-thread references to the handler are within this class only. It is
* all re-entrant code, and the handler does not change during runtime any more, so no
* mutex protection for now.
*/
static Log::LogComponentHandle st_logItHandleAnagate;
static AnaInt32 s_canHandleArray[256];
static bool s_isCanHandleInUseArray[256];

Expand Down
14 changes: 3 additions & 11 deletions CanInterfaceImplementations/pkcan/pkcan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@
#include "pkcan.h"
#include "CanModuleUtils.h"


/* static */ bool PKCanScan::s_logItRegisteredPk = false;
/* static */ Log::LogComponentHandle PKCanScan::s_logItHandlePk = 0;
/* static */ std::map<string, string> PKCanScan::m_busMap;

#define MLOGPK(LEVEL,THIS) LOG(Log::LEVEL, PKCanScan::s_logItHandlePk) << __FUNCTION__ << " " << " peak bus= " << THIS->getBusName() << " "
#define MLOGPK(LEVEL,THIS) LOG(Log::LEVEL, THIS->logItHandle()) << __FUNCTION__ << " " << " peak bus= " << THIS->getBusName() << " "

boost::mutex peakReconnectMutex; // protect m_busMap

Expand Down Expand Up @@ -149,7 +146,7 @@ DWORD WINAPI PKCanScan::CanScanControlThread(LPVOID pCanScan)
* @param name = 2 parameters separated by ":" like "n0:n1"
* * n0 = "pk" for peak@windows
* * 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 at the ip
* * ex.: "pk:can1" speaks to port 1 (the second port) on peak module
* * ex.: "pk:1" works as well
*
* @param parameters one parameter: "p0", positive integer
Expand All @@ -164,20 +161,15 @@ bool PKCanScan::createBus(const string name ,const string parameters )
m_busName = name;
m_busParameters = parameters;

// calling base class to get the instance from there
Log::LogComponentHandle myHandle;
LogItInstance* logItInstance = CCanAccess::getLogItInstance(); // actually calling instance method, not class

// register peak@W component for logging
if (!LogItInstance::setInstance(logItInstance))
std::cout << __FILE__ << " " << __LINE__ << " " << __FUNCTION__
<< " could not set LogIt instance" << std::endl;

if (!logItInstance->getComponentHandle( CanModule::LogItComponentName, myHandle))
if (!logItInstance->getComponentHandle( CanModule::LogItComponentName, m_logItHandlePk))
std::cout << __FILE__ << " " << __LINE__ << " " << __FUNCTION__
<< " could not get LogIt component handle for " << LogItComponentName << std::endl;

PKCanScan::s_logItHandlePk = myHandle;
MLOGPK(DBG, this) << " name= " << name << " parameters= " << parameters << ", configuring CAN board";

m_sBusName = name; // maybe this can be cleaned up: we have m_busName already
Expand Down
4 changes: 2 additions & 2 deletions CanInterfaceImplementations/pkcan/pkcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ class PKCanScan: public CanModule::CCanAccess
*/
bool getErrorMessage(long error, char **message);

static Log::LogComponentHandle s_logItHandlePk;
static bool s_logItRegisteredPk;
static std::map<string, string> m_busMap; // {name, parameters}
Log::LogComponentHandle logItHandle(){ return m_logItHandlePk; }

private:

TPCANHandle getHandle(const char *name);
Log::LogComponentHandle m_logItHandlePk;

bool sendErrorCode(long);
// The main control thread function for the CAN update scan manager.
Expand Down
17 changes: 6 additions & 11 deletions CanInterfaceImplementations/sockcan/SockCanScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@
#include <LogIt.h>

/* static */ std::map<string, string> CSockCanScan::m_busMap;
/* static */ Log::LogComponentHandle CSockCanScan::st_logItHandleSock;
boost::mutex sockReconnectMutex; // protect m_busMap

#define MLOGSOCK(LEVEL,THIS) LOG(Log::LEVEL, CSockCanScan::st_logItHandleSock) << __FUNCTION__ << " sock bus= " << THIS->getBusName() << " "
#define MLOGSOCK(LEVEL,THIS) LOG(Log::LEVEL, THIS->logItHandle()) << __FUNCTION__ << " sock bus= " << THIS->getBusName() << " "

boost::mutex sockReconnectMutex; // protect m_busMap


/**
Expand All @@ -68,7 +67,8 @@ CSockCanScan::CSockCanScan() :
m_hCanScanThread(0),
m_idCanScanThread(0),
m_errorCode(-1),
m_busName("nobus")
m_busName("nobus"),
m_logItHandleSock(0)
{
m_statistics.beginNewRun();
}
Expand Down Expand Up @@ -539,21 +539,16 @@ bool CSockCanScan::sendRemoteRequest(short cobID)
*/
bool CSockCanScan::createBus(const string name, const string parameters)
{
// calling base class to get the instance from there
Log::LogComponentHandle myHandle;
LogItInstance* logItInstance = CCanAccess::getLogItInstance(); // actually calling instance method, not class

// register socket component for logging
LogItInstance* logItInstance = CCanAccess::getLogItInstance();
if ( !LogItInstance::setInstance(logItInstance))
std::cout << __FILE__ << " " << __LINE__ << " " << __FUNCTION__
<< " could not set LogIt instance" << std::endl;

if (!logItInstance->getComponentHandle(CanModule::LogItComponentName, myHandle))
if (!logItInstance->getComponentHandle(CanModule::LogItComponentName, m_logItHandleSock))
std::cout << __FILE__ << " " << __LINE__ << " " << __FUNCTION__
<< " could not get LogIt component handle for " << LogItComponentName << std::endl;

CSockCanScan::st_logItHandleSock = myHandle;

// protect against creating the same bus twice
bool skip = false;
{
Expand Down
3 changes: 2 additions & 1 deletion CanInterfaceImplementations/sockcan/SockCanScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class CSockCanScan : public CCanAccess
return(f);
}
static std::map<string, string> m_busMap; // {name, parameters}
Log::LogComponentHandle logItHandle() { return m_logItHandleSock; }

private:
volatile bool m_CanScanThreadRunEnableFlag; //Flag for running/shutting down the CanScan thread
Expand All @@ -91,7 +92,7 @@ class CSockCanScan : public CCanAccess
std::string m_channelName;
std::string m_busName;

static Log::LogComponentHandle st_logItHandleSock;
Log::LogComponentHandle m_logItHandleSock;

//Closeup method that will be called from the destructor.
bool stopBus ();
Expand Down
21 changes: 12 additions & 9 deletions CanInterfaceImplementations/systec/STCanScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
bool STCanScan::s_isCanHandleInUseArray[256];
tUcanHandle STCanScan::s_canHandleArray[256];

/* static */ bool STCanScan::s_logItRegisteredSt = false;
/* static */ Log::LogComponentHandle STCanScan::s_logItHandleSt = 0;
///* static */ bool STCanScan::s_logItRegisteredSt = false;
///* static */ Log::LogComponentHandle STCanScan::s_logItHandleSt = 0;

#define MLOGST(LEVEL,THIS) LOG(Log::LEVEL, STCanScan::s_logItHandleSt) << __FUNCTION__ << " " << " systec bus= " << THIS->getBusName() << " "
#define MLOGST(LEVEL,THIS) LOG(Log::LEVEL, THIS->logItHandle()) << __FUNCTION__ << " " << " systec bus= " << THIS->getBusName() << " "

#ifdef _WIN32

Expand Down Expand Up @@ -135,24 +135,27 @@ STCanScan::~STCanScan()
* i.e. "250000"
*
* @return 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.
*/
bool STCanScan::createBus(const string name,const string parameters)
{
// calling base class to get the instance from there
Log::LogComponentHandle myHandle;
LogItInstance* logItInstance = CCanAccess::getLogItInstance(); // actually calling instance method, not class
//std::cout << __FILE__ << " " << __LINE__ << " " << __FUNCTION__ << " ptr= 0x" << logItInstance << std::endl;

// register systec@W component for logging
if ( !LogItInstance::setInstance(logItInstance))
std::cout << __FILE__ << " " << __LINE__ << " " << __FUNCTION__
<< " could not set LogIt instance" << std::endl;

if (!logItInstance->getComponentHandle(CanModule::LogItComponentName, myHandle))
if (!logItInstance->getComponentHandle(CanModule::LogItComponentName, m_logItHandleSt))
std::cout << __FILE__ << " " << __LINE__ << " " << __FUNCTION__
<< " could not get LogIt component handle for " << LogItComponentName << std::endl;

STCanScan::s_logItHandleSt = myHandle;

MLOGST(DBG, this) << " name= " << name << " parameters= " << parameters << ", configuring CAN board";
m_sBusName = name;
Expand Down
4 changes: 2 additions & 2 deletions CanInterfaceImplementations/systec/STCanScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ class STCanScan: public CanModule::CCanAccess
//Returns the instance of the CanStatistics object
virtual void getStatistics( CanStatistics & result );

static Log::LogComponentHandle s_logItHandleSt;
static bool s_logItRegisteredSt;
Log::LogComponentHandle logItHandle(){ return m_logItHandleSt; }

private:

Expand All @@ -80,6 +79,7 @@ class STCanScan: public CanModule::CCanAccess
//Current baud rate
unsigned int m_baudRate;

Log::LogComponentHandle m_logItHandleSt;

bool sendErrorCode(long);

Expand Down
2 changes: 0 additions & 2 deletions CanLibLoader/src/CanLibLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@
#include "CanLibLoaderLin.h"
#endif

using namespace std;
namespace CanModule
{

CanLibLoader::CanLibLoader(const std::string& libName) {
LogItInstance *logIt = LogItInstance::getInstance();
logIt->getComponentHandle( CanModule::LogItComponentName, lh );
//LOG(Log::TRC, lh ) << "logItComponentHandle= " << lh;
}

CanLibLoader::~CanLibLoader() {}
Expand Down
8 changes: 4 additions & 4 deletions Documentation/sphinx-source/vendors/anagate.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
===========
==========
`AnaGate`_
===========
==========

All modules from vendor `AnaGate`_ are handled by class AnaCanScan which manages the modules through their underlying vendor specific API and provides
the standard generic CanModule API.
Expand All @@ -14,7 +14,7 @@ Here the underlying vendor specific classes and the specific parameters are docu

The downside of Anagate CAN-ethernet modules is of course that the latency of the network has to be added to the bridge latency.

The connection
The connection
--------------

To connect to a specific port for I/O, and send CAN messages, the following methods are used.
Expand All @@ -32,7 +32,7 @@ This is how the CanModule standard API is used for anagate. The code is identica
.. code-block:: c++

libloader = CanModule::CanLibLoader::createInstance( "an" );
cca = libloader->openCanBus( "an:can0", "250000 0 1" ); // termination, ISEG controllers, p3, p4, p5 defaults
cca = libloader->openCanBus( "an:can0:137.138.12.99", "250000 0 1" ); // termination, ISEG controllers, p3, p4, p5 defaults
CanMessage cm; // empty
cca->sendMessage( &cm );

Expand Down

0 comments on commit 98d32db

Please sign in to comment.