2016-11-22 21:51:47 -08:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2017-01-01 01:05:57 -07:00
|
|
|
/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
|
2016-11-22 21:51:47 -08:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
#include <string>
|
2016-11-24 21:53:04 -08:00
|
|
|
#include <vector>
|
2016-11-22 21:51:47 -08:00
|
|
|
|
|
|
|
|
#include "HAL/SerialPort.h"
|
|
|
|
|
#include "HAL/cpp/priority_mutex.h"
|
|
|
|
|
#include "llvm/SmallString.h"
|
|
|
|
|
#include "llvm/SmallVector.h"
|
|
|
|
|
|
|
|
|
|
namespace hal {
|
|
|
|
|
class SerialHelper {
|
|
|
|
|
public:
|
2016-12-20 22:16:05 -08:00
|
|
|
SerialHelper();
|
2016-11-22 21:51:47 -08:00
|
|
|
|
2016-11-24 21:53:04 -08:00
|
|
|
std::string GetVISASerialPortName(HAL_SerialPort port, int32_t* status);
|
|
|
|
|
std::string GetOSSerialPortName(HAL_SerialPort port, int32_t* status);
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> GetVISASerialPortList(int32_t* status);
|
|
|
|
|
std::vector<std::string> GetOSSerialPortList(int32_t* status);
|
2016-11-22 21:51:47 -08:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void SortHubPathVector();
|
|
|
|
|
void CoiteratedSort(llvm::SmallVectorImpl<llvm::SmallString<16>>& vec);
|
|
|
|
|
void QueryHubPaths(int32_t* status);
|
|
|
|
|
|
2016-11-24 21:53:04 -08:00
|
|
|
int32_t GetIndexForPort(HAL_SerialPort port, int32_t* status);
|
|
|
|
|
|
2016-11-22 21:51:47 -08:00
|
|
|
// Vectors to hold data before sorting.
|
|
|
|
|
// Note we will most likely have at max 2 instances, and the longest string
|
|
|
|
|
// is around 12, so these should never touch the heap;
|
|
|
|
|
llvm::SmallVector<llvm::SmallString<16>, 4> m_visaResource;
|
|
|
|
|
llvm::SmallVector<llvm::SmallString<16>, 4> m_osResource;
|
|
|
|
|
llvm::SmallVector<llvm::SmallString<16>, 4> m_unsortedHubPath;
|
|
|
|
|
llvm::SmallVector<llvm::SmallString<16>, 4> m_sortedHubPath;
|
|
|
|
|
|
|
|
|
|
int32_t m_resourceHandle;
|
|
|
|
|
|
2017-05-11 21:25:22 -07:00
|
|
|
static hal::priority_mutex m_nameMutex;
|
2016-11-22 21:51:47 -08:00
|
|
|
static std::string m_usbNames[2];
|
|
|
|
|
};
|
|
|
|
|
} // namespace hal
|