Using the built-in C library in Python emulation

Short question
What would be easier to emulate (in Python) a complex (SAE J1939) communication stack from an existing embedded C library:
1) Full port - value manually converts all C functions to python modules
2) Wrap the stack in a Python shell - this means calling real c code in Python

Background Information
I already wrote small parts of this stack in Python, however they are very non-standard for implementation with 100% coverage. For this reason, we recently purchased a SAE J1939 stack on a shelf for our embedded platforms. To clarify, I know that parts affecting the hardware level must be re-created and mapped to PC drivers.

I hope to find someone here on SO who or even looked at porting the 5K LOC C library to Python. If there are C tools for Python that work well, that would be useful for me and for learning.

+4
source share
2 answers

My advice is to wrap it.

The reasons for this:

  • if you convert a function by function, you introduce new errors (we are just people), and such things are quite difficult to check
  • packaging for python is easy using swig or even ctypes to load DLLs on the fly, you will find many tutorials
  • if your library is updated, you have less impact in the long run.

However you need

  • make sure your license allows you to do this
  • They know that with the same implementation on the built-in and PC side, this will not help to track errors.
  • you may have slightly less portability than the full python implementation (anyway, this is not so important for you, since your low level needs to be rewritten for each purpose).
+3
source

Definitely wrap it. It may be just as easy to run ctypesgen.py and then use it. Check out this blog post about using ctypesgen to create a wrapper for libreadline http://wavetossed.blogspot.com/2011/07/asynchronous-gnu-readline.html to access the full API.

+2
source

All Articles