Exemplo n.º 1
0
    def initializeHardware(self, patientObj, performSetup=False, PII=False, setupPG=True): 
        """
        Initializes the communicator and optionally a PG. The Komodo Patient 
        object is used as input to get the DragonPG handle/object (optional) and
        to instantiate the Perseus communicator object. 

        The communicator is reset to factory settings, rebooted, activated in 
        the Latitude database, and the serial number is set. Optionally, the 
        communicator can be directed to make the initial server call and/or 
        perform a PII by setting performSetup=True.

        In the event that PII=True and setupPG=False, this method will assume 
        that the PG has been previously initialized outside of this method and
        will still attempt the PII.

        @param patientObj: Komodo Patient object
        @type patientObj: C{L{komodo.entities.patient.Patient}}
        @param performSetup: Whether to perform server call
        @type performSetup: C{bool}
        @param PII: True/False expression to perform a PII
        @type PII: C{bool}
        @param setupPG: True/False expression to create DragonPG handle (returns None if False)
        @type setupPG: C{bool}
        @return: Tuple containing Perseus communicator object and Dragon PG handle
        @rtype: C{tuple}
        """        

        # Don't setup the PG unless asked to
        if setupPG:
            self.log.info('Initializing the Pulse Generator')
            pg = komodo.dragonpg.getInstance(self.testContext, patientObj.pg)
        else:
            self.log.info('initializeHardware: skipping initialization of pulse generator by request')
            pg = None

        # Power up the communicator
        relaybox = perseus.relaybox.LatitudeRelayBox() 
        self.log.info('Checking power state of the communicator')
        if not relaybox.getCommunicatorPower(): 
            relaybox.setCommunicatorPower(1) 
            self.log.info('initializeHardware: Powering up communicator and waiting for one minute')
            time.sleep(60)

        # Setup the communicator
        try:
            communicator = perseus.communicator.getInstance()
            
        # getInstance fails unable to connect to diag or otherwise, just try
        # again by rebooting first
        except:
            self.log.info('initializeHardware: Powering up communicator and waiting for DIAG')
            relaybox.setCommunicatorPower(0) 
            time.sleep(3)
            relaybox.setCommunicatorPower(1) 
            time.sleep(30)
            communicator = perseus.communicator.getInstance()
            communicator.waitForDiagUp()
            
        communicator.setUTCDateAndTime(perseus.dateandtime.utcNow()) 
        
        if perseus.availability.evaluate('G2InductiveCommunicator_FS') or \
           perseus.availability.evaluate('BobcatInductiveCommunicator_FS') or \
           perseus.availability.evaluate('G2RFCommunicator_FS'):
            communicator.setSerialNumber(patientObj.communicator.serialNumber) 
            communicator.resetToFactorySettingsAndWait()
            
        else:    
            # Start RTC 58817
            self.log.info('Attempting to set the communicator country')
            if self.testContext['country']:
                ctry = self.testContext['country']
            else:
                ctry = self.testContext['env'].defaultCountry
            assert communicator.setCountry(ctry.iso3code), '%s was not set correctly' % self.testContext['country'].name                
            # End RTC 58817

            communicator.mtiEnter()
            communicator.mtiCommand('resetToFactorySettings')
            communicator.mtiCommand('set Serial %s' % patientObj.communicator.serialNumber)
            communicator.mtiExit()
            communicator.waitForDiagUp()
            communicator.waitForEvent('uiDisplayUpdated', timeout=60)

        # Configure the Wanded G2-based Communicators for PGSim
        if perseus.availability.evaluate('Japan') and perseus.availability.evaluate('InductiveCommunicator'):
            if self.testContext['pgsim']:
                communicator.configureForPGSim()
            else:
                communicator.configureForPG()

        # Configure the MICS-based Communicators for PGSim                
        if perseus.availability.evaluate('MICSCommunicator'):
            if self.testContext['pgsim']:
                communicator.configureTelemetry(communicator.PG_VIA_ETHERNET)
            else:
                communicator.configureTelemetry(communicator.PG_VIA_RF)

        # Setup the communicator and do a PII as requested
        if performSetup:
            self.log.info('Attempting communicator setup/server call')
            commLogLocation = communicator.startSerialPortLogging(communicator.LOG_FILE)  # RTC 58050: Exception: Error during performSetup
            performSetupResult = communicator.performSetup()
            communicator.stopSerialPortLogging()
            if not performSetupResult:
                raise Exception('Error during performSetup')
            os.remove(commLogLocation) # remove serial log from successful calls                

            if PII: 
                self.log.info('Attempting Patient-initiated interrogation')
                communicator.performPII()
            
                # SyRS007720 states it can take 30 seconds for data to appear on the system.  
                # In practice 10 seconds is enough if no alerts are present
                time.sleep(10) 
                
        else:
            self.log.info('Skipping setup of communicator by request')
            self.log.info('Skipping PII of pulse generator by request')

        return communicator, pg    
Exemplo n.º 2
0
def initializeHardware(testContext, poc, pg, interrogate=False, logging=True):
    """
    Initialize a POC communicator and a PG. The KomodoRS POC and PG entities are 
    used as input to get the PGPro handle/object and to instantiate the Perseus 
    communicator object. 

    The communicator is reset to factory settings, rebooted, and the serial 
    number is set. Optionally, the communicator can be directed to perform an
    interrogation by setting interrogate=True.

    @param testContext: KomodoRS testContext
    @type testContext: C{Dict}
    
    @param poc: C{L{POCCommunicatorEntity<komodors.entities.POCCommunicatorEntity>}}
    @type poc: POCCommunicatorEntity
    
    @param pg: C{L{PGEntity<komodors.entities.PGEntity>}}
    @type pg: PGEntity    
    
    @param interrogate: True/False expression to perform a interrogation
    @type interrogate: C{bool}

    @param logging: True/False expression to start serial port logging on the communicator
    @type logging: C{bool}

    @return: Tuple containing Perseus communicator object and PG handle
    @rtype: C{tuple}
    """

    log = getFunctionLogger()
    assert "pgsim" in testContext, "The provided input for testContext does not have the pgsim key"
    assert type(poc) == POCCommunicatorEntity, "The provided input for POC is not of the correct type"
    assert type(pg) == PGEntity, "The provided input for pg is not of the correct type"

    # Power up the communicator
    relaybox = perseus.relaybox.LatitudeRelayBox()
    log.info("Checking power state of the communicator")
    if not relaybox.getCommunicatorPower():
        relaybox.setCommunicatorPower(1)
        log.info("Powering up communicator and waiting for one minute")
        time.sleep(60)

    # Setup the communicator
    try:
        communicator = perseus.communicator.getInstance()

    # If getInstance fails unable to connect to diag or otherwise, just try
    # again after rebooting first
    except:
        log.info("A problem occurred when initializing the communicator.")
        log.info("Power-cycling the communicator and waiting for DIAG")
        relaybox.setCommunicatorPower(0)
        time.sleep(3)
        relaybox.setCommunicatorPower(1)
        time.sleep(45)
        communicator = perseus.communicator.getInstance()

    assert communicator is not None, "Instantiation of communicator hardware returned a None result"
    assert (
        poc.modelNumber == communicator.getModelNumber()
    ), "Instantiation of communicator hardware returned a different hardware object"
    if logging:
        communicator.startSerialPortLogging(communicator.LOG_FILE)
        log.info("Communicator serial port logging has begun")

    testContext["comm"] = communicator

    communicator.waitForDiagUp()
    communicator.setUTCDateAndTime(perseus.dateandtime.utcNow())
    log.info("Setting communicator serial number to %s" % poc.serialNumber)
    communicator.setSerialNumber(poc.serialNumber)
    communicator.resetToFactorySettingsAndWait()

    # Configure the Wanded G2-based Communicators for PGSim
    if testContext["pgsim"]:
        communicator.configureForPGSim(pg.modelNumber, pg.serialNumber)
    else:
        communicator.configureForPG()

    # Get the PG Handle
    log.info("Initializing the Pulse Generator")
    pghandle = getPGInstance(testContext, pg)
    assert pghandle is not None, "Instantiation of pg hardware returned a None result"
    testContext["pg"] = pghandle

    # Do a PII if requested
    if interrogate:
        log.info("Attempting Patient-initiated interrogation")
        communicator.performPII(returnToHome=True)
    else:
        log.info("Skipping interrogation of pulse generator by request")

    return communicator, pghandle