Example #1
0
    def testDownloadNext(self, mock_selector, mock_socket):
        ms = MockSocket()

        mock_socket.return_value.recv.side_effect = ms.recv
        mock_selector.return_value.select.side_effect = ms.select

        ms.push_frame([0x01, 0x00, 0x00, 0x00, 0xff])

        with Master(transport.Eth('localhost', loglevel="DEBUG")) as xm:
            data = [0xCA, 0xFE, 0xBA, 0xBE]
            res = xm.downloadNext(*data)

        mock_socket.return_value.send.assert_called_with(bytes(
            [0x06, 0x00, 0x00, 0x00, 0xef, 0x04, 0xca, 0xfe, 0xba, 0xbe]))

        assert res == b''
Example #2
0
    def testUserCmd(self, mock_selector, mock_socket):
        ms = MockSocket()

        mock_socket.return_value.recv.side_effect = ms.recv
        mock_selector.return_value.select.side_effect = ms.select

        ms.push_frame([0x03, 0x00, 0x00, 0x00, 0xff, 0xaa, 0xbb])

        with Master(transport.Eth('localhost', loglevel="DEBUG")) as xm:
            data = [0xbe, 0xef]
            res = xm.userCmd(0x55, *data)

        mock_socket.return_value.send.assert_called_with(
            bytes([0x04, 0x00, 0x00, 0x00, 0xf1, 0x55, 0xbe, 0xef]))

        assert res == b'\xaa\xbb'
Example #3
0
    def testUpload(self, mock_selector, mock_socket):
        ms = MockSocket()

        mock_socket.return_value.recv.side_effect = ms.recv
        mock_selector.return_value.select.side_effect = ms.select

        ms.push_frame([
            0x09, 0x00, 0x00, 0x00,
            0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08])

        with Master(transport.Eth('localhost', loglevel="DEBUG")) as xm:
            res = xm.upload(8)

        mock_socket.return_value.send.assert_called_with(bytes([
            0x02, 0x00, 0x00, 0x00,
            0xf5, 0x08]))

        assert res == b'\x01\x02\x03\x04\x05\x06\x07\x08'
Example #4
0
    def testConnect2(self, mock_selector, mock_socket):
        ms = MockSocket()

        mock_socket.return_value.recv.side_effect = ms.recv
        mock_selector.return_value.select.side_effect = ms.select

        with Master(transport.Eth('localhost', loglevel="DEBUG")) as xm:
            ms.push_packet(self.DefaultConnectResponse)

            res = xm.connect()

            mock_socket.return_value.send.assert_called_with(bytes(
                [0x02, 0x00, 0x00, 0x00, 0xff, 0x00]))

            assert res.maxCto == 255
            assert res.maxDto == 1500
            assert res.protocolLayerVersion == 1
            assert res.transportLayerVersion == 1
            assert res.resource.dbg is True
            assert res.resource.pgm is True
            assert res.resource.stim is True
            assert res.resource.daq is True
            assert res.resource.calpag is True
            assert res.commModeBasic.optional is True
            assert res.commModeBasic.slaveBlockMode is True
            assert res.commModeBasic.addressGranularity == \
                types.AddressGranularity.BYTE
            assert res.commModeBasic.byteOrder == types.ByteOrder.INTEL

            assert xm.slaveProperties.byteOrder == res.commModeBasic.byteOrder
            assert xm.slaveProperties.maxCto == res.maxCto
            assert xm.slaveProperties.maxDto == res.maxDto

            ms.push_frame("06 00 01 00 FF 00 01 05 01 04")

            res = xm.getVersion()

            mock_socket.return_value.send.assert_called_with(bytes(
                [0x02, 0x00, 0x01, 0x00, 0xc0, 0x00]))

            assert res.protocolMajor == 1
            assert res.protocolMinor == 5
            assert res.transportMajor == 1
            assert res.transportMinor == 4
Example #5
0
    def testGetSeed(self, mock_selector, mock_socket):
        ms = MockSocket()

        mock_socket.return_value.recv.side_effect = ms.recv
        mock_selector.return_value.select.side_effect = ms.select

        with Master(transport.Eth('localhost', loglevel="DEBUG")) as xm:
            ms.push_packet(self.DefaultConnectResponse)

            res = xm.connect()

            ms.push_packet("FF 04 12 34 56 78")

            res = xm.getSeed(0x00, 0x00)

            mock_socket.return_value.send.assert_called_with(bytes(
                [0x03, 0x00, 0x01, 0x00, 0xf8, 0x00, 0x00]))

        assert res.length == 4
        assert res.seed == list(b'\x12\x34\x56\x78')
