-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Update oregon_scientific.c #2086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,23 +50,25 @@ static float get_os_temperature(unsigned char *message) | |
{ | ||
float temp_c = 0; | ||
temp_c = (((message[5] >> 4) * 100) + ((message[4] & 0x0f) * 10) + ((message[4] >> 4) & 0x0f)) / 10.0F; | ||
if (message[5] & 0x0f) | ||
// Correct 0x0f to 0x08: | ||
if (message[5] & 0x08) { | ||
temp_c = -temp_c; | ||
} | ||
return temp_c; | ||
} | ||
|
||
static float get_os_rain_rate(unsigned char *message) | ||
{ | ||
float rain_rate = 0; // Nibbles 11..8 rain rate, LSD = 0.01 inches per hour | ||
rain_rate = (((message[5] & 0x0f) * 1000) + ((message[5] >> 4) * 100) + ((message[4] & 0x0f) * 10) + ((message[4] >> 4) & 0x0f)) / 100.0F; | ||
float rain_rate = 0.0F; // Nibbles 11..8 rain rate, LSD = 0.1 units per hour, 4321 = 123.4 units per hour | ||
rain_rate = (((message[5] & 0x0f) * 100) + ((message[5] >> 4) * 10) + (message[4] & 0x0f) + ((message[4] >> 4) & 0x0f)) / 10.0F; | ||
return rain_rate; | ||
} | ||
|
||
static float get_os_total_rain(unsigned char *message) | ||
{ | ||
float total_rain = 0.0F; // Nibbles 17..12 Total rain, LSD = 0.001, 543210 = 012.345 inches | ||
float total_rain = 0.0F; // Nibbles 17..12 Total rain, LSD = 0.001, 654321 = 123.456 | ||
total_rain = (message[8] & 0x0f) * 100.0F | ||
+ ((message[8] >> 4) & 0x0f) * 10.0F + (message[7] & 0x0f) | ||
+ ((message[8] >> 4) & 0x0f) * 10.0F + (message[7] & 0x0f) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing whitespace |
||
+ ((message[7] >> 4) & 0x0f) / 10.0F + (message[6] & 0x0f) / 100.0F | ||
+ ((message[6] >> 4) & 0x0f) / 1000.0F; | ||
return total_rain; | ||
|
@@ -375,7 +377,18 @@ static int oregon_scientific_v2_1_decode(r_device *decoder, bitbuffer_t *bitbuff | |
else if (sensor_id == ID_THN132N && msg_bits == 64) { | ||
if (validate_os_v2_message(decoder, msg, 64, msg_bits, 12) != 0) | ||
return 0; | ||
// Sanity check BCD digits | ||
if ( ((msg[5] >> 4) & 0x0F) > 9 || (msg[4] & 0x0F) > 9 || ((msg[4] >> 4) & 0x0F) > 9 ) { | ||
decoder_log(decoder, 1, __func__, "THN132N Message failed BCD sanity check."); | ||
return DECODE_FAIL_SANITY; | ||
} | ||
float temp_c = get_os_temperature(msg); | ||
// Sanity check value | ||
if (temp_c > 70 || temp_c < -50) { | ||
decoder_logf(decoder, 1, __func__, "THN132N Message failed values sanity check: temperature_C %3.1fC.", temp_c); | ||
return DECODE_FAIL_SANITY; | ||
} | ||
|
||
/* clang-format off */ | ||
data = data_make( | ||
"model", "", DATA_STRING, "Oregon-THN132N", | ||
|
@@ -514,7 +527,18 @@ static int oregon_scientific_v2_1_decode(r_device *decoder, bitbuffer_t *bitbuff | |
else if (sensor_id == ID_UVR128 && msg_bits == 148) { | ||
if (validate_os_v2_message(decoder, msg, 148, msg_bits, 12) != 0) | ||
return 0; | ||
// Sanity check BCD digits | ||
if ( ((msg[4] >> 4) & 0x0F) > 9 || (msg[4] & 0x0F) > 9 ) { | ||
decoder_log(decoder, 1, __func__, "UVR128 Message failed BCD sanity check."); | ||
return DECODE_FAIL_SANITY; | ||
} | ||
int uvidx = get_os_uv(msg); | ||
// Sanity check value | ||
if (uvidx < 0 || uvidx > 25) { | ||
decoder_logf(decoder, 1, __func__, "UVR128 Message failed values sanity check: uv %u.", uvidx); | ||
return DECODE_FAIL_SANITY; | ||
} | ||
|
||
/* clang-format off */ | ||
data = data_make( | ||
"model", "", DATA_STRING, "Oregon-UVR128", | ||
|
@@ -624,8 +648,18 @@ static int oregon_scientific_v3_decode(r_device *decoder, bitbuffer_t *bitbuffer | |
if (sensor_id == ID_THGR810 || sensor_id == ID_THGR810a) { | ||
if (validate_os_checksum(decoder, msg, 15) != 0) | ||
return DECODE_FAIL_MIC; | ||
// Sanity check BCD digits | ||
if ( ((msg[5] >> 4) & 0x0F) > 9 || (msg[4] & 0x0F) > 9 || ((msg[4] >> 4) & 0x0F) > 9 || (msg[6] & 0x0F) > 9 || ((msg[6] >> 4) & 0x0F) > 9 ) { | ||
decoder_log(decoder, 1, __func__, "THGR810 Message failed BCD sanity check."); | ||
return DECODE_FAIL_SANITY; | ||
} | ||
float temp_c = get_os_temperature(msg); | ||
int humidity = get_os_humidity(msg); | ||
// Sanity check values | ||
if (temp_c > 70 || temp_c < -50 || humidity < 0 || humidity > 98) { | ||
decoder_logf(decoder, 1, __func__, "THGR810 Message failed values sanity check: temperature_C %3.1fC humidity %d%%.", temp_c, humidity); | ||
return DECODE_FAIL_SANITY; | ||
} | ||
/* clang-format off */ | ||
data = data_make( | ||
"model", "", DATA_STRING, "Oregon-THGR810", | ||
|
@@ -674,16 +708,23 @@ static int oregon_scientific_v3_decode(r_device *decoder, bitbuffer_t *bitbuffer | |
else if (sensor_id == ID_PCR800) { | ||
if (validate_os_checksum(decoder, msg, 18) != 0) | ||
return DECODE_FAIL_MIC; | ||
// Sanity check BCD digits | ||
if ( (msg[8] & 0x0F) > 9 || ((msg[8] >> 4) & 0x0F) > 9 || (msg[7] & 0x0F) > 9 || ((msg[7] >> 4) & 0x0F) > 9 || (msg[6] & 0x0F) > 9 || ((msg[6] >> 4) & 0x0F) > 9 || (msg[5] & 0x0F) > 9 || ((msg[5] >> 4) & 0x0F) > 9 || (msg[4] & 0x0F) > 9 || ((msg[4] >> 4) & 0x0F) > 9 ) { | ||
decoder_log(decoder, 1, __func__, "PCR800 Message failed BCD sanity check."); | ||
return DECODE_FAIL_SANITY; | ||
} | ||
|
||
float rain_rate = get_os_rain_rate(msg); | ||
float total_rain = get_os_total_rain(msg); | ||
|
||
/* clang-format off */ | ||
data = data_make( | ||
"model", "", DATA_STRING, "Oregon-PCR800", | ||
"id", "House Code", DATA_INT, get_os_rollingcode(msg), | ||
"channel", "Channel", DATA_INT, get_os_channel(msg, sensor_id), | ||
"battery_ok", "Battery", DATA_INT, !get_os_battery(msg), | ||
"rain_rate_in_h", "Rain Rate", DATA_FORMAT, "%3.1f in/h", DATA_DOUBLE, rain_rate, | ||
"rain_in", "Total Rain", DATA_FORMAT, "%3.1f in", DATA_DOUBLE, total_rain, | ||
"rain_rate_in_h", "Rain Rate", DATA_FORMAT, "%5.1f in/h", DATA_DOUBLE, rain_rate, | ||
"rain_in", "Total Rain", DATA_FORMAT, "%7.3f in", DATA_DOUBLE, total_rain, | ||
NULL); | ||
/* clang-format on */ | ||
decoder_output_data(decoder, data); | ||
|
@@ -710,9 +751,22 @@ static int oregon_scientific_v3_decode(r_device *decoder, bitbuffer_t *bitbuffer | |
else if (sensor_id == ID_WGR800 || sensor_id == ID_WGR800a) { | ||
if (validate_os_checksum(decoder, msg, 17) != 0) | ||
return DECODE_FAIL_MIC; | ||
// Sanity check BCD digits | ||
if ( (msg[5] & 0x0F) > 9 || ((msg[6] >> 4) & 0x0F) > 9 || (msg[6] & 0x0F) > 9 || ((msg[7] >> 4) & 0x0F) > 9 || (msg[7] & 0x0F) > 9 || ((msg[8] >> 4) & 0x0F) > 9 ) { | ||
decoder_log(decoder, 1, __func__, "WGR800 Message failed BCD sanity check."); | ||
return DECODE_FAIL_SANITY; | ||
} | ||
|
||
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; | ||
float quadrant = (0x0f&(msg[4]>>4))*22.5F; | ||
|
||
// Sanity check values | ||
if (gustWindspeed < 0 || gustWindspeed > 56 || avgWindspeed < 0 || avgWindspeed > 56 || quadrant < 0 || quadrant > 337.5) { | ||
decoder_logf(decoder, 1, __func__, "WGR800 Message failed values sanity check: wind_max_m_s %2.1f wind_avg_m_s %2.1f wind_dir_deg %3.1f.", gustWindspeed, avgWindspeed, quadrant); | ||
return DECODE_FAIL_SANITY; | ||
} | ||
|
||
/* clang-format off */ | ||
data = data_make( | ||
"model", "", DATA_STRING, "Oregon-WGR800", | ||
|
@@ -868,7 +922,7 @@ static char *output_fields[] = { | |
r_device oregon_scientific = { | ||
.name = "Oregon Scientific Weather Sensor", | ||
.modulation = OOK_PULSE_MANCHESTER_ZEROBIT, | ||
.short_width = 440, // Nominal 1024Hz (488µs), but pulses are shorter than pauses | ||
.short_width = 440, // Nominal 1024Hz (488µs), but pulses are shorter than pauses | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UTF8/Latin1 conversion problems introduced an invalid code here. Best to replace |
||
.long_width = 0, // not used | ||
.reset_limit = 2400, | ||
.decode_fn = &oregon_scientific_decode, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is later used as "rain_rate_in_h", can you confirm that units is in/h here? Or Is a unit 0.1 in, thus the change of scale wrong here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, good question. Not sure why I edited that section... The sensor generated rain_rate lags so much I don't use it myself (I calculate it based on when the rain_total field changes.) I used the page here: https://www.bashewa.com/wmr200-protocol.php as a starting point and compared it with the data I get from a PCR800 sensor. I believe the PCR800 reports it in units of 0.1 inches per hour.