X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/f5ecd97b15797e14e691bb6f3562ec1685c96bca..refs/pull/926/head:/client/flasher.c

diff --git a/client/flasher.c b/client/flasher.c
index 2bb87df9..d7fa0b5e 100644
--- a/client/flasher.c
+++ b/client/flasher.c
@@ -10,18 +10,14 @@
 #include <stdlib.h>
 #include <string.h>
 #include <inttypes.h>
+#include <pthread.h>
 #include "proxmark3.h"
 #include "util.h"
 #include "util_posix.h"
 #include "flash.h"
-#include "uart.h"
+#include "comms.h"
 #include "usb_cmd.h"
-
-#ifdef _WIN32
-# define unlink(x)
-#else
-# include <unistd.h>
-#endif
+#include "uart.h"
 
 void cmd_debug(UsbCommand* UC) {
   //  Debug
@@ -37,29 +33,6 @@ void cmd_debug(UsbCommand* UC) {
   printf("...\n");
 }
 
-void SendCommand(UsbCommand* txcmd) {
-//  printf("send: ");
-//  cmd_debug(txcmd);
-  if (!uart_send(sp,(uint8_t*)txcmd,sizeof(UsbCommand))) {
-    printf("Sending bytes to proxmark failed\n");
-    exit(1);
-  }
-}
-
-void ReceiveCommand(UsbCommand* rxcmd) {
-  uint8_t* prxcmd = (uint8_t*)rxcmd;
-  uint8_t* prx = prxcmd;
-  size_t rxlen;
-  while (true) {
-    if (uart_receive(sp, prx, sizeof(UsbCommand) - (prx-prxcmd), &rxlen)) {
-      prx += rxlen;
-      if ((prx-prxcmd) >= sizeof(UsbCommand)) {
-        return;
-      }
-    }
-  }
-}
-
 static void usage(char *argv0)
 {
 	fprintf(stderr, "Usage:   %s <port> [-b] image.elf [image.elf...]\n\n", argv0);
@@ -77,7 +50,7 @@ static void usage(char *argv0)
 
 int main(int argc, char **argv)
 {
-	int can_write_bl = 0;
+	int can_write_bl = false;
 	int num_files = 0;
 	int res;
 	flash_file_t files[MAX_FILES];
@@ -92,7 +65,7 @@ int main(int argc, char **argv)
 	for (int i = 2; i < argc; i++) {
 		if (argv[i][0] == '-') {
 			if (!strcmp(argv[i], "-b")) {
-				can_write_bl = 1;
+				can_write_bl = true;
 			} else {
 				usage(argv[0]);
 				return -1;
@@ -110,12 +83,12 @@ int main(int argc, char **argv)
 
 	char* serial_port_name = argv[1];
 
-	fprintf(stderr,"Waiting for Proxmark to appear on %s", serial_port_name);
-	do {
-		msleep(1000);
-		fprintf(stderr, ".");
-	} while (!OpenProxmark(0, serial_port_name));
-	fprintf(stderr," Found.\n");
+	if (!OpenProxmark(serial_port_name, true, 120)) {   // wait for 2 minutes
+		fprintf(stderr, "Could not find Proxmark on %s.\n\n", serial_port_name);
+		return -1;
+	} else {
+		fprintf(stderr," Found.\n");
+	}
 
 	res = flash_start_flashing(can_write_bl, serial_port_name);
 	if (res < 0)
@@ -137,7 +110,8 @@ int main(int argc, char **argv)
 	if (res < 0)
 		return -1;
 
-	CloseProxmark(serial_port_name);
+	// Stop the command thread.
+	CloseProxmark();
 
 	fprintf(stderr, "All done.\n\n");
 	fprintf(stderr, "Have a nice day!\n");