This commit is contained in:
33
lib/fetchOTA/utils.cpp
Normal file
33
lib/fetchOTA/utils.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <utils.h>
|
||||
#include <stdio.h>
|
||||
|
||||
Version parseVersion(const char *versionStr) {
|
||||
Version v = {0, 0, 0}; // Initialize with default values
|
||||
|
||||
// Buffer to check for any extra content
|
||||
char extraContent;
|
||||
// Try to extract three integers and check for non-numeric trailing characters
|
||||
int parsedCount = sscanf(versionStr, "%d.%d.%d%c", &v.major, &v.minor, &v.patch, &extraContent);
|
||||
|
||||
// If parsed count is not 3, or there is an extra character, mark as invalid
|
||||
if (parsedCount > 3) {
|
||||
v.major = v.minor = v.patch = 0;
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
Configuration getLatestConfiguration(Configuration *configs, int count) {
|
||||
Configuration latest = configs[0];
|
||||
for (int i = 1; i < count; i++) {
|
||||
const Version ¤tVersion = configs[i].version;
|
||||
const Version &latestVersion = latest.version;
|
||||
|
||||
// Compare the versions stored in the Configuration structs
|
||||
if (currentVersion.major > latestVersion.major ||
|
||||
(currentVersion.major == latestVersion.major && currentVersion.minor > latestVersion.minor) ||
|
||||
(currentVersion.major == latestVersion.major && currentVersion.minor == latestVersion.minor && currentVersion.patch > latestVersion.patch)) {
|
||||
latest = configs[i];
|
||||
}
|
||||
}
|
||||
return latest;
|
||||
}
|
||||
Reference in New Issue
Block a user