<HTML><BODY><div id="composeWebView_editable_content" data-mailruapp-compose-id="composeWebView_editable_content" style="text-align: left;">Tested this today. Works with my 240 dives I have by now on the Uemis.<div><br></div><div>Also the blindly strstr was obvious and an overlook on my side.</div><div><br></div><div>The initial object id wasn't from me :-)</div><div><br></div><div>So I am happy with my newbie contributions :-)</div><div><br></div><div>The code to update selected dives is ready but requires a UI change. I suppose you don't want this for 4.5.<br><br>G. Lerch<br><br><br>Sonntag, 20. September 2015 06:14 +0200 von Linus Torvalds  <torvalds@linux-foundation.org>:<br>    <div id="composeWebView_previouse_content" data-mailruapp-compose-id="composeWebView_previouse_content"><blockquote style="border-left: 1px solid #fc2c38; margin: 10px 10px 10px 5px; padding: 0 0 0 10px;"><div class="js-helper js-readmsg-msg">
        <style type="text/css"></style>
        <div>
                <base target="_self" href="https://e-aj.my.com/">
                
                        <div id="style_14427224980000003548_BODY"><br>
From: Linus Torvalds <<a href="/compose?To=torvalds@linux%2dfoundation.org">torvalds@linux-foundation.org</a>><br>
Date: Sat, 19 Sep 2015 21:09:58 -0700<br>
Subject: [PATCH 2/2] uemis downloader: start downloading using the correct dive ID<br>
<br>
The logic to pick the initial dive ID for the uemis downloader was very<br>
confused, and did not work at all when restarting a download when the<br>
Uemis filled up, and the "Force download all dives" flag was set.  It<br>
also required a rather odd Uemis-specific callback from the download UI<br>
because of how it picked the initial ID.<br>
<br>
This changes the logic to just look at the list of downloaded dives when<br>
restarting, which simplifies the logic a lot, gets rid of the odd<br>
special callback, and also means that the whole "Force download" issue<br>
just goes away.  It seems to work now.<br>
<br>
Signed-off-by: Linus Torvalds <<a href="/compose?To=torvalds@linux%2dfoundation.org">torvalds@linux-foundation.org</a>><br>
---<br>
 dive.h                             |  2 +-<br>
 qt-ui/downloadfromdivecomputer.cpp |  8 --------<br>
 uemis-downloader.c                 | 40 +++++++++++++++++++++-----------------<br>
 uemis.h                            |  1 -<br>
 4 files changed, 23 insertions(+), 28 deletions(-)<br>
<br>
diff --git a/dive.h b/dive.h<br>
index fa95f6721631..4eb44cfc9c8d 100644<br>
--- a/dive.h<br>
+++ b/dive.h<br>
@@ -498,7 +498,7 @@ struct dive_table {<br>
   struct dive **dives;<br>
 };<br>
 <br>
-extern struct dive_table dive_table;<br>
+extern struct dive_table dive_table, downloadTable;<br>
 extern struct dive displayed_dive;<br>
 extern struct dive_site displayed_dive_site;<br>
 extern int selected_dive;<br>
diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp<br>
index 7e18dae70baa..1fef9f6bff1e 100644<br>
--- a/qt-ui/downloadfromdivecomputer.cpp<br>
+++ b/qt-ui/downloadfromdivecomputer.cpp<br>
@@ -298,14 +298,6 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()<br>
           diveImportedModel->clearTable();<br>
           clear_table(&downloadTable);<br>
   }<br>
-       if (ui.vendor->currentText() == "Uemis") {<br>
-               if (currentState == ERROR && downloadTable.nr > 0)<br>
-                       // let the uemis code know how far we've gotten<br>
-                       uemis_set_max_diveid_from_dialog(downloadTable.dives[downloadTable.nr - 1]->dc.diveid);<br>
-               else<br>
-                       // fresh download, so only look at what's in the dive_table<br>
-                       uemis_set_max_diveid_from_dialog(0);<br>
-       }<br>
   updateState(DOWNLOADING);<br>
 <br>
   // you cannot cancel the dialog, just the download<br>
diff --git a/uemis-downloader.c b/uemis-downloader.c<br>
index 70cc3f78d449..3b8ddf900e89 100644<br>
--- a/uemis-downloader.c<br>
+++ b/uemis-downloader.c<br>
@@ -928,23 +928,32 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, char *<br>
   return true;<br>
 }<br>
 <br>
-static int max_diveid_from_dialog;<br>
-<br>
-void uemis_set_max_diveid_from_dialog(int diveid)<br>
-{<br>
-       max_diveid_from_dialog = diveid;<br>
-}<br>
-<br>
-static char *uemis_get_divenr(char *deviceidstr)<br>
+static char *uemis_get_divenr(char *deviceidstr, int force)<br>
 {<br>
   uint32_t deviceid, maxdiveid = 0;<br>
   int i;<br>
   char divenr[10];<br>
-<br>
+       struct dive_table *table;<br>
   deviceid = atoi(deviceidstr);<br>
-       struct dive *d;<br>
-       for_each_dive (i, d) {<br>
+<br>
+       /*<br>
+        * If we are are retrying after a disconnect/reconnect, we<br>
+        * will look up the highest dive number in the dives we<br>
+        * already have.<br>
+        *<br>
+        * Also, if "force_download" is true, do this even if we<br>
+        * don't have any dives (maxdiveid will remain zero)<br>
+        */<br>
+       if (force || downloadTable.nr)<br>
+               table = &downloadTable;<br>
+       else<br>
+               table = &dive_table;<br>
+<br>
+       for (i = 0; i < table->nr; i++) {<br>
+               struct dive *d = table->dives[i];<br>
           struct divecomputer *dc;<br>
+               if (!d)<br>
+                       continue;<br>
           for_each_dc (d, dc) {<br>
                   if (dc->model && !strcmp(dc->model, "Uemis Zurich") &&<br>
                       (dc->deviceid == 0 || dc->deviceid == 0x7fffffff || dc->deviceid == deviceid) &&<br>
@@ -952,7 +961,7 @@ static char *uemis_get_divenr(char *deviceidstr)<br>
                           maxdiveid = dc->diveid;<br>
           }<br>
   }<br>
-       snprintf(divenr, 10, "%d", maxdiveid > max_diveid_from_dialog ? maxdiveid : max_diveid_from_dialog);<br>
+       snprintf(divenr, 10, "%d", maxdiveid);<br>
   return strdup(divenr);<br>
 }<br>
 <br>
@@ -1215,12 +1224,7 @@ const char *do_uemis_import(device_data_t *data)<br>
           goto bail;<br>
 <br>
   param_buff[1] = "notempty";<br>
-       /* if we force it we start downloading from the first dive on the Uemis;<br>
-        *  otherwise check which was the last dive downloaded */<br>
-       if (!force_download)<br>
-               newmax = uemis_get_divenr(deviceid);<br>
-       else<br>
-               newmax = strdup("0");<br>
+       newmax = uemis_get_divenr(deviceid, force_download);<br>
 <br>
   first = start = atoi(newmax);<br>
   dive_to_read = first;<br>
diff --git a/uemis.h b/uemis.h<br>
index 90ae99028799..5f32fe76c0af 100644<br>
--- a/uemis.h<br>
+++ b/uemis.h<br>
@@ -16,7 +16,6 @@ void uemis_parse_divelog_binary(char *base64, void *divep);<br>
 int uemis_get_weight_unit(int diveid);<br>
 void uemis_mark_divelocation(int diveid, int divespot, uint32_t dive_site_uuid);<br>
 void uemis_set_divelocation(int divespot, char *text, double longitude, double latitude);<br>
-void uemis_set_max_diveid_from_dialog(int diveid);<br>
 int uemis_get_divespot_id_by_diveid(uint32_t diveid);<br>
 <br>
 typedef struct<br>
-- <br>
2.6.0.rc1.16.g1962994<br>
<br>
</div>
                        
                
                <base target="_self" href="https://e-aj.my.com/">
        </div>

        
</div></blockquote></div></div></div></BODY></HTML>