def SendCommandAndGetResponse(self, commandToRun, waitForIdle=True): """ #------------------------------------------------------------------------------------------------------------------- # Name: SendCommandAndGetResponse # Input: Takes argument : # commandToRun: The UDAS API to be sent # Description: Wrapper Function that communicates with the UDAS s/w and then wait for UDAS to go IDLE # Return: StatusResult() object #------------------------------------------------------------------------------------------------------------------- """ result = self.SendApiAndGetResponse(commandToRun) if result.HasError(): return result if waitForIdle: startTime = datetime.datetime.now() while ((datetime.datetime.now() - startTime).seconds < 60): result = self.SendApiAndGetResponse("GetHWState()", False) if result.HasError(): time.sleep(3) continue isBusy = False if (self.LastKratosResponse == "READY") else True if not isBusy: return StatusResult.Success() time.sleep(3) logger.error("KRATOS failed to return to IDLE state in 1 minute") return StatusResult.Success()
def PIDControl(self, thermalZone, desiredTemperature, timeout, SVTemp=25): """ #------------------------------------------------------------------------------------------------------------------- # Name: PIDControl # Input: Takes 4 arguments # argument1: thermal Zone # argument2: desiredTemperature in degree C # argument3: timeout in seconds. # argument4: SVTemp Temperature in degree C, default value is 25.0C # Description: Sets RV temperature, reports device temperature #------------------------------------------------------------------------------------------------------------------- """ msTimeout = timeout * 1000 logger.info("Inside PIDControl function") methodString = "-m PIDControl-" + str(thermalZone) + "," + str( desiredTemperature) + "," + str(msTimeout) + "," + str(SVTemp) logger.info(methodString) result = self.SendCommandAndGetResponse(methodString, timeout) logger.debug(result.CmdResult.Output) if result.Status.HasError(): logger.error("Error in running PIDControl") return result.Status logger.debug("PIDControl function working fine") return StatusResult.Success()
def PingStatus(self, IpAddress): """ #------------------------------------------------------------------------------------------------------------------- # Name: PingStatus # Input: IpAddress # Description:Pings the machine (with IpAddress provided as an argument) # Return: StatusResult() object #------------------------------------------------------------------------------------------------------------------- """ result = CommandLine.RunCommand('ping ' + IpAddress, 30) if result.Status.HasError(): logger.error("Error in pinging host {0} . {1}".format( IpAddress, result.CmdResult.Output)) return StatusResult.Error("Error in pinging host {0} . {1}".format( IpAddress, result.CmdResult.Output)) logger.info(result.CmdResult.Output) if ('unreachable.' in result.CmdResult.Output): #No route from the local system. Packets sent were never put on the wire. return StatusResult.Error('IpAddress is unreacheable. ' + result.CmdResult.Output) elif ('Ping request could not find host' in result.CmdResult.Output): return StatusResult.Error('host_not_found. ' + result.CmdResult.Output) elif ('Request timed out.' in result.CmdResult.Output): return StatusResult.Error('Connection time out' + result.CmdResult.Output) return StatusResult.Success()
def GetSinglePlotStatistics(self, statisticList): logger.info("Getting Single Plot Statistics ") methodString = "-m GetSinglePlotStatistics-1,1" result = self.SendCommandAndGetResponse(methodString) if result.Status.HasError(): logger.error( "Error in Sending Command to get Single Point Statistics") return result current = "current : " voltage = "voltage : " match = re.findall(current + '(.*?);', result.CmdResult.Output, re.DOTALL) if len(match) < 1: return StatusResult.Error("Could not read Current Value") # logger.info("Current : " + match[0]) current = match[0] match = re.findall(voltage + '(.*?);', result.CmdResult.Output, re.DOTALL) if len(match) < 1: return StatusResult.Error("Could not read Voltage Value") # logger.info("Voltage : " + match[0]) voltage = match[0] statisticList[0] = current statisticList[1] = voltage return StatusResult.Success()
def SetDataCollectionPath(self): """ #------------------------------------------------------------------------------------------------------------------- # Name: SetDataCollectionPath # Input: Takes no argument # Description: Sets up path to save UDAS waveform on automation PC # Return: StatusResult() object #------------------------------------------------------------------------------------------------------------------- """ logger.info("Setting Logs Location for saving UDAS") if self.boardHasEpm: if self.epm.getData: logger.warning('ALPACA : Measurement already running. Stopping previous measurement') result = self.StopMeasurement() if result.HasError(): logger.error('ALPACA : Error stopping previous measurement') return result self.logsPath = "C:\\Automation\\Logs\\" + str(datetime.now().strftime('%Y-%m-%d_%H-%M-%S')) if self.boardHasEpm: try: logger.info('ALPACA : Log directory path : ' + self.logsPath) self.epm.SetLogDirectory(self.logsPath) except Exception as e: logger.error(str(e)) return StatusResult.Error('ALPACA : ', str(e)) return StatusResult.Success()
def ControlTemperature(self, thermalZone, desiredTemperature, timeout, SVTemp=25): """ #------------------------------------------------------------------------------------------------------------------- # Name: ControlTemperature # Input: Takes 4 argument # argument1: thermalZone # argument2: desiredTemperature # argument3: timeout in seconds # argument4: SVTemp # Description: Controls temperature on device #--------------------------------------------------------------------------------------------------- """ logger.info("Calling ControlTemperature function") methodString = "-m ControlTemperature-" + str(thermalZone) + "," + str( desiredTemperature) + "," + str(timeout * 1000) + "," + str(SVTemp) #logger.debug(methodString) result = self.SendCommandAndGetResponse(methodString, timeout) logger.debug(result.CmdResult.Output) if result.Status.HasError(): logger.error("Error in running ControlTemperature") return result.Status logger.debug("ControlTemperature function working fine") return StatusResult.Success()
def SetupServerIperf(port, throughput): """ #------------------------------------------------------------------------------------------------------------------- # Name: SetupServerIperf # Input: Takes two arguments # argument1: port # argument2: throughput # Description: Function used start iPerf Server # Return: StatusResult result #------------------------------------------------------------------------------------------------------------------- """ logger.info("Calling SetupServerIperf function") logger.info("TBS: Starting Iperf Server") command = TbsIPerfActions.plinkstr + "iperf -s -p " + str( port) + " -u -i2 -w " + str(throughput) + "M " logger.info("TBS: " + str(command)) try: logger.info("Creating iPerfServer Thread") iPerfServerThread = Thread(target=CommandLine.RunCommand, args=[command, 15]) logger.info("Staring iPerfServer Thread") iPerfServerThread.start() except Exception as e: logger.error("Exception raised from SetupServerIperf function: " + str(e)) return StatusResult.Error( "Exception raised from SetupServerIperf function: " + str(e)) time.sleep(10) logger.info("SetupServerIperf function worked fine") return StatusResult.Success()
def CheckTSens(self, thermalZone): """ #------------------------------------------------------------------------------------------------------------------- # Name: CheckTSens # Input: Takes 1 argument # argument1: thermalZone # Description: Checks temperature on device and reports when it's stable #--------------------------------------------------------------------------------------------------- """ logger.info("Calling CheckTSens function") methodString = "-m CheckTSens-" + str(thermalZone) result = self.SendCommandAndGetResponse(methodString) if result.Status.HasError(): logger.error("Error in running CheckTSens") return result.Status tSens5Temperature = "TSens5Temperature : " match = re.findall(tSens5Temperature + '(.*?);', result.CmdResult.Output, re.DOTALL) if len(match) < 1: return None tSens5Temperature = match[0] logger.debug("CheckTSens function working fine") return tSens5Temperature
def GetSinglePlotStatistics(self, statisticList): logger.info("Getting Single Plot Statistics ") for channel in ['CURRENT', 'VOLTAGE']: commandToRun = f"GetSinglePlotStatistics(0,{channel})" result = self.SendCommandAndGetResponse(commandToRun) if result.HasError(): logger.error(f"Error in reading battery {channel}") return result dataFields = None if self.LastApiResponse: dataFields = self.LastApiResponse.split(",") if (dataFields == None or len(dataFields) < 3): return StatusResult.Error( f"Kratos: Failed to parse response while reading battery {channel} value. Response: {self.LastApiResponse}" ) if channel == 'CURRENT': statisticList[0] = dataFields[2] else: statisticList[1] = dataFields[2] return StatusResult.Success()
def StartMeasurement(self): """ #------------------------------------------------------------------------------------------------------------------- # Name: StartMeasurement # Input: Takes no argument # Description: Starts power measurement on ALPACA # Return: StatusResult() object #------------------------------------------------------------------------------------------------------------------- """ if self.boardHasEpm: if self.epm.getData: logger.warning('ALPACA : Measurement already running. Stopping previous measurement') result = self.StopMeasurement() if result.HasError(): logger.error('ALPACA : Error stopping previous measurement') return result logger.info('ALPACA : Starting measurement') try: self.epm.StartMeasurement() except Exception as e: logger.error(str(e)) return StatusResult.Error('ALPACA : ', str(e)) return StatusResult.Success()
def UsbOn(self): """ ------------------------------------------------------------------------------------------------------------------- Name: UsbOn Input: Takes no argument Description: Enables USB Return: StatusResult() object ------------------------------------------------------------------------------------------------------------------- """ logger.info("Spiderboard: USB On") result = self.ExecuteCommand(SpiderBoard.usbOn) if result.HasError(): logger.error(result.ErrorMessage()) return StatusResult.Error("USB on with the Spiderboard failed! " + result.ErrorMessage()) return StatusResult.Success()
def RestartKratos(self, IpAddress): """ #------------------------------------------------------------------------------------------------------------------- # Name: RestartKratos # Input: Takes Argument: IpAddress of the KratosMachine # Description: Terminates the Kratos application on the kratosmachine. Batch file running on the machine will restart the kratos app. # Return: StatusResult() object #------------------------------------------------------------------------------------------------------------------- """ logger.info("Restarting Kratos Application") methodString = " -m RestartKratos2-" + str(IpAddress) result = self.SendCommandAndGetResponse(methodString) if result.Status.HasError(): logger.error("Error in Sending Command to RestartKratos") return result.Status time.sleep(300) return StatusResult.Success()
def Relay2Off(self): """ ------------------------------------------------------------------------------------------------------------------- Name: Relay2Off Input: Takes no argument Description: Disables Relay2 Return: StatusResult() object ------------------------------------------------------------------------------------------------------------------- """ logger.info("Spiderboard: Relay2 Off") result = self.ExecuteCommand(SpiderBoard.relay2Off) if result.HasError(): logger.error(result.ErrorMessage()) return StatusResult.Error( "Relay2 off with the Spiderboard failed! " + result.ErrorMessage()) return StatusResult.Success()
def CloseSpiderboardComPort(self): """ ------------------------------------------------------------------------------------------------------------------- Name: CloseSpiderboardComPort Input: Takes no argument Description: Close the COM port connection to the Spiderboard. Return: StatusResult() object ------------------------------------------------------------------------------------------------------------------- """ if self.serObj: result = WindowsComPort.CloseComPort(self.serObj) if result.HasError(): logger.error('Failed to close Spiderboard COM port:') logger.error(result.ErrorMessage()) return result return StatusResult.Success()
def SetTemperature(self, temperature): """ #------------------------------------------------------------------------------------------------------------------- # Name: SetTemperature # Input: Takes one argument # argument1: Temperature in degree C # Description: Sets temperature on Thermal Controller #------------------------------------------------------------------------------------------------------------------- """ logger.info("Setting temperature to " + str(temperature)) methodString = "-m SetTemperature-" + str(temperature) result = self.SendCommandAndGetResponse(methodString) if result.Status.HasError(): logger.error("Error in setting Temperature" + result.CmdResult.Output) return result.Status logger.debug("SetTemperatue function working fine") return StatusResult.Success()
def initialize_scenario(self): """ #------------------------------------------------------------------------------------------------------------------- # Name: initialize_scenario # Description: Initialize instance variables for a single scenario # Input: Takes no argument # Return: StatusResult() object #------------------------------------------------------------------------------------------------------------------- """ if self._tbslte_handle is None: try: self._tbslte_handle = TBSLTEUtil(self._host_id) except Exception as e: logger.error( 'Failed to initialize TBS module. Please make sure your TBS is running on Octopus 96 or above' ) return StatusResult.Error( f'Failed to create TBSLTEUtil object. Error: {e}') return StatusResult.Success()
def CheckCalibrationStatus(self, calibrationStatusList): """ #------------------------------------------------------------------------------------------------------------------- # Name: CheckCalibrationStatus # Description: Checks Status of Self Calibration, DMM Calibration & External Calibration #------------------------------------------------------------------------------------------------------------------- """ logger.info("Checking Calibration") methodString = "-m CheckCalibrationStatus-false,false,false" result = self.SendCommandAndGetResponse(methodString) if result.Status.HasError(): logger.error( "Error in Sending Command to get Single Point Statistics") return result selfCalibrationStatus = "selfCalOk : " dmmCalibrationStatus = "dmmCalOk : " externalCalibrationStatus = "extCalOk : " match = re.findall(selfCalibrationStatus + '(.*?);', result.CmdResult.Output, re.DOTALL) if len(match) < 1: return StatusResult.Error("Could not read Self Calibration Status") selfCalibrationStatus = match[0] match = re.findall(dmmCalibrationStatus + '(.*?);', result.CmdResult.Output, re.DOTALL) if len(match) < 1: return StatusResult.Error("Could not read DMM Calibration Status") dmmCalibrationStatus = match[0] match = re.findall(externalCalibrationStatus + '(.*?);', result.CmdResult.Output, re.DOTALL) if len(match) < 1: return StatusResult.Error( "Could not read External Calibration Status") externalCalibrationStatus = match[0] calibrationStatusList.append(selfCalibrationStatus) calibrationStatusList.append(dmmCalibrationStatus) calibrationStatusList.append(externalCalibrationStatus) return result
def ReleaseTacPort(self): """ #------------------------------------------------------------------------------------------------------------------- # Name: ReleaseTacPort # Input: Takes no argument # Description: close TAC port # Return: StatusResult() object #------------------------------------------------------------------------------------------------------------------- """ if self.boardHasTac and hasattr(self.tac, 'ser'): try: logger.debug('Releasing TAC port') self.tac.ser.close() except Exception as e: logger.error('Failed to close TAC port') logger.error(str(e)) return StatusResult.Error('Failed to close TAC port : ', str(e)) return StatusResult.Success()
def StopClientIperf(): """ #------------------------------------------------------------------------------------------------------------------- # Name: StopClientIperf # Input: Takes no arguments # Description: Function used to Stop iPerf Client # Return: StatusResult result #------------------------------------------------------------------------------------------------------------------- """ logger.info("Calling StopClientIperf function") logger.info("TBS: Stopping Iperf Client") command = TbsIPerfActions.plinkstr + "pkill miperf" logger.info("TBS: " + str(command)) result = CommandLine.RunCommand(command, 10) if result.Status.HasError(): logger.error("Unable to kill miperf") return StatusResult.Error("Unable to kill miperf") logger.info("StopClientIperf function worked fine") return StatusResult.Success()
def CoolDevice(self, temperature, timeout): """ #------------------------------------------------------------------------------------------------------------------- # Name: CoolDevice # Input: Takes 2 arguments # argument1: Temperature # argument2: Timeout # Description: Cools down temperature on device #--------------------------------------------------------------------------------------------------- """ logger.info("Calling CoolDevice function") methodString = "-m CoolDevice-" + str(temperature) + "," + str( timeout * 1000) result = self.SendCommandAndGetResponse(methodString, timeout) if result.Status.HasError(): logger.error("Error in running CoolDevice") return result.Status logger.debug("CoolDevice function working fine") return StatusResult.Success()
def EdlSwitchOff(self): """ #------------------------------------------------------------------------------------------------------------------- # Name: EdlSwitchOff # Input: Takes no argument # Description: Switch OFF EDL on ALPACA card # Return: StatusResult() object #------------------------------------------------------------------------------------------------------------------- """ logger.info('ALPACA: EDL switch off') if self.boardHasTac: try: self.tac._write('edl', 0) except Exception as e: logger.error(str(e)) return StatusResult.Error('ALPACA : ', str(e)) return StatusResult.Success()
def PowerOn(self): """ #------------------------------------------------------------------------------------------------------------------- # Name: PowerOn # Input: Takes no argument # Description: Power On ALPACA card # Return: StatusResult() object #------------------------------------------------------------------------------------------------------------------- """ logger.info("ALPACA: Power ON"); if self.boardHasTac: try: self.tac.On() except Exception as e: logger.error(str(e)) return StatusResult.Error('ALPACA : ', str(e)) return StatusResult.Success()
def UsbOff(self): """ #------------------------------------------------------------------------------------------------------------------- # Name: UsbOff # Input: Takes no argument # Description: Disable USB on ALPACA # Return: StatusResult() object #------------------------------------------------------------------------------------------------------------------- """ logger.info('ALPACA: USB OFF') if self.boardHasTac: try: self.tac.DisconnectUsb() except Exception as e: logger.error(str(e)) return StatusResult.Error('ALPACA : ', str(e)) return StatusResult.Success()
def CheckCalibrationStatus(self, calibrationStatusList): """ #------------------------------------------------------------------------------------------------------------------- # Name: CheckCalibrationStatus # Description: Checks Status of Self Calibration, DMM Calibration & External Calibration #------------------------------------------------------------------------------------------------------------------- """ logger.info("Checking Calibration") commandToRun = "CheckCalibrationStatus()" result = self.SendCommandAndGetResponse(commandToRun) if result.HasError(): logger.error( "Kratos: Error in sending command to check the calibration status" ) return result response = self.LastApiResponse.split(',') if (response == None or len(response) != 3): return StatusResult.Error( f"Incorrect response from Kratos while checking calibration status. Response: {self.LastApiResponse}" ) logger.debug(f"External Calibration Status : {response[0]}") logger.debug(f"Self Calibration Status : {response[1]}") logger.debug(f"DMM Calibration Status : {response[2]}") if "PASS" not in response[0]: logger.warning( "External calibration is expired, please contact the IPS team to do the external calibration" ) selfCalibrationStatus = 'True' if ("PASS" in response[1]) else 'False' dmmCalibrationStatus = 'True' if ("PASS" in response[2]) else 'False' externalCalibrationStatus = 'True' if ("PASS" in response[0]) else 'False' calibrationStatusList.append(selfCalibrationStatus) calibrationStatusList.append(dmmCalibrationStatus) calibrationStatusList.append(externalCalibrationStatus) return result
def PingKratos(self, IpAddress, waitTime): """ #------------------------------------------------------------------------------------------------------------------- # Name: PingKratos # Input: IpAddress, waitTime # Description: Try pinging IpAddress for timeout duration = waitTime # Return: StatusResult() object #------------------------------------------------------------------------------------------------------------------- """ currentTime = time.time() timeout = time.time() + waitTime while (currentTime < timeout): result = self.PingStatus(IpAddress) if not result.HasError(): return StatusResult.Success() logger.error("Error in pinging Kratos PC. " + result.ErrorMessage() + ". Pinging again...") time.sleep(120) currentTime = time.time() return StatusResult.Error("Error in pinging Kratos PC : " + str(IpAddress))
def HandleComPort(self): """ ------------------------------------------------------------------------------------------------------------------- Name: HandleComPort Input: Takes no argument Description: Handle the serial COM port connection to the Spiderboard Return: StatusResult() object ------------------------------------------------------------------------------------------------------------------- """ #Search for the Spiderboard COM port result = self.GetSpiderboardComPort() if result.HasError(): logger.error(result.ErrorMessage()) return result if self.portObj: #Open the port and create the COM port object result = self.OpenSpiderboardComPort() if result.HasError(): logger.error('Failed to open Spiderboard COM port') logger.error(result.ErrorMessage()) return result return StatusResult.Success()
def GetUeIpAddress(): """ #------------------------------------------------------------------------------------------------------------------- # Name: GetUeIpAddress # Input: Takes no arguments # Description: Function used to get UE IP Address # Return: UE IP Address #------------------------------------------------------------------------------------------------------------------- """ logger.info("Calling GetUeIpAddress function") logger.info("TBS: Detecting MME State") str1 = "/opt/lte/bin/appTestability.py -s localhost -p 15004 \\\"MME COMMAND GET MME_QUERY_STATE\\\"" command = TbsTestabilityActions.plinkstr + "\"" + str1 + "\"" logger.debug("Command is: " + str(command)) result = CommandLine.RunCommand(command, 15) matched = 0 OutputLines = str(result.CmdResult.OutputLines) OutputLines = OutputLines.split("\\n") logger.info("OutputLines: " + str(OutputLines) + "\n") for line in OutputLines: #logger.debug("Line contains: " + str(line)) if matched == 1: if "IPV4_ADDRESS" in line: match = re.search(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', line).group() if "10.1.1" in match: ipAddress = match logger.info("TBS: UE IP Address: " + str(ipAddress)) return ipAddress if ipAddress == "": logger.error("Failed to detect UE IP Address") return None else: match = re.search(r"\"IP_TYPE\" : \"IPV4\",", line) if match != None: matched = 1 logger.debug("Line contains: " + str(line))
def SetConfigurationFile(self, configFile): """ #------------------------------------------------------------------------------------------------------------------- # Name: SetConfigurationFile # Input: Takes one argument # configFile: json config filename for ALPACA # Description: Sets up configuration for ALPACA card # Return: StatusResult() object #------------------------------------------------------------------------------------------------------------------- """ logger.info("Loading ALPACA Configuration : " + configFile) if not configFile.endswith('.json'): return StatusResult.Error('ALPACA : ', 'Incorrect Configuration file for ALPACA, JSON file needed') configFile = CommonApplicationUtilities._ResourcesConfigFilePath + '\\Alpaca\\' + configFile if self.boardHasEpm: if self.epm.getData: logger.warning('ALPACA : Measurement already running. Stopping previous measurement') result = self.StopMeasurement() if result.HasError(): logger.error('ALPACA : Error while stopping previous measurement') return result if not os.path.exists(configFile): return StatusResult.Error('ALPACA : ', 'Configuration file not found') if self.boardHasEpm: try: self.epm.SetConfigFile(configFile) except Exception as e: logger.error(str(e)) return StatusResult.Error('ALPACA : ', str(e)) return StatusResult.Success()
def ReadPVTemperature(self): """ #------------------------------------------------------------------------------------------------------------------- # Name: ReadPVTemperature # Description: Reads PV temperature on Thermal Controller #------------------------------------------------------------------------------------------------------------------- """ logger.info("Read PV temperature from Thermal Controller") methodString = "-m ReadPVTemperature-1" result = self.SendCommandAndGetResponse(methodString) if result.Status.HasError(): logger.error("Error in reading PV Temperature") return result.Status pvTemp = "PVTemp : " match = re.findall(pvTemp + '(.*?);', result.CmdResult.Output, re.DOTALL) if len(match) < 1: return None pvTemp = match[0] logger.debug("ReadPVTemperature function working fine") return pvTemp
def StartClientIperf(port, throughput, duration): """ #------------------------------------------------------------------------------------------------------------------- # Name: StartClientIperf # Input: Takes five arguments # argument1: port # argument2: throughput # argument3: duration - time in seconds to run iPerf # Description: Function used to start iPerf client # Return: StatusResult result #------------------------------------------------------------------------------------------------------------------- """ logger.info("Calling StartClientIperf function") ueIpAddress = TbsIPerfActions.GetUeIpAddress() if ueIpAddress == "": logger.error("Error in getting UE IP Address") return logger.error("Failed to detect UE IP Address") logger.info("TBS: Starting Iperf Client") command = TbsIPerfActions.plinkstr + "miperf -c " + str( ueIpAddress) + " -p " + str(port) + " -u -b " + str( throughput) + "M -t " + str(duration) + " -i2 -w16M" logger.info("TBS: " + str(command)) try: logger.info("Starting iPerfClientThread") iPerfClientThread = Thread(target=CommandLine.RunCommand, args=[command, 15]) iPerfClientThread.start() except Exception as e: logger.error("Exception raised from StartClientIperf function: " + str(e)) return StatusResult.Error( "Exception raised from StartClientIperf function: " + str(e)) time.sleep(10) logger.info("SetupClientIperf function worked fine") return StatusResult.Success()