From c7adaa722b3f1000cfe0733c98727111578662a9 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 15 Feb 2018 20:40:36 +0100 Subject: [PATCH] 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 --- library/Osmocom_Types.ttcn | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/library/Osmocom_Types.ttcn b/library/Osmocom_Types.ttcn index a748bbcae..a736e95a5 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 @@ module Osmocom_Types { 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)" }