OpcUaCanOpen
CANopen OPC-UA server
STCanScan.h
Go to the documentation of this file.
1 
23 #ifndef CCANSTSCAN_H_
24 #define CCANSTSCAN_H_
25 
26 #include "tchar.h"
27 #include "Winsock2.h"
28 #include "windows.h"
29 #include <string>
30 #include "CanStatistics.h"
31 #include "usbcan32.h"
32 #include "CCanAccess.h"
33 
34 using namespace CanModule;
35 
36 /*
37  * This is an implementation of the abstract class CCanAccess. It serves as a can bus access layer that will communicate with Systec crates (Windows only)
38  */
39 class STCanScan: public CanModule::CCanAccess
40 {
41 public:
42  //Constructor of the class. Will initiate the statistics.
43  STCanScan();
44  //Disables copy constructor
45  STCanScan(STCanScan const & other) = delete;
46  //Disables asignation
47  STCanScan& operator=(STCanScan const & other) = delete;
48  //Destructor of the class
49  virtual ~STCanScan();
50 
51  virtual bool createBus(const string name ,const string parameters);
52 
53  virtual bool sendMessage(short cobID, unsigned char len, unsigned char *message, bool rtr = false);
54 
55  /*
56  * 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
57  * can bus channel to send the request trough. Similar to sendMessage, but it sends an special message reserved for requests.
58  * @param cobID: Identifier that will be used for the request.
59  * @return: Was the initialisation process successful?
60  */
61  virtual bool sendRemoteRequest(short cobID);
62  //Returns the instance of the CanStatistics object
63  virtual void getStatistics( CanStatistics & result );
64 
65  Log::LogComponentHandle logItHandle(){ return m_logItHandleSt; }
66 
67 private:
68 
69  //The number of the can module associated with this instance.
71  //The number of the can channel associated with this instance.
73  //The number of can handle associated with this instance.
75  //Instance of the can handle
76  tUcanHandle m_UcanHandle;
77  //Instance of Can Statistics
79  //Current baud rate
80  unsigned int m_baudRate;
81 
83 
84  bool sendErrorCode(long);
85 
88  // Handle for the CAN update scan manager thread.
89  HANDLE m_hCanScanThread;
90  // Thread ID for the CAN update scan manager thread.
91  DWORD m_idCanScanThread;
92  // The main control thread function for the CAN update scan manager.
93  static DWORD WINAPI CanScanControlThread(LPVOID pCanScan);
94 
95  int configureCanBoard(const string name,const string parameters);
96  int openCanPort(tUcanInitCanParam initializationParameters);
97  /*
98  * Provides textual representation of an error code.
99  */
100  bool errorCodeToString(long error, char message[]);
101  static void setCanHandleInUse(int n,bool t) { s_isCanHandleInUseArray[n] = t; }
102  static bool isCanHandleInUse(int n) { return s_isCanHandleInUseArray[n]; }
103  static void setCanHandle(int n,tUcanHandle tU) { s_canHandleArray[n] = tU; }
104  static tUcanHandle getCanHandle(int n) { return s_canHandleArray[n]; }
105 
106  static tUcanHandle s_canHandleArray[256];
107  static bool s_isCanHandleInUseArray[256];
108 
109 
110 };
111 
112 #endif