mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Replace std::stringstream with llvm::raw_svector_ostream (#345)
A few locations were changed to use std::ostringstream.
This commit is contained in:
committed by
Peter Johnson
parent
7006672b06
commit
b433d98c02
@@ -10,9 +10,11 @@
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
inline std::string NowTime();
|
||||
|
||||
enum TLogLevel {
|
||||
@@ -31,7 +33,7 @@ class Log {
|
||||
public:
|
||||
Log();
|
||||
virtual ~Log();
|
||||
std::ostringstream& Get(TLogLevel level = logINFO);
|
||||
llvm::raw_ostream& Get(TLogLevel level = logINFO);
|
||||
|
||||
public:
|
||||
static TLogLevel& ReportingLevel();
|
||||
@@ -39,7 +41,8 @@ class Log {
|
||||
static TLogLevel FromString(const std::string& level);
|
||||
|
||||
protected:
|
||||
std::ostringstream os;
|
||||
llvm::SmallString<128> buf;
|
||||
llvm::raw_svector_ostream oss{buf};
|
||||
|
||||
private:
|
||||
Log(const Log&);
|
||||
@@ -48,16 +51,16 @@ class Log {
|
||||
|
||||
inline Log::Log() {}
|
||||
|
||||
inline std::ostringstream& Log::Get(TLogLevel level) {
|
||||
os << "- " << NowTime();
|
||||
os << " " << ToString(level) << ": ";
|
||||
os << std::string(level > logDEBUG ? level - logDEBUG : 0, '\t');
|
||||
return os;
|
||||
inline llvm::raw_ostream& Log::Get(TLogLevel level) {
|
||||
oss << "- " << NowTime();
|
||||
oss << " " << ToString(level) << ": ";
|
||||
oss << std::string(level > logDEBUG ? level - logDEBUG : 0, '\t');
|
||||
return oss;
|
||||
}
|
||||
|
||||
inline Log::~Log() {
|
||||
os << std::endl;
|
||||
std::cerr << os.str();
|
||||
oss << "\n";
|
||||
std::cerr << oss.str();
|
||||
}
|
||||
|
||||
inline TLogLevel& Log::ReportingLevel() {
|
||||
@@ -96,16 +99,29 @@ typedef Log FILELog;
|
||||
Log().Get(level)
|
||||
|
||||
inline std::string NowTime() {
|
||||
std::stringstream ss;
|
||||
ss << std::setfill('0') << std::setw(2);
|
||||
llvm::SmallString<128> buf;
|
||||
llvm::raw_svector_ostream oss(buf);
|
||||
|
||||
using namespace std::chrono;
|
||||
auto now = system_clock::now().time_since_epoch();
|
||||
|
||||
ss << duration_cast<hours>(now).count() % 24 << ":"
|
||||
<< duration_cast<minutes>(now).count() % 60 << ":"
|
||||
<< duration_cast<seconds>(now).count() % 60 << "."
|
||||
<< duration_cast<milliseconds>(now).count() % 1000;
|
||||
// Hours
|
||||
auto count = duration_cast<hours>(now).count() % 24;
|
||||
if (count < 10) oss << "0";
|
||||
oss << count << ":";
|
||||
|
||||
return ss.str();
|
||||
// Minutes
|
||||
count = duration_cast<minutes>(now).count() % 60;
|
||||
if (count < 10) oss << "0";
|
||||
oss << count << ":";
|
||||
|
||||
// Seconds
|
||||
count = duration_cast<seconds>(now).count() % 60;
|
||||
if (count < 10) oss << "0";
|
||||
oss << count << ".";
|
||||
|
||||
// Milliseconds
|
||||
oss << duration_cast<milliseconds>(now).count() % 1000;
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#define DEFAULT_SAFETY_EXPIRATION 0.1
|
||||
|
||||
#include <sstream>
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -21,7 +21,7 @@ class MotorSafety {
|
||||
virtual void StopMotor() = 0;
|
||||
virtual void SetSafetyEnabled(bool enabled) = 0;
|
||||
virtual bool IsSafetyEnabled() const = 0;
|
||||
virtual void GetDescription(std::ostringstream& desc) const = 0;
|
||||
virtual void GetDescription(llvm::raw_ostream& desc) const = 0;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "MotorSafety.h"
|
||||
#include "SensorBase.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
#include "tables/ITable.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
@@ -53,7 +54,7 @@ class Relay : public MotorSafety,
|
||||
void StopMotor() override;
|
||||
bool IsSafetyEnabled() const override;
|
||||
void SetSafetyEnabled(bool enabled) override;
|
||||
void GetDescription(std::ostringstream& desc) const override;
|
||||
void GetDescription(llvm::raw_ostream& desc) const override;
|
||||
|
||||
void ValueChanged(ITable* source, llvm::StringRef key,
|
||||
std::shared_ptr<nt::Value> value, bool isNew) override;
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "MotorSafety.h"
|
||||
#include "MotorSafetyHelper.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -94,7 +94,7 @@ class RobotDrive : public MotorSafety, public ErrorBase {
|
||||
void StopMotor() override;
|
||||
bool IsSafetyEnabled() const override;
|
||||
void SetSafetyEnabled(bool enabled) override;
|
||||
void GetDescription(std::ostringstream& desc) const override;
|
||||
void GetDescription(llvm::raw_ostream& desc) const override;
|
||||
|
||||
protected:
|
||||
void InitRobotDrive();
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
#include "MotorSafety.h"
|
||||
#include "MotorSafetyHelper.h"
|
||||
#include "PWM.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -34,7 +34,7 @@ class SafePWM : public PWM, public MotorSafety {
|
||||
void StopMotor();
|
||||
bool IsSafetyEnabled() const;
|
||||
void SetSafetyEnabled(bool enabled);
|
||||
void GetDescription(std::ostringstream& desc) const;
|
||||
void GetDescription(llvm::raw_ostream& desc) const;
|
||||
|
||||
virtual void SetSpeed(double speed);
|
||||
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
#include "AnalogInput.h"
|
||||
#include "HAL/AnalogInput.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "HAL/AnalogAccumulator.h"
|
||||
#include "HAL/HAL.h"
|
||||
#include "HAL/Ports.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "Timer.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -30,7 +30,8 @@ const int AnalogInput::kAccumulatorChannels[] = {0, 1};
|
||||
* on-board 4-7 are on the MXP port.
|
||||
*/
|
||||
AnalogInput::AnalogInput(int channel) {
|
||||
std::stringstream buf;
|
||||
llvm::SmallString<32> str;
|
||||
llvm::raw_svector_ostream buf(str);
|
||||
buf << "Analog Input " << channel;
|
||||
|
||||
if (!SensorBase::CheckAnalogInputChannel(channel)) {
|
||||
|
||||
@@ -8,12 +8,13 @@
|
||||
#include "AnalogOutput.h"
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
#include "HAL/HAL.h"
|
||||
#include "HAL/Ports.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -25,8 +26,9 @@ using namespace frc;
|
||||
* @param channel The channel number on the roboRIO to represent.
|
||||
*/
|
||||
AnalogOutput::AnalogOutput(int channel) {
|
||||
std::stringstream buf;
|
||||
buf << "analog input " << channel;
|
||||
llvm::SmallString<32> str;
|
||||
llvm::raw_svector_ostream buf(str);
|
||||
buf << "analog output " << channel;
|
||||
|
||||
if (!SensorBase::CheckAnalogOutputChannel(channel)) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
|
||||
@@ -8,13 +8,14 @@
|
||||
#include "DigitalInput.h"
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
#include "HAL/DIO.h"
|
||||
#include "HAL/HAL.h"
|
||||
#include "HAL/Ports.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -26,7 +27,8 @@ using namespace frc;
|
||||
* @param channel The DIO channel 0-9 are on-board, 10-25 are on the MXP port
|
||||
*/
|
||||
DigitalInput::DigitalInput(int channel) {
|
||||
std::stringstream buf;
|
||||
llvm::SmallString<32> str;
|
||||
llvm::raw_svector_ostream buf(str);
|
||||
|
||||
if (!CheckDigitalChannel(channel)) {
|
||||
buf << "Digital Channel " << channel;
|
||||
|
||||
@@ -8,12 +8,13 @@
|
||||
#include "DigitalOutput.h"
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
#include "HAL/DIO.h"
|
||||
#include "HAL/HAL.h"
|
||||
#include "HAL/Ports.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -26,7 +27,8 @@ using namespace frc;
|
||||
* port
|
||||
*/
|
||||
DigitalOutput::DigitalOutput(int channel) {
|
||||
std::stringstream buf;
|
||||
llvm::SmallString<32> str;
|
||||
llvm::raw_svector_ostream buf(str);
|
||||
|
||||
m_pwmGenerator = HAL_kInvalidHandle;
|
||||
if (!CheckDigitalChannel(channel)) {
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
|
||||
#include "DoubleSolenoid.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "HAL/HAL.h"
|
||||
#include "HAL/Ports.h"
|
||||
#include "HAL/Solenoid.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -41,7 +41,8 @@ DoubleSolenoid::DoubleSolenoid(int moduleNumber, int forwardChannel,
|
||||
: SolenoidBase(moduleNumber),
|
||||
m_forwardChannel(forwardChannel),
|
||||
m_reverseChannel(reverseChannel) {
|
||||
std::stringstream buf;
|
||||
llvm::SmallString<32> str;
|
||||
llvm::raw_svector_ostream buf(str);
|
||||
if (!CheckSolenoidModule(m_moduleNumber)) {
|
||||
buf << "Solenoid Module " << m_moduleNumber;
|
||||
wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf.str());
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
#include "MotorSafetyHelper.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "DriverStation.h"
|
||||
#include "MotorSafety.h"
|
||||
#include "Timer.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -95,10 +95,11 @@ void MotorSafetyHelper::Check() {
|
||||
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
|
||||
if (m_stopTime < Timer::GetFPGATimestamp()) {
|
||||
std::ostringstream desc;
|
||||
llvm::SmallString<128> buf;
|
||||
llvm::raw_svector_ostream desc(buf);
|
||||
m_safeObject->GetDescription(desc);
|
||||
desc << "... Output not updated often enough.";
|
||||
wpi_setWPIErrorWithContext(Timeout, desc.str().c_str());
|
||||
wpi_setWPIErrorWithContext(Timeout, desc.str());
|
||||
m_safeObject->StopMotor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
#include "HAL/PWM.h"
|
||||
#include "PWM.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "HAL/HAL.h"
|
||||
#include "HAL/Ports.h"
|
||||
#include "Utility.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -28,7 +28,8 @@ using namespace frc;
|
||||
* MXP port
|
||||
*/
|
||||
PWM::PWM(int channel) {
|
||||
std::stringstream buf;
|
||||
llvm::SmallString<32> str;
|
||||
llvm::raw_svector_ostream buf(str);
|
||||
|
||||
if (!CheckPWMChannel(channel)) {
|
||||
buf << "PWM Channel " << channel;
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
|
||||
#include "PowerDistributionPanel.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "HAL/HAL.h"
|
||||
#include "HAL/PDP.h"
|
||||
#include "HAL/Ports.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -76,7 +76,8 @@ double PowerDistributionPanel::GetCurrent(int channel) const {
|
||||
int32_t status = 0;
|
||||
|
||||
if (!CheckPDPChannel(channel)) {
|
||||
std::stringstream buf;
|
||||
llvm::SmallString<32> str;
|
||||
llvm::raw_svector_ostream buf(str);
|
||||
buf << "PDP Channel " << channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
}
|
||||
|
||||
@@ -8,13 +8,12 @@
|
||||
#include "HAL/Relay.h"
|
||||
#include "Relay.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "HAL/HAL.h"
|
||||
#include "HAL/Ports.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "MotorSafetyHelper.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -29,7 +28,8 @@ using namespace frc;
|
||||
*/
|
||||
Relay::Relay(int channel, Relay::Direction direction)
|
||||
: m_channel(channel), m_direction(direction) {
|
||||
std::stringstream buf;
|
||||
llvm::SmallString<128> str;
|
||||
llvm::raw_svector_ostream buf(str);
|
||||
if (!SensorBase::CheckRelayChannel(m_channel)) {
|
||||
buf << "Relay Channel " << m_channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
@@ -268,7 +268,7 @@ bool Relay::IsSafetyEnabled() const {
|
||||
return m_safetyHelper->IsSafetyEnabled();
|
||||
}
|
||||
|
||||
void Relay::GetDescription(std::ostringstream& desc) const {
|
||||
void Relay::GetDescription(llvm::raw_ostream& desc) const {
|
||||
desc << "Relay " << GetChannel();
|
||||
}
|
||||
|
||||
|
||||
@@ -718,7 +718,7 @@ void RobotDrive::SetSafetyEnabled(bool enabled) {
|
||||
m_safetyHelper->SetSafetyEnabled(enabled);
|
||||
}
|
||||
|
||||
void RobotDrive::GetDescription(std::ostringstream& desc) const {
|
||||
void RobotDrive::GetDescription(llvm::raw_ostream& desc) const {
|
||||
desc << "RobotDrive";
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ bool SafePWM::IsSafetyEnabled() const {
|
||||
return m_safetyHelper->IsSafetyEnabled();
|
||||
}
|
||||
|
||||
void SafePWM::GetDescription(std::ostringstream& desc) const {
|
||||
void SafePWM::GetDescription(llvm::raw_ostream& desc) const {
|
||||
desc << "PWM " << GetChannel();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
#include "HAL/Solenoid.h"
|
||||
#include "Solenoid.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "HAL/HAL.h"
|
||||
#include "HAL/Ports.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -33,7 +33,8 @@ Solenoid::Solenoid(int channel)
|
||||
*/
|
||||
Solenoid::Solenoid(int moduleNumber, int channel)
|
||||
: SolenoidBase(moduleNumber), m_channel(channel) {
|
||||
std::stringstream buf;
|
||||
llvm::SmallString<32> str;
|
||||
llvm::raw_svector_ostream buf(str);
|
||||
if (!CheckSolenoidModule(m_moduleNumber)) {
|
||||
buf << "Solenoid Module " << m_moduleNumber;
|
||||
wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf.str());
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "HAL/DriverStation.h"
|
||||
#include "HAL/HAL.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -32,19 +32,21 @@ bool wpi_assert_impl(bool conditionValue, llvm::StringRef conditionText,
|
||||
llvm::StringRef message, llvm::StringRef fileName,
|
||||
int lineNumber, llvm::StringRef funcName) {
|
||||
if (!conditionValue) {
|
||||
std::stringstream locStream;
|
||||
llvm::SmallString<128> locBuf;
|
||||
llvm::raw_svector_ostream locStream(locBuf);
|
||||
locStream << funcName << " [";
|
||||
llvm::SmallString<128> fileTemp;
|
||||
locStream << basename(fileName.c_str(fileTemp)) << ":" << lineNumber << "]";
|
||||
|
||||
std::stringstream errorStream;
|
||||
llvm::SmallString<128> errorBuf;
|
||||
llvm::raw_svector_ostream errorStream(errorBuf);
|
||||
|
||||
errorStream << "Assertion \"" << conditionText << "\" ";
|
||||
|
||||
if (!message.empty()) {
|
||||
errorStream << "failed: " << message << std::endl;
|
||||
errorStream << "failed: " << message << "\n";
|
||||
} else {
|
||||
errorStream << "failed." << std::endl;
|
||||
errorStream << "failed.\n";
|
||||
}
|
||||
|
||||
std::string stack = GetStackTrace(2);
|
||||
@@ -68,20 +70,22 @@ void wpi_assertEqual_common_impl(llvm::StringRef valueA, llvm::StringRef valueB,
|
||||
llvm::StringRef message,
|
||||
llvm::StringRef fileName, int lineNumber,
|
||||
llvm::StringRef funcName) {
|
||||
std::stringstream locStream;
|
||||
llvm::SmallString<128> locBuf;
|
||||
llvm::raw_svector_ostream locStream(locBuf);
|
||||
locStream << funcName << " [";
|
||||
llvm::SmallString<128> fileTemp;
|
||||
locStream << basename(fileName.c_str(fileTemp)) << ":" << lineNumber << "]";
|
||||
|
||||
std::stringstream errorStream;
|
||||
llvm::SmallString<128> errorBuf;
|
||||
llvm::raw_svector_ostream errorStream(errorBuf);
|
||||
|
||||
errorStream << "Assertion \"" << valueA << " " << equalityType << " "
|
||||
<< valueB << "\" ";
|
||||
|
||||
if (!message.empty()) {
|
||||
errorStream << "failed: " << message << std::endl;
|
||||
errorStream << "failed: " << message << "\n";
|
||||
} else {
|
||||
errorStream << "failed." << std::endl;
|
||||
errorStream << "failed.\n";
|
||||
}
|
||||
|
||||
std::string trace = GetStackTrace(3);
|
||||
@@ -217,12 +221,13 @@ std::string GetStackTrace(int offset) {
|
||||
void* stackTrace[128];
|
||||
int stackSize = backtrace(stackTrace, 128);
|
||||
char** mangledSymbols = backtrace_symbols(stackTrace, stackSize);
|
||||
std::stringstream trace;
|
||||
llvm::SmallString<1024> buf;
|
||||
llvm::raw_svector_ostream trace(buf);
|
||||
|
||||
for (int i = offset; i < stackSize; i++) {
|
||||
// Only print recursive functions once in a row.
|
||||
if (i == 0 || stackTrace[i] != stackTrace[i - 1]) {
|
||||
trace << "\tat " << demangle(mangledSymbols[i]) << std::endl;
|
||||
trace << "\tat " << demangle(mangledSymbols[i]) << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
#include "Error.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "DriverStation.h"
|
||||
#include "Timer.h"
|
||||
#include "Utility.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -64,7 +64,8 @@ void Error::Set(Code code, llvm::StringRef contextMessage,
|
||||
}
|
||||
|
||||
void Error::Report() {
|
||||
std::stringstream locStream;
|
||||
llvm::SmallString<128> buf;
|
||||
llvm::raw_svector_ostream locStream(buf);
|
||||
locStream << m_function << " [";
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
#define WPI_ERRORS_DEFINE_STRINGS
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -83,7 +85,8 @@ void ErrorBase::SetImaqError(int success, llvm::StringRef contextMessage,
|
||||
int lineNumber) const {
|
||||
// If there was an error
|
||||
if (success <= 0) {
|
||||
std::stringstream err;
|
||||
llvm::SmallString<128> buf;
|
||||
llvm::raw_svector_ostream err(buf);
|
||||
err << success << ": " << contextMessage;
|
||||
|
||||
// Set the current error information for this object.
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
#include "networktables/NetworkTable.h"
|
||||
|
||||
using namespace frc;
|
||||
@@ -154,7 +155,8 @@ void LiveWindow::AddActuator(const std::string& subsystem,
|
||||
*/
|
||||
void LiveWindow::AddSensor(std::string type, int channel,
|
||||
LiveWindowSendable* component) {
|
||||
std::ostringstream oss;
|
||||
llvm::SmallString<128> buf;
|
||||
llvm::raw_svector_ostream oss(buf);
|
||||
oss << type << "[" << channel << "]";
|
||||
AddSensor("Ungrouped", oss.str(), component);
|
||||
std::shared_ptr<LiveWindowSendable> component_stl(
|
||||
@@ -169,7 +171,8 @@ void LiveWindow::AddSensor(std::string type, int channel,
|
||||
*/
|
||||
void LiveWindow::AddActuator(std::string type, int channel,
|
||||
LiveWindowSendable* component) {
|
||||
std::ostringstream oss;
|
||||
llvm::SmallString<128> buf;
|
||||
llvm::raw_svector_ostream oss(buf);
|
||||
oss << type << "[" << channel << "]";
|
||||
AddActuator("Ungrouped", oss.str(),
|
||||
std::shared_ptr<LiveWindowSendable>(component,
|
||||
@@ -181,7 +184,8 @@ void LiveWindow::AddActuator(std::string type, int channel,
|
||||
*/
|
||||
void LiveWindow::AddActuator(std::string type, int module, int channel,
|
||||
LiveWindowSendable* component) {
|
||||
std::ostringstream oss;
|
||||
llvm::SmallString<128> buf;
|
||||
llvm::raw_svector_ostream oss(buf);
|
||||
oss << type << "[" << module << "," << channel << "]";
|
||||
AddActuator("Ungrouped", oss.str(),
|
||||
std::shared_ptr<LiveWindowSendable>(component,
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#define DEFAULT_SAFETY_EXPIRATION 0.1
|
||||
|
||||
#include <sstream>
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -21,7 +21,7 @@ class MotorSafety {
|
||||
virtual void StopMotor() = 0;
|
||||
virtual void SetSafetyEnabled(bool enabled) = 0;
|
||||
virtual bool IsSafetyEnabled() const = 0;
|
||||
virtual void GetDescription(std::ostringstream& desc) const = 0;
|
||||
virtual void GetDescription(llvm::raw_ostream& desc) const = 0;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "MotorSafety.h"
|
||||
#include "SensorBase.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
#include "simulation/SimContinuousOutput.h"
|
||||
#include "tables/ITable.h"
|
||||
#include "tables/ITableListener.h"
|
||||
@@ -55,7 +56,7 @@ class Relay : public MotorSafety,
|
||||
void StopMotor() override;
|
||||
bool IsSafetyEnabled() const override;
|
||||
void SetSafetyEnabled(bool enabled) override;
|
||||
void GetDescription(std::ostringstream& desc) const override;
|
||||
void GetDescription(llvm::raw_ostream& desc) const override;
|
||||
|
||||
void ValueChanged(ITable* source, llvm::StringRef key,
|
||||
std::shared_ptr<nt::Value> value, bool isNew) override;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "ErrorBase.h"
|
||||
#include "MotorSafety.h"
|
||||
#include "MotorSafetyHelper.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -97,7 +98,7 @@ class RobotDrive : public MotorSafety, public ErrorBase {
|
||||
void StopMotor() override;
|
||||
bool IsSafetyEnabled() const override;
|
||||
void SetSafetyEnabled(bool enabled) override;
|
||||
void GetDescription(std::ostringstream& desc) const override;
|
||||
void GetDescription(llvm::raw_ostream& desc) const override;
|
||||
|
||||
protected:
|
||||
void InitRobotDrive();
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "MotorSafety.h"
|
||||
#include "MotorSafetyHelper.h"
|
||||
#include "PWM.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -34,7 +35,7 @@ class SafePWM : public PWM, public MotorSafety {
|
||||
void StopMotor();
|
||||
bool IsSafetyEnabled() const;
|
||||
void SetSafetyEnabled(bool enabled);
|
||||
void GetDescription(std::ostringstream& desc) const;
|
||||
void GetDescription(llvm::raw_ostream& desc) const;
|
||||
|
||||
virtual void SetSpeed(double speed);
|
||||
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
#include "AnalogGyro.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "Timer.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -34,9 +34,10 @@ const double AnalogGyro::kDefaultVoltsPerDegreePerSecond = 0.007;
|
||||
void AnalogGyro::InitAnalogGyro(int channel) {
|
||||
SetPIDSourceType(PIDSourceType::kDisplacement);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "analog/" << channel;
|
||||
impl = new SimGyro(ss.str());
|
||||
llvm::SmallString<128> buf;
|
||||
llvm::raw_svector_ostream oss(buf);
|
||||
oss << "analog/" << channel;
|
||||
impl = new SimGyro(oss.str());
|
||||
|
||||
LiveWindow::GetInstance()->AddSensor("AnalogGyro", channel, this);
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
#include "AnalogInput.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -20,9 +20,10 @@ using namespace frc;
|
||||
* @param channel The channel number to represent.
|
||||
*/
|
||||
AnalogInput::AnalogInput(int channel) : m_channel(channel) {
|
||||
std::stringstream ss;
|
||||
ss << "analog/" << channel;
|
||||
m_impl = new SimFloatInput(ss.str());
|
||||
llvm::SmallString<32> buf;
|
||||
llvm::raw_svector_ostream oss(buf);
|
||||
oss << "analog/" << channel;
|
||||
m_impl = new SimFloatInput(oss.str());
|
||||
|
||||
LiveWindow::GetInstance()->AddSensor("AnalogInput", channel, this);
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ using namespace frc;
|
||||
* @param channel The digital channel (1..14).
|
||||
*/
|
||||
DigitalInput::DigitalInput(int channel) : m_channel(channel) {
|
||||
std::stringstream ss;
|
||||
ss << "dio/" << channel;
|
||||
m_impl = new SimDigitalInput(ss.str());
|
||||
std::ostringstream oss;
|
||||
oss << "dio/" << channel;
|
||||
m_impl = new SimDigitalInput(oss.str());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -37,10 +39,11 @@ DoubleSolenoid::DoubleSolenoid(int moduleNumber, int forwardChannel,
|
||||
forwardChannel = channel;
|
||||
m_reversed = true;
|
||||
}
|
||||
std::stringstream ss;
|
||||
ss << "pneumatic/" << moduleNumber << "/" << forwardChannel << "/"
|
||||
<< moduleNumber << "/" << reverseChannel;
|
||||
m_impl = new SimContinuousOutput(ss.str());
|
||||
llvm::SmallString<32> buf;
|
||||
llvm::raw_svector_ostream oss(buf);
|
||||
oss << "pneumatic/" << moduleNumber << "/" << forwardChannel << "/"
|
||||
<< moduleNumber << "/" << reverseChannel;
|
||||
m_impl = new SimContinuousOutput(oss.str());
|
||||
|
||||
LiveWindow::GetInstance()->AddActuator("DoubleSolenoid", moduleNumber,
|
||||
forwardChannel, this);
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
#include "Encoder.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -52,9 +52,10 @@ void Encoder::InitEncoder(int channelA, int channelB, bool reverseDirection,
|
||||
} else {
|
||||
m_reverseDirection = reverseDirection;
|
||||
}
|
||||
std::stringstream ss;
|
||||
ss << "dio/" << channelA << "/" << channelB;
|
||||
impl = new SimEncoder(ss.str());
|
||||
llvm::SmallString<32> buf;
|
||||
llvm::raw_svector_ostream oss(buf);
|
||||
oss << "dio/" << channelA << "/" << channelB;
|
||||
impl = new SimEncoder(oss.str());
|
||||
impl->Start();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
#include "MotorSafetyHelper.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "DriverStation.h"
|
||||
#include "MotorSafety.h"
|
||||
#include "Timer.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -100,10 +100,11 @@ void MotorSafetyHelper::Check() {
|
||||
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
|
||||
if (m_stopTime < Timer::GetFPGATimestamp()) {
|
||||
std::ostringstream desc;
|
||||
llvm::SmallString<128> buf;
|
||||
llvm::raw_svector_ostream desc(buf);
|
||||
m_safeObject->GetDescription(desc);
|
||||
desc << "... Output not updated often enough.";
|
||||
wpi_setWPIErrorWithContext(Timeout, desc.str().c_str());
|
||||
wpi_setWPIErrorWithContext(Timeout, desc.str());
|
||||
m_safeObject->StopMotor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
#include "PWM.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "Utility.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -30,16 +30,17 @@ const int PWM::kPwmDisabled = 0;
|
||||
* port
|
||||
*/
|
||||
PWM::PWM(int channel) {
|
||||
std::stringstream ss;
|
||||
llvm::SmallString<32> buf;
|
||||
llvm::raw_svector_ostream oss(buf);
|
||||
|
||||
if (!CheckPWMChannel(channel)) {
|
||||
ss << "PWM Channel " << channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, ss.str());
|
||||
oss << "PWM Channel " << channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, oss.str());
|
||||
return;
|
||||
}
|
||||
|
||||
ss << "pwm/" << channel;
|
||||
impl = new SimContinuousOutput(ss.str());
|
||||
oss << "pwm/" << channel;
|
||||
impl = new SimContinuousOutput(oss.str());
|
||||
m_channel = channel;
|
||||
m_eliminateDeadband = false;
|
||||
|
||||
|
||||
@@ -7,11 +7,10 @@
|
||||
|
||||
#include "Relay.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "MotorSafetyHelper.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -26,21 +25,22 @@ using namespace frc;
|
||||
*/
|
||||
Relay::Relay(int channel, Relay::Direction direction)
|
||||
: m_channel(channel), m_direction(direction) {
|
||||
std::stringstream ss;
|
||||
llvm::SmallString<32> buf;
|
||||
llvm::raw_svector_ostream oss(buf);
|
||||
if (!SensorBase::CheckRelayChannel(m_channel)) {
|
||||
ss << "Relay Channel " << m_channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, ss.str());
|
||||
oss << "Relay Channel " << m_channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, oss.str());
|
||||
return;
|
||||
}
|
||||
|
||||
m_safetyHelper = std::make_unique<MotorSafetyHelper>(this);
|
||||
m_safetyHelper->SetSafetyEnabled(false);
|
||||
|
||||
ss << "relay/" << m_channel;
|
||||
impl = new SimContinuousOutput(ss.str()); // TODO: Allow two different relays
|
||||
// (targetting the different halves
|
||||
// of a relay) to be combined to
|
||||
// control one motor.
|
||||
oss << "relay/" << m_channel;
|
||||
|
||||
// TODO: Allow two different relays (targetting the different halves of a
|
||||
// relay) to be combined to control one motor.
|
||||
impl = new SimContinuousOutput(oss.str());
|
||||
LiveWindow::GetInstance()->AddActuator("Relay", 1, m_channel, this);
|
||||
go_pos = go_neg = false;
|
||||
}
|
||||
@@ -194,7 +194,7 @@ bool Relay::IsSafetyEnabled() const {
|
||||
return m_safetyHelper->IsSafetyEnabled();
|
||||
}
|
||||
|
||||
void Relay::GetDescription(std::ostringstream& desc) const {
|
||||
void Relay::GetDescription(llvm::raw_ostream& desc) const {
|
||||
desc << "Relay " << GetChannel();
|
||||
}
|
||||
|
||||
|
||||
@@ -715,7 +715,7 @@ void RobotDrive::SetSafetyEnabled(bool enabled) {
|
||||
// FIXME: m_safetyHelper->SetSafetyEnabled(enabled);
|
||||
}
|
||||
|
||||
void RobotDrive::GetDescription(std::ostringstream& desc) const {
|
||||
void RobotDrive::GetDescription(llvm::raw_ostream& desc) const {
|
||||
desc << "RobotDrive";
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "SafePWM.h"
|
||||
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -76,7 +75,7 @@ bool SafePWM::IsSafetyEnabled() const {
|
||||
return m_safetyHelper->IsSafetyEnabled();
|
||||
}
|
||||
|
||||
void SafePWM::GetDescription(std::ostringstream& desc) const {
|
||||
void SafePWM::GetDescription(llvm::raw_ostream& desc) const {
|
||||
desc << "PWM " << GetChannel();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
#include "Solenoid.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
#include "simulation/simTime.h"
|
||||
|
||||
using namespace frc;
|
||||
@@ -29,9 +29,10 @@ Solenoid::Solenoid(int channel) : Solenoid(1, channel) {}
|
||||
* @param channel The channel on the solenoid module to control (1..8).
|
||||
*/
|
||||
Solenoid::Solenoid(int moduleNumber, int channel) {
|
||||
std::stringstream ss;
|
||||
ss << "pneumatic/" << moduleNumber << "/" << channel;
|
||||
m_impl = new SimContinuousOutput(ss.str());
|
||||
llvm::SmallString<32> buf;
|
||||
llvm::raw_svector_ostream oss(buf);
|
||||
oss << "pneumatic/" << moduleNumber << "/" << channel;
|
||||
m_impl = new SimContinuousOutput(oss.str());
|
||||
|
||||
LiveWindow::GetInstance()->AddActuator("Solenoid", moduleNumber, channel,
|
||||
this);
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "Timer.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
#include "simulation/simTime.h"
|
||||
|
||||
using namespace frc;
|
||||
@@ -61,7 +61,8 @@ bool wpi_assert_impl(bool conditionValue, llvm::StringRef conditionText,
|
||||
llvm::StringRef message, llvm::StringRef fileName,
|
||||
int lineNumber, llvm::StringRef funcName) {
|
||||
if (!conditionValue) {
|
||||
std::stringstream errorStream;
|
||||
llvm::SmallString<1024> errorBuf;
|
||||
llvm::raw_svector_ostream errorStream(errorBuf);
|
||||
|
||||
errorStream << "Assertion \"" << conditionText << "\" ";
|
||||
errorStream << "on line " << lineNumber << " ";
|
||||
@@ -70,9 +71,9 @@ bool wpi_assert_impl(bool conditionValue, llvm::StringRef conditionText,
|
||||
errorStream << "of " << basename(fileName.c_str(fileTemp)) << " ";
|
||||
|
||||
if (!message.empty()) {
|
||||
errorStream << "failed: " << message << std::endl;
|
||||
errorStream << "failed: " << message << "\n";
|
||||
} else {
|
||||
errorStream << "failed." << std::endl;
|
||||
errorStream << "failed.\n";
|
||||
}
|
||||
|
||||
// Print to console and send to remote dashboard
|
||||
@@ -94,7 +95,8 @@ void wpi_assertEqual_common_impl(int valueA, int valueB,
|
||||
llvm::StringRef fileName, int lineNumber,
|
||||
llvm::StringRef funcName) {
|
||||
// Error string buffer
|
||||
std::stringstream error;
|
||||
llvm::SmallString<1024> buf;
|
||||
llvm::raw_svector_ostream error(buf);
|
||||
|
||||
// If an error message was specified, include it
|
||||
// Build error string
|
||||
@@ -192,12 +194,13 @@ std::string GetStackTrace(int offset) {
|
||||
void* stackTrace[128];
|
||||
int stackSize = backtrace(stackTrace, 128);
|
||||
char** mangledSymbols = backtrace_symbols(stackTrace, stackSize);
|
||||
std::stringstream trace;
|
||||
llvm::SmallString<1024> buf;
|
||||
llvm::raw_svector_ostream trace(buf);
|
||||
|
||||
for (int i = offset; i < stackSize; i++) {
|
||||
// Only print recursive functions once in a row.
|
||||
if (i == 0 || stackTrace[i] != stackTrace[i - 1]) {
|
||||
trace << "\tat " << demangle(mangledSymbols[i]) << std::endl;
|
||||
trace << "\tat " << demangle(mangledSymbols[i]) << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,13 +7,14 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <jni.h>
|
||||
#include "HAL/cpp/Log.h"
|
||||
|
||||
#include "edu_wpi_first_wpilibj_can_CANJNI.h"
|
||||
|
||||
#include "FRC_NetworkCommunication/CANSessionMux.h"
|
||||
#include "HAL/CAN.h"
|
||||
#include "HAL/cpp/Log.h"
|
||||
#include "HALUtil.h"
|
||||
#include "edu_wpi_first_wpilibj_can_CANJNI.h"
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/raw_ostream.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -44,14 +45,15 @@ Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetCommCANSessionMuxSendMessage(
|
||||
(uint8_t *)(data ? env->GetDirectBufferAddress(data) : 0);
|
||||
uint8_t dataSize = (uint8_t)(data ? env->GetDirectBufferCapacity(data) : 0);
|
||||
|
||||
CANJNI_LOG(logDEBUG) << "Message ID " << std::hex << messageID;
|
||||
CANJNI_LOG(logDEBUG) << "Message ID ";
|
||||
CANJNI_LOG(logDEBUG).write_hex(messageID);
|
||||
|
||||
if (logDEBUG <= canJNILogLevel) {
|
||||
if (dataBuffer) {
|
||||
std::ostringstream str;
|
||||
str << std::setfill('0') << std::hex;
|
||||
llvm::SmallString<128> buf;
|
||||
llvm::raw_svector_ostream str(buf);
|
||||
for (int32_t i = 0; i < dataSize; i++) {
|
||||
str << std::setw(2) << (int)dataBuffer[i] << ' ';
|
||||
str.write_hex(dataBuffer[i]) << ' ';
|
||||
}
|
||||
|
||||
Log().Get(logDEBUG) << "Data: " << str.str();
|
||||
@@ -93,13 +95,20 @@ Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetCommCANSessionMuxReceiveMessage(
|
||||
FRC_NetworkCommunication_CANSessionMux_receiveMessage(
|
||||
messageIDPtr, messageIDMask, buffer, &dataSize, timeStampPtr, &status);
|
||||
|
||||
CANJNI_LOG(logDEBUG) << "Message ID " << std::hex << *messageIDPtr;
|
||||
CANJNI_LOG(logDEBUG) << "Message ID ";
|
||||
CANJNI_LOG(logDEBUG).write_hex(*messageIDPtr);
|
||||
|
||||
if (logDEBUG <= canJNILogLevel) {
|
||||
std::ostringstream str;
|
||||
str << std::setfill('0') << std::hex;
|
||||
llvm::SmallString<128> buf;
|
||||
llvm::raw_svector_ostream str(buf);
|
||||
|
||||
for (int32_t i = 0; i < dataSize; i++) {
|
||||
str << std::setw(2) << (int)buffer[i] << ' ';
|
||||
// Pad one-digit data with a zero
|
||||
if (buffer[i] <= 16) {
|
||||
str << '0';
|
||||
}
|
||||
|
||||
str.write_hex(buffer[i]) << ' ';
|
||||
}
|
||||
|
||||
Log().Get(logDEBUG) << "Data: " << str.str();
|
||||
|
||||
@@ -59,20 +59,21 @@ namespace frc {
|
||||
void ThrowAllocationException(JNIEnv *env, int32_t minRange, int32_t maxRange,
|
||||
int32_t requestedValue, int32_t status) {
|
||||
const char *message = HAL_GetErrorMessage(status);
|
||||
char *buf = new char[strlen(message) + 100];
|
||||
sprintf(buf,
|
||||
" Code: $%d. %s, Minimum Value: %d, Maximum Value: %d, Requested Value: %d",
|
||||
status, message, minRange, maxRange, requestedValue);
|
||||
allocationExCls.Throw(env, buf);
|
||||
delete[] buf;
|
||||
llvm::SmallString<1024> buf;
|
||||
llvm::raw_svector_ostream oss(buf);
|
||||
oss << " Code: " << status << ". " << message << ", Minimum Value: "
|
||||
<< minRange << ", Maximum Value: " << maxRange << ", Requested Value: "
|
||||
<< requestedValue;
|
||||
env->ThrowNew(allocationExCls, buf.c_str());
|
||||
allocationExCls.Throw(env, buf.c_str());
|
||||
}
|
||||
|
||||
void ThrowHalHandleException(JNIEnv *env, int32_t status) {
|
||||
const char *message = HAL_GetErrorMessage(status);
|
||||
char *buf = new char[strlen(message) + 30];
|
||||
sprintf(buf, " Code: $%d. %s", status, message);
|
||||
halHandleExCls.Throw(env, buf);
|
||||
delete[] buf;
|
||||
llvm::SmallString<1024> buf;
|
||||
llvm::raw_svector_ostream oss(buf);
|
||||
oss << " Code: " << status << ". " << message;
|
||||
halHandleExCls.Throw(env, buf.c_str());
|
||||
}
|
||||
|
||||
constexpr const char wpilibjPrefix[] = "edu.wpi.first.wpilibj";
|
||||
@@ -84,10 +85,10 @@ void ReportError(JNIEnv *env, int32_t status, bool do_throw) {
|
||||
}
|
||||
const char *message = HAL_GetErrorMessage(status);
|
||||
if (do_throw && status < 0) {
|
||||
char *buf = new char[strlen(message) + 30];
|
||||
sprintf(buf, " Code: %d. %s", status, message);
|
||||
runtimeExCls.Throw(env, buf);
|
||||
delete[] buf;
|
||||
llvm::SmallString<1024> buf;
|
||||
llvm::raw_svector_ostream oss(buf);
|
||||
oss << " Code: " << status << ". " << message;
|
||||
runtimeExCls.Throw(env, buf.c_str());
|
||||
} else {
|
||||
std::string func;
|
||||
auto stack = GetJavaStackTrace<wpilibjPrefix>(env, &func);
|
||||
@@ -107,10 +108,10 @@ void ThrowError(JNIEnv *env, int32_t status, int32_t minRange, int32_t maxRange,
|
||||
ThrowHalHandleException(env, status);
|
||||
}
|
||||
const char *message = HAL_GetErrorMessage(status);
|
||||
char *buf = new char[strlen(message) + 30];
|
||||
sprintf(buf, " Code: %d. %s", status, message);
|
||||
runtimeExCls.Throw(env, buf);
|
||||
delete[] buf;
|
||||
llvm::SmallString<1024> buf;
|
||||
llvm::raw_svector_ostream oss(buf);
|
||||
oss << " Code: " << status << ". " << message;
|
||||
runtimeExCls.Throw(env, buf.c_str());
|
||||
}
|
||||
|
||||
void ReportCANError(JNIEnv *env, int32_t status, int message_id) {
|
||||
@@ -143,9 +144,10 @@ void ReportCANError(JNIEnv *env, int32_t status, int message_id) {
|
||||
}
|
||||
case ERR_CANSessionMux_NotAllowed:
|
||||
case kRIOStatusFeatureNotSupported: {
|
||||
char buf[100];
|
||||
sprintf(buf, "MessageID = %d", message_id);
|
||||
canMessageNotAllowedExCls.Throw(env, buf);
|
||||
llvm::SmallString<100> buf;
|
||||
llvm::raw_svector_ostream oss(buf);
|
||||
oss << "MessageID = " << message_id;
|
||||
canMessageNotAllowedExCls.Throw(env, buf.c_str());
|
||||
break;
|
||||
}
|
||||
case ERR_CANSessionMux_NotInitialized:
|
||||
@@ -160,9 +162,10 @@ void ReportCANError(JNIEnv *env, int32_t status, int message_id) {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
char buf[100];
|
||||
sprintf(buf, "Fatal status code detected: %d", status);
|
||||
uncleanStatusExCls.Throw(env, buf);
|
||||
llvm::SmallString<100> buf;
|
||||
llvm::raw_svector_ostream oss(buf);
|
||||
oss << "Fatal status code detected: " << status;
|
||||
uncleanStatusExCls.Throw(env, buf.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user