1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
#include "verify.hh"
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QString>
#include <QFile>
#include <QTextStream>
#include <iostream>
#include "logger.hh"
#include "config.hh"
#include "csvreader.hh"
#include "dfufile.hh"
#include "radiolimits.hh"
#include "rd5r.hh"
#include "uv390.hh"
#include "md2017.hh"
#include "dm1701.hh"
#include "gd73.hh"
#include "gd77.hh"
#include "opengd77.hh"
#include "openuv380.hh"
#include "d868uv.hh"
#include "d878uv.hh"
#include "d878uv2.hh"
#include "d578uv.hh"
int verify(QCommandLineParser &parser, QCoreApplication &app)
{
Q_UNUSED(app);
if (2 > parser.positionalArguments().size())
parser.showHelp(-1);
QString filename = parser.positionalArguments().at(1);
QFile file(filename);
if (! file.open(QIODevice::ReadOnly)) {
logError() << "Cannot open file" << filename;
return -1;
}
Config config;
// Determine type by ending or flag
if (parser.isSet("csv") || (filename.endsWith(".conf") || filename.endsWith(".csv"))) {
QTextStream stream(&file);
QString errorMessage;
if (! CSVReader::read(&config, stream, errorMessage)) {
logError() << "Cannot read config file '" << filename << "': " << errorMessage;
return -1;
}
logInfo() << "Verify '" << filename << "': No syntax issues found.";
} else if (parser.isSet("bin") || (filename.endsWith(".bin") || filename.endsWith(".dfu"))) {
logError() << "Verification of binary code-plugs makes no sense.";
return -1;
} else if (parser.isSet("yaml") || (filename.endsWith(".yaml") || filename.endsWith(".yml"))) {
ErrorStack err;
if (! config.readYAML(filename,err)) {
logError() << "Cannot read codeplug file '" << filename
<< "': " << err.format();
return -1;
}
} else {
logError() << "Cannot determine filetype from filename '" << filename
<< "': Consider using --csv.";
return -1;
}
if (! parser.isSet("radio")) {
logInfo() << "To verify the codeplug against a specific radio, conser using the --radio=RADIO option.";
return 0;
}
RadioLimitContext ctx;
RadioInfo::Radio radio = RadioInfo::byKey(parser.value("radio").toLower()).id();
switch (radio) {
case RadioInfo::RD5R: {
RD5R radio; ErrorStack err;
Config *intermediate = radio.codeplug().preprocess(&config, err);
if (nullptr == intermediate) {
logError() << "Cannot pre-process codeplug: " << err.format();
return -1;
}
radio.limits().verifyConfig(intermediate, ctx);
delete intermediate;
} break;
case RadioInfo::UV390: {
UV390 radio; ErrorStack err;
Config *intermediate = radio.codeplug().preprocess(&config, err);
if (nullptr == intermediate) {
logError() << "Cannot pre-process codeplug: " << err.format();
return -1;
}
radio.limits().verifyConfig(intermediate, ctx);
delete intermediate;
} break;
case RadioInfo::MD2017: {
MD2017 radio; ErrorStack err;
Config *intermediate = radio.codeplug().preprocess(&config, err);
if (nullptr == intermediate) {
logError() << "Cannot pre-process codeplug: " << err.format();
return -1;
}
radio.limits().verifyConfig(intermediate, ctx);
delete intermediate;
} break;
case RadioInfo::DM1701: {
DM1701 radio; ErrorStack err;
Config *intermediate = radio.codeplug().preprocess(&config, err);
if (nullptr == intermediate) {
logError() << "Cannot pre-process codeplug: " << err.format();
return -1;
}
radio.limits().verifyConfig(intermediate, ctx);
delete intermediate;
} break;
case RadioInfo::GD73: {
GD73 radio; ErrorStack err;
Config *intermediate = radio.codeplug().preprocess(&config, err);
if (nullptr == intermediate) {
logError() << "Cannot pre-process codeplug: " << err.format();
return -1;
}
radio.limits().verifyConfig(intermediate, ctx);
delete intermediate;
} break;
case RadioInfo::GD77: {
GD77 radio; ErrorStack err;
Config *intermediate = radio.codeplug().preprocess(&config, err);
if (nullptr == intermediate) {
logError() << "Cannot pre-process codeplug: " << err.format();
return -1;
}
radio.limits().verifyConfig(intermediate, ctx);
delete intermediate;
} break;
case RadioInfo::OpenGD77: {
OpenGD77 radio; ErrorStack err;
Config *intermediate = radio.codeplug().preprocess(&config, err);
if (nullptr == intermediate) {
logError() << "Cannot pre-process codeplug: " << err.format();
return -1;
}
radio.limits().verifyConfig(intermediate, ctx);
delete intermediate;
} break;
case RadioInfo::OpenUV380: {
OpenUV380 radio; ErrorStack err;
Config *intermediate = radio.codeplug().preprocess(&config, err);
if (nullptr == intermediate) {
logError() << "Cannot pre-process codeplug: " << err.format();
return -1;
}
radio.limits().verifyConfig(intermediate, ctx);
delete intermediate;
} break;
case RadioInfo::D868UV: {
D868UV radio; ErrorStack err;
Config *intermediate = radio.codeplug().preprocess(&config, err);
if (nullptr == intermediate) {
logError() << "Cannot pre-process codeplug: " << err.format();
return -1;
}
radio.limits().verifyConfig(intermediate, ctx);
delete intermediate;
} break;
case RadioInfo::D878UV: {
D878UV radio; ErrorStack err;
Config *intermediate = radio.codeplug().preprocess(&config, err);
if (nullptr == intermediate) {
logError() << "Cannot pre-process codeplug: " << err.format();
return -1;
}
radio.limits().verifyConfig(intermediate, ctx);
delete intermediate;
} break;
case RadioInfo::D878UVII: {
D878UV2 radio; ErrorStack err;
Config *intermediate = radio.codeplug().preprocess(&config, err);
if (nullptr == intermediate) {
logError() << "Cannot pre-process codeplug: " << err.format();
return -1;
}
radio.limits().verifyConfig(intermediate, ctx);
delete intermediate;
} break;
case RadioInfo::D578UV: {
D578UV radio; ErrorStack err;
Config *intermediate = radio.codeplug().preprocess(&config, err);
if (nullptr == intermediate) {
logError() << "Cannot pre-process codeplug: " << err.format();
return -1;
}
radio.limits().verifyConfig(intermediate, ctx);
delete intermediate;
} break;
default:
logError() << "Cannot verify code-plug against unknown radio '" << radio << "'.";
return -1;
}
bool valid = true;
for (int i=0; i<ctx.count(); i++) {
switch (ctx.message(i).severity()) {
case RadioLimitIssue::Silent:
logDebug() << ctx.message(i).format();
break;
case RadioLimitIssue::Hint:
logInfo() << ctx.message(i).format();
break;
case RadioLimitIssue::Warning:
logWarn() << ctx.message(i).format();
break;
case RadioLimitIssue::Critical:
logError() << ctx.message(i).format();
valid = false;
break;
}
}
return (valid ? 0 : -1);
}
|