feat(api) sdk/firmware version check

This commit is contained in:
TinyOh 2019-02-28 03:53:50 +08:00
parent 6953758101
commit b2bd90192d
2 changed files with 108 additions and 19 deletions

View File

@ -339,9 +339,7 @@ std::string API::GetInfo(const Info &info) const {
LOG(WARNING) << "build.info not found: " << info_path; LOG(WARNING) << "build.info not found: " << info_path;
return "null"; return "null";
} }
std::string vs_main = fs["MYNTEYE_VERSION"]; return fs["MYNTEYE_VERSION"];
int vs_tweak = fs["MYNTEYE_VERSION_TWEAK"];
return vs_main + std::string(".") + std::to_string(vs_tweak);
} }
return device_->GetInfo(info); return device_->GetInfo(info);

View File

@ -19,29 +19,120 @@
MYNTEYE_BEGIN_NAMESPACE MYNTEYE_BEGIN_NAMESPACE
typedef struct { typedef struct {
const std::string device_type; const std::string device_type;
const std::string sdk_version; const std::string sdk_version;
const std::string firmware_version; const std::string firmware_version;
const std::string status;
}firmware_version_match_table_unit; }firmware_version_match_table_unit;
const char* ERRO_DESCRIPTION_F =
"Please update the firmware at first";
const char* ERRO_DESCRIPTION_S =
"Please update the SDK at first";
const char* WARN_DESCRIPTION_F =
"We suggest that you should update the firmware";
const char* WARN_DESCRIPTION_S =
"We suggest that you should update the SDK";
const char* PASS_DESCRIPTION = "pass";
/** firmware/sdk version matched table */ /** firmware/sdk version matched table */
/**----device type-----sdk version---firmware version-----pass tag-----*/
static const firmware_version_match_table_unit FSVM_TABLE[] ={ static const firmware_version_match_table_unit FSVM_TABLE[] ={
{"MYNT-EYE-S1030", "2.3.1.0", "2.0.0"}, /** S1030 */
{"MYNT-EYE-S1030", "2.3.1.0", "2.0.0"}, {"MYNT-EYE-S1030", ">2.3.0", "2.3.0", PASS_DESCRIPTION},
{} {"MYNT-EYE-S1030", ">2.3.0", "2.2.2", PASS_DESCRIPTION},
{"MYNT-EYE-S1030", ">2.3.0", "2.2.0", WARN_DESCRIPTION_F},
{"MYNT-EYE-S1030", ">2.3.0", "<2.2.0", ERRO_DESCRIPTION_F},
{"MYNT-EYE-S1030", "<2.3.1", "<2.2.0", WARN_DESCRIPTION_S},
/** S2100 */
{"MYNT-EYE-S2100", ">0.0.0", "1.0", PASS_DESCRIPTION},
/** S210A */
{"MYNT-EYE-S210A", ">0.0.0", "1.0", PASS_DESCRIPTION},
}; };
void getVersion(const std::string &str, char *version) {
std::string st1("");
int j = 0;
for (size_t i = 0; i < str.size(); i++) {
if (str[i] == '.') {
version[j++] = atoi(st1.c_str());
st1 = "";
} else {
st1 += str[i];
}
}
version[j++] = atoi(st1.c_str());
}
bool conditionMatch(const std::string& condition, const std::string& target) {
char version[4] = {0};
char version_c[4] = {0};
getVersion(target, version);
int tag_c = 0;
std::string condition_c;
if (condition[0] == '>') {
tag_c = 1;
condition_c = condition.substr(1);
} else if (condition[0] == '<') {
tag_c = -1;
condition_c = condition.substr(1);
} else {
tag_c = 0;
condition_c = condition;
}
getVersion(condition_c, version_c);
int tag_big = memcmp(version, version_c, 4);
if (tag_big * tag_c > 0 || (tag_big == 0 && tag_c == 0)) return true;
return false;
}
enum STATUS_UNIT {
ST_PASS,
ST_ERRO_F,
ST_ERRO_S,
ST_NOT_PASS
};
STATUS_UNIT checkUnit(const std::string& sdkv,
const std::string& devn,
const std::string& firmv,
const firmware_version_match_table_unit& condition) {
if (condition.device_type == devn &&
conditionMatch(condition.sdk_version, sdkv) &&
conditionMatch(condition.firmware_version, firmv)) {
if (condition.status == ERRO_DESCRIPTION_F) {
return ST_ERRO_F;
}
if (condition.status == ERRO_DESCRIPTION_S) {
return ST_ERRO_S;
}
if (condition.status == WARN_DESCRIPTION_F ||
condition.status == WARN_DESCRIPTION_S) {
LOG(WARNING) << condition.status;
}
return ST_PASS;
}
return ST_NOT_PASS;
}
bool checkFirmwareVersion(const std::shared_ptr<API> api) { bool checkFirmwareVersion(const std::shared_ptr<API> api) {
LOG(INFO) << "SDK version: " << api->GetInfo(Info::SDK_VERSION); auto sdkv = api->GetInfo(Info::SDK_VERSION);
LOG(INFO) << "Device name: " << api->GetInfo(Info::DEVICE_NAME); auto devn = api->GetInfo(Info::DEVICE_NAME);
LOG(INFO) << "Serial number: " << api->GetInfo(Info::SERIAL_NUMBER); auto firmv = api->GetInfo(Info::FIRMWARE_VERSION);
LOG(INFO) << "Firmware version: " << api->GetInfo(Info::FIRMWARE_VERSION);
LOG(INFO) << "Hardware version: " << api->GetInfo(Info::HARDWARE_VERSION); for (size_t i =0;
LOG(INFO) << "Spec version: " << api->GetInfo(Info::SPEC_VERSION); i < sizeof(FSVM_TABLE)/sizeof(firmware_version_match_table_unit);
LOG(INFO) << "Lens type: " << api->GetInfo(Info::LENS_TYPE); i++) {
LOG(INFO) << "IMU type: " << api->GetInfo(Info::IMU_TYPE); auto res = checkUnit(sdkv, devn, firmv, FSVM_TABLE[i]);
LOG(INFO) << "Nominal baseline: " << api->GetInfo(Info::NOMINAL_BASELINE); if (res == ST_PASS) {
return true; return true;
} else if (res == ST_ERRO_S || res == ST_ERRO_F) {
LOG(ERROR) << FSVM_TABLE[i].status;
return false;
}
}
LOG(ERROR) << ERRO_DESCRIPTION_S;
return false;
} }
MYNTEYE_END_NAMESPACE MYNTEYE_END_NAMESPACE