diff --git a/akit/src/main/native/include/akit/LogDataReceiver.h b/akit/src/main/native/include/akit/LogDataReceiver.h new file mode 100644 index 00000000..084bb72f --- /dev/null +++ b/akit/src/main/native/include/akit/LogDataReceiver.h @@ -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 +#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; +}; + +} diff --git a/akit/src/main/native/include/akit/networktables/NT4Publisher.h b/akit/src/main/native/include/akit/networktables/NT4Publisher.h new file mode 100644 index 00000000..b30cdcdc --- /dev/null +++ b/akit/src/main/native/include/akit/networktables/NT4Publisher.h @@ -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 +#include +#include +#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 publishers; + std::unordered_map units; +}; + +} + +}