Skip to content

Commit

Permalink
Add option for printing archive header
Browse files Browse the repository at this point in the history
Add option (-a, --archive-header) to print the archive header instead of
always printing
  • Loading branch information
bytesnz committed Sep 8, 2017
1 parent e721078 commit 321f792
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Options:
- all the records since arc date
(in yyyy-mm-dd[THH:MM format]
- the last arc records
-A, --archive-header Print the archive data header with the
archive records
-i, --get-interval Get the current archive interval
-t, --get-time Get weather station time.
-s, --set-time Set weather station time to system time.
Expand Down Expand Up @@ -232,7 +234,7 @@ grRainByMonth = 328.12,328.56,327.68,328.22,331.94,330.86,327.70,328.26,348.76,3
grRainByYear = 655.35,655.35,655.35,655.35,655.35,655.35,655.35,655.35,655.35,655.35,655.35,655.35,655.35,655.35,655.35,655.35,655.35,655.35,655.35,655.35,655.35,655.35,370.78,354.48
```

## Archive Data Example Output
## Archive Data Example Output (with Archive Header)
```
date,time,outside temp (°F),outside temp high (°F), outside temp low (°F),insideTemp (°F),extra temp1 (°F), extra temp2 (°F), extra temp3 (°F),inside humidity (%),outside humidity (%),extra humidity 1 (%),extra humidity 2 (%),rainfall (clicks),highest rain rate (clicks/hr),barometer (inches Hg),forecast at end of period,number of wind samples,average wind speed (mph),prevailing wind direction (°),prevailing wind rose,highest wind speed (mph),highest wind direction (°),higest wind rose,average solar radiation (W/m^2),maximum solar radiation (W/m^2),average uv index,max uv,accumulated et (in),leaf temp 1 (°F),leaf temp 2 (°F),leaf wetness 1,leaf wetness 2,soil temp 1 (°F),soil temp 2 (°F),soil temp 3 (°F),soil temp 4 (°F),soil moisture 1 (cb),soil moisture 2 (cb), soil moisture 3 (cb), soil moisture 4 (cb)
2017-09-04,19:00,72.9,73.7,72.9,78.2,,,,75,65,,,,,30.155,Increasing clouds with little temperature change. Precipitation possible within 24 to 48 hrs.,1181,11,10,NNW,24,11,NNW,0,,0,,0.003,,,,,,,,,,,,
Expand Down
31 changes: 21 additions & 10 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include "dhandler.h"
#include "byte.h"

#define VERSION "1.3.1"
#define VERSION "1.3.2"

/* local Data */
static char szttyDevice[255]; /* Serial device string */
Expand All @@ -55,6 +55,7 @@ static bool bGetRTD; /* Get Real Time Data */
static bool bGetHLD; /* Get High Low Data */
static bool bGetGD; /* Get graph data */
static bool bArchive; /* Get archive data */
static bool bPrintArchiveHeader; /* Print archive header with data */
static bool bGetInterval; /* Get arcive interval */
static bool bGetTime; /* Get time flag */
static bool bSetTime; /* Set time flag */
Expand Down Expand Up @@ -105,6 +106,8 @@ int main(int argc, char *argv[])
printf(" - all the records since arc date\n");
printf(" (in yyyy-mm-dd[THH:MM format]\n");
printf(" - the last arc records\n");
printf(" -A, --archive-header Print the archive data header with the\n");
printf(" archive records\n");
printf(" -i, --get-interval Get the current archive interval\n");
printf(" -t, --get-time Get weather station time.\n");
printf(" -s, --set-time Set weather station time to system time.\n");
Expand Down Expand Up @@ -388,7 +391,9 @@ int main(int argc, char *argv[])
}

if (numPages) {
PrintArchHeader();
if (bPrintArchiveHeader) {
PrintArchHeader();
}

if (archiveRecords && (archiveRecords / 5) < numPages) {
numPages = archiveRecords / 5;
Expand Down Expand Up @@ -479,6 +484,7 @@ int GetParms(int argc, char *argv[])
{ "get-hilo", no_argument, 0, 'l' },
{ "get-graph", no_argument, 0, 'g' },
{ "get-archive", optional_argument, 0, 'a' },
{ "archive-header", no_argument, 0, 'A' },
{ "get-interval", no_argument, 0, 'i' },
{ "get-time", no_argument, 0, 't' },
{ "set-time", no_argument, 0, 's' },
Expand All @@ -499,6 +505,8 @@ int GetParms(int argc, char *argv[])
bGetRTD = false;
bGetHLD = false;
bGetGD = false;
bArchive = false;
bPrintArchiveHeader = false;
bHTML = false;
bVerbose = false;
bDebug = false;
Expand All @@ -510,7 +518,7 @@ int GetParms(int argc, char *argv[])
if(argc == 1)
return 0; /* no parms at all */

while ((c = getopt_long(argc, argv, "ofrmxlga::ivetsb:d:", longopts, NULL )) != EOF) {
while ((c = getopt_long(argc, argv, "ofrmxlga::Aivetsb:d:", longopts, NULL )) != EOF) {
switch (c) {
case 'o': bBKLOn = true; break;
case 'f': bBKLOff = true; break;
Expand All @@ -527,6 +535,7 @@ int GetParms(int argc, char *argv[])
bVerbose = true;
bDebug = true;
break;
case 'A': bPrintArchiveHeader = true; break;

case 'a':
bArchive = true;
Expand Down Expand Up @@ -778,16 +787,18 @@ int runCommand(char* command, int commandLength, int expectedLength, char* dataL
}

// Check for 0x0a0d at end
if (nCnt == totalLength + 2) {
if (szSerBuffer[totalLength] == 0x0a
&& szSerBuffer[totalLength + 1] == 0x0d) {
if (nCnt == totalLength + 2 && szSerBuffer[totalLength] == 0x0a
&& szSerBuffer[totalLength + 1] == 0x0d) {
if (bVerbose) {
printf("Good\n");
}
} else {
if(nCnt != totalLength)
printf("Bad\n");
else
printf("Good\n");
if (bVerbose) {
if(nCnt != totalLength)
printf("Bad\n");
else
printf("Good\n");
}

if(nCnt != totalLength) {
fprintf(stderr, "vproweather: Didn't get all data. Try changing delay parameter.\n");
Expand Down

0 comments on commit 321f792

Please sign in to comment.