aboutsummaryrefslogtreecommitdiffstats
path: root/src/e1_test_dieter.c
blob: 6277556f13c5f8dbe148a13ca8cda0e723ff8034 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <stdint.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>

#include <osmocom/core/utils.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/application.h>
#include <osmocom/gsm/gsm_utils.h>

#include "osmo_e1.h"

static struct osmo_e1_instance inst;
static struct log_info log_info = {};

static void data_cb(struct osmo_e1_instance_ts *e1t, struct msgb *msg)
{
	printf("Rx TS %02u: %s\n", e1t->ts_nr, msgb_hexdump(msg));
	msgb_free(msg);
}

static void notify_cb(struct osmo_e1_instance *e1i, enum osmo_e1_notify_event evt,
			bool present, void *data)
{
	fprintf(stdout, "NOTIFY: %s %s\n", osmo_e1_notify_event_name(evt), present ? "PRESENT" : "ABSENT");
}

static void read_file(const char *fname)
{
	int fd;

	fd = open(fname, O_RDONLY);
	if (fd < 0)
		exit(23);
	while (1) {
		int rc;
		uint8_t buf[32];

		rc = read(fd, buf, sizeof(buf));
		if (rc <= 0)
			return;
		if (rc < sizeof(buf))
			exit(24);
		//printf("FRAME: %s\n", osmo_hexdump(buf, sizeof(buf)));
		osmo_e1_rx_frame(&inst, buf);
	}
}

int main(int argc, char **argv)
{
	int i;

	osmo_init_logging2(NULL, &log_info);
	osmo_e1_init();

	osmo_e1_instance_init(&inst, "e1_test", &notify_cb, true, NULL);
	for (i = 1; i < 32; i++) {
		struct osmo_e1_instance_ts *e1t = osmo_e1_instance_ts(&inst, i);
		enum osmo_e1_ts_mode mode;
		bool enable;
		switch (i) {
		case 2:
			mode = OSMO_E1_TS_HDLC_CRC;
			enable = true;
			break;
		case 5:
		case 6:
		case 7:
		case 8:
		default:
			mode = OSMO_E1_TS_RAW;
			enable = false;
			break;
		}
		osmo_e1_ts_config(e1t, &data_cb, 64, enable, mode);
	}

	read_file("Insite_to_Racal_E1.bin");
}