Commit 95f45fc7 authored by Christian Fibich's avatar Christian Fibich Committed by Stefan Tauner
Browse files

[FIC Emulator]

Added functionality to automatically spawn PTY pair.
Can now replace a CONF_DONE message by an UNDERRUN.
parent 63c5d352
......@@ -6,8 +6,10 @@ TIMER_BYTES=$(shell sed -nr 's/^TIMER_WIDTH=([0-9]+)$$/\1/p' $(FIJI_CFG_FILE))
.PHONY: clean
CFLAGS=-Wno-implicit-fallthrough -Wall -Wextra -pedantic -std=c11
fic-emulator: fic-emulator.c $(FIJI_CFG_FILE)
gcc -Wall -Wextra -pedantic -std=c11 $< \
gcc $(CFLAGS) $< \
-DCFG_FILE='"$(FIJI_CFG_FILE)"' \
-DFIU_NUM=$(FIU_NUM) \
-DFIU_CFG_BITS=$(FIU_CFG_BITS) \
......@@ -17,7 +19,7 @@ fic-emulator: fic-emulator.c $(FIJI_CFG_FILE)
-o $@
fic-emulator-debug: fic-emulator.c $(FIJI_CFG_FILE)
gcc -Wall -Wextra -pedantic -std=c11 $< \
gcc $(CFLAGS) $< \
-DCFG_FILE='"$(FIJI_CFG_FILE)"' \
-DFIU_NUM=$(FIU_NUM) \
-DFIU_CFG_BITS=$(FIU_CFG_BITS) \
......
......@@ -23,7 +23,13 @@
*
* Description: FIC emulator
*
* 1. use e.g.
* If started without the `-d DEVICE` command-line parameter, the
* FIC emulator opens a PTY pair and prints the name of the slave end.
* This terminal can be used for fiji_ee.pl or fiji_ee_gui.pl
*
* If you prefer socat, or already have a device:
*
* 1. Run
* $ socat -d -d pty,raw,echo=0 pty,raw,echo=0
* to emulate a pair of terminals
*
......@@ -52,6 +58,8 @@
#include <termios.h>
#include <inttypes.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>
#define CEILING(x,y) (((x) + (y) - 1) / (y))
......@@ -83,6 +91,9 @@
puts("\033[25h\033[0m"); \
} while(0);
#define LOG_LINES 10
int fd;
struct termios old_stdin_tio;
......@@ -177,7 +188,6 @@ int main (int argc, char *argv[]) {
uint8_t msg = 0;
uint8_t err = 0;
char opt;
uint8_t in[NUM_BYTES];
uint8_t underrun = 0;
uint8_t replace_conf_done = 0;
unsigned int nmsg = 0;
......@@ -240,6 +250,7 @@ int main (int argc, char *argv[]) {
}
int ptsfd = -1;
char pts[1024];
if (!path) {
fd = open("/dev/ptmx",O_RDWR | O_NOCTTY | O_SYNC);
......@@ -253,7 +264,6 @@ int main (int argc, char *argv[]) {
RESTORE_TERM();
return EXIT_FAILURE;
}
char pts[1024];
if(ptsname_r(fd,pts,sizeof(pts)) != 0) {
RESTORE_TERM();
fprintf(stderr,"%s: ptsname(): %s\n",argv[0],strerror(errno));
......@@ -264,7 +274,6 @@ int main (int argc, char *argv[]) {
fprintf(stderr,"%s: open(): %s\n",argv[0],strerror(errno));
exit(EXIT_FAILURE);
}
(void) printf("\x1b[1mConnect FIJI EE to: %s\x1b[0m\n\n",pts);
} else {
fd = open(path,O_RDWR | O_NOCTTY | O_SYNC);
if (fd < 0) {
......@@ -275,7 +284,13 @@ int main (int argc, char *argv[]) {
printf("Emulating FIC on %s\n\n", path);
}
printf("[1] FD1 on/off\n" \
uint8_t messages[LOG_LINES][NUM_BYTES] = {0};
struct timeval timestamps[LOG_LINES] = {0};
int offs=0;
while(1) {
(void) printf("\x1b[2J\x1b[;H\x1b[1mConnect FIJI EE to: %s\x1b[0m\n\n",pts);
(void) printf("[1] FD1 on/off\n" \
"[2] FD2 on/off\n" \
"[u] UART Error on/off\n" \
"[i] ID Error on/off\n" \
......@@ -283,12 +298,33 @@ int main (int argc, char *argv[]) {
"[r] Underrun after READY on/off\n" \
"[z] Underrun instead of CONF_DONE on/off\n" \
/* "[f] MSG_TYPE_ILLEGAL\n" \ */
"[x] Exit\n");
"[x] Exit\n\n");
for (int i = 0; i < LOG_LINES; i++) {
int ix = (i+offs)%LOG_LINES;
char timebuf[26];
ctime_r(&timestamps[ix].tv_sec,timebuf);
timebuf[strlen(timebuf)-1] = '\0';
if (timestamps[ix].tv_sec) {
printf("[%ld.%06ld] %s MESSAGE %6d, ",timestamps[ix].tv_sec,
timestamps[ix].tv_usec,
(messages[ix][CONFIG_OFFSET] & UPDATE_FLAG) ? "UPDATE" : "INJECT",
offs+(i-LOG_LINES));
for (int i = 0; i < CFGS_PER_MSG; i++) {
printf("T%i=%d ", i+1, *(uint32_t *)(&messages[ix][TIMER_OFFSET+i*TIMER_BYTES]));
}
printf("ID=%#04x ", *(uint16_t *)(&messages[ix][ID_OFFSET]));
printf("CFG=%#02x ", messages[ix][CONFIG_OFFSET]);
printf("CRC=%#02x\n", messages[ix][CRC_OFFSET]);
} else {
printf("\n");
}
}
puts("\033[25l\033[7m");
(void) fputs("\n\033[25l\033[7m",stdout);
putstatus(msg,err,underrun,replace_conf_done,NULL,nmsg);
while(1) {
(void) fputs("\x1b[0m",stdout);
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
......@@ -339,6 +375,8 @@ int main (int argc, char *argv[]) {
continue;
}
uint8_t *in = messages[(offs)%LOG_LINES];
(void) gettimeofday(timestamps+(offs++)%LOG_LINES,NULL);
if (read_msg(fd,in) == -1) {
fprintf(stderr,"read_msg()\n");
......@@ -367,9 +405,6 @@ int main (int argc, char *argv[]) {
fprintf(stderr,"%02d: 0x%02x\n",i, in[i]);
}
#endif
putstatus(msg,err,underrun,replace_conf_done,(in + CRC_OFFSET),++nmsg);
ret = replace_conf_done ? MSG_TYPE_UNDERRUN : MSG_TYPE_CONF_DONE;
ret |= msg;
ret |= err;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment