lishen2 / isotp-c

An implementation of the ISO-TP (ISO15765-2) CAN protocol in C
MIT License
203 stars 77 forks source link

System functions as callbacks? #14

Closed j3kestrel closed 2 years ago

j3kestrel commented 4 years ago

Have you considered implementing isotp_send_can(), isotp_user_get-ms() and isotp_user_debug() as callbacks that are registered as arguments to isotp_init_link() and stored in IsoTpLink? This would permit using different instances of the functions for each instance of IsoTpLink.

In my case, I wish to manage CAN send buffer queue's differently for each IsoTpLink instance. I also wanted to pass a pointer my own printf() function instead of writing a wrapper. For this I edited isotp_user.h to make isotp_user_debug a macro that redirected to my function, but I can see cases where the debug console stream from each IsoTpLink instance may wish to be handled differently.

I see little need for different isotp_user_get_ms() instances, but I like the clean implementation of dependency injection and treating this function the same way keeps the pattern uniform.

I may implement this for myself. If there were interest I should be able to create a pull request.

I don't have isotp-c running yet, but it looks well done. Thank you!

lishen2 commented 2 years ago

Please create a pull request. Callbacks dose better.

driftregion commented 11 months ago

Hi @lishen2, would you consider the PR I opened? I'm using isotp-c in https://github.com/driftregion/iso14229/ and am encountering the need that @j3kestrel described.

Thanks