Drive information is stored in FL2 files.

This commit is contained in:
dg
2023-05-10 20:47:55 +00:00
parent 6b990a9f51
commit 5022b67e4a
6 changed files with 38 additions and 5 deletions

View File

@@ -25,7 +25,15 @@ static void upgradeFluxFile(FluxFileProto& proto)
proto.set_version(FluxFileVersion::VERSION_2);
}
if (proto.version() > FluxFileVersion::VERSION_2)
if (proto.version() == FluxFileVersion::VERSION_2)
{
proto.mutable_drive()->set_rotational_period_ms(
proto.rotational_period_ms());
proto.set_version(FluxFileVersion::VERSION_3);
}
if (proto.version() > FluxFileVersion::VERSION_3)
error(
"this is a version {} flux file, but this build of the client can "
"only handle up to version {} --- please upgrade",
@@ -57,7 +65,7 @@ FluxFileProto loadFl2File(const std::string filename)
void saveFl2File(const std::string filename, FluxFileProto& proto)
{
proto.set_magic(FluxMagic::MAGIC);
proto.set_version(FluxFileVersion::VERSION_2);
proto.set_version(FluxFileVersion::VERSION_3);
std::ofstream of(filename, std::ios::out | std::ios::binary);
if (!proto.SerializeToOstream(&of))

View File

@@ -1,5 +1,7 @@
syntax = "proto2";
import "lib/drive.proto";
enum FluxMagic {
MAGIC = 0x466c7578;
}
@@ -7,6 +9,7 @@ enum FluxMagic {
enum FluxFileVersion {
VERSION_1 = 1;
VERSION_2 = 2;
VERSION_3 = 3;
}
message TrackFluxProto {
@@ -19,6 +22,7 @@ message FluxFileProto {
optional int32 magic = 1;
optional FluxFileVersion version = 2;
repeated TrackFluxProto track = 3;
optional double rotational_period_ms = 4;
optional double rotational_period_ms = 4 [ deprecated=true ];
optional DriveProto drive = 5;
}

View File

@@ -43,6 +43,7 @@ public:
track->add_flux(fluxBytes);
}
proto.mutable_drive()->MergeFrom(config.drive());
saveFl2File(_filename, proto);
}

View File

@@ -36,6 +36,10 @@ public:
Fl2FluxSource(const Fl2FluxSourceProto& config): _config(config)
{
_proto = loadFl2File(_config.filename());
if (::config.has_drive())
warning("FLUX: overriding drive configuration with flux file contents");
::config.mutable_drive()->MergeFrom(_proto.drive());
}
public:

View File

@@ -1,4 +1,5 @@
#include "globals.h"
#include "lib/globals.h"
#include "lib/logger.h"
#include <sys/time.h>
#include <stdarg.h>
@@ -9,3 +10,10 @@ double getCurrentTime(void)
return double(tv.tv_sec) + tv.tv_usec / 1000000.0;
}
void warning(const std::string msg)
{
log(msg);
fmt::print("Warning: {}\n", msg);
}

View File

@@ -49,6 +49,14 @@ inline void error(fmt::string_view fstr, const Args&... args)
throw ErrorException { fmt::format(fstr, args...) };
}
extern void warning(const std::string msg);
template <typename... Args>
inline void warning(fmt::string_view fstr, const Args&... args)
{
warning(fmt::format(fstr, args...));
}
template <class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;