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 
25 {
26  static MockCanAccess g_sMockCanAccess;
27  return &g_sMockCanAccess;
28 }
29 
31 :CanModule::CCanAccess(),m_baudRate(0)
32 {
34 }
35 
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 
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) << "]";
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 
71 {
73  result = m_statistics; // copy whole structure
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 
83 {
84  return true;
85 }