WPILibC++ 2023.4.3-108-ge5452e3
SerialHelper.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <stdint.h>
8
9#include <string>
10#include <vector>
11
12#include <wpi/SmallString.h>
13#include <wpi/SmallVector.h>
14#include <wpi/mutex.h>
15
16#include "hal/SerialPort.h"
17
18namespace hal {
19/**
20 * A class for deterministically getting information about Serial Ports.
21 */
23 public:
25
26 /**
27 * Get the VISA name of a serial port.
28 *
29 * @param[in] port the serial port index
30 * @param[out] status status check
31 * @return the VISA name
32 */
33 std::string GetVISASerialPortName(HAL_SerialPort port, int32_t* status);
34
35 /**
36 * Get the OS name of a serial port.
37 *
38 * @param[in] port the serial port index
39 * @param[out] status status check
40 * @return the OS name
41 */
42 std::string GetOSSerialPortName(HAL_SerialPort port, int32_t* status);
43
44 /**
45 * Get a vector of all serial port VISA names.
46 *
47 * @param[out] status status check
48 * @return vector of serial port VISA names
49 */
50 std::vector<std::string> GetVISASerialPortList(int32_t* status);
51
52 /**
53 * Get a vector of all serial port OS names.
54 *
55 * @param[out] status status check
56 * @return vector of serial port OS names
57 */
58 std::vector<std::string> GetOSSerialPortList(int32_t* status);
59
60 private:
61 void SortHubPathVector();
62 void CoiteratedSort(wpi::SmallVectorImpl<wpi::SmallString<16>>& vec);
63 void QueryHubPaths(int32_t* status);
64
65 int32_t GetIndexForPort(HAL_SerialPort port, int32_t* status);
66
67 // Vectors to hold data before sorting.
68 // Note we will most likely have at max 2 instances, and the longest string
69 // is around 12, so these should never touch the heap;
72 wpi::SmallVector<wpi::SmallString<16>, 4> m_unsortedHubPath;
73 wpi::SmallVector<wpi::SmallString<16>, 4> m_sortedHubPath;
74
75 int32_t m_resourceHandle;
76
77 static wpi::mutex m_nameMutex;
78 static std::string m_usbNames[2];
79};
80} // namespace hal
This file defines the SmallString class.
This file defines the SmallVector class.
A class for deterministically getting information about Serial Ports.
Definition: SerialHelper.h:22
std::string GetOSSerialPortName(HAL_SerialPort port, int32_t *status)
Get the OS name of a serial port.
std::vector< std::string > GetOSSerialPortList(int32_t *status)
Get a vector of all serial port OS names.
std::string GetVISASerialPortName(HAL_SerialPort port, int32_t *status)
Get the VISA name of a serial port.
std::vector< std::string > GetVISASerialPortList(int32_t *status)
Get a vector of all serial port VISA names.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1186
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:557
HAL_SerialPort
Definition: SerialPort.h:18
::int32_t int32_t
Definition: Meta.h:57
WPILib Hardware Abstraction Layer (HAL) namespace.
Definition: ChipObject.h:40
::std::mutex mutex
Definition: mutex.h:17