Example #6
0
    def testGetVersion(self, mock_selector, mock_socket):
        ms = MockSocket()

        mock_socket.return_value.recv.side_effect = ms.recv
        mock_selector.return_value.select.side_effect = ms.select

        with Master(transport.Eth('localhost', loglevel="DEBUG")) as xm:
            ms.push_packet(self.DefaultConnectResponse)

            res = xm.connect()

            ms.push_packet("FF 00 01 05 01 04")

            res = xm.getVersion()

            mock_socket.return_value.send.assert_called_with(bytes(
                [0x02, 0x00, 0x01, 0x00, 0xc0, 0x00]))

            assert res.protocolMajor == 1
            assert res.protocolMinor == 5
            assert res.transportMajor == 1
            assert res.transportMinor == 4
Example #7
0
    def testUnlock(self, mock_selector, mock_socket):
        ms = MockSocket()

        mock_socket.return_value.recv.side_effect = ms.recv
        mock_selector.return_value.select.side_effect = ms.select

        with Master(transport.Eth('localhost', loglevel="DEBUG")) as xm:
            ms.push_packet(self.DefaultConnectResponse)

            res = xm.connect()

            ms.push_packet("FF 10")

            res = xm.unlock(0x04, [0x12, 0x34, 0x56, 0x78])

            mock_socket.return_value.send.assert_called_with(bytes(
                [0x06, 0x00, 0x01, 0x00, 0xf7, 0x04, 0x12, 0x34, 0x56, 0x78]))

        assert res.calpag is False
        assert res.daq is False
        assert res.stim is False
        assert res.pgm is True
Example #8
0
    def testSetMta(self, mock_selector, mock_socket):
        ms = MockSocket()

        mock_socket.return_value.recv.side_effect = ms.recv
        mock_selector.return_value.select.side_effect = ms.select

        with Master(transport.Eth('localhost', loglevel="DEBUG")) as xm:
            ms.push_packet(self.DefaultConnectResponse)

            res = xm.connect()

            mock_socket.return_value.send.assert_called_with(bytes(
                [0x02, 0x00, 0x00, 0x00, 0xff, 0x00]))

            ms.push_frame("01 00 01 00 FF")

            res = xm.setMta(0x12345678, 0x55)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x08, 0x00, 0x01, 0x00,
                0xf6, 0x00, 0x00, 0x55, 0x78, 0x56, 0x34, 0x12]))

            assert res == b''
Example #9
0
    def testShortUpload(self, mock_selector, mock_socket):
        ms = MockSocket()

        mock_socket.return_value.recv.side_effect = ms.recv
        mock_selector.return_value.select.side_effect = ms.select

        with Master(transport.Eth('localhost', loglevel="DEBUG")) as xm:
            ms.push_packet(self.DefaultConnectResponse)

            res = xm.connect()

            mock_socket.return_value.send.assert_called_with(bytes(
                [0x02, 0x00, 0x00, 0x00, 0xff, 0x00]))

            ms.push_frame("09 00 01 00 FF 01 02 03 04 05 06 07 08")

            res = xm.shortUpload(8, 0xcafebabe, 1)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x08, 0x00, 0x01, 0x00,
                0xf4, 0x08, 0x00, 0x01, 0xbe, 0xba, 0xfe, 0xca]))

            assert res == b'\x01\x02\x03\x04\x05\x06\x07\x08'
Example #10
0
    def testModifyBits(self, mock_selector, mock_socket):
        ms = MockSocket()

        mock_socket.return_value.recv.side_effect = ms.recv
        mock_selector.return_value.select.side_effect = ms.select

        with Master(transport.Eth('localhost', loglevel="DEBUG")) as xm:
            ms.push_packet(self.DefaultConnectResponse)

            res = xm.connect()

            mock_socket.return_value.send.assert_called_with(bytes(
                [0x02, 0x00, 0x00, 0x00, 0xff, 0x00]))

            ms.push_frame("01 00 01 00 ff")

            res = xm.modifyBits(0xff, 0x1234, 0xabcd)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x06, 0x00, 0x01, 0x00, 0xec, 0xff, 0x34, 0x12,
                0xcd, 0xab]))

            assert res == b''
