Skip to content

get an active device's serial number? #548

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

Closed
svenevs opened this issue Feb 11, 2018 · 4 comments
Closed

get an active device's serial number? #548

svenevs opened this issue Feb 11, 2018 · 4 comments

Comments

@svenevs
Copy link

svenevs commented Feb 11, 2018

I'm using the C++ wrappers, so I have some class like

class Kinect360_Impl : public Freenect::FreenectDevice {
public:
    Kinect360_Impl(freenect_context *_ctx, int _index)
        : Freenect::FreenectDevice(_ctx, _index)
        , mCtx(_ctx)
        , mIndex(_index) {
        setDepthFormat(FREENECT_DEPTH_MM, FREENECT_RESOLUTION_MEDIUM);
    }

and could ideally emulate the loop here

libfreenect/src/core.c

Lines 194 to 199 in 83e57e1

for(item = attrlist ; item != NULL; item = item->next , index++) {
if (strlen(item->camera_serial) == strlen(camera_serial) && strcmp(item->camera_serial, camera_serial) == 0) {
freenect_free_device_attributes(attrlist);
return freenect_open_device(ctx, dev, index);
}
}

since I've stored both the index and the context, and instead of comparing strings, I'm actually just checking what index I'm at. But this is a hidden function

int count = fnusb_list_device_attributes(ctx, &attrlist);

so now I would need to start re-doing that code. Is there any way to do this differently, or is this the only option?

@svenevs svenevs changed the title more straightforward way of getting an active device's serial number? get an active device's serial number? Feb 11, 2018
@piedar
Copy link
Contributor

piedar commented Mar 6, 2018

I looked into this briefly, and it's not easy. It would be easy if we could always trust the camera serial, but we have to fall back on the audio serial for K4W devices.

@svenevs
Copy link
Author

svenevs commented Mar 18, 2018

I see. Out of curiosity, why is the fallback a problem? Is it that the audio serial is a different length or could possibly be a "duplicate" to a real Kinect serial number?

@piedar
Copy link
Contributor

piedar commented Mar 19, 2018

The audio serial itself works fine, but it's tough to get it to handle all edge cases. Like what if the caller asked to open MOTOR only? Unlikely, but it makes it more difficult to figure out which libusb_devices go with which freenect_device.

It appears we'd have to do another libusb query for the list of all devices and search through them to find the matching audio device, or try to do everything up-front when opening subdevices (which is rather brittle code already). It's also necessary to call libusb_open_device() before querying the serial, which opens another door for failure. My first attempt was complete spaghetti code.

But now that I think about it, it might work to add a libusb_device* usb_dev member to fnusb_dev. Then when opening subdevices we could always populate those entries, even if we're not actually going to open the associated device handles. (We'd also have to call libusb_ref_device() to make sure the pointers don't get freed when the list gets unrefed.) That at least solves the problem of which libusb devices go with the freenect device.

I don't have a lot of time to work on this, but I'll give it another go when I get a chance.

@piedar piedar added this to the v0.6.1 milestone Mar 19, 2018
@piedar
Copy link
Contributor

piedar commented Mar 23, 2018

Good news! Check out #554.

@piedar piedar closed this as completed Mar 23, 2018
@piedar piedar modified the milestones: v0.6.1, v0.6.0 Mar 23, 2018
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

No branches or pull requests

2 participants