Skip to content

Commit

Permalink
fix weird nan in level min messing up JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
jasper committed Nov 22, 2023
1 parent 8159821 commit d0bc19a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Library/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ namespace Util {
static std::string toString(Format format);
static std::string toString(bool b) { return b ? std::string("ON") : std::string("OFF"); };
static std::string toString(bool b, FLOAT32 v) { return b ? std::string("AUTO") : std::to_string(v); }
static std::string toString(FLOAT32 f) {
std::string s = std::to_string(f);
if (s == "nan" || s == "-nan") return "null";
return s;
}

static void toUpper(std::string& s);
static void toFloat(CU8* in, CFLOAT32* out, int len);
Expand Down
7 changes: 5 additions & 2 deletions Ships/Statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include <memory>
#include <mutex>

#include "Utilities.h"
#include "Message.h"

// ----------------------------
// Class to log message count stat

Expand Down Expand Up @@ -140,8 +143,8 @@ class MessageStatistics {

element += "{\"count\":" + std::to_string(empty ? 0 : _count) +
",\"vessels\":" + std::to_string(empty ? 0 : _vessels) +
",\"level_min\":" + std::to_string(empty || !_count ? 0 : _level_min) +
",\"level_max\":" + std::to_string(empty || !_count ? 0 : _level_max) +
",\"level_min\":" + ((empty || !_count) ? std::string("0") : Util::Convert::toString(_level_min)) +
",\"level_max\":" + ((empty || !_count) ? std::string("0") : Util::Convert::toString(_level_max)) +
",\"ppm\":" + std::to_string(empty || !_count ? 0 : _ppm / _count) +
",\"dist\":" + std::to_string(empty ? 0 : _distance) +
",\"channel\":[";
Expand Down

0 comments on commit d0bc19a

Please sign in to comment.