MRPT  1.9.9
CCANBusReader.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 // This file contains portions of code from sicklms200.cc from the Player/Stage
11 // project.
12 
13 #include "hwdrivers-precomp.h" // Precompiled headers
14 
15 #include <mrpt/system/crc.h>
16 #include <mrpt/system/CTicTac.h>
17 #include <mrpt/system/os.h>
18 #include <cstdio> // printf
19 #include <cstring> // memset
21 
22 #include <thread>
23 #include <iostream>
24 
26 
27 #define RET_ERROR(msg) \
28  { \
29  cout << "[" << __CURRENT_FUNCTION_NAME__ << "] " << msg << endl; \
30  return false; \
31  }
32 
33 using namespace std;
34 using namespace mrpt;
35 using namespace mrpt::obs;
36 using namespace mrpt::hwdrivers;
37 using namespace mrpt::system;
38 
39 char hexCharToInt(char n)
40 {
41  if (n >= '0' && n <= '9')
42  return (n - '0');
43  else
44 
45  if (n >= 'A' && n <= 'F')
46  return (n - 'A' + 10);
47  else
48  return 0;
49 }
50 
51 /*-------------------------------------------------------------
52  CCANBusReader
53 -------------------------------------------------------------*/
54 CCANBusReader::CCANBusReader()
55  : mrpt::system::COutputLogger("CCANBusReader"),
56  m_com_port(),
57  m_mySerialPort(nullptr),
58  m_com_baudRate(57600),
59  m_nTries_connect(1),
60  m_nTries_current(0),
61  m_canbus_speed(250000),
62  m_canreader_timestamp(false),
63  m_CANBusChannel_isOpen(false)
64 {
65  m_sensorLabel = "CANBusReader";
67 }
68 
69 /*-------------------------------------------------------------
70  ~CCANBusReader
71 -------------------------------------------------------------*/
73 {
75  {
76  try
77  {
79  }
80  catch (...)
81  {
82  }
83  }
84 
85  if (m_mySerialPort)
86  {
87  delete m_mySerialPort;
88  m_mySerialPort = nullptr;
89  }
90 }
91 
93 {
95  mrpt::make_aligned_shared<mrpt::obs::CObservationCANBusJ1939>();
96  bool thereIsObservation;
97  bool hardwareError;
98 
99  doProcessSimple(thereIsObservation, *obs, hardwareError);
100  if (thereIsObservation)
101  appendObservation(obs);
102  else
103  cout << "No frame received" << endl;
104 }
105 
106 /*-------------------------------------------------------------
107  doProcess
108 -------------------------------------------------------------*/
110  bool& outThereIsObservation,
111  mrpt::obs::CObservationCANBusJ1939& outObservation, bool& hardwareError)
112 {
113  outThereIsObservation = false;
114  hardwareError = false;
115 
116  if (!tryToOpenComms())
117  {
118  hardwareError = true;
119  return;
120  }
121 
122  m_state = ssWorking;
123 
124  // Wait for a scan:
125  uint8_t out_prio, out_pdu_format, out_pdu_spec, out_src_address,
126  out_data_length;
127  uint16_t out_pgn;
128  vector<uint8_t> out_data;
129  vector<char> out_raw_frame;
131  out_prio, out_pdu_format, out_pdu_spec, out_src_address,
132  out_data_length, out_pgn, out_data, out_raw_frame))
133  return;
134 
135  // Yes, we have a new scan:
136  // cout << "we've got a frame" << endl;
137  // -----------------------------------------------
138  // Extract the observation:
139  // -----------------------------------------------
140  outObservation.timestamp = mrpt::system::now();
141  outObservation.sensorLabel = m_sensorLabel; // Set label
142 
143  // And the scan ranges:
144  outObservation.m_priority = out_prio;
145  outObservation.m_pdu_spec = out_pdu_spec;
146  outObservation.m_pdu_format = out_pdu_format;
147  outObservation.m_src_address = out_src_address;
148  outObservation.m_pgn = out_pgn;
149  outObservation.m_data_length = out_data_length;
150  outObservation.m_data.resize(out_data.size());
151  for (uint8_t k = 0; k < out_data.size(); ++k)
152  outObservation.m_data[k] = out_data[k];
153  outObservation.m_raw_frame.resize(out_raw_frame.size());
154  for (uint8_t k = 0; k < out_raw_frame.size(); ++k)
155  outObservation.m_raw_frame[k] = out_raw_frame[k];
156 
157  // we've got a new observation
158  outThereIsObservation = true;
159 }
160 
161 /*-------------------------------------------------------------
162  loadConfig_sensorSpecific
163 -------------------------------------------------------------*/
165  const mrpt::config::CConfigFileBase& configSource,
166  const std::string& iniSection)
167 {
168  // m_sensorPose = CPose3D(
169  // configSource.read_float(iniSection,"pose_x",0),
170  // configSource.read_float(iniSection,"pose_y",0),
171  // configSource.read_float(iniSection,"pose_z",0),
172  // DEG2RAD( configSource.read_float(iniSection,"pose_yaw",0) ),
173  // DEG2RAD( configSource.read_float(iniSection,"pose_pitch",0) ),
174  // DEG2RAD( configSource.read_float(iniSection,"pose_roll",0) )
175  // ); // irrelevant
176 
178  configSource.read_int(iniSection, "CANBusSpeed", m_canbus_speed);
179  m_canreader_timestamp = configSource.read_bool(
180  iniSection, "useCANReaderTimestamp", m_canreader_timestamp);
181 
182 #ifdef _WIN32
183  m_com_port =
184  configSource.read_string(iniSection, "COM_port_WIN", m_com_port, true);
185 #else
186  m_com_port =
187  configSource.read_string(iniSection, "COM_port_LIN", m_com_port, true);
188 #endif
189 
191  configSource.read_int(iniSection, "COM_baudRate", m_com_baudRate);
193  configSource.read_int(iniSection, "nTries_connect", m_nTries_connect);
194 }
195 
196 /*-------------------------------------------------------------
197  Tries to open the com port and setup
198  all the LMS protocol. Returns true if OK or already open.
199 -------------------------------------------------------------*/
201 {
202  if (err_msg) *err_msg = "";
203  try
204  {
205  if (!m_mySerialPort)
206  {
207  // There is no COMMS port open yet...
208  if (!m_com_port.empty())
209  {
210  // cout << "Creating port" << endl;
212  new mrpt::comms::CSerialPort(); // Create the port myself:
213  }
214  else
215  throw std::logic_error(
216  "ERROR: No serial port attached with bindIO, neither it "
217  "set with 'setSerialPort'");
218  }
219 
220  // We assure now we have a stream... try to open it, if it's not done
221  // yet.
222  bool just_open = false;
223  if (m_mySerialPort != nullptr)
224  {
225  if (!m_mySerialPort->isOpen())
226  {
227  // Try to open it now:
229  m_mySerialPort->open(); // will raise an exception on error.
230 
231  // Set basic params:
232  m_mySerialPort->setConfig(9600);
233  m_mySerialPort->setTimeouts(100, 0, 10, 0, 50);
234 
235  just_open = true;
236  }
237  }
238 
239  // It seems the port was open and working so we are done here.
240  if (!just_open) return true;
241 
242  // ==================================================================
243  // Otherwise, it was just opened now, we must send the
244  // ** initialization commands **
245  // and put the CAN Converter in recording mode:
246  // ==================================================================
247  cout << "Setting up serial comms in port " << m_com_port;
248  if (!setupSerialComms()) RET_ERROR("error");
249  cout << " ... done" << endl;
250 
251  // initialize
252  // set CAN Bus speed
253  /**/
254  bool res;
255  cout << "Setting up CAN BUS Speed at: " << m_canbus_speed << endl;
256  for (int nTry = 0; nTry < 250000 /*4*/; nTry++)
257  if (true == (res = sendCANBusReaderSpeed())) break;
258  if (!res) return false;
259  cout << " ... done" << endl;
260 
261  // open the CAN channel. If true, at this point, frames should be poping
262  // out the CAN Bus
263  cout << "Opening CAN BUS and starting to receive." << endl;
264  for (int nTry = 0; nTry < 250000 /*4*/; nTry++)
265  if (true == (res = CANBusOpenChannel())) break;
266  if (!res) return false;
267  cout << " ... done" << endl;
268 
269  // cout << "Autopoll" << endl;
270  // for (int nTry=0;nTry<250000/*4*/;nTry++)
271  // if (true==(res=CANBusAutoPoll()))
272  // break;
273  // if(!res) return false;
274  // cout << " ... done" << endl;
275 
276  return res;
277  /**/
278  }
279  catch (std::exception& e)
280  {
281  std::string s =
282  "[CCANBusReader] Error trying to open CANBusReader at port ";
283  s += e.what();
284  if (err_msg) *err_msg = s;
286  return false;
287  }
288 }
289 
290 /*-------------------------------------------------------------
291  Tries to send the command to set up the speed of the
292  CAN Bus reader -> tractor link
293 -------------------------------------------------------------*/
295 {
296  // command: S0 --> S8 according to the selected speed
297  unsigned char cmd[2];
298 
299  cmd[0] = 'S';
300  switch (m_canbus_speed)
301  {
302  case 10000:
303  cmd[1] = '0';
304  break;
305  case 20000:
306  cmd[1] = '1';
307  break;
308  case 50000:
309  cmd[1] = '2';
310  break;
311  case 100000:
312  cmd[1] = '3';
313  break;
314  case 125000:
315  cmd[1] = '4';
316  break;
317  case 250000:
318  cmd[1] = '5';
319  break;
320  case 500000:
321  cmd[1] = '6';
322  break;
323  case 800000:
324  cmd[1] = '7';
325  break;
326  case 1000000:
327  cmd[1] = '8';
328  break;
329  default:
330  RET_ERROR("Incorrect CAN Bus speed");
331  break;
332  }
333  sendCommandToCANReader(cmd, 2);
334  return waitACK(50);
335 }
336 
338 {
339  unsigned char cmd[1];
340  cmd[0] = 'O';
341  sendCommandToCANReader(cmd, 1);
343  return m_CANBusChannel_isOpen;
344 }
345 
347 {
348  unsigned char cmd[1];
349  cmd[0] = 'C';
350  sendCommandToCANReader(cmd, 1);
351  // m_CANBusChannel_isOpen = !waitACK(50);
352  m_CANBusChannel_isOpen = false;
353  // return !m_CANBusChannel_isOpen;
354  return true;
355 }
356 
358 {
359  unsigned char cmd[1];
360  cmd[0] = 'A';
361  sendCommandToCANReader(cmd, 1);
362  return waitACK(50);
363 }
364 
366 {
367  unsigned char cmd[2];
368  cmd[0] = 'X';
369  cmd[1] = '1';
370  sendCommandToCANReader(cmd, 2);
371  return waitACK(50);
372 }
373 
375 {
376  unsigned char cmd[1];
377  cmd[0] = 'P';
378  sendCommandToCANReader(cmd, 1);
379  return waitACK(50);
380 }
381 
382 /*-------------------------------------------------------------
383  waitContinuousSampleFrame
384 -------------------------------------------------------------*/
386  uint8_t& out_prio, uint8_t& out_pdu_format, uint8_t& out_pdu_spec,
387  uint8_t& out_src_address, uint8_t& out_data_length, uint16_t& out_pgn,
388  vector<uint8_t>& out_data, vector<char>& out_raw_frame)
389 {
390  size_t nRead, nBytesToRead;
391  size_t nFrameBytes = 0;
392  size_t lengthField;
393  unsigned char buf[40];
394 
395  // clear buffer
396  for (uint8_t k = 0; k < 40; ++k) buf[k] = 0;
397 
398  uint8_t dlc = 0;
399  while (nFrameBytes < (lengthField = (10U + dlc + 1U)))
400  {
401  // cout << "trying to receive" << endl;
402  if (lengthField > 30)
403  {
404  cout << "#" << int(dlc) << " ";
405  nFrameBytes = 0; // No es cabecera de trama correcta
406  for (uint8_t k = 0; k < 40; ++k) buf[k] = 0;
407  dlc = 0;
408  }
409 
410  if (nFrameBytes < 10)
411  nBytesToRead = 1;
412  else
413  {
414  dlc = 2 * uint8_t(hexCharToInt(buf[9]));
415  // cout << "dlc: " << int(dlc) << endl;
416  nBytesToRead = (lengthField)-nFrameBytes;
417  }
418 
419  try
420  {
421  nRead = m_mySerialPort->Read(buf + nFrameBytes, nBytesToRead);
422  // cout << "to read: " << nBytesToRead << " received: " <<
423  // nRead << " -> ";
424  // for( uint8_t k = 0; k < nRead; ++k )
425  // cout << int(buf[k+nFrameBytes]);
426  // cout << endl;
427  }
428  catch (std::exception& e)
429  {
430  // Disconnected?
432  "[waitContinuousSampleFrame] Disconnecting due to comms error: "
433  << e.what());
434  return false;
435  }
436 
437  if (!nRead) return false;
438 
439  if (nRead < nBytesToRead) std::this_thread::sleep_for(30ms);
440 
441  // Reading OK:
442  // Was it the first one?
443  if (nFrameBytes > 0 || (nFrameBytes == 0 && buf[0] == 0x54 /*T*/))
444  nFrameBytes += nRead;
445  else
446  {
447  nFrameBytes = 0; // No es cabecera de trama correcta
448  for (uint8_t k = 0; k < 40; ++k) buf[k] = 0;
449  }
450  } // end while
451 
452  // Process frame
453  // convert ASCII text into integer
454  vector<uint8_t> aux;
455  out_raw_frame.resize(nFrameBytes);
456  for (uint8_t k = 0; k < nFrameBytes; ++k)
457  {
458  aux.push_back(hexCharToInt(buf[k]));
459  out_raw_frame[k] = buf[k];
460  }
461 
462  out_prio = (aux[1] << 2) | (aux[2] >> 2);
463  out_pdu_format = (aux[3] << 4) | aux[4];
464  out_pdu_spec = (aux[5] << 4) | aux[6];
465  out_src_address = (aux[7] << 4) | aux[8];
466  out_data_length = aux[9];
467  out_pgn = uint16_t(out_pdu_format) << 8 | uint16_t(out_pdu_spec);
468  out_data.resize(out_data_length);
469  for (uint8_t k = 0, k2 = 0; k < 2 * out_data_length; k += 2, k2++)
470  out_data[k2] = (aux[10 + k] << 4) | aux[11 + k];
471 
472  if (buf[nFrameBytes - 1] != 0x0D)
473  {
474  cout << format(
475  "[CCANBusReader::waitContinuousSampleFrame] expected 0x0D "
476  "ending flag, 0x%X found instead",
477  buf[nFrameBytes])
478  << endl;
479  return false; // Bad ending flag
480  }
481 
482  // All OK
483  return true;
484 }
485 
486 /*-------------------------------------------------------------
487  initialize
488 -------------------------------------------------------------*/
490 {
491  string err_str;
493  if (!tryToOpenComms(&err_str))
494  {
495  cerr << err_str << endl;
496  throw std::logic_error(err_str);
497  }
498 }
499 
500 /*-----------------------------------------------------------------
501  Assures laser is connected and operating at 38400, in
502  its case returns true.
503  -----------------------------------------------------------------*/
505 {
506  ASSERT_(
507  m_com_baudRate == 9600 || m_com_baudRate == 38400 ||
508  m_com_baudRate == 57600 || m_com_baudRate == 500000);
509 
510  if (m_mySerialPort == nullptr) return true;
511 
512  int detected_rate = 0;
513  for (size_t reps = 0; !detected_rate && reps < m_nTries_connect; reps++)
514  {
515  m_nTries_current = reps;
516 
517  int rates[] = {0, 9600, 38400, 57600, 500000};
518 
519  // Try first the desired rate to speed up the process, just in case
520  // the converter is already setup from a previous run:
521  rates[0] = m_com_baudRate;
522 
523  detected_rate = 0;
524 
525  for (size_t i = 0;
526  !detected_rate && i < sizeof(rates) / sizeof(rates[0]); i++)
527  {
528  // Are we already receiving at 500k?
529  // ------------------------------------------------
530  m_mySerialPort->setConfig(rates[i]);
531  std::this_thread::sleep_for(100ms);
533 
534  // close the connection
535  /**/
536  cout << endl << "Closing CAN Channel " << endl;
537  for (int nTry = 0; nTry < 250000 /*4*/; nTry++)
538  if (true == CANBusCloseChannel()) break;
539  cout << " ... done" << endl;
540  /**/
541 
542  std::this_thread::sleep_for(100ms);
544 
545  for (int nTry = 0; nTry < 250000 /*4*/ && !detected_rate; nTry++)
546  {
548 
549  // Ask for the laser version at the current rate:
550  if (queryVersion(true))
551  {
552  detected_rate = rates[i];
553  break;
554  }
555  std::this_thread::sleep_for(20ms);
556  } // for tries
557  // There is no link, or the baudrate is wrong...
558  }
559 
560  // Try again in a while:
561  if (!detected_rate && reps != (m_nTries_connect - 1))
562  std::this_thread::sleep_for(5000ms);
563  }
564 
565  // Switch "this" serial port to the detected baudrate
566  setBaudRate(detected_rate);
567 
570 
571  // Wait...
572  std::this_thread::sleep_for(500ms);
573 
574  // And check comms at the new baud rate:
575  return true;
576 }
577 
578 /*-----------------------------------------------------------------
579  Query to LMS a status query.
580  Returns true if response is read ok.
581  -----------------------------------------------------------------*/
582 bool CCANBusReader::queryVersion(bool printOutVersion)
583 {
585 
586  uint8_t cmd[1];
587  cmd[0] = 'V';
588  uint16_t cmd_len = 1;
589 
590  if (!sendCommandToCANReader(cmd, cmd_len, false)) return false;
591  return waitForVersion(500, printOutVersion);
592 }
593 
594 // Returns false if timeout
596 {
597  uint8_t b = 0;
598  CTicTac tictac;
599  tictac.Tic();
600 
601  do
602  {
603  if (m_mySerialPort->Read(&b, 1))
604  {
605  // Byte rx:
606  if (b == 0x0D /*0x30*/)
607  {
608  cout << int(b) << endl;
609  return true; // [CR]
610  }
611  }
612  } while (tictac.Tac() < timeout_ms * 1e-3);
613 
614  if (b == 0x07) // [BELL]
615  RET_ERROR(format("ERROR received."))
616  else if (b != 0)
617  RET_ERROR(format("Unexpected code received: 0x%02X", b))
618  else
619  return false; // RET_ERROR("Timeout")
620 }
621 
622 bool CCANBusReader::waitForVersion(uint16_t timeout, bool printOutVersion)
623 {
624  uint8_t b;
625  unsigned int nBytes = 0;
626 
627  CTicTac tictac;
628  tictac.Tic();
629  const double maxTime = timeout * 1e-3;
630 
631  while (nBytes < 6)
632  {
633  if (m_mySerialPort->Read(&b, 1))
634  {
635  // cout << "received " << nBytes << " bytes: " << char(b)
636  //<<
637  // endl;
638  // First byte must be STX:
639  if (nBytes > 0 || (nBytes == 0 && b == 'V'))
640  {
641  // Store in frame:
642  m_received_frame_buffer[nBytes] = b;
643  nBytes++;
644  }
645  }
646  if (tictac.Tac() >= maxTime)
647  {
648  cout << "Version timeout" << endl;
649  return false; // Timeout
650  }
651  }
652 
653  // Check len:
654  if (m_received_frame_buffer[nBytes - 1] != 0x0D)
655  {
656  printf(
657  "[CCANBusReader::waitForVersion] Error: expected 0x0D final byte, "
658  "received %x\n",
659  m_received_frame_buffer[nBytes - 1]);
660  return false;
661  }
662 
663  if (printOutVersion)
664  {
665  cout << "Version: ";
666  for (uint8_t k = 0; k < nBytes; ++k)
667  cout << char(m_received_frame_buffer[k]);
668  cout << endl;
669  }
670  return true;
671 }
672 // Returns false if timeout
674 {
675  uint8_t b;
676  unsigned int nBytes = 0;
677 
678  CTicTac tictac;
679  tictac.Tic();
680  const double maxTime = timeout * 1e-3;
681  uint8_t dlc = 0;
682  while (nBytes < 10 || (nBytes < (10U + dlc + 1U /*CR*/)))
683  {
684  if (m_mySerialPort->Read(&b, 1))
685  {
686  // First byte must be STX:
687  if (nBytes > 1 || (!nBytes && b == 0x54 /*'T'*/))
688  {
689  // Store in frame:
690  m_received_frame_buffer[nBytes] = b;
691  nBytes++;
692  }
693  if (nBytes == 10)
694  dlc = 2 * uint8_t(
695  hexCharToInt(
696  m_received_frame_buffer[9])); // here is the
697  // number of
698  // BYTES of
699  // data -> 2
700  // hex values
701  // for byte
702  }
703  if (tictac.Tac() >= maxTime) return false; // Timeout
704  }
705  // Check final flag
706  if (m_received_frame_buffer[10U + dlc] != 0x0D)
707  {
708  printf(
709  "[CCANBusReader::waitIncomingFrame] Error: expected 0x0D as final "
710  "flag, received %x\n",
711  m_received_frame_buffer[10U + dlc]);
712  return false;
713  }
714 
715 #if 0
716  printf("RX: ");
717  for (unsigned int i=0;i<nBytes;i++)
718  printf("%02X ",m_received_frame_buffer[i]);
719  printf("\n");
720 #endif
721 
722  // OK
723  return true;
724 }
725 
727  const uint8_t* cmd, const uint16_t cmd_len, bool wait)
728 {
729  MRPT_UNUSED_PARAM(wait);
730  uint8_t cmd_full[1024];
731  ASSERT_(sizeof(cmd_full) > cmd_len);
732 
733  // command is just plain text so no frame header nor CRC is needed
734  memcpy(cmd_full, cmd, cmd_len);
735  cmd_full[cmd_len] = 0x0D; // [CR] at the end
736 
737  const size_t toWrite = cmd_len + 1;
738 
739 #if 1
740  printf("TX: ");
741  for (unsigned int i = 0; i < toWrite; i++) printf("%02X ", cmd_full[i]);
742  printf("\n");
743 #endif
744 
745  // const int NTRIES = 3;
746 
747  // for (int k=0;k<NTRIES;k++)
748  // {
749  if (toWrite != m_mySerialPort->Write(cmd_full, toWrite))
750  {
751  cout << "[CCANBusReader::SendCommandToCANReader] Error writing data to "
752  "serial port."
753  << endl;
754  return false;
755  }
756  return true;
757  // std::this_thread::sleep_for(15ms);
758  // if(wait)
759  // {
760  // if(waitACK(5000))
761  // return true;
762  // std::this_thread::sleep_for(10ms);
763  // }
764  // else
765  // return true; // perform special wait outside this method
766  // }
767 
768  return false;
769 }
double Tac() noexcept
Stops the stopwatch.
Definition: CTicTac.cpp:90
bool sendCANBusReaderSpeed()
Sends the specified speed to the CAN Converter.
void loadConfig_sensorSpecific(const mrpt::config::CConfigFileBase &configSource, const std::string &iniSection)
See the class documentation at the top for expected parameters.
unsigned __int16 uint16_t
Definition: rptypes.h:44
void appendObservation(const mrpt::serialization::CSerializable::Ptr &obj)
Like appendObservations() but for just one observation.
std::string read_string(const std::string &section, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
A communications serial port built as an implementation of a utils::CStream.
Definition: CSerialPort.h:41
bool waitACK(uint16_t timeout_ms)
char hexCharToInt(char n)
std::string m_sensorLabel
See CGenericSensor.
bool waitContinuousSampleFrame(uint8_t &out_prio, uint8_t &out_pdu_format, uint8_t &out_pdu_spec, uint8_t &out_src_address, uint8_t &out_data_length, uint16_t &out_pgn, std::vector< uint8_t > &out_data, std::vector< char > &out_raw_frame)
This class stores a message from a CAN BUS with the protocol J1939.
GLenum GLsizei n
Definition: glext.h:5074
void doProcessSimple(bool &outThereIsObservation, mrpt::obs::CObservationCANBusJ1939 &outObservation, bool &hardwareError)
Specific laser scanner "software drivers" must process here new data from the I/O stream...
A high-performance stopwatch, with typical resolution of nanoseconds.
void open()
Open the port.
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Definition: datetime.h:87
Contains classes for various device interfaces.
bool waitIncomingFrame(uint16_t timeout)
STL namespace.
void setBaudRate(int baud)
Changes the serial port baud rate (call prior to &#39;doProcess&#39;); valid values are 9600,38400 and 500000.
GLdouble s
Definition: glext.h:3676
void setConfig(int baudRate, int parity=0, int bits=8, int nStopBits=1, bool enableFlowControl=false)
Changes the configuration of the port.
int read_int(const std::string &section, const std::string &name, int defaultValue, bool failIfNotFound=false) const
unsigned char uint8_t
Definition: rptypes.h:41
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
void doProcess()
This method will be invoked at a minimum rate of "process_rate" (Hz)
bool CANBusCloseChannel()
Closes the CAN Channel.
This class allows loading and storing values and vectors of different types from a configuration text...
bool waitForVersion(uint16_t timeout, bool printOutVersion=false)
#define RET_ERROR(msg)
virtual ~CCANBusReader()
Destructor.
Versatile class for consistent logging and management of output messages.
void setSerialPortName(const std::string &COM_name)
Sets the serial port to open (it is an error to try to change this while open yet).
Definition: CSerialPort.cpp:97
This "software driver" implements the communication protocol for interfacing a SICK LMS 2XX laser sca...
Definition: CCANBusReader.h:58
bool isOpen() const
Returns if port has been correctly open.
This namespace contains representation of robot actions and observations.
size_t Write(const void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for writing to the stream.
GLubyte GLubyte b
Definition: glext.h:6279
void purgeBuffers()
Purge tx and rx buffers.
uint8_t m_received_frame_buffer[2000]
Definition: CCANBusReader.h:89
bool tryToOpenComms(std::string *err_msg=nullptr)
Tries to open the com port and setup all the LMS protocol.
GLsizei const GLchar ** string
Definition: glext.h:4101
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
void setTimeouts(int ReadIntervalTimeout, int ReadTotalTimeoutMultiplier, int ReadTotalTimeoutConstant, int WriteTotalTimeoutMultiplier, int WriteTotalTimeoutConstant)
Changes the timeouts of the port, in milliseconds.
void initialize()
Set-up communication with the laser.
std::string sensorLabel
An arbitrary label that can be used to identify the sensor.
Definition: CObservation.h:62
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp.
Definition: CObservation.h:60
bool sendCommandToCANReader(const uint8_t *cmd, const uint16_t cmd_len, bool wait=true)
bool read_bool(const std::string &section, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
std::vector< char > m_raw_frame
The ASCII frame.
mrpt::comms::CSerialPort * m_mySerialPort
Will be !=nullptr only if I created it, so I must destroy it at the end.
Definition: CCANBusReader.h:97
uint16_t m_pgn
The Parameter Group Number within this frame.
std::string m_com_port
If set to non-empty, the serial port will be attempted to be opened automatically when this class is ...
Definition: CCANBusReader.h:94
int m_com_baudRate
Baudrate: 9600, 38400, 500000.
Definition: CCANBusReader.h:99
uint8_t m_src_address
The address of the source node within this frame.
GLuint res
Definition: glext.h:7268
void Tic() noexcept
Starts the stopwatch.
Definition: CTicTac.cpp:79
#define MRPT_LOG_ERROR_STREAM(__CONTENTS)
std::vector< uint8_t > m_data
The data within this frame (0-8 bytes)
size_t Read(void *Buffer, size_t Count)
Implements the virtual method responsible for reading from the stream - Unlike CStream::ReadBuffer, this method will not raise an exception on zero bytes read, as long as there is not any fatal error in the communications.
bool CANBusOpenChannel()
Opens the CAN Channel.
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
Definition: os.cpp:356
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
Definition: common.h:186
bool queryVersion(bool printOutVersion=false)
unsigned int m_nTries_connect
Default = 1.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020