Skip to content

Commit

Permalink
Fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
facontidavide committed Apr 9, 2024
1 parent 9ce4680 commit 5ddfa8e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
3 changes: 2 additions & 1 deletion plotjuggler_plugins/DataStreamUDP/udp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ bool UDP_Server::start(QStringList*)
};

connect(dialog.ui->comboBoxProtocol,
qOverload<const QString&>(&QComboBox::currentIndexChanged), this, onComboChanged);
qOverload<const QString&>(&QComboBox::currentIndexChanged), this,
onComboChanged);

dialog.ui->comboBoxProtocol->setCurrentText(protocol);
onComboChanged(protocol);
Expand Down
54 changes: 29 additions & 25 deletions plotjuggler_plugins/ParserLineInflux/line_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ using namespace PJ;
class MsgParserImpl : public MessageParser
{
public:
MsgParserImpl(const std::string& topic_name,
const std::string& type_name,
const std::string&,
PJ::PlotDataMapRef& data)
MsgParserImpl(const std::string& topic_name, const std::string& type_name,
const std::string&, PJ::PlotDataMapRef& data)
: MessageParser(topic_name, data), topic_name_(topic_name)
{
}
Expand All @@ -23,37 +21,40 @@ class MsgParserImpl : public MessageParser
std::string key;
std::string prefix;
// Obtain the key name from measurement name and tags
for(auto line: str.splitRef('\n', Qt::SkipEmptyParts))
for (auto line : str.splitRef('\n', Qt::SkipEmptyParts))
{
auto parts = line.split(' ', Qt::SkipEmptyParts);
if(parts.size() != 2 && parts.size() != 3) {
if (parts.size() != 2 && parts.size() != 3)
{
continue;
}
const auto tags = parts[0].split(',', Qt::SkipEmptyParts);
const auto fields = parts[1].split(',', Qt::SkipEmptyParts);
if(tags.size() < 1 || fields.size() < 1) {
if (tags.size() < 1 || fields.size() < 1)
{
continue;
}
uint64_t timestamp = 0;
if(parts.size() == 3)
if (parts.size() == 3)
{
timestamp = parts[2].toULongLong();
}
else {
else
{
using namespace std::chrono;
auto now = steady_clock::now();
timestamp = duration_cast<nanoseconds>(now.time_since_epoch()).count();
}
const double ts_sec = double(timestamp) * 1e-9;

prefix = topic_name_;
for(auto tag: tags)
for (auto tag : tags)
{
prefix += '/';
auto tag_str = tag.toLocal8Bit();
prefix.append(tag_str.data(), tag_str.size());
}
for(auto field: fields)
for (auto field : fields)
{
const auto field_parts = field.split('=');
const auto name = field_parts[0].toLocal8Bit();
Expand All @@ -63,33 +64,37 @@ class MsgParserImpl : public MessageParser
key += '/';
key.append(name.data(), name.size());

if(value.startsWith('"') && value.endsWith('"'))
if (value.startsWith('"') && value.endsWith('"'))
{
auto& data = _plot_data.getOrCreateStringSeries(key);
data.pushBack({ts_sec, std::string(ToChar(value.data()+1), value.size()-2)});
data.pushBack(
{ ts_sec, std::string(ToChar(value.data() + 1), value.size() - 2) });
}
else if(value == "t" || value == "T" || value == "true" || value == "True" || value == "TRUE")
else if (value == "t" || value == "T" || value == "true" || value == "True" ||
value == "TRUE")
{
auto& data = _plot_data.getOrCreateNumeric(key);
data.pushBack({ts_sec, 1.0});
data.pushBack({ ts_sec, 1.0 });
}
else if(value == "f" || value == "F" || value == "false" || value == "False" || value == "FALSE")
else if (value == "f" || value == "F" || value == "false" || value == "False" ||
value == "FALSE")
{
auto& data = _plot_data.getOrCreateNumeric(key);
data.pushBack({ts_sec, 0.0});
data.pushBack({ ts_sec, 0.0 });
}
else {
else
{
bool ok = false;
// remove last character if there is an integer suffix
if(value.endsWith('i') || value.endsWith('u'))
if (value.endsWith('i') || value.endsWith('u'))
{
value.chop(1);
}
double num = value.toDouble(&ok);
if(ok)
if (ok)
{
auto& data = _plot_data.getOrCreateNumeric(key);
data.pushBack({ts_sec, num});
data.pushBack({ ts_sec, num });
}
}
}
Expand All @@ -98,14 +103,13 @@ class MsgParserImpl : public MessageParser
}

private:

std::string topic_name_;
};

MessageParserPtr ParserLine::createParser(const std::string& topic_name,
const std::string& type_name,
const std::string& schema,
PJ::PlotDataMapRef& data)
const std::string& type_name,
const std::string& schema,
PJ::PlotDataMapRef& data)
{
return std::make_shared<MsgParserImpl>(topic_name, type_name, schema, data);
}
3 changes: 1 addition & 2 deletions plotjuggler_plugins/ParserLineInflux/sample_telegraf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@

[[outputs.socket_writer]]
address = "udp://127.0.0.1:8094"

# Send telegraf metrics to file(s)
[[outputs.file]]
## Files to write to, "stdout" is a specially handled file.
Expand Down Expand Up @@ -169,4 +169,3 @@
## zlib -- supports levels 0, 1, and 9.
## By default the default compression level for each algorithm is used.
# compression_level = -1

0 comments on commit 5ddfa8e

Please sign in to comment.