author | viric <viriketo@gmail.com> |
Wed, 21 Dec 2011 23:27:15 +0100 | |
changeset 20 | b470691c2fc3 |
parent 19 | 3ed36b0e41bd |
child 21 | 59497fb48e2c |
permissions | -rw-r--r-- |
5
8459d991779e
Setting the license and authors, preparing for a release.
viric <viriketo@gmail.com>
parents:
4
diff
changeset
|
1 |
/* |
8459d991779e
Setting the license and authors, preparing for a release.
viric <viriketo@gmail.com>
parents:
4
diff
changeset
|
2 |
PCE-HT71 programmer and data downloader for libusb |
17
021968512187
Improving the help when run without parameters.
viric <viriketo@gmail.com>
parents:
15
diff
changeset
|
3 |
Copyright (C) 2010-2011 LluĂs Batlle i Rossell |
5
8459d991779e
Setting the license and authors, preparing for a release.
viric <viriketo@gmail.com>
parents:
4
diff
changeset
|
4 |
|
8459d991779e
Setting the license and authors, preparing for a release.
viric <viriketo@gmail.com>
parents:
4
diff
changeset
|
5 |
This program is free software: you can redistribute it and/or modify |
8459d991779e
Setting the license and authors, preparing for a release.
viric <viriketo@gmail.com>
parents:
4
diff
changeset
|
6 |
it under the terms of the GNU General Public License as published by |
8459d991779e
Setting the license and authors, preparing for a release.
viric <viriketo@gmail.com>
parents:
4
diff
changeset
|
7 |
the Free Software Foundation, either version 3 of the License, or |
8459d991779e
Setting the license and authors, preparing for a release.
viric <viriketo@gmail.com>
parents:
4
diff
changeset
|
8 |
(at your option) any later version. |
8459d991779e
Setting the license and authors, preparing for a release.
viric <viriketo@gmail.com>
parents:
4
diff
changeset
|
9 |
|
8459d991779e
Setting the license and authors, preparing for a release.
viric <viriketo@gmail.com>
parents:
4
diff
changeset
|
10 |
This program is distributed in the hope that it will be useful, |
8459d991779e
Setting the license and authors, preparing for a release.
viric <viriketo@gmail.com>
parents:
4
diff
changeset
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
8459d991779e
Setting the license and authors, preparing for a release.
viric <viriketo@gmail.com>
parents:
4
diff
changeset
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8459d991779e
Setting the license and authors, preparing for a release.
viric <viriketo@gmail.com>
parents:
4
diff
changeset
|
13 |
GNU General Public License for more details. |
8459d991779e
Setting the license and authors, preparing for a release.
viric <viriketo@gmail.com>
parents:
4
diff
changeset
|
14 |
|
8459d991779e
Setting the license and authors, preparing for a release.
viric <viriketo@gmail.com>
parents:
4
diff
changeset
|
15 |
You should have received a copy of the GNU General Public License |
8459d991779e
Setting the license and authors, preparing for a release.
viric <viriketo@gmail.com>
parents:
4
diff
changeset
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
8459d991779e
Setting the license and authors, preparing for a release.
viric <viriketo@gmail.com>
parents:
4
diff
changeset
|
17 |
*/ |
0 | 18 |
#include <usb.h> |
19 |
#include <stdio.h> |
|
20 |
#include <assert.h> |
|
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
21 |
#include <unistd.h> |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
22 |
#include <string.h> |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
23 |
#include <errno.h> |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
24 |
#include <time.h> |
0 | 25 |
|
26 |
const int vendor=0x10c4; |
|
27 |
const int product=0x0003; |
|
28 |
||
29 |
usb_dev_handle *handle; |
|
30 |
struct usb_device *device; |
|
31 |
||
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
32 |
int ep_in = 1; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
33 |
int ep_out = 2; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
34 |
|
18
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
35 |
|
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
36 |
/* Downloading, the base timestamp */ |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
37 |
time_t timestamp; |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
38 |
int time_per_sample; |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
39 |
|
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
40 |
enum |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
41 |
{ |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
42 |
HELP, |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
43 |
SET, |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
44 |
DOWNLOAD |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
45 |
} action; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
46 |
|
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
47 |
struct |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
48 |
{ |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
49 |
int nsamples; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
50 |
int time_per_sample; |
4 | 51 |
int immediate; |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
52 |
char *download_file; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
53 |
} config; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
54 |
|
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
55 |
FILE *outfile; |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
56 |
|
0 | 57 |
int connect() |
58 |
{ |
|
59 |
struct usb_bus *bus; |
|
60 |
bus = usb_get_busses(); |
|
61 |
||
62 |
while (bus != 0) |
|
63 |
{ |
|
64 |
struct usb_device *dev; |
|
65 |
dev = bus->devices; |
|
66 |
while(dev != 0) |
|
67 |
{ |
|
68 |
if (dev->descriptor.idVendor == vendor |
|
69 |
&& dev->descriptor.idProduct == product) |
|
70 |
{ |
|
71 |
handle = usb_open(dev); |
|
72 |
device = dev; |
|
73 |
return 0; |
|
74 |
} |
|
75 |
dev = dev->next; |
|
76 |
} |
|
77 |
bus = bus->next; |
|
78 |
} |
|
79 |
||
80 |
handle = 0; |
|
81 |
return -1; |
|
82 |
} |
|
83 |
||
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
84 |
int send_program() |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
85 |
{ |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
86 |
int res; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
87 |
res = usb_bulk_write(handle, ep_out, "\x01\x40\x00", 3, 1000); |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
88 |
assert(res == 3); |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
89 |
} |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
90 |
|
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
91 |
int send_config() |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
92 |
{ |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
93 |
int res; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
94 |
char buf[64]; |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
95 |
struct tm *t; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
96 |
time_t tmp_time; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
97 |
tmp_time = time(NULL); |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
98 |
t = localtime(&tmp_time); |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
99 |
|
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
100 |
buf[0] = '\xce'; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
101 |
buf[1] = 0; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
102 |
buf[2] = 0; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
103 |
buf[3] = 0; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
104 |
|
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
105 |
// Samples |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
106 |
*( (int *) &buf[4]) = config.nsamples; |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
107 |
// Samples got |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
108 |
*( (int *) &buf[8]) = 0; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
109 |
// Sample rate |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
110 |
*( (int *) &buf[12]) = config.time_per_sample; |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
111 |
// Year |
3 | 112 |
*( (int *) &buf[16]) = t->tm_year + 1900; |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
113 |
// Mintemp |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
114 |
buf[20] = 0; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
115 |
buf[21] = 0; |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
116 |
*( (short int *) &buf[22]) = 0x4120; |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
117 |
// Maxtemp |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
118 |
buf[24] = 0; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
119 |
buf[25] = 0; |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
120 |
*( (short int *) &buf[26]) = 0x41a0; |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
121 |
|
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
122 |
// Month |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
123 |
buf[28] = t->tm_mon; |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
124 |
// Day |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
125 |
buf[29] = t->tm_mday; |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
126 |
// hour |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
127 |
buf[30] = t->tm_hour; |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
128 |
// Minute |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
129 |
buf[31] = t->tm_min; |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
130 |
// second |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
131 |
buf[32] = t->tm_sec; |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
132 |
// Celsius (1 F) |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
133 |
buf[33] = 0; |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
134 |
// Pause between leds (300s) |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
135 |
buf[34] = 0x1e; |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
136 |
// Name |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
137 |
buf[35] = 'A'; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
138 |
buf[36] = '0'; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
139 |
|
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
140 |
// Immediate |
4 | 141 |
buf[51] = config.immediate ? 2 : 1; |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
142 |
// Minhum |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
143 |
buf[52] = 0; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
144 |
buf[53] = 0; |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
145 |
*( (short int *) &buf[54]) = 0x410f; |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
146 |
// Maxhum |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
147 |
buf[56] = 0; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
148 |
buf[57] = 0; |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
149 |
*( (short int *) &buf[58]) = 0x4296; |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
150 |
// final |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
151 |
buf[60] = 0xce; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
152 |
buf[61] = 0x0; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
153 |
buf[62] = 0x0; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
154 |
buf[63] = 0x0; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
155 |
|
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
156 |
res = usb_bulk_write(handle, ep_out, buf, 64, 1000); |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
157 |
assert(res == 64); |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
158 |
|
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
159 |
res = usb_bulk_read(handle, ep_in, buf, 1, 1000); |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
160 |
assert(res == 1); |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
161 |
} |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
162 |
|
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
163 |
void parse_data(char *data) |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
164 |
{ |
18
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
165 |
time_t now; |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
166 |
struct tm *tm_now; |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
167 |
struct tm tm; |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
168 |
|
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
169 |
now = time(0); |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
170 |
|
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
171 |
tm_now = localtime(&now); |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
172 |
memset(&tm, 0, sizeof(tm)); |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
173 |
|
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
174 |
tm.tm_isdst = tm_now->tm_isdst; |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
175 |
tm.tm_year = *((short int *) (data + 16)) - 1900; |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
176 |
tm.tm_mon = *((unsigned char *) (data + 28)); |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
177 |
tm.tm_mday = *((unsigned char *) (data + 29)); |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
178 |
tm.tm_hour = *((unsigned char *) (data + 30)); |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
179 |
tm.tm_min = *((unsigned char *) (data + 31)); |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
180 |
tm.tm_sec = *((unsigned char *) (data + 32)); |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
181 |
|
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
182 |
timestamp = mktime(&tm); |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
183 |
|
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
184 |
fprintf(outfile, "# Start: %i-%i-%i %i:%i:%i @%llu\n", |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
185 |
tm.tm_year + 1900, |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
186 |
tm.tm_mon+1, |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
187 |
tm.tm_mday, |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
188 |
tm.tm_hour, |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
189 |
tm.tm_min, |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
190 |
tm.tm_sec, |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
191 |
(unsigned long long) timestamp); |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
192 |
|
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
193 |
fprintf(outfile, "# Num Samples: %hi\n", |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
194 |
*((short int *) (data + 8)) |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
195 |
); |
18
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
196 |
|
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
197 |
time_per_sample = *((short int *) (data + 12)); |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
198 |
|
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
199 |
fprintf(outfile, "# Time between samples: %i s\n", |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
200 |
time_per_sample); |
19
3ed36b0e41bd
Making the pce output a gnuplot script directly.
viric <viriketo@gmail.com>
parents:
18
diff
changeset
|
201 |
|
3ed36b0e41bd
Making the pce output a gnuplot script directly.
viric <viriketo@gmail.com>
parents:
18
diff
changeset
|
202 |
fprintf(outfile, "set xdata time; set timefmt \"%%s\"; plot \"-\" using 2:3 " |
3ed36b0e41bd
Making the pce output a gnuplot script directly.
viric <viriketo@gmail.com>
parents:
18
diff
changeset
|
203 |
"with lines title \"temp\", \"\" using 2:4 with lines title \"hum\"; pause -1\n"); |
3ed36b0e41bd
Making the pce output a gnuplot script directly.
viric <viriketo@gmail.com>
parents:
18
diff
changeset
|
204 |
|
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
205 |
} |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
206 |
|
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
207 |
int |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
208 |
start_download() |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
209 |
{ |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
210 |
int res; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
211 |
|
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
212 |
res = usb_bulk_write(handle, ep_out, "\x00\x10\x01", 3, 1000); |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
213 |
assert(res == 3); |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
214 |
|
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
215 |
char data[100]; |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
216 |
res = usb_bulk_read(handle, ep_in, data, 3, 1000); |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
217 |
assert(res == 3); |
4 | 218 |
fprintf(stderr, "Debug: %02hhx%02hhx%02hhx\n", data[0], data[1], data[2]); |
219 |
assert(data[0] == 2); |
|
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
220 |
|
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
221 |
int num = *((short int*) &data[1]); |
4 | 222 |
fprintf(stderr, "Found %i bytes = %i samples\n", num, num/4); |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
223 |
|
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
224 |
if (num > 0) |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
225 |
{ |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
226 |
int num_frames = (num + 63) / 64; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
227 |
fprintf(stderr, "%i frames\n", num_frames); |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
228 |
|
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
229 |
/* |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
230 |
res = usb_bulk_write(handle, ep_out, "\x00\x00\x01", 3, 1000); |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
231 |
assert(res == 3); |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
232 |
*/ |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
233 |
|
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
234 |
res = usb_bulk_read(handle, ep_in, data, 64, 1000); |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
235 |
assert(res == 64); |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
236 |
|
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
237 |
parse_data(data); |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
238 |
|
18
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
239 |
int sample = 0; |
11
0a821b9bdc80
Fixing the download of many samples.
viric <viriketo@gmail.com>
parents:
10
diff
changeset
|
240 |
int block = 0; |
10
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
241 |
do |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
242 |
{ |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
243 |
char frame[3]; |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
244 |
int step_frames = num_frames >= 0x40 ? 0x40 : num_frames; |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
245 |
frame[0] = 0; |
11
0a821b9bdc80
Fixing the download of many samples.
viric <viriketo@gmail.com>
parents:
10
diff
changeset
|
246 |
frame[1] = block; |
10
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
247 |
frame[2] = step_frames; |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
248 |
|
10
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
249 |
res = usb_bulk_write(handle, ep_out, frame, 3, 1000); |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
250 |
assert(res == 3); |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
251 |
|
10
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
252 |
res = usb_bulk_read(handle, ep_in, data, 3, 1000); |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
253 |
assert(res == 3); |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
254 |
fprintf(stderr, "Debug: %02hhx%02hhx%02hhx\n", data[0], data[1], data[2]); |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
255 |
assert(data[0] == 2); |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
256 |
|
10
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
257 |
int i; |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
258 |
for(i=0; i < step_frames; ++i) |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
259 |
{ |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
260 |
res = usb_bulk_read(handle, ep_in, data, 64, 5000); |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
261 |
assert(res == 64); |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
262 |
int take = (num >= 64) ? 64 : num; |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
263 |
|
10
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
264 |
int j; |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
265 |
for(j=0; j<take; j+=4) |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
266 |
{ |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
267 |
float temp = *((short int *) (data + j)) / 10.; |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
268 |
float hum = *((short int *) (data + j + 2)) / 10.; |
18
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
269 |
|
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
270 |
time_t sampletime = timestamp + time_per_sample * sample; |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
271 |
|
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
272 |
fprintf(outfile, "%i %llu %g %g\n", sample, |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
273 |
(unsigned long long) sampletime, |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
274 |
temp, hum); |
f85465640dd4
Making pce print timestamps in the download.
viric <viriketo@gmail.com>
parents:
17
diff
changeset
|
275 |
sample++; |
10
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
276 |
} |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
277 |
num -= 64; |
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
278 |
num_frames -= 1; |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
279 |
} |
11
0a821b9bdc80
Fixing the download of many samples.
viric <viriketo@gmail.com>
parents:
10
diff
changeset
|
280 |
++block; |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
281 |
} |
10
fc8a8cfe680a
Fixing a bug, when it had to download more than 0x40 frames.
viric <viriketo@gmail.com>
parents:
8
diff
changeset
|
282 |
while(num_frames > 0); |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
283 |
} |
1
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
284 |
} |
fdce143cc82c
It works a bit. I reverse enginered part.
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
285 |
|
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
286 |
void |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
287 |
usage() |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
288 |
{ |
17
021968512187
Improving the help when run without parameters.
viric <viriketo@gmail.com>
parents:
15
diff
changeset
|
289 |
fprintf(stderr, "pce v0.3 - PCE-HT71 programmer and data downloader\n"); |
021968512187
Improving the help when run without parameters.
viric <viriketo@gmail.com>
parents:
15
diff
changeset
|
290 |
fprintf(stderr, "usage: pce [-n maxsamples] [-t timepersample] [-i] <-d downloadfile | -s>\n"); |
021968512187
Improving the help when run without parameters.
viric <viriketo@gmail.com>
parents:
15
diff
changeset
|
291 |
fprintf(stderr, "Options:\n"); |
021968512187
Improving the help when run without parameters.
viric <viriketo@gmail.com>
parents:
15
diff
changeset
|
292 |
fprintf(stderr, " -i Start measuring now, instead of waiting the manual button.\n"); |
021968512187
Improving the help when run without parameters.
viric <viriketo@gmail.com>
parents:
15
diff
changeset
|
293 |
fprintf(stderr, " -s Program the capture according to '-n' and '-t'\n"); |
021968512187
Improving the help when run without parameters.
viric <viriketo@gmail.com>
parents:
15
diff
changeset
|
294 |
fprintf(stderr, " -d file Download the data captured until now and stop it\n"); |
021968512187
Improving the help when run without parameters.
viric <viriketo@gmail.com>
parents:
15
diff
changeset
|
295 |
fprintf(stderr, " -n maxs Set the maximum number of samples to capture (default 16000)\n"); |
021968512187
Improving the help when run without parameters.
viric <viriketo@gmail.com>
parents:
15
diff
changeset
|
296 |
fprintf(stderr, " -t time Set the number of seconds between samples (default 2)\n"); |
021968512187
Improving the help when run without parameters.
viric <viriketo@gmail.com>
parents:
15
diff
changeset
|
297 |
fprintf(stderr, "\nCopyright (C) 2010-2011 Lluis Batlle i Rossell\n"); |
8
897b154201f8
More about the license, shown at program usage show.
viric <viriketo@gmail.com>
parents:
7
diff
changeset
|
298 |
fprintf(stderr, "This program comes with ABSOLUTELY NO WARRANTY.\n"); |
897b154201f8
More about the license, shown at program usage show.
viric <viriketo@gmail.com>
parents:
7
diff
changeset
|
299 |
fprintf(stderr, "This is free software, and you are welcome to redistribute it\n"); |
17
021968512187
Improving the help when run without parameters.
viric <viriketo@gmail.com>
parents:
15
diff
changeset
|
300 |
fprintf(stderr, "under certain conditions; read the COPYING file for details."); |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
301 |
} |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
302 |
|
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
303 |
int main(int argc, char **argv) |
0 | 304 |
{ |
305 |
int res; |
|
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
306 |
int opt; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
307 |
|
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
308 |
config.nsamples = 16000; |
4 | 309 |
config.immediate = 0; |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
310 |
config.time_per_sample = 2; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
311 |
config.download_file = 0; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
312 |
action = HELP; |
4 | 313 |
while ((opt = getopt(argc, argv, "n:d:t:si")) != -1) { |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
314 |
switch (opt) { |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
315 |
case 'n': |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
316 |
config.nsamples = atoi(optarg); |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
317 |
break; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
318 |
case 't': |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
319 |
config.time_per_sample = atoi(optarg); |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
320 |
break; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
321 |
case 'd': |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
322 |
config.download_file = optarg; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
323 |
action = DOWNLOAD; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
324 |
break; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
325 |
case 's': |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
326 |
action = SET; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
327 |
break; |
4 | 328 |
case 'i': |
329 |
config.immediate = 1; |
|
330 |
break; |
|
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
331 |
default: |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
332 |
usage(); |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
333 |
return 1; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
334 |
} |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
335 |
} |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
336 |
|
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
337 |
if (action == HELP) |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
338 |
{ |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
339 |
usage(); |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
340 |
return 0; |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
341 |
} |
0 | 342 |
|
343 |
usb_init(); |
|
344 |
||
345 |
usb_find_busses(); |
|
346 |
usb_find_devices(); |
|
347 |
||
348 |
connect(); |
|
349 |
if (handle == 0) |
|
350 |
{ |
|
351 |
fprintf(stderr, "Cannot find the PCE-HT71\n"); |
|
352 |
return -1; |
|
353 |
} |
|
354 |
||
355 |
res = usb_claim_interface(handle, |
|
356 |
device->config->interface->altsetting->bInterfaceNumber); |
|
357 |
assert(res == 0 && "claim_interface"); |
|
358 |
||
4 | 359 |
if (action == SET) |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
360 |
{ |
4 | 361 |
fprintf(stderr, "Settings: \n"); |
362 |
fprintf(stderr, " Max samples: %i\n", config.nsamples); |
|
363 |
fprintf(stderr, " Time between samples: %i\n", config.time_per_sample); |
|
364 |
fprintf(stderr, " Mode: %s\n", config.immediate ? "immediate" : "manual"); |
|
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
365 |
send_program(); |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
366 |
send_config(); |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
367 |
} |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
368 |
else |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
369 |
{ |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
370 |
outfile = fopen(config.download_file, "w"); |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
371 |
if (outfile != NULL) |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
372 |
{ |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
373 |
start_download(); |
4 | 374 |
fprintf(stderr, "File \"%s\" written\n", config.download_file); |
2
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
375 |
fclose(outfile); |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
376 |
} |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
377 |
else |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
378 |
{ |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
379 |
fprintf(stderr, "Error opening file: %s", strerror(errno)); |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
380 |
} |
884635f4a24f
First working a bit version, with usage()
viric <viriketo@gmail.com>
parents:
1
diff
changeset
|
381 |
} |
0 | 382 |
|
383 |
res = usb_release_interface(handle, |
|
384 |
device->config->interface->altsetting->bInterfaceNumber); |
|
385 |
assert(res == 0 && "release_interface"); |
|
386 |
usb_close(handle); |
|
387 |
handle = 0; |
|
388 |
return 0; |
|
389 |
} |