Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
Programmable RF Attenuator
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Programmable RF Attenuator
Commits
33180743
Commit
33180743
authored
Nov 05, 2021
by
Juan David González Cobas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
try first attempt at enumeration with serials
parent
764768f1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
0 deletions
+68
-0
usb-enum.c
software/lib/usb-enum.c
+68
-0
No files found.
software/lib/usb-enum.c
0 → 100644
View file @
33180743
#include <stdio.h>
#include <string.h>
#include <libudev.h>
#define OAU_VENDOR_ID "1556"
/* CERN USB Vendor ID */
#define OAU_DEVICE_ID "0443"
/* oau USB Device ID */
#define ID_VENDOR_ID OAU_VENDOR_ID
#define ID_DEVICE_ID OAU_DEVICE_ID
static
int
oua_enumerate
(
char
*
vendor_id
,
char
*
device_id
);
int
main
(
int
argc
,
char
*
argv
[])
{
oua_enumerate
(
ID_VENDOR_ID
,
ID_DEVICE_ID
);
return
0
;
}
static
int
oua_enumerate
(
char
*
vendor_id
,
char
*
device_id
)
{
struct
udev
*
udev
=
udev_new
();
struct
udev_enumerate
*
enumerate
=
udev_enumerate_new
(
udev
);
struct
udev_list_entry
*
devs
,
*
ptr
;
int
found_ports
=
0
;
//udev_enumerate_add_match_subsystem(enumerate, "tty");
udev_enumerate_add_match_property
(
enumerate
,
"ID_VENDOR_ID"
,
vendor_id
);
udev_enumerate_add_match_property
(
enumerate
,
"ID_MODEL_ID"
,
device_id
);
udev_enumerate_scan_devices
(
enumerate
);
devs
=
udev_enumerate_get_list_entry
(
enumerate
);
udev_list_entry_foreach
(
ptr
,
devs
)
{
const
char
*
path
=
udev_list_entry_get_name
(
ptr
);
struct
udev_device
*
dev
=
udev_device_new_from_syspath
(
udev
,
path
);
const
char
*
devnode
=
udev_device_get_devnode
(
dev
);
const
char
*
serial
=
udev_device_get_sysattr_value
(
dev
,
"serial"
);
printf
(
"serial: %s,
\n
"
,
serial
);
goto
notfound
;
if
(
devnode
!=
NULL
)
{
struct
udev_list_entry
*
l
,
*
links
=
udev_device_get_devlinks_list_entry
(
dev
);
//int port;
udev_list_entry_foreach
(
l
,
links
)
{
const
char
*
linkname
=
udev_list_entry_get_name
(
l
);
int
i
,
len
=
strlen
(
linkname
);
const
char
*
ports
[]
=
{
"0-port0"
,
"1-port0"
,
"2-port0"
,
"3-port0"
,
};
int
trim
=
strlen
(
ports
[
0
]);
for
(
i
=
0
;
i
<
4
;
i
++
)
if
(
!
strcmp
(
ports
[
i
],
&
linkname
[
len
-
trim
]))
{
//ports_info[i].port = port = i;
//strcpy(ports_info[i].symlink, path);
//strcpy(ports_info[i].devnode, devnode);
goto
found
;
}
goto
notfound
;
}
found:
found_ports
++
;
}
notfound:
udev_device_unref
(
dev
);
}
udev_enumerate_unref
(
enumerate
);
return
(
found_ports
==
4
)
?
0
:
-
1
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment