piggz / harbour-amazfish

Amazfit Bip support for SailfishOS
GNU General Public License v3.0
103 stars 51 forks source link

InfiniTime resource downloading not working #246

Closed omartijn closed 8 months ago

omartijn commented 1 year ago

I have just installed the latest version of AmazFish on my device (a Sony Xperia 10 II running SFOS 4.4.0.72) from Chum. My watch is running InfiniTime 1.11.0, installed a few days ago (when it came out).

I have downloaded the resource zip and am trying to flash it to the watch using the "Download File" option. When I select the file it tells me the file type is "Ressource ()", it shows 0% (even before pressing the button). Then nothing more happens. Pressing the download button does nothing, the watch is also not showing any response to this.

Am I doing something wrong?

warnerbryce commented 1 year ago

I have the same situation : SailfishOS 4.3 PinePhone Pro Amazfish 2.10

JF002 commented 1 year ago

I checked on my x86_64 desktop (running Manjaro) and on my arm64 laptop (running Manjaro ARM) and it worked as expected. However, I tested on my Pinephone running SFOS and... yeah, it doesn't work.

After further analysis, I noticed that Amazfish tries to send a *huge data packet to the PineTime. It's probably bigger than the amount of memory allocated to the BLE stack in InfiniTime so the transfer fails.

The issue seems to be located in this function : Amazfish needs to know the MTU that was negotiated between the host and the watch to know the maximum packet size it can send. The default value is 20 bytes, but it's set to another value if we can get one.

The issue in this case is that the function returns 0, which probably means "infinity", which is not good for an embedded system with a very small RAM memory!

I tried with applying a MTU of 200 bytes in that case, and everything seems to work properly.

So, I guess we need to handle the errors in that function, and chose a sane default MTU value... OR... understand why the MTU is not properly reported on some setups!

For reference, here is the patch with my test:

$ git diff
diff --git a/daemon/src/devices/pinetimejfdevice.cpp b/daemon/src/devices/pinetimejfdevice.cpp
index 8f36e49..8871f5b 100644
--- a/daemon/src/devices/pinetimejfdevice.cpp
+++ b/daemon/src/devices/pinetimejfdevice.cpp
@@ -16,7 +16,8 @@
 namespace {
     size_t GetMtuForCharacteristic(QString path, const char* characteristicUUID)
     {
-        size_t transferMtu = 20;
+       qDebug() << "Get MTU...";
+        size_t transferMtu = 200;
         QDBusInterface adapterIntro("org.bluez", path, "org.freedesktop.DBus.Introspectable", QDBusConnection::systemBus(), 0);
         QDBusReply<QString> adapterXml = adapterIntro.call("Introspect");
         QDomDocument adapterDoc;
@@ -34,11 +35,15 @@ namespace {
                 if(currentCharacteristicUUID == characteristicUUID){
                     QDBusInterface mtuInterface("org.bluez", nodePath, "org.bluez.GattCharacteristic1", QDBusConnection::systemBus(), 0);
                     QString mtu = mtuInterface.property("MTU").toString();
-                    transferMtu = mtu.toInt();
+                   int detectedMtu = mtu.toInt();
+                   if(detectedMtu > 0)
+                      transferMtu = mtu.toInt();
+                   qDebug()<<"Detected MTU : " << transferMtu;
                 }

             }
         }
+       qDebug() << "Returned MTU : " << transferMtu;
         return transferMtu;
     }
 }

Edit : upgrading to bluez 5.65 seems to fix the issue!

piggz commented 1 year ago

Further investigation shows updating to to bluez 5.65 fixes the problem. This is available at https://build.merproject.org/project/show/home:piggz:harbour-amazfish-dev until it lands in sailfish in the next version.

omartijn commented 1 year ago

Ah, thanks. I checked the packages there, but that unfortunately only shows build for older SFOS versions. My device is on 4.4.0.72, the closes build of bluez5 is 4.4.0.58.

piggz commented 8 months ago

@omartijn this is fixed and can be closed?

omartijn commented 8 months ago

Yes, it started working after an update to SFOS.