OpcUaCanOpen
CANopen OPC-UA server
AnaCanScan.h
Go to the documentation of this file.
1 
24 #ifndef CCANANASCAN_H_
25 #define CCANANASCAN_H_
26 
27 
28 #include <string>
29 #include "CanStatistics.h"
30 #include "CCanAccess.h"
31 #include "CanMessage.h"
32 
33 #ifdef _WIN32
34 
35 // #include "AnaGateDllCAN.h"
36 #include "AnaGateDllCan.h"
37 #include "AnaGateDll.h"
38 #include "tchar.h"
39 #include "Winsock2.h"
40 #include "windows.h"
41 
42 #else
43 
44 #include "AnaGateDLL.h"
45 #include "AnaGateDllCan.h"
46 
47 typedef unsigned long DWORD;
48 #endif
49 
54 using namespace CanModule;
55 
56 
58 {
59 
60 public:
61  AnaCanScan();//Constructor of the class. Will initiate the statistics.
62  AnaCanScan(AnaCanScan const & other) = delete; //Disables copy constructor
63  AnaCanScan& operator=(AnaCanScan const & other) = delete; // Disables assignment
64  virtual ~AnaCanScan();
65 
66  virtual bool createBus(const string name ,const string parameters);
67  virtual bool sendMessage(short cobID, unsigned char len, unsigned char *message, bool rtr = false);
68  virtual bool sendMessage(CanMessage *);
69  virtual bool sendRemoteRequest(short cobID);
70  virtual void getStatistics( CanStatistics & result );
71 
72  void statisticsOnRecieve(int);
73  void callbackOnRecieve(CanMessage&);
74  void startAlive( int aliveTime_sec );
75  void setConnectWaitTime( int timeout_ms );
76 
77  static std::string canMessageToString(CanMessage &f);
79 private:
80 
81  int m_canPortNumber; //The number of can port (CANA, CANB, ...) associated with this instance.
83  unsigned int m_baudRate; //Current baud rate for statistics
84  DWORD m_idCanScanThread; // Thread ID for the CAN update scan manager thread.
86  string m_busName;
88  AnaInt32 m_UcanHandle; //Instance of the can handle
89  CanStatistics m_statistics; //Instance of Can Statistics
90  AnaInt32 m_timeout; // connect_wait time
91 
102  static AnaInt32 s_canHandleArray[256];
103  static bool s_isCanHandleInUseArray[256];
104 
105  static void objectMapSize();
106  static int reconnectAllPorts( string ip );
107 
113  static void setCanHandleInUse(int handle, bool flag) { s_isCanHandleInUseArray[ handle ] = flag; }
114  static bool isCanHandleInUse(int handle) { return s_isCanHandleInUseArray[ handle ]; }
115  static void setCanHandleOfPort(int port, AnaInt32 handle) { s_canHandleArray[ port ] = handle; }
116  static AnaInt32 getCanHandleFromPort(int n) { return s_canHandleArray[n]; }
117 
118 
119  static std::map<string, bool> reconnectInProgress_map; // could use 1-dim vector but map is faster
120  static void setIpReconnectInProgress( string ip, bool flag );
121  static bool isIpReconnectInProgress( string ip );
122 
123  bool sendErrorCode(AnaInt32);
124  string ipAdress(){ return(m_canIPAddress );}
125  int canPortNumber(){ return(m_canPortNumber);}
126  int handle(){ return(m_UcanHandle);}
127  int configureCanBoard(const string name,const string parameters);
128  int connectReceptionHandler();
129  int openCanPort();
130  int reconnect();
131  bool errorCodeToString(long error, char message[]);
132  void stopBus( void );
133  void eraseReceptionHandlerFromMap( AnaInt32 h );
134 
135 };
136 
137 #endif //CCANANASCAN_H_