From 2c48d4dfbbf613a6da3c8a46ee6ce9d3d9357a2d Mon Sep 17 00:00:00 2001 From: "Roger.Knobbe" Date: Thu, 4 Feb 2016 18:40:00 -0800 Subject: [PATCH] starting to migrate to data_make --- src/devices/oregon_scientific.c | 60 ++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/src/devices/oregon_scientific.c b/src/devices/oregon_scientific.c index 749628b5..acf50e80 100644 --- a/src/devices/oregon_scientific.c +++ b/src/devices/oregon_scientific.c @@ -14,7 +14,8 @@ #define ID_THN132N 0xec40 // same as THR228N but different packet size #define ID_RTGN318 0x0cc3 // warning: id is from 0x0cc3 and 0xfcc3 #define ID_PCR800 0x2914 - +#define ID_THGR810 0xf824 +#define ID_WGR800 0x1984 float get_os_temperature(unsigned char *message, unsigned int sensor_id) { // sensor ID included to support sensors with temp in different position @@ -313,6 +314,9 @@ return 0; static int oregon_scientific_v3_parser(bitbuffer_t *bitbuffer) { bitrow_t *bb = bitbuffer->bb; + data_t *data; + char time_str[LOCAL_TIME_BUFLEN]; + local_time_str(0, time_str); // Check stream for possible Oregon Scientific v3 protocol data (skip part of first and last bytes to get past sync/startup bit errors) if ((((bb[0][0]&0xf) == 0x0f) && (bb[0][1] == 0xff) && ((bb[0][2]&0xc0) == 0xc0)) || @@ -367,12 +371,21 @@ static int oregon_scientific_v3_parser(bitbuffer_t *bitbuffer) { if ((msg[0] == 0xf8) && (msg[1] == 0x24)) { if (validate_os_checksum(msg, 15) == 0) { - int channel = get_os_channel(msg, 0xf824); - float temp_c = get_os_temperature(msg, 0xf824); - int humidity = get_os_humidity(msg, 0xf824); - int battery = get_os_battery(msg, 0xf824); + int channel = get_os_channel(msg, ID_THGR810); + float temp_c = get_os_temperature(msg, ID_THGR810); + int humidity = get_os_humidity(msg, ID_THGR810); + int battery = get_os_battery(msg, ID_THGR810); + data = data_make("time", "", DATA_STRING, time_str, + "model", "", DATA_STRING, "Weather Sensor THGR810", + "id", "House Code", DATA_INT, get_os_rollingcode(msg, ID_THGR810), + "channel", "Channel", DATA_INT, channel, + "battery", "Battery", DATA_STRING, battery?"LOW":"OK", + "temperature_C", "Celcius", DATA_FORMAT, "%.02f C", DATA_DOUBLE, temp_c, + "temperature_F", "Fahrenheit", DATA_FORMAT, "%.02f F", DATA_DOUBLE, ((temp_c*9)/5)+32, + "humidity", "Humidity", DATA_FORMAT, "%u %%", DATA_INT, humidity, + NULL); - fprintf(stdout,"Weather Sensor THGR810 Channel %d Battery %s Temp: %3.1fC %3.1fF Humidity: %d%%\n", channel, battery ? "LOW":"OK", temp_c, ((temp_c*9)/5)+32, humidity); + data_acquired_handler(data); } return 1; //msg[k] = ((msg[k] & 0x0F) << 4) + ((msg[k] & 0xF0) >> 4); } else if ((msg[0] == 0xd8) && (msg[1] == 0x74)) { @@ -387,19 +400,42 @@ static int oregon_scientific_v3_parser(bitbuffer_t *bitbuffer) { int battery = get_os_battery(msg, ID_PCR800); float rain_rate=get_os_rain_rate(msg, ID_PCR800); float total_rain=get_os_total_rain(msg, ID_PCR800); - fprintf(stdout, "Weather Sensor PCR800 Rain Gauge Channel %d Battery %s Rate %3.1f in/hr Total %3.1f in\n", - channel, battery?"LOW":"OK", rain_rate, total_rain); + data = data_make("time", "", DATA_STRING, time_str, + "model", "", DATA_STRING, "Weather Sensor PCR800 Rain Gauge", + "id", "House Code", DATA_INT, get_os_rollingcode(msg,ID_PCR800), + "channel", "Channel", DATA_INT, channel, + "battery", "Battery", DATA_STRING, battery?"LOW":"OK", + "rain_rate", "Rain Rate", DATA_FORMAT, "%3.1f in/hr", DATA_DOUBLE, rain_rate, + "total_rain", "Total Rain", DATA_FORMAT, "%3.1f in", DATA_DOUBLE, total_rain, + NULL); + data_acquired_handler(data); } return 1; } else if ((msg[0] == 0x19) && (msg[1] == 0x84)) { if (validate_os_checksum(msg, 17) == 0) { // 13..11 Current Speed, meters per second, LSD is 0.1 m/s // 16..14 Average speed, meters per second, LSD is 0.1 m/s - float gustWindspeed = ((msg[7]>>4)&0x0f) *10.0F + (msg[6]&0x0f) *1.0F + ((msg[6]>>4)&0x0f) /10.0F; - float avgWindspeed = (msg[8]&0x0f) * 10.0F + ((msg[8]>>4)&0x0f) *1.0F + (msg[7]&0x0f) / 10.0F; - int battery = get_os_battery(msg, 0xf819); +/* + int i; + printf("13..11 current speed, 16..14 average speed\n"); + for (i=0;i<34;i+=2) printf("%-2d ", i/10); printf("\n"); + for (i=0;i<34;i+=2) printf("%-2d ",i%10);printf("\n"); + for (i=0;i<17;i++) printf("%02x ", msg[i]); printf("\n"); +*/ + float gustWindspeed = (msg[5]&0x0f) /10.0F + ((msg[6]>>4)&0x0f) *1.0F + (msg[6]&0x0f) * 10.0F; + float avgWindspeed = ((msg[7]>>4)&0x0f) / 10.0F + (msg[7]&0x0f) *1.0F + ((msg[8]>>4)&0x0f) * 10.0F; + int battery = get_os_battery(msg, ID_WGR800); float quadrant = (0x0f&(msg[5]>>4))*22.5; - fprintf(stdout, "Weather Sensor WGR800 Wind Gauge Battery %s Gust Wind Speed : %2.0f m/s Wind direction %3.0f dgrs\n", battery?"LOW":"OK", gustWindspeed, quadrant); + data = data_make("time", "", DATA_STRING, time_str, + "model", "", DATA_STRING, "Weather Sensor WGR800 Wind Gauge", + "id", "House Code", DATA_INT, get_os_rollingcode(msg, ID_WGR800), + "channel", "Channel", DATA_INT, get_os_channel(msg, ID_WGR800), + "battery", "Battery", DATA_STRING, battery?"LOW":"OK", + "gust", "Gust", DATA_FORMAT, "%2.1f m/s",DATA_DOUBLE, gustWindspeed, + "average", "Average", DATA_FORMAT, "%2.1f m/s",DATA_DOUBLE, avgWindspeed, + "direction", "Direction", DATA_FORMAT, "%3.1f degrees",DATA_DOUBLE, quadrant, + NULL); + data_acquired_handler(data); } return 1; } else if ((msg[0] == 0x20) || (msg[0] == 0x21) || (msg[0] == 0x22)