Skip to content

feat: extend discovery for realsense cameras#262

Closed
ChristianDarr-personal wants to merge 27 commits intoedgexfoundry:mainfrom
EdgeX-Camera-Management:extend-discovery
Closed

feat: extend discovery for realsense cameras#262
ChristianDarr-personal wants to merge 27 commits intoedgexfoundry:mainfrom
EdgeX-Camera-Management:extend-discovery

Conversation

@ChristianDarr-personal
Copy link
Copy Markdown
Contributor

@ChristianDarr-personal ChristianDarr-personal commented Jun 21, 2023

If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/edgex-go/blob/main/.github/Contributing.md

PR Checklist

Please check if your PR fulfills the following requirements:

  • I am not introducing a breaking change (if you are, flag in conventional commit message with BREAKING CHANGE: describing the break)
  • I am not introducing a new dependency (add notes below if you are)
  • I have added unit tests for the new feature or bug fix (if not, why?)
  • I have fully tested (add details below) this the new feature or bug fix (if not, why?)
  • I have opened a PR for the related docs change (if not, why?)

Testing Instructions

  1. Make sure a realsense camera is plugged into your device.
  2. Use v4l2-ctl --list-devices to check that the device is recognized by your system and to check the paths of the device.
  3. Build the usb device service using make docker.
  4. Run the edgex core services along with the device service.
  5. Check the discovered devices (http://0.0.0.0:59881/api/v3/device/service/name/device-usb-camera), make sure that the paths match. Note that only the 1sat, 3rd and 5th paths are saved in the device, as these are the only streaming paths.
  6. Test for rediscovery by deleting the device or restarting the service, etc.
  7. Make sure the paths are updated if ports are changed.

New Dependency Instructions (If applicable)

Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jun 21, 2023

Codecov Report

Merging #262 (c54c24d) into main (c5a4cd9) will increase coverage by 2.04%.
The diff coverage is 13.86%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@           Coverage Diff            @@
##            main    #262      +/-   ##
========================================
+ Coverage   2.38%   4.43%   +2.04%     
========================================
  Files          8       8              
  Lines        879     925      +46     
========================================
+ Hits          21      41      +20     
- Misses       858     883      +25     
- Partials       0       1       +1     
Impacted Files Coverage Δ
internal/driver/device.go 11.42% <ø> (ø)
internal/driver/routes.go 0.00% <0.00%> (ø)
internal/driver/driver.go 3.48% <14.00%> (+3.48%) ⬆️

Copy link
Copy Markdown
Contributor

@ajcasagrande ajcasagrande left a comment

Choose a reason for hiding this comment

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

Added some comments to help direct you in possible alternative approaches. Work with @presatish and use best judgement to proceed how you see fit.

lc logger.LoggingClient
name string
path string
paths []interface{}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we might want to make these be a string array for simplicity, as i believe this is an internal representation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So that's what I tried originally, but it kept panicking with type errors. This was the solution I settled on, but I will keep on trying to fix those errors

// If there is a mismatch between them, scan all paths to find the matching device and update the existing device with the correct path.
func (d *Driver) RefreshExistingDevicePath(cd models.Device) {
d.lc.Debug("Refreshing existing device paths")
for _, fdPath := range cd.Protocols[UsbProtocol][Paths].([]interface{}) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not sure if this is the proper approach. I think it might make more sense to find all of the /dev/video that this device uses and then compare them.

// Scan all paths to find the matching device.
// The file descriptor of video capture device can be /dev/video0 ~ 63
// https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/devices.txt#L1402-L1406
var init []interface{}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

probably rename this function updateDevicePaths

d.lc.Info("Discovery is triggered")

var devices []sdkModels.DiscoveredDevice
devices := make(map[string]sdkModels.DiscoveredDevice)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am wondering for discovery if it makes more sense to take a more calculated approach, where we use v4l or something to discover the /dev/videos on a bus/device level rather than a plain scan of all video paths?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure if we wanted to look into a more complete refactor for discovery, but I will definitely look into it.

Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
@ChristianDarr-personal ChristianDarr-personal changed the title Extend discovery refactor: extend discovery for realsense Jun 26, 2023
@ChristianDarr-personal ChristianDarr-personal marked this pull request as ready for review June 26, 2023 17:47
@presatish presatish changed the title refactor: extend discovery for realsense feat: extend discovery for realsense cameras Jun 26, 2023
Copy link
Copy Markdown
Contributor

@presatish presatish left a comment

Choose a reason for hiding this comment

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

A couple of attributions are missing in attribution.txt, that file needs to be updated.

@lenny-goodell
Copy link
Copy Markdown
Member

A couple of attributions are missing in attribution.txt, that file needs to be updated.

Are these adding new dependencies that are not used else where in EdgeX? If so please see https://wiki.edgexfoundry.org/display/FA/Vetting+Process+for+3rd+Party+Dependencies

@lenny-goodell
Copy link
Copy Markdown
Member

@ChristianDarr-personal , your last commit is fail Semantic PR. Amend the commit to fix spelling.

Signed-off-by: Darr, Christian <christian.darr@intel.com>
@presatish
Copy link
Copy Markdown
Contributor

A couple of attributions are missing in attribution.txt, that file needs to be updated.

Are these adding new dependencies that are not used else where in EdgeX? If so please see https://wiki.edgexfoundry.org/display/FA/Vetting+Process+for+3rd+Party+Dependencies

These are indirect dependencies, so do we still need to do what you have suggested?

@lenny-goodell
Copy link
Copy Markdown
Member

These are indirect dependencies, so do we still need to do what you have suggested?

Nope, just on the direct dependencies.

Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
Attribution.txt Outdated
Comment on lines +226 to +237

github.com/gabriel-vasile/mimetype (MIT) https://github.com/gabriel-vasile/mimetype
https://github.com/gabriel-vasile/mimetype/blob/master/LICENSE

github.com/klauspost/compress (Apache-2.0) https://github.com/klauspost/compress
https://github.com/klauspost/compress/blob/master/LICENSE

github.com/stretchr/objx (MIT) https://github.com/stretchr/objx
https://github.com/stretchr/objx/blob/master/LICENSE

google.golang.org/genproto/googleapis/rpc https://github.com/googleapis/go-genproto/blob/main/LICENSE
https://github.com/googleapis/go-genproto/tree/main/googleapis/rpc No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Where are these coming from? You didn't change the go.mod explicit section.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

make test was still showing that I needed to include these for the attribution

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, this is because the go-mod indirect section changed when nothing changed in the explicit section

)

require (
github.com/Microsoft/go-winio v0.6.0 // indirect
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What triggered these updates?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When trying to compile, I ran go mod tidy after some build issues

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I just ran go mod tidy and make build on main and nothing changed. Please rerun go mod tidy and see if anything changes. Something strange if it doesn't.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ChristianDarr-personal Yes these changes seem to be not necessary and not sure how it happened. So you can just delete or comment out the indirect ones and run go mod tidy and that should restore the old dependencies back.

Signed-off-by: Darr, Christian <christian.darr@intel.com>
@@ -8,13 +8,14 @@ package driver

import (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Update copyright for this too.

func getV4L2Output() ([]string, errors.EdgeX) {
cmd := exec.Command("v4l2-ctl", "--list-devices")
output, _ := cmd.Output()
// if err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is no need for checking errors here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was something that I wanted to ask your advice on. So I was getting an error with this as the output:

Intel(R) RealSense(TM) Depth Ca (usb-0000:00:14.0-1.3):
	/dev/video1
	/dev/video3
	/dev/video5
	/dev/video8
	/dev/video9
	/dev/video11
	/dev/media0
	/dev/media1

HD Pro Webcam C920 (usb-0000:00:14.0-1.4):
	/dev/video13
	/dev/video14
	/dev/media3

C270 HD WEBCAM (usb-0000:00:14.0-2.1):
	/dev/video6
	/dev/video7
	/dev/media2

Cannot open device /dev/video0, exiting.

This outputs the necessary information, but using the Output() function, it returns an error, and I can't access the info. So I elected to ignore that error for now, but I was wondering if you had any thoughts on how to handle this

Signed-off-by: preethi-satishcandra <preethi.satishchandra@intel.com>
ChristianDarr-personal and others added 11 commits June 27, 2023 11:23
Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: preethi-satishcandra <preethi.satishchandra@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
Signed-off-by: Darr, Christian <christian.darr@intel.com>
@presatish presatish closed this Jul 27, 2023
@presatish presatish deleted the extend-discovery branch August 16, 2023 18:18
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.

5 participants