Skip to content

Commit

Permalink
Merge pull request #185 from luxonis/develop
Browse files Browse the repository at this point in the history
Release v2.8.0
  • Loading branch information
SzabolcsGergely authored Jul 23, 2021
2 parents bab310c + eaa9a12 commit 7d76a83
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 103 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if(WIN32)
endif()

# Create depthai project
project(depthai VERSION "2.7.2" LANGUAGES CXX C)
project(depthai VERSION "2.8.0" LANGUAGES CXX C)
get_directory_property(has_parent PARENT_DIRECTORY)
if(has_parent)
set(DEPTHAI_VERSION ${PROJECT_VERSION} PARENT_SCOPE)
Expand Down
2 changes: 1 addition & 1 deletion cmake/Depthai/DepthaiDeviceSideConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot")

# "full commit hash of device side binary"
set(DEPTHAI_DEVICE_SIDE_COMMIT "673983dd2b693f267cb3cb11a4247ec4a38a6508")
set(DEPTHAI_DEVICE_SIDE_COMMIT "c0a7810c9c1e7678ae65035b8f23d4cac6beb568")

# "version if applicable"
set(DEPTHAI_DEVICE_SIDE_VERSION "")
2 changes: 1 addition & 1 deletion examples/src/imu_rotation_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int main() {
rVvalues.j,
rVvalues.k,
rVvalues.real,
rVvalues.accuracy);
rVvalues.rotationVectorAccuracy);
}

int key = cv::waitKey(1);
Expand Down
9 changes: 0 additions & 9 deletions include/depthai/device/Device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
#include "depthai-shared/log/LogLevel.hpp"
#include "depthai-shared/log/LogMessage.hpp"

// libraries
#include "nanorpc/core/client.h"
#include "nanorpc/packer/nlohmann_msgpack.h"

