Skip to content

Commit

Permalink
fix var hides class member, this-> in constructors
Browse files Browse the repository at this point in the history
- fix few compile warn 'ex' unreferenced local variable
- rename setBusId() param to not hide class member
- refactor XLinkConnection constructors
- partial fix luxonis#247
  • Loading branch information
diablodale committed Mar 18, 2023
1 parent c2b96c8 commit 5db9896
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 72 deletions.
4 changes: 1 addition & 3 deletions examples/FeatureTracker/feature_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ class FeatureTrackerDrawer {
}
}

FeatureTrackerDrawer(std::string trackbarName, std::string windowName) {
this->trackbarName = trackbarName;
this->windowName = windowName;
FeatureTrackerDrawer(std::string trackbarName, std::string windowName) : trackbarName(trackbarName), windowName(windowName) {
cv::namedWindow(windowName.c_str());
cv::createTrackbar(trackbarName.c_str(), windowName.c_str(), &trackedFeaturesPathLength, maxTrackedFeaturesPathLength, nullptr);
}
Expand Down
4 changes: 2 additions & 2 deletions include/depthai/pipeline/node/SPIOut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class SPIOut : public NodeCRTP<Node, SPIOut, SPIOutProperties> {
* Specifies SPI Bus number to use
* @param id SPI Bus id
*/
void setBusId(int id) {
properties.busId = id;
void setBusId(int busId) {
properties.busId = busId;
}
};

Expand Down
5 changes: 1 addition & 4 deletions include/depthai/utility/LockingQueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ template <typename T>
class LockingQueue {
public:
LockingQueue() = default;
explicit LockingQueue(unsigned maxSize, bool blocking = true) {
this->maxSize = maxSize;
this->blocking = blocking;
}
explicit LockingQueue(unsigned maxSize, bool blocking = true) : maxSize(maxSize), blocking(blocking) {}

void setMaxSize(unsigned sz) {
// Lock first
Expand Down
4 changes: 2 additions & 2 deletions src/device/CalibrationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ CalibrationHandler::CalibrationHandler(dai::Path calibrationDataPath, dai::Path
camera.extrinsics.rotationMatrix[2][1] = temp;
}

CalibrationHandler::CalibrationHandler(EepromData eepromData) {
this->eepromData = eepromData;
CalibrationHandler::CalibrationHandler(EepromData newEepromData) {
eepromData = newEepromData;
}

dai::EepromData CalibrationHandler::getEepromData() const {
Expand Down
10 changes: 5 additions & 5 deletions src/device/DeviceBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ dai::Version DeviceBase::getIMUFirmwareVersion() {
try {
dai::Version version = dai::Version(versionStr);
return version;
} catch(const std::exception& ex) {
} catch(const std::exception&) {
dai::Version version = dai::Version(0, 0, 0);
return version;
}
Expand All @@ -844,7 +844,7 @@ dai::Version DeviceBase::getEmbeddedIMUFirmwareVersion() {
try {
dai::Version version = dai::Version(versionStr);
return version;
} catch(const std::exception& ex) {
} catch(const std::exception&) {
dai::Version version = dai::Version(0, 0, 0);
return version;
}
Expand Down Expand Up @@ -1086,7 +1086,7 @@ bool DeviceBase::isEepromAvailable() {
bool DeviceBase::flashCalibration(CalibrationHandler calibrationDataHandler) {
try {
flashCalibration2(calibrationDataHandler);
} catch(const EepromError& ex) {
} catch(const EepromError&) {
return false;
}
return true;
Expand Down Expand Up @@ -1118,7 +1118,7 @@ CalibrationHandler DeviceBase::readCalibration() {
dai::EepromData eepromData{};
try {
return readCalibration2();
} catch(const EepromError& ex) {
} catch(const EepromError&) {
// ignore - use default
}
return CalibrationHandler(eepromData);
Expand Down Expand Up @@ -1182,7 +1182,7 @@ CalibrationHandler DeviceBase::readFactoryCalibrationOrDefault() {
dai::EepromData eepromData{};
try {
return readFactoryCalibration();
} catch(const EepromError& ex) {
} catch(const EepromError&) {
// ignore - use default
}
return CalibrationHandler(eepromData);
Expand Down
18 changes: 9 additions & 9 deletions src/device/DeviceBootloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,9 @@ std::tuple<bool, std::string> DeviceBootloader::flashDepthaiApplicationPackage(s
std::vector<uint8_t> package,
Memory memory) {
// Bug in NETWORK bootloader in version 0.0.12 < 0.0.14 - flashing can cause a soft brick
auto version = getVersion();
if(bootloaderType == Type::NETWORK && version < Version(0, 0, 14)) {
throw std::invalid_argument("Network bootloader requires version 0.0.14 or higher to flash applications. Current version: " + version.toString());
auto bootloaderVersion = getVersion();
if(bootloaderType == Type::NETWORK && bootloaderVersion < Version(0, 0, 14)) {
throw std::invalid_argument("Network bootloader requires version 0.0.14 or higher to flash applications. Current version: " + bootloaderVersion.toString());
}

std::tuple<bool, std::string> ret;
Expand Down Expand Up @@ -1102,8 +1102,8 @@ std::tuple<bool, std::string> DeviceBootloader::flashCustom(
std::vector<uint8_t> optFileData;
if(!filename.empty()) {
// Read file into memory first
std::ifstream stream(filename, std::ios::in | std::ios::binary);
optFileData = std::vector<std::uint8_t>(std::istreambuf_iterator<char>(stream), {});
std::ifstream optFile(filename, std::ios::in | std::ios::binary);
optFileData = std::vector<std::uint8_t>(std::istreambuf_iterator<char>(optFile), {});
data = optFileData.data();
size = optFileData.size();
}
Expand All @@ -1125,17 +1125,17 @@ std::tuple<bool, std::string> DeviceBootloader::flashCustom(
result.success = 0; // TODO remove these inits after fix https://github.com/luxonis/depthai-bootloader-shared/issues/4
result.errorMsg[0] = 0;
do {
std::vector<uint8_t> data;
if(!receiveResponseData(data)) return {false, "Couldn't receive bootloader response"};
std::vector<uint8_t> responseData;
if(!receiveResponseData(responseData)) return {false, "Couldn't receive bootloader response"};

Response::FlashStatusUpdate update;
if(parseResponse(data, update)) {
if(parseResponse(responseData, update)) {
// if progress callback is set
if(progressCb != nullptr) {
progressCb(update.progress);
}
// if flash complete response arrived, break from while loop
} else if(parseResponse(data, result)) {
} else if(parseResponse(responseData, result)) {
break;
} else {
// Unknown response, shouldn't happen
Expand Down
14 changes: 7 additions & 7 deletions src/pipeline/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ void Node::Output::unlink(const Input& in) {
parent.getParentPipeline().unlink(*this, in);
}

void Node::Input::setBlocking(bool blocking) {
this->blocking = blocking;
void Node::Input::setBlocking(bool newBlocking) {
blocking = newBlocking;
}

bool Node::Input::getBlocking() const {
Expand All @@ -103,7 +103,7 @@ bool Node::Input::getBlocking() const {
}

void Node::Input::setQueueSize(int size) {
this->queueSize = size;
queueSize = size;
}

int Node::Input::getQueueSize() const {
Expand All @@ -113,16 +113,16 @@ int Node::Input::getQueueSize() const {
return defaultQueueSize;
}

void Node::Input::setWaitForMessage(bool waitForMessage) {
this->waitForMessage = waitForMessage;
void Node::Input::setWaitForMessage(bool newWaitForMessage) {
waitForMessage = newWaitForMessage;
}

bool Node::Input::getWaitForMessage() const {
return waitForMessage.value_or(defaultWaitForMessage);
}

void Node::Input::setReusePreviousMessage(bool waitForMessage) {
this->waitForMessage = !waitForMessage;
void Node::Input::setReusePreviousMessage(bool reusePreviousMessage) {
waitForMessage = !reusePreviousMessage;
}

bool Node::Input::getReusePreviousMessage() const {
Expand Down
8 changes: 4 additions & 4 deletions src/pipeline/Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ Pipeline Pipeline::clone() const {
return clone;
}

Pipeline::Pipeline(const std::shared_ptr<PipelineImpl>& pimpl) {
this->pimpl = pimpl;
Pipeline::Pipeline(const std::shared_ptr<PipelineImpl>& newPimpl) {
pimpl = newPimpl;
}

GlobalProperties Pipeline::getGlobalProperties() const {
Expand Down Expand Up @@ -304,8 +304,8 @@ void PipelineImpl::setXLinkChunkSize(int sizeBytes) {
globalProperties.xlinkChunkSize = sizeBytes;
}

void PipelineImpl::setBoardConfig(BoardConfig board) {
this->board = board;
void PipelineImpl::setBoardConfig(BoardConfig boardCfg) {
board = boardCfg;
}

BoardConfig PipelineImpl::getBoardConfig() const {
Expand Down
18 changes: 9 additions & 9 deletions src/pipeline/node/ColorCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ std::string ColorCamera::getCamera() const {
}

// Set which color camera to use
void ColorCamera::setCamId(int64_t id) {
void ColorCamera::setCamId(int64_t camId) {
// cast to board socket
switch(id) {
switch(camId) {
case 0:
properties.boardSocket = CameraBoardSocket::RGB;
break;
Expand All @@ -66,7 +66,7 @@ void ColorCamera::setCamId(int64_t id) {
properties.boardSocket = CameraBoardSocket::CAM_D;
break;
default:
throw std::invalid_argument(fmt::format("CamId value: {} is invalid.", id));
throw std::invalid_argument(fmt::format("CamId value: {} is invalid.", camId));
break;
}
}
Expand Down Expand Up @@ -490,12 +490,12 @@ bool ColorCamera::getPreviewKeepAspectRatio() {
return properties.previewKeepAspectRatio;
}

void ColorCamera::setNumFramesPool(int raw, int isp, int preview, int video, int still) {
properties.numFramesPoolRaw = raw;
properties.numFramesPoolIsp = isp;
properties.numFramesPoolPreview = preview;
properties.numFramesPoolVideo = video;
properties.numFramesPoolStill = still;
void ColorCamera::setNumFramesPool(int numRaw, int numIsp, int numPreview, int numVideo, int numStill) {
properties.numFramesPoolRaw = numRaw;
properties.numFramesPoolIsp = numIsp;
properties.numFramesPoolPreview = numPreview;
properties.numFramesPoolVideo = numVideo;
properties.numFramesPoolStill = numStill;
}

void ColorCamera::setPreviewNumFramesPool(int num) {
Expand Down
6 changes: 3 additions & 3 deletions src/pipeline/node/MonoCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ std::string MonoCamera::getCamera() const {
}

// Set which color camera to use
void MonoCamera::setCamId(int64_t id) {
void MonoCamera::setCamId(int64_t camId) {
// cast to board socket
switch(id) {
switch(camId) {
case 0:
properties.boardSocket = CameraBoardSocket::RGB;
break;
Expand All @@ -58,7 +58,7 @@ void MonoCamera::setCamId(int64_t id) {
properties.boardSocket = CameraBoardSocket::CAM_D;
break;
default:
throw std::invalid_argument(fmt::format("CamId value: {} is invalid.", id));
throw std::invalid_argument(fmt::format("CamId value: {} is invalid.", camId));
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pipeline/node/NeuralNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void NeuralNetwork::setBlob(const dai::Path& path) {
}

void NeuralNetwork::setBlob(OpenVINO::Blob blob) {
this->networkOpenvinoVersion = blob.version;
networkOpenvinoVersion = blob.version;
auto asset = assetManager.set("__blob", std::move(blob.data));
properties.blobUri = asset->getRelativeUri();
properties.blobSize = static_cast<uint32_t>(asset->data.size());
Expand Down
4 changes: 2 additions & 2 deletions src/pipeline/node/SPIIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ void SPIIn::setStreamName(const std::string& name) {
properties.streamName = name;
}

void SPIIn::setBusId(int id) {
properties.busId = id;
void SPIIn::setBusId(int busId) {
properties.busId = busId;
}

void SPIIn::setMaxDataSize(std::uint32_t maxDataSize) {
Expand Down
1 change: 0 additions & 1 deletion src/utility/Initialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ bool initialize(const char* additionalInfo, bool installSignalHandler, void* jav
xlinkGlobalHandler.protocol = X_LINK_USB_VSC;
xlinkGlobalHandler.options = javavm;
auto status = XLinkInitialize(&xlinkGlobalHandler);
std::string errorMsg;
const auto ERROR_MSG_USB_TIP = fmt::format("If running in a container, make sure that the following is set: \"{}\"",
"-v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule='c 189:* rmw'");
if(X_LINK_SUCCESS != status) {
Expand Down
31 changes: 11 additions & 20 deletions src/xlink/XLinkConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,33 +277,24 @@ DeviceInfo XLinkConnection::bootBootloader(const DeviceInfo& deviceInfo) {
return DeviceInfo(foundDeviceDesc);
}

XLinkConnection::XLinkConnection(const DeviceInfo& deviceDesc, std::vector<std::uint8_t> mvcmdBinary, XLinkDeviceState_t expectedState) {
XLinkConnection::XLinkConnection(const DeviceInfo& deviceDesc, std::vector<std::uint8_t> mvcmdBinary, XLinkDeviceState_t expectedState)
: bootWithPath(false), mvcmd(std::move(mvcmdBinary)) {
initialize();

bootDevice = true;
bootWithPath = false;
this->mvcmd = std::move(mvcmdBinary);
initDevice(deviceDesc, expectedState);
}

XLinkConnection::XLinkConnection(const DeviceInfo& deviceDesc, dai::Path pathToMvcmd, XLinkDeviceState_t expectedState) {
XLinkConnection::XLinkConnection(const DeviceInfo& deviceDesc, dai::Path mvcmdPath, XLinkDeviceState_t expectedState) : pathToMvcmd(std::move(mvcmdPath)) {
initialize();

if(!pathToMvcmd.empty()) {
std::ifstream f(pathToMvcmd);
if(!f.good()) throw std::runtime_error("Error path doesn't exist. Note: Environment variables in path are not expanded. (E.g. '~', '$PATH').");
std::ifstream testStream(pathToMvcmd);
if(!testStream.good()) throw std::runtime_error("Error path doesn't exist. Note: Environment variables in path are not expanded. (E.g. '~', '$PATH').");
}
bootDevice = true;
bootWithPath = true;
this->pathToMvcmd = std::move(pathToMvcmd);
initDevice(deviceDesc, expectedState);
}

// Skip boot
XLinkConnection::XLinkConnection(const DeviceInfo& deviceDesc, XLinkDeviceState_t expectedState) {
XLinkConnection::XLinkConnection(const DeviceInfo& deviceDesc, XLinkDeviceState_t expectedState) : bootDevice(false) {
initialize();

bootDevice = false;
initDevice(deviceDesc, expectedState);
}

Expand All @@ -325,7 +316,7 @@ void XLinkConnection::close() {
constexpr auto BOOTUP_SEARCH = seconds(5);

if(deviceLinkId != -1 && rebootOnDestruction) {
auto tmp = deviceLinkId;
auto previousLinkId = deviceLinkId;

auto ret = XLinkResetRemoteTimeout(deviceLinkId, duration_cast<milliseconds>(RESET_TIMEOUT).count());
if(ret != X_LINK_SUCCESS) {
Expand All @@ -342,17 +333,17 @@ void XLinkConnection::close() {
auto t1 = steady_clock::now();
bool found = false;
do {
DeviceInfo tmp;
std::tie(found, tmp) = XLinkConnection::getDeviceByMxId(deviceInfo.getMxId(), X_LINK_ANY_STATE, false);
DeviceInfo rebootingDeviceInfo;
std::tie(found, rebootingDeviceInfo) = XLinkConnection::getDeviceByMxId(deviceInfo.getMxId(), X_LINK_ANY_STATE, false);
if(found) {
if(tmp.state == X_LINK_UNBOOTED || tmp.state == X_LINK_BOOTLOADER) {
if(rebootingDeviceInfo.state == X_LINK_UNBOOTED || rebootingDeviceInfo.state == X_LINK_BOOTLOADER) {
break;
}
}
} while(!found && steady_clock::now() - t1 < BOOTUP_SEARCH);
}

spdlog::debug("XLinkResetRemote of linkId: ({})", tmp);
spdlog::debug("XLinkResetRemote of linkId: ({})", previousLinkId);
}

closed = true;
Expand Down

0 comments on commit 5db9896

Please sign in to comment.