christoph2 / pyxcp

ASAM XCP in Python
http://pyxcp.rtfd.org
GNU Lesser General Public License v3.0
207 stars 64 forks source link

Slave byteorder is not used in master #19

Closed waszil closed 5 years ago

waszil commented 5 years ago

I have a slave device with Motorola byte order, and all the master methods that use struct.pack/unpack, are hard-wired with '<' which means Intel. Therefore these do not work, for example setMta.

I suggest that the MasterBaseType should have slaveByteOrder and/or slaveByteOrderStructChar fields, and these should be updated when parsing the connect response:

response = self.transport.request(types.Command.CONNECT, 0x00)
result = types.ConnectResponse.parse(response)
...
self.slaveByteOrder = result.commModeBasic.byteOrder
if self.slaveByteOrder == 'MOTOROLA':
    self.slaveByteOrderStructChar = '>'
else:
    self.slaveByteOrderStructChar = '<'

and after this, the master methods can use this:

# in setMta:
addr = struct.pack("%sI" % self.slaveByteOrderStructChar, address)
...

Or am I missing something? Thanks!

christoph2 commented 5 years ago

You're absolutely right! Considering byte-order from CONNECT_Res is a missing required feature. I will integrate it ASAP.

waszil commented 5 years ago

Great, thanks!