Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions akit/src/main/native/include/akit/LogDataReceiver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2021-2026 Littleton Robotics
// http://github.com/Mechanical-Advantage
//
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file
// at the root directory of this project.

#pragma once
#include <string_view>
#include "akit/LogTable.h"

namespace akit {

class LogDataReceiver {
public:
static constexpr std::string_view TIMESTAMP_KEY = "/Timestamp";

virtual void start() = 0;
virtual void end() = 0;
virtual void putTable(LogTable table) = 0;
};

}
53 changes: 53 additions & 0 deletions akit/src/main/native/include/akit/networktables/NT4Publisher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) 2021-2026 Littleton Robotics
// http://github.com/Mechanical-Advantage
//
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file
// at the root directory of this project.

#pragma once
#include <networktables/NetworkTable.h>
#include <networktables/NetworkTableInstance.h>
#include <networktables/IntegerTopic.h>
#include "akit/LogDataReceiver.h"

namespace akit {

namespace nt {

class NT4Publisher: LogDataReceiver {
public:
NT4Publisher() : akitTable {
::nt::NetworkTableInstance::GetDefault().GetTable("/AdvantageKit") }, timestampPublisher {
akitTable->GetIntegerTopic(TIMESTAMP_KEY.substr(1)).Publish( {
.sendAll = true }) } {
}

void putTable(LogTable table) override {
timestampPublisher.Set(table.getTimestamp(), table.getTimestamp());

std::unordered_map < std::string, LogTable::LogValue > newMap =
table.getAll(false);
std::unordered_map < std::string, LogTable::LogValue > oldMap =
lastTable.getAll(false);

for (const auto &field : newMap) {
if (field.second == oldMap.at(field.first))
continue;

std::string key = field.first.substr(1);
std::string unit = field.second.unitStr;
}
}

private:
std::shared_ptr<::nt::NetworkTable> akitTable;
LogTable lastTable { 0 };
::nt::IntegerPublisher timestampPublisher;
std::unordered_map<std::string, ::nt::GenericPublisher> publishers;
std::unordered_map<std::string, std::string> units;
};

}

}