在Python仿真中使用嵌入式C库

发布于 2024-11-27 05:18:54 字数 418 浏览 0 评论 0原文

简短问题
从现有的嵌入式 C 库(在 Python 中)模拟复杂的 (SAE J1939) 通信堆栈会更容易:
1) 完整移植 - 意味着手动将所有 C 函数转换为 python 模块
2)将堆栈包装在Python包装器中 - 意思是在Python中调用真正的c代码

背景信息
我已经用 Python 编写了该堆栈的一小部分,但是以 100% 覆盖率实现它们并不简单。正是因为这个原因,我们最近为我们的嵌入式平台购买了现成的 SAE J1939 堆栈。为了澄清,我知道涉及硬件层的部分必须重新创建并映射到 PC 的 CAN 驱动程序。

我希望在这里找到有人已经或什至研究过将 5k LOC C 库移植到 Python。如果有任何运行良好的 C 到 Python 工具,对我的研究也会有帮助。

Short Question
Which would be easier to emulate (in Python) a complex (SAE J1939) communication stack from an existing embedded C library:
1) Full port - meaning manually convert all of the C functions to python modules
2) Wrap the stack in a Python wrapper - meaning call the real c code in Python

Background Information
I have already written small portions of this stack in Python, however they are very non-trival to implement with 100% coverage. Because of this very reason, we have recently purchased an off the shelf SAE J1939 stack for our embedded platforms. To clarify, I know that portions touching the hardware layer will have to be re-created and mapped to the PC's CAN drivers.

I am hoping to find someone here on SO that has or even looked into porting a 5k LOC C library to Python. If there are any C to Python tools that work well that would be helpful for me to look into as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷心人i 2024-12-04 05:18:54

我的建议是把它包裹起来。

原因是:

但是,您需要

  • 检查您购买的许可证是否允许您这样做,
  • 因为在嵌入式和 PC 端具有相同的实现,它无助于跟踪错误,
  • 您的可移植性可能比完整的 python 实现要差一些(无论如何,不​​是对您来说很重要,因为您的低层需要根据每个目标重写)

My advice would be to wrap it.

Reasons for that:

  • if you convert function by function, you'll introduce new bugs (we're just human) and this kind of stuff is pretty hard to test
  • wrapping for python is done easily, using swig or even ctypes to load a dll on the fly, you'll find tons of tutorial
  • if your lib gets updated, you have less impact in the long term.

However, you need to

  • check that the license you purchase allows you to do that
  • know that having same implementation on embedded and PC side, it won't help tracking bugs
  • you might have a bit less portability than a full python implementation (anyway, not much of a point for you as your low layer needs to be rewritten per target)
故事与诗 2024-12-04 05:18:54

一定要包起来。运行 ctypesgen.py 然后使用它可能很简单。查看这篇关于使用 ctypesgen 为 libreadline 创建包装器的博客文章 http:// wavetossed.blogspot.com/2011/07/asynchronous-gnu-readline.html 以便访问完整的 API。

Definitely wrap it. It might be as easy are running ctypesgen.py and then using it. Check this blog article about using ctypesgen to create a wrapper for libreadline http://wavetossed.blogspot.com/2011/07/asynchronous-gnu-readline.html in order to get access to the full API.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文