namespace dai {

// Device (RAII), connects to device and maintains watchdog, timesync, ...
Expand Down Expand Up @@ -510,8 +506,6 @@ class Device {
void checkClosed() const;

std::shared_ptr<XLinkConnection> connection;
std::unique_ptr<nanorpc::core::client<nanorpc::packer::nlohmann_msgpack>> client;
std::mutex rpcMutex;
std::vector<uint8_t> patchedCmd;

DeviceInfo deviceInfo = {};
Expand Down Expand Up @@ -543,9 +537,6 @@ class Device {
std::thread loggingThread;
std::atomic<bool> loggingRunning{true};

// RPC stream
std::unique_ptr<XLinkStream> rpcStream;

// closed
std::atomic<bool> closed{false};

Expand Down
4 changes: 0 additions & 4 deletions include/depthai/device/DeviceBootloader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
#include "depthai/xlink/XLinkConnection.hpp"
#include "depthai/xlink/XLinkStream.hpp"

// libraries
#include "nanorpc/core/client.h"
#include "nanorpc/packer/nlohmann_msgpack.h"

// shared
#include "depthai-bootloader-shared/Memory.hpp"
#include "depthai-bootloader-shared/Section.hpp"
Expand Down
2 changes: 1 addition & 1 deletion include/depthai/openvino/OpenVINO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace dai {
class OpenVINO {
public:
/// OpenVINO Version supported version information
enum Version { VERSION_2020_1, VERSION_2020_2, VERSION_2020_3, VERSION_2020_4, VERSION_2021_1, VERSION_2021_2, VERSION_2021_3 };
enum Version { VERSION_2020_3, VERSION_2020_4, VERSION_2021_1, VERSION_2021_2, VERSION_2021_3, VERSION_2021_4 };

/**
* @returns Supported versions
Expand Down
2 changes: 1 addition & 1 deletion include/depthai/pipeline/Pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class PipelineImpl {
// Pipeline asset manager
AssetManager assetManager;
// Default version
constexpr static auto DEFAULT_OPENVINO_VERSION = OpenVINO::Version::VERSION_2021_3;
constexpr static auto DEFAULT_OPENVINO_VERSION = OpenVINO::Version::VERSION_2021_4;
// Optionally forced version
tl::optional<OpenVINO::Version> forceRequiredOpenVINOVersion;
// Global pipeline properties
Expand Down
18 changes: 12 additions & 6 deletions include/depthai/pipeline/datatype/ImgFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,38 @@ class ImgFrame : public Buffer {

// getters
/**
* Retrievies image timestamp related to steady_clock / time.monotonic
* Retrieves image timestamp related to steady_clock / time.monotonic
*/
std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> getTimestamp() const;

/**
* Retrievies instance number
* Retrieves image timestamp directly captured from device's monotonic clock,
* not synchronized to host time. Used mostly for debugging
*/
std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> getTimestampDevice() const;

/**
* Retrieves instance number
*/
unsigned int getInstanceNum() const;

/**
* Retrievies image category
* Retrieves image category
*/
unsigned int getCategory() const;

/**
* Retrievies image sequence number
* Retrieves image sequence number
*/
unsigned int getSequenceNum() const;

/**
* Retrievies image width in pixels
* Retrieves image width in pixels
*/
unsigned int getWidth() const;

/**
* Retrievies image height in pixels
* Retrieves image height in pixels
*/
unsigned int getHeight() const;

Expand Down
74 changes: 41 additions & 33 deletions src/device/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "utility/Resources.hpp"

// libraries
#include "nanorpc/core/client.h"
#include "nanorpc/packer/nlohmann_msgpack.h"
#include "spdlog/fmt/chrono.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/spdlog.h"
Expand Down Expand Up @@ -187,6 +189,11 @@ class Device::Impl {
// Device Logger
DeviceLogger logger{"", stdoutColorSink};

// RPC
std::mutex rpcMutex;
std::unique_ptr<XLinkStream> rpcStream;
std::unique_ptr<nanorpc::core::client<nanorpc::packer::nlohmann_msgpack>> rpcClient;

void setLogLevel(LogLevel level);
LogLevel getLogLevel();
void setPattern(const std::string& pattern);
Expand Down Expand Up @@ -358,7 +365,7 @@ void Device::close() {
if(loggingThread.joinable()) loggingThread.join();

// Close rpcStream
rpcStream = nullptr;
pimpl->rpcStream = nullptr;

spdlog::debug("Device closed, {}", duration_cast<milliseconds>(steady_clock::now() - t1).count());
}
Expand Down Expand Up @@ -518,31 +525,32 @@ void Device::init2(bool embeddedMvcmd, bool usb2Mode, const std::string& pathToM
deviceInfo.state = X_LINK_BOOTED;

// prepare rpc for both attached and host controlled mode
rpcStream = std::make_unique<XLinkStream>(*connection, dai::XLINK_CHANNEL_MAIN_RPC, dai::XLINK_USB_BUFFER_MAX_SIZE);
pimpl->rpcStream = std::make_unique<XLinkStream>(*connection, dai::XLINK_CHANNEL_MAIN_RPC, dai::XLINK_USB_BUFFER_MAX_SIZE);

client = std::make_unique<nanorpc::core::client<nanorpc::packer::nlohmann_msgpack>>([this](nanorpc::core::type::buffer request) {
// TODO(TheMarpe) - causes issues on Windows
// std::unique_lock<std::mutex> lock(this->rpcMutex);
pimpl->rpcClient = std::make_unique<nanorpc::core::client<nanorpc::packer::nlohmann_msgpack>>([this](nanorpc::core::type::buffer request) {
// Lock for time of the RPC call, to not mix the responses between calling threads.
// Note: might cause issues on Windows on incorrect shutdown. To be investigated
std::unique_lock<std::mutex> lock(pimpl->rpcMutex);

// Log the request data
if(spdlog::get_level() == spdlog::level::trace) {
spdlog::trace("RPC: {}", nlohmann::json::from_msgpack(request).dump());
}

// Send request to device
rpcStream->write(std::move(request));
pimpl->rpcStream->write(std::move(request));

// Receive response back
// Send to nanorpc to parse
return rpcStream->read();
return pimpl->rpcStream->read();
});

// prepare watchdog thread, which will keep device alive
watchdogThread = std::thread([this]() {
std::shared_ptr<XLinkConnection> conn = this->connection;
while(watchdogRunning) {
try {
client->call("watchdogKeepalive");
pimpl->rpcClient->call("watchdogKeepalive");
} catch(const std::exception&) {
break;
}
Expand Down Expand Up @@ -845,80 +853,80 @@ std::string Device::getQueueEvent(std::chrono::microseconds timeout) {
std::string Device::getMxId() {
checkClosed();

return client->call("getMxId").as<std::string>();
return pimpl->rpcClient->call("getMxId").as<std::string>();
}

std::vector<CameraBoardSocket> Device::getConnectedCameras() {
checkClosed();

return client->call("getConnectedCameras").as<std::vector<CameraBoardSocket>>();
return pimpl->rpcClient->call("getConnectedCameras").as<std::vector<CameraBoardSocket>>();
}

// Convinience functions for querying current system information
MemoryInfo Device::getDdrMemoryUsage() {
checkClosed();

return client->call("getDdrUsage").as<MemoryInfo>();
return pimpl->rpcClient->call("getDdrUsage").as<MemoryInfo>();
}

MemoryInfo Device::getCmxMemoryUsage() {
checkClosed();

return client->call("getCmxUsage").as<MemoryInfo>();
return pimpl->rpcClient->call("getCmxUsage").as<MemoryInfo>();
}

MemoryInfo Device::getLeonCssHeapUsage() {
checkClosed();

return client->call("getLeonCssHeapUsage").as<MemoryInfo>();
return pimpl->rpcClient->call("getLeonCssHeapUsage").as<MemoryInfo>();
}

MemoryInfo Device::getLeonMssHeapUsage() {
checkClosed();

return client->call("getLeonMssHeapUsage").as<MemoryInfo>();
return pimpl->rpcClient->call("getLeonMssHeapUsage").as<MemoryInfo>();
}

ChipTemperature Device::getChipTemperature() {
checkClosed();

return client->call("getChipTemperature").as<ChipTemperature>();
return pimpl->rpcClient->call("getChipTemperature").as<ChipTemperature>();
}

CpuUsage Device::getLeonCssCpuUsage() {
checkClosed();

return client->call("getLeonCssCpuUsage").as<CpuUsage>();
return pimpl->rpcClient->call("getLeonCssCpuUsage").as<CpuUsage>();
}

CpuUsage Device::getLeonMssCpuUsage() {
checkClosed();

return client->call("getLeonMssCpuUsage").as<CpuUsage>();
return pimpl->rpcClient->call("getLeonMssCpuUsage").as<CpuUsage>();
}

UsbSpeed Device::getUsbSpeed() {
checkClosed();

return client->call("getUsbSpeed").as<UsbSpeed>();
return pimpl->rpcClient->call("getUsbSpeed").as<UsbSpeed>();
}

bool Device::isPipelineRunning() {
checkClosed();

return client->call("isPipelineRunning").as<bool>();
return pimpl->rpcClient->call("isPipelineRunning").as<bool>();
}

void Device::setLogLevel(LogLevel level) {
checkClosed();

client->call("setLogLevel", level);
pimpl->rpcClient->call("setLogLevel", level);
}

LogLevel Device::getLogLevel() {
checkClosed();

return client->call("getLogLevel").as<LogLevel>();
return pimpl->rpcClient->call("getLogLevel").as<LogLevel>();
}

DeviceInfo Device::getDeviceInfo() {
Expand Down Expand Up @@ -970,24 +978,24 @@ bool Device::removeLogCallback(int callbackId) {
void Device::setSystemInformationLoggingRate(float rateHz) {
checkClosed();

client->call("setSystemInformationLoggingRate", rateHz);
pimpl->rpcClient->call("setSystemInformationLoggingRate", rateHz);
}

float Device::getSystemInformationLoggingRate() {
checkClosed();

return client->call("getSystemInformationLoggingrate").as<float>();
return pimpl->rpcClient->call("getSystemInformationLoggingrate").as<float>();
}

bool Device::flashCalibration(CalibrationHandler calibrationDataHandler) {
if(!calibrationDataHandler.validateCameraArray()) {
throw std::runtime_error("Failed to validate the extrinsics connection. Enable debug mode for more information.");
}
return client->call("storeToEeprom", calibrationDataHandler.getEepromData()).as<bool>();
return pimpl->rpcClient->call("storeToEeprom", calibrationDataHandler.getEepromData()).as<bool>();
}

CalibrationHandler Device::readCalibration() {
dai::EepromData eepromData = client->call("readFromEeprom");
dai::EepromData eepromData = pimpl->rpcClient->call("readFromEeprom");
return CalibrationHandler(eepromData);
}

Expand Down Expand Up @@ -1068,14 +1076,14 @@ bool Device::startPipeline(const Pipeline& pipeline) {
}

// Load pipelineDesc, assets, and asset storage
client->call("setPipelineSchema", schema);
pimpl->rpcClient->call("setPipelineSchema", schema);

// Transfer storage != empty
if(!assetStorage.empty()) {
client->call("setAssets", assets);
pimpl->rpcClient->call("setAssets", assets);

// allocate, returns a pointer to memory on device side
auto memHandle = client->call("memAlloc", static_cast<std::uint32_t>(assetStorage.size())).as<uint32_t>();
auto memHandle = pimpl->rpcClient->call("memAlloc", static_cast<std::uint32_t>(assetStorage.size())).as<uint32_t>();

// Transfer the whole assetStorage in a separate thread
const std::string streamAssetStorage = "__stream_asset_storage";
Expand All @@ -1090,22 +1098,22 @@ bool Device::startPipeline(const Pipeline& pipeline) {
});

// Open a channel to transfer AssetStorage
client->call("readFromXLink", streamAssetStorage, memHandle, assetStorage.size());
pimpl->rpcClient->call("readFromXLink", streamAssetStorage, memHandle, assetStorage.size());
t1.join();

// After asset storage is transfers, set the asset storage
client->call("setAssetStorage", memHandle, assetStorage.size());
pimpl->rpcClient->call("setAssetStorage", memHandle, assetStorage.size());
}

// print assets on device side for test
client->call("printAssets");
pimpl->rpcClient->call("printAssets");

// Build and start the pipeline
bool success = false;
std::string errorMsg;
std::tie(success, errorMsg) = client->call("buildPipeline").as<std::tuple<bool, std::string>>();
std::tie(success, errorMsg) = pimpl->rpcClient->call("buildPipeline").as<std::tuple<bool, std::string>>();
if(success) {
client->call("startPipeline");
pimpl->rpcClient->call("startPipeline");
} else {
throw std::runtime_error(errorMsg);
return false;
Expand Down
Loading

0 comments on commit 7d76a83

Please sign in to comment.