#include <AnaCanScan.h>
Inherits CanModule::CCanAccess.
Definition at line 57 of file AnaCanScan.h.
◆ AnaCanScan() [1/2]
AnaCanScan::AnaCanScan |
( |
| ) |
|
◆ AnaCanScan() [2/2]
AnaCanScan::AnaCanScan |
( |
AnaCanScan const & |
other | ) |
|
|
delete |
◆ ~AnaCanScan()
AnaCanScan::~AnaCanScan |
( |
| ) |
|
|
virtual |
◆ callbackOnRecieve()
void AnaCanScan::callbackOnRecieve |
( |
CanMessage & |
msg | ) |
|
◆ canMessageToString()
std::string AnaCanScan::canMessageToString |
( |
CanMessage & |
f | ) |
|
|
static |
◆ canPortNumber()
int AnaCanScan::canPortNumber |
( |
| ) |
|
|
inlineprivate |
◆ configureCanBoard()
int AnaCanScan::configureCanBoard |
( |
const string |
name, |
|
|
const string |
parameters |
|
) |
| |
|
private |
decode the name, parameter and return the port of the configured module
Definition at line 264 of file AnaCanScan.cpp.
◆ connectReceptionHandler()
AnaInt32 AnaCanScan::connectReceptionHandler |
( |
| ) |
|
|
private |
connect the reception handler and only AFTER that register the handle in the global obj.
map, since reception is asynchron. Finally, in the caller, the stale handle is deleted from the map.
Definition at line 631 of file AnaCanScan.cpp.
◆ createBus()
bool AnaCanScan::createBus |
( |
const string |
name, |
|
|
const string |
parameters |
|
) |
| |
|
virtual |
Method that initialises a CAN bus channel for anagate.
All following methods called on the same object will be using this initialized channel.
- Parameters
-
name | 3 parameters separated by ":" like "n0:n1:n2" n0 = "an" for anagate n1 = port number on the module, 0=A, 1=B, etc etc n2 = ip number ex.: "an:can1:137.138.12.99" speaks to port B (=1) on anagate module at the ip ex.: "an:1:137.138.12.99" works as well |
parameters | up to 5 parameters separated by whitespaces : "p0 p1 p2 p3 p4" in THAT order, positive integers
- "Unspecified" (or empty): using defaults = "125000 0 0 0 0" // all params missing
- p0: bitrate: 10000, 20000, 50000, 62000, 100000, 125000, 250000, 500000, 800000, 1000000 bit/s
- p1: operatingMode: 0=default mode, values 1 (loop back) and 2 (listen) are not supported by CanModule
- p2: termination: 0=not terminated (default), 1=terminated (120 Ohm for CAN bus)
- p3: highSpeed: 0=deactivated (default), 1=activated. If activated, confirmation and filtering of CAN traffic are switched off
- p4: TimeStamp: 0=deactivated (default), 1=activated. If activated, a timestamp is added to the CAN frame. Not all modules support this. i.e. "250000 0 1 0 0" (see anagate manual for more details)
|
- Returns
- was the initialisation process successful?
Implements CanModule::CCanAccess.
Definition at line 230 of file AnaCanScan.cpp.
◆ eraseReceptionHandlerFromMap()
void AnaCanScan::eraseReceptionHandlerFromMap |
( |
AnaInt32 |
h | ) |
|
|
private |
◆ errorCodeToString()
bool AnaCanScan::errorCodeToString |
( |
long |
error, |
|
|
char |
message[] |
|
) |
| |
|
private |
◆ getCanHandleFromPort()
static AnaInt32 AnaCanScan::getCanHandleFromPort |
( |
int |
n | ) |
|
|
inlinestaticprivate |
◆ getStatistics()
◆ handle()
int AnaCanScan::handle |
( |
| ) |
|
|
inlineprivate |
◆ ipAdress()
string AnaCanScan::ipAdress |
( |
| ) |
|
|
inlineprivate |
◆ isCanHandleInUse()
static bool AnaCanScan::isCanHandleInUse |
( |
int |
handle | ) |
|
|
inlinestaticprivate |
◆ isIpReconnectInProgress()
bool AnaCanScan::isIpReconnectInProgress |
( |
string |
ip | ) |
|
|
staticprivate |
◆ objectMapSize()
void AnaCanScan::objectMapSize |
( |
| ) |
|
|
staticprivate |
◆ openCanPort()
int AnaCanScan::openCanPort |
( |
| ) |
|
|
private |
Obtains an Anagate 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
communicate with the hardware using the CanOpen interface: open anagate port, attach reply handler. No message queuing. CANSetMaxSizePerQueue not called==default==0
Definition at line 331 of file AnaCanScan.cpp.
◆ operator=()
◆ reconnect()
int AnaCanScan::reconnect |
( |
| ) |
|
|
private |
we try to reconnect one port after a power loss, and we should do this for all ports returns: 0 = OK -1 = could not CANOpenDevice device -2 = could not connect callback CANSetCallbackEx -3 = device was found open, tried to close but did not succeed (maybe you should just try sending again)
• 1 = DISCONNECTED : The connection to the AnaGate is disconnected. • 2 = CONNECTING : The connection is connecting. • 3 = CONNECTED : The connection is established. • 4 = DISCONNECTING : The connection is disonnecting. • 5 = NOT_INITIALIZED : The network protocol is not successfully initialized.
Definition at line 698 of file AnaCanScan.cpp.
◆ reconnectAllPorts()
AnaInt32 AnaCanScan::reconnectAllPorts |
( |
string |
ip | ) |
|
|
staticprivate |
reconnects all ports of a given ip adress=one module.
We have one object per CAN port, so i.e. for an anagate duo (ports A and B) we have two objects with the same IP but with port 0 and 1.So we will have to scan over all objects there because we do not know how many CANports a given anagate bridge has. We also allow globally only one ongoing reconnect to one ip at a time. Theoretically we could have a separate reconnection thread per ip, but that looks like overcomplicating the code and the issue. If several anagate modules fail they will all reconnect one after the other. That is OK since if all of these modules loose power and reboot at the same moment they will also be ready at roughly the same moment for reconnect. That means that we have to wait for the first ip to reconnect for a while but then all other ips will reconnect rather quickly in the most likely case. returns: 0 = OK -1 = cant open / reconnect CAN ports +1 = ignore, since another thread is doing the reconnect already
delete the map elements where the key is different from the handle, since we reassigned handles in the living objects like: g_AnaCanScanPointerMap[ m_UcanHandle ] = this;
Definition at line 513 of file AnaCanScan.cpp.
◆ sendErrorCode()
bool AnaCanScan::sendErrorCode |
( |
AnaInt32 |
status | ) |
|
|
private |
◆ sendMessage() [1/2]
bool AnaCanScan::sendMessage |
( |
short |
cobID, |
|
|
unsigned char |
len, |
|
|
unsigned char * |
message, |
|
|
bool |
rtr = false |
|
) |
| |
|
virtual |
send a CAN message frame (8 byte) for anagate Method that sends a message through 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 trough.
- Parameters
-
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? |
- Returns
- Was the sending process successful?
todo anyway extended can messages are not treated here yet
a sending on one port failed miserably. we are pessimistic and assume that the whole module (=ip) with all ports has lost power. Therefore we try to reconnect all used ports of this ip. This is a bit brute, but it will work. Nevertheless we should limit our efforts to this module=ip only and not reconnect all other modules managed by this task. we also avoid reconnecting all ports of an ip several times (for each failed send on a port)
Implements CanModule::CCanAccess.
Definition at line 432 of file AnaCanScan.cpp.
◆ sendMessage() [2/2]
◆ sendRemoteRequest()
bool AnaCanScan::sendRemoteRequest |
( |
short |
cobID | ) |
|
|
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.
- Parameters
-
cobID | Identifier that will be used for the request. |
- Returns
- Was the initialisation process successful?
Implements CanModule::CCanAccess.
Definition at line 819 of file AnaCanScan.cpp.
◆ setCanHandleInUse()
static void AnaCanScan::setCanHandleInUse |
( |
int |
handle, |
|
|
bool |
flag |
|
) |
| |
|
inlinestaticprivate |
we have one object for each CAN port, each object has an unique handle.
Several objects thus share the same ip. CAN ports and object handles are therefore equivalent, except that the handle value is assigned by the OS at CANopen.
Definition at line 113 of file AnaCanScan.h.
◆ setCanHandleOfPort()
static void AnaCanScan::setCanHandleOfPort |
( |
int |
port, |
|
|
AnaInt32 |
handle |
|
) |
| |
|
inlinestaticprivate |
◆ setConnectWaitTime()
void AnaCanScan::setConnectWaitTime |
( |
int |
timeout_ms | ) |
|
set a connection specific timeout value.
Global timeout is 6000, set by CanOpenDevice In order to make this specific timeout apply we have to reconnect
Definition at line 788 of file AnaCanScan.cpp.
◆ setIpReconnectInProgress()
void AnaCanScan::setIpReconnectInProgress |
( |
string |
ip, |
|
|
bool |
flag |
|
) |
| |
|
staticprivate |
◆ startAlive()
void AnaCanScan::startAlive |
( |
int |
aliveTime_sec | ) |
|
starts explicitly the anagate keepalive mechanism
- Todo:
- not sure we need this actually
Definition at line 798 of file AnaCanScan.cpp.
◆ statisticsOnRecieve()
void AnaCanScan::statisticsOnRecieve |
( |
int |
bytes | ) |
|
◆ stopBus()
void AnaCanScan::stopBus |
( |
void |
| ) |
|
|
private |
◆ m_baudRate
unsigned int AnaCanScan::m_baudRate |
|
private |
◆ m_busName
string AnaCanScan::m_busName |
|
private |
◆ m_busParameters
string AnaCanScan::m_busParameters |
|
private |
◆ m_canCloseDevice
bool AnaCanScan::m_canCloseDevice |
|
private |
◆ m_canIPAddress
string AnaCanScan::m_canIPAddress |
|
private |
◆ m_canPortNumber
int AnaCanScan::m_canPortNumber |
|
private |
◆ m_idCanScanThread
DWORD AnaCanScan::m_idCanScanThread |
|
private |
◆ m_statistics
◆ m_timeout
AnaInt32 AnaCanScan::m_timeout |
|
private |
◆ m_UcanHandle
AnaInt32 AnaCanScan::m_UcanHandle |
|
private |
◆ reconnectInProgress_map
std::map< string, bool > AnaCanScan::reconnectInProgress_map |
|
staticprivate |
◆ s_canHandleArray
AnaInt32 AnaCanScan::s_canHandleArray |
|
staticprivate |
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.
Definition at line 102 of file AnaCanScan.h.
◆ s_isCanHandleInUseArray
bool AnaCanScan::s_isCanHandleInUseArray |
|
staticprivate |
◆ st_logItHandleAnagate
The documentation for this class was generated from the following files: