OpcUaCanOpen
CANopen OPC-UA server
pkcan.h
Go to the documentation of this file.
1 
8 #ifndef CCANPKSCAN_H_
9 #define CCANPKSCAN_H_
10 
11 
12 #include <string>
13 #include "Winsock2.h"
14 #include "windows.h"
15 
16 #include <PCANBasic.h>
17 #include "CCanAccess.h"
18 #include "CanStatistics.h"
19 
20 using namespace CanModule;
21 
22 /*
23  * This is an implementation of the abstract class CCanAccess. It serves as a can bus access layer that will communicate with Peak USB-CAN devices (Windows only)
24  */
25 class PKCanScan: public CanModule::CCanAccess
26 {
27 public:
28  //Constructor of the class. Will initiate the statistics.
29  PKCanScan();
30  //Disables copy constructor
31  PKCanScan(PKCanScan const & other) = delete;
32  //Disables asignation
33  PKCanScan& operator=(PKCanScan const & other) = delete;
34  //Destructor of the class
35  virtual ~PKCanScan();
36  virtual bool createBus(const string name,const string parameters);
37  /*
38  * Method that sends a message trough the can bus channel. If the method createBus was not called before this, sendMessage will fail, as there is no
39  * can bus channel to send a message trough.
40  * @param cobID: Identifier that will be used for the message.
41  * @param len: Length of the message. If the message is bigger than 8 characters, it will be split into separate 8 characters messages.
42  * @param message: Message to be sent trough the can bus.
43  * @param rtr: is the message a remote transmission request?
44  * @return: Was the sending process successful?
45  */
46  virtual bool sendMessage(short cobID, unsigned char len, unsigned char *message, bool rtr = false);
47  /*
48  * 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
49  * can bus channel to send the request trough. Similar to sendMessage, but it sends an special message reserved for requests.
50  * @param cobID: Identifier that will be used for the request.
51  * @return: Was the initialisation process successful?
52  */
53  virtual bool sendRemoteRequest(short cobID);
54  //Returns the instance of the CanStatistics object
55  virtual void getStatistics( CanStatistics & result );
56 
57  /*
58  * Converts Error code into a text message.
59  */
60  bool getErrorMessage(long error, char **message);
61 
62  static std::map<string, string> m_busMap; // {name, parameters}
63  Log::LogComponentHandle logItHandle(){ return m_logItHandlePk; }
64 
65 private:
66 
67  TPCANHandle getHandle(const char *name);
69 
70  bool sendErrorCode(long);
71  // The main control thread function for the CAN update scan manager.
72  static DWORD WINAPI CanScanControlThread(LPVOID pCanScan);
73 
74  //Instance of Can Statistics
76  TPCANStatus m_busStatus;
78  //Current baud rate
79  unsigned int m_baudRate;
80  string m_busName;
82 
83  //Instance of the can handle
84  TPCANHandle m_canObjHandler;
85  bool configureCanboard(const string name,const string parameters);
86  void stopBus ( void );
87 
88  HANDLE m_hCanScanThread;
89 // HANDLE m_ReadEvent;
90 
91  // Thread ID for the CAN update scan manager thread.
92  DWORD m_idCanScanThread;
93 };
94 
95 #endif