radio_tool 0.2.1
Loading...
Searching...
No Matches
yaesu_fw.cpp
1
19#include <radio_tool/fw/yaesu_fw.hpp>
20#include <radio_tool/util.hpp>
21
22using namespace radio_tool::fw;
23
24auto YaesuFW::Read(const std::string& file) -> void
25{
26 auto i = std::ifstream(file, std::ios_base::binary);
27 if (i.is_open())
28 {
29 // Compute binary file size
30 i.seekg(0, std::ios_base::end);
31 auto binarySize = i.tellg();
32 i.seekg(0);
33
34 // Read binary
35 data.resize(binarySize);
36 i.read((char*)data.data(), binarySize);
37
38 // Pad with 0xFF until multiple of 1KiB
39 data.resize(binarySize + ((1024 - binarySize % 1024) % 1024), 0xFF);
40 }
41 i.close();
42}
43
44auto YaesuFW::Write(const std::string& file) -> void
45{
46 std::ofstream fout(file, std::ios_base::binary);
47 if (fout.is_open())
48 {
49 // write firmware data
50 fout.write((char*)data.data(), data.size());
51 fout.close();
52 }
53}
54
55auto YaesuFW::ToString() const -> std::string
56{
57 std::stringstream out;
58 out << "== Yaesu Firmware == " << std::endl
59 << "Size: " << radio_tool::FormatBytes(data.size()) << std::endl;
60 return out.str();
61}
62
63auto YaesuFW::Decrypt() -> void {}
64auto YaesuFW::Encrypt() -> void {}
65auto YaesuFW::SetRadioModel(const std::string&) -> void {}
66auto YaesuFW::GetRadioModel() const -> const std::string
67{
68 return "Unknown";
69}
70
71auto YaesuFW::SupportsFirmwareFile(const std::string& file) -> bool
72{
73 std::ifstream i;
74 i.open(file, i.binary);
75 if (i.is_open())
76 {
77 return true;
78 }
79 else
80 {
81 throw std::runtime_error("Can't open firmware file");
82 }
83}
84
85auto YaesuFW::SupportsRadioModel(const std::string& model) -> bool
86{
87 return true;
88}
89
90auto YaesuFW::IsCompatible(const FirmwareSupport* Other) const -> bool
91{
92 if (typeid(Other) != typeid(this)) {
93 return false;
94 }
95
96 auto afw = dynamic_cast<const YaesuFW*>(Other);
97 return afw->radio_model == radio_model;
98}
std::vector< uint8_t > data
Definition: fw.hpp:166
auto GetRadioModel() const -> const std::string override
Definition: yaesu_fw.cpp:66
auto ToString() const -> std::string override
Definition: yaesu_fw.cpp:55
static auto SupportsRadioModel(const std::string &model) -> bool
Definition: yaesu_fw.cpp:85
auto Encrypt() -> void override
Definition: yaesu_fw.cpp:64
auto SetRadioModel(const std::string &) -> void override
Definition: yaesu_fw.cpp:65
auto Write(const std::string &file) -> void override
Definition: yaesu_fw.cpp:44
auto IsCompatible(const FirmwareSupport *Other) const -> bool override
Definition: yaesu_fw.cpp:90
auto Read(const std::string &file) -> void override
Definition: yaesu_fw.cpp:24
auto Decrypt() -> void override
Definition: yaesu_fw.cpp:63
static auto SupportsFirmwareFile(const std::string &file) -> bool
Definition: yaesu_fw.cpp:71