mirror of https://gerrit.osmocom.org/osmo-tetra
add traffic dumping patch, use getopt to parse arguments
Enable the user to specify a directory, where contents of traffic channel will be saved. Together with this dump, a text file with SSIs of the engaged stations is saved too. Based on 0004-HACK-Quick-hack-to-save-the-speech-data-from-TCH.patch available at https://build.opensuse.org/package/view_file/home:mnhauke:sdr/osmo-tetra/0004-HACK-Quick-hack-to-save-the-speech-data-from-TCH.patch Change-Id: I94135753a76cadfa373167ffca18e89bee5bcff8
This commit is contained in:
parent
22bb16dfa4
commit
73e9e0e871
|
@ -22,6 +22,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <linux/limits.h>
|
||||
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/core/msgb.h>
|
||||
|
@ -184,6 +185,48 @@ void tp_sap_udata_ind(enum tp_sap_data_type type, const uint8_t *bits, unsigned
|
|||
DEBUGP("%s %s type4: %s\n", tbp->name, time_str,
|
||||
osmo_ubit_dump(type4, tbp->type345_bits));
|
||||
|
||||
/* If this is a traffic channel, dump. */
|
||||
if ((type == TPSAP_T_SCH_F) && tms->cur_burst.is_traffic && tms->dumpdir) {
|
||||
char fname[PATH_MAX];
|
||||
int16_t block[690];
|
||||
FILE *f;
|
||||
int i;
|
||||
|
||||
/* Open target file */
|
||||
snprintf(fname, sizeof(fname), "%s/traffic_%d_%d.out", tms->dumpdir,
|
||||
tms->cur_burst.is_traffic, tms->tsn);
|
||||
f = fopen(fname, "ab");
|
||||
|
||||
/* Generate a block */
|
||||
memset(block, 0x00, sizeof(int16_t) * 690);
|
||||
for (i = 0; i < 6; i++)
|
||||
block[115*i] = 0x6b21 + i;
|
||||
|
||||
for (i = 0; i < 114; i++)
|
||||
block[1+i] = type4[i] ? -127 : 127;
|
||||
|
||||
for (i = 0; i < 114; i++)
|
||||
block[116+i] = type4[114+i] ? -127 : 127;
|
||||
|
||||
for (i = 0; i < 114; i++)
|
||||
block[231+i] = type4[228+i] ? -127 : 127;
|
||||
|
||||
for (i = 0; i < 90; i++)
|
||||
block[346+i] = type4[342+i] ? -127 : 127;
|
||||
|
||||
/* Write it */
|
||||
fwrite(block, sizeof(int16_t), 690, f);
|
||||
|
||||
fclose(f);
|
||||
|
||||
/* Write used ssi */
|
||||
snprintf(fname, sizeof(fname), "%s/traffic_%d_%d.txt", tms->dumpdir,
|
||||
tms->cur_burst.is_traffic, tms->tsn);
|
||||
f = fopen(fname, "a");
|
||||
fprintf(f, "%d\n", tms->ssi);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
if (tbp->interleave_a) {
|
||||
/* Run block deinterleaving: type-3 bits */
|
||||
block_deinterleave(tbp->type345_bits, tbp->interleave_a, type4, type3);
|
||||
|
|
|
@ -39,28 +39,39 @@ void *tetra_tall_ctx;
|
|||
int main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
int opt;
|
||||
struct tetra_rx_state *trs;
|
||||
struct tetra_mac_state *tms;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: %s <file_with_1_byte_per_bit>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fd = open(argv[1], O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
tetra_gsmtap_init("localhost", 0);
|
||||
|
||||
tms = talloc_zero(tetra_tall_ctx, struct tetra_mac_state);
|
||||
tetra_mac_state_init(tms);
|
||||
|
||||
trs = talloc_zero(tetra_tall_ctx, struct tetra_rx_state);
|
||||
trs->burst_cb_priv = tms;
|
||||
|
||||
while ((opt = getopt(argc, argv, "d:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'd':
|
||||
tms->dumpdir = strdup(optarg);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unknown option %c\n", opt);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc <= optind) {
|
||||
fprintf(stderr, "Usage: %s [-d DUMPDIR] <file_with_1_byte_per_bit>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fd = open(argv[optind], O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
tetra_gsmtap_init("localhost", 0);
|
||||
|
||||
while (1) {
|
||||
uint8_t buf[64];
|
||||
int len;
|
||||
|
@ -76,6 +87,7 @@ int main(int argc, char **argv)
|
|||
tetra_burst_sync_in(trs, buf, len);
|
||||
}
|
||||
|
||||
free(tms->dumpdir);
|
||||
talloc_free(trs);
|
||||
talloc_free(tms);
|
||||
|
||||
|
|
|
@ -47,7 +47,11 @@ struct tetra_mac_state {
|
|||
struct {
|
||||
int is_traffic;
|
||||
} cur_burst;
|
||||
struct tetra_si_decoded last_sid;
|
||||
struct tetra_si_decoded last_sid;
|
||||
|
||||
char *dumpdir; /* Where to save traffic channel dump */
|
||||
int ssi; /* SSI */
|
||||
int tsn; /* Timeslon number */
|
||||
};
|
||||
|
||||
void tetra_mac_state_init(struct tetra_mac_state *tms);
|
||||
|
|
|
@ -28,9 +28,9 @@ static const uint8_t lchan2gsmtap[] = {
|
|||
};
|
||||
|
||||
|
||||
struct msgb *tetra_gsmtap_makemsg(struct tetra_tdma_time *tm, enum tetra_log_chan lchan,
|
||||
uint8_t ts, uint8_t ss, int8_t signal_dbm,
|
||||
uint8_t snr, const ubit_t *bitdata, unsigned int bitlen)
|
||||
struct msgb *tetra_gsmtap_makemsg(struct tetra_tdma_time *tm, enum tetra_log_chan lchan, uint8_t ts, uint8_t ss,
|
||||
int8_t signal_dbm, uint8_t snr, const ubit_t *bitdata, unsigned int bitlen,
|
||||
struct tetra_mac_state *tms)
|
||||
{
|
||||
struct msgb *msg;
|
||||
struct gsmtap_hdr *gh;
|
||||
|
@ -47,6 +47,7 @@ struct msgb *tetra_gsmtap_makemsg(struct tetra_tdma_time *tm, enum tetra_log_cha
|
|||
gh->hdr_len = sizeof(*gh)/4;
|
||||
gh->type = GSMTAP_TYPE_TETRA_I1;
|
||||
gh->timeslot = ts;
|
||||
tms->tsn = ts;
|
||||
gh->sub_slot = ss;
|
||||
gh->snr_db = snr;
|
||||
gh->signal_dbm = signal_dbm;
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
#define TETRA_GSMTAP_H
|
||||
#include "tetra_common.h"
|
||||
|
||||
struct msgb *tetra_gsmtap_makemsg(struct tetra_tdma_time *tm, enum tetra_log_chan lchan,
|
||||
uint8_t ts, uint8_t ss, int8_t signal_dbm,
|
||||
uint8_t snr, const uint8_t *data, unsigned int len);
|
||||
struct msgb *tetra_gsmtap_makemsg(struct tetra_tdma_time *tm, enum tetra_log_chan lchan, uint8_t ts, uint8_t ss,
|
||||
int8_t signal_dbm, uint8_t snr, const uint8_t *bitdata, unsigned int bitlen,
|
||||
struct tetra_mac_state *tms);
|
||||
|
||||
int tetra_gsmtap_sendmsg(struct msgb *msg);
|
||||
|
||||
|
|
|
@ -181,6 +181,8 @@ static void rx_resrc(struct tetra_tmvsap_prim *tmvp, struct tetra_mac_state *tms
|
|||
rx_tm_sdu(tms, msg, len_bits);
|
||||
}
|
||||
|
||||
tms->ssi = rsd.addr.ssi;
|
||||
|
||||
out:
|
||||
printf("\n");
|
||||
}
|
||||
|
@ -241,7 +243,7 @@ static void rx_aach(struct tetra_tmvsap_prim *tmvp, struct tetra_mac_state *tms)
|
|||
|
||||
/* save the state whether the current burst is traffic or not */
|
||||
if (aad.dl_usage > 3)
|
||||
tms->cur_burst.is_traffic = 1;
|
||||
tms->cur_burst.is_traffic = aad.dl_usage;
|
||||
else
|
||||
tms->cur_burst.is_traffic = 0;
|
||||
|
||||
|
@ -276,7 +278,7 @@ static int rx_tmv_unitdata_ind(struct tetra_tmvsap_prim *tmvp, struct tetra_mac_
|
|||
gsmtap_msg = tetra_gsmtap_makemsg(&tup->tdma_time, tup->lchan,
|
||||
tup->tdma_time.tn,
|
||||
/* FIXME: */ 0, 0, 0,
|
||||
msg->l1h, msgb_l1len(msg));
|
||||
msg->l1h, msgb_l1len(msg), tms);
|
||||
if (gsmtap_msg)
|
||||
tetra_gsmtap_sendmsg(gsmtap_msg);
|
||||
|
||||
|
|
Loading…
Reference in New Issue