[AETHER-3190] Use dongle info for signal quality and control plane status

Change-Id: I4b6163b1d3c715963d0565cb4b1636898bbb199e
diff --git a/VERSION b/VERSION
index 879be8a..e7c7d3c 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.7.7
+0.7.8
diff --git a/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py b/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py
index 680643f..cfebbe6 100755
--- a/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py
+++ b/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py
@@ -67,15 +67,15 @@
         rc = sp.wait()
         ret,err = sp.communicate()
         if err != "" :
-            logging.error("unable to find serial port " + err)
+            self.log.error("unable to find serial port " + err)
 
         ret = ret.replace(CONF.modem.port,"").strip()
-        logging.info("Modem.get_modem_port found " + ret)
+        self.log.info("Modem.get_modem_port found " + ret)
         return ret
 
     def connect(self):
         self.port=self.get_modem_port()
-        logging.info("modem.connect Port: %s, BaudRate: %i",self.port,self.baudrate)
+        self.log.info("modem.connect Port: %s, BaudRate: %i",self.port,self.baudrate)
         self.serial = serial.Serial(
             port=self.port,
             baudrate=self.baudrate,
@@ -90,6 +90,7 @@
         self.serial.write(bytearray(command + "\r", "ascii"))
         read = self.serial.inWaiting()
         while True:
+            self.log.debug("Waiting for write to complete...")
             if read > 0:
                 self._response += self.serial.read(read)
             else:
@@ -97,6 +98,7 @@
             read = self.serial.inWaiting()
             if read == 0:
                 break
+        self.log.debug("Write complete...")
         return self._response.decode("ascii").replace('\r\n', ' ')
 
     def write(self, command, wait_resp=True):
@@ -118,7 +120,10 @@
         self.serial.close()
 
 
-def get_control_plane_state(modem):
+def get_control_plane_state(modem, dongle_stats=None):
+    if dongle_stats and dongle_stats['Connection'] == 'Connected':
+        return State.connected
+
     # Disable radio fuction
     # "echo" works more stable than serial for this action
     try:
@@ -314,12 +319,16 @@
     return speedtest_iperf
 
 
-def get_signal_quality(modem):
+def get_signal_quality(modem, dongle_stats=None):
+    if dongle_stats and dongle_stats['RSRQ'] != '' and dongle_stats['RSRP'] != '':
+        rsrq = int((float(dongle_stats['RSRQ']) + 19.5) * 2)
+        rsrp = int(float(dongle_stats['RSRP']) + 140)
+        return {'rsrq': rsrq, 'rsrp': rsrp}
+
     success, result = modem.write('AT+CESQ')
     logging.debug("get_signal_quality success %i result %s",success,result)
     if not success or 'CESQ: ' not in result:
         logging.error("Failed to get signal quality")
-
         return {'rsrq':0, 'rsrp':0}
 
     logging.debug("%s", result)
@@ -335,7 +344,8 @@
 
     return result
 
-def get_dongle_stats(modem):
+
+def get_dongle_stats():
     result = {'SuccessfulFetch' : False}
     if "report_in_band" in CONF._fields:
         result['inBandReporting'] = CONF.report_in_band
@@ -354,6 +364,8 @@
                "Band",
                "EARFCN",
                "BandWidth",
+               "RSRP",
+               "RSRQ",
                "ServCellState",
                "Connection",
                "IPv4Addr"]
@@ -529,20 +541,25 @@
         sys.exit(1)
 
     while True:
-        cp_state = get_control_plane_state(modem)
-        signal_quality = get_signal_quality(modem)
-        dongle_stats = get_dongle_stats(modem)
+        dongle_stats = get_dongle_stats()
+        cp_state = get_control_plane_state(modem, dongle_stats)
+        if cp_state != State.connected:
+            logging.error("Control plane not connected")
+            continue
+        signal_quality = get_signal_quality(modem, dongle_stats)
         if cp_state is State.error:
             logging.error("Modem is in error state.")
             reset_usb()
             sys.exit(1)
         if cp_state is State.disconnected:
             # Failed to attach, don't need to run other tests
+            logging.error("Check control plane - fail")
             report_status(signal_quality, dongle_stats)
             continue
 
         up_state, dry_run_latency = get_user_plane_state(modem)
         if up_state is State.disconnected:
+            logging.error("Check user plane - fail")
             # Basic user plane test failed, don't need to run the rest of tests
             report_status(signal_quality, dongle_stats, cp_state)
             continue
@@ -551,6 +568,7 @@
         if speedtest_status:
             speedtest_iperf = get_iperf_test(modem)
         else:
+            logging.error("Check iperf check - fail")
             report_status(signal_quality, dongle_stats, cp_state, up_state, speedtest_ping)
             continue