Skip to content

Commit

Permalink
Fixed pressure and GPX output
Browse files Browse the repository at this point in the history
  • Loading branch information
dbdexter-dev committed Jan 27, 2023
1 parent 7061736 commit e7904c2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
41 changes: 41 additions & 0 deletions src/decode/decoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ namespace radiosonde {
m_data.auxData = auxStream.str();
}

if (m_data.pressure <= 0) {
m_data.pressure = altitude_to_pressure(m_data.alt);
}

if (fragment.fields) {
m_callback(&m_data, m_ctx);
}
Expand All @@ -131,3 +135,40 @@ dewpt(float temp, float rh)
const float tmp = (logf(rh / 100.0f) + (17.27f * temp / (237.3f + temp))) / 17.27f;
return 237.3f * tmp / (1 - tmp);
}
static float
altitude_to_pressure(float alt)
{
const float g0 = 9.80665;
const float M = 0.0289644;
const float R_star = 8.3144598;

const float hbs[] = {0.0, 11000.0, 20000.0, 32000.0, 47000.0, 51000.0, 77000.0};
const float Lbs[] = {-0.0065, 0.0, 0.001, 0.0028, 0.0, -0.0028, -0.002};
const float Pbs[] = {101325.0, 22632.1, 5474.89, 868.02, 110.91, 66.94, 3.96};
const float Tbs[] = {288.15, 216.65, 216.65, 228.65, 270.65, 270.65, 214.65};

float Lb, Pb, Tb, hb;
int b;

for (b=0; b<(int)LEN(Lbs)-1; b++) {
if (alt < hbs[b+1]) {
Lb = Lbs[b];
Pb = Pbs[b];
Tb = Tbs[b];
hb = hbs[b];
break;
}
}

if (b == (int)LEN(Lbs) - 1) {
Lb = Lbs[b];
Pb = Pbs[b];
Tb = Tbs[b];
hb = hbs[b];
}

if (Lb != 0) {
return 1e-2 * Pb * powf((Tb + Lb * (alt - hb)) / Tb, - (g0 * M) / (R_star * Lb));
}
return 1e-2 * Pb * expf(-g0 * M * (alt - hb) / (R_star * Tb));
}
2 changes: 1 addition & 1 deletion src/gpx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ GPXWriter::startTrack(const char *name)
{
if (!m_fd) return;
if (m_trackActive && !strcmp(name, sondeSerial)) return;
for (int i=0; name[i] != '\0'; i++) if (!isalnum(name[i])) return;
for (int i=0; name[i] != '\0'; i++) if (!isgraph(name[i])) return;

if (m_trackActive) {
stopTrack();
Expand Down
8 changes: 4 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ RadiosondeDecoderModule::menuHandler(void *ctx)
ImGui::Text("%.1f°C", _this->lastData.temp);
if (!_this->lastData.calibrated) ImGui::PopStyleColor();
if (!_this->lastData.calibrated && ImGui::IsItemHovered()) {
ImGui::SetTooltip("Calibration data not yet available.");
ImGui::SetTooltip("Calibration data not yet complete (%.0f%%).", _this->lastData.calib_percent);
}
}

Expand All @@ -256,7 +256,7 @@ RadiosondeDecoderModule::menuHandler(void *ctx)
ImGui::Text("%.1f%%", _this->lastData.rh);
if (!_this->lastData.calibrated) ImGui::PopStyleColor();
if (!_this->lastData.calibrated && ImGui::IsItemHovered()) {
ImGui::SetTooltip("Calibration data not yet available.");
ImGui::SetTooltip("Calibration data not yet complete (%.0f%%).", _this->lastData.calib_percent);
}
}

Expand All @@ -269,7 +269,7 @@ RadiosondeDecoderModule::menuHandler(void *ctx)
ImGui::Text("%.1f°C", _this->lastData.dewpt);
if (!_this->lastData.calibrated) ImGui::PopStyleColor();
if (!_this->lastData.calibrated && ImGui::IsItemHovered()) {
ImGui::SetTooltip("Calibration data not yet available.");
ImGui::SetTooltip("Calibration data not yet complete (%.0f%%).", _this->lastData.calib_percent);
}
}

Expand All @@ -282,7 +282,7 @@ RadiosondeDecoderModule::menuHandler(void *ctx)
ImGui::Text("%.1fhPa", _this->lastData.pressure);
if (!_this->lastData.calibrated) ImGui::PopStyleColor();
if (!_this->lastData.calibrated && ImGui::IsItemHovered()) {
ImGui::SetTooltip("Calibration data not yet available.");
ImGui::SetTooltip("Calibration data not yet complete (%.0f%%).", _this->lastData.calib_percent);
}
}

Expand Down

0 comments on commit e7904c2

Please sign in to comment.