【问题标题】:How to write a parent program that is using other C programs?如何编写使用其他 C 程序的父程序?
【发布时间】:2019-01-25 12:39:38
【问题描述】:

我正在制作一个 can-bus 网络,它将调查一些传感器以收集数据,以便更好地了解我们想要分析和控制的环境。为此,我们使用 candump 监控流量并可以发送到 sen 信息(来自可以在此地址中找到的 CAN-BUS 文件:https://github.com/linux-can/can-utils.git)。我修改了一些代码,它们编译得很好,现在我想做的是制作一个可以编排这个 C 程序的父代码,以控制环境。我想使用 python 或 c++ 来做到这一点。

示例算法

while(sys == on){

if (everything is in place && security) then 
{candump -l -t -n nb_of_max_cycle can0} 
else { puts("error")}

if (user_id == permited_id && authentification) then 
{ cansend can0 tram=[hexID_arbitration+data] }
else { puts("denied") }

}

提前感谢所有类型的建议。

我尝试使用 IDE,但我无法编译任何东西,因为使用的 makefile 是专门为具有 CANBUS 的 iso 标准的罐头程序制作的。

我想使用 c 函数调用、放置或获取基本信息,就像我在使用此代码的终端上一样。

【问题讨论】:

  • 选择一种语言并告诉我们这是针对哪个系统的。如何从程序启动另一个进程取决于编程语言和主机系统。
  • Python then.@Lundin

标签: python c++ c can-bus


【解决方案1】:

您可以使用std::system 来运行其他程序。

类似:

if (std::system("candump -l -t -n nb_of_max_cycle can0") != 0) {
  puts("error");
}

总的来说,这是一种完成工作的可怕方式。您需要将那些较低级别程序 (candump more_params >output.txt) 的输出重定向到文件,如果您想用它做任何事情。如果你只想要一些简单的东西可能就足够了。

更好的方法是为这些东西提供适当的接口并将它们链接到您的二进制文件中。查看candumpcansend 实现了什么,并调用了类似的函数。这应该可以让您更好地控制系统的整体工作方式。

【讨论】:

  • 实际上输出是来自candump,所以从sockets到输出的一切都是由candump完成的。我只是想创建一个更高级别的程序,这样人们就不会进入这些文件并根据他们的需要更改每个 if 的参数而不接触 can 通信。
猜你喜欢
  • 2014-11-18
  • 2023-03-24
  • 2014-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多