-
Notifications
You must be signed in to change notification settings - Fork 1
/
dump8610.c
119 lines (99 loc) · 3.1 KB
/
dump8610.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* open8610 - dump8610.c
*
* Version 1.10
*
* Control WS8610 weather station
*
* Copyright 2003-2005, Kenneth Lavrsen, Grzegorz Wisniewski, Sander Eerkes
* 2007 Philip Rayner
* This program is published under the GNU General Public license
*/
#include "rw8610.h"
/********************************************************************
* print_usage prints a short user guide
*
* Input: none
*
* Output: prints to stdout
*
* Returns: exits program
*
********************************************************************/
void print_usage(void)
{
printf("\n");
printf("dump8610 - Dump all data from WS-8610 to file.\n");
printf("Data is stored with address in human readable format\n");
printf("(C)2003 Kenneth Lavrsen.\n");
printf("(C)2005 Grzegorz Wisniewski,Sander Eerkes. (Version alfa)\n");
printf("(C)2006 Phil Rayner.\n");
printf("This program is released under the GNU General Public License (GPL)\n\n");
printf("Usage:\n");
printf("dump8610 filename start_address end_address\n");
printf("Addresses in hex, range 0-7FFF\n");
exit(0);
}
/********** MAIN PROGRAM ************************************************
*
* This program reads from a WS8610 weather station at a given address
* range and write the data in a text file in human readable format.
*
* Just run the program without parameters
* for usage.
*
* It uses the config file for device name.
* Config file locations - see open8610.conf
*
***********************************************************************/
int main(int argc, char *argv[])
{
WEATHERSTATION ws;
FILE *fileptr;
unsigned char data[32768];
int i;
int start_adr, end_adr;
struct config_type config;
// Get in-data and select mode.
// Get serial port from connfig file.
// Note: There is no command line config file path feature!
// history8610 will only search the default locations for the config file
get_configuration(&config, "");
if (argc!=4)
{
print_usage();
exit(0);
}
// Setup serial port
ws = open_weatherstation(config.serial_device_name);
fileptr = fopen(argv[1], "w");
if (fileptr == NULL)
{
printf("Cannot open file %s\n",argv[1]);
exit(0);
}
start_adr = strtol(argv[2],NULL,16);
end_adr = strtol(argv[3],NULL,16);
if (start_adr < 0 || start_adr > 0x7FFF || end_adr < 0 ||
end_adr > 0x7FFF || start_adr>=end_adr)
{
printf("Address range invalid\n");
exit(0);
}
if (read_safe(ws, start_adr, end_adr-start_adr + 1, data) == -1) {
printf("\nError reading data\n");
close_weatherstation(ws);
fclose(fileptr);
exit(0);
}
// Write out the data
for (i=0; i<=end_adr-start_adr; i++)
{
printf("Address: %04X - Data: %02X\n",start_adr+i,data[i]);
// fprintf(fileptr,"Address: %04X - Data: %02X\n",start_adr+i,data[i]);
if ((i / 8) * 8 == i) fprintf(fileptr,"\n%04X: ",start_adr+i);
fprintf(fileptr,"%02X ",data[i]);
}
// Goodbye and Goodnight
close_weatherstation(ws);
return(0);
}