Example #11
0
    def testShortDownload(self, mock_selector, mock_socket):
        ms = MockSocket()

        mock_socket.return_value.recv.side_effect = ms.recv
        mock_selector.return_value.select.side_effect = ms.select

        with Master(transport.Eth('localhost', loglevel="DEBUG")) as xm:
            ms.push_packet(self.DefaultConnectResponse)

            res = xm.connect()

            mock_socket.return_value.send.assert_called_with(bytes(
                [0x02, 0x00, 0x00, 0x00, 0xff, 0x00]))

            ms.push_frame("01 00 01 00 FF")

            data = [0xCA, 0xFE, 0xBA, 0xBE]
            res = xm.shortDownload(0x12345678, 0x55, *data)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x0c, 0x00, 0x01, 0x00, 0xed, 0x04, 0x00, 0x55,
                0x78, 0x56, 0x34, 0x12, 0xca, 0xfe, 0xba, 0xbe]))

            assert res == b''
Example #12
0
    def testGetCommModeInfo2(self, mock_selector, mock_socket):
        ms = MockSocket()

        mock_socket.return_value.recv.side_effect = ms.recv
        mock_selector.return_value.select.side_effect = ms.select

        with Master(transport.Eth('localhost', loglevel="DEBUG")) as xm:
            ms.push_packet(self.DefaultConnectResponse)

            res = xm.connect()

            ms.push_packet("FF 00 01 FF 02 00 00 19")

            res = xm.getCommModeInfo()

            mock_socket.return_value.send.assert_called_with(bytes(
                [0x01, 0x00, 0x01, 0x00, 0xfb]))

        assert res.commModeOptional.interleavedMode is False
        assert res.commModeOptional.masterBlockMode is True
        assert res.maxbs == 2
        assert res.minSt == 0
        assert res.queueSize == 0
        assert res.xcpDriverVersionNumber == 25
Example #13
0
    def testDaqCommands(self, mock_selector, mock_socket):
        ms = MockSocket()

        mock_socket.return_value.recv.side_effect = ms.recv
        mock_selector.return_value.select.side_effect = ms.select

        with Master(transport.Eth('localhost', loglevel="DEBUG")) as xm:
            ms.push_packet(self.DefaultConnectResponse)

            res = xm.connect()

            mock_socket.return_value.send.assert_called_with(bytes(
                [0x02, 0x00, 0x00, 0x00, 0xff, 0x00]))

            ms.push_frame([0x01, 0x00, 0x01, 0x00, 0xff])

            res = xm.setDaqPtr(2, 3, 4)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x06, 0x00, 0x01, 0x00, 0xe2, 0x00, 0x02, 0x00, 0x03, 0x04]))

            assert res == b''

            ms.push_frame([0x01, 0x00, 0x02, 0x00, 0xff])

            res = xm.writeDaq(31, 15, 1, 0x12345678)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x08, 0x00, 0x02, 0x00,
                0xe1, 0x1f, 0x0f, 0x01, 0x78, 0x56, 0x34, 0x12]))

            assert res == b''

            ms.push_frame([0x01, 0x00, 0x03, 0x00, 0xff])

            res = xm.setDaqListMode(0x3b, 256, 512, 1, 0xff)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x08, 0x00, 0x03, 0x00,
                0xe0, 0x3b, 0x00, 0x01, 0x00, 0x02, 0x01, 0xff]))

            assert res == b''

            ms.push_frame([0x02, 0x00, 0x04, 0x00, 0xff, 0x00])

            res = xm.startStopDaqList(1, 512)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x04, 0x00, 0x04, 0x00, 0xde, 0x01, 0x00, 0x02]))

            assert res.firstPid == 0

            ms.push_frame([0x01, 0x00, 0x05, 0x00, 0xff])

            res = xm.startStopSynch(3)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x02, 0x00, 0x05, 0x00, 0xdd, 0x03]))

            assert res == b''

            ms.push_packet("FF")

            res = xm.writeDaqMultiple([
                dict(bitOffset=1, size=2, address=3, addressExt=4),
                dict(bitOffset=5, size=6, address=0x12345678, addressExt=7)
            ])

            mock_socket.return_value.send.assert_called_with(bytes([
                0x12, 0x00, 0x06, 0x00, 0xC7, 0x02,
                0x01, 0x02, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00,
                0x05, 0x06, 0x78, 0x56, 0x34, 0x12, 0x07, 0x00
            ]))

            assert res == b''

            ms.push_frame("08 00 06 00 FF 1F 03 04 78 56 34 12")

            res = xm.readDaq()

            mock_socket.return_value.send.assert_called_with(bytes([
                0x01, 0x00, 0x07, 0x00, 0xdb]))

            assert res.bitOffset == 31
            assert res.sizeofDaqElement == 3
            assert res.adressExtension == 4
            assert res.address == 0x12345678

            ms.push_frame("08 00 07 00 FF 00 03 04 78 56 34 12")

            res = xm.getDaqClock()

            mock_socket.return_value.send.assert_called_with(bytes([
                0x01, 0x00, 0x08, 0x00, 0xdc]))

            # todo: assert res.triggerInfo ==
            # todo: assert res.payloadFmt ==
            # todo: assert res.timestamp == 0x12345678
            assert res == 0x12345678

            ms.push_frame("08 00 08 00 FF 55 00 01 34 12 22 03")

            res = xm.getDaqProcessorInfo()

            mock_socket.return_value.send.assert_called_with(bytes([
                0x01, 0x00, 0x09, 0x00, 0xda]))

            assert res.daqProperties.overloadMsb is True
            assert res.daqProperties.bitStimSupported is False
            assert res.maxDaq == 256
            assert res.maxEventChannel == 0x1234
            assert res.minDaq == 0x22
            assert res.daqKeyByte.Optimisation_Type == "OM_ODT_TYPE_64"

            ms.push_frame("08 00 09 00 FF 12 34 56 78 AA 34 12")

            res = xm.getDaqResolutionInfo()

            mock_socket.return_value.send.assert_called_with(bytes([
                0x01, 0x00, 0x0A, 0x00, 0xd9]))

            assert res.granularityOdtEntrySizeDaq == 0x12
            assert res.maxOdtEntrySizeDaq == 0x34
            assert res.granularityOdtEntrySizeStim == 0x56
            assert res.maxOdtEntrySizeStim == 0x78
            assert res.timestampMode.size == "S2"
            assert res.timestampMode.fixed is True
            assert res.timestampMode.unit == "DAQ_TIMESTAMP_UNIT_1PS"
            assert res.timestampTicks == 0x1234

            ms.push_frame("08 00 0A 00 FF AA 00 00 34 12 56 78")

            res = xm.getDaqListMode(256)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x04, 0x00, 0x0B, 0x00, 0xdf, 0x00, 0x00, 0x01]))

            assert res.currentMode.resume is True
            assert res.currentMode.selected is False
            assert res.currentEventChannel == 0x1234
            assert res.currentPrescaler == 0x56
            assert res.currentPriority == 0x78

            ms.push_frame("07 00 0B 00 FF 48 EE 05 06 07 FF")

            res = xm.getDaqEventInfo(256)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x04, 0x00, 0x0C, 0x00, 0xd7, 0x00, 0x00, 0x01]))

            assert res.daqEventProperties.consistency == "CONSISTENCY_DAQ"
            assert res.daqEventProperties.stim is True
            assert res.daqEventProperties.daq is False
            assert res.maxDaqList == 0xee
            assert res.eventChannelNameLength == 0x05
            assert res.eventChannelTimeCycle == 0x06
            assert res.eventChannelTimeUnit == 0x07
            assert res.eventChannelPriority == 0xff

            ms.push_packet("FF AA 34 12 02")

            res = xm.dtoCtrProperties(0x05, 0x1234, 0x5678, 0x02)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x07, 0x00, 0x0D, 0x00,
                0xc5, 0x05, 0x34, 0x12, 0x78, 0x56, 0x02]))

            assert res.properties.evtCtrPresent is True
            assert res.properties.relatedEventFixed is False
            assert res.relatedEventChannel == 0x1234
            assert res.mode.stimMode is True
            assert res.mode.daqMode is False

            ms.push_frame([0x01, 0x00, 0x0C, 0x00, 0xff])

            res = xm.clearDaqList(256)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x04, 0x00, 0x0E, 0x00, 0xe3, 0x00, 0x00, 0x01]))

            assert res == b''

            ms.push_frame("06 00 0D 00 FF 15 10 20 34 12")

            res = xm.getDaqListInfo(256)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x04, 0x00, 0x0F, 0x00, 0xd8, 0x00, 0x00, 0x01]))

            assert res.daqListProperties.packed is True
            assert res.daqListProperties.eventFixed is False
            assert res.maxOdt == 0x10
            assert res.maxOdt == 0x10
            assert res.maxOdtEntries == 0x20
            assert res.fixedEvent == 0x1234

            ms.push_frame([0x01, 0x00, 0x0E, 0x00, 0xff])

            res = xm.freeDaq()

            mock_socket.return_value.send.assert_called_with(bytes([
                0x01, 0x00, 0x10, 0x00, 0xd6]))

            assert res == b''

            ms.push_frame([0x01, 0x00, 0x0F, 0x00, 0xff])

            res = xm.allocDaq(258)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x04, 0x00, 0x11, 0x00, 0xd5, 0x00, 0x02, 0x01]))

            assert res == b''

            ms.push_frame([0x01, 0x00, 0x10, 0x00, 0xff])

            res = xm.allocOdt(258, 3)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x05, 0x00, 0x12, 0x00, 0xd4, 0x00, 0x02, 0x01, 0x03]))

            assert res == b''

            ms.push_frame([0x01, 0x00, 0x11, 0x00, 0xff])

            res = xm.allocOdtEntry(258, 3, 4)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x06, 0x00, 0x13, 0x00, 0xd3, 0x00, 0x02, 0x01, 0x03, 0x04]))

            assert res == b''

            ms.push_frame([0x01, 0x00, 0x12, 0x00, 0xff])

            res = xm.setDaqPackedMode(258, 0)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x05, 0x00, 0x14, 0x00,
                0xc0, 0x01, 0x02, 0x01, 0x00]))

            assert res == b''

            ms.push_frame([0x03, 0x00, 0x13, 0x00, 0xff, 0x00, 0x00])

            res = xm.getDaqPackedMode(258)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x04, 0x00, 0x15, 0x00, 0xc0, 0x02, 0x02, 0x01]))

            assert res.daqPackedMode == types.DaqPackedMode.NONE
            assert res.dpmTimestampMode is None

            ms.push_frame([0x01, 0x00, 0x14, 0x00, 0xff])

            res = xm.setDaqPackedMode(258, 2, 0b01, 0x1234)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x08, 0x00, 0x16, 0x00,
                0xc0, 0x01, 0x02, 0x01, 0x02, 0x01, 0x34, 0x12]))

            assert res == b''

            ms.push_frame("06 00 15 00 FF 00 02 01 34 12")

            res = xm.getDaqPackedMode(258)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x04, 0x00, 0x17, 0x00, 0xc0, 0x02, 0x02, 0x01]))

            assert res.daqPackedMode == "EVENT_GROUPED"
            assert res.dpmTimestampMode == 0x01
            assert res.dpmSampleCount == 0x1234
Example #14
0
    def testPagCommands(self, mock_selector, mock_socket):
        ms = MockSocket()

        mock_socket.return_value.recv.side_effect = ms.recv
        mock_selector.return_value.select.side_effect = ms.select

        with Master(transport.Eth('localhost', loglevel="DEBUG")) as xm:
            ms.push_packet(self.DefaultConnectResponse)

            res = xm.connect()

            ms.push_packet("FF")

            res = xm.setCalPage(0x03, 0x12, 0x34)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x04, 0x00, 0x01, 0x00, 0xeb, 0x03, 0x12, 0x34]))

            assert res == b''

            ms.push_packet("FF 00 00 55")

            res = xm.getCalPage(0x02, 0x44)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x03, 0x00, 0x02, 0x00, 0xea, 0x02, 0x44]))

            assert res == 0x55

            ms.push_packet("FF 10 01")

            res = xm.getPagProcessorInfo()

            mock_socket.return_value.send.assert_called_with(bytes([
                0x01, 0x00, 0x03, 0x00, 0xe9]))

            assert res.maxSegments == 16
            assert res.pagProperties == 0x01

            ms.push_packet("FF 00 00 00 78 56 34 12")

            res = xm.getSegmentInfo(0, 5, 1, 0)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x05, 0x00, 0x04, 0x00, 0xe8, 0x00, 0x05, 0x01, 0x00]))

            assert res.basicInfo == 0x12345678

            ms.push_packet("FF aa bb cc 78 56")

            res = xm.getSegmentInfo(1, 5, 0, 0)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x05, 0x00, 0x05, 0x00, 0xe8, 0x01, 0x05, 0x00, 0x00]))

            assert res.maxPages == 0xaa
            assert res.addressExtension == 0xbb
            assert res.maxMapping == 0xcc
            assert res.compressionMethod == 0x78
            assert res.encryptionMethod == 0x56

            ms.push_packet("FF 00 00 00 78 56 34 12")

            res = xm.getSegmentInfo(2, 5, 1, 3)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x05, 0x00, 0x06, 0x00, 0xe8, 0x02, 0x05, 0x01, 0x03]))

            assert res.mappingInfo == 0x12345678

            ms.push_packet("FF 3F 55")

            res = xm.getPageInfo(0x12, 0x34)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x04, 0x00, 0x07, 0x00, 0xe7, 0x00, 0x12, 0x34]))

            assert res[0].xcpWriteAccessWithEcu
            assert res[1] == 0x55

            ms.push_packet("FF")

            res = xm.setSegmentMode(0x01, 0x23)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x03, 0x00, 0x08, 0x00, 0xe6, 0x01, 0x23]))

            assert res == b''

            ms.push_packet("FF 00 01")

            res = xm.getSegmentMode(0x23)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x03, 0x00, 0x09, 0x00, 0xe5, 0x00, 0x23]))

            assert res == 0x01

            ms.push_packet("FF")

            res = xm.copyCalPage(0x12, 0x34, 0x56, 0x78)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x05, 0x00, 0x0A, 0x00, 0xe4, 0x12, 0x34, 0x56, 0x78]))

            assert res == b''
Example #15
0
def cstest():
    tr = transport.Eth('localhost', port= 5555, protocol = TCP', loglevel = "WARN")  # "DEBUG"
    #tr = transport.SxI("COM27", 115200, loglevel = "WARN")
    with Master(tr) as xm:
    #    tm = Timing()

        conn = xm.connect()
        print(conn, flush = True)

        print("calpag ?", xm.supportsCalpag)
        print("daq ?", xm.supportsDaq)
        print("pgm ?", xm.supportsPgm)
        print("stim ?", xm.supportsStim)

        print(xm.getStatus(), flush = True)
        xm.synch()

        if conn.commModeBasic.optional:
            print(xm.getCommModeInfo(), flush = True)
        else:
            print("No details on connection.")

        gid = xm.getID(0x1)
        print(gid, flush = True)
        result = xm.fetch(gid.length)
        print(result.decode("utf8"))

#        bench(xm)

#        gid = xm.getID(0xdc)
#        print(gid)
#        result = xm.upload()
#        print("ID: '{}'".format(result.decode("utf8")))

#        start = time.perf_counter()
#        result = xm.fetch(gid.length, 252)
#        stop = time.perf_counter()
#        print("ETA: {:.2f} s - rate: {:.2f} kB/s".format(stop - start, (gid.length / (stop - start)) / 1000 ) )

#        print("ID: '{}'".format(result.decode("utf8")))

        #xm.setMta(0x005BF000)
        #bhv = xm.fetch(0x104)
        #print(bhv)

        resInfo = xm.getDaqResolutionInfo()
        print(resInfo, flush = True)
        xm.getDaqProcessorInfo()

    #    print("CS:", xm.buildChecksum(4711))

        start = xm.getDaqClock()
        print("Timestamp / Start: {}".format(start))
        """
        length, seed = xm.getSeed(0, 0xff)
        print("SEED: ", hexDump(seed))
        resultCode, kee = getKey("SeedNKeyXcp.dll", 1, seed)
        if resultCode == 0:
            res = xm.unlock(len(kee), kee)
            print(res)
        """


        startMeasurement(xm)
    ##
    ##    xm.freeDaq()
    ##    print("AllocDAQ:", xm.allocDaq(2))
    ##
    ##    print("allocOdt", xm.allocOdt(1, 5))
    ##    print("allocOdt", xm.allocOdt(0, 4))
    ##    print("allocOdt", xm.allocOdt(1, 3))
    ##
    ##    print("allocOdt", xm.allocOdtEntry(1, 3, 5))
    ##    print("allocOdt", xm.allocOdtEntry(0, 1, 2))
    ##    print("allocOdt", xm.allocOdtEntry(0, 3, 6))
    ##    print("allocOdt", xm.allocOdtEntry(1, 1, 5))
    ##

        #xm.freeDaq()

    #    for _ in range(10):
    #        tm.start()
    #        time.sleep(0.250)
    #        tm.stop()
    #        stop = xm.getDaqClock()
    #        print("trueValue: {}".format(timecode(stop - start, resInfo)))
    #        print("Timestamp / Diff: {}".format(stop - start))

        print("Timer")
        print("=====")
    #    print(tm)

        print(xm.setMta(0x1C0000), flush = True)
        #print(xm.setRequest(0x3, 1))
        print(xm.disconnect(), flush = True)
        #xm.close()
        print("XCP roundtrip timing")
        print("=" * 20)
    for _ in range(tr.daqQueue.qsize()):
        daq = tr.daqQueue.get(timeout = 1.0)
        print(types.DAQ.parse(daq))
Example #16
0
    def testPgmCommands(self, mock_selector, mock_socket):
        ms = MockSocket()

        mock_socket.return_value.recv.side_effect = ms.recv
        mock_selector.return_value.select.side_effect = ms.select

        with Master(transport.Eth('localhost', loglevel="DEBUG")) as xm:
            ms.push_packet(self.DefaultConnectResponse)

            res = xm.connect()

            mock_socket.return_value.send.assert_called_with(bytes(
                [0x02, 0x00, 0x00, 0x00, 0xff, 0x00]))

            ms.push_packet(b"\xFF\x00\x01\x08\x2A\xFF\x55")

            res = xm.programStart()

            mock_socket.return_value.send.assert_called_with(bytes([
                0x01, 0x00, 0x01, 0x00, 0xd2]))

            assert res.commModePgm.masterBlockMode is True
            assert res.commModePgm.interleavedMode is False
            assert res.commModePgm.slaveBlockMode is False
            assert res.maxCtoPgm == 8
            assert res.maxBsPgm == 0x2a
            assert res.minStPgm == 0xff
            assert res.queueSizePgm == 0x55

            ms.push_packet("FF")

            res = xm.programClear(0x00, 0xa0000100)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x08, 0x00, 0x02, 0x00,
                0xd1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xa0]))

            assert res == b''

            ms.push_packet("FF")

            res = xm.program([0x01, 0x02, 0x03, 0x04])

            mock_socket.return_value.send.assert_called_with(bytes([
                0x06, 0x00, 0x03, 0x00,
                0xD0, 0x04, 0x01, 0x02, 0x03, 0x04]))

            assert res == b''

            ms.push_packet("FF")

            res = xm.programReset()

            mock_socket.return_value.send.assert_called_with(bytes([
                0x01, 0x00, 0x04, 0x00, 0xcf]))

            assert res == b''

            ms.push_packet("FF AA BB")

            res = xm.getPgmProcessorInfo()

            mock_socket.return_value.send.assert_called_with(bytes([
                0x01, 0x00, 0x05, 0x00, 0xce]))

            assert res.pgmProperties.nonSeqPgmRequired is True
            assert res.pgmProperties.nonSeqPgmSupported is False
            assert res.maxSector == 0xbb

            ms.push_packet("FF AA BB CC 78 56 34 12")

            res = xm.getSectorInfo(0, 0x12)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x03, 0x00, 0x06, 0x00, 0xcd, 0, 0x12]))

            assert res.clearSequenceNumber == 0xaa
            assert res.programSequenceNumber == 0xbb
            assert res.programmingMethod == 0xcc
            assert res.sectorInfo == 0x12345678

            ms.push_packet("FF AA")

            res = xm.getSectorInfo(2, 0x12)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x03, 0x00, 0x07, 0x00, 0xcd, 2, 0x12]))

            assert res.sectorNameLength == 0xaa

            ms.push_packet("FF")

            res = xm.programPrepare(0x1234)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x04, 0x00, 0x08, 0x00, 0xcc, 0x00, 0x34, 0x12]))

            assert res == b''

            ms.push_packet("FF")

            res = xm.programFormat(0x81, 0x82, 0x83, 0x01)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x05, 0x00, 0x09, 0x00, 0xCB, 0x81, 0x82, 0x83, 0x01]))

            assert res == b''

            ms.push_packet("FF")

            res = xm.programNext([0x01, 0x02, 0x03, 0x04])

            mock_socket.return_value.send.assert_called_with(bytes([
                0x06, 0x00, 0x0A, 0x00,
                0xCA, 0x04, 0x01, 0x02, 0x03, 0x04]))

            assert res == b''

            ms.push_packet("FF")

            res = xm.programMax([0x01, 0x02, 0x03, 0x04])

            mock_socket.return_value.send.assert_called_with(bytes([
                0x05, 0x00, 0x0B, 0x00,
                0xC9, 0x01, 0x02, 0x03, 0x04]))

            assert res == b''

            ms.push_packet("FF")

            res = xm.programVerify(0x01, 0x0004, 0xCAFEBABE)

            mock_socket.return_value.send.assert_called_with(bytes([
                0x08, 0x00, 0x0C, 0x00,
                0xC8, 0x01, 0x04, 0x00, 0xBE, 0xBA, 0xFE, 0xCA]))

            assert res == b''
