From 3bfb43d37968a143bfb65d52ab9fb7e7ee7d8ad0 Mon Sep 17 00:00:00 2001
From: root <root@no.no.james.local>
Date: Tue, 1 Sep 2015 14:19:25 +0100
Subject: works

---
 .gitignore   |   1 -
 dfu.c        |   8 +++++---
 nrfdfu.c     |  11 +++++++++--
 prototypes.h |  47 ++++++++++++++++++++++-------------------------
 test.zip     | Bin 0 -> 39564 bytes
 5 files changed, 36 insertions(+), 31 deletions(-)
 create mode 100644 test.zip

diff --git a/.gitignore b/.gitignore
index 35c695c..b12ffae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,4 @@
 main
-test.zip
 *.o
 core.*
 *~
diff --git a/dfu.c b/dfu.c
index 3d22133..ded587b 100644
--- a/dfu.c
+++ b/dfu.c
@@ -57,6 +57,7 @@ send_data_quickly (BLE * b, uint8_t * d, size_t sz, int pkts)
 }
 
 
+#if 0
 static int
 send_data_slowly (BLE * b, uint8_t * d, size_t sz)
 {
@@ -91,8 +92,9 @@ send_data_slowly (BLE * b, uint8_t * d, size_t sz)
   return EXIT_SUCCESS;
 
 }
+#endif
 
-void
+int
 dfu (const char *bdaddr, const char *type, const char *version, uint8_t * dat,
      size_t dat_sz, uint8_t * bin, size_t bin_sz)
 {
@@ -213,7 +215,7 @@ dfu (const char *bdaddr, const char *type, const char *version, uint8_t * dat,
         break;
 
       ble_close (b);
-      return;
+      return 0;
 
 
     }
@@ -228,6 +230,6 @@ dfu (const char *bdaddr, const char *type, const char *version, uint8_t * dat,
 
 
   ble_close (b);
-  exit (EXIT_FAILURE);
+  return -1;
 
 }
diff --git a/nrfdfu.c b/nrfdfu.c
index 3f9316c..81d94da 100644
--- a/nrfdfu.c
+++ b/nrfdfu.c
@@ -34,6 +34,8 @@ main (int argc, char *argv[])
   size_t dat_size;
 
 
+  int tries = 3;
+
 
   while ((opt = getopt (argc, argv, "b:p:")) != -1)
     {
@@ -69,8 +71,13 @@ main (int argc, char *argv[])
           (unsigned) bin_size);
 
 
-  dfu (bdaddr, m->type, m->dfu_version, dat, dat_size, bin, bin_size);
+  while (tries--)
+    {
+      if (!dfu
+          (bdaddr, m->type, m->dfu_version, dat, dat_size, bin, bin_size))
+        return EXIT_SUCCESS;
+    }
 
 
-  return EXIT_SUCCESS;
+  return EXIT_FAILURE;
 }
diff --git a/prototypes.h b/prototypes.h
index e16dc69..0fba901 100644
--- a/prototypes.h
+++ b/prototypes.h
@@ -1,32 +1,29 @@
 /* nrfdfu.c */
-extern int main (int argc, char *argv[]);
+extern int main(int argc, char *argv[]);
 /* util.c */
-extern void *xmalloc (size_t s);
-extern void *xrealloc (void *p, size_t s);
+extern void *xmalloc(size_t s);
+extern void *xrealloc(void *p, size_t s);
 /* zip.c */
-extern void fatal_zip (struct zip *zip);
-extern struct zip *open_zip (const char *fn);
-extern size_t read_file_from_zip (struct zip *zip, const char *fn,
-                                  void *_buf);
+extern void fatal_zip(struct zip *zip);
+extern struct zip *open_zip(const char *fn);
+extern size_t read_file_from_zip(struct zip *zip, const char *fn, void *_buf);
 /* ble.c */
-extern void ble_close (BLE * ble);
-extern void ble_init (void);
-extern BLE *ble_open (const char *bdaddr);
-extern int ble_register_notify (BLE * ble);
-extern int ble_send_cp (BLE * ble, uint8_t * buf, size_t len);
-extern int ble_send_data (BLE * ble, uint8_t * buf, size_t len);
-extern int ble_send_data_noresp (BLE * ble, uint8_t * buf, size_t len);
-extern void ble_wait_setup (BLE * ble, uint8_t op);
-extern int ble_wait_run (BLE * ble);
-extern void ble_notify_pkts_start (BLE * ble);
-extern void ble_notify_pkts_stop (BLE * ble);
-extern size_t ble_notify_get_pkts (BLE * ble);
+extern void ble_close(BLE *ble);
+extern void ble_init(void);
+extern BLE *ble_open(const char *bdaddr);
+extern int ble_register_notify(BLE *ble);
+extern int ble_send_cp(BLE *ble, uint8_t *buf, size_t len);
+extern int ble_send_data(BLE *ble, uint8_t *buf, size_t len);
+extern int ble_send_data_noresp(BLE *ble, uint8_t *buf, size_t len);
+extern void ble_wait_setup(BLE *ble, uint8_t op);
+extern int ble_wait_run(BLE *ble);
+extern void ble_notify_pkts_start(BLE *ble);
+extern void ble_notify_pkts_stop(BLE *ble);
+extern size_t ble_notify_get_pkts(BLE *ble);
 /* manifest.c */
-extern json_object *_json_object_object_get (json_object * obj,
-                                             const char *name);
-extern struct manifest *parse_manifest (const char *str);
+extern json_object *_json_object_object_get(json_object *obj, const char *name);
+extern struct manifest *parse_manifest(const char *str);
 /* dfu.c */
-extern void dfu (const char *bdaddr, const char *type, const char *version,
-                 uint8_t * dat, size_t dat_sz, uint8_t * bin, size_t bin_sz);
+extern int dfu(const char *bdaddr, const char *type, const char *version, uint8_t *dat, size_t dat_sz, uint8_t *bin, size_t bin_sz);
 /* hexdump.c */
-extern void hexdump (void *_d, int len);
+extern void hexdump(void *_d, int len);
diff --git a/test.zip b/test.zip
new file mode 100644
index 0000000..c76787c
Binary files /dev/null and b/test.zip differ
-- 
cgit v1.2.3