aboutsummaryrefslogtreecommitdiffstats
path: root/library/TRXC_Types.ttcn
blob: aaa58eec06ddd08dbad350f7006b2e5afa294c7e (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
module TRXC_Types {

/* TRX Control protocol type definitions in TTCN-3
 * (C) 2018 Harald Welte <laforge@gnumonks.org>
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

import from Osmocom_Types all;

type charstring TrxcType ("CMD", "RSP", "IND") with {
	variant "TEXT_CODING(,convert=upper_case,'((CMD)|(RSP)|(IND))',case_insensitive)"
}

type charstring TrxcVerb ("POWERON", "POWEROFF", "CLOCK",
			  "RXTUNE", "TXTUNE", "SETSLOT", "SETTSC", "SETBSIC", "SETPOWER",
			  "SETMAXDLY", "SETMAXDLYNB", "SETSLOT", "HANDOVER", "NOHANDOVER",
			  "MEASURE", "FAKE_RSSI", "FAKE_TOA", "FAKE_CI", "FAKE_TRXC_DELAY") with {
	variant "TEXT_CODING(,convert=upper_case,
			'((POWERON)|(POWEROFF)|(CLOCK)|(RXTUNE)|(TXTUNE)|(SETSLOT)|(SETTSC)|(SETBSIC)|(SETPOWER)|(SETMAXDLY)|(SETMAXDLYNB)|(HANDOVER)|(NOHANDOVER)|(MEASURE)|(FAKE_RSSI)|(FAKE_TOA)|(FAKE_CI)|(FAKE_TRXC_DELAY))'
			,case_insensitive)"
}

type integer TrxcStatus;
type charstring TrxcParam;
type record of TrxcParam TrxcParams with {
	variant "SEPARATOR(' ', ' ')"
}

type record TrxcCommand {
	TrxcVerb	verb,
	TrxcParams	params optional
} with {
	variant "SEPARATOR(' ', ' ')"
}

type record TrxcResponse {
	TrxcVerb	verb,
	TrxcStatus	status,
	TrxcParams	params optional
} with {
	variant "SEPARATOR(' ', ' ')"
}

type record TrxcIndication {
	TrxcVerb	verb,
	TrxcParams	params optional
} with {
	variant "SEPARATOR(' ', ' ')"
}

type union TrxcMessage {
	TrxcCommand	cmd,
	TrxcResponse	rsp,
	TrxcIndication	ind
} with {
	variant (cmd) "BEGIN('CMD ')"
	variant (rsp) "BEGIN('RSP ')"
	variant (ind) "BEGIN('IND ')"
}

external function enc_TrxcMessage(in TrxcMessage id) return charstring
	with { extension "prototype(convert) encode(TEXT)" };
external function dec_TrxcMessage(in charstring id) return TrxcMessage
	with { extension "prototype(convert) decode(TEXT)" };

/* rxlev2dbm(0..63) gives us [-110..-47], plus -10 dbm for noise */
type integer TRXC_RSSI		(-120..-47);
type integer TRXC_RSSI_THRESH	(-120..120);

template (value) TrxcMessage ts_TRXC_FAKE_RSSI(TRXC_RSSI rssi, TRXC_RSSI_THRESH thresh := 0) := {
	cmd := {
		verb := "FAKE_RSSI",
		params := { int2str(rssi), int2str(thresh) }
	}
}

template (value) TrxcMessage ts_TRXC_FAKE_TIMING(int16_t timing, int16_t thresh := 0) := {
	cmd := {
		verb := "FAKE_TOA",
		params := { int2str(timing), int2str(thresh) }
	}
}

template (value) TrxcMessage ts_TRXC_FAKE_CI(int16_t ci, int16_t thresh := 0) := {
	cmd := {
		verb := "FAKE_CI",
		params := { int2str(ci), int2str(thresh) }
	}
}

template (value) TrxcMessage ts_TRXC_FAKE_TRXC_DELAY(integer delay_ms := 0) := {
	cmd := {
		verb := "FAKE_TRXC_DELAY",
		params := { int2str(delay_ms) }
	}
}


} with { encode "TEXT" }