updating the version check in the device model for firmware versions, the string comparison was just wrong
This commit is contained in:
parent
a7fee2f76d
commit
2edca58f7c
3 changed files with 64 additions and 13 deletions
|
|
@ -226,7 +226,6 @@ export default function DeviceWizard(props: Props) {
|
|||
*/
|
||||
const adjustAvailablePositions = (port: PortInformation, availability: DeviceAvailabilityMap) => {
|
||||
let currentAvailability = availability;
|
||||
console.log(port)
|
||||
switch (port.addressType) {
|
||||
case quack.AddressType.ADDRESS_TYPE_CONFIGURABLE_PIN_ARRAY:
|
||||
currentAvailability.set(port.addressType, [{ address: port.address, label: port.label }]);
|
||||
|
|
|
|||
|
|
@ -181,6 +181,59 @@ export class Device {
|
|||
return max
|
||||
}
|
||||
|
||||
private versionComparison(deviceVersion: string, requiredVersion: string): boolean {
|
||||
const parse = (v: string) => {
|
||||
const [core, pre] = v.split("-");
|
||||
const parts = core.split(".").map(n => parseInt(n, 10));
|
||||
|
||||
let preLabel = "";
|
||||
let preNum = 0;
|
||||
|
||||
if (pre) {
|
||||
const match = pre.match(/^([a-zA-Z]+)(\d*)$/);
|
||||
if (match) {
|
||||
preLabel = match[1].toLowerCase();
|
||||
preNum = match[2] ? parseInt(match[2], 10) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
return { parts, preLabel, preNum };
|
||||
};
|
||||
|
||||
const rank = (label: string): number => {
|
||||
switch (label) {
|
||||
case "alpha": return 1;
|
||||
case "beta": return 2;
|
||||
case "rc": return 3;
|
||||
default: return 0; // release
|
||||
}
|
||||
};
|
||||
|
||||
const a = parse(deviceVersion);
|
||||
const b = parse(requiredVersion);
|
||||
|
||||
// Compare major/minor/patch
|
||||
const len = Math.max(a.parts.length, b.parts.length);
|
||||
for (let i = 0; i < len; i++) {
|
||||
const av = a.parts[i] ?? 0;
|
||||
const bv = b.parts[i] ?? 0;
|
||||
if (av > bv) return true;
|
||||
if (av < bv) return false;
|
||||
}
|
||||
|
||||
// Handle prerelease vs release
|
||||
if (!a.preLabel && b.preLabel) return true; // release > prerelease
|
||||
if (a.preLabel && !b.preLabel) return false;
|
||||
|
||||
// Both prereleases → compare rank
|
||||
if (a.preLabel !== b.preLabel) {
|
||||
return rank(a.preLabel) >= rank(b.preLabel);
|
||||
}
|
||||
|
||||
// Same prerelease label → compare numeric suffix
|
||||
return a.preNum >= b.preNum;
|
||||
}
|
||||
|
||||
public featureSupported(feature: string): boolean {
|
||||
let versions = featureVersions.get(feature);
|
||||
if (!versions) {
|
||||
|
|
@ -188,27 +241,27 @@ export class Device {
|
|||
}
|
||||
switch (this.settings.platform) {
|
||||
case pond.DevicePlatform.DEVICE_PLATFORM_PHOTON:
|
||||
return this.status.firmwareVersion >= versions.photon;
|
||||
return this.versionComparison(this.status.firmwareVersion, versions.photon);
|
||||
case pond.DevicePlatform.DEVICE_PLATFORM_ELECTRON:
|
||||
return this.status.firmwareVersion >= versions.electron;
|
||||
return this.versionComparison(this.status.firmwareVersion, versions.electron);
|
||||
case pond.DevicePlatform.DEVICE_PLATFORM_V2_CELLULAR:
|
||||
return this.status.firmwareVersion >= versions.v2Cell;
|
||||
return this.versionComparison(this.status.firmwareVersion, versions.v2Cell);
|
||||
case pond.DevicePlatform.DEVICE_PLATFORM_V2_WIFI:
|
||||
return this.status.firmwareVersion >= versions.v2Wifi;
|
||||
return this.versionComparison(this.status.firmwareVersion, versions.v2Wifi);
|
||||
case pond.DevicePlatform.DEVICE_PLATFORM_V2_WIFI_S3:
|
||||
return this.status.firmwareVersion >= versions.v2WifiS3;
|
||||
return this.versionComparison(this.status.firmwareVersion, versions.v2WifiS3);
|
||||
case pond.DevicePlatform.DEVICE_PLATFORM_V2_CELLULAR_S3:
|
||||
return this.status.firmwareVersion >= versions.v2CellS3;
|
||||
return this.versionComparison(this.status.firmwareVersion, versions.v2CellS3);
|
||||
case pond.DevicePlatform.DEVICE_PLATFORM_V2_CELLULAR_BLACK:
|
||||
return this.status.firmwareVersion >= versions.v2CellBlack;
|
||||
return this.versionComparison(this.status.firmwareVersion, versions.v2CellBlack);
|
||||
case pond.DevicePlatform.DEVICE_PLATFORM_V2_CELLULAR_GREEN:
|
||||
return this.status.firmwareVersion >= versions.v2CellGreen;
|
||||
return this.versionComparison(this.status.firmwareVersion, versions.v2CellGreen);
|
||||
case pond.DevicePlatform.DEVICE_PLATFORM_V2_WIFI_BLUE:
|
||||
return this.status.firmwareVersion >= versions.v2WifiBlue;
|
||||
return this.versionComparison(this.status.firmwareVersion, versions.v2WifiBlue);
|
||||
case pond.DevicePlatform.DEVICE_PLATFORM_V2_CELLULAR_BLUE:
|
||||
return this.status.firmwareVersion >= versions.v2CellBlue;
|
||||
return this.versionComparison(this.status.firmwareVersion, versions.v2CellBlue);
|
||||
case pond.DevicePlatform.DEVICE_PLATFORM_V2_ETHERNET_BLUE:
|
||||
return this.status.firmwareVersion >= versions.v2EthBlue;
|
||||
return this.versionComparison(this.status.firmwareVersion, versions.v2EthBlue);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,7 +169,6 @@ export default function DevicePage() {
|
|||
const loadPortScan = () => {
|
||||
deviceAPI.listFoundComponents(parseInt(deviceID))
|
||||
.then(resp => {
|
||||
console.log(resp.data)
|
||||
if (resp.data.foundComponents?.i2c || resp.data.foundComponents?.oneWire){
|
||||
setScannedAddresses(pond.ListFoundComponentsResponse.fromObject(resp.data).foundComponents ?? undefined)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue