Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
ds1820tousb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lehrstuhl für Informatik 4 (Systemsoftware)
PASST
ds1820tousb
Commits
e09fe2e4
Commit
e09fe2e4
authored
14 years ago
by
simimeie
Browse files
Options
Downloads
Patches
Plain Diff
- new restartonerror parameter
- new reset command (if the device supports it too)
parent
b00d2319
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hostsoftware.c
+28
-4
28 additions, 4 deletions
hostsoftware.c
with
28 additions
and
4 deletions
hostsoftware.c
+
28
−
4
View file @
e09fe2e4
/* $Id: hostsoftware.c,v 1.
7
2010/0
1/30 16:19:4
5 simimeie Exp $
/* $Id: hostsoftware.c,v 1.
8
2010/0
3/23 07:52:2
5 simimeie Exp $
* This is the control software for the ds1820-to-usb device that runs
* on the USB host to which the device is connected.
* You will need libusb and its development headers to compile this.
...
...
@@ -31,6 +31,7 @@ int verblev = 1;
}
int
devicenr
=
1
;
int
runinforeground
=
0
;
int
restartonerror
=
0
;
#define USBDEV_SHARED_VENDOR 0x16C0
/* VOTI */
#define USBDEV_SHARED_PRODUCT 0x05DC
/* Obdev's free shared PID */
...
...
@@ -43,6 +44,7 @@ int runinforeground = 0;
#define CMD_STATUS_SHORT 1
/* query device for status */
#define CMD_RESCAN 2
/* tell the device to rescan the probe bus */
#define CMD_STATUS_LONG 3
/* query device for list of probes and their status */
#define CMD_HARDRESET 4
/* reset device and probe bus */
struct
daemondata
{
unsigned
char
serial
[
6
];
...
...
@@ -66,6 +68,7 @@ static void usage(char *name)
printf
(
" test do an echo test with the device
\n
"
);
printf
(
" status query and show device status
\n
"
);
printf
(
" rescan tell the device to rescan its probe bus
\n
"
);
printf
(
" reset tell the device to reset the probe bus and itself
\n
"
);
printf
(
" showint shows 'interrupts' received from the device. These are
\n
"
);
printf
(
" not real interrupts, they are USB 'interrupts', and actually
\n
"
);
printf
(
" work by polling in regular intervals...
\n
"
);
...
...
@@ -413,7 +416,20 @@ static void printtooutbuf(char * outbuf, int oblen, struct daemondata * dd) {
*
outbuf
=
0
;
}
static
void
dodaemon
(
usb_dev_handle
*
handle
,
struct
daemondata
*
dd
)
{
static
void
dotryrestart
(
struct
daemondata
*
dd
,
char
**
argv
)
{
if
(
restartonerror
)
{
struct
daemondata
*
curdd
=
dd
;
while
(
curdd
!=
NULL
)
{
close
(
curdd
->
fd
);
curdd
=
curdd
->
next
;
}
fprintf
(
stderr
,
"Will try to restart in %d second(s)...
\n
"
,
restartonerror
);
sleep
(
restartonerror
);
execv
(
argv
[
0
],
argv
);
}
}
static
void
dodaemon
(
usb_dev_handle
*
handle
,
struct
daemondata
*
dd
,
char
**
argv
)
{
fd_set
mylsocks
;
struct
daemondata
*
curdd
;
struct
timeval
to
;
...
...
@@ -436,6 +452,7 @@ static void dodaemon(usb_dev_handle * handle, struct daemondata * dd) {
if
((
readysocks
=
select
((
maxfd
+
1
),
&
mylsocks
,
NULL
,
NULL
,
&
to
))
<
0
)
{
/* Error?! */
if
(
errno
!=
EINTR
)
{
perror
(
"ERROR: error on select()"
);
dotryrestart
(
dd
,
argv
);
exit
(
1
);
}
}
else
{
...
...
@@ -472,6 +489,7 @@ static void dodaemon(usb_dev_handle * handle, struct daemondata * dd) {
* usb_errno variable one can poll, but no... */
if
(
nBytes
!=
-
ETIMEDOUT
)
{
fprintf
(
stderr
,
"ERROR: USB error: %s
\n
"
,
usb_strerror
());
dotryrestart
(
dd
,
argv
);
exit
(
1
);
}
}
else
if
(
nBytes
!=
8
)
{
/* No error but wrong number of bytes */
...
...
@@ -492,7 +510,7 @@ static void dodaemon(usb_dev_handle * handle, struct daemondata * dd) {
/* never reached */
}
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
usb_dev_handle
*
handle
=
NULL
;
unsigned
char
buffer
[
8
];
...
...
@@ -510,6 +528,8 @@ int main(int argc, char **argv)
usage
(
argv
[
0
]);
exit
(
0
);
}
else
if
(
strcmp
(
argv
[
curarg
],
"--help"
)
==
0
)
{
usage
(
argv
[
0
]);
exit
(
0
);
}
else
if
(
strcmp
(
argv
[
curarg
],
"--restartonerror"
)
==
0
)
{
restartonerror
++
;
}
else
if
(
strcmp
(
argv
[
curarg
],
"-d"
)
==
0
)
{
curarg
++
;
if
(
curarg
>=
argc
)
{
...
...
@@ -565,6 +585,10 @@ int main(int argc, char **argv)
fprintf
(
stderr
,
"ERROR: Invalid reply to rescan command from device (%d bytes instead of 1)
\n
"
,
nBytes
);
}
}
}
else
if
(
strcmp
(
argv
[
curarg
],
"reset"
)
==
0
)
{
nBytes
=
usb_control_msg
(
handle
,
USB_TYPE_VENDOR
|
USB_RECIP_DEVICE
|
USB_ENDPOINT_IN
,
CMD_HARDRESET
,
0
,
0
,
(
char
*
)
buffer
,
sizeof
(
buffer
),
5000
);
VERBPRINT
(
1
,
"%d bytes received as reply.
\n
"
,
nBytes
);
VERBPRINT
(
0
,
"%s
\n
"
,
"Reset command sent. If this worked, you should see an USB disconnect and reconnect now
\n
"
);
}
else
if
(
strcmp
(
argv
[
curarg
],
"showint"
)
==
0
)
{
/* More of a debug mode: Show interrupt data */
doshowint
(
handle
);
}
else
if
(
strcmp
(
argv
[
curarg
],
"daemon"
)
==
0
)
{
/* Daemon mode */
...
...
@@ -642,7 +666,7 @@ int main(int argc, char **argv)
sia
.
sa_flags
=
0
;
/* to die from 'broken pipe'! */
sigaction
(
SIGPIPE
,
&
sia
,
NULL
);
}
dodaemon
(
handle
,
mydaemondata
);
dodaemon
(
handle
,
mydaemondata
,
argv
);
}
else
{
fprintf
(
stderr
,
"ERROR: Command '%s' is unknown.
\n
"
,
argv
[
curarg
]);
usage
(
argv
[
0
]);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment