Exemple #1
0
def setEnsembleContext(theMDIB, theClient):
    # calling operation on remote device
    print("Trying to set ensemble context of device A")
    # first we get the container to the element in the MDIB
    descriptorContainer = theMDIB.descriptions.NODETYPE.getOne(
        domTag('EnsembleContextDescriptor'))
    # get the context of our provider(client)
    contextClient = theClient.ContextService_client
    # start with empty operation handle and try to find the one we need
    operationHandle = None
    # iterate over all matching handles (can be 0..n)
    for oneOp in theMDIB.descriptions.NODETYPE.get(
            domTag('SetContextStateOperationDescriptor'), []):
        if oneOp.OperationTarget == descriptorContainer.handle:
            operationHandle = oneOp.Handle
    # now we should have a operatoin handle to work with
    # create a new ensemble context as parameter to this operation
    newEnsembleContext = contextClient.mkProposedContextObject(
        descriptorContainer.handle)
    newEnsembleContext.ContextAssociation = 'Assoc'
    newEnsembleContext.Identification = [
        pmtypes.InstanceIdentifier(root="1.2.3",
                                   extensionString="SupervisorSuperEnsemble")
    ]
    # execute the remote operation (based on handle) with the newly created ensemble as parameter
    contextClient.setContextState(operationHandle, [newEnsembleContext])
    def test_ActivateOperationDescriptorContainer(self):
        def _cmp_ActivateOperationDescriptorContainer(_dc, _dc2):
            self.assertEqual(_dc.diff(_dc2), [])
            self.assertEqual(_dc.Argument, _dc2.Argument)
            #            self.assertEqual(_dc.ActivationDuration, _dc2.ActivationDuration)
            self.assertEqual(_dc.Retriggerable, _dc2.Retriggerable)

        dc = descriptorcontainers.ActivateOperationDescriptorContainer(
            nsmapper=self.nsmapper,
            nodeName=namespaces.domTag('MyDescriptor'),
            handle='123',
            parentHandle='456',
        )
        # create copy with default values
        node = dc.mkNode()
        dc2 = descriptorcontainers.ActivateOperationDescriptorContainer.fromNode(
            nsmapper=self.nsmapper, node=node, parentHandle='467')
        _cmp_ActivateOperationDescriptorContainer(dc, dc2)

        dc.Argument = [
            pmtypes.Argument(argName=pmtypes.CodedValue('abc', 'def'),
                             arg=namespaces.domTag('blubb'))
        ]
        node = dc.mkNode()
        dc2.updateDescrFromNode(node)
        _cmp_ActivateOperationDescriptorContainer(dc, dc2)
Exemple #3
0
    def test_AbstractStateContainer(self):
        sc = statecontainers.AbstractStateContainer(
            nsmapper=self.nsmapper, descriptorContainer=self.dc, node=None)
        # constructor shall create a node
        self.assertEqual(sc.nodeName, namespaces.domTag('State'))

        #initially the state version shall be 0, and DescriptorVersion shall be set
        self.assertEqual(sc.StateVersion, 0)
        self.assertEqual(sc.DescriptorVersion, self.dc.DescriptorVersion)

        # verify that mkStateNode() also updates changed Descriptorversion
        self.dc.DescriptorVersion += 1
        sc.mkStateNode()
        self.assertEqual(sc.DescriptorVersion, self.dc.DescriptorVersion)

        # verify incrementState works ay expected
        sc.incrementState()
        self.assertEqual(sc.StateVersion, 1)
        node = sc.mkStateNode()
        self.assertEqual(node.get('StateVersion'), '1')

        # test updateFromNode
        node = etree_.Element(namespaces.domTag('State'),
                              attrib={
                                  'StateVersion': '2',
                                  'DescriptorHandle': self.dc.handle
                              })
        sc.updateFromNode(node)
        self.assertEqual(sc.StateVersion, 2)
        self.assertEqual(sc.node.get('StateVersion'), '2')

        node = etree_.Element(namespaces.domTag('State'),
                              attrib={
                                  'StateVersion':
                                  '3',
                                  'DescriptorHandle':
                                  'something_completely_different'
                              })
        self.assertRaises(RuntimeError, sc.updateFromNode, node)

        #test creation from node
        sc2 = statecontainers.AbstractStateContainer(
            nsmapper=self.nsmapper,
            descriptorContainer=self.dc,
            node=copy.deepcopy(sc.node)
        )  # sc2 might change node, therfore give it a deep copy
        self._verifyAbstractStateContainerDataEqual(sc, sc2)

        # test update from Node
        sc.DescriptorVersion += 1
        sc.incrementState()
        node = sc.mkStateNode()
        sc2.updateFromNode(node)
        self._verifyAbstractStateContainerDataEqual(sc, sc2)
