bcm_sync.cpp
Go to the documentation of this file.
3 #include <iostream>
4 
5 int main(int argc, char** argv){
6 
7  if(argc < 4){
8  std::cout << "Usage: " << argv[0] << " DEVICE PERIOD_MS HEADER [OVERFLOW] [+ID*] [-ID*] [--]" << std::endl;
9  return 1;
10  }
11 
12  std::string can_device = argv[1];
13  int sync_ms = atoi(argv[2]);
14  can::Header header = can::toheader(argv[3]);
15 
16  if(!header.isValid()){
17  std::cout << "header is invalid" << std::endl;
18  return 1;
19  }
20  int sync_overflow = 0;
21 
22  int start = 4;
23  if(argc > start && argv[start][0] != '-' && argv[start][0] != '+'){
24  sync_overflow = atoi(argv[4]);
25  if(sync_overflow == 1 || sync_overflow < 0 || sync_overflow > 240){
26  std::cout << "sync overflow is invalid" << std::endl;
27  return 1;
28  }
29  ++start;
30  }
31 
32  std::set<int> monitored, ignored;
33 
34  for(; argc > start; ++start){
35  if(strncmp("--", argv[start], 2) == 0) break;
36  int id = atoi(argv[start]);
37 
38  if(id > 0 && id < 128) monitored.insert(id);
39  else if (id < 0 && id > -128) ignored.insert(-id);
40  else{
41  std::cout << "ID is invalid: " << id << std::endl;
42  return 1;
43  }
44  }
45 
46  can::SocketCANDriverSharedPtr driver = std::make_shared<can::SocketCANDriver>();
47  if(!driver->init(can_device, false, can::NoSettings::create())){
48  std::cout << "Could not initialize CAN" << std::endl;
49  return 1;
50  }
51 
52  canopen::SyncProperties sync_properties(header, sync_ms, sync_overflow);
53  canopen::BCMsync sync(can_device, driver, sync_properties);
54 
55  sync.setMonitored(monitored);
56  sync.setIgnored(ignored);
57 
58  canopen::LayerStatus status;
59  sync.init(status);
60  if(!status.bounded<canopen::LayerStatus::Warn>()){
61  std::cout << "Could not initialize sync" << std::endl;
62  return 1;
63  }
64 
65  driver->run();
66 
67  return 0;
68 }
void init(LayerStatus &status)
Definition: layer.h:86
Header toheader(const std::string &s)
bool isValid() const
void setMonitored(const T &other)
Definition: bcm_sync.h:156
void setIgnored(const T &other)
Definition: bcm_sync.h:160
int main(int argc, char **argv)
Definition: bcm_sync.cpp:5
bool bounded() const
Definition: layer.h:35
std::shared_ptr< SocketCANDriver > SocketCANDriverSharedPtr
static SettingsConstSharedPtr create()


canopen_master
Author(s): Mathias Lüdtke
autogenerated on Mon Feb 28 2022 23:28:03