VOL-3899:  The tx/rx power in PON_Optical metric report should be
converted from raw data to dBm before pushing to kafka

Change-Id: I750ca3059b69c149e9108ea610997d6f02b67961
diff --git a/PM_Notes.md b/PM_Notes.md
index 09cd64a..4148207 100644
--- a/PM_Notes.md
+++ b/PM_Notes.md
@@ -28,11 +28,12 @@
 ```
 // OpticalPowerGroupMetrics are supported optical pm names
 var OpticalPowerGroupMetrics = map[string]voltha.PmConfig_PmType{
-	"ani_g_instance_id": voltha.PmConfig_CONTEXT,
-	"transmit_power":    voltha.PmConfig_GAUGE,
-	"receive_power":     voltha.PmConfig_GAUGE,
+	"ani_g_instance_id":  voltha.PmConfig_CONTEXT,
+	"transmit_power_dBm": voltha.PmConfig_GAUGE,
+	"receive_power_dBm":  voltha.PmConfig_GAUGE,
 }
 ```
+
 ### _UniStatus_
 ```
 // UniStatusGroupMetrics are supported UNI status names
@@ -44,17 +45,6 @@
 }
 ```
 
-### _UniStatusGroupMetrics_
-```
-var UniStatusGroupMetrics = map[string]voltha.PmConfig_PmType{
-	"uni_port_no":     voltha.PmConfig_CONTEXT,
-	"entity_id":       voltha.PmConfig_CONTEXT,
-	"ethernet_type":   voltha.PmConfig_GAUGE,
-	"oper_status":     voltha.PmConfig_GAUGE,
-	"uni_admin_state": voltha.PmConfig_GAUGE,
-}
-```
-
 ### _EthernetBridgeHistory_
 ```
 var EthernetBridgeHistory = map[string]voltha.PmConfig_PmType{
@@ -136,8 +126,6 @@
 }
 ```
 
-`Note` : The values collected for the metrics are as is from the OMCI messages, meaning the adapter does not do any sort of conversion. Refer OMCI spec (G.988 v 11/2017 edition) to get more details of the units of the collected metrics.
-
 ## Basic KPI Format (**KpiEvent2**)
 
 The KPI information is published on the kafka bus under the _voltha.events_ topic. For
diff --git a/VERSION b/VERSION
index 98974210..c322f2e 100755
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.2.6-dev
+1.2.6-dev175
diff --git a/internal/pkg/onuadaptercore/onu_metrics_manager.go b/internal/pkg/onuadaptercore/onu_metrics_manager.go
index 806f1e1..41efe82 100644
--- a/internal/pkg/onuadaptercore/onu_metrics_manager.go
+++ b/internal/pkg/onuadaptercore/onu_metrics_manager.go
@@ -28,6 +28,7 @@
 	"github.com/opencord/voltha-lib-go/v4/pkg/db/kvstore"
 	"github.com/opencord/voltha-lib-go/v4/pkg/log"
 	"github.com/opencord/voltha-protos/v4/go/voltha"
+	"math"
 	"sync"
 	"time"
 )
@@ -65,9 +66,9 @@
 
 // OpticalPowerGroupMetrics are supported optical pm names
 var OpticalPowerGroupMetrics = map[string]voltha.PmConfig_PmType{
-	"ani_g_instance_id": voltha.PmConfig_CONTEXT,
-	"transmit_power":    voltha.PmConfig_GAUGE,
-	"receive_power":     voltha.PmConfig_GAUGE,
+	"ani_g_instance_id":  voltha.PmConfig_CONTEXT,
+	"transmit_power_dBm": voltha.PmConfig_GAUGE,
+	"receive_power_dBm":  voltha.PmConfig_GAUGE,
 }
 
 // OpticalPowerGroupMetrics specific constants
@@ -674,13 +675,13 @@
 					if val, ok := meAttributes["ManagedEntityId"]; ok && val != nil {
 						opticalMetrics[k] = float32(val.(uint16))
 					}
-				case "transmit_power":
+				case "transmit_power_dBm":
 					if val, ok := meAttributes["TransmitOpticalLevel"]; ok && val != nil {
-						opticalMetrics[k] = float32(val.(uint16))
+						opticalMetrics[k] = float32(math.Round((float64(mm.twosComplementToSignedInt16(val.(uint16)))/500.0)*10) / 10) // convert to dBm rounded of to single decimal place
 					}
-				case "receive_power":
+				case "receive_power_dBm":
 					if val, ok := meAttributes["OpticalSignalLevel"]; ok && val != nil {
-						opticalMetrics[k] = float32(val.(uint16))
+						opticalMetrics[k] = float32(math.Round((float64(mm.twosComplementToSignedInt16(val.(uint16)))/500.0)*10) / 10) // convert to dBm rounded of to single decimal place
 					}
 				default:
 					// do nothing
@@ -2615,3 +2616,34 @@
 	}
 	return slice
 }
+
+func (mm *onuMetricsManager) twosComplementToSignedInt16(val uint16) int16 {
+	var uint16MsbMask uint16 = 0x8000
+	if val&uint16MsbMask == uint16MsbMask {
+		return int16(^val+1) * -1
+	}
+
+	return int16(val)
+}
+
+/* // These are need in the future
+
+func (mm *onuMetricsManager) twosComplementToSignedInt32(val uint32) int32 {
+	var uint32MsbMask uint32 = 0x80000000
+	if val & uint32MsbMask == uint32MsbMask {
+		return int32(^val + 1) * -1
+	}
+
+	return int32(val)
+}
+
+func (mm *onuMetricsManager) twosComplementToSignedInt64(val uint64) int64 {
+	var uint64MsbMask uint64 = 0x8000000000000000
+	if val & uint64MsbMask == uint64MsbMask {
+		return int64(^val + 1) * -1
+	}
+
+	return int64(val)
+}
+
+*/