Osmocom_Types: Add bool2bit() and bool2bit_templ()
Those can be very handy to convert boolean values and templates
to the BIT1 type that is used a lot in Ericsson code.
Change-Id: I137595edabd2bbf5e6cf8bf9bdb73b3589c94c64
diff --git a/library/Osmocom_Types.ttcn b/library/Osmocom_Types.ttcn
index a748bbc..a736e95 100644
--- a/library/Osmocom_Types.ttcn
+++ b/library/Osmocom_Types.ttcn
@@ -1,4 +1,7 @@
module Osmocom_Types {
+
+ import from General_Types all;
+
type integer uint8_t (0..255) with { variant "unsigned 8 bit" };
type integer uint16_t (0..65535) with { variant "unsigned 16 bit" };
type integer uint24_t (0..16777215) with { variant "unsigned 24 bit" };
@@ -66,4 +69,30 @@
T.timeout;
}
+function bool2bit(boolean inp) return BIT1 {
+ if (inp) {
+ return '1'B;
+ } else {
+ return '0'B;
+ }
+}
+
+function bool2bit_tmpl(template boolean inp) return template BIT1 {
+ if (istemplatekind(inp, "omit")) {
+ return omit;
+ } else if (istemplatekind(inp, "*")) {
+ return *;
+ } else if (istemplatekind(inp, "?")) {
+ } else {
+ if (valueof(inp)) {
+ return '1'B;
+ } else {
+ return '0'B;
+ }
+ }
+ setverdict(fail, "Unsupported template");
+ self.stop;
+}
+
+
} with { encode "RAW"; variant "FIELDORDER(msb)" }