| Tipro API Communicate with Tipro devices

TiproHidDevice.h
Go to the documentation of this file.
1
17 #ifndef _TIPRO_TIPROHIDAPI_TIPROHIDDEVICE_H_
18 #define _TIPRO_TIPROHIDAPI_TIPROHIDDEVICE_H_
19
20 #include <mutex>
21 #include "hidapi.h"
22 #include "TiproBus.h"
23
24
25 typedef unsigned char UCHAR;
26
32 class TiproHidDevice
33 {
34 public:
35
36 enum ETErrCode
37 {
38 // compatible with EErrCode from CHid -> converted in ConvertErr() function
39 terrNone, // 0x00
40 terrWrongParameter, // 0x01
41 terrInvalidHandleValue, // 0x02
42 terrDeviceNotOpened, // 0x03
43 terrGetFeature, // 0x04
44 terrSetFeature, // 0x05
45 terrUnknown, // 0x06
46 // CTiproHid specific errors
47 terrCmdNotSupportedAtFWLevel, // 0x07
48 terrFWLevelNotAvailable, // 0x08
49 terrFWLevelChangeFailed, // 0x09
50 terrWTCDelayExpired, // 0x0A
51 terrWrongSignatureBytes, // 0x0B
52 terrResponseTimoutExpired, // 0x0C
53 // Firmware exchange errors
54 terrExchStatusVoid, // 0x0D
55 terrExchStatusReqTO, // 0x0E
56 terrExchStatusReqReject, // 0x0F
57 terrExchStatusReqFail, // 0x10
58 terrExchStatusReqSucc, // 0x11
59 terrExchStatusAnsPend, // 0x12
60 terrExchStatusAnsTO, // 0x13
61 terrExchStatusAnsReject, // 0x14
62 terrExchStatusAnsFail, // 0x15
63 terrExchStatusAnsOK, // 0x16
64 terrExchStatusFWBug // 0x17
65 };
66
67 //20190904
68 static const UCHAR FRCMD_RESET = 0x00;
69 static const UCHAR FRCMD_TMC_IF_DISABLE = 0x01;
70 static const UCHAR FRCMD_TMC_IF_ENABLE = 0x02;
71 static const UCHAR FRCMD_TMC_IF_V2_ENABLE = 0x03;
72 static const UCHAR FRCMD_LEVEL1_CMD = 0x04;
73 static const UCHAR FRCMD_CLR_SERIAL_NO = 0x05;
74 static const UCHAR FRCMD_OPT_IF = 0x06;
75 static const UCHAR FRCMD_FW_LEVEL = 0x07;
76 static const UCHAR FRCMD_MID_EXCH = 0x08;
77
78
79 TiproBus g_TiproBus;
80
85 virtual int Open();
86
91 virtual int Close();
92
96 TiproHidDevice();
97
102 TiproHidDevice(const char path[]);
103
107 virtual ~TiproHidDevice();
108
113 TiproHidDevice(const TiproHidDevice& other);
114
119 virtual TiproHidDevice& operator= (const TiproHidDevice& other);
120
131 virtual int SendCommandToConnectedDeviceEx(const UCHAR nCommand, const UCHAR nDest, const UCHAR *pParameters, const int nLen, UCHAR *pResponse, int *nResponseLen);
132
137 virtual int HIDEnumerateModules();//201907from tiprohidapiwindows
138
143 virtual const char* GetPath();
144
149 virtual hid_device* GetHidDevice();
150
155 virtual int Reset();
156
164 virtual int GetIndexedStringDescriptor(int lStrIx, wchar_t *pString, int lBufferLen);
165
172 virtual int GetManufacturerString(wchar_t *pString, int lBufferLen);
173
180 virtual int GetProductString(wchar_t *pString, int lBufferLen);
181
188 virtual int GetSerialNumberString(wchar_t *pString, int lBufferLen);
189
198 virtual int GetModuleVersion(int nIndex, unsigned char *nVerMaj, unsigned char *nVerMin, unsigned char *nVerBuild);
199
210 virtual int GetModuleVersionEx(int nIndex, unsigned char *nVerMaj, unsigned char *nVerMin, unsigned char *nVerBuild, unsigned char *nModuleType, unsigned char *nModuleID);
211
221 virtual int GetControllerInfo(int *nVerMaj, int *nVerMin, int *nVerBuild,int *nVerCustom, int *nFWLevel);
222
223 private:
224 static const unsigned int REPORT_LEN = 65; //Report length. It should be to communicate with the device
225 std::string _path = ""; //Device path
226 hid_device *_device = NULL; //Device object
227 unsigned int _report_length = 0; //Report length
228 unsigned short _signature = 0; //Signature
229 std::mutex door; //Mutex lock
230
235 hid_device* HidOpenPath();
236
241 int HidClose();
242
249 int HidSendFeatureReport(const unsigned char *data, size_t length);
250
257 int HidGetFeatureReport(unsigned char *data, size_t length);
258
267 int SendCommand(const unsigned char data_send[], size_t length_send, unsigned char data_receive[], size_t& length_receive);//20190909
268
274 int SetFwLevel(int fwlevel);
275
276
277 };
278
279 #endif
TiproHidDevice::GetModuleVersion
virtual int GetModuleVersion(int nIndex, unsigned char *nVerMaj, unsigned char *nVerMin, unsigned char *nVerBuild)
Gets module version from device, based on module index.
TiproHidDevice::GetControllerInfo
virtual int GetControllerInfo(int *nVerMaj, int *nVerMin, int *nVerBuild, int *nVerCustom, int *nFWLevel)
Gets controller version of device.
TiproHidDevice::~TiproHidDevice
virtual ~TiproHidDevice()
Destructor.
TiproHidDevice::SendCommandToConnectedDeviceEx
virtual int SendCommandToConnectedDeviceEx(const UCHAR nCommand, const UCHAR nDest, const UCHAR *pParameters, const int nLen, UCHAR *pResponse, int *nResponseLen)
Sends command to the device.
TiproHidDevice::GetSerialNumberString
virtual int GetSerialNumberString(wchar_t *pString, int lBufferLen)
Gets serial number string from device.
TiproHidDevice::GetManufacturerString
virtual int GetManufacturerString(wchar_t *pString, int lBufferLen)
Gets manufacturer string from device.
TiproHidDevice::HIDEnumerateModules
virtual int HIDEnumerateModules()
Enumerates modules of the device.
TiproHidDevice::Close
virtual int Close()
Closes device.
TiproHidDevice::TiproHidDevice
TiproHidDevice()
Constructor.
TiproHidDevice::GetModuleVersionEx
virtual int GetModuleVersionEx(int nIndex, unsigned char *nVerMaj, unsigned char *nVerMin, unsigned char *nVerBuild, unsigned char *nModuleType, unsigned char *nModuleID)
Gets module version, type and ID from device, based on module index.
TiproHidDevice::GetHidDevice
virtual hid_device * GetHidDevice()
Returns hid_device handle of the device.
TiproHidDevice::Reset
virtual int Reset()
Resets the device.
TiproHidDevice::GetPath
virtual const char * GetPath()
Returns path name of the device.
TiproHidDevice::Open
virtual int Open()
Opens device for communication.
TiproHidDevice::operator=
virtual TiproHidDevice & operator=(const TiproHidDevice &other)
Compare operator.
TiproHidDevice
Definition: TiproHidDevice.h:32
TiproHidDevice::GetProductString
virtual int GetProductString(wchar_t *pString, int lBufferLen)
Gets product string from device.
TiproHidDevice::GetIndexedStringDescriptor
virtual int GetIndexedStringDescriptor(int lStrIx, wchar_t *pString, int lBufferLen)
Gets a string from device, based on its string index.