Exemple #4
0
def setLocalEnsembleContext(mdib, ensemble):
    descriptorContainer = mdib.descriptions.NODETYPE.getOne(
        domTag('EnsembleContextDescriptor'))
    if not descriptorContainer:
        print("No ensemble contexts in mdib")
        return
    allEnsembleContexts = mdib.contextStates.descriptorHandle.get(
        descriptorContainer.handle, [])
    with mdib.mdibUpdateTransaction() as mgr:
        # set all to currently associated Locations to Disassociated
        associatedEnsembles = [
            l for l in allEnsembleContexts
            if l.ContextAssociation == pmtypes.ContextAssociation.ASSOCIATED
        ]
        for l in associatedEnsembles:
            ensembleContext = mgr.getContextState(l.descriptorHandle, l.Handle)
            ensembleContext.ContextAssociation = pmtypes.ContextAssociation.DISASSOCIATED
            ensembleContext.UnbindingMdibVersion = mdib.mdibVersion  # UnbindingMdibVersion is the first version in which it is no longer bound ( == this version)

        newEnsState = mgr.getContextState(
            descriptorContainer.handle)  # this creates a new location state
        newEnsState.ContextAssociation = 'Assoc'
        newEnsState.Identification = [
            pmtypes.InstanceIdentifier(root="1.2.3", extensionString=ensemble)
        ]
    def test_LimitAlertConditionDescriptorContainer(self):
        dc = descriptorcontainers.LimitAlertConditionDescriptorContainer(
            nsmapper=self.nsmapper,
            nodeName=namespaces.domTag('MyDescriptor'),
            handle='123',
            parentHandle='456',
        )
        # create copy with default values
        node = dc.mkNode()
        dc2 = descriptorcontainers.LimitAlertConditionDescriptorContainer.fromNode(
            nsmapper=self.nsmapper, node=node, parentHandle='467')
        self._cmp_LimitAlertConditionDescriptorContainer(dc, dc2)

        # set values, test updateFromNode
        dc.MaxLimits = pmtypes.Range(lower=0,
                                     upper=100,
                                     stepWidth=1,
                                     relativeAccuracy=0.1,
                                     absoluteAccuracy=0.2)
        dc.AutoLimitSupported = True
        node = dc.mkNode()
        dc2.updateDescrFromNode(node)
        self._cmp_LimitAlertConditionDescriptorContainer(dc, dc2)

        # create copy with values set
        dc2 = descriptorcontainers.LimitAlertConditionDescriptorContainer.fromNode(
            nsmapper=self.nsmapper, node=node, parentHandle='467')
        self._cmp_LimitAlertConditionDescriptorContainer(dc, dc2)
    def test_getContextStates(self):
        facility = 'HOSP42'
        poc = 'Care Unit 1'
        bed = 'my bed'
        loc = SdcLocation(fac=facility, poc=poc, bed=bed)
        for sdcDevice in self._alldevices:
            sdcDevice.mdib.setLocation(loc)
            contextService = sdcDevice._handler._ContextDispatcher
            endpoint_reference = '123'
            getEnv = self._mkGetRequest(sdcDevice,
                                        contextService.port_type_string,
                                        'GetContextStates', endpoint_reference)
            receivedEnv = AddressedSoap12Envelope.fromXMLString(
                getEnv.as_xml())
            httpHeader = {}
            response = contextService.dispatchSoapRequest(
                None, httpHeader, receivedEnv)
            print(response.as_xml(pretty=True))
            response.validateBody(sdcDevice.mdib.bicepsSchema.bmmSchema)
            _ns = sdcDevice.mdib.nsmapper  # shortcut
            query = '*/{}[@{}="{}"]'.format(
                _ns.docName(Prefix.MSG, 'ContextState'),
                _ns.docName(Prefix.XSI, 'type'),
                _ns.docName(Prefix.PM, 'LocationContextState'))
            locationContextNodes = response.bodyNode.xpath(
                query, namespaces=_ns.docNssmap)
            self.assertEqual(len(locationContextNodes), 1)
            identificationNode = locationContextNodes[0].find(
                domTag('Identification'))
            if sdcDevice is self.sdcDevice_final:
                self.assertEqual(identificationNode.get('Extension'),
                                 '{}///{}//{}'.format(facility, poc, bed))
            else:
                self.assertEqual(identificationNode.get('Extension'),
                                 '{}/{}/{}'.format(facility, poc, bed))

            locationDetailNode = locationContextNodes[0].find(
                domTag('LocationDetail'))
            self.assertEqual(locationDetailNode.get('PoC'), poc)
            self.assertEqual(locationDetailNode.get('Bed'), bed)
            self.assertEqual(locationDetailNode.get('Facility'), facility)
            print(response.as_xml(pretty=True))
 def test_episodicContextReportEvent(self):
     ''' verify that an event message is sent to subscriber and that message is valid'''
     # directly inject a subscription event, this test is not about starting subscriptions
     for sdcDevice in self._allDevices:
         testSubscr = mockstuff.TestDevSubscription(sdcDevice.mdib.sdc_definitions.Actions.EpisodicContextReport, sdcDevice.mdib.bicepsSchema)
         sdcDevice.subscriptionsManager._subscriptions.addObject(testSubscr)
         patientContextDescriptor = sdcDevice.mdib.descriptions.NODETYPE.getOne(namespaces.domTag('PatientContextDescriptor'))
         descriptorHandle = patientContextDescriptor.handle
         with sdcDevice.mdib.mdibUpdateTransaction() as mgr:
             st = mgr.getContextState(descriptorHandle)
             st.PatientType = pmtypes.PatientType.ADULT
         self.assertEqual(len(testSubscr.reports), 1)
         response = testSubscr.reports[0]
         response.validateBody(sdcDevice.mdib.bicepsSchema.bmmSchema)
    def test_EnumStringMetricDescriptorContainer(self):
        dc = descriptorcontainers.EnumStringMetricDescriptorContainer(
            nsmapper=self.nsmapper,
            nodeName=namespaces.domTag('MyDescriptor'),
            handle='123',
            parentHandle='456',
        )
        dc.AllowedValue = [pmtypes.AllowedValue('abc')]

        node = dc.mkNode()
        print(etree_.tostring(node, pretty_print=True))
        dc2 = descriptorcontainers.EnumStringMetricDescriptorContainer.fromNode(
            nsmapper=self.nsmapper, node=node, parentHandle='467')
        self.assertEqual(dc.AllowedValue, dc2.AllowedValue)
Exemple #9
0
    def test_RealTimeSampleArrayMetricStateContainer(self):
        dc = descriptorcontainers.RealTimeSampleArrayMetricDescriptorContainer(
            nsmapper=self.nsmapper,
            nodeName='MyDescriptor',
            handle='123',
            parentHandle='456')

        def verifyEqual(origin, copied):
            self.assertEqual(copied.metricValue.Samples,
                             origin.metricValue.Samples)
            self.assertEqual(copied.metricValue.DeterminationTime,
                             origin.metricValue.DeterminationTime)
            self.assertEqual(copied.metricValue.Annotation,
                             origin.metricValue.Annotation)
            self.assertEqual(copied.metricValue.ApplyAnnotations,
                             origin.metricValue.ApplyAnnotations)
            self._verifyAbstractStateContainerDataEqual(copied, origin)

        sc = statecontainers.RealTimeSampleArrayMetricStateContainer(
            nsmapper=self.nsmapper, descriptorContainer=dc, node=None)
        sc.mkMetricValue()
        self.assertEqual(sc.nodeName, namespaces.domTag('State'))
        self.assertTrue(isinstance(sc.metricValue, pmtypes.SampleArrayValue))

        sc.metricValue.Samples = [1, 2, 3, 4, 5.5]
        sc.metricValue.DeterminationTime = 1234567
        sc.metricValue.Annotations = []
        sc.metricValue.ApplyAnnotations = []
        sc.ActivationState = 'act'

        #test creation from node
        node = sc.mkStateNode()
        sc2 = statecontainers.RealTimeSampleArrayMetricStateContainer(
            nsmapper=self.nsmapper, descriptorContainer=dc, node=node)
        verifyEqual(sc, sc2)

        #test update from node
        sc.metricValue.Samples = [5.5, 6.6]
        sc.metricValue.DeterminationTime = 2345678
        sc.metricValue.Annotations = [
            pmtypes.Annotation(pmtypes.CodedValue('a', 'b'))
        ]
        sc.metricValue.ApplyAnnotations = [pmtypes.ApplyAnnotation(1, 2)]

        sc.incrementState()
        node = sc.mkStateNode()
        sc2.updateFromNode(node)
        verifyEqual(sc, sc2)
    def test_AlertConditionDescriptorContainer(self):
        dc = descriptorcontainers.AlertConditionDescriptorContainer(
            nsmapper=self.nsmapper,
            nodeName=namespaces.domTag('MyDescriptor'),
            handle='123',
            parentHandle='456',
        )
        # create copy with default values
        node = dc.mkNode()
        dc2 = descriptorcontainers.AlertConditionDescriptorContainer.fromNode(
            nsmapper=self.nsmapper, node=node, parentHandle='467')
        self._cmp_AlertConditionDescriptorContainer(dc, dc2)

        # set values, test updateFromNode
        dc.Source = [
            pmtypes.ElementWithTextOnly('A'),
            pmtypes.ElementWithTextOnly('B')
        ]
        dc.Cause = [
            pmtypes.CauseInfo(remedyInfo=pmtypes.RemedyInfo(
                [pmtypes.LocalizedText('abc'),
                 pmtypes.LocalizedText('def')]),
                              descriptions=[
                                  pmtypes.LocalizedText('descr1'),
                                  pmtypes.LocalizedText('descr2')
                              ]),
            pmtypes.CauseInfo(remedyInfo=pmtypes.RemedyInfo(
                [pmtypes.LocalizedText('123'),
                 pmtypes.LocalizedText('456')]),
                              descriptions=[
                                  pmtypes.LocalizedText('descr1'),
                                  pmtypes.LocalizedText('descr2')
                              ])
        ]
        dc.Kind = 'cont'
        dc.Priority = 'High'
        node = dc.mkNode()
        dc2.updateDescrFromNode(node)
        self._cmp_AlertConditionDescriptorContainer(dc, dc2)

        # create copy with values set
        dc2 = descriptorcontainers.AlertConditionDescriptorContainer.fromNode(
            nsmapper=self.nsmapper, node=node, parentHandle='467')
        self._cmp_AlertConditionDescriptorContainer(dc, dc2)
Exemple #11
0
 def __init__(self,
              wsdiscovery,
              my_uuid,
              mdib_xml_string,
              validate=True,
              sslContext=None,
              logLevel=logging.INFO,
              log_prefix='',
              chunked_messages=False):
     model = DPWSThisModel(
         manufacturer='Draeger CoC Systems',
         manufacturerUrl='www.draeger.com',
         modelName='SomeDevice',
         modelNumber='1.0',
         modelUrl='www.draeger.com/whatever/you/want/model',
         presentationUrl='www.draeger.com/whatever/you/want/presentation')
     device = DPWSThisDevice(friendlyName='Py SomeDevice',
                             firmwareVersion='0.99',
                             serialNumber='12345')
     #        log_prefix = '' if not ident else '<{}>:'.format(ident)
     deviceMdibContainer = DeviceMdibContainer.fromString(
         mdib_xml_string, log_prefix=log_prefix)
     # set Metadata
     mdsDescriptor = deviceMdibContainer.descriptions.NODETYPE.getOne(
         namespaces.domTag('MdsDescriptor'))
     mdsDescriptor.Manufacturer.append(pmtypes.LocalizedText(u'Dräger'))
     mdsDescriptor.ModelName.append(
         pmtypes.LocalizedText(model.modelName[None]))
     mdsDescriptor.SerialNumber.append(
         pmtypes.ElementWithTextOnly('ABCD-1234'))
     mdsDescriptor.ModelNumber = '0.99'
     mdsDescriptor.updateNode()
     super(SomeDevice, self).__init__(
         wsdiscovery,
         my_uuid,
         model,
         device,
         deviceMdibContainer,
         validate,
         # registerDefaultOperations=True,
         sslContext=sslContext,
         logLevel=logLevel,
         log_prefix=log_prefix,
         chunked_messages=chunked_messages)
    def _test_ClockDescriptorContainer(self, cls):
        dc = cls(
            nsmapper=self.nsmapper,
            nodeName=namespaces.domTag('MyDescriptor'),
            handle='123',
            parentHandle='456',
        )
        # create copy with default values
        node = dc.mkNode()
        dc2 = cls.fromNode(nsmapper=self.nsmapper,
                           node=node,
                           parentHandle='467')
        self.assertEqual(dc.TimeProtocol, dc2.TimeProtocol)
        self.assertEqual(dc.Resolution, dc2.Resolution)

        dc.TimeProtocol = [
            pmtypes.CodedValue('abc', 'def'),
            pmtypes.CodedValue('123', '456')
        ]
        dc.Resolution = 3.14
        node = dc.mkNode()
        dc2.updateDescrFromNode(node)
        self.assertEqual(dc.TimeProtocol, dc2.TimeProtocol)
        self.assertEqual(dc.Resolution, dc2.Resolution)
Exemple #13
0
    dpwsDevice = sdc11073.pysoap.soapenvelope.DPWSThisDevice(friendlyName='TestDevice',
                                                             firmwareVersion='Version1',
                                                             serialNumber='12345')
    if ca_folder:
        ssl_context = mk_ssl_context_from_folder(ca_folder, cyphers_file=None,
                                                 ssl_passwd=ssl_passwd)
    else:
        ssl_context = None
    sdcDevice = sdc11073.sdcdevice.sdcdeviceimpl.SdcDevice(wsd, my_uuid, dpwsModel, dpwsDevice, my_mdib,
                                                           sslContext=ssl_context)
    sdcDevice.startAll()

    validators = [sdc11073.pmtypes.InstanceIdentifier('Validator', extensionString='System')]
    sdcDevice.setLocation(loc, validators)
    patientDescriptorHandle = my_mdib.descriptions.nodeName.get(domTag('PatientContext'))[0].handle
    with my_mdib.mdibUpdateTransaction() as mgr:
        patientContainer = mgr.getContextState(patientDescriptorHandle)
        patientContainer.Givenname = "Given"
        patientContainer.Middlename = "Middle"
        patientContainer.Familyname = "Familiy"
        patientContainer.Birthname = "Birthname"
        patientContainer.Title = "Title"
        patientContainer.ContextAssociation = "Assoc"
        identifiers = []
        patientContainer.Identification = identifiers

    descs = list(sdcDevice.mdib.descriptions.objects)
    descs.sort(key=lambda x: x.handle)
    metric = None
    alertCondition = None
Exemple #14
0
    def testRecording(self):
        testFile = "testFile"

        # create and start recorder
        rec = sdc11073.recording.ClientRecorder(self.sdcClientCocoFinal,
                                                ".",
                                                filename=testFile)
        rec.startRecording()
        self.cleanUpDirs.append(rec.currentRecordingPath)

        # make changes to the mdib
        with self.sdcDeviceCoCoFinal.mdib.mdibUpdateTransaction(
                setDeterminationTime=False) as mgr:
            mst = mgr.getMetricState('0x34F00100')
            if mst.metricValue is None:
                mst.mkMetricValue()
            mst.metricValue.Value = 12
            mst.metricValue.Validity = 'Vld'
            mst.metricValue.DeterminationTime = time.time()
            metricDescriptor = mgr.getDescriptor('0x34F00100')
            metricDescriptor.DeterminationPeriod = 29.0
            numericMetricDescriptorContainer = NumericMetricDescriptorContainer(
                nsmapper=self.sdcDeviceCoCoFinal.mdib.nsmapper,
                nodeName=namespaces.domTag('Metric'),
                handle="testHandle",
                parentHandle='2.1.1.1'  #"COCO_2827", #""COCO_3120",
            )
            numericMetricDescriptorContainer.Type = CodedValue('11921', 'sys')
            numericMetricDescriptorContainer.Unit = CodedValue('11921', 'sys')
            numericMetricDescriptorContainer.Resolution = 0.01
            mgr.createDescriptor(numericMetricDescriptorContainer)

        with self.sdcDeviceCoCoFinal.mdib.mdibUpdateTransaction(
                setDeterminationTime=False) as mgr:
            metricState = mgr.getMetricState("testHandle")
            metricState.Validity = 'Vld'

        time.sleep(1)

        mdsHandle = self.sdcDeviceCoCoFinal.mdib.descriptions.NODETYPE.getOne(
            sdc11073.namespaces.domTag('MdsDescriptor')).handle
        with self.sdcDeviceCoCoFinal.mdib.mdibUpdateTransaction() as mgr:
            tst = mgr.getComponentState(mdsHandle)
            tst.ActivationState = "StndBy"
        time.sleep(1)

        with self.sdcDeviceCoCoFinal.mdib.mdibUpdateTransaction(
                setDeterminationTime=True) as mgr:
            acst = mgr.getAlertState('0xD3C00100')
            acst.Presence = False
        time.sleep(1)

        with self.sdcDeviceCoCoFinal.mdib.mdibUpdateTransaction(
                setDeterminationTime=True) as mgr:
            asst = mgr.getAlertState(
                '0xD3C00100.loc.Vis')  #('AlertSignal_0xD3C00100_Aud')
            asst.ActivationState = 'On'
        time.sleep(1)

        patientDescriptorContainer = self.sdcDeviceCoCoFinal.mdib.descriptions.NODETYPE.getOne(
            sdc11073.namespaces.domTag('PatientContextDescriptor'))
        # create a patient locally on device, then test update from client
        with self.sdcDeviceCoCoFinal.mdib.mdibUpdateTransaction() as mgr:
            st = mgr.getContextState(patientDescriptorContainer.handle)
            st.Givenname = 'Max123'
            st.Middlename = 'Willy'
            st.Birthname = 'Mustermann \n'
            st.Familyname = 'Musterfrau'
            st.Title = 'Rex'
            st.Sex = 'M'
            st.PatientType = pmtypes.PatientType.ADULT
            st.Height = sdc11073.pmtypes.Measurement(
                88.2, sdc11073.pmtypes.CodedValue('abc', 'def'))
            st.Weight = sdc11073.pmtypes.Measurement(
                68.2, sdc11073.pmtypes.CodedValue('abc'))
            st.Race = sdc11073.pmtypes.CodedValue('123', 'def')

        newLocation = SdcLocation(fac='tasdaklx',
                                  poc='CsadU1',
                                  bed='cocoDraft10Bed')
        self.sdcDeviceCoCoFinal.setLocation(newLocation, [])

        paw = waveforms.SawtoothGenerator(min_value=0,
                                          max_value=10,
                                          waveformperiod=1.1,
                                          sampleperiod=0.01)
        self.sdcDeviceCoCoFinal.mdib.registerWaveformGenerator(
            '0x34F05500', paw)

        # record some waveforms and then stop
        for x in range(20):
            time.sleep(1)
            # make changes to the mdib
            with self.sdcDeviceCoCoFinal.mdib.mdibUpdateTransaction(
                    setDeterminationTime=False) as mgr:
                mst = mgr.getMetricState('0x34F00100')
                mst.metricValue.Value = x

        with self.sdcDeviceCoCoFinal.mdib.mdibUpdateTransaction(
                setDeterminationTime=True) as mgr:
            asst = mgr.getAlertState(
                '0xD3C00100.loc.Vis')  #('AlertSignal_0xD3C00100_Aud')
            asst.ActivationState = 'Off'
        time.sleep(1)
        rec.stopRecording()
        # verify recording has stopped by monitoring the file size
        recordingFile = os.path.join(rec.currentRecordingPath,
                                     testFile) + ".rec"
        currentSize = os.path.getsize(recordingFile)
        time.sleep(1)
        self.assertEqual(currentSize, os.path.getsize(recordingFile))
        #
        # verify contents have metric and real time updates
        with open(recordingFile, 'r') as f:
            version = f.readline()
            self.assertTrue("pysdc ver" in version)

            mdib = f.readline()
            self.assertTrue("GetMdibResponse" in mdib)

            for line in f:
                nodeString = line.split("|", 1)[1]
                if nodeString.startswith("u'"):
                    nodeString = nodeString[2:-2]
                else:
                    nodeString = nodeString[1:-2]
                node = lxml.etree.fromstring(nodeString)

                if node.tag == namespaces.msgTag(
                        'DescriptionModificationReport'):
                    val = node.xpath('//dom:MetricValue',
                                     namespaces=namespaces.nsmap)
                    self.assertEqual(val[0].attrib['Value'], '12')
                    f.close()
                    break

        #verify archive has been created
        rec.archive()
        expectedZipFile = os.path.join(rec.currentRecordingPath,
                                       testFile) + ".zip"
        self.assertTrue(os.path.exists(expectedZipFile))
        rec_file = os.path.join(rec.currentRecordingPath, testFile) + ".rec"
        player = sdc11073.recording.MdibPlayer()
        mdib = player.readRecording(rec_file)

        model = DPWSThisModel(manufacturer="Draeger",
                              manufacturerUrl="draeger.com",
                              modelName="testMOdel",
                              modelNumber="231412411241",
                              modelUrl="draeger.com/testMOdel",
                              presentationUrl="draeger.com/testMOdel")
        device = DPWSThisDevice(friendlyName="SuperDevice",
                                firmwareVersion="v1.23",
                                serialNumber="MISAD31245124")

        self._publishingDevice = SdcDevice(self.wsdiscovery, uuid.uuid1(),
                                           model, device, mdib)
        # commLogger = commlog.CommLogger(log_folder="testcomm",
        #                                 log_out=True,
        #                                 log_in=False,
        #                                 broadcastIpFilter=None)
        # commlog.defaultLogger = commLogger

        self._publishingDevice.startAll()
        loca = SdcLocation(fac='Noneas', poc='CU1', bed='cocoDraft6Bed')
        self._publishingDevice.setLocation(loca, [])
        player.play(self._publishingDevice, loop=True)
        time.sleep(40)
        player.stop()
Exemple #15
0
    def test_AbstractContextStateContainer(self):
        def verifyEqual(origin, copied):
            self.assertEqual(copied.ContextAssociation,
                             origin.ContextAssociation)
            self.assertEqual(copied.BindingMdibVersion,
                             origin.BindingMdibVersion)
            self.assertEqual(copied.UnbindingMdibVersion,
                             origin.UnbindingMdibVersion)
            self.assertEqual(copied.BindingStartTime, origin.BindingStartTime)
            self.assertEqual(copied.BindingEndTime, origin.BindingEndTime)
            self.assertEqual(copied.Validator, origin.Validator)
            self.assertEqual(copied.Identification, origin.Identification)
            self._verifyAbstractStateContainerDataEqual(copied, origin)

        sc = statecontainers.AbstractContextStateContainer(
            nsmapper=self.nsmapper, descriptorContainer=self.dc, node=None)
        self.assertEqual(sc.ContextAssociation, 'No')
        self.assertEqual(sc.BindingMdibVersion, None)
        self.assertEqual(sc.UnbindingMdibVersion, None)
        self.assertEqual(sc.BindingStartTime, None)
        self.assertEqual(sc.BindingEndTime, None)
        self.assertEqual(sc.Validator, [])
        self.assertEqual(sc.Identification, [])

        idents = [
            pmtypes.InstanceIdentifier(
                root='abc',
                type_codedValue=pmtypes.CodedValue('abc', 'def'),
                identifierNames=[pmtypes.LocalizedText('ABC')],
                extensionString='123')
        ]
        sc.Identification = idents
        self.assertEqual(sc.Identification, idents)

        validators = [
            pmtypes.InstanceIdentifier(
                root='ABC',
                type_codedValue=pmtypes.CodedValue('123', '456'),
                identifierNames=[pmtypes.LocalizedText('DEF')],
                extensionString='321')
        ]
        sc.Validator = validators
        self.assertEqual(sc.Validator, validators)

        for value in ('assoc', 'disassoc'):
            sc.ContextAssociation = value
            node = sc.mkStateNode()
            self.assertEqual(node.get('ContextAssociation'), value)

        for value in (12345.123, 67890.987):
            sc.BindingStartTime = value
            sc.BindingEndTime = value + 1
            node = sc.mkStateNode()
            self.assertEqual(
                node.get('BindingStartTime'),
                containerproperties.TimestampConverter.toXML(value))
            self.assertEqual(
                node.get('BindingEndTime'),
                containerproperties.TimestampConverter.toXML(value + 1))

        for value in (0, 42, 123):
            sc.BindingMdibVersion = value
            sc.UnbindingMdibVersion = value + 1
            node = sc.mkStateNode()
            self.assertEqual(node.get('BindingMdibVersion'),
                             containerproperties.IntegerConverter.toXML(value))
            self.assertEqual(
                node.get('UnbindingMdibVersion'),
                containerproperties.IntegerConverter.toXML(value + 1))

        node = etree_.Element(namespaces.domTag('State'),
                              attrib={
                                  'StateVersion': '2',
                                  'DescriptorHandle': '123',
                                  'BindingStartTime': '1234567',
                                  'BindingEndTime': '2345678',
                                  'Handle': sc.Handle
                              })
        sc.updateFromNode(node)
        self.assertEqual(sc.BindingStartTime, 1234.567)
        self.assertEqual(sc.BindingEndTime, 2345.678)
        self.assertEqual(sc.node.get('BindingStartTime'), '1234567')
        self.assertEqual(sc.node.get('BindingEndTime'), '2345678')
        self.assertEqual(sc.Identification, [])
        self.assertEqual(sc.Validator, [])

        #test creation from node
        sc.Identification = idents
        sc.Validator = validators
        node = sc.mkStateNode()
        sc2 = statecontainers.AbstractContextStateContainer(
            nsmapper=self.nsmapper, descriptorContainer=self.dc, node=node)
        verifyEqual(sc, sc2)
Exemple #16
0
            ca_folder,
            cyphers_file='device_cyphers.txt',
            ssl_passwd=ssl_passwd)
    else:
        ssl_context = None
    sdcDevice = sdc11073.sdcdevice.sdcdeviceimpl.SdcDevice(
        wsd, my_uuid, dpwsModel, dpwsDevice, my_mdib, sslContext=ssl_context)
    sdcDevice.startAll()

    validators = [
        sdc11073.pmtypes.InstanceIdentifier('Validator',
                                            extensionString='System')
    ]
    sdcDevice.setLocation(loc, validators)
    patientDescriptorHandle = my_mdib.descriptions.nodeName.get(
        domTag('PatientContext'))[0].handle
    with my_mdib.mdibUpdateTransaction() as mgr:
        patientContainer = mgr.getContextState(patientDescriptorHandle)
        patientContainer.Givenname = "Given"
        patientContainer.Middlename = "Middle"
        patientContainer.Familyname = "Familiy"
        patientContainer.Birthname = "Birthname"
        patientContainer.Title = "Title"
        patientContainer.ContextAssociation = "Assoc"
        identifiers = []
        patientContainer.Identification = identifiers

    descs = list(sdcDevice.mdib.descriptions.objects)
    descs.sort(key=lambda x: x.handle)
    metric = None
    alertCondition = None
Exemple #17
0
 def _removeMdsDescriptor(self):
     handle = self._device.mdib.descriptions.NODETYPE.getOne(
         domTag('MdsDescriptor')).handle  #node.attrib['Handle']
     with self._device.mdib.mdibUpdateTransaction() as mgr:
         mgr.removeDescriptor(handle)
Exemple #18
0
                             firmwareVersion='Version1',
                             serialNumber='12345')
 # create a device (provider) class that will do all the SDC magic
 sdcDevice = SdcDevice(ws_discovery=myDiscovery,
                       my_uuid=my_uuid,
                       model=dpwsModel,
                       device=dpwsDevice,
                       deviceMdibContainer=my_mdib)
 # start the local device and make it discoverable
 sdcDevice.startAll()
 # set the local ensemble context to ease discovery based on ensemble ID
 setLocalEnsembleContext(my_mdib, "MyEnsemble")
 # set the location on our device
 sdcDevice.setLocation(my_location)
 # create one local numeric metric that will change later on
 numMetrDescr = domTag("NumericMetricDescriptor")
 # get all metrics from the mdib (as described in the file)
 allMetricDescrs = [
     c for c in my_mdib.descriptions.objects if c.NODETYPE == numMetrDescr
 ]
 # now change all the metrics in one transaction
 with my_mdib.mdibUpdateTransaction() as mgr:
     for metricDescr in allMetricDescrs:
         # get the metric state of this specific metric
         st = mgr.getMetricState(metricDescr.handle)
         # create a value in case it is not there yet
         st.mkMetricValue()
         # set the value and some other fields to a fixed value
         st.metricValue.Value = 1.0
         st.metricValue.ActiveDeterminationPeriod = "1494554822450"
         st.metricValue.Validity = 'Vld'