如何编写使用其他 C 程序的父程序?

How to write a parent program that is using other C programs?

我正在制作一个 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 标准的 can 程序制作的。

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

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

类似于:

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

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

更好的方法是为这些东西获取适当的接口,然后 link 将它们放入您的二进制文件中。查看 candumpcansend 的实现并调用类似的函数。这应该可以让您更好地控制系统的整体工作方式。