Example #17
0
def cstest():
    tr = transport.Eth('localhost', port= 5555, connected = False, loglevel = "DEBUG")
    #tr = transport.SxI("COM27", 115200, loglevel = "WARN")
    with Master(tr) as xm:
    #    tm = Timing()

        conn = xm.connect()
        print(conn, flush = True)

        print("calpag ?", xm.supportsCalpag)
        print("daq ?", xm.supportsDaq)
        print("pgm ?", xm.supportsPgm)
        print("stim ?", xm.supportsStim)

        xm.getStatus()
        xm.synch()

        if conn.commModeBasic.optional:
            xm.getCommModeInfo()
        else:
            print("No details on connection.")

        result = xm.getID(0x01)
        result = xm.upload(result.length)
        print("ID: '{}'".format(result.decode("utf8")))

        resInfo = xm.getDaqResolutionInfo()
        print(resInfo)
        #xm.getDaqProcessorInfo()

    #    print("CS:", xm.buildChecksum(4711))

        start = xm.getDaqClock()
        print("Timestamp / Start: {}".format(start))

        length, seed = xm.getSeed(0, 0xff)
        #print(seed)
        print("SEED: ", hexDump(seed))
        #unlock(xm, 1)
        resultCode, kee = getKey("SeedNKeyXcp.dll", 1, seed)
        if resultCode == 0:
            res = xm.unlock(len(kee), kee)
            print(res)


        startMeasurement(xm)
    ##
    ##    xm.freeDaq()
    ##    print("AllocDAQ:", xm.allocDaq(2))
    ##
    ##    print("allocOdt", xm.allocOdt(1, 5))
    ##    print("allocOdt", xm.allocOdt(0, 4))
    ##    print("allocOdt", xm.allocOdt(1, 3))
    ##
    ##    print("allocOdt", xm.allocOdtEntry(1, 3, 5))
    ##    print("allocOdt", xm.allocOdtEntry(0, 1, 2))
    ##    print("allocOdt", xm.allocOdtEntry(0, 3, 6))
    ##    print("allocOdt", xm.allocOdtEntry(1, 1, 5))
    ##

        #xm.freeDaq()

    #    for _ in range(10):
    #        tm.start()
    #        time.sleep(0.250)
    #        tm.stop()
    #        stop = xm.getDaqClock()
    #        print("trueValue: {}".format(timecode(stop - start, resInfo)))
    #        print("Timestamp / Diff: {}".format(stop - start))

        print("Timer")
        print("=====")
    #    print(tm)

        xm.setMta(0x1C0000)
        xm.disconnect()
        #xm.close()
        print("XCP roundtrip timing")
        print("=" * 20)