From 8362717ca60dc927b18503183c83a19e33c5fd84 Mon Sep 17 00:00:00 2001 From: Mark Jessop Date: Sat, 26 Nov 2022 10:19:56 +1030 Subject: [PATCH] Rebase dfm and MTS01 decoders --- auto_rx/autorx/__init__.py | 2 +- auto_rx/autorx/utils.py | 2 +- demod/mod/dfm09mod.c | 6 +++--- demod/mod/mts01mod.c | 40 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/auto_rx/autorx/__init__.py b/auto_rx/autorx/__init__.py index 42a4f41..4555196 100644 --- a/auto_rx/autorx/__init__.py +++ b/auto_rx/autorx/__init__.py @@ -12,7 +12,7 @@ from queue import Queue # MINOR - New sonde type support, other fairly big changes that may result in telemetry or config file incompatability issus. # PATCH - Small changes, or minor feature additions. -__version__ = "1.6.0-beta20" +__version__ = "1.6.0-beta21" # Global Variables diff --git a/auto_rx/autorx/utils.py b/auto_rx/autorx/utils.py index 5489fd5..580a356 100644 --- a/auto_rx/autorx/utils.py +++ b/auto_rx/autorx/utils.py @@ -141,7 +141,7 @@ def strip_sonde_serial(serial): """ Strip off any leading sonde type that may be present in a serial number """ # Look for serials with prefixes matching the following known sonde types. - _re = re.compile("^(DFM|M10|M20|IMET|IMET5|IMET54|MRZ|LMS6|IMS100|MTS01)-") + _re = re.compile("^(DFM|M10|M20|IMET|IMET5|IMET54|MRZ|LMS6|IMS100|RS11G|MTS01)-") # If we have a match, return the trailing part of the serial, re-adding # any - separators if they exist. diff --git a/demod/mod/dfm09mod.c b/demod/mod/dfm09mod.c index 1f79337..ce208de 100644 --- a/demod/mod/dfm09mod.c +++ b/demod/mod/dfm09mod.c @@ -800,7 +800,7 @@ static int conf_out(gpx_t *gpx, ui8_t *conf_bits, int ec) { } - if (conf_id >= 0 && conf_id <= 8) { + if (conf_id >= 0 && conf_id <= 8 && ec == 0) { gpx->cfgchk24[conf_id] = 1; val = bits2val(conf_bits+4, 4*6); gpx->val24[conf_id] = val; @@ -822,8 +822,8 @@ static int conf_out(gpx_t *gpx, ui8_t *conf_bits, int ec) { gpx->Rf = 220e3; if (gpx->cfgchk) { // 0xC: "P+" DFM-09P , "T-" DFM-17TU ; 0xD: "P-" DFM-17P ? - if (gpx->ptu_out >= 0xD || (gpx->ptu_out >= 0xC && gpx->meas24[6] < 220e3)) { // gpx->meas24[6] < 220e3 <=> gpx->meas24[0] > 1e6 ? - gpx->sensortyp = 'P'; // gpx->meas24[0] > 1e6 ? + if (gpx->ptu_out >= 0xD || (gpx->ptu_out >= 0xC && gpx->meas24[6] < 220e3)) { // gpx->meas24[6] < 220e3 <=> gpx->meas24[0] > 2e5 ? + gpx->sensortyp = 'P'; // gpx->meas24[0] > 2e5 ? } if ( ((gpx->ptu_out == 0xB || gpx->ptu_out == 0xC) && gpx->sensortyp == 'T') || gpx->ptu_out >= 0xD) gpx->Rf = 332e3; // DFM-17 ? diff --git a/demod/mod/mts01mod.c b/demod/mod/mts01mod.c index 9275b00..75a75db 100644 --- a/demod/mod/mts01mod.c +++ b/demod/mod/mts01mod.c @@ -61,6 +61,9 @@ typedef struct { int year; int month; int day; int hrs; int min; int sec; double lat; double lon; double alt; + double vH; double vD; + float T; float RH; + int batt; char ID[8+4]; ui8_t frame_bytes[FRAMELEN+4]; char frame_bits[BITFRAMELEN+8]; @@ -133,6 +136,18 @@ static int fn(gpx_t *gpx, int n) { return pos; } +static float get_Temp(float R) { +// Thermistor approximation +// 1/T = 1/To + 1/B log(r) , r=R/Ro + float B0 = 3000.0; // B/Kelvin + float T0 = 0.0 + 273.15; + float R0 = 15.0; + float T = 0; // T/Kelvin + if (R > 0) T = 1.0/(1.0/T0 + 1.0/B0 * log(R/R0)); + return T - 273.15; // Celsius +} + + static int print_frame(gpx_t *gpx, int pos) { int i, j; int crcdat, crcval, crc_ok; @@ -195,6 +210,9 @@ static int print_frame(gpx_t *gpx, int pos) { gpx->month = atoi(datetime_str+ 2); datetime_str[ 2] = '\0'; gpx->year = atoi(datetime_str) + 2000; + int pos_BATT = fn(gpx, 4); + gpx->batt = atof(gpx->frm_str+pos_BATT); + int pos_LAT = fn(gpx, 5); gpx->lat = atof(gpx->frm_str+pos_LAT); @@ -204,12 +222,28 @@ static int print_frame(gpx_t *gpx, int pos) { int pos_ALT = fn(gpx, 7); gpx->alt = atof(gpx->frm_str+pos_ALT); + int pos_VD = fn(gpx, 8); // 0..360 Heading + gpx->vD = atof(gpx->frm_str+pos_VD); + + int pos_VH = fn(gpx, 9); // m/s vH + gpx->vH = atof(gpx->frm_str+pos_VH); + + int pos_rawT1 = fn(gpx, 11); + int pos_rawT2 = fn(gpx, 12); + int pos_rawRH = fn(gpx, 13); + + gpx->T = get_Temp(atof(gpx->frm_str+pos_rawT1)); // rawT1==rawT2 + + if (gpx->option.vbs) { printf(" [%4d] ", gpx->frnr); printf(" (%s) ", gpx->ID); printf(" %4d-%02d-%02d ", gpx->year, gpx->month, gpx->day); printf("%02d:%02d:%02d ", gpx->hrs, gpx->min, gpx->sec); printf(" lat: %.6f lon: %.6f alt: %.0f ", gpx->lat, gpx->lon, gpx->alt); + printf(" vH: %4.1f D: %5.1f ", gpx->vH, gpx->vD); + printf(" Vbat:%.1fV ", gpx->batt/1000.0); + if (gpx->T > -270.0f) printf(" T=%.1fC ", gpx->T); printf("\n"); } @@ -218,8 +252,10 @@ static int print_frame(gpx_t *gpx, int pos) { // UTC oder GPS? char *ver_jsn = NULL; printf("{ \"type\": \"%s\"", "MTS01"); - printf(", \"frame\": %d, \"id\": \"MTS01-%s\", \"datetime\": \"%04d-%02d-%02dT%02d:%02d:%06.3fZ\", \"lat\": %.5f, \"lon\": %.5f, \"alt\": %.5f", - gpx->frnr, gpx->ID, gpx->year, gpx->month, gpx->day, gpx->hrs, gpx->min, (float)gpx->sec, gpx->lat, gpx->lon, gpx->alt ); + printf(", \"frame\": %d, \"id\": \"MTS01-%s\", \"datetime\": \"%04d-%02d-%02dT%02d:%02d:%06.3fZ\", \"lat\": %.5f, \"lon\": %.5f, \"alt\": %.5f, \"vel_h\": %.5f, \"heading\": %.5f", + gpx->frnr, gpx->ID, gpx->year, gpx->month, gpx->day, gpx->hrs, gpx->min, (float)gpx->sec, gpx->lat, gpx->lon, gpx->alt, gpx->vH, gpx->vD ); + printf(", \"batt\": %.2f", gpx->batt/1000.0); + if (gpx->T > -270.0f) printf(", \"temp\": %.1f", gpx->T); if (gpx->jsn_freq > 0) { printf(", \"freq\": %d", gpx->jsn_freq); }