mirror of
https://github.com/sipeed/MaixCDK.git
synced 2026-09-19 14:30:55 -05:00
add get maixpy version api
This commit is contained in:
@@ -15,11 +15,18 @@ namespace maix::sys
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Get system version
|
* Get system version
|
||||||
* @return version string, e.g. "2024.4.1-13af4b"
|
* @return version string, e.g. "maixcam-2024-08-13-maixpy-v4.4.20"
|
||||||
* @maixpy maix.sys.os_version
|
* @maixpy maix.sys.os_version
|
||||||
*/
|
*/
|
||||||
std::string os_version();
|
std::string os_version();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get MaixPy version, if get failed will return empty string.
|
||||||
|
* @return version string, e.g. "4.4.21"
|
||||||
|
* @maixpy maix.sys.maixpy_version
|
||||||
|
*/
|
||||||
|
std::string maixpy_version();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get device name
|
* Get device name
|
||||||
* @return device name, e.g. "MaixCAM"
|
* @return device name, e.g. "MaixCAM"
|
||||||
|
|||||||
@@ -50,6 +50,57 @@ namespace maix::sys
|
|||||||
return "Unkonwn";
|
return "Unkonwn";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string maixpy_version()
|
||||||
|
{
|
||||||
|
#if PLATFORM_MAIXCAM
|
||||||
|
// fast way, read /usr/lib/python3.11/site-packages/maix/version.py
|
||||||
|
// find key value:
|
||||||
|
// version_major = 4
|
||||||
|
// version_minor = 4
|
||||||
|
// version_patch = 20
|
||||||
|
// return $version_major.$version_minor.$version_patch
|
||||||
|
std::ifstream version_file("/usr/lib/python3.11/site-packages/maix/version.py");
|
||||||
|
if (!version_file.is_open()) {
|
||||||
|
log::warn("Failed to open version file.");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
int version_major = -1, version_minor = -1, version_patch = -1;
|
||||||
|
|
||||||
|
while (std::getline(version_file, line)) {
|
||||||
|
if (line.find("version_major") != std::string::npos) {
|
||||||
|
std::string num = line.substr(line.find("=") + 1);
|
||||||
|
version_major = std::stoi(num);
|
||||||
|
}
|
||||||
|
else if (line.find("version_minor") != std::string::npos) {
|
||||||
|
std::string num = line.substr(line.find("=") + 1);
|
||||||
|
version_minor = std::stoi(num);
|
||||||
|
}
|
||||||
|
else if (line.find("version_patch") != std::string::npos) {
|
||||||
|
std::string num = line.substr(line.find("=") + 1);
|
||||||
|
version_patch = std::stoi(num);
|
||||||
|
}
|
||||||
|
if(version_major >=0 && version_minor >= 0 && version_patch >=0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
version_file.close();
|
||||||
|
|
||||||
|
if (version_major == -1 || version_minor == -1 || version_patch == -1) {
|
||||||
|
log::warn("Version information incomplete or not found.");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostringstream version_stream;
|
||||||
|
version_stream << version_major << "." << version_minor << "." << version_patch;
|
||||||
|
return version_stream.str();
|
||||||
|
#else
|
||||||
|
log::warn("maixpy_version() not implemented for this platform");
|
||||||
|
return "";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
std::string device_name()
|
std::string device_name()
|
||||||
{
|
{
|
||||||
FILE *file = NULL;
|
FILE *file = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user