Skip to content

Commit b539e7b

Browse files
author
Filippo Mutta
committed
Updated xlink and added test for Gate Write
1 parent 461e015 commit b539e7b

File tree

7 files changed

+52
-12
lines changed

7 files changed

+52
-12
lines changed

cmake/depthaiDependencies.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ else()
176176
FetchContent_Declare(
177177
XLink
178178
GIT_REPOSITORY https://github.com/luxonis/XLink.git
179-
GIT_TAG fdc7ca6699431bab598e366057274c9e215967c0
179+
GIT_TAG e519b8698d81722b05b389551e1038006198ef77
180180
)
181181

182182
FetchContent_MakeAvailable(

examples/cpp/Camera/camera_max_resolution.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ int main() {
2323
auto videoIn = videoQueue->get<dai::ImgFrame>();
2424
if(videoIn == nullptr) continue;
2525

26-
cv::imshow("video", videoIn->getCvFrame());
26+
videoIn->getCvFrame();
27+
std::cout << "Got frame" << std::endl;
28+
//cv::imshow("video", videoIn->getCvFrame());
2729

28-
if(cv::waitKey(1) == 'q') {
29-
break;
30-
}
30+
//if(cv::waitKey(1) == 'q') {
31+
// break;
32+
//}
3133
}
3234

3335
return 0;
34-
}
36+
}

examples/cpp/Camera/camera_output.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,22 @@ int main() {
1313

1414
// Create nodes
1515
auto cam = pipeline.create<dai::node::Camera>()->build();
16-
auto videoQueue = cam->requestOutput(std::make_pair(640, 400))->createOutputQueue();
16+
auto videoQueue = cam->requestOutput(std::make_pair(4096, 2160))->createOutputQueue();
17+
//auto videoQueue = cam->requestOutput(std::make_pair(2048, 1556))->createOutputQueue();
1718

1819
// Start pipeline
1920
pipeline.start();
2021

2122
while(true) {
2223
auto videoIn = videoQueue->get<dai::ImgFrame>();
2324
if(videoIn == nullptr) continue;
24-
25-
cv::imshow("video", videoIn->getCvFrame());
25+
videoIn->getCvFrame();
26+
/* cv::imshow("video", videoIn->getCvFrame());
2627
2728
if(cv::waitKey(1) == 'q') {
2829
break;
29-
}
30+
}*/
3031
}
3132

3233
return 0;
33-
}
34+
}

include/depthai/device/DeviceGate.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "depthai/device/Version.hpp"
1515
#include "depthai/utility/Pimpl.hpp"
1616
#include "depthai/xlink/XLinkConnection.hpp"
17+
#include "depthai/xlink/XLinkStream.hpp"
1718
namespace dai {
1819

1920
/**
@@ -65,6 +66,8 @@ class DeviceGate {
6566
std::atomic_bool sessionCreated{false};
6667

6768
XLinkPlatform_t platform;
69+
std::shared_ptr<XLinkConnection> gateConnection;
70+
std::shared_ptr<XLinkStream> gateStream;
6871
std::string version;
6972
// pimpl
7073
class Impl;

include/depthai/xlink/XLinkStream.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,14 @@ class XLinkStream {
9292
void write(long fd);
9393
void write(long fd, span<const uint8_t> data);
9494
void write(const void* data, std::size_t size);
95+
void writeGate(span<const uint8_t> data);
9596
std::vector<std::uint8_t> read();
9697
std::vector<std::uint8_t> read(XLinkTimespec& timestampReceived);
9798
void read(std::vector<std::uint8_t>& data);
9899
void read(std::vector<std::uint8_t>& data, long& fd);
99100
void read(std::vector<std::uint8_t>& data, XLinkTimespec& timestampReceived);
100101
void read(std::vector<std::uint8_t>& data, long& fd, XLinkTimespec& timestampReceived);
102+
void readGate(std::vector<std::uint8_t>& data);
101103
// split write helper
102104
void writeSplit(const void* data, std::size_t size, std::size_t split);
103105
void writeSplit(const std::vector<uint8_t>& data, std::size_t split);

src/device/DeviceGate.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ DeviceGate::DeviceGate(const DeviceInfo& deviceInfo) : deviceInfo(deviceInfo) {
4444
if(deviceInfo.platform != X_LINK_RVC3 && deviceInfo.platform != X_LINK_RVC4) {
4545
throw std::invalid_argument("Gate only supports RVC3 and RVC4 platforms");
4646
}
47-
this->platform = deviceInfo.platform;
47+
this->platform =deviceInfo.platform;
4848
if(deviceInfo.platform == X_LINK_RVC3) {
4949
version = DEPTHAI_DEVICE_RVC3_VERSION;
5050
} else if(deviceInfo.platform == X_LINK_RVC4) {
@@ -56,12 +56,27 @@ DeviceGate::DeviceGate(const DeviceInfo& deviceInfo) : deviceInfo(deviceInfo) {
5656
pimpl->cli = std::make_unique<httplib::Client>(deviceInfo.name, DEFAULT_PORT);
5757
pimpl->cli->set_read_timeout(60); // 60 seconds timeout to allow for compressing the crash dumps without async
5858
// pimpl->cli->set_connection_timeout(2);
59+
60+
gateConnection = std::make_shared<XLinkConnection>(deviceInfo, X_LINK_GATE);
61+
gateStream = std::make_shared<XLinkStream>(gateConnection, "XLink Gate Stream", 32 * 1024 * 1024);
62+
5963
}
6064

6165
bool DeviceGate::isOkay() {
6266
if(auto res = pimpl->cli->Get("/api/v1/status")) {
6367
return nlohmann::json::parse(res->body)["status"].get<bool>();
6468
}
69+
70+
struct request_t {
71+
uint16_t RequestNum;
72+
}__attribute__((packed));
73+
request_t request;
74+
request.RequestNum = 1;
75+
76+
span<const uint8_t> data;
77+
memcpy((char*)data.data(), &request, sizeof(request));
78+
gateStream->writeGate(data);
79+
6580
return false;
6681
}
6782

src/xlink/XLinkStream.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ void XLinkStream::write(long fd, span<const uint8_t> data) {
113113
}
114114
}
115115

116+
void XLinkStream::writeGate(span<const uint8_t> data) {
117+
auto status = XLinkGateWriteData(streamId, data.data(), static_cast<int>(data.size()));
118+
if(status != X_LINK_SUCCESS) {
119+
throw XLinkWriteError(status, streamName);
120+
}
121+
}
122+
123+
116124
void XLinkStream::read(std::vector<std::uint8_t>& data) {
117125
XLinkTimespec timestampReceived;
118126
read(data, timestampReceived);
@@ -158,6 +166,15 @@ std::vector<std::uint8_t> XLinkStream::read(XLinkTimespec& timestampReceived) {
158166
return data;
159167
}
160168

169+
void XLinkStream::readGate(std::vector<std::uint8_t>& data) {
170+
StreamPacketDesc packet;
171+
const auto status = XLinkReadMoveData(streamId, &packet);
172+
if(status != X_LINK_SUCCESS) {
173+
throw XLinkReadError(status, streamName);
174+
}
175+
data = std::vector<std::uint8_t>(packet.data, packet.data + packet.length);
176+
}
177+
161178
StreamPacketDesc XLinkStream::readMove() {
162179
StreamPacketDesc packet;
163180
const auto status = XLinkReadMoveData(streamId, &packet);

0 commit comments

Comments
 (0)