mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Drive information is stored in FL2 files.
This commit is contained in:
12
lib/fl2.cc
12
lib/fl2.cc
@@ -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))
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ public:
|
||||
track->add_flux(fluxBytes);
|
||||
}
|
||||
|
||||
proto.mutable_drive()->MergeFrom(config.drive());
|
||||
saveFl2File(_filename, proto);
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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...>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user