summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Vymetalek <pavel@vym.cz>2015-06-07 01:21:47 +0200
committerPavel Vymetalek <pavel@vym.cz>2015-06-07 01:21:47 +0200
commitaabf4d86a7fe5c4d48e440e8d4a1b05dadc6ea7a (patch)
tree3c8f2e292513b75c4e99fd3f3a30b9b7b82344b7
parenta0437c10c49126f3924c62eb50b741da476c60ad (diff)
downloadtaptoserial-aabf4d86a7fe5c4d48e440e8d4a1b05dadc6ea7a.tar.gz
prvni pokusy na progressbaru
-rw-r--r--taptoser.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/taptoser.c b/taptoser.c
index 834c2a7..3985022 100644
--- a/taptoser.c
+++ b/taptoser.c
@@ -1,4 +1,5 @@
-#include <stdio.h>
+#include <stdio.h>
+#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@@ -27,6 +28,9 @@ static int inp_indx = 0;
int serial_fd;
size_t out_indx;
+float width, progress_pos, progress_part;
+
+
void usage(void) {
printf ("Tap file serial port uploader/downloader. (c)2012 Pavel Vymetálek <pvymetalek@seznam.cz>\n");
printf ("Usage:\ntaptoser [-v] [-h] [-o] [-b|--baud baud_rate] /dev/serial tap_file\n");
@@ -130,6 +134,7 @@ void decode(unsigned char *header)
{
char name[11];
unsigned int n;
+ unsigned int pos_progress;
strncpy(name, (char*)(header+2), 10);
name[10] = '\0';
@@ -137,14 +142,14 @@ void decode(unsigned char *header)
printf("Flag: %u\n", (unsigned int)*header);
n = getword(header+14);
h_len = getword(header+12);
+
switch(*(header+1))
{
case '\0':
printf("Type: 0 => program\nProgram length: %u bytes\n", h_len);
- if (n < 32768)
- printf("Runs from line %u\n", n);
+ if (n < 32768) printf("Runs from line %u\n", n);
printf("Length without variables: %u bytes\n",
- getword(header+16));
+ getword(header+16));
break;
case '\1':
printf("Type: 1 => number array\nLength: %u bytes\n", h_len);
@@ -172,6 +177,11 @@ int main(int argc, char** argv, char** env)
long pos = 0;
struct stat st;
unsigned char header[19];
+
+ struct winsize termsize;
+ ioctl (STDOUT_FILENO, TIOCGWINSZ, &termsize);
+ printf ("width: %d \n", termsize.ws_col);
+ width = termsize.ws_col;
struct termios oldtio, newtio;
int z;
@@ -238,6 +248,9 @@ int main(int argc, char** argv, char** env)
tooshort(fd);
for (out_indx = 0; out_indx < 2; out_indx++) {
TestCts();
+ progress_pos = 0;
+
+ printf("[");
write (serial_fd, &header[out_indx], 1);
usleep (200);
}
@@ -266,6 +279,12 @@ int main(int argc, char** argv, char** env)
pos += no = fread(header, 1, 1, fd);
TestCts();
write (serial_fd, header, 1);
+ progress_part = h_len / width;
+
+// for (progress_pos = 0; progress_pos < out_indx*progress_part; progress_pos++) {
+// printf ("#\r");
+// }
+
usleep (1000);
if (no != 1)
tooshort(fd);