WPILibC++  2019.2.1-26-ge8b2471
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
SerialHelper.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2016-2018 FIRST. 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 <wpi/SmallString.h>
16 #include <wpi/SmallVector.h>
17 #include <wpi/mutex.h>
18 
19 #include "hal/SerialPort.h"
20 
21 namespace hal {
25 class SerialHelper {
26  public:
27  SerialHelper();
28 
36  std::string GetVISASerialPortName(HAL_SerialPort port, int32_t* status);
37 
45  std::string GetOSSerialPortName(HAL_SerialPort port, int32_t* status);
46 
53  std::vector<std::string> GetVISASerialPortList(int32_t* status);
54 
61  std::vector<std::string> GetOSSerialPortList(int32_t* status);
62 
63  private:
64  void SortHubPathVector();
65  void CoiteratedSort(wpi::SmallVectorImpl<wpi::SmallString<16>>& vec);
66  void QueryHubPaths(int32_t* status);
67 
68  int32_t GetIndexForPort(HAL_SerialPort port, int32_t* status);
69 
70  // Vectors to hold data before sorting.
71  // Note we will most likely have at max 2 instances, and the longest string
72  // is around 12, so these should never touch the heap;
73  wpi::SmallVector<wpi::SmallString<16>, 4> m_visaResource;
75  wpi::SmallVector<wpi::SmallString<16>, 4> m_unsortedHubPath;
76  wpi::SmallVector<wpi::SmallString<16>, 4> m_sortedHubPath;
77 
78  int32_t m_resourceHandle;
79 
80  static wpi::mutex m_nameMutex;
81  static std::string m_usbNames[2];
82 };
83 } // namespace hal
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: hostname.h:17
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:868
std::string GetVISASerialPortName(HAL_SerialPort port, int32_t *status)
Get the VISA name of a serial port.
std::string GetOSSerialPortName(HAL_SerialPort port, int32_t *status)
Get the OS name of a serial port.
WPILib Hardware Abstraction Layer (HAL) namespace.
Definition: SimDataValue.h:19
std::vector< std::string > GetOSSerialPortList(int32_t *status)
Get a vector of all serial port OS names.
std::vector< std::string > GetVISASerialPortList(int32_t *status)
Get a vector of all serial port VISA names.
A class for deterministically getting information about Serial Ports.
Definition: SerialHelper.h:25