-3

I am making a can-bus network that will survey some sensors to gather data in order to have better understanding of an environment that we want to analyse and control. In order to do so we use candump to monitor traffic and can send to sen information (from CAN-BUS files that can be find in this address: https://github.com/linux-can/can-utils.git). I modified some of the codes and they compile well, now what I want to do is to make a parent code that can orchestrate this C programs in order to control the environment. I want to use python or c++ to do this.

Example Algorithm

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") }

}

Thanks beforehand for all type of suggestions.

I have tried to work with a IDE but I can't compile anything because the makefile that is used is specificly made for can programs with the iso standarts for CANBUS.

I want to call and put or get basic info with c functions like I am on a terminal with this code.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483

1 Answers1

2

You can use std::system to run the other programs.

Something like:

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

This is overall a horrible way to get the job done. You need to redirect output from those lower level programs (candump more_params >output.txt) to files is you want to do anything with that. If you only want something simple might be just enough.

A better way is to get a proper interface into these things and link them into your binary. Check out what candump and cansend are implemented and call similar functions. This should give you better control over how the system works overall.

Ruks
  • 3,886
  • 1
  • 10
  • 22
Sorin
  • 11,863
  • 22
  • 26
  • Actually output is from candump so everything from sockets to output is done by candump. I just want to creat a higher level of program so people won't get in to those files and change the parameters of each if to their needs without touching the can communication. – Deniz Tohumcu Jan 25 '19 at 15:49