intrepidcs / python_ics

Library for interfacing with Intrepid devices in Python
MIT License
61 stars 31 forks source link

ISO15765 padding not works #28

Closed keelung-yang closed 5 years ago

keelung-yang commented 6 years ago

image

Here is my code which modified from iso15765_example.py

`@dataclass class ECU: name: str txid: int rxid: int

txmsg: ics.CmISO157652TxMessage = ics.CmISO157652TxMessage()
rxmsg: ics.CmISO157652RxMessage = ics.CmISO157652RxMessage()
net: int = ics.NETID_HSCAN
padding: int = 0x00
blocksize: int = 100
fstimeout: int = 0x10
fswait: int = 0x3000
cftimeout: int = 1000
stmin: int = 10

def __post_init__(self):
    self.txmsg.vs_netid = self.net
    self.txmsg.id = self.txid
    self.txmsg.fc_id = self.rxid
    self.txmsg.fc_id_mask = 0xFFF
    self.txmsg.padding = self.padding
    self.txmsg.blockSize = 0
    self.txmsg.fs_timeout = self.fstimeout
    self.txmsg.fs_wait = self.fswait
    self.txmsg.stMin = 0
    self.txmsg.flags = (1 << 5) | (8 << 23)
    # self.txmsg.flowControlExtendedAddress = 0xFE

    self.rxmsg.vs_netid = self.net
    self.rxmsg.id = self.rxid
    self.rxmsg.id_mask = 0xFFF
    self.rxmsg.fc_id = self.txid
    self.rxmsg.padding = self.padding
    self.rxmsg.blockSize = self.blocksize
    self.rxmsg.cf_timeout = self.cftimeout
    self.rxmsg.stMin = self.stmin
    self.rxmsg.flags = (1 << 5) | (1 << 4)

`

` def main(args): logfmt = '%(asctime)s %(message)s' logging.basicConfig(level=args.logLevel, format=logfmt)

net = args.net
ecu = ECU('ICM', 0x760, 0x768)
data = [0x10, 0x40]

ecu.txmsg.data = data
ecu.txmsg.num_bytes = len(data)

device = ics.open_device()
ics.iso15765_enable_networks(device, net)
ics.iso15765_receive_message(device, net, ecu.rxmsg)
if ics.iso15765_transmit_message(device, net, ecu.txmsg, ecu.fswait):
    waitms = (len(data) / 8) * ecu.txmsg.fs_timeout
    print(f'Waiting {waitms} ms')
    time.sleep((waitms / 1000) + 0.5)
else:
    print(ics.get_error_messages(device))
get_iso15765_msgs(device)

ics.iso15765_disable_networks(device)`
keelung-yang commented 6 years ago

It's a bug for single frame message. According to 'ISO 15765-2:2011(E) 9.4.2.1 CAN frame data padding':

If this solution is used, the DLC is always set to 8, even if the N_PDU to be transmitted is shorter than 8 bytes. The sender has to pad any unused bytes in the frame. In particular, this can be the case for an SF, FC frame or the last CF of a segmented message

I tested iso15765_example.py, changed number_of_bytes to 4 and 9, the output:

image

drebbe-intrepid commented 5 years ago

@keelung-yang Sorry I missed all your issue reports, seems like my email notifications aren't working like they should anymore...

I have a lot on my list currently, hopefully sometime in January I can check everything off my list.

syntroniks commented 5 years ago

I'm encountering this issue as well. Thanks for the update @drebbe-intrepid

My device under test handles non-padded frames for some messages (tester present, read data by ID) but not others (security access)

drebbe-intrepid commented 5 years ago

@syntroniks Can you provide more details? icsneo40.dll version, python version, what intrepid hardware you are using, and OS version would be greatly appreciated.

syntroniks commented 5 years ago

Windows

1709 Build 16299.611

Python:

python
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32

icsneo40.dll (wow, 17MB!):

File Version: 3.7.1.87

Hardware:

ValueCAN 3

I'm willing to test, as always :)

drebbe-intrepid commented 5 years ago

@syntroniks Thank you for the information. I'll let you know, if I find anything. If you are in possession of any other devices like a FIRE2, testing on those would be appreciated.

syntroniks commented 5 years ago

Yes, I've got one of your higher-end interfaces. I'll give that a shot first thing in January and report back.

On Wed, Dec 19, 2018 at 2:50 PM David Rebbe notifications@github.com wrote:

@syntroniks https://github.com/syntroniks Thank you for the information. I'll let you know, if I find anything. If you are in possession of any other devices like a FIRE2, testing on those would be appreciated.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/intrepidcs/python_ics/issues/28#issuecomment-448739072, or mute the thread https://github.com/notifications/unsubscribe-auth/AFNgES8-_SjEz6uf4XTZf38KEdUoPRvUks5u6qaJgaJpZM4XzPq7 .

drebbe-intrepid commented 5 years ago

@syntroniks Please update to at least 3.8.2.111. This should hopefully fix your issue.

@keelung-yang It looks like you are using the same device and neoVI Server. This shouldn't work correctly with the example, can you please provide full source to your modifications?

drebbe-intrepid commented 5 years ago

closing this out due to lack of activity. Please re-open if needed.

syntroniks commented 5 years ago

Thanks for updating David, I don't have a license current enough to upgrade to that version of Vehicle Spy. I'll try once we renew and I suspect everything will work as intended.

Again, thanks for your investigation and assistance.

djcatter commented 4 years ago

We were able to repeat this with python 2.7 with the latest version of VSpy 3.9.1.27 and DLLs. Can try on a new ValueCAN4 if that would help. Just set the demo script to 2.

Note that the padding does fill out in the Flow Control Frame.

Opening Device ValueCAN3 135678 (Open Client handles: 0)... Opened Device ValueCAN3 135678. Opening Device ValueCAN3 133157 (Open Client handles: 0)... Opened Device ValueCAN3 133157. Setting up iso15765 message on ValueCAN3 133157... Setup iso15765 message on ValueCAN3 133157. Transmitting iso15765 message on ValueCAN3 135678... Transmitted iso15765 message on ValueCAN3 135678. Received 1 messages with 0 errors. Message #1 ArbID: 0x7e0L Data: ['0x2', '0x0', '0x1']

Name: python-ics Version: 4.3 Summary: Library for interfacing with Intrepid devices in Python Home-page: https://github.com/intrepidcs/python_ics/