OpcUaCanOpen
CANopen OPC-UA server
MockCanAccess.cpp
Go to the documentation of this file.
1
#include "
MockCanAccess.h
"
2
4
// MockCanAccess.cpp: implementation of the MockCanAccess class.
6
7
#include <time.h>
8
#include <cstring>
9
#include <string.h>
10
11
#include <map>
12
#include <
LogIt.h
>
13
#include <sstream>
14
#include <iostream>
15
16
#ifdef _WIN32
17
#define DLLEXPORTFLAG __declspec(dllexport)
18
#else
19
#define DLLEXPORTFLAG
20
#endif
21
22
using namespace
CanModule
;
23
24
extern
"C"
DLLEXPORTFLAG
CanModule::CCanAccess
*
getCanBusAccess
()
25
{
26
static
MockCanAccess
g_sMockCanAccess;
27
return
&g_sMockCanAccess;
28
}
29
30
MockCanAccess::MockCanAccess
()
31
:
CanModule
::
CCanAccess
(),m_baudRate(0)
32
{
33
m_statistics
.
beginNewRun
();
34
}
35
36
MockCanAccess::~MockCanAccess
()
37
{
38
LOG
(
Log::DBG
) <<
"Destroying MockCanAccess object"
;
39
}
40
41
bool
MockCanAccess::createBus
(
const
string
name
,
const
string
parameters)
42
{
43
LOG
(
Log::INF
) << __FUNCTION__ <<
" called with name ["
<<
name
<<
"] parameters ["
<< parameters <<
"]"
;
44
return
true
;
45
}
46
47
bool
MockCanAccess::sendRemoteRequest
(
short
cobID)
48
{
49
LOG
(
Log::DBG
) << __FUNCTION__ <<
" Sending cobID: ["
<<cobID <<
"]"
;
50
m_statistics
.
onTransmit
(
sizeof
(cobID));
51
return
true
;
52
}
53
54
bool
MockCanAccess::sendMessage
(
short
cobID,
unsigned
char
len,
unsigned
char
*message,
bool
rtr)
55
{
56
LOG
(
Log::DBG
) << __FUNCTION__ <<
" Sending message: ["
<< ( message == 0 ?
""
: (
const
char
*) message) <<
"], cobID: ["
<< cobID <<
"], Message Length: ["
<<
static_cast<
int
>
(len) <<
"]"
;
57
m_statistics
.
onTransmit
(len);
58
59
if
(0 == memcmp(message,
CAN_ECHO_MSG
, len))
60
{
61
CanMessage
response;
62
response.
c_id
= cobID;
63
response.
c_dlc
= len;
64
memcpy(response.
c_data
, message, (
unsigned
int
)len);
65
canMessageCame
(response);
66
}
67
return
true
;
68
}
69
70
void
MockCanAccess::getStatistics
(
CanStatistics
& result )
71
{
72
m_statistics
.
computeDerived
(
m_baudRate
);
73
result =
m_statistics
;
// copy whole structure
74
m_statistics
.
beginNewRun
();
75
}
76
77
std::string
MockCanAccess::getCanMessageDataAsString
(
const
unsigned
char
*
data
,
const
unsigned
char
& len
/*8*/
)
78
{
79
return
std::string
(
data
,
data
+ (len*
sizeof
(
unsigned
char
)));
80
}
81
82
bool
MockCanAccess::initialiseLogging
(
LogItInstance
* remoteInstance)
83
{
84
return
true
;
85
}
CanModule
CanInterfaceImplementations
unitTestMockUpImplementation
MockCanAccess.cpp
Generated on Fri Sep 11 2020 14:29:48 for OpcUaCanOpen by
1.8.14