Skip to content

Commit 92a72b2

Browse files
committed
Added LOOP2 packet data to realtime data output
- 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
1 parent 1dd4b55 commit 92a72b2

File tree

4 files changed

+156
-39
lines changed

4 files changed

+156
-39
lines changed

dhandler.c

+70-37
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ static char szForeStrings[] =
265265
"Mostly clear and cooler.\0\0" ;
266266

267267

268-
static RTDATA rcd; /* the one and only real time weather packet */
268+
static RTDATA rcd; /* the one and only v1 real time weather packet */
269+
static RTDATA2 rcd2; /* the one and only v2 real time weather packet */
269270
static HLDATA hld; /* the one and only highs/lows packet */
270271

271272
/* local functions */
@@ -347,6 +348,17 @@ void GetRTData(char *szData)
347348

348349

349350

351+
/*--------------------------------------------------------------------------
352+
GetRT2Data
353+
Gets the real time weather data packet v2 to the static RTDATA2 struct.
354+
----------------------------------------------------------------------------*/
355+
void GetRT2Data(char *szData)
356+
{
357+
memcpy((char*)&rcd2, szData, sizeof(RTDATA2));
358+
}
359+
360+
361+
350362

351363
/*--------------------------------------------------------------------------
352364
GetHLData
@@ -359,14 +371,55 @@ void GetHLData(char *szData)
359371

360372

361373

374+
375+
/*--------------------------------------------------------------------------
376+
GetHLData
377+
Gets the high/low weather data packet to the static HLDATA struct.
378+
----------------------------------------------------------------------------*/
379+
char* getWindRose(uint8_t bearing) {
380+
if(bearing >= 347 && bearing < 12) /* compass rose version */
381+
return "N";
382+
else if(bearing >= 12 && bearing < 34)
383+
return "NNE";
384+
else if(bearing >= 34 && bearing < 57)
385+
return "NE";
386+
else if(bearing >= 57 && bearing < 79)
387+
return "ENE";
388+
else if(bearing >= 79 && bearing < 102)
389+
return "E";
390+
else if(bearing >= 102 && bearing < 124)
391+
return "ESE";
392+
else if(bearing >= 124 && bearing < 147)
393+
return "SE";
394+
else if(bearing >= 147 && bearing < 170)
395+
return "SSE";
396+
else if(bearing >= 170 && bearing < 192)
397+
return "S";
398+
else if(bearing >= 192 && bearing < 214)
399+
return "SSW";
400+
else if(bearing >= 214 && bearing < 237)
401+
return "SW";
402+
else if(bearing >= 237 && bearing < 259)
403+
return "WSW";
404+
else if(bearing >= 259 && bearing < 280)
405+
return "W";
406+
else if(bearing >= 280 && bearing < 303)
407+
return "WNW";
408+
else if(bearing >= 303 && bearing < 347)
409+
return "NW";
410+
else /* >326 <347 */
411+
return "NNW";
412+
}
413+
362414
/*--------------------------------------------------------------------------
363415
PrintRTData
364416
Dumps the real time weather data to stdout.
365417
----------------------------------------------------------------------------*/
366-
void PrintRTData(void)
418+
void PrintRTData(bool includeLoop2Data)
367419
{
368420
int16_t i;
369421

422+
printf("%s = 0x%04x\n", _NEXT_RECORD, rcd.wNextRec );
370423
/* 3-hour rolling baro trend */
371424
i = rcd.cP;
372425
printf("%s = ", _BARO_TREND);
@@ -392,42 +445,17 @@ void PrintRTData(void)
392445
printf("%s = %d\n", _INSIDE_HUM, rcd.yInsideHum );
393446
printf("%s = %.1f\n", _OUTSIDE_TEMP, ((int16_t)rcd.wOutsideTemp) / 10.0 );
394447
printf("%s = %d\n", _WIND_SPEED, rcd.yWindSpeed );
395-
printf("%s = %d\n", _WIND_AVG_SPEED, rcd.yAvgWindSpeed );
448+
if (includeLoop2Data) {
449+
printf("%s = %.1f\n", _WIND_AVG_SPEED, (double)rcd2.avgWindSpd10m / 10.0 );
450+
} else {
451+
printf("%s = %d\n", _WIND_AVG_SPEED, rcd.yAvgWindSpeed );
452+
}
453+
if (includeLoop2Data) printf("%s = %.1f\n", _WIND_2M_AVG_SPEED, (double)rcd2.avgWindSpd2m / 10.0 );
396454
printf("%s = %d\n", _WIND_DIR, rcd.wWindDir );
397-
printf("%s = ", _WIND_DIR_ROSE);
398-
if(rcd.wWindDir >= 347 && rcd.wWindDir < 12) /* compass rose version */
399-
printf("N\n");
400-
else if(rcd.wWindDir >= 12 && rcd.wWindDir < 34)
401-
printf("NNE\n");
402-
else if(rcd.wWindDir >= 34 && rcd.wWindDir < 57)
403-
printf("NE\n");
404-
else if(rcd.wWindDir >= 57 && rcd.wWindDir < 79)
405-
printf("ENE\n");
406-
else if(rcd.wWindDir >= 79 && rcd.wWindDir < 102)
407-
printf("E\n");
408-
else if(rcd.wWindDir >= 102 && rcd.wWindDir < 124)
409-
printf("ESE\n");
410-
else if(rcd.wWindDir >= 124 && rcd.wWindDir < 147)
411-
printf("SE\n");
412-
else if(rcd.wWindDir >= 147 && rcd.wWindDir < 170)
413-
printf("SSE\n");
414-
else if(rcd.wWindDir >= 170 && rcd.wWindDir < 192)
415-
printf("S\n");
416-
else if(rcd.wWindDir >= 192 && rcd.wWindDir < 214)
417-
printf("SSW\n");
418-
else if(rcd.wWindDir >= 214 && rcd.wWindDir < 237)
419-
printf("SW\n");
420-
else if(rcd.wWindDir >= 237 && rcd.wWindDir < 259)
421-
printf("WSW\n");
422-
else if(rcd.wWindDir >= 259 && rcd.wWindDir < 280)
423-
printf("W\n");
424-
else if(rcd.wWindDir >= 280 && rcd.wWindDir < 303)
425-
printf("WNW\n");
426-
else if(rcd.wWindDir >= 303 && rcd.wWindDir < 347)
427-
printf("NW\n");
428-
else /* >326 <347 */
429-
printf("NNW\n");
430-
455+
printf("%s = %s\n", _WIND_DIR_ROSE, getWindRose(rcd.wWindDir) );
456+
if (includeLoop2Data) printf("%s = %d\n", _WIND_10M_GUST_SPEED, rcd2.windGust10m );
457+
if (includeLoop2Data) printf("%s = %d\n", _WIND_10M_GUST_DIR, rcd2.windGust10mDir );
458+
if (includeLoop2Data) printf("%s = %s\n", _WIND_10M_GUST_DIR_ROSE, getWindRose(rcd2.windGust10mDir) );
431459
printf("%s = %d\n", _OUTSIDE_HUM, rcd.yOutsideHum );
432460
printf("%s = %.2f\n", _RAIN_RATE, rcd.wRainRate / 100.0 );
433461
printf("%s = %s\n", _IS_RAINING, rcd.wRainRate ? "yes" : "no");
@@ -441,11 +469,16 @@ void PrintRTData(void)
441469
printf("n/a\n");
442470
else
443471
printf("%d\n", rcd.wSolarRad );
472+
if (includeLoop2Data) printf("%s = %d\n", _HEAT_INDEX, rcd2.heatIndex );
473+
if (includeLoop2Data) printf("%s = %d\n", _WIND_CHILL, rcd2.windChill );
474+
if (includeLoop2Data) printf("%s = %d\n", _THSW_INDEX, rcd2.thswIndex );
444475
printf("%s = %.2f\n", _RAIN_STORM, rcd.wStormRain / 100.0 );
445476
printf("%s = ", _STORM_START_DATE);
446477
PrintDate(rcd.wStormStart);
447478
printf("\n");
448479

480+
if (includeLoop2Data) printf("%s = %.2f\n", _RAIN_LAST_15M, rcd2.last15mRain / 100.0);
481+
if (includeLoop2Data) printf("%s = %.2f\n", _RAIN_LAST_HOUR, rcd2.lastHourRain / 100.0);
449482
printf("%s = %.2f\n", _DAY_RAIN, rcd.wRainDay / 100.0);
450483
printf("%s = %.2f\n", _MONTH_RAIN, rcd.wRainMonth / 100.0);
451484
printf("%s = %.2f\n", _YEAR_RAIN, rcd.wRainYear / 100.0);

dhandler.h

+67-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
/* exports */
3232
extern int CheckCRC(int nCnt, char *pData);
3333
extern void GetRTData(char *szData);
34+
extern void GetRT2Data(char *szData);
3435
extern void GetHLData(char *szData);
35-
extern void PrintRTData(void);
36+
extern void PrintRTData(bool includeLoop2Data);
3637
extern void PrintHLData(void);
3738
extern void PrintGDData(uint8_t * pData);
3839
extern void PrintTime(char *szData);
@@ -284,6 +285,71 @@ typedef struct t_RTDATA
284285
} PACKED RTDATA;
285286

