FreeCalypso > hg > ice1-trau-tester
diff ater8/activate.c @ 42:ff94d7fc5891
new program itt-ater-8
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 30 Aug 2024 19:02:42 +0000 |
parents | ater/activate.c@237687e2be6c |
children | 3cc26391d24d |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ater8/activate.c Fri Aug 30 19:02:42 2024 +0000 @@ -0,0 +1,89 @@ +/* + * Here we implement the operation of activating a new TRAU channel + * on a sub-timeslot. + */ + +#include <stdint.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <osmocom/core/select.h> +#include <osmocom/isdn/i460_mux.h> +#include <osmocom/trau/trau_frame.h> + +#include "globals.h" +#include "submux.h" +#include "read_file.h" +#include "out_frame.h" + +void cmd_activate(int argc, char **argv) +{ + int nr, rc; + bool dtxd; + struct ater_subslot *at; + int16_t *init_frame; + unsigned init_frame_count; + + if (argc < 3 || argc > 4) { +usage: fprintf(stderr, "usage: %s 0-7 initial-frame.dec [dtxd]\n", + argv[0]); + return; + } + if (argv[1][0] < '0' || argv[1][0] > '7' || argv[1][1]) + goto usage; + nr = argv[1][0] - '0'; + if (argv[3]) { + if (strcmp(argv[3], "dtxd")) + goto usage; + dtxd = true; + } else + dtxd = false; + + at = &subslots[nr]; + if (at->is_active) { + fprintf(stderr, "error: subslot %d is already active\n", nr); + return; + } + rc = read_binary_file(argv[2], &init_frame, &init_frame_count); + if (rc < 0) + return; /* error msg already printed */ + if (init_frame_count != 1) { + free(init_frame); + fprintf(stderr, "error: %s contains more than one frame\n", + argv[2]); + return; + } + + /* good to proceed now */ + at->is_active = true; + init_trau_ul_frame(nr); + at->ul_frame.c_bits[8] = dtxd; + trau_frame_from_record(init_frame, &at->ul_frame, &at->frame_has_taf); + free(init_frame); +} + +void cmd_deact(int argc, char **argv) +{ + int nr; + struct ater_subslot *at; + + if (argc != 2) { +usage: fprintf(stderr, "usage: %s 0-7\n", argv[0]); + return; + } + if (argv[1][0] < '0' || argv[1][0] > '7' || argv[1][1]) + goto usage; + nr = argv[1][0] - '0'; + at = &subslots[nr]; + if (!at->is_active) { + fprintf(stderr, "error: subslot %d is not active\n", nr); + return; + } + at->is_active = false; + if (at->play_buffer) { + free(at->play_buffer); + at->play_buffer = NULL; + } +}