From acc71804ab525281e67e5988f65557efecf3dcc4 Mon Sep 17 00:00:00 2001 From: "Hansi, dl9rdz" Date: Sat, 29 May 2021 12:14:13 +0200 Subject: [PATCH] DFM subtypes enhancement for SondeHub --- RX_FSK/RX_FSK.ino | 61 ++++++++++++++++++------------------- RX_FSK/version.h | 2 +- libraries/SondeLib/DFM.cpp | 2 ++ libraries/SondeLib/RS41.cpp | 5 +++ libraries/SondeLib/Sonde.h | 1 + 5 files changed, 38 insertions(+), 33 deletions(-) diff --git a/RX_FSK/RX_FSK.ino b/RX_FSK/RX_FSK.ino index 52481fe..e34d9d3 100644 --- a/RX_FSK/RX_FSK.ino +++ b/RX_FSK/RX_FSK.ino @@ -2997,6 +2997,19 @@ enum SHState { SH_DISCONNECTED, SH_CONNECTING, SH_CONN_IDLE, SH_CONN_WAITACK }; SHState shState = SH_DISCONNECTED; +/* Sonde.h: enum SondeType { STYPE_DFM, STYPE_DFM09_OLD, STYPE_RS41, STYPE_RS92, STYPE_M10, STYPE_M20, STYPE_DFM06_OLD, STYPE_MP3H }; */ +const char *sondeTypeStrSH[NSondeTypes] = { "DFM", "DFM", "RS41", "RS92", "M10", "M20", "DFM", "MRZ" }; +const char *dfmSubtypeStrSH[16] = { NULL, NULL, NULL, NULL, NULL, NULL, + "DFM06", // 0x06 + "PS15", // 0x07 + NULL, NULL, + "DFM09", // 0x0A + "DFM17", // 0x0B + "DFM09P", // 0x0C + "DFM17", // 0x0D + NULL, NULL + }; + void sondehub_send_data(WiFiClient *client, SondeInfo *s, struct st_sondehub *conf) { Serial.println("sondehub_send_data()"); @@ -3077,39 +3090,23 @@ void sondehub_send_data(WiFiClient *client, SondeInfo *s, struct st_sondehub *co ); w += strlen(w); - if ( s->type == STYPE_DFM09_OLD || s->type == STYPE_DFM06_OLD || s->type == STYPE_M10 || s->type == STYPE_M20 ) { //send frame as unix timestamp for these sonde - //send unix timestamp - sprintf(w, - "\"frame\": \"%d\",", - int(t) - ); - w += strlen(w); - if ( s->type == STYPE_DFM09_OLD) { //fix subtype - sprintf(w, - "\"type\": \"DFM\"," - "\"subtype\": \"DFM09\"," - ); - w += strlen(w); - } else if ( s->type == STYPE_DFM06_OLD) { //fix subtype - sprintf(w, - "\"type\": \"DFM\"," - "\"subtype\": \"DFM06\"," - ); - w += strlen(w); - } else { - sprintf(w, - "\"type\": \"%s\",", - sondeTypeStr[s->type] - ); - w += strlen(w); - } + if ( TYPE_IS_DFM(s->type) || TYPE_IS_METEO(s->type) ) { //send frame as unix timestamp for these sonde + sprintf(w, "\"frame\": %d,", int(t)); } else { - sprintf(w, - "\"frame\": %d," - "\"type\": \"%s\",", - s->frame, sondeTypeStr[s->type] - ); - w += strlen(w); + sprintf(w, "\"frame\": %d,", s->frame); + } + w += strlen(w); + + sprintf(w, "\"type\": \"%s\",", sondeTypeStrSH[s->type]); + w += strlen(w); + + /* if there is a subtype (DFM only) */ + if ( TYPE_IS_DFM(s->type) && s->subtype > 0 && s->subtype < 16 ) { + const char *t = dfmSubtypeStrSH[s->subtype]; + // as in https://github.com/projecthorus/radiosonde_auto_rx/blob/e680221f69a568e1fdb24e76db679233f32cb027/auto_rx/autorx/sonde_specific.py#L84 + if (t) sprintf(w, "\"subtype\": \"%s\",", t); + else sprintf(w, "\"subtype\": \"DFMx%X\",", s->subtype); // Unknown subtype + w += strlen(w); } if (((int)s->temperature != 0) && ((int)s->relativeHumidity != 0)) { diff --git a/RX_FSK/version.h b/RX_FSK/version.h index 365529e..aae9fc3 100644 --- a/RX_FSK/version.h +++ b/RX_FSK/version.h @@ -1,4 +1,4 @@ const char *version_name = "rdzTTGOsonde"; -const char *version_id = "devel20210526"; +const char *version_id = "devel20210529"; const int SPIFFS_MAJOR=2; const int SPIFFS_MINOR=11; diff --git a/libraries/SondeLib/DFM.cpp b/libraries/SondeLib/DFM.cpp index 551caeb..938a4aa 100644 --- a/libraries/SondeLib/DFM.cpp +++ b/libraries/SondeLib/DFM.cpp @@ -269,6 +269,7 @@ void DFM::finddfname(uint8_t *b) if(i==6) { snprintf(sonde.si()->id, 10, "D%x ", id); sonde.si()->validID = true; + sonde.si()->subtype = (st>>4)&0x0F; strncpy(sonde.si()->typestr, typestr[ (st>>4)&0x0F ], 5); return; } @@ -319,6 +320,7 @@ void DFM::finddfname(uint8_t *b) Serial.print("\nNEW AUTOID:"); Serial.println(sonde.si()->id); sonde.si()->validID = true; + sonde.si()->subtype = (st>>4)&0x0F; strncpy(sonde.si()->typestr, typestr[ (st>>4)&0x0F ], 5); } if(dfmstate.nameregok==i) { diff --git a/libraries/SondeLib/RS41.cpp b/libraries/SondeLib/RS41.cpp index 4f5894c..c81fc50 100644 --- a/libraries/SondeLib/RS41.cpp +++ b/libraries/SondeLib/RS41.cpp @@ -462,6 +462,11 @@ static void posrs41(const byte b[], uint32_t b_len, uint32_t p) x = (double)getint32(b, b_len, p)*0.01; y = (double)getint32(b, b_len, p+4UL)*0.01; z = (double)getint32(b, b_len, p+8UL)*0.01; + if(x==0 && y==0 && z==0) { + // RS41 sometimes sends frame with all 0 + if(sonde.si()->validPos) sonde.si()->validPos |= 0x80; // flag as old + return; + } wgs84r(x, y, z, &lat, &long0, &heig); Serial.print(" "); sonde.si()->lat = (float)(X2C_DIVL(lat,1.7453292519943E-2)); diff --git a/libraries/SondeLib/Sonde.h b/libraries/SondeLib/Sonde.h index e20e4df..925d142 100644 --- a/libraries/SondeLib/Sonde.h +++ b/libraries/SondeLib/Sonde.h @@ -67,6 +67,7 @@ typedef struct st_sondeinfo { // receiver configuration bool active; SondeType type; + int8_t subtype; /* 0 for none/unknown, hex type for dfm, maybe add 1/2 for M10/M20 as well?*/ float freq; // decoded ID char typestr[5]; // decoded type (use type if *typestr==0)