286287

288+
/* Definition of Davis LOOP2 data packet */
289+
typedef struct t_RTDATA2
290+
{
291+
uint8_t yACK; /* -1 ACK from stream */
292+
char cL; /* 0 character "L" */
293+
char cO; /* 1 character "O" */
294+
char cO1; /* 2 character "O" */
295+
char cP; /* 3 character "P" (RevA) or the current */
296+
/* 3-hour Barometer trend as follows: */
297+
/* 196 = Falling Rapidly */
298+
/* 236 = Falling Slowly */
299+
/* 0 = Steady */
300+
/* 20 = Rising Slowly */
301+
/* 60 = Rising Rapidly */
302+
/* any other value is 3-hour data not available */
303+
uint8_t packetType; /* 4 Always zero for current firmware release */
304+
uint16_t unused; /* 5 Unused, filled with 0x7FFF */
305+
uint16_t barometer; /* 7 Current barometer as (Hg / 1000) */
306+
int16_t insideTemp; /* 9 Inside Temperature as (DegF / 10) */
307+
uint8_t insideHum; /* 11 Inside Humidity as percentage */
308+
int16_t outsideTemp; /* 12 Outside Temperature as (DegF / 10) */
309+
uint8_t windSpeed; /* 14 Wind Speed */
310+
uint8_t unused2; /* 15 Unused, filled with 0xFF */
311+
uint16_t windDir; /* 16 Wind Direction in degress */
312+
uint16_t avgWindSpd10m; /* 18 10-minute average wind speed */
313+
uint16_t avgWindSpd2m; /* 20 2-minute average wind speed */
314+
uint16_t windGust10m; /* 22 10-minute wind gust maximum? */
315+
uint16_t windGust10mDir; /* 24 10-minute wind gust direction */
316+
uint16_t unused3; /* 26 Unused, filled with 0x7FFF */
317+
uint16_t unused4; /* 28 Unused, filled with 0x7FFF */
318+
int16_t dewPoint; /* 30 Signed two byte value to the whole DegF */
319+
uint16_t unused5; /* 32 Unused, filled with 0x7FFF */
320+
uint8_t outsideHum; /* 33 Outside humidity in % */
321+
uint8_t unused6; /* 34 Unused, filled with 0xFF */
322+
int16_t heatIndex; /* 35 Heat index in DegF */
323+
int16_t windChill; /* 37 Wind Chill in DegF */
324+
int16_t thswIndex; /* 39 THSW Index in DegF */
325+
uint16_t rainRate; /* 41 Rain rate in clicks per hour */
326+
uint8_t uvLevel; /* 43 UV Level */
327+
uint16_t solarRad; /* 44 Solar Radiation (W/m^2) */
328+
uint16_t stormRain; /* 46 Total Storm Rain (number of rain clicks) */
329+
uint16_t stormStart; /* 48 Start date of current storm */
330+
/* mmmmdddddyyyyyyy */
331+
uint16_t dayRain; /* 50 Rain Today */
332+
uint16_t last15mRain; /* 52 Rain in the last 15 minutes */
333+
uint16_t lastHourRain; /* 54 Rain in the last hour */
334+
uint16_t dailyET; /* 56 Daily ET */
335+
uint16_t last24hrRain; /* 58 Rain in the last 24 hours */
336+
uint8_t barRedMethod; /* 60 Barometric reduction method */
337+
/* 0 - user offset */
338+
/* 1 - altimeter setting */
339+
/* 2 - NOAA bar reduction (always for VP2) */
340+
uint16_t userBarOffset; /* 61 User-entered barometric offset (1000th/") */
341+
uint16_t barCaliNumber; /* 63 Calibration offset in 1000th of an inch */
342+
uint16_t barRaw; /* 65 Barometric sensor raw reading (1000th/") */
343+
uint16_t barAbsPress; /* 67 Raw Barometric reading - user offset */
344+
uint16_t altSetting; /* 69 Altimeter setting (1000th/") */
345+
uint8_t unused7; /* 71 Unused, filled with 0xFF */
346+
uint8_t unused8; /* 72`Undefined */
347+
uint8_t yLF; /* 95 Line Feed (\n) 0x0a */
348+
uint8_t yCR; /* 96 Carraige Return (\r) 0x0d */
349+
uint16_t WCRC; /* 97 CRC check bytes (CCITT-16 standard) */
350+
} PACKED RTDATA2;
351+
352+
287353
/* Definition of Davis HILOW packet */
288354
typedef struct t_HLDATA
289355
{

main.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ int main(int argc, char *argv[])
7979
time_t tt;
8080
int16_t i;
8181
int16_t nCnt;
82+
bool gotV2Data = true;
8283

8384

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

346-
PrintRTData(); /* ...and to stdout */
347+
/* Get LOOP 2 data */
348+
if (runCommand("LPS 2 1\n", 99, "real time v2")) {
349+
gotV2Data = false;
350+
} else {
351+
GetRT2Data(szSerBuffer); /* get data to struct */
352+
}
353+
354+
PrintRTData(gotV2Data); /* ...and to stdout */
347355
}
348356

349357
/* all done, exit */

names.h

+10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#endif
2828

2929
/* real time data */
30+
#define _NEXT_RECORD "rtNextArchiveRecord"
3031
#define _BARO_TREND "rtBaroTrend"
3132
#define _BARO_TREND_IMG "rtBaroTrendImg"
3233
#define _BARO_CURR "rtBaroCurr"
@@ -35,15 +36,24 @@
3536
#define _OUTSIDE_TEMP "rtOutsideTemp"
3637
#define _WIND_SPEED "rtWindSpeed"
3738
#define _WIND_AVG_SPEED "rtWindAvgSpeed"
39+
#define _WIND_2M_AVG_SPEED "rtWind2mAvgSpeed"
3840
#define _WIND_DIR "rtWindDir"
3941
#define _WIND_DIR_ROSE "rtWindDirRose"
42+
#define _WIND_10M_GUST_SPEED "rtWind10mGustMaxSpeed"
43+
#define _WIND_10M_GUST_DIR "rtWind10mGustMaxDir"
44+
#define _WIND_10M_GUST_DIR_ROSE "rtWind10mGustMaxDirRose"
4045
#define _OUTSIDE_HUM "rtOutsideHum"
4146
#define _RAIN_RATE "rtRainRate"
4247
#define _IS_RAINING "rtIsRaining"
4348
#define _UV_LEVEL "rtUVLevel"
4449
#define _SOLAR_RAD "rtSolarRad"
50+
#define _HEAT_INDEX "rtHeatIndex"
51+
#define _WIND_CHILL "rtWindChill"
52+
#define _THSW_INDEX "rtThswIndex"
4553
#define _RAIN_STORM "rtRainStorm"
4654
#define _STORM_START_DATE "rtStormStartDate"
55+
#define _RAIN_LAST_15M "rt15mRain"
56+
#define _RAIN_LAST_HOUR "rtHourRain"
4757
#define _DAY_RAIN "rtDayRain"
4858
#define _MONTH_RAIN "rtMonthRain"
4959
#define _YEAR_RAIN "rtYearRain"

0 commit comments

Comments
 (0)