Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:liuhw
picocom
display_time.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File display_time.patch of Package picocom
diff --git a/picocom.c b/picocom.c index 36fba37..3449f7e 100644 --- a/picocom.c +++ b/picocom.c @@ -36,6 +36,8 @@ #include <sys/types.h> #include <sys/stat.h> #include <sys/wait.h> +#include <sys/time.h> +#include <time.h> #include <limits.h> #ifdef USE_FLOCK #include <sys/file.h> @@ -101,6 +103,7 @@ const char *flow_str[] = { #define KEY_KEYS CKEY('k') /* show available command keys */ #define KEY_SEND CKEY('s') /* send file */ #define KEY_RECEIVE CKEY('r') /* receive file */ +#define KEY_TIME CKEY('z') /* show time */ #define KEY_HEX CKEY('w') /* write hex */ #define KEY_BREAK CKEY('\\') /* break */ @@ -216,6 +219,7 @@ struct { int raise_rts; int raise_dtr; int quiet; + int time; } opts = { .port = NULL, .baud = 9600, @@ -245,6 +249,7 @@ struct { .lower_dtr = 0, .raise_rts = 0, .raise_dtr = 0, + .time = 0, .quiet = 0 }; @@ -1045,6 +1050,8 @@ show_keys() KEYC(KEY_SEND)); fd_printf(STO, "*** [C-%c] : Receive file\r\n", KEYC(KEY_RECEIVE)); + fd_printf(STO, "*** [C-%c] : Toggle display time\r\n", + KEYC(KEY_TIME)); fd_printf(STO, "*** [C-%c] : Show port settings\r\n", KEYC(KEY_STATUS)); fd_printf(STO, "*** [C-%c] : Show this message\r\n", @@ -1359,6 +1366,14 @@ do_command (unsigned char c) run_cmd(tty_fd, xfr_cmd, fname); free(fname); break; + case KEY_TIME: + opts.time = (opts.time + 1) % 2; + if ( opts.time ) { + fd_printf(STO, "\r\n*** display time on ***\r\n"); + }else{ + fd_printf(STO, "\r\n*** display time off ***\r\n"); + } + break; case KEY_HEX: n = read_hex(hexbuf, sizeof(hexbuf)); if ( n < 0 ) { @@ -1382,6 +1397,24 @@ do_command (unsigned char c) /**********************************************************************/ +void print_time_str(void) +{ + static int xa,xb; + struct timeval tv; + struct tm lt = {0}; + char buff[32], buff2[64]; + + gettimeofday(&tv, NULL); + xa = (tv.tv_sec % 100000) * 1000 + (tv.tv_usec / 1000); + if ( xa - xb > 5 ) { + xb = xa; + localtime_r(&(tv.tv_sec), <); + strftime(buff, sizeof(buff), "%H:%M:%S", <); + sprintf(buff2, "\r\n%s.%03ld> ", buff, tv.tv_usec / 1000); + write(STO, buff2, 16); + } +} + static struct timeval * msec2tv (struct timeval *tv, long ms) { @@ -1519,6 +1552,9 @@ loop(void) } else { int i; char *bmp = &buff_map[0]; + if ( opts.time ){ + print_time_str(); + } if ( opts.log_filename ) if ( writen_ni(log_fd, buff_rd, n) < n ) fatal("write to logfile failed: %s", strerror(errno));
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor