Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bytearray index out of range #180

Open
mannyOaks opened this issue Oct 30, 2024 · 3 comments
Open

Bytearray index out of range #180

mannyOaks opened this issue Oct 30, 2024 · 3 comments

Comments

@mannyOaks
Copy link

mannyOaks commented Oct 30, 2024

Hi, I'm currently using pyxcp to read some signal's values using DAQ, but ran into a "bytearray index out of range" error that makes me unable to read the values.

image
As you can see in this image, response is an empty bytearray, but data is a bytearray of length 1799.

Here is the script I'm running that gets me this error

config = {
    "HOST": hostname,
    "PORT": port,
    "PROTOCOL": "udp",
    "CREATE_DAQ_TIMESTAMPS": True,
}

x = Master("eth", config=config)
a2l = A2lParser(a2l_path)

x.connect()

DAQ_LIST_NUMBER = 0
BIT_OFFSET = 255
MAX_ENTRY_SIZE = 255
DAQ_MODE_TIME_OFF = 0x0
DAQ_START_STOP_LIST_MODE = 0x02
STOP_SYNCH_MODE = 0x0
START_SYNCH_MODE = 0x1

# MAX_DTO value is 1438 in my ECU
MAX_DTO = x.slaveProperties.maxDto

signal = XcpUtils.get_attribute_dict_from_a2l_list(a2l.variable_list, signal_name)
data_type = DataType(signal.get("data_type"))
length = XcpHelper.calculate_signal_length_with_data_type(data_type.size, signal.get("matrix_dim"))
# Length of this specific signal is 3136, meaning we need 3 tables
odt_tables_count = math.ceil(length / (MAX_DTO - 1))

MAX_SIZE = MAX_DTO - 1
odt_matrix = []
for _ in range(odt_tables_count):
    matrix_size = sum(sum(e) for e in odt_matrix)
    if matrix_size + MAX_SIZE > length:
        entry_size = length - matrix_size
    else:
        entry_size = MAX_SIZE

    entries = []
    while entry_size > 0:
        if entry_size > MAX_ENTRY_SIZE:
            size = MAX_ENTRY_SIZE
        else:
            size = entry_size

        entry_size -= size
        entries.append(size)
    odt_matrix.append(entries)
# odt_matrix = [
#   [255, 255, 255, 255, 255, 162],
#   [255, 255, 255, 255, 255, 162],
#   [255, 7],
# ]

event = XcpUtils.get_attribute_dict_from_a2l_list(a2l.event_list, event_name)
event_channel_number = event.get("channel_number")

x.freeDaq()
x.allocDaq(1)  # Only one list
x.allocOdt(DAQ_LIST_NUMBER, odt_tables_count)

for odt_number, entries in enumerate(odt_matrix):
    x.allocOdtEntry(DAQ_LIST_NUMBER, odt_number, len(entries))

ecu_address = signal.get("ecu_address")
for odt_number, entries in enumerate(odt_matrix):
    x.setDaqPtr(DAQ_LIST_NUMBER, odt_number, 0)
    for entry_size in entries:
        x.writeDaq(
            BIT_OFFSET,
            entry_size,
            signal.get("address_ext"),
            ecu_address,
        )
        ecu_address += entry_size

x.setDaqListMode(DAQ_MODE_TIME_OFF, DAQ_LIST_NUMBER, event_channel_number, 1, 0)
x.startStopDaqList(DAQ_START_STOP_LIST_MODE, DAQ_LIST_NUMBER)

x.startStopSynch(START_SYNCH_MODE)
x.startStopSynch(STOP_SYNCH_MODE)

x.disconnect()

I'm running commands in the same order as Vector's CANape, and CANape does return some values with the same signal I'm reading in this script, any ideas what might I be doing wrong?

Python version, OS and pyxcp version:
image
image
image

@christoph2
Copy link
Owner

OK, this is mainly a documentation issue, i.e. my fault...

The complete DAQ process -- setup, ODT allocation and recording is part of pyXCP; the example file run_daq.py is exactly what you are you looking for.

There is some documentation in form of this discussion (will be reworked to offical documentation soon).

@mannyOaks
Copy link
Author

mannyOaks commented Oct 31, 2024

Unfortunately, I had already tried that approach and this was the output:

[2024-10-31 12:49:11,265][INFO] - XCPonEth - Connected to: 10.1.0.34:30444  local address: 10.1.0.46:58123 [AF_INET][SOCK_DGRAM]
[2024-10-31 12:49:11,265][DEBUG] - CONNECT
[2024-10-31 12:49:11,265][DEBUG] - -> [02 00 00 00 ff 00]
[2024-10-31 12:49:11,270][DEBUG] - <- L8 C12275 [ff 05 40 40 9e 05 01 01]
[2024-10-31 12:49:11,274][DEBUG] - GET_STATUS
[2024-10-31 12:49:11,274][DEBUG] - -> [01 00 01 00 fd]
[2024-10-31 12:49:11,275][DEBUG] - <- L6 C12276 [ff 00 00 00 00 00]
setup DAQ lists.
[2024-10-31 12:49:11,276][DEBUG] - GET_DAQ_PROCESSOR_INFO
[2024-10-31 12:49:11,276][DEBUG] - -> [01 00 02 00 da]
[2024-10-31 12:49:11,280][DEBUG] - <- L8 C12277 [ff 83 ff ff 12 00 00 20]
[2024-10-31 12:49:11,281][DEBUG] - GET_DAQ_RESOLUTION_INFO
[2024-10-31 12:49:11,281][DEBUG] - -> [01 00 03 00 d9]
[2024-10-31 12:49:11,286][DEBUG] - <- L8 C12278 [ff 01 ff 01 ff 00 00 00]
[2024-10-31 12:49:11,286][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,286][DEBUG] - -> [04 00 04 00 d7 00 00 00]
[2024-10-31 12:49:11,290][DEBUG] - <- L7 C12279 [ff 04 01 07 01 07 8b]
[2024-10-31 12:49:11,291][DEBUG] - UPLOAD
[2024-10-31 12:49:11,291][DEBUG] - -> [02 00 05 00 f5 07]
[2024-10-31 12:49:11,295][DEBUG] - <- L8 C12280 [ff 43 30 5f 31 30 4d 53]
[2024-10-31 12:49:11,296][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,296][DEBUG] - -> [04 00 06 00 d7 00 01 00]
[2024-10-31 12:49:11,300][DEBUG] - <- L7 C12281 [ff 04 01 07 02 07 8a]
[2024-10-31 12:49:11,300][DEBUG] - UPLOAD
[2024-10-31 12:49:11,300][DEBUG] - -> [02 00 07 00 f5 07]
[2024-10-31 12:49:11,305][DEBUG] - <- L8 C12282 [ff 43 30 5f 32 30 4d 53]
[2024-10-31 12:49:11,306][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,306][DEBUG] - -> [04 00 08 00 d7 00 02 00]
[2024-10-31 12:49:11,310][DEBUG] - <- L7 C12283 [ff 04 01 09 01 08 89]
[2024-10-31 12:49:11,311][DEBUG] - UPLOAD
[2024-10-31 12:49:11,311][DEBUG] - -> [02 00 09 00 f5 09]
[2024-10-31 12:49:11,316][DEBUG] - <- L10 C12284 [ff 43 30 5f 42 47 54 41 53 4b]
[2024-10-31 12:49:11,317][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,317][DEBUG] - -> [04 00 0a 00 d7 00 03 00]
[2024-10-31 12:49:11,321][DEBUG] - <- L7 C12285 [ff 04 01 07 01 07 8b]
[2024-10-31 12:49:11,321][DEBUG] - UPLOAD
[2024-10-31 12:49:11,321][DEBUG] - -> [02 00 0b 00 f5 07]
[2024-10-31 12:49:11,325][DEBUG] - <- L8 C12286 [ff 43 31 5f 31 30 4d 53]
[2024-10-31 12:49:11,326][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,326][DEBUG] - -> [04 00 0c 00 d7 00 04 00]
[2024-10-31 12:49:11,331][DEBUG] - <- L7 C12287 [ff 04 01 06 05 06 8c]
[2024-10-31 12:49:11,332][DEBUG] - UPLOAD
[2024-10-31 12:49:11,332][DEBUG] - -> [02 00 0d 00 f5 06]
[2024-10-31 12:49:11,335][DEBUG] - <- L7 C12288 [ff 43 31 5f 35 4d 53]
[2024-10-31 12:49:11,335][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,335][DEBUG] - -> [04 00 0e 00 d7 00 05 00]
[2024-10-31 12:49:11,340][DEBUG] - <- L7 C12289 [ff 04 01 07 02 07 8a]
[2024-10-31 12:49:11,340][DEBUG] - UPLOAD
[2024-10-31 12:49:11,340][DEBUG] - -> [02 00 0f 00 f5 07]
[2024-10-31 12:49:11,345][DEBUG] - <- L8 C12290 [ff 43 31 5f 32 30 4d 53]
[2024-10-31 12:49:11,345][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,346][DEBUG] - -> [04 00 10 00 d7 00 06 00]
[2024-10-31 12:49:11,350][DEBUG] - <- L7 C12291 [ff 04 01 08 01 08 89]
[2024-10-31 12:49:11,351][DEBUG] - UPLOAD
[2024-10-31 12:49:11,351][DEBUG] - -> [02 00 11 00 f5 08]
[2024-10-31 12:49:11,355][DEBUG] - <- L9 C12292 [ff 43 31 5f 31 30 30 4d 53]
[2024-10-31 12:49:11,356][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,357][DEBUG] - -> [04 00 12 00 d7 00 07 00]
[2024-10-31 12:49:11,360][DEBUG] - <- L7 C12293 [ff 04 01 09 01 08 88]
[2024-10-31 12:49:11,361][DEBUG] - UPLOAD
[2024-10-31 12:49:11,361][DEBUG] - -> [02 00 13 00 f5 09]
[2024-10-31 12:49:11,365][DEBUG] - <- L10 C12294 [ff 43 31 5f 42 47 54 41 53 4b]
[2024-10-31 12:49:11,365][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,366][DEBUG] - -> [04 00 14 00 d7 00 08 00]
[2024-10-31 12:49:11,370][DEBUG] - <- L7 C12295 [ff 04 01 08 01 08 88]
[2024-10-31 12:49:11,370][DEBUG] - UPLOAD
[2024-10-31 12:49:11,370][DEBUG] - -> [02 00 15 00 f5 08]
[2024-10-31 12:49:11,375][DEBUG] - <- L9 C12296 [ff 43 32 5f 31 30 30 4d 53]
[2024-10-31 12:49:11,376][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,376][DEBUG] - -> [04 00 16 00 d7 00 09 00]
[2024-10-31 12:49:11,381][DEBUG] - <- L7 C12297 [ff 04 01 07 01 07 8b]
[2024-10-31 12:49:11,381][DEBUG] - UPLOAD
[2024-10-31 12:49:11,381][DEBUG] - -> [02 00 17 00 f5 07]
[2024-10-31 12:49:11,386][DEBUG] - <- L8 C12298 [ff 43 32 5f 31 30 4d 53]
[2024-10-31 12:49:11,386][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,386][DEBUG] - -> [04 00 18 00 d7 00 0a 00]
[2024-10-31 12:49:11,390][DEBUG] - <- L7 C12299 [ff 04 01 07 02 07 8a]
[2024-10-31 12:49:11,390][DEBUG] - UPLOAD
[2024-10-31 12:49:11,390][DEBUG] - -> [02 00 19 00 f5 07]
[2024-10-31 12:49:11,395][DEBUG] - <- L8 C12300 [ff 43 32 5f 32 30 4d 53]
[2024-10-31 12:49:11,396][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,396][DEBUG] - -> [04 00 1a 00 d7 00 0b 00]
[2024-10-31 12:49:11,400][DEBUG] - <- L7 C12301 [ff 04 01 06 05 06 8c]
[2024-10-31 12:49:11,400][DEBUG] - UPLOAD
[2024-10-31 12:49:11,400][DEBUG] - -> [02 00 1b 00 f5 06]
[2024-10-31 12:49:11,406][DEBUG] - <- L7 C12302 [ff 43 32 5f 35 4d 53]
[2024-10-31 12:49:11,406][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,406][DEBUG] - -> [04 00 1c 00 d7 00 0c 00]
[2024-10-31 12:49:11,411][DEBUG] - <- L7 C12303 [ff 04 01 07 04 07 89]
[2024-10-31 12:49:11,411][DEBUG] - UPLOAD
[2024-10-31 12:49:11,411][DEBUG] - -> [02 00 1d 00 f5 07]
[2024-10-31 12:49:11,416][DEBUG] - <- L8 C12304 [ff 43 32 5f 34 30 4d 53]
[2024-10-31 12:49:11,416][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,416][DEBUG] - -> [04 00 1e 00 d7 00 0d 00]
[2024-10-31 12:49:11,420][DEBUG] - <- L7 C12305 [ff 04 01 09 01 08 87]
[2024-10-31 12:49:11,420][DEBUG] - UPLOAD
[2024-10-31 12:49:11,420][DEBUG] - -> [02 00 1f 00 f5 09]
[2024-10-31 12:49:11,425][DEBUG] - <- L10 C12306 [ff 43 32 5f 42 47 54 41 53 4b]
[2024-10-31 12:49:11,425][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,425][DEBUG] - -> [04 00 20 00 d7 00 0e 00]
[2024-10-31 12:49:11,430][DEBUG] - <- L7 C12307 [ff 04 01 08 01 08 88]
[2024-10-31 12:49:11,430][DEBUG] - UPLOAD
[2024-10-31 12:49:11,430][DEBUG] - -> [02 00 21 00 f5 08]
[2024-10-31 12:49:11,436][DEBUG] - <- L9 C12308 [ff 43 33 5f 31 30 30 4d 53]
[2024-10-31 12:49:11,436][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,436][DEBUG] - -> [04 00 22 00 d7 00 0f 00]
[2024-10-31 12:49:11,440][DEBUG] - <- L7 C12309 [ff 04 01 07 01 07 8b]
[2024-10-31 12:49:11,441][DEBUG] - UPLOAD
[2024-10-31 12:49:11,441][DEBUG] - -> [02 00 23 00 f5 07]
[2024-10-31 12:49:11,445][DEBUG] - <- L8 C12310 [ff 43 33 5f 31 30 4d 53]
[2024-10-31 12:49:11,446][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,446][DEBUG] - -> [04 00 24 00 d7 00 10 00]
[2024-10-31 12:49:11,451][DEBUG] - <- L7 C12311 [ff 04 01 07 02 07 8a]
[2024-10-31 12:49:11,451][DEBUG] - UPLOAD
[2024-10-31 12:49:11,451][DEBUG] - -> [02 00 25 00 f5 07]
[2024-10-31 12:49:11,455][DEBUG] - <- L8 C12312 [ff 43 33 5f 32 30 4d 53]
[2024-10-31 12:49:11,456][DEBUG] - GET_DAQ_EVENT_INFO
[2024-10-31 12:49:11,456][DEBUG] - -> [04 00 26 00 d7 00 11 00]
[2024-10-31 12:49:11,460][DEBUG] - <- L7 C12313 [ff 04 01 09 01 08 89]
[2024-10-31 12:49:11,461][DEBUG] - UPLOAD
[2024-10-31 12:49:11,461][DEBUG] - -> [02 00 27 00 f5 09]
[2024-10-31 12:49:11,465][DEBUG] - <- L10 C12314 [ff 43 33 5f 42 47 54 41 53 4b]
[2024-10-31 12:49:11,466][DEBUG] - FREE_DAQ
[2024-10-31 12:49:11,466][DEBUG] - -> [01 00 28 00 d6]
[2024-10-31 12:49:11,470][DEBUG] - <- L1 C12315 [ff]
[2024-10-31 12:49:11,471][DEBUG] - ALLOC_DAQ
[2024-10-31 12:49:11,471][DEBUG] - -> [04 00 29 00 d5 00 01 00]
[2024-10-31 12:49:11,475][DEBUG] - <- L1 C12316 [ff]
[2024-10-31 12:49:11,476][DEBUG] - ALLOC_ODT
[2024-10-31 12:49:11,476][DEBUG] - -> [05 00 2a 00 d4 00 00 00 01]
[2024-10-31 12:49:11,481][DEBUG] - <- L1 C12317 [ff]
[2024-10-31 12:49:11,481][DEBUG] - ALLOC_ODT_ENTRY
[2024-10-31 12:49:11,481][DEBUG] - -> [06 00 2b 00 d3 00 00 00 00 01]
[2024-10-31 12:49:11,486][DEBUG] - <- L1 C12318 [ff]
[2024-10-31 12:49:11,486][DEBUG] - SET_DAQ_PTR
[2024-10-31 12:49:11,486][DEBUG] - -> [06 00 2c 00 e2 00 00 00 00 00]
[2024-10-31 12:49:11,490][DEBUG] - <- L1 C12319 [ff]
[2024-10-31 12:49:11,491][DEBUG] - WRITE_DAQ
[2024-10-31 12:49:11,491][DEBUG] - -> [08 00 2d 00 e1 ff 04 00 94 7e d1 9b]
[2024-10-31 12:49:11,495][DEBUG] - <- L1 C12320 [ff]
[2024-10-31 12:49:11,496][DEBUG] - SET_DAQ_LIST_MODE
[2024-10-31 12:49:11,496][DEBUG] - -> [08 00 2e 00 e0 00 00 00 00 00 01 ff]
[2024-10-31 12:49:11,500][DEBUG] - <- L1 C12321 [ff]
[2024-10-31 12:49:11,500][DEBUG] - START_STOP_DAQ_LIST
[2024-10-31 12:49:11,501][DEBUG] - -> [04 00 2f 00 de 02 00 00]
[2024-10-31 12:49:11,505][DEBUG] - <- L2 C12322 [ff 00]
terminate called after throwing an instance of 'std::runtime_error'
  what():  Invalid timestamp size
Aborted

Created a pyxcp_conf.py file out of:

TRANSPORT = "ETH"
HOST = "HOSTNAME"
PORT = 1111
PROTOCOL = "UDP"
IPV6 = false
CREATE_DAQ_TIMESTAMPS = false

And this is the script I ran:

ap = ArgumentParser(description="DAQ test")

a2l = A2lParser(a2l_path)
signal = XcpUtils.get_attribute_dict_from_a2l_list(a2l.variable_list, signal_name)
event = XcpUtils.get_attribute_dict_from_a2l_list(a2l.event_list, event_name)

daq_lists = [
    DaqList(
        "part_1",
        event.get("channel_number"),
        False,
        False,
        [
            (signal_name, signal.get("ecu_address"), 0, "U32"),
        ],
    )
]

daq_parser = DaqRecorder(daq_lists, "run_daq", 1)  # Record to ".xmraw" file.

with ap.run(policy=daq_parser) as x:
    x.connect()
    if x.slaveProperties.optionalCommMode:
        x.getCommModeInfo()

    x.cond_unlock("DAQ")  # DAQ resource is locked in many cases.

    print("setup DAQ lists.")
    daq_parser.setup()
    print("start DAQ lists.")
    daq_parser.start()

    time.sleep(10)  # Run for 10 seconds.

    print("Stop DAQ....")
    daq_parser.stop()
    print("finalize DAQ lists.\n")
    x.disconnect()

@christoph2
Copy link
Owner

The timestamping code at this point is brand new; I didn't test the "no-timestamping" case; this is (hopefully) fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants