-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.c
69 lines (62 loc) · 1.43 KB
/
test2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* Copyright (C) Bjorn Andersson <[email protected]> */
#include "ds2490.h"
#include "util.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
int
main(void)
{
uint8_t owdevs[32][8];
int devcount;
owusb_device_t *dev;
int len, i;
uint8_t in[9];
uint8_t out[256];
if ((i = owusb_init()) != 0) {
printf("Failed to initialize: %d\n", i);
return -1;
}
dev = &owusb_devs[0];
/*len = owusb_search_all(dev, (uint8_t *)owdevs, 32 * 8);*/
len = owusb_search(dev, 0xf0, (uint8_t *)owdevs, 32 * 8);
devcount = len / 8;
for (i = 0; i < devcount; i++) {
print_addr((uint8_t *)owdevs[i]);
}
printf("\n");
#if 0
memset(out, 0, 16);
out[0] = 0x05;
owusb_write(dev, out, 8);
owusb_com_search_access(dev, PARAM_NTF|PARAM_IM | PARAM_RST | PARAM_F, 1, 1, 1, 0xf0);
sleep(1);
owusb_interrupt_read(dev);
owusb_print_state(dev);
owusb_read(dev, out, 16);
print_hex(out, 16);
return 0;
#endif
while (1) {
owusb_com_reset(dev, PARAM_IM, 0, 0);
owusb_write_byte(dev, 0xcc);
owusb_write_byte(dev, 0x44);
while (owusb_read_bit(dev) == 0);
for (i = 0; i < devcount; i++) {
if (owdevs[i][0] != 0x28) continue;
out[0] = 0x55;
memcpy(&out[1], owdevs[i], 8);
out[9] = 0xbe;
if (owusb_block_io(dev, out, 10, in, 9, 1, 0) != 0) {
exit(1);
}
/*print_hex(in, 9);*/
printf("%.4f\t", convert_temp(in));
}
printf("\n");
sleep(60);
}
/*crc = calc_crc8(data, 7);
printf("CRC: %02x\n", crc);*/
}