usb_device_handle.hpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except
  4. in compliance with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2016
  6. All rights reserved.
  7. */
  8. #ifndef USB_DEVICE_HANDLE_HPP
  9. #define USB_DEVICE_HANDLE_HPP
  10. #include "types.h"
  11. #include "usb_device.hpp"
  12. #include "usb_device_list.hpp"
  13. struct USBError
  14. {
  15. enum Enum
  16. {
  17. NONE,
  18. DEVICE_GONE,
  19. INVALID_PARAM,
  20. FAILED,
  21. TIMED_OUT
  22. };
  23. private: USBError();
  24. };
  25. typedef USBDeviceList<const USBDevice*> ANTDeviceList;
  26. //typedef void (*DeviceCallback)(UCHAR); //!!Should we make this an error enum?
  27. //NOTE: We assume that there are no devices plugged/unplugged between getting the list and opening a device.
  28. //NOTE: USBDevice instances are invalid once a new device list is requested! This applies to all derived classes' lists as well.
  29. //!!Maybe USBDeviceHandle should have a GetDeviceList() function as well, and then USBDeviceList will only have to worry about being a constant container
  30. //!!Or maybe Device should have GetDeviceList();
  31. class USBDeviceHandle
  32. {
  33. public:
  34. static const USHORT USB_ANT_VID = 0x0FCF;
  35. static const USHORT USB_ANT_VID_TWO = 0x1915;
  36. static BOOL CopyANTDevice(const USBDevice*& pclUSBDeviceCopy_, const USBDevice* pclUSBDeviceOrg_);
  37. static const ANTDeviceList GetAllDevices(ULONG ulDeviceTypeField_ = 0xFFFFFFFF); //!!copy!
  38. static const ANTDeviceList GetAvailableDevices(ULONG ulDeviceTypeField_ = 0xFFFFFFFF); //!!copy!
  39. static BOOL Open(const USBDevice& clDevice_, USBDeviceHandle*& pclDeviceHandle_, ULONG ulBaudRate_);
  40. static BOOL Close(USBDeviceHandle*& pclDeviceHandle_, BOOL bReset_ = FALSE);
  41. virtual USBError::Enum Write(void* pvData_, ULONG ulSize_, ULONG& ulBytesWritten_) = 0; //!!Need timeout?
  42. /////////////////////////////////////////////////////////////////
  43. // Writes bytes to the serial port.
  44. // Parameters:
  45. // *pvData_: A pointer to a block of data to be queued
  46. // for sending over the serial port.
  47. // usSize_: The length of the block of data that is
  48. // pointed to by *pvData_.
  49. // Returns TRUE if successful. Otherwise, it returns FALSE.
  50. // ulBytesWritten_ is only valid when returns successful. //!!
  51. /////////////////////////////////////////////////////////////////
  52. virtual USBError::Enum Read(void* pvData_, ULONG ulSize_, ULONG& ulBytesRead_, ULONG ulWaitTime_) = 0;
  53. virtual const USBDevice& GetDevice() = 0;
  54. protected:
  55. USBDeviceHandle() {}
  56. virtual ~USBDeviceHandle() {}
  57. private:
  58. //!!virtual BOOL Open() = 0;
  59. /////////////////////////////////////////////////////////////////
  60. // Opens up the communication channel with the serial module.
  61. // Returns TRUE if successful. Otherwise, it returns FALSE.
  62. /////////////////////////////////////////////////////////////////
  63. //!!virtual BOOL Close(BOOL bReset = FALSE) = 0;
  64. /////////////////////////////////////////////////////////////////
  65. // Closes down the communication channel with the serial module.
  66. /////////////////////////////////////////////////////////////////
  67. };
  68. #endif //USB_DEVICE_HANDLE_HPP