2017-12-30 14:54:18 +11:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
2017-12-30 14:54:18 +11:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "HALSimLowFi.h"
|
|
|
|
|
|
2018-04-29 23:33:19 -07:00
|
|
|
#include <wpi/Twine.h>
|
2017-12-30 14:54:18 +11:00
|
|
|
|
|
|
|
|
void HALSimLowFi::Initialize() {
|
|
|
|
|
table = nt::NetworkTableInstance::GetDefault().GetTable("sim");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HALSimNTProvider::Inject(std::shared_ptr<HALSimLowFi> parentArg,
|
|
|
|
|
std::string tableNameArg) {
|
|
|
|
|
parent = parentArg;
|
|
|
|
|
tableName = std::move(tableNameArg);
|
|
|
|
|
table = parent->table->GetSubTable(tableName);
|
|
|
|
|
|
|
|
|
|
this->Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NTProviderBaseCallback(const char* name, void* param,
|
|
|
|
|
const struct HAL_Value* value) {
|
|
|
|
|
auto info =
|
|
|
|
|
static_cast<struct HALSimNTProvider::NTProviderCallbackInfo*>(param);
|
|
|
|
|
uint32_t chan = static_cast<uint32_t>(info->channel);
|
|
|
|
|
auto provider = info->provider;
|
|
|
|
|
auto table = info->table;
|
|
|
|
|
provider->OnCallback(chan, table);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HALSimNTProvider::InitializeDefault(
|
|
|
|
|
int numChannels, HALCbRegisterIndexedFunc registerFunc) {
|
|
|
|
|
this->numChannels = numChannels;
|
|
|
|
|
cbInfos.reserve(numChannels);
|
|
|
|
|
for (int i = 0; i < numChannels; i++) {
|
|
|
|
|
struct NTProviderCallbackInfo info = {
|
2018-04-29 23:33:19 -07:00
|
|
|
this, table->GetSubTable(tableName + wpi::Twine(i)), i};
|
2017-12-30 14:54:18 +11:00
|
|
|
cbInfos.emplace_back(info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto& info : cbInfos) {
|
|
|
|
|
registerFunc(info.channel, NTProviderBaseCallback, &info, true);
|
|
|
|
|
OnInitializedChannel(info.channel, info.table);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HALSimNTProvider::InitializeDefaultSingle(
|
|
|
|
|
HALCbRegisterSingleFunc registerFunc) {
|
|
|
|
|
struct NTProviderCallbackInfo info = {this, table, 0};
|
|
|
|
|
cbInfos.push_back(info);
|
|
|
|
|
|
|
|
|
|
for (auto& info : cbInfos) {
|
|
|
|
|
registerFunc(NTProviderBaseCallback, &info, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HALSimNTProvider::OnInitializedChannel(
|
|
|
|
|
uint32_t channel, std::shared_ptr<nt::NetworkTable> table) {}
|