[MERGED] osmo-ttcn3-hacks[master]: GSM_Types: add rxqual2ber and rxlev2dbm + ivnerse functions

2018-02-23 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: GSM_Types: add rxqual2ber and rxlev2dbm + ivnerse functions
..


GSM_Types: add rxqual2ber and rxlev2dbm + ivnerse functions

Change-Id: I6293f6a9b73d5614cbb61c64617af4dd8afc1e73
---
M library/GSM_Types.ttcn
1 file changed, 52 insertions(+), 0 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/library/GSM_Types.ttcn b/library/GSM_Types.ttcn
index e57575d..634af34 100644
--- a/library/GSM_Types.ttcn
+++ b/library/GSM_Types.ttcn
@@ -168,4 +168,56 @@
}
}
 
+/* Convert RF signal level in dBm to RxLev (TS 45.008 Chapter 8.1.4) */
+function dbm2rxlev(integer dbm) return uint6_t {
+   var integer rxlev := dbm + 110;
+   if (rxlev > 63) {
+   rxlev := 63;
+   } else if (rxlev < 0) {
+   rxlev := 0;
+   }
+   return rxlev;
+}
+
+function rxlev2dbm(uint6_t rxlev) return integer {
+   return -110 + rxlev;
+}
+
+/* convert BER to RxQual value (TS 45.008 Chapter 8.2.4 */
+function ber2rxqual(float ber) return uint3_t {
+   if (ber < 0.2) {
+   return 0;
+   } else if (ber < 0.4) {
+   return 1;
+   } else if (ber < 0.8) {
+   return 2;
+   } else if (ber < 1.6) {
+   return 3;
+   } else if (ber < 3.2) {
+   return 4;
+   } else if (ber < 6.4) {
+   return 5;
+   } else if (ber < 12.8) {
+   return 6;
+   } else {
+   return 7;
+   }
+}
+
+/* convert RxQual to BER (TS 45.008 Chapter 8.2.4 */
+function rxqual2ber(uint3_t rxqual) return float {
+   select (rxqual) {
+   case (0) { return 0.14 }
+   case (1) { return 0.28 }
+   case (2) { return 0.57 }
+   case (3) { return 1.13 }
+   case (4) { return 2.26 }
+   case (5) { return 4.53 }
+   case (6) { return 9.05 }
+   case (7) { return 18.10 }
+   case else { return 1000.0 }
+   }
+}
+
+
 } with { encode "RAW"; variant "FIELDORDER(msb)" }

-- 
To view, visit https://gerrit.osmocom.org/6873
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6293f6a9b73d5614cbb61c64617af4dd8afc1e73
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder


osmo-ttcn3-hacks[master]: GSM_Types: add rxqual2ber and rxlev2dbm + ivnerse functions

2018-02-23 Thread Harald Welte

Patch Set 1: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/6873
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I6293f6a9b73d5614cbb61c64617af4dd8afc1e73
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[PATCH] osmo-ttcn3-hacks[master]: GSM_Types: add rxqual2ber and rxlev2dbm + ivnerse functions

2018-02-23 Thread Harald Welte

Review at  https://gerrit.osmocom.org/6873

GSM_Types: add rxqual2ber and rxlev2dbm + ivnerse functions

Change-Id: I6293f6a9b73d5614cbb61c64617af4dd8afc1e73
---
M library/GSM_Types.ttcn
1 file changed, 52 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/73/6873/1

diff --git a/library/GSM_Types.ttcn b/library/GSM_Types.ttcn
index e57575d..634af34 100644
--- a/library/GSM_Types.ttcn
+++ b/library/GSM_Types.ttcn
@@ -168,4 +168,56 @@
}
}
 
+/* Convert RF signal level in dBm to RxLev (TS 45.008 Chapter 8.1.4) */
+function dbm2rxlev(integer dbm) return uint6_t {
+   var integer rxlev := dbm + 110;
+   if (rxlev > 63) {
+   rxlev := 63;
+   } else if (rxlev < 0) {
+   rxlev := 0;
+   }
+   return rxlev;
+}
+
+function rxlev2dbm(uint6_t rxlev) return integer {
+   return -110 + rxlev;
+}
+
+/* convert BER to RxQual value (TS 45.008 Chapter 8.2.4 */
+function ber2rxqual(float ber) return uint3_t {
+   if (ber < 0.2) {
+   return 0;
+   } else if (ber < 0.4) {
+   return 1;
+   } else if (ber < 0.8) {
+   return 2;
+   } else if (ber < 1.6) {
+   return 3;
+   } else if (ber < 3.2) {
+   return 4;
+   } else if (ber < 6.4) {
+   return 5;
+   } else if (ber < 12.8) {
+   return 6;
+   } else {
+   return 7;
+   }
+}
+
+/* convert RxQual to BER (TS 45.008 Chapter 8.2.4 */
+function rxqual2ber(uint3_t rxqual) return float {
+   select (rxqual) {
+   case (0) { return 0.14 }
+   case (1) { return 0.28 }
+   case (2) { return 0.57 }
+   case (3) { return 1.13 }
+   case (4) { return 2.26 }
+   case (5) { return 4.53 }
+   case (6) { return 9.05 }
+   case (7) { return 18.10 }
+   case else { return 1000.0 }
+   }
+}
+
+
 } with { encode "RAW"; variant "FIELDORDER(msb)" }

-- 
To view, visit https://gerrit.osmocom.org/6873
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6293f6a9b73d5614cbb61c64617af4dd8afc1e73
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte