def test_Callback12(self):
        """[ GenApiTest@CallbackTestSuite_TestCallback12.xml|gxml
    
        <Category Name="Event">
          <pFeature>Node</pFeature>
        </Category>
    
        <Integer Name="Node">
          <Value>1</Value>
        </Integer>
    
        """

        Camera = CNodeMapRef()
        Camera._LoadXMLFromFile("GenApiTest",
                                "CallbackTestSuite_TestCallback12")

        Node = Camera.GetNode("Node")

        cbEvent = CallbackObject()
        Register(Node.GetNode(), cbEvent.Callback)

        self.assertEqual(0, cbEvent.Count())
        Node.SetValue(0)
        self.assertEqual(1, cbEvent.Count())
Beispiel #2
0
    def test_Command04(self):
        """[ GenApiTest@CommandTestSuite_TestCommand04.xml|gxml
    
        <Command Name="Command">
            <ImposedAccessMode>WO</ImposedAccessMode>
            <pValue>Value</pValue>
            <pCommandValue>CommandValue</pCommandValue>
        </Command>
    
        <Integer Name="CommandValue">
            <Value>42</Value>
        </Integer>
    
        <Integer Name="Value">
            <Value>0</Value>
        </Integer>
    
        """

        Camera = CNodeMapRef()
        Camera._LoadXMLFromFile("GenApiTest", "CommandTestSuite_TestCommand04")

        Command = Camera.GetNode("Command")
        self.assertTrue(bool(Command))

        Value = Camera.GetNode("Value")
        self.assertTrue(bool(Value))

        CommandValue = Camera.GetNode("CommandValue")
        self.assertTrue(bool(CommandValue))

        CallbackTarget = CallbackObject()
        Register(Command.GetNode(), CallbackTarget.Callback)

        # due to the execute a callback is fired
        Command.Execute()
        self.assertEqual(1, CallbackTarget.Count())

        # since the command node is WO IsDone does not trigger a callback
        self.assertEqual(True, Command.IsDone())
        self.assertEqual(1, CallbackTarget.Count())
    def test_Callback04(self):
        """[ GenApiTest@CallbackTestSuite_TestCallback04.xml|gxml
    
        <Command Name="MyCommand">
          <Value>0</Value>
          <CommandValue>0xff</CommandValue>
        </Command>
    
        """

        Camera = CNodeMapRef()
        Camera._LoadXMLFromFile("GenApiTest",
                                "CallbackTestSuite_TestCallback04")

        O1 = CallbackObject()
        O2 = CallbackObject()

        Cmd = Camera.GetNode("MyCommand")

        Register(Cmd.GetNode(), CallbackUtility.Callback)
        Register(Cmd.GetNode(), O1.Callback)
        Register(Cmd.GetNode(), O2.Callback)

        numCalls = 42
        CallbackUtility.Reset()

        for i in range(0, numCalls):
            Cmd.Execute()

        self.assertEqual(numCalls, CallbackUtility.Count())
        self.assertEqual(numCalls, O1.Count())
        self.assertEqual(numCalls, O2.Count())
    def test_Callback03(self):
        """[ GenApiTest@CallbackTestSuite_TestCallback03.xml|gxml
    
        <Boolean Name="MyBoolean">
          <Value>true</Value>
        </Boolean>
    
        """

        Camera = CNodeMapRef()
        Camera._LoadXMLFromFile("GenApiTest",
                                "CallbackTestSuite_TestCallback03")

        O1 = CallbackObject()
        O2 = CallbackObject()

        Bool = Camera.GetNode("MyBoolean")

        Register(Bool.GetNode(), CallbackUtility.Callback)
        Register(Bool.GetNode(), O1.Callback)
        Register(Bool.GetNode(), O2.Callback)

        numCalls = 42
        CallbackUtility.Reset()

        for i in range(0, numCalls):
            Bool.SetValue(i & 0x1)

        self.assertEqual(numCalls, CallbackUtility.Count())
        self.assertEqual(numCalls, O1.Count())
        self.assertEqual(numCalls, O2.Count())
Beispiel #5
0
    def test_Polling_Integer(self):
        """[ GenApiTest@PollTestSuite_TestPolling_Integer.xml|gxml
    
        <Integer Name="Value">
           <pValue>Register</pValue>
        </Integer>
    
        <IntReg Name="Register">
            <Address>0x0f00</Address>
            <Length>4</Length>
            <AccessMode>RW</AccessMode>
            <pPort>Port</pPort>
            <PollingTime>1000</PollingTime>
            <Sign>Unsigned</Sign>
            <Endianess>LittleEndian</Endianess>
        </IntReg>
    
        <Port Name="Port"/>
    
        """

        Camera = CNodeMapRef()
        Camera._LoadXMLFromFile("GenApiTest", "PollTestSuite_TestPolling_Integer")
        Node = Camera.GetNode("Register")

        self.assertEqual(1000, Node.Node.GetPollingTime())

        Value = Camera.GetNode("Value")

        self.assertEqual(-1, Value.Node.GetPollingTime())

        CallBackTarget = CallbackObject()
        Register(Node.Node, CallBackTarget.Callback)
        Register(Value.Node, CallBackTarget.Callback)

        Camera._Poll(500)
        self.assertEqual(0, CallBackTarget.Count())

        Camera._Poll(500)
        self.assertEqual(2, CallBackTarget.Count())
Beispiel #6
0
    def test_Command03(self):
        """[ GenApiTest@CommandTestSuite_TestCommand03.xml|gxml
    
        <Command Name="Command">
            <pValue>Value</pValue>
            <pCommandValue>CommandValue</pCommandValue>
        </Command>
    
        <Integer Name="CommandValue">
            <Value>42</Value>
        </Integer>
    
        <Integer Name="Value">
            <Value>0</Value>
        </Integer>
    
        """

        Camera = CNodeMapRef()
        Camera._LoadXMLFromFile("GenApiTest", "CommandTestSuite_TestCommand03")

        Command = Camera.GetNode("Command")
        self.assertTrue(bool(Command))

        Value = Camera.GetNode("Value")
        self.assertTrue(bool(Value))

        CommandValue = Camera.GetNode("CommandValue")
        self.assertTrue(bool(CommandValue))

        CallbackTarget = CallbackObject()
        Register(Command.GetNode(), CallbackTarget.Callback)

        # nothing happened so no callback expected
        self.assertEqual(True, Command.IsDone())
        self.assertEqual(0, CallbackTarget.Count())

        # a first callback happens after execute
        Command.Execute()
        self.assertEqual(1, CallbackTarget.Count())

        for count in range(10, 0):
            # no callback on IsDone because the value has not changed yet
            self.assertEqual(False, Command.IsDone())
            # self.assertEqual( (int64_t)42, ptrValue.GetValue() )
            # self.assertEqual( 1, CallbackTarget.Count() )

        # now the value has changed so we expect a callback
        Value.SetValue(0)
        self.assertEqual(2, CallbackTarget.Count())

        # On IsDone the Command node notives that the vale has changed and fires another time
        self.assertEqual(True, Command.IsDone())
        self.assertEqual(3, CallbackTarget.Count())
    def test_Callback02(self):
        # create and initialize node map
        """[ GenApiTest@CallbackTestSuite_TestCallback02.xml|gxml
    
        <Float Name="MyFloat">
          <Value>0.0</Value>
          <Min>0.0</Min>
          <Max>100.0</Max>
          <Unit>dB</Unit>
        </Float>
    
        """

        Camera = CNodeMapRef()
        Camera._LoadXMLFromFile("GenApiTest",
                                "CallbackTestSuite_TestCallback02")

        Float01 = Camera.GetNode("MyFloat")

        O1 = CallbackObject()
        O2 = CallbackObject()

        hCbk1 = Register(Float01.GetNode(), O1.Callback)
        hCbk2 = Register(Float01.GetNode(), O2.Callback)

        numCalls = 42
        for i in range(0, numCalls):
            Float01.SetValue(i)

        self.assertEqual(numCalls, O1.Count())
        self.assertEqual(numCalls, O2.Count())

        # de-register callback
        Deregister(hCbk1)
        self.assertFalse(Float01.GetNode().DeregisterCallback(hCbk1))

        Float01.SetValue(33)
        self.assertEqual(numCalls, O1.Count())
        self.assertEqual(numCalls + 1, O2.Count())

        # deregister invalid callback handle
        self.assertFalse(Float01.GetNode().DeregisterCallback(9999))
    def test_Callback13(self):
        # create and initialize node map
        """[ GenApiTest@CallbackTestSuite_TestCallback13.xml|gxml
    
        <Integer Name="Node">
          <Value>1</Value>
        </Integer>
    
        """

        Camera = CNodeMapRef()
        Camera._LoadXMLFromFile("GenApiTest",
                                "CallbackTestSuite_TestCallback13")

        Node = Camera.GetNode("Node")

        cbEvent = CallbackObject()
        Register(Node.GetNode(), self.Callback13_inside, cbPostInsideLock)
        Register(Node.GetNode(), self.Callback13_outside, cbPostOutsideLock)

        Node.SetValue(0)
    def test_Callback05(self):
        """[ GenApiTest@CallbackTestSuite_TestCallback05.xml|gxml
    
        <Enumeration Name="MyFood">
          <EnumEntry Name="Orange" >
            <Value>0</Value>
          </EnumEntry>
          <EnumEntry Name="Apple" >
            <Value>1</Value>
          </EnumEntry>
          <EnumEntry Name="Pretzel" >
            <Value>2</Value>
          </EnumEntry>
          <EnumEntry Name="Juice" >
            <Value>3</Value>
          </EnumEntry>
          <Value>0</Value>
        </Enumeration>
    
        """

        Camera = CNodeMapRef()
        Camera._LoadXMLFromFile("GenApiTest",
                                "CallbackTestSuite_TestCallback05")

        O1 = CallbackObject()
        O2 = CallbackObject()

        Enum = Camera.GetNode("MyFood")

        Register(Enum.GetNode(), CallbackUtility.Callback)
        Register(Enum.GetNode(), O1.Callback)
        Register(Enum.GetNode(), O2.Callback)

        numCalls = 42
        CallbackUtility.Reset()

        for i in range(0, numCalls):
            Enum.SetIntValue(i & 0x3)

        self.assertEqual(numCalls, CallbackUtility.Count())
        self.assertEqual(numCalls, O1.Count())
        self.assertEqual(numCalls, O2.Count())
Beispiel #10
0
    def test_Polling_Register(self):
        """[ GenApiTest@PollTestSuite_TestPolling_Register.xml|gxml
    
        <Register Name="Register">
            <Address>0x0f00</Address>
            <Length>4</Length>
            <AccessMode>RW</AccessMode>
            <pPort>Port</pPort>
            <PollingTime>1000</PollingTime>
        </Register>
    
        <Port Name="Port"/>
    
        """

        Camera = CNodeMapRef()
        Camera._LoadXMLFromFile("GenApiTest", "PollTestSuite_TestPolling_Register")

        Node = Camera.GetNode("Register")

        self.assertEqual(1000, Node.Node.GetPollingTime())

        CallBackTarget = CallbackObject()
        Register(Node.Node, CallBackTarget.Callback)

        Camera._Poll(500)
        self.assertEqual(0, CallBackTarget.Count())

        Camera._Poll(500)
        self.assertEqual(1, CallBackTarget.Count())

        Camera._Poll(500)
        self.assertEqual(1, CallBackTarget.Count())

        Camera._Poll(500)
        self.assertEqual(2, CallBackTarget.Count())
    def test_Callback09(self):
        class CMyTestPort(CTestPort):
            m_Enable = False

            def EnableAdvFeature(self, enable):
                m_Enable = enable

            def Write(self, Buffer, Address, Length):
                if (Address >= 0 and Address < 8):
                    pass
                else:
                    super(CTestPort, self).Write(Buffer, Address, Length)

            def Read(self, Buffer, Address, Length):
                if (Address >= 0 and Address < 8):
                    pass
                else:
                    super(CTestPort, self).Read(Buffer, Address, Length)

        """[ GenApiTest@CallbackTestSuite_TestCallback09.xml|gxml
    
        <StructReg Comment="Fancy Feature" >
    
          <pIsAvailable>B</pIsAvailable>
          <pAddress>B</pAddress>
          <Length>4</Length>
          <AccessMode>RW</AccessMode>
          <pPort>MyPort</pPort>
          <Endianess>LittleEndian</Endianess>
    
        <!--  bool meaning Feature Available -->
          <StructEntry Name="A">
            <AccessMode>RO</AccessMode>
            <Bit>0</Bit>
          </StructEntry>
    
        <!--  Value 1 -->
          <StructEntry Name="C" >
            <pIsAvailable>A</pIsAvailable>
            <LSB>8</LSB>
            <MSB>15</MSB>
          </StructEntry>
    
        <!--  Value 2 -->
          <StructEntry Name="D" >
            <pIsAvailable>A</pIsAvailable>
            <LSB>16</LSB>
            <MSB>23</MSB>
          </StructEntry>
    
        </StructReg>
    
        <!--  Base-Address of Fancy -->
        <SmartFeature Name="B">
          <FeatureID>A014EDBC-6768-4bcb-B039-9070961F2843</FeatureID>
          <Address>8</Address>
          <pPort>MyPort</pPort>
          <pIsAvailable>F</pIsAvailable>
        </SmartFeature>
    
        <!--  DCAM-like lock -->
        <AdvFeatureLock Name="F">
          <Address>0</Address>
          <Length>8</Length>
          <AccessMode>RW</AccessMode>
          <pPort>MyPort</pPort>
          <FeatureID>0x0030533B73C3</FeatureID>
          <Timeout>0</Timeout>
        </AdvFeatureLock>
    
        <Port Name="MyPort" />
    
        """

        Camera = CNodeMapRef()
        Camera._LoadXMLFromFile("GenApiTest",
                                "CallbackTestSuite_TestCallback09")

        # create and initialize a test port
        Port = CMyTestPort()
        # int8_t sfvalue[24]
        # all bits set => feature is not available
        # for(uint32_t i=0 i < sizeof(sfvalue) i++) {
        #    sfvalue[i] = (int8_t)0xFF
        # }
        Port.CreateEntry(0x000, "uint32_t", -1, RW, LittleEndian)
        Port.CreateEntry(0x004, "uint32_t", -1, RW, LittleEndian)
        Port.CreateEntry(0x008, "raw", 24, sfvalue, RW)
        Port.CreateEntry(0x020, "uint32_t", -1, RW, LittleEndian)

        # connect the node map to the port
        Camera._Connect(Port, "MyPort")

        cbA, cbB, cbC, cbD, cbE, cbF, cbG = [
            CallbackObject() for i in range(7)
        ]

        A = Camera.GetNode("A")
        B = Camera.GetNode("B")
        C = Camera.GetNode("C")
        D = Camera.GetNode("D")
        F = Camera.GetNode("F")

        # Register( A.GetNode(), cbA.Callback )
        # Register( B.GetNode(), cbB.Callback )
        # Register( C.GetNode(), cbC.Callback )
        # Register( D.GetNode(), cbD.Callback )
        # Register( F.GetNode(), cbF.Callback )

        self.assertEqual(RO, F.GetAccessMode())
        self.assertEqual(NA, B.GetAccessMode())
        self.assertEqual(NA, A.GetAccessMode())
        self.assertEqual(NA, C.GetAccessMode())
        self.assertEqual(NA, D.GetAccessMode())

        # enable advanced feature and set address 0x20in quad 5
        Port.EnableAdvFeature(True)
        # for(uint32_t i=0 i < sizeof(sfvalue) i++) {
        #    sfvalue[i] = 0
        # }
        # sfvalue[19] |= (1 << 5)
        # Port.Write( &sfvalue, 0x8, 24 )
        F.GetNode().InvalidateNode()  # invalidate advanced feature lock F
        B.GetNode().InvalidateNode()  # invalidate smart feature B
        # cbA.Reset(), cbB.Reset(), cbC.Reset(), cbD.Reset(), cbE.Reset(), cbF.Reset()

        self.assertEqual(RO, B.GetAccessMode())
        self.assertEqual(RO, A.GetAccessMode())
        self.assertEqual(RW, C.GetAccessMode())
        self.assertEqual(RW, D.GetAccessMode())

        # no callbacks although B and F write implicitly
        numCalls = 0
        # self.assertEqual( numCalls, cbA.Count() )
        # self.assertEqual( numCalls, cbB.Count() )
        # self.assertEqual( numCalls, cbC.Count() )
        # self.assertEqual( numCalls, cbD.Count() )
        # self.assertEqual( numCalls, cbF.Count() )

        # Set feature C => no callbacks but C itself
        C.SetValue(0)
        numCalls = 0
        # self.assertEqual( numCalls, cbA.Count() )
        # self.assertEqual( numCalls, cbB.Count() )
        # self.assertEqual( numCalls, cbD.Count() )
        # self.assertEqual( numCalls, cbF.Count() )
        numCalls = 1
        # self.assertEqual( numCalls, cbC.Count() )
        # cbC.Reset()

        # Set feature D => no callbacks but D itself
        D.SetValue(0)
        numCalls = 0
        # self.assertEqual( numCalls, cbA.Count() )
        # self.assertEqual( numCalls, cbB.Count() )
        # self.assertEqual( numCalls, cbC.Count() )
        # self.assertEqual( numCalls, cbF.Count() )
        numCalls = 1
    def test_Callback08(self):
        """[ GenApiTest@CallbackTestSuite_TestCallback08.xml|gxml
    
        <Integer Name="A">
          <pValue>D</pValue>
        </Integer>
    
        <Integer Name="B">
          <pValue>F</pValue>
        </Integer>
    
        <Float Name="C">
          <Value>3.141</Value>
        </Float>
    
        <MaskedIntReg Name="D" >
          <Address>0x0</Address>
          <Length>8</Length>
          <AccessMode>RW</AccessMode>
          <pPort>MyPort</pPort>
          <pInvalidator>E</pInvalidator>
          <LSB>15</LSB>
          <MSB>8</MSB>
          <Sign>Unsigned</Sign>
          <Endianess>BigEndian</Endianess>
          <pSelected>F</pSelected>
        </MaskedIntReg>
    
        <IntReg Name="E">
          <Address>0x0</Address>
          <Length>8</Length>
          <AccessMode>RW</AccessMode>
          <pPort>MyPort</pPort>
          <pInvalidator>D</pInvalidator>
          <Sign>Unsigned</Sign>
          <Endianess>BigEndian</Endianess>
        </IntReg>
    
        <IntReg Name="F">
          <Address>0x8</Address>
          <Length>4</Length>
          <AccessMode>RW</AccessMode>
          <pPort>MyPort</pPort>
          <Sign>Unsigned</Sign>
          <Endianess>BigEndian</Endianess>
        </IntReg>
    
        <IntReg Name="G">
          <Address>0xC</Address>
          <Length>4</Length>
          <AccessMode>RW</AccessMode>
          <pPort>MyPort</pPort>
          <pInvalidator>E</pInvalidator>
          <Sign>Unsigned</Sign>
          <Endianess>BigEndian</Endianess>
        </IntReg>
    
        <Port Name="MyPort" />
    
        """

        Camera = CNodeMapRef()
        Camera._LoadXMLFromFile("GenApiTest",
                                "CallbackTestSuite_TestCallback08")

        # create and initialize a test port
        Port = CTestPort()
        Port.CreateEntry(0, "uint64_t", 42, RW, BigEndian)
        Port.CreateEntry(8, "uint32_t", 10, RW, BigEndian)
        Port.CreateEntry(12, "uint32_t", 20, RW, BigEndian)
        Port.CreateEntry(16, "uint32_t", 40, RW, BigEndian)
        Port.CreateEntry(20, "uint32_t", 50, RW, BigEndian)
        Port.CreateEntry(24, "uint32_t", 60, RW, BigEndian)

        # connect the node map to the port
        Camera._Connect(Port, "MyPort")

        cbA, cbB, cbC, cbD, cbE, cbF, cbG = [
            CallbackObject() for i in range(7)
        ]

        A = Camera.GetNode("A")
        B = Camera.GetNode("B")
        C = Camera.GetNode("C")
        D = Camera.GetNode("D")
        E = Camera.GetNode("E")
        F = Camera.GetNode("F")
        G = Camera.GetNode("G")

        Register(A.GetNode(), cbA.Callback)
        Register(B.GetNode(), cbB.Callback)
        Register(C.GetNode(), cbC.Callback)
        Register(D.GetNode(), cbD.Callback)
        Register(E.GetNode(), cbE.Callback)
        Register(F.GetNode(), cbF.Callback)
        Register(G.GetNode(), cbG.Callback)

        # set A => cb of A, B, D, E F, G not C
        numCalls = 1
        cbA.Reset()
        cbA.Reset()
        cbB.Reset()
        cbC.Reset()
        cbD.Reset()
        cbE.Reset()
        cbF.Reset()
        cbG.Reset()
        A.SetValue(0)
        self.assertEqual(numCalls, cbA.Count())
        self.assertEqual(numCalls, cbB.Count())
        self.assertEqual(numCalls, cbD.Count())
        self.assertEqual(numCalls, cbE.Count())
        self.assertEqual(numCalls, cbF.Count())
        self.assertEqual(numCalls, cbG.Count())
        numCalls = 0
        self.assertEqual(numCalls, cbC.Count())
        # set B => cb of B, F not A, C, D, E, G
        numCalls = 1
        cbA.Reset()
        cbA.Reset()
        cbB.Reset()
        cbC.Reset()
        cbD.Reset()
        cbE.Reset()
        cbF.Reset()
        cbG.Reset()
        B.SetValue(0)
        self.assertEqual(numCalls, cbB.Count())
        self.assertEqual(numCalls, cbB.Count())
        numCalls = 0
        self.assertEqual(numCalls, cbA.Count())
        self.assertEqual(numCalls, cbC.Count())
        self.assertEqual(numCalls, cbD.Count())
        self.assertEqual(numCalls, cbE.Count())
        self.assertEqual(numCalls, cbG.Count())

        # set C => no cb
        numCalls = 1
        cbA.Reset()
        cbA.Reset()
        cbB.Reset()
        cbC.Reset()
        cbD.Reset()
        cbE.Reset()
        cbF.Reset()
        cbG.Reset()
        C.SetValue(0)
        self.assertEqual(numCalls, cbC.Count())
        numCalls = 0
        self.assertEqual(numCalls, cbA.Count())
        self.assertEqual(numCalls, cbB.Count())
        self.assertEqual(numCalls, cbD.Count())
        self.assertEqual(numCalls, cbE.Count())
        self.assertEqual(numCalls, cbF.Count())
        self.assertEqual(numCalls, cbG.Count())

        # set D => cb of A, B, D, F, E, G, C
        numCalls = 1
        cbA.Reset()
        cbA.Reset()
        cbB.Reset()
        cbC.Reset()
        cbD.Reset()
        cbE.Reset()
        cbF.Reset()
        cbG.Reset()
        D.SetValue(0)
        self.assertEqual(numCalls, cbA.Count())
        self.assertEqual(numCalls, cbB.Count())
        self.assertEqual(numCalls, cbD.Count())
        self.assertEqual(numCalls, cbE.Count())
        self.assertEqual(numCalls, cbF.Count())
        self.assertEqual(numCalls, cbG.Count())
        numCalls = 0
        self.assertEqual(numCalls, cbC.Count())

        # set E => cb of A, B, D, F, E, G, C
        numCalls = 1
        cbA.Reset()
        cbA.Reset()
        cbB.Reset()
        cbC.Reset()
        cbD.Reset()
        cbE.Reset()
        cbF.Reset()
        cbG.Reset()
        E.SetValue(0)
        self.assertEqual(numCalls, cbA.Count())
        self.assertEqual(numCalls, cbB.Count())
        self.assertEqual(numCalls, cbD.Count())
        self.assertEqual(numCalls, cbE.Count())
        self.assertEqual(numCalls, cbF.Count())
        self.assertEqual(numCalls, cbG.Count())
        numCalls = 0
        self.assertEqual(numCalls, cbC.Count())

        # set F => cb of B, F not of A, B, C, D, E,
        numCalls = 1
        cbA.Reset()
        cbA.Reset()
        cbB.Reset()
        cbC.Reset()
        cbD.Reset()
        cbE.Reset()
        cbF.Reset()
        cbG.Reset()
        F.SetValue(0)
        self.assertEqual(numCalls, cbB.Count())
        self.assertEqual(numCalls, cbF.Count())
        numCalls = 0
        self.assertEqual(numCalls, cbA.Count())
        self.assertEqual(numCalls, cbC.Count())
        self.assertEqual(numCalls, cbD.Count())
        self.assertEqual(numCalls, cbE.Count())
        self.assertEqual(numCalls, cbG.Count())

        # set G => cb of G not of A, B, C, D, E, F
        numCalls = 1
        cbA.Reset()
        cbA.Reset()
        cbB.Reset()
        cbC.Reset()
        cbD.Reset()
        cbE.Reset()
        cbF.Reset()
        cbG.Reset()
        G.SetValue(0)
        self.assertEqual(numCalls, cbG.Count())
        numCalls = 0
        self.assertEqual(numCalls, cbA.Count())
        self.assertEqual(numCalls, cbB.Count())
        self.assertEqual(numCalls, cbC.Count())
        self.assertEqual(numCalls, cbD.Count())
        self.assertEqual(numCalls, cbE.Count())
        self.assertEqual(numCalls, cbF.Count())
    def test_Callback07(self):
        """[ GenApiTest@CallbackTestSuite_TestCallback07.xml|gxml
    
        <Enumeration Name="MyFood">
          <EnumEntry Name="Orange" >
            <Value>0</Value>
          </EnumEntry>
          <EnumEntry Name="Apple" >
            <Value>1</Value>
          </EnumEntry>
          <EnumEntry Name="Pretzel" >
            <Value>2</Value>
          </EnumEntry>
          <EnumEntry Name="Juice" >
            <Value>3</Value>
          </EnumEntry>
          <pValue>curFood</pValue>
          <pSelected>curDishPrice</pSelected>
          <pSelected>GrandTotal</pSelected>
        </Enumeration>
    
        <Integer Name="Price">
          <pValue>GrandTotal</pValue>
        </Integer>
    
        <Integer Name="NumPersons">
          <Value>5</Value>
        </Integer>
    
        <IntReg Name="curFood">
          <Address>0</Address>
          <Length>8</Length>
          <AccessMode>RW</AccessMode>
          <pPort>MyPort</pPort>
          <Sign>Unsigned</Sign>
          <Endianess>BigEndian</Endianess>
        </IntReg>
    
        <IntReg Name="curDishPrice">
          <Address>8</Address>
          <pAddress>curFood</pAddress>
          <Length>4</Length>
          <AccessMode>RW</AccessMode>
          <pPort>MyPort</pPort>
          <Sign>Unsigned</Sign>
          <Endianess>BigEndian</Endianess>
        </IntReg>
    
        <IntSwissKnife Name="GrandTotal">
          <pVariable Name="N">NumPersons</pVariable>
          <pVariable Name="P">curDishPrice</pVariable>
          <Formula>N*P</Formula>
        </IntSwissKnife>
    
        <Port Name="MyPort" />
    
        """

        Camera = CNodeMapRef()
        Camera._LoadXMLFromFile("GenApiTest",
                                "CallbackTestSuite_TestCallback07")

        # create and initialize a test port
        Port = CTestPort()
        Port.CreateEntry(0, "uint64_t", 42, RW, BigEndian)
        Port.CreateEntry(8, "uint32_t", 10, RW, BigEndian)
        Port.CreateEntry(12, "uint32_t", 20, RW, BigEndian)
        Port.CreateEntry(16, "uint32_t", 40, RW, BigEndian)
        Port.CreateEntry(20, "uint32_t", 50, RW, BigEndian)
        Port.CreateEntry(24, "uint32_t", 60, RW, BigEndian)

        # connect the node map to the port
        Camera._Connect(Port, "MyPort")
        cbPrice, cbFood, cbPerson = [CallbackObject() for i in range(3)]

        Enum = Camera.GetNode("MyFood")

        Food = Camera.GetNode("curFood")

        Price = Camera.GetNode("Price")

        DishPrice = Camera.GetNode("curDishPrice")

        NumPersons = Camera.GetNode("NumPersons")

        Register(Enum.GetNode(), cbFood.Callback)
        Register(Price.GetNode(), cbPrice.Callback)
        Register(NumPersons.GetNode(), cbPerson.Callback)

        numCalls = 1

        # change the number of persons . Price changes, food not
        cbFood.Reset()
        cbPrice.Reset()
        cbPerson.Reset()
        NumPersons.SetValue(2)
        numCalls = 0
        self.assertEqual(numCalls, cbFood.Count())
        numCalls = 1
        self.assertEqual(numCalls, cbPrice.Count())
        self.assertEqual(numCalls, cbPerson.Count())

        # change the food . Price changes, number of persons not
        cbFood.Reset()
        cbPrice.Reset()
        cbPerson.Reset()
        Food.SetValue(2)
        numCalls = 0
        self.assertEqual(numCalls, cbPerson.Count())
        numCalls = 1
        self.assertEqual(numCalls, cbFood.Count())
        self.assertEqual(numCalls, cbPrice.Count())

        # change the dish price . Price changes, number of persons and food not
        Food.SetValue(0)  # otherwise 'DishPrice's address is incorrect
        cbFood.Reset()
        cbPrice.Reset()
        cbPerson.Reset()
        DishPrice.SetValue(2)
        numCalls = 0
        self.assertEqual(numCalls, cbPerson.Count())
        self.assertEqual(numCalls, cbFood.Count())
        numCalls = 1
        self.assertEqual(numCalls, cbPrice.Count())
    def _TestCallback10(self, Camera):

        # create and initialize a test port
        Port = CTestPort()
        Port.CreateEntry(0x000, "uint32_t", 42, RW, LittleEndian)
        Port.CreateEntry(0x004, "uint32_t", 42, RW, LittleEndian)
        Port.CreateEntry(0x008, "uint32_t", 42, RW, LittleEndian)

        # connect the node map to the port
        Camera._Connect(Port, "MyPort")

        A = Camera.GetNode("A")
        B = Camera.GetNode("B")
        C = Camera.GetNode("C")
        D = Camera.GetNode("D")
        E = Camera.GetNode("E")
        MyPort = Camera.GetNode("MyPort")

        obA, obB, obC, obD, obE, obMyPort = [
            CallbackObject() for i in range(6)
        ]
        Register(A.Node, obA.Callback)
        Register(B.Node, obB.Callback)
        Register(C.Node, obC.Callback)
        Register(D.Node, obD.Callback)
        Register(E.Node, obE.Callback)
        Register(MyPort.Node, obMyPort.Callback)

        # Check number of callbacks triggered by SetValue
        # Use C und D first, because they serve as pMin and pMax for A
        for o in (obA, obB, obC, obD, obE, obMyPort):
            o.Reset()
        C.SetValue(0.0)

        self.assertEqual(1, obA.Count())
        self.assertEqual(0, obB.Count())
        self.assertEqual(1, obC.Count())
        self.assertEqual(0, obD.Count())
        self.assertEqual(0, obE.Count())
        self.assertEqual(0, obMyPort.Count())

        for o in (obA, obB, obC, obD, obE, obMyPort):
            o.Reset()
        D.SetValue(1.0)
        self.assertEqual(1, obA.Count())
        self.assertEqual(0, obB.Count())
        self.assertEqual(0, obC.Count())
        self.assertEqual(1, obD.Count())
        self.assertEqual(0, obE.Count())
        self.assertEqual(0, obMyPort.Count())

        for o in (obA, obB, obC, obD, obE, obMyPort):
            o.Reset()
        B.SetValue(1.0)
        self.assertEqual(1, obA.Count())
        self.assertEqual(1, obB.Count())
        self.assertEqual(0, obC.Count())
        self.assertEqual(0, obD.Count())
        self.assertEqual(0, obE.Count())
        self.assertEqual(0, obMyPort.Count())

        for o in (obA, obB, obC, obD, obE, obMyPort):
            o.Reset()
        A.SetValue(1.0)
        self.assertEqual(1, obA.Count())
        self.assertEqual(1, obB.Count())
        self.assertEqual(0, obC.Count())
        self.assertEqual(0, obD.Count())
        self.assertEqual(0, obE.Count())
        self.assertEqual(0, obMyPort.Count())

        for o in (obA, obB, obC, obD, obE, obMyPort):
            o.Reset()
        E.SetValue(1)
        self.assertEqual(1, obA.Count())
        self.assertEqual(1, obB.Count())
        self.assertEqual(1, obC.Count())
        self.assertEqual(1, obD.Count())
        self.assertEqual(1, obE.Count())
        self.assertEqual(0, obMyPort.Count())

        for o in (obA, obB, obC, obD, obE, obMyPort):
            o.Reset()
        A.Node.InvalidateNode()
        self.assertEqual(1, obA.Count())
        self.assertEqual(0, obB.Count())
        self.assertEqual(0, obC.Count())
        self.assertEqual(0, obD.Count())
        self.assertEqual(0, obE.Count())
        self.assertEqual(0, obMyPort.Count())

        for o in (obA, obB, obC, obD, obE, obMyPort):
            o.Reset()
        B.Node.InvalidateNode()
        self.assertEqual(1, obA.Count())
        self.assertEqual(1, obB.Count())
        self.assertEqual(0, obC.Count())
        self.assertEqual(0, obD.Count())
        self.assertEqual(0, obE.Count())
        self.assertEqual(0, obMyPort.Count())

        for o in (obA, obB, obC, obD, obE, obMyPort):
            o.Reset()
        C.Node.InvalidateNode()
        self.assertEqual(1, obA.Count())
        self.assertEqual(0, obB.Count())
        self.assertEqual(1, obC.Count())
        self.assertEqual(0, obD.Count())
        self.assertEqual(0, obE.Count())
        self.assertEqual(0, obMyPort.Count())

        for o in (obA, obB, obC, obD, obE, obMyPort):
            o.Reset()
        D.Node.InvalidateNode()
        self.assertEqual(1, obA.Count())
        self.assertEqual(0, obB.Count())
        self.assertEqual(0, obC.Count())
        self.assertEqual(1, obD.Count())
        self.assertEqual(0, obE.Count())
        self.assertEqual(0, obMyPort.Count())

        for o in (obA, obB, obC, obD, obE, obMyPort):
            o.Reset()
        E.Node.InvalidateNode()
        self.assertEqual(1, obA.Count())
        self.assertEqual(1, obB.Count())
        self.assertEqual(1, obC.Count())
        self.assertEqual(1, obD.Count())
        self.assertEqual(1, obE.Count())
        self.assertEqual(0, obMyPort.Count())

        for o in (obA, obB, obC, obD, obE, obMyPort):
            o.Reset()
        MyPort.Node.InvalidateNode()
        self.assertEqual(1, obA.Count())
        self.assertEqual(1, obB.Count())
        self.assertEqual(1, obC.Count())
        self.assertEqual(1, obD.Count())
        self.assertEqual(0, obE.Count())
        self.assertEqual(1, obMyPort.Count())

        for o in (obA, obB, obC, obD, obE, obMyPort):
            o.Reset()
        Camera._InvalidateNodes()
        self.assertEqual(1, obA.Count())
        self.assertEqual(1, obB.Count())
        self.assertEqual(1, obC.Count())
        self.assertEqual(1, obD.Count())
        self.assertEqual(1, obE.Count())
        self.assertEqual(1, obMyPort.Count())
Beispiel #15
0
    def test_Command05(self):
        """[ GenApiTest@CommandTestSuite_TestCommand05.xml|gxml
    
        <Command Name="Command">
            <pValue>Value</pValue>
            <pCommandValue>CommandValue</pCommandValue>
            <PollingTime>1000</PollingTime>
        </Command>
    
        <Integer Name="CommandValue">
            <Value>42</Value>
        </Integer>
    
        <Integer Name="Value">
            <Value>0</Value>
        </Integer>
    
        <Command Name="CommandWO">
            <ImposedAccessMode>WO</ImposedAccessMode>
            <pValue>Value</pValue>
            <pCommandValue>CommandValue</pCommandValue>
            <PollingTime>1000</PollingTime>
        </Command>
    
        <Command Name="Command_ValueWO">
            <pValue>ValueWO</pValue>
            <pCommandValue>CommandValue</pCommandValue>
            <PollingTime>1000</PollingTime>
        </Command>
    
        <Integer Name="ValueWO">
            <ImposedAccessMode>WO</ImposedAccessMode>
            <Value>0</Value>
        </Integer>
    
        """

        Camera = CNodeMapRef()
        Camera._LoadXMLFromFile("GenApiTest", "CommandTestSuite_TestCommand05")

        Command = Camera.GetNode("Command")
        self.assertTrue(bool(Command))

        Value = Camera.GetNode("Value")
        self.assertTrue(bool(Value))

        CommandValue = Camera.GetNode("CommandValue")
        self.assertTrue(bool(CommandValue))

        CallbackTarget = CallbackObject()
        Register(Command.GetNode(), CallbackTarget.Callback)

        Command.Execute()
        self.assertEqual(1, CallbackTarget.Count())
        self.assertEqual(False, Command.IsDone())

        Camera._Poll(500)
        self.assertEqual(1, CallbackTarget.Count())
        self.assertEqual(False, Command.IsDone())

        Camera._Poll(500)
        self.assertEqual(2, CallbackTarget.Count())
        self.assertEqual(False, Command.IsDone())

        # now the self-clearing flag is clearing
        Value.SetValue(0)
        # this is due to the fact that Command is dependent on value
        self.assertEqual(3, CallbackTarget.Count())

        Camera._Poll(1000)
        self.assertEqual(4, CallbackTarget.Count())
        self.assertEqual(True, Command.IsDone())

        # similar tests with WO node (done immediatelly, no polling)
        CommandWO = Camera.GetNode("CommandWO")
        self.assertTrue(bool(CommandWO))

        CallbackTargetWO = CallbackObject()
        Register(CommandWO.GetNode(), CallbackTargetWO.Callback)

        CommandWO.Execute()
        self.assertEqual(1, CallbackTargetWO.Count())
        self.assertEqual(True, CommandWO.IsDone())

        Camera._Poll(1000)
        self.assertEqual(1, CallbackTargetWO.Count())
        self.assertEqual(True, CommandWO.IsDone())

        # and again with command having a WO value
        Command_ValueWO = Camera.GetNode("Command_ValueWO")
        self.assertTrue(bool(Command_ValueWO))

        CallbackTarget_ValueWO = CallbackObject()
        Register(Command_ValueWO.GetNode(), CallbackTarget_ValueWO.Callback)

        Command_ValueWO.Execute()
        self.assertEqual(1, CallbackTarget_ValueWO.Count())
        self.assertEqual(True, Command_ValueWO.IsDone())

        Camera._Poll(1000)
        self.assertEqual(1, CallbackTarget_ValueWO.Count())
        self.assertEqual(True, Command_ValueWO.IsDone())