Skip to content

Depthai USB Support #1390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open

Depthai USB Support #1390

wants to merge 13 commits into from

Conversation

TheMutta
Copy link

Purpose

This branch adds the ability to Depthai to communicate with Gate via USB through XLink

Specification

All the API calls in the DepthaiGate class use USB communication if TCP/IP is not available
None / not applicable

Dependencies & Potential Impact

All the dependencies are already integrated in XLink

Deployment Plan

The changes don't affect the normal functioning via TCP/IP and don't break existing features, they can be rolled out easily.

Testing & Validation

The branch was tested by using all the API calls, which all completed successfully.

cursor[bot]

This comment was marked as outdated.

@TheMutta
Copy link
Author

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: USB Fallback Missing Error Handling

The createSession() USB fallback implementation in DeviceGate.cpp is missing an error check after reading the USB response header. Unlike other USB methods in the file, it does not verify request.RequestNum == RESPONSE_ERROR. This allows the code to proceed with memory allocation and JSON parsing using potentially invalid request.RequestSize or error data, which can lead to memory corruption, crashes, or incorrect behavior.

src/device/DeviceGate.cpp#L237-L244

XLinkPlatformGateRead(&request, sizeof(request));
char *respBuffer = new char[request.RequestSize + 1];
XLinkPlatformGateRead(respBuffer, request.RequestSize);
respBuffer[request.RequestSize]= '\0';
auto resp = nlohmann::json::parse(respBuffer);
delete[] respBuffer;
spdlog::debug("DeviceGate createSession response: {}", resp.dump());

Fix in CursorFix in Web


Bug: USB Firmware Upload Fails JSON Binary Handling

The USB communication path incorrectly embeds the firmware package (a std::vector<uint8_t>) directly into a JSON object. Unlike the HTTP path which uses multipart form data for binary uploads, JSON does not natively support raw binary data. This format mismatch will prevent the server from correctly processing the firmware package.

src/device/DeviceGate.cpp#L260-L266

nlohmann::json uploadFwpBody = {{"sessionId", sessionId},
{"file", package}};
request.RequestNum = UPLOAD_FWP;
request.RequestSize = uploadFwpBody.dump().size();
XLinkPlatformGateWrite(&request, sizeof(USBRequest_t));
XLinkPlatformGateWrite((void*)uploadFwpBody.dump().c_str(), uploadFwpBody.dump().size());

Fix in CursorFix in Web


Comment bugbot run to trigger another review on this PR
Was this report helpful? Give feedback by reacting with 👍 or 👎

@TheMutta TheMutta changed the base branch from v3_develop to develop July 18, 2025 10:41
return false;
}

char *respBuffer = new char[request.RequestSize + 1];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets use C++ here - eg a vector /w reserve or resize and pass its "data()" to XLink to not have to manually new & delete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants