From ce2fcf8821fbcbe8a117c236041f4a338a19810c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonas=20M=C3=A5rtensson?= Date: Sun, 31 May 2020 20:02:09 +0200 Subject: [PATCH] Avoid converting spanloss to double when calculating target power value MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Currently spanloss is measured and set without any fractional digits. We would like to have one fractional digit but this creates problems because of the conversion to double when calculating target power resulting in the power value having more than the two fractional digits allowed by the yang module. This patch proposes to skip the conversion to double and only use BigDecimal to avoid the problem. The proposal to measure spanloss with one fractional digit will be submitted in a separate patch. Signed-off-by: Jonas MÃ¥rtensson Change-Id: Ibd13c991d43f2e94739710412e8edadcc0c537bf --- .../org/opendaylight/transportpce/olm/power/PowerMgmtImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/olm/src/main/java/org/opendaylight/transportpce/olm/power/PowerMgmtImpl.java b/olm/src/main/java/org/opendaylight/transportpce/olm/power/PowerMgmtImpl.java index 9b05e83a9..e8da5c3f8 100644 --- a/olm/src/main/java/org/opendaylight/transportpce/olm/power/PowerMgmtImpl.java +++ b/olm/src/main/java/org/opendaylight/transportpce/olm/power/PowerMgmtImpl.java @@ -260,7 +260,8 @@ public class PowerMgmtImpl implements PowerMgmt { "Power Value is null: spanLossTx null or out of openROADM range ]0,28] {}", spanLossTx); return false; } - BigDecimal powerValue = BigDecimal.valueOf(Math.min(spanLossTx.doubleValue() - 9, 2)); + BigDecimal powerValue = spanLossTx.subtract(BigDecimal.valueOf(9)); + powerValue = powerValue.min(BigDecimal.valueOf(2)); LOG.info("Power Value is {}", powerValue); try { -- 2.36.6