[PATCH v2] Notify Ostc 4 users about new firmwares

Anton Lundin glance at acc.umu.se
Sun Jan 8 05:06:10 PST 2017


This adds support for notifying Ostc 4 users about new firmwares when
they download dives from their computers, gives them the option to
trigger the upgrade flow.

Signed-off-by: Anton Lundin <glance at acc.umu.se>
---
 desktop-widgets/configuredivecomputerdialog.cpp | 29 +++++++++++++++++++------
 desktop-widgets/downloadfromdivecomputer.cpp    |  3 ++-
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/desktop-widgets/configuredivecomputerdialog.cpp b/desktop-widgets/configuredivecomputerdialog.cpp
index a91c7d1..e18af71 100644
--- a/desktop-widgets/configuredivecomputerdialog.cpp
+++ b/desktop-widgets/configuredivecomputerdialog.cpp
@@ -233,6 +233,9 @@ OstcFirmwareCheck::OstcFirmwareCheck(QString product) : parent(0)
 	} else if (product == "OSTC Sport") {
 		url = QUrl("http://www.heinrichsweikamp.net/autofirmware/ostc_sport_changelog.txt");
 		latestFirmwareHexFile = QString("http://www.heinrichsweikamp.net/autofirmware/ostc_sport_firmware.hex");
+	} else if (product == "OSTC 4") {
+		url = QUrl("http://www.heinrichsweikamp.net/autofirmware/ostc4_changelog.txt");
+		latestFirmwareHexFile = QString("http://www.heinrichsweikamp.net/autofirmware/ostc4_firmware.bin");
 	} else { // not one of the known dive computers
 		return;
 	}
@@ -260,15 +263,27 @@ void OstcFirmwareCheck::checkLatest(QWidget *_parent, device_data_t *data)
 
 	// libdivecomputer gives us the firmware on device as an integer
 	// for the OSTC that means highbyte.lowbyte is the version number
-	// For OSTC 4's there is actually a another minor, x.y.Z, but its not
-	// exposed via libdivecomputer, so we won't trigger this update flow
-	// when the Z changes
-	int firmwareOnDevice = devData.libdc_firmware;
-	QString firmwareOnDeviceString = QString("%1.%2").arg(firmwareOnDevice / 256).arg(firmwareOnDevice % 256);
+	// For OSTC 4's its stored as XXXX XYYY YYZZ ZZZB, -> X.Y.Z beta?
 
+	int firmwareOnDevice = devData.libdc_firmware;
+	QString firmwareOnDeviceString;
 	// Convert the latestFirmwareAvailable to a integear we can compare with
 	QStringList fwParts = latestFirmwareAvailable.split(".");
-	int latestFirmwareAvailableNumber = fwParts[0].toInt() * 256 + fwParts[1].toInt();
+	int latestFirmwareAvailableNumber;
+
+	if (strcmp(data->product, "OSTC 4") == 0) {
+		unsigned char X, Y, Z, beta;
+		X = (firmwareOnDevice & 0xF800) >> 11;
+		Y = (firmwareOnDevice & 0x07C0) >> 6;
+		Z = (firmwareOnDevice & 0x003E) >> 1;
+		beta = firmwareOnDevice & 0x0001;
+		firmwareOnDeviceString = QString("%1.%2.%3%4").arg(X).arg(Y).arg(Z).arg(beta?" beta":"");
+		latestFirmwareAvailableNumber = fwParts[0].toInt() << 11 + fwParts[1].toInt() << 6 + fwParts[1].toInt() <<1;
+	} else { // OSTC 3, Sport, Cr
+		firmwareOnDeviceString = QString("%1.%2").arg(firmwareOnDevice / 256).arg(firmwareOnDevice % 256);
+		latestFirmwareAvailableNumber = fwParts[0].toInt() * 256 + fwParts[1].toInt();
+	}
+
 	if (latestFirmwareAvailableNumber > firmwareOnDevice) {
 		QMessageBox response(parent);
 		QString message = tr("You should update the firmware on your dive computer: you have version %1 but the latest stable version is %2")
@@ -297,7 +312,7 @@ void OstcFirmwareCheck::upgradeFirmware()
 	QFileInfo fi(filename);
 	filename = fi.absolutePath().append(QDir::separator()).append(saveFileName);
 	storeFirmware = QFileDialog::getSaveFileName(parent, tr("Save the downloaded firmware as"),
-						     filename, tr("HEX files (*.hex)"));
+						     filename, tr("Firmware files (*.hex *.bin)"));
 	if (storeFirmware.isEmpty())
 		return;
 
diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp
index 61ec172..ab8e5a3 100644
--- a/desktop-widgets/downloadfromdivecomputer.cpp
+++ b/desktop-widgets/downloadfromdivecomputer.cpp
@@ -371,7 +371,8 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
 	// this check will compair apples and oranges, firmware wise, then.
 	QString product(ui.product->currentText());
 	if (product == "OSTC 3" || product == "OSTC 3+" ||
-			product == "OSTC Cr" || product == "OSTC Sport")
+			product == "OSTC Cr" || product == "OSTC Sport" ||
+			product == "OSTC 4")
 		ostcFirmwareCheck = new OstcFirmwareCheck(product);
 }
 
-- 
2.9.3



More information about the subsurface mailing list