Skip to content

Commit

Permalink
Added LOOP2 packet data to realtime data output
Browse files Browse the repository at this point in the history
- Added LOOP2 labels for realtime data
- Added LOOP2 packet data defintion and functions
- Extracted wind rose string functionality to its own function
- Added LOOP2 data to PrintRTData()
- Added bool param to PrintRTData() to make sure LOOP2 data is printed
  only if the LOOP2 command was successful
  • Loading branch information
bytesnz committed Sep 8, 2017
1 parent 1dd4b55 commit 92a72b2
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 39 deletions.
107 changes: 70 additions & 37 deletions dhandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ static char szForeStrings[] =
"Mostly clear and cooler.\0\0" ;


static RTDATA rcd; /* the one and only real time weather packet */
static RTDATA rcd; /* the one and only v1 real time weather packet */
static RTDATA2 rcd2; /* the one and only v2 real time weather packet */
static HLDATA hld; /* the one and only highs/lows packet */

/* local functions */
Expand Down Expand Up @@ -347,6 +348,17 @@ void GetRTData(char *szData)



/*--------------------------------------------------------------------------
GetRT2Data
Gets the real time weather data packet v2 to the static RTDATA2 struct.
----------------------------------------------------------------------------*/
void GetRT2Data(char *szData)
{
memcpy((char*)&rcd2, szData, sizeof(RTDATA2));
}




/*--------------------------------------------------------------------------
GetHLData
Expand All @@ -359,14 +371,55 @@ void GetHLData(char *szData)




/*--------------------------------------------------------------------------
GetHLData
Gets the high/low weather data packet to the static HLDATA struct.
----------------------------------------------------------------------------*/
char* getWindRose(uint8_t bearing) {
if(bearing >= 347 && bearing < 12) /* compass rose version */
return "N";
else if(bearing >= 12 && bearing < 34)
return "NNE";
else if(bearing >= 34 && bearing < 57)
return "NE";
else if(bearing >= 57 && bearing < 79)
return "ENE";
else if(bearing >= 79 && bearing < 102)
return "E";
else if(bearing >= 102 && bearing < 124)
return "ESE";
else if(bearing >= 124 && bearing < 147)
return "SE";
else if(bearing >= 147 && bearing < 170)
return "SSE";
else if(bearing >= 170 && bearing < 192)
return "S";
else if(bearing >= 192 && bearing < 214)
return "SSW";
else if(bearing >= 214 && bearing < 237)
return "SW";
else if(bearing >= 237 && bearing < 259)
return "WSW";
else if(bearing >= 259 && bearing < 280)
return "W";
else if(bearing >= 280 && bearing < 303)
return "WNW";
else if(bearing >= 303 && bearing < 347)
return "NW";
else /* >326 <347 */
return "NNW";
}

/*--------------------------------------------------------------------------
PrintRTData
Dumps the real time weather data to stdout.
----------------------------------------------------------------------------*/
void PrintRTData(void)
void PrintRTData(bool includeLoop2Data)
{
int16_t i;

printf("%s = 0x%04x\n", _NEXT_RECORD, rcd.wNextRec );
/* 3-hour rolling baro trend */
i = rcd.cP;
printf("%s = ", _BARO_TREND);
Expand All @@ -392,42 +445,17 @@ void PrintRTData(void)
printf("%s = %d\n", _INSIDE_HUM, rcd.yInsideHum );
printf("%s = %.1f\n", _OUTSIDE_TEMP, ((int16_t)rcd.wOutsideTemp) / 10.0 );
printf("%s = %d\n", _WIND_SPEED, rcd.yWindSpeed );
printf("%s = %d\n", _WIND_AVG_SPEED, rcd.yAvgWindSpeed );
if (includeLoop2Data) {
printf("%s = %.1f\n", _WIND_AVG_SPEED, (double)rcd2.avgWindSpd10m / 10.0 );
} else {
printf("%s = %d\n", _WIND_AVG_SPEED, rcd.yAvgWindSpeed );
}
if (includeLoop2Data) printf("%s = %.1f\n", _WIND_2M_AVG_SPEED, (double)rcd2.avgWindSpd2m / 10.0 );
printf("%s = %d\n", _WIND_DIR, rcd.wWindDir );
printf("%s = ", _WIND_DIR_ROSE);
if(rcd.wWindDir >= 347 && rcd.wWindDir < 12) /* compass rose version */
printf("N\n");
else if(rcd.wWindDir >= 12 && rcd.wWindDir < 34)
printf("NNE\n");
else if(rcd.wWindDir >= 34 && rcd.wWindDir < 57)
printf("NE\n");
else if(rcd.wWindDir >= 57 && rcd.wWindDir < 79)
printf("ENE\n");
else if(rcd.wWindDir >= 79 && rcd.wWindDir < 102)
printf("E\n");
else if(rcd.wWindDir >= 102 && rcd.wWindDir < 124)
printf("ESE\n");
else if(rcd.wWindDir >= 124 && rcd.wWindDir < 147)
printf("SE\n");
else if(rcd.wWindDir >= 147 && rcd.wWindDir < 170)
printf("SSE\n");
else if(rcd.wWindDir >= 170 && rcd.wWindDir < 192)
printf("S\n");
else if(rcd.wWindDir >= 192 && rcd.wWindDir < 214)
printf("SSW\n");
else if(rcd.wWindDir >= 214 && rcd.wWindDir < 237)
printf("SW\n");
else if(rcd.wWindDir >= 237 && rcd.wWindDir < 259)
printf("WSW\n");
else if(rcd.wWindDir >= 259 && rcd.wWindDir < 280)
printf("W\n");
else if(rcd.wWindDir >= 280 && rcd.wWindDir < 303)
printf("WNW\n");
else if(rcd.wWindDir >= 303 && rcd.wWindDir < 347)
printf("NW\n");
else /* >326 <347 */
printf("NNW\n");

printf("%s = %s\n", _WIND_DIR_ROSE, getWindRose(rcd.wWindDir) );
if (includeLoop2Data) printf("%s = %d\n", _WIND_10M_GUST_SPEED, rcd2.windGust10m );
if (includeLoop2Data) printf("%s = %d\n", _WIND_10M_GUST_DIR, rcd2.windGust10mDir );
if (includeLoop2Data) printf("%s = %s\n", _WIND_10M_GUST_DIR_ROSE, getWindRose(rcd2.windGust10mDir) );
printf("%s = %d\n", _OUTSIDE_HUM, rcd.yOutsideHum );
printf("%s = %.2f\n", _RAIN_RATE, rcd.wRainRate / 100.0 );
printf("%s = %s\n", _IS_RAINING, rcd.wRainRate ? "yes" : "no");
Expand All @@ -441,11 +469,16 @@ void PrintRTData(void)
printf("n/a\n");
else
printf("%d\n", rcd.wSolarRad );
if (includeLoop2Data) printf("%s = %d\n", _HEAT_INDEX, rcd2.heatIndex );
if (includeLoop2Data) printf("%s = %d\n", _WIND_CHILL, rcd2.windChill );
if (includeLoop2Data) printf("%s = %d\n", _THSW_INDEX, rcd2.thswIndex );
printf("%s = %.2f\n", _RAIN_STORM, rcd.wStormRain / 100.0 );
printf("%s = ", _STORM_START_DATE);
PrintDate(rcd.wStormStart);
printf("\n");

if (includeLoop2Data) printf("%s = %.2f\n", _RAIN_LAST_15M, rcd2.last15mRain / 100.0);
if (includeLoop2Data) printf("%s = %.2f\n", _RAIN_LAST_HOUR, rcd2.lastHourRain / 100.0);
printf("%s = %.2f\n", _DAY_RAIN, rcd.wRainDay / 100.0);
printf("%s = %.2f\n", _MONTH_RAIN, rcd.wRainMonth / 100.0);
printf("%s = %.2f\n", _YEAR_RAIN, rcd.wRainYear / 100.0);
Expand Down
68 changes: 67 additions & 1 deletion dhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
/* exports */
extern int CheckCRC(int nCnt, char *pData);
extern void GetRTData(char *szData);
extern void GetRT2Data(char *szData);
extern void GetHLData(char *szData);
extern void PrintRTData(void);
extern void PrintRTData(bool includeLoop2Data);
extern void PrintHLData(void);
extern void PrintGDData(uint8_t * pData);
extern void PrintTime(char *szData);
Expand Down Expand Up @@ -284,6 +285,71 @@ typedef struct t_RTDATA
} PACKED RTDATA;


/* Definition of Davis LOOP2 data packet */
typedef struct t_RTDATA2
{
uint8_t yACK; /* -1 ACK from stream */
char cL; /* 0 character "L" */
char cO; /* 1 character "O" */
char cO1; /* 2 character "O" */
char cP; /* 3 character "P" (RevA) or the current */
/* 3-hour Barometer trend as follows: */
/* 196 = Falling Rapidly */
/* 236 = Falling Slowly */
/* 0 = Steady */
/* 20 = Rising Slowly */
/* 60 = Rising Rapidly */
/* any other value is 3-hour data not available */
uint8_t packetType; /* 4 Always zero for current firmware release */
uint16_t unused; /* 5 Unused, filled with 0x7FFF */
uint16_t barometer; /* 7 Current barometer as (Hg / 1000) */
int16_t insideTemp; /* 9 Inside Temperature as (DegF / 10) */
uint8_t insideHum; /* 11 Inside Humidity as percentage */
int16_t outsideTemp; /* 12 Outside Temperature as (DegF / 10) */
uint8_t windSpeed; /* 14 Wind Speed */
uint8_t unused2; /* 15 Unused, filled with 0xFF */
uint16_t windDir; /* 16 Wind Direction in degress */
uint16_t avgWindSpd10m; /* 18 10-minute average wind speed */
uint16_t avgWindSpd2m; /* 20 2-minute average wind speed */
uint16_t windGust10m; /* 22 10-minute wind gust maximum? */
uint16_t windGust10mDir; /* 24 10-minute wind gust direction */
uint16_t unused3; /* 26 Unused, filled with 0x7FFF */
uint16_t unused4; /* 28 Unused, filled with 0x7FFF */
int16_t dewPoint; /* 30 Signed two byte value to the whole DegF */
uint16_t unused5; /* 32 Unused, filled with 0x7FFF */
uint8_t outsideHum; /* 33 Outside humidity in % */
uint8_t unused6; /* 34 Unused, filled with 0xFF */
int16_t heatIndex; /* 35 Heat index in DegF */
int16_t windChill; /* 37 Wind Chill in DegF */
int16_t thswIndex; /* 39 THSW Index in DegF */
uint16_t rainRate; /* 41 Rain rate in clicks per hour */
uint8_t uvLevel; /* 43 UV Level */
uint16_t solarRad; /* 44 Solar Radiation (W/m^2) */
uint16_t stormRain; /* 46 Total Storm Rain (number of rain clicks) */
uint16_t stormStart; /* 48 Start date of current storm */
/* mmmmdddddyyyyyyy */
uint16_t dayRain; /* 50 Rain Today */
uint16_t last15mRain; /* 52 Rain in the last 15 minutes */
uint16_t lastHourRain; /* 54 Rain in the last hour */
uint16_t dailyET; /* 56 Daily ET */
uint16_t last24hrRain; /* 58 Rain in the last 24 hours */
uint8_t barRedMethod; /* 60 Barometric reduction method */
/* 0 - user offset */
/* 1 - altimeter setting */
/* 2 - NOAA bar reduction (always for VP2) */
uint16_t userBarOffset; /* 61 User-entered barometric offset (1000th/") */
uint16_t barCaliNumber; /* 63 Calibration offset in 1000th of an inch */
uint16_t barRaw; /* 65 Barometric sensor raw reading (1000th/") */
uint16_t barAbsPress; /* 67 Raw Barometric reading - user offset */
uint16_t altSetting; /* 69 Altimeter setting (1000th/") */
uint8_t unused7; /* 71 Unused, filled with 0xFF */
uint8_t unused8; /* 72`Undefined */
uint8_t yLF; /* 95 Line Feed (\n) 0x0a */
uint8_t yCR; /* 96 Carraige Return (\r) 0x0d */
uint16_t WCRC; /* 97 CRC check bytes (CCITT-16 standard) */
} PACKED RTDATA2;


/* Definition of Davis HILOW packet */
typedef struct t_HLDATA
{
Expand Down
10 changes: 9 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ int main(int argc, char *argv[])
time_t tt;
int16_t i;
int16_t nCnt;
bool gotV2Data = true;


/* Get command line parms */
Expand Down Expand Up @@ -343,7 +344,14 @@ int main(int argc, char *argv[])
}
GetRTData(szSerBuffer); /* get data to struct */

PrintRTData(); /* ...and to stdout */
/* Get LOOP 2 data */
if (runCommand("LPS 2 1\n", 99, "real time v2")) {
gotV2Data = false;
} else {
GetRT2Data(szSerBuffer); /* get data to struct */
}

PrintRTData(gotV2Data); /* ...and to stdout */
}

/* all done, exit */
Expand Down
10 changes: 10 additions & 0 deletions names.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#endif

/* real time data */
#define _NEXT_RECORD "rtNextArchiveRecord"
#define _BARO_TREND "rtBaroTrend"
#define _BARO_TREND_IMG "rtBaroTrendImg"
#define _BARO_CURR "rtBaroCurr"
Expand All @@ -35,15 +36,24 @@
#define _OUTSIDE_TEMP "rtOutsideTemp"
#define _WIND_SPEED "rtWindSpeed"
#define _WIND_AVG_SPEED "rtWindAvgSpeed"
#define _WIND_2M_AVG_SPEED "rtWind2mAvgSpeed"
#define _WIND_DIR "rtWindDir"
#define _WIND_DIR_ROSE "rtWindDirRose"
#define _WIND_10M_GUST_SPEED "rtWind10mGustMaxSpeed"
#define _WIND_10M_GUST_DIR "rtWind10mGustMaxDir"
#define _WIND_10M_GUST_DIR_ROSE "rtWind10mGustMaxDirRose"
#define _OUTSIDE_HUM "rtOutsideHum"
#define _RAIN_RATE "rtRainRate"
#define _IS_RAINING "rtIsRaining"
#define _UV_LEVEL "rtUVLevel"
#define _SOLAR_RAD "rtSolarRad"
#define _HEAT_INDEX "rtHeatIndex"
#define _WIND_CHILL "rtWindChill"
#define _THSW_INDEX "rtThswIndex"
#define _RAIN_STORM "rtRainStorm"
#define _STORM_START_DATE "rtStormStartDate"
#define _RAIN_LAST_15M "rt15mRain"
#define _RAIN_LAST_HOUR "rtHourRain"
#define _DAY_RAIN "rtDayRain"
#define _MONTH_RAIN "rtMonthRain"
#define _YEAR_RAIN "rtYearRain"
Expand Down

0 comments on commit 92a72b2

Please sign in to comment.