diff options
Diffstat (limited to 'monitor')
-rw-r--r-- | monitor/Makefile | 3 | ||||
-rw-r--r-- | monitor/disp.c | 35 | ||||
-rwxr-xr-x | monitor/mon | bin | 17656 -> 0 bytes | |||
-rw-r--r-- | monitor/mon.c | 51 | ||||
-rw-r--r-- | monitor/mon.h | 7 |
5 files changed, 91 insertions, 5 deletions
diff --git a/monitor/Makefile b/monitor/Makefile index 15dadc4..92b7a60 100644 --- a/monitor/Makefile +++ b/monitor/Makefile @@ -3,3 +3,6 @@ HF=mon.h mon: $(CF) $(HF) gcc -o $@ $(CF) -lcurses -O2 + +clean: + rm mon diff --git a/monitor/disp.c b/monitor/disp.c index 7eaedc0..96d994d 100644 --- a/monitor/disp.c +++ b/monitor/disp.c @@ -74,9 +74,12 @@ void disp_display(t_mon *mon) { werase(wpstatus); - wprintw(wpstatus, "Step:\t\t%d\t%s\t%s\n", + wprintw(wpstatus, "Step:\t\t%d\t%s", mon->step, - (mon->status == MS_AUTO ? "A" : "M"), + (mon->status == MS_AUTO ? "A" : (mon->status == MS_RUN ? "M" : ""))); + if (mon->status == MS_FREQ) wprintw(wpstatus, "%dHz", mon->freq); + if (mon->status == MS_AUTO) wprintw(wpstatus, " %dHz", mon->max_freq); + wprintw(wpstatus, "\t%s\n", (mon->ticker_mode == TM_SECOND ? "TS" : (mon->ticker_mode == TM_FAST ? "TF" : "TZ"))); wprintw(wpstatus, "\nInputs:\n"); @@ -98,9 +101,30 @@ void disp_display(t_mon *mon) { } if (mon->n_outputs == 0) wprintw(wpstatus, "\t(none)\n"); - wprintw(wpstatus, "\nSerial buffer:\n%s\n", mon->ser_buf); + if (mon->ser_in_in != -1) { + wprintw(wpstatus, "\nSerial buffer:\n%s\n", mon->ser_buf); + } + + wprintw(wpstatus, "\n\n"); + for (i = 0; i < 8; i++) + wprintw(wpstatus, " %s ", (mon->d7[i] != -1 && mon->outputs[mon->d7[i]].v_bin[0] == '1' ? "---" : " ")); + wprintw(wpstatus, "\n"); + for (i = 0; i < 8; i++) + wprintw(wpstatus, " %c %c", + (mon->d7[i] != -1 && mon->outputs[mon->d7[i]].v_bin[1] == '1' ? '|' : ' '), + (mon->d7[i] != -1 && mon->outputs[mon->d7[i]].v_bin[2] == '1' ? '|' : ' ')); + wprintw(wpstatus, "\n"); + for (i = 0; i < 8; i++) + wprintw(wpstatus, " %s ", (mon->d7[i] != -1 && mon->outputs[mon->d7[i]].v_bin[3] == '1' ? "---" : " ")); + wprintw(wpstatus, "\n"); + for (i = 0; i < 8; i++) + wprintw(wpstatus, " %c %c", + (mon->d7[i] != -1 && mon->outputs[mon->d7[i]].v_bin[4] == '1' ? '|' : ' '), + (mon->d7[i] != -1 && mon->outputs[mon->d7[i]].v_bin[5] == '1' ? '|' : ' ')); + wprintw(wpstatus, "\n"); + for (i = 0; i < 8; i++) + wprintw(wpstatus, " %s ", (mon->d7[i] != -1 && mon->outputs[mon->d7[i]].v_bin[6] == '1' ? "---" : " ")); - wmove(wcmdline, 0, cmd_pos + 2); wrefresh(wpstatus); if (mon->ser_out_buf != 0) { @@ -108,6 +132,9 @@ void disp_display(t_mon *mon) { wrefresh(wpoutput); mon->ser_out_buf = 0; } + + wmove(wcmdline, 0, cmd_pos + 2); + wrefresh(wcmdline); } diff --git a/monitor/mon b/monitor/mon Binary files differdeleted file mode 100755 index 0c60bde..0000000 --- a/monitor/mon +++ /dev/null diff --git a/monitor/mon.c b/monitor/mon.c index 41182a8..4a51f6e 100644 --- a/monitor/mon.c +++ b/monitor/mon.c @@ -10,6 +10,7 @@ q Quit a Set automatic mode (send input all the time) m Set manual mode (send input when user sends empty command) + f <freq> Set frequency mode (every second, do 'freq' steps) i <id> <v> Set input #id to value v (v is a string, transmitted as-is to simulator) tf Tick fast (send 1 every cycle) ts Tick for every second @@ -22,6 +23,7 @@ i3 : output for serial output s Set no serial input :<text> Send text to serial + d7 x x ... Set outputs to be interpreted as 7-bar digit displayer (up to 8 outputs, use - for no output) */ int mon_read_prologue(t_mon *mon) { @@ -49,6 +51,8 @@ int mon_read_prologue(t_mon *mon) { } mon->step = 0; + mon->freq = 1; + mon->max_freq = 1000; mon->status = MS_RUN; mon->clk = time(NULL); @@ -61,15 +65,39 @@ int mon_read_prologue(t_mon *mon) { mon->ser_buf[0] = 0; mon->ser_out_buf = 0; + for (i = 0; i < 8; i++) mon->d7[i] = -1; + return 0; } void mon_loop(t_mon *mon) { disp_display(mon); + time_t prev_time = time(NULL); + int steps = 0; + while (mon->status != MS_FINISH) { handle_kbd(mon); if (mon->status == MS_AUTO) { mon_step(mon); + steps++; + if (time(NULL) != prev_time) { + mon->max_freq = steps; + steps = 0; + prev_time = time(NULL); + } + } else if (mon->status == MS_FREQ) { + if (steps < mon->freq) { + mon_step(mon); + steps++; + usleep(1000000 / mon->freq - 1000000 / mon->max_freq); + } else { + if (prev_time != time(NULL)) { + steps = 0; + prev_time = time(NULL); + } else { + usleep(10000); + } + } } else { usleep(10000); } @@ -85,6 +113,12 @@ void mon_handle_command(t_mon *mon, const char *c) { mon->status = MS_AUTO; } else if (!strcmp(c, "m")) { mon->status = MS_RUN; + } else if (c[0] == 'f') { + const char *p = c + 1; + mon->freq = 0; + while (isspace(*p)) p++; + while (isdigit(*p)) mon->freq = 10 * mon->freq + (*(p++) - '0'); + mon->status = MS_FREQ; } else if (c[0] == 'i') { const char *p = c + 1; int a = 0; @@ -132,9 +166,26 @@ void mon_handle_command(t_mon *mon, const char *c) { mon->ser_out = w; } } + } else if (c[0] == ':') { strcat(mon->ser_buf, c + 1); strcat(mon->ser_buf, "\n"); + } else if (c[0] == 'd' && c[1] == '7') { + const char *p = c + 2; + int i = 0; + for (i = 0; i < 8; i++) { + while (isspace(*p)) p++; + if (*p == 0) { + mon->d7[i] = -1; + } else if (*p == '-') { + mon->d7[i] = -1; + p++; + } else { + mon->d7[i] = 0; + while (isdigit(*p)) mon->d7[i] = 10 * mon->d7[i] + (*(p++) - '0'); + if (mon->d7[i] >= mon->n_outputs) mon->d7[i] = -1; + } + } } disp_display(mon); } diff --git a/monitor/mon.h b/monitor/mon.h index 39ac37e..7abcf8c 100644 --- a/monitor/mon.h +++ b/monitor/mon.h @@ -22,7 +22,8 @@ typedef struct { typedef enum { MS_FINISH, MS_RUN, - MS_AUTO + MS_AUTO, + MS_FREQ } t_status; typedef enum { @@ -39,6 +40,8 @@ typedef struct { t_output *outputs; int step; + int freq; + int max_freq; t_status status; @@ -49,6 +52,8 @@ typedef struct { int ser_in_in, ser_in_busy_out, ser_out; char ser_buf[256]; char ser_out_buf; + + int d7[8]; } t_mon; void disp_init(); |