Added macro PRINTF_ERROR_RETURN which working with progressbar
This commit is contained in:
1 parent
e4f7cf7bc5
commit
e66d87fde0
3 files changed
+8
-5
No files matched your search
+2
-2
@@ -211,7 +211,7 @@ static int send_2nd(usb_dev_handle * udev, struct image * image) {
|
|||||||
if ( ret == 0 )
|
if ( ret == 0 )
|
||||||
break;
|
break;
|
||||||
if ( usb_bulk_write(udev, WRITE_DEV, (char *)buffer, ret, WRITE_TIMEOUT) != ret )
|
if ( usb_bulk_write(udev, WRITE_DEV, (char *)buffer, ret, WRITE_TIMEOUT) != ret )
|
||||||
ERROR_RETURN("Sending 2nd X-Loader image failed", -1);
|
PRINTF_ERROR_RETURN("Sending 2nd X-Loader image failed", -1);
|
||||||
readed += ret;
|
readed += ret;
|
||||||
printf_progressbar(readed, image->size);
|
printf_progressbar(readed, image->size);
|
||||||
}
|
}
|
||||||
@@ -253,7 +253,7 @@ static int send_secondary(usb_dev_handle * udev, struct image * image) {
|
|||||||
if ( ret == 0 )
|
if ( ret == 0 )
|
||||||
break;
|
break;
|
||||||
if ( usb_bulk_write(udev, WRITE_DEV, (char *)buffer, ret, WRITE_TIMEOUT) != ret )
|
if ( usb_bulk_write(udev, WRITE_DEV, (char *)buffer, ret, WRITE_TIMEOUT) != ret )
|
||||||
ERROR_RETURN("Sending Secondary image failed", -1);
|
PRINTF_ERROR_RETURN("Sending Secondary image failed", -1);
|
||||||
readed += ret;
|
readed += ret;
|
||||||
printf_progressbar(readed, image->size);
|
printf_progressbar(readed, image->size);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -336,7 +336,7 @@ static int nolo_send_image(struct usb_device_info * dev, struct image * image, i
|
|||||||
if ( ret == 0 )
|
if ( ret == 0 )
|
||||||
break;
|
break;
|
||||||
if ( usb_bulk_write(dev->udev, 2, buf, ret, 5000) != ret )
|
if ( usb_bulk_write(dev->udev, 2, buf, ret, 5000) != ret )
|
||||||
ERROR_RETURN("Sending image failed", -1);
|
PRINTF_ERROR_RETURN("Sending image failed", -1);
|
||||||
readed += ret;
|
readed += ret;
|
||||||
printf_progressbar(readed, image->size);
|
printf_progressbar(readed, image->size);
|
||||||
}
|
}
|
||||||
@@ -420,7 +420,7 @@ int nolo_flash_image(struct usb_device_info * dev, struct image * image) {
|
|||||||
while ( state != 4 ) {
|
while ( state != 4 ) {
|
||||||
|
|
||||||
if ( nolo_get_string(dev, "cmt:status", buf, sizeof(buf)) < 0 )
|
if ( nolo_get_string(dev, "cmt:status", buf, sizeof(buf)) < 0 )
|
||||||
ERROR_RETURN("cmt:status failed", -1);
|
PRINTF_ERROR_RETURN("cmt:status failed", -1);
|
||||||
|
|
||||||
if ( strncmp(buf, "finished", strlen("finished")) == 0 ) {
|
if ( strncmp(buf, "finished", strlen("finished")) == 0 ) {
|
||||||
|
|
||||||
@@ -440,7 +440,7 @@ int nolo_flash_image(struct usb_device_info * dev, struct image * image) {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
if ( sscanf(buf, "%s:%llu/%llu", status, &part, &total) != 3 )
|
if ( sscanf(buf, "%s:%llu/%llu", status, &part, &total) != 3 )
|
||||||
ERROR_RETURN("cmt:status unknown", -1);
|
PRINTF_ERROR_RETURN("cmt:status unknown", -1);
|
||||||
|
|
||||||
if ( strcmp(status, "program") == 0 && state <= 0 ) {
|
if ( strcmp(status, "program") == 0 && state <= 0 ) {
|
||||||
printf_progressbar(last_total, last_total);
|
printf_progressbar(last_total, last_total);
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
#ifndef PRINTF_UTILS_H
|
#ifndef PRINTF_UTILS_H
|
||||||
#define PRINTF_UTILS_H
|
#define PRINTF_UTILS_H
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
extern int printf_prev;
|
extern int printf_prev;
|
||||||
|
|
||||||
#define PRINTF_BACK() do { if ( printf_prev ) { printf("\r%-*s\r", printf_prev, ""); printf_prev = 0; } } while (0)
|
#define PRINTF_BACK() do { if ( printf_prev ) { printf("\r%-*s\r", printf_prev, ""); printf_prev = 0; } } while (0)
|
||||||
@@ -27,6 +29,7 @@ extern int printf_prev;
|
|||||||
#define PRINTF_LINE(...) do { PRINTF_BACK(); PRINTF_ADD(__VA_ARGS__); fflush(stdout); } while (0)
|
#define PRINTF_LINE(...) do { PRINTF_BACK(); PRINTF_ADD(__VA_ARGS__); fflush(stdout); } while (0)
|
||||||
#define PRINTF_END() do { if ( printf_prev ) { printf("\n"); printf_prev = 0; } } while (0)
|
#define PRINTF_END() do { if ( printf_prev ) { printf("\n"); printf_prev = 0; } } while (0)
|
||||||
#define PRINTF_ERROR(...) do { PRINTF_END(); ERROR_INFO(__VA_ARGS__); } while (0)
|
#define PRINTF_ERROR(...) do { PRINTF_END(); ERROR_INFO(__VA_ARGS__); } while (0)
|
||||||
|
#define PRINTF_ERROR_RETURN(str, ...) do { PRINTF_ERROR("%s", str); return __VA_ARGS__; } while (0)
|
||||||
|
|
||||||
void printf_progressbar(unsigned long long part, unsigned long long total);
|
void printf_progressbar(unsigned long long part, unsigned long long total);
|
||||||
void printf_and_wait(const char * format, ...);
|
void printf_and_wait(const char * format, ...);
|
||||||
|
|||||||
Reference in new issue
Block a user