WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
SerialHelper.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2016. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <stdint.h>
11 
12 #include <string>
13 #include <vector>
14 
15 #include "HAL/SerialPort.h"
16 #include "HAL/cpp/priority_mutex.h"
17 #include "llvm/SmallString.h"
18 #include "llvm/SmallVector.h"
19 
20 namespace hal {
21 class SerialHelper {
22  public:
23  SerialHelper();
24 
25  std::string GetVISASerialPortName(HAL_SerialPort port, int32_t* status);
26  std::string GetOSSerialPortName(HAL_SerialPort port, int32_t* status);
27 
28  std::vector<std::string> GetVISASerialPortList(int32_t* status);
29  std::vector<std::string> GetOSSerialPortList(int32_t* status);
30 
31  private:
32  void SortHubPathVector();
33  void CoiteratedSort(llvm::SmallVectorImpl<llvm::SmallString<16>>& vec);
34  void QueryHubPaths(int32_t* status);
35 
36  int32_t GetIndexForPort(HAL_SerialPort port, int32_t* status);
37 
38  // Vectors to hold data before sorting.
39  // Note we will most likely have at max 2 instances, and the longest string
40  // is around 12, so these should never touch the heap;
41  llvm::SmallVector<llvm::SmallString<16>, 4> m_visaResource;
42  llvm::SmallVector<llvm::SmallString<16>, 4> m_osResource;
43  llvm::SmallVector<llvm::SmallString<16>, 4> m_unsortedHubPath;
44  llvm::SmallVector<llvm::SmallString<16>, 4> m_sortedHubPath;
45 
46  int32_t m_resourceHandle;
47 
48  static priority_mutex m_nameMutex;
49  static std::string m_usbNames[2];
50 };
51 } // namespace hal
Definition: priority_mutex.h:53
Definition: SerialHelper.h:21