# HG changeset patch # User Mychaela Falconia # Date 1719168781 0 # Node ID 631f2db08538145a6fbb4961c4d7e77074c3df6b # Parent 7233c10af3adebdd099eb20889f14aa2f3c6fb0b pcm: implement print-rx and record commands diff -r 7233c10af3ad -r 631f2db08538 pcm/Makefile --- a/pcm/Makefile Sun Jun 23 18:33:09 2024 +0000 +++ b/pcm/Makefile Sun Jun 23 18:53:01 2024 +0000 @@ -1,5 +1,5 @@ PROG= itt-pcm-one -OBJS= main.o read_ts.o user_cmd.o +OBJS= main.o read_ts.o record_ctrl.o user_cmd.o LIBUTIL=../libutil/libutil.a include ../config.defs @@ -9,6 +9,8 @@ all: ${PROG} +${OBJS}: globals.h + ${PROG}: ${OBJS} ${LIBUTIL} ${CC} -o $@ ${OBJS} ${LIBUTIL} ${OSMO_LINK} diff -r 7233c10af3ad -r 631f2db08538 pcm/globals.h --- a/pcm/globals.h Sun Jun 23 18:33:09 2024 +0000 +++ b/pcm/globals.h Sun Jun 23 18:53:01 2024 +0000 @@ -5,6 +5,10 @@ extern struct osmo_e1dp_client *g_client; extern int ts_fd; extern uint8_t readbuf[160]; +extern FILE *record_file; int ts_fd_cb(struct osmo_fd *ofd, unsigned int what); void handle_user_cmd(int argc, char **argv); +void cmd_record_start(int argc, char **argv); +void cmd_record_stop(int argc, char **argv); +void cmd_print_rx(int argc, char **argv); diff -r 7233c10af3ad -r 631f2db08538 pcm/read_ts.c --- a/pcm/read_ts.c Sun Jun 23 18:33:09 2024 +0000 +++ b/pcm/read_ts.c Sun Jun 23 18:53:01 2024 +0000 @@ -14,6 +14,7 @@ #include "globals.h" uint8_t readbuf[160]; +FILE *record_file; int ts_fd_cb(struct osmo_fd *ofd, unsigned int what) { @@ -26,5 +27,7 @@ rc); exit(1); } + if (record_file) + fwrite(readbuf, 1, 160, record_file); return 0; } diff -r 7233c10af3ad -r 631f2db08538 pcm/record_ctrl.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcm/record_ctrl.c Sun Jun 23 18:53:01 2024 +0000 @@ -0,0 +1,50 @@ +/* + * Here we implement stdin commands that control recording of E1 timeslot + * read stream. + */ + +#include +#include +#include +#include + +#include + +#include "globals.h" + +void cmd_record_start(int argc, char **argv) +{ + if (argc != 2) { + printf("error: record command needs 1 argument\n"); + return; + } + if (record_file) { + printf("error: recording already in progress\n"); + return; + } + record_file = fopen(argv[1], "w"); + if (!record_file) + perror(argv[1]); +} + +void cmd_record_stop(int argc, char **argv) +{ + if (!record_file) { + printf("error: no recording in progress\n"); + return; + } + fclose(record_file); + record_file = NULL; +} + +void cmd_print_rx(int argc, char **argv) +{ + int i, j, off; + + off = 0; + for (i = 0; i < 10; i++) { + for (j = 0; j < 16; j++) + printf(" %02X", readbuf[off++]); + putchar('\n'); + } +} diff -r 7233c10af3ad -r 631f2db08538 pcm/user_cmd.c --- a/pcm/user_cmd.c Sun Jun 23 18:33:09 2024 +0000 +++ b/pcm/user_cmd.c Sun Jun 23 18:53:01 2024 +0000 @@ -13,7 +13,27 @@ #include "globals.h" +static struct cmdtab { + char *cmd; + void (*func)(int argc, char **argv); +} cmdtab[] = { + {"print-rx", cmd_print_rx}, + {"record", cmd_record_start}, + {"record-stop", cmd_record_stop}, + /* table search terminator */ + {NULL, NULL} +}; + void handle_user_cmd(int argc, char **argv) { - /* to be filled */ + struct cmdtab *tp; + + for (tp = cmdtab; tp->cmd; tp++) + if (!strcmp(tp->cmd, argv[0])) + break; + if (!tp->func) { + printf("error: unknown or unimplemented command\n"); + return; + } + tp->func(argc, argv); }