20#include <radio_tool/fw/fw.hpp>
21#include <radio_tool/fw/cipher/sgl.hpp>
30 constexpr auto NotAscii = [](
unsigned char ch) {
31 return !(ch >=
' ' && ch <=
'~');
38 const uint16_t& sgl_version,
40 const std::string& group,
41 const std::string& model,
42 const std::string& version,
43 const std::string& key,
44 const uint8_t& binary_offset,
45 const uint16_t& header2_offset)
46 : sgl_version(sgl_version),
48 binary_offset(binary_offset),
49 header2_offset(header2_offset),
50 radio_group(group.begin(), std::find_if(group.begin(), group.end(), NotAscii)),
51 radio_model(model.begin(), std::find_if(model.begin(), model.end(), NotAscii)),
52 protocol_version(version),
55 if (sgl_version > 0x100) {
56 throw std::runtime_error(
"Version max is 0x100");
58 if (binary_offset > 0x80) {
59 throw std::runtime_error(
"Binary offset max is 0x80");
61 if (header2_offset < 0x1e || header2_offset > 0x100) {
62 throw std::runtime_error(
"Header 2 offset must be between 0x1e <-> 0x100");
66 auto ToString()
const->std::string;
68 auto Serialize(
bool encrypt =
true)
const->std::vector<uint8_t>;
80 const uint16_t sgl_version;
81 const uint32_t length;
82 const uint8_t binary_offset;
83 const uint16_t header2_offset;
84 const std::string radio_group;
85 const std::string radio_model;
86 const std::string protocol_version;
87 const std::string model_key;
127 namespace tyt::config::sgl
129 const std::vector<uint8_t> Magic = {
'S',
'G',
'L',
'!' };
131 const std::vector<TYTSGLRadioConfig> All = {
132 TYTSGLRadioConfig(
"GD77", SGLHeader(1, 0,
"SG-MD-760",
"MD-760",
"V1.00.01",
"DV01xxx", 0x00, 0xff), fw::cipher::sgl, fw::cipher::sgl_length, 0x807),
133 TYTSGLRadioConfig(
"GD77S", SGLHeader(1, 0,
"SG-MD-730",
"MD-730",
"V1.00.01",
"DV02xxx", 0x00, 0xff), fw::cipher::sgl, fw::cipher::sgl_length, 0x2a8e),
134 TYTSGLRadioConfig(
"BF5R", SGLHeader(1, 0,
"BF-5R",
"BF-5R",
"V1.00.01",
"DV02xxx", 0x00, 0xff), fw::cipher::sgl, fw::cipher::sgl_length, 0x306e),
135 TYTSGLRadioConfig(
"DM1801", SGLHeader(1, 0,
"BF-DMR",
"1801",
"V1.00.01",
"DV03xxx", 0x00, 0xff), fw::cipher::sgl, fw::cipher::sgl_length, 0x2c7c),
144 auto Read(
const std::string& file) ->
void override;
145 auto Write(
const std::string& file) ->
void override;
146 auto ToString()
const->std::string
override;
147 auto Decrypt() ->
void override;
148 auto Encrypt() ->
void override;
179 static auto Create() -> std::unique_ptr<FirmwareSupport>
181 return std::make_unique<TYTSGLFW>();