public.cc
Go to the documentation of this file.
1 
37 #include <stdlib.h>
38 #include <algorithm>
39 
41 
42 #include "details/channel.hh"
43 #include "details/query.hh"
44 
49 
54 
60 
62 
66 
69 
72 
92 
97 
100 
101 namespace crl {
102 namespace multisense {
103 namespace details {
104 
105 //
106 // The user may "hold on" to the buffer back-end
107 // of a datum within a callback thread.
108 
110 
111 //
112 //
113 // Public API follows
114 //
115 //
116 
117 //
118 // Adds a new image listener
119 
121  DataSource imageSourceMask,
122  void *userDataP)
123 {
124  try {
125 
127  m_imageListeners.push_back(new ImageListener(callback,
128  imageSourceMask,
129  userDataP,
131 
132  } catch (const std::exception& e) {
133  CRL_DEBUG("exception: %s\n", e.what());
134  return Status_Exception;
135  }
136  return Status_Ok;
137 }
138 
139 //
140 // Adds a new laser listener
141 
143  void *userDataP)
144 {
145  try {
146 
148  m_lidarListeners.push_back(new LidarListener(callback,
149  0,
150  userDataP,
152 
153  } catch (const std::exception& e) {
154  CRL_DEBUG("exception: %s\n", e.what());
155  return Status_Exception;
156  }
157  return Status_Ok;
158 }
159 
160 //
161 // Adds a new PPS listener
162 
164  void *userDataP)
165 {
166  try {
167 
169  m_ppsListeners.push_back(new PpsListener(callback,
170  0,
171  userDataP,
173 
174  } catch (const std::exception& e) {
175  CRL_DEBUG("exception: %s\n", e.what());
176  return Status_Exception;
177  }
178  return Status_Ok;
179 }
180 
181 //
182 // Adds a new IMU listener
183 
185  void *userDataP)
186 {
187  try {
188 
190  m_imuListeners.push_back(new ImuListener(callback,
191  0,
192  userDataP,
194 
195  } catch (const std::exception& e) {
196  CRL_DEBUG("exception: %s\n", e.what());
197  return Status_Exception;
198  }
199  return Status_Ok;
200 }
201 
202 //
203 // Removes an image listener
204 
206 {
207  try {
209 
210  std::list<ImageListener*>::iterator it;
211  for(it = m_imageListeners.begin();
212  it != m_imageListeners.end();
213  it ++) {
214 
215  if ((*it)->callback() == callback) {
216  delete *it;
217  m_imageListeners.erase(it);
218  return Status_Ok;
219  }
220  }
221 
222  } catch (const std::exception& e) {
223  CRL_DEBUG("exception: %s\n", e.what());
224  return Status_Exception;
225  }
226 
227  return Status_Error;
228 }
229 
230 //
231 // Removes a lidar listener
232 
234 {
235  try {
237 
238  std::list<LidarListener*>::iterator it;
239  for(it = m_lidarListeners.begin();
240  it != m_lidarListeners.end();
241  it ++) {
242 
243  if ((*it)->callback() == callback) {
244  delete *it;
245  m_lidarListeners.erase(it);
246  return Status_Ok;
247  }
248  }
249 
250  } catch (const std::exception& e) {
251  CRL_DEBUG("exception: %s\n", e.what());
252  return Status_Exception;
253  }
254 
255  return Status_Error;
256 }
257 
258 //
259 // Removes a PPS listener
260 
262 {
263  try {
265 
266  std::list<PpsListener*>::iterator it;
267  for(it = m_ppsListeners.begin();
268  it != m_ppsListeners.end();
269  it ++) {
270 
271  if ((*it)->callback() == callback) {
272  delete *it;
273  m_ppsListeners.erase(it);
274  return Status_Ok;
275  }
276  }
277 
278  } catch (const std::exception& e) {
279  CRL_DEBUG("exception: %s\n", e.what());
280  return Status_Exception;
281  }
282 
283  return Status_Error;
284 }
285 
286 //
287 // Removes an IMU listener
288 
290 {
291  try {
293 
294  std::list<ImuListener*>::iterator it;
295  for(it = m_imuListeners.begin();
296  it != m_imuListeners.end();
297  it ++) {
298 
299  if ((*it)->callback() == callback) {
300  delete *it;
301  m_imuListeners.erase(it);
302  return Status_Ok;
303  }
304  }
305 
306  } catch (const std::exception& e) {
307  CRL_DEBUG("exception: %s\n", e.what());
308  return Status_Exception;
309  }
310 
311  return Status_Error;
312 }
313 
314 //
315 // Reserve the current callback buffer being used in a dispatch thread
316 
318 {
319  if (dispatchBufferReferenceTP) {
320 
321  try {
322 
323  return reinterpret_cast<void*>(new utility::BufferStream(*dispatchBufferReferenceTP));
324 
325  } catch (const std::exception& e) {
326 
327  CRL_DEBUG("exception: %s\n", e.what());
328 
329  } catch (...) {
330 
331  CRL_DEBUG_RAW("unknown exception\n");
332  }
333  }
334 
335  return NULL;
336 }
337 
338 //
339 // Release a user reserved buffer back to us
340 
342 {
343  if (referenceP) {
344  try {
345 
346  delete reinterpret_cast<utility::BufferStream*>(referenceP);
347  return Status_Ok;
348 
349  } catch (const std::exception& e) {
350 
351  CRL_DEBUG("exception: %s\n", e.what());
352  return Status_Exception;
353 
354  } catch (...) {
355 
356  CRL_DEBUG_RAW("unknown exception\n");
357  return Status_Exception;
358  }
359  }
360 
361  return Status_Error;
362 }
363 
364 //
365 // Get a copy of the histogram for a particular frame ID
366 
368  image::Histogram& histogram)
369 {
370  try {
371 
373 
374  const wire::ImageMeta *metaP = m_imageMetaCache.find_nolock(frameId);
375  if (NULL == metaP) {
376  CRL_DEBUG("no meta cached for frameId %ld",
377  static_cast<long int>(frameId));
378  return Status_Failed;
379  }
380 
383 
384  const int entries = histogram.channels * histogram.bins;
385  const int sizeBytes = entries * sizeof(uint32_t);
386 
387  histogram.data.resize(entries);
388  memcpy(&(histogram.data[0]), metaP->histogramP, sizeBytes);
389 
390  return Status_Ok;
391 
392  }
393  catch (const std::exception& e) {
394  CRL_DEBUG("exception: %s\n", e.what());
395  return Status_Exception;
396  }
397  catch (...) {
398  CRL_DEBUG ("%s\n", "unknown exception");
399  }
400 
401  return Status_Error;
402 }
403 
404 Status impl::getPtpStatus(int64_t frameId,
405  system::PtpStatus &ptpStatus)
406 {
407  try {
408 
410 
411  const wire::ImageMeta *metaP = m_imageMetaCache.find_nolock(frameId);
412  if (NULL == metaP) {
413  CRL_DEBUG("no meta cached for frameId %ld",
414  static_cast<long int>(frameId));
415  return Status_Failed;
416  }
417 
418  ptpStatus = system::PtpStatus();
419 
420  return Status_Ok;
421 
422  }
423  catch (const std::exception& e) {
424  CRL_DEBUG("exception: %s\n", e.what());
425  return Status_Exception;
426  }
427  catch (...) {
428  CRL_DEBUG ("%s\n", "unknown exception");
429  }
430 
431  return Status_Error;
432 }
433 
434 //
435 // Enable/disable network-based time synchronization
436 
438 {
439  m_networkTimeSyncEnabled = enabled;
440  return Status_Ok;
441 }
442 
443 //
444 // Enable/disable PTP time synchronization
445 
447 {
448  Status status;
449 
450  wire::SysSetPtp cmd;
451  cmd.enable = enabled ? 1 : 0;
452 
453  status = waitAck(cmd);
454 
455  if (Status_Ok == status)
456  m_ptpTimeSyncEnabled = enabled;
457 
458  return status;
459 }
460 
461 //
462 // Primary stream control
463 
465 {
467 
469 
470  cmd.enable(sourceApiToWire(mask));
471 
472  Status status = waitAck(cmd);
473  if (Status_Ok == status)
474  m_streamsEnabled |= mask;
475 
476  return status;
477 }
479 {
481 
483 
484  cmd.disable(sourceApiToWire(mask));
485 
486  Status status = waitAck(cmd);
487  if (Status_Ok == status)
488  m_streamsEnabled &= ~mask;
489 
490  return status;
491 }
493 {
495 
496  mask = m_streamsEnabled;
497 
498  return Status_Ok;
499 }
500 
501 //
502 // Secondary stream control
503 
505 {
507 
508  cmd.streams.push_back(wire::DirectedStream(stream.mask,
509  stream.address,
510  stream.udpPort,
511  stream.fpsDecimation));
512  return waitAck(cmd);
513 }
514 
515 Status impl::startDirectedStreams(const std::vector<DirectedStream>& streams)
516 {
518 
519  for (uint32_t index = 0 ; index < streams.size() ; ++index) {
520  DirectedStream stream = streams[index];
521 
522  cmd.streams.push_back(wire::DirectedStream(stream.mask,
523  stream.address,
524  stream.udpPort,
525  stream.fpsDecimation));
526  }
527  return waitAck(cmd);
528 }
529 
531 {
533 
534  cmd.streams.push_back(wire::DirectedStream(stream.mask,
535  stream.address,
536  stream.udpPort,
537  stream.fpsDecimation));
538  return waitAck(cmd);
539 }
540 
541 Status impl::getDirectedStreams(std::vector<DirectedStream>& streams)
542 {
543  Status status;
545 
546  streams.clear();
547 
548  status = waitData(wire::SysGetDirectedStreams(), rsp);
549  if (Status_Ok != status)
550  return status;
551 
552  std::vector<wire::DirectedStream>::const_iterator it = rsp.streams.begin();
553  for(; it != rsp.streams.end(); ++it)
554  streams.push_back(DirectedStream((*it).mask,
555  (*it).address,
556  (*it).udpPort,
557  (*it).fpsDecimation));
558  return Status_Ok;
559 }
560 
562 {
563  maximum = MAX_DIRECTED_STREAMS;
564  return Status_Ok;
565 }
566 
567 //
568 // Set the trigger source
569 
571 {
572  uint32_t wireSource;
573 
574  switch(s) {
575  case Trigger_Internal:
576 
578  break;
579 
580  case Trigger_External:
581 
583  break;
584 
586 
588  break;
589 
590  case Trigger_PTP:
591 
593  break;
594 
595  default:
596 
597  return Status_Error;
598  }
599 
600  return waitAck(wire::CamSetTriggerSource(wireSource));
601 }
602 
603 //
604 // Set the motor speed
605 
607 {
608  return waitAck(wire::LidarSetMotor(rpm));
609 }
610 
611 //
612 // Get/set the lighting configuration
613 
615 {
616  Status status;
617  wire::LedStatus data;
618 
619  status = waitData(wire::LedGetStatus(), data);
620  if (Status_Ok != status)
621  return status;
622 
623  for(uint32_t i=0; i<lighting::MAX_LIGHTS; i++) {
624  float duty=0.0f;
625  if ((1<<i) & data.available)
626  duty = (data.intensity[i] * 100.0f) / 255;
627  c.setDutyCycle(i, duty);
628  }
629 
630  c.setFlash(data.flash != 0);
631 
632  return Status_Ok;
633 }
634 
636 {
637  wire::LedSet msg;
638 
639  msg.flash = c.getFlash() ? 1 : 0;
640  for(uint32_t i=0; i<lighting::MAX_LIGHTS; i++) {
641 
642  float duty = c.getDutyCycle(i);
643  if (duty >= 0.0f) { // less than zero == not set
644  msg.mask |= (1<<i);
645  msg.intensity[i] = static_cast<uint8_t> (255.0f * (utility::boundValue(duty, 0.0f, 100.0f) / 100.0f));
646  }
647  }
648 
649  return waitAck(msg);
650 }
651 
653 {
654  Status requestStatus;
656 
657  requestStatus = waitData(wire::LedGetSensorStatus(), data);
658  if (Status_Ok != requestStatus)
659  return requestStatus;
660 
662 
663  return Status_Ok;
664 }
665 
666 //
667 // Requests version from sensor
668 
670 {
672  return Status_Ok;
673 }
674 
675 //
676 // Version of this API
677 
679 {
680  version = API_VERSION;
681  return Status_Ok;
682 }
683 
684 //
685 // Requests all versioning information
686 
688 {
689  v.apiBuildDate = std::string(__DATE__ ", " __TIME__);
696 
697  return Status_Ok;
698 }
699 
700 //
701 // Query camera configuration
702 
704 {
705  Status status;
707 
708  status = waitData(wire::CamGetConfig(), d);
709  if (Status_Ok != status)
710  return status;
711 
712  // for access to protected calibration members
713  class ConfigAccess : public image::Config {
714  public:
715  void setCal(float fx, float fy, float cx, float cy,
716  float tx, float ty, float tz,
717  float r, float p, float w) {
718  m_fx = fx; m_fy = fy; m_cx = cx; m_cy = cy;
719  m_tx = tx; m_ty = ty; m_tz = tz;
720  m_roll = r; m_pitch = p; m_yaw = w;
721  };
722  };
723 
724  // what is the proper c++ cast for this?
725  ConfigAccess& a = *((ConfigAccess *) &config);
726 
727  a.setResolution(d.width, d.height);
728  if (-1 == d.disparities) { // pre v2.3 firmware
729  if (1024 == d.width) // TODO: check for monocular
730  d.disparities = 128;
731  else
732  d.disparities = 0;
733  }
734  a.setDisparities(d.disparities);
735  a.setFps(d.framesPerSecond);
736  a.setGain(d.gain);
737 
738  a.setExposure(d.exposure);
739  a.setAutoExposure(d.autoExposure != 0);
740  a.setAutoExposureMax(d.autoExposureMax);
741  a.setAutoExposureDecay(d.autoExposureDecay);
742  a.setAutoExposureThresh(d.autoExposureThresh);
743 
744  a.setWhiteBalance(d.whiteBalanceRed, d.whiteBalanceBlue);
745  a.setAutoWhiteBalance(d.autoWhiteBalance != 0);
746  a.setAutoWhiteBalanceDecay(d.autoWhiteBalanceDecay);
747  a.setAutoWhiteBalanceThresh(d.autoWhiteBalanceThresh);
748  a.setStereoPostFilterStrength(d.stereoPostFilterStrength);
749  a.setHdr(d.hdrEnabled);
750 
751  a.setAutoExposureRoi(d.autoExposureRoiX, d.autoExposureRoiY,
753 
754  a.setCal(d.fx, d.fy, d.cx, d.cy,
755  d.tx, d.ty, d.tz,
756  d.roll, d.pitch, d.yaw);
757 
758  a.setCameraProfile(static_cast<CameraProfile>(d.cameraProfile));
759 
760  return Status_Ok;
761 }
762 
763 //
764 // Set camera configuration
765 //
766 // Currently several sensor messages are combined and presented
767 // to the user as one.
768 
770 {
771  Status status;
772 
773  status = waitAck(wire::CamSetResolution(c.width(),
774  c.height(),
775  c.disparities(),
776  c.camMode(),
777  c.offset()));
778  if (Status_Ok != status)
779  return status;
780 
781  wire::CamControl cmd;
782 
783  cmd.framesPerSecond = c.fps();
784  cmd.gain = c.gain();
785 
786  cmd.exposure = c.exposure();
787  cmd.autoExposure = c.autoExposure() ? 1 : 0;
791 
794  cmd.autoWhiteBalance = c.autoWhiteBalance() ? 1 : 0;
798  cmd.hdrEnabled = c.hdrEnabled();
800 
805 
806  cmd.cameraProfile = static_cast<uint32_t>(c.cameraProfile());
807 
808  return waitAck(cmd);
809 }
810 
811 //
812 // Get camera calibration
813 
815 {
817 
819  if (Status_Ok != status)
820  return status;
821 
822  CPY_ARRAY_2(c.left.M, d.left.M, 3, 3);
823  CPY_ARRAY_1(c.left.D, d.left.D, 8);
824  CPY_ARRAY_2(c.left.R, d.left.R, 3, 3);
825  CPY_ARRAY_2(c.left.P, d.left.P, 3, 4);
826 
827  CPY_ARRAY_2(c.right.M, d.right.M, 3, 3);
828  CPY_ARRAY_1(c.right.D, d.right.D, 8);
829  CPY_ARRAY_2(c.right.R, d.right.R, 3, 3);
830  CPY_ARRAY_2(c.right.P, d.right.P, 3, 4);
831 
832  CPY_ARRAY_2(c.aux.M, d.aux.M, 3, 3);
833  CPY_ARRAY_1(c.aux.D, d.aux.D, 8);
834  CPY_ARRAY_2(c.aux.R, d.aux.R, 3, 3);
835  CPY_ARRAY_2(c.aux.P, d.aux.P, 3, 4);
836 
837  return Status_Ok;
838 }
839 
840 //
841 // Set camera calibration
842 
844 {
846 
847  CPY_ARRAY_2(d.left.M, c.left.M, 3, 3);
848  CPY_ARRAY_1(d.left.D, c.left.D, 8);
849  CPY_ARRAY_2(d.left.R, c.left.R, 3, 3);
850  CPY_ARRAY_2(d.left.P, c.left.P, 3, 4);
851 
852  CPY_ARRAY_2(d.right.M, c.right.M, 3, 3);
853  CPY_ARRAY_1(d.right.D, c.right.D, 8);
854  CPY_ARRAY_2(d.right.R, c.right.R, 3, 3);
855  CPY_ARRAY_2(d.right.P, c.right.P, 3, 4);
856 
857  CPY_ARRAY_2(d.aux.M, c.aux.M, 3, 3);
858  CPY_ARRAY_1(d.aux.D, c.aux.D, 8);
859  CPY_ARRAY_2(d.aux.R, c.aux.R, 3, 3);
860  CPY_ARRAY_2(d.aux.P, c.aux.P, 3, 4);
861 
862  return waitAck(d);
863 }
864 
865 //
866 // Get sensor calibration
867 
869 {
871 
873  if (Status_Ok != status)
874  return status;
875  CPY_ARRAY_1(c.adc_gain, d.adc_gain, 2);
877  CPY_ARRAY_1(c.vramp, d.vramp, 2);
878 
879  return Status_Ok;
880 }
881 
882 //
883 // Set sensor calibration
884 
886 {
888 
889  CPY_ARRAY_1(d.adc_gain, c.adc_gain, 2);
891  CPY_ARRAY_1(d.vramp, c.vramp, 2);
892 
893  return waitAck(d);
894 }
895 
896 //
897 // Get sensor calibration
898 
900 {
902 
904  if (Status_Ok != status)
905  return status;
906  c.delay = d.delay;
907 
908  return Status_Ok;
909 }
910 
911 //
912 // Set sensor calibration
913 
915 {
917 
918  d.delay = c.delay;;
919 
920  return waitAck(d);
921 }
922 
923 //
924 // Get lidar calibration
925 
927 {
929 
931  if (Status_Ok != status)
932  return status;
933 
936 
937  return Status_Ok;
938 }
939 
940 //
941 // Set lidar calibration
942 
944 {
946 
949 
950  return waitAck(d);
951 }
952 
953 //
954 // Get a list of supported image formats / data sources
955 
956 Status impl::getDeviceModes(std::vector<system::DeviceMode>& modes)
957 {
959 
960  Status status = waitData(wire::SysGetDeviceModes(), d);
961  if (Status_Ok != status)
962  return Status_Error;
963 
964  modes.resize(d.modes.size());
965  for(uint32_t i=0; i<d.modes.size(); i++) {
966 
967  system::DeviceMode& a = modes[i];
968  const wire::DeviceMode& w = d.modes[i];
969 
970  a.width = w.width;
971  a.height = w.height;
973  if (m_sensorVersion.firmwareVersion >= 0x0203)
974  a.disparities = w.disparities;
975  else
976  a.disparities = (a.width == 1024) ? 128 : 0;
977  }
978 
979  return Status_Ok;
980 }
981 
982 //
983 // Set/get the mtu
984 
985 Status impl::setMtu(int32_t mtu)
986 {
987  Status status = Status_Ok;
988 
989  //
990  // Firmware v2.3 or better will send us an MTU-sized
991  // response packet, which can be used to verify the
992  // MTU setting before we actually make the change.
993 
994  if (m_sensorVersion.firmwareVersion <= 0x0202)
995  status = waitAck(wire::SysMtu(mtu));
996  else {
997 
999  status = waitData(wire::SysTestMtu(mtu), resp);
1000  if (Status_Ok == status)
1001  status = waitAck(wire::SysMtu(mtu));
1002  }
1003 
1004  if (Status_Ok == status)
1005  m_sensorMtu = mtu;
1006 
1007  return status;
1008 }
1009 
1010 Status impl::getMtu(int32_t& mtu)
1011 {
1012  wire::SysMtu resp;
1013 
1014  Status status = waitData(wire::SysGetMtu(), resp);
1015  if (Status_Ok == status)
1016  mtu = resp.mtu;
1017 
1018  return status;
1019 }
1020 
1022 {
1023  wire::MotorPoll resp;
1024 
1025  Status status = waitData(wire::LidarPollMotor(), resp);
1026  if (Status_Ok == status)
1027  pos = resp.angleStart;
1028 
1029  return status;
1030 }
1031 
1032 //
1033 // Set/get the network configuration
1034 
1036 {
1038  c.ipv4Gateway,
1039  c.ipv4Netmask));
1040 }
1041 
1043 {
1044  wire::SysNetwork resp;
1045 
1046  Status status = waitData(wire::SysGetNetwork(), resp);
1047  if (Status_Ok == status) {
1048  c.ipv4Address = resp.address;
1049  c.ipv4Gateway = resp.gateway;
1050  c.ipv4Netmask = resp.netmask;
1051  }
1052 
1053  return status;
1054 }
1055 
1056 //
1057 // Get device info from sensor
1058 
1060 {
1062 
1063  Status status = waitData(wire::SysGetDeviceInfo(), w);
1064  if (Status_Ok != status)
1065  return status;
1066 
1067  info.name = w.name;
1068  info.buildDate = w.buildDate;
1069  info.serialNumber = w.serialNumber;
1071  info.pcbs.clear();
1072 
1073  for(uint8_t i=0; i<w.numberOfPcbs; i++) {
1074  system::PcbInfo pcb;
1075 
1076  pcb.name = w.pcbs[i].name;
1077  pcb.revision = w.pcbs[i].revision;
1078 
1079  info.pcbs.push_back(pcb);
1080  }
1081 
1082  info.imagerName = w.imagerName;
1084  info.imagerWidth = w.imagerWidth;
1085  info.imagerHeight = w.imagerHeight;
1086  info.lensName = w.lensName;
1087  info.lensType = w.lensType;
1091  info.lightingType = w.lightingType;
1092  info.numberOfLights = w.numberOfLights;
1093  info.laserName = w.laserName;
1094  info.laserType = w.laserType;
1095  info.motorName = w.motorName;
1096  info.motorType = w.motorType;
1098 
1099  return Status_Ok;
1100 }
1101 
1102 
1104 {
1106 
1121 
1126 
1132 
1133  return Status_Ok;
1134 }
1135 
1137 {
1139 
1141  if (Status_Ok != status)
1142  return status;
1143 
1144  calibration.x = d.calibration[0];
1145  calibration.y = d.calibration[1];
1146  calibration.z = d.calibration[2];
1147  calibration.roll = d.calibration[3];
1148  calibration.pitch = d.calibration[4];
1149  calibration.yaw = d.calibration[5];
1150 
1151  return Status_Ok;
1152 }
1153 
1155 {
1157 
1158  w.calibration[0] = calibration.x;
1159  w.calibration[1] = calibration.y;
1160  w.calibration[2] = calibration.z;
1161  w.calibration[3] = calibration.roll;
1162  w.calibration[4] = calibration.pitch;
1163  w.calibration[5] = calibration.yaw;
1164 
1165  return waitAck(w);
1166 }
1167 
1168 //
1169 // Sets the device info
1170 
1171 Status impl::setDeviceInfo(const std::string& key,
1172  const system::DeviceInfo& info)
1173 {
1175 
1176  w.key = key; // must match device firmware key
1177  w.name = info.name;
1178  w.buildDate = info.buildDate;
1179  w.serialNumber = info.serialNumber;
1181  w.numberOfPcbs = std::min((uint8_t) info.pcbs.size(),
1183  for(uint32_t i=0; i<w.numberOfPcbs; i++) {
1184  w.pcbs[i].name = info.pcbs[i].name;
1185  w.pcbs[i].revision = info.pcbs[i].revision;
1186  }
1187 
1188  w.imagerName = info.imagerName;
1190  w.imagerWidth = info.imagerWidth;
1191  w.imagerHeight = info.imagerHeight;
1192  w.lensName = info.lensName;
1193  w.lensType = info.lensType;
1197  w.lightingType = info.lightingType;
1198  w.numberOfLights = info.numberOfLights;
1199  w.laserName = info.laserName;
1200  w.laserType = info.laserType;
1201  w.motorName = info.motorName;
1202  w.motorType = info.motorType;
1204 
1205  return waitAck(w);
1206 }
1207 
1208 //
1209 // Flash the bitstream file (dangerous!)
1210 
1211 Status impl::flashBitstream(const std::string& filename)
1212 {
1213  return doFlashOp(filename,
1216 }
1217 
1218 //
1219 // Flash the firmware file (dangerous!)
1220 
1221 Status impl::flashFirmware(const std::string& filename)
1222 {
1223  return doFlashOp(filename,
1226 }
1227 
1228 //
1229 // Verify the bitstream file
1230 
1231 Status impl::verifyBitstream(const std::string& filename)
1232 {
1233  return doFlashOp(filename,
1236 }
1237 
1238 //
1239 // Verify the firmware file
1240 
1241 Status impl::verifyFirmware(const std::string& filename)
1242 {
1243  return doFlashOp(filename,
1246 }
1247 
1248 //
1249 // Get IMU information
1250 
1251 Status impl::getImuInfo(uint32_t& maxSamplesPerMessage,
1252  std::vector<imu::Info>& info)
1253 {
1254  wire::ImuInfo w;
1255 
1256  Status status = waitData(wire::ImuGetInfo(), w);
1257  if (Status_Ok != status)
1258  return status;
1259 
1260  //
1261  // Wire --> API
1262 
1263  maxSamplesPerMessage = w.maxSamplesPerMessage;
1264  info.resize(w.details.size());
1265  for(uint32_t i=0; i<w.details.size(); i++) {
1266 
1267  const wire::imu::Details& d = w.details[i];
1268 
1269  info[i].name = d.name;
1270  info[i].device = d.device;
1271  info[i].units = d.units;
1272 
1273  info[i].rates.resize(d.rates.size());
1274  for(uint32_t j=0; j<d.rates.size(); j++) {
1275  info[i].rates[j].sampleRate = d.rates[j].sampleRate;
1276  info[i].rates[j].bandwidthCutoff = d.rates[j].bandwidthCutoff;
1277  }
1278  info[i].ranges.resize(d.ranges.size());
1279  for(uint32_t j=0; j<d.ranges.size(); j++) {
1280  info[i].ranges[j].range = d.ranges[j].range;
1281  info[i].ranges[j].resolution = d.ranges[j].resolution;
1282  }
1283  }
1284 
1285  return Status_Ok;
1286 }
1287 
1288 //
1289 // Get IMU configuration
1290 
1291 Status impl::getImuConfig(uint32_t& samplesPerMessage,
1292  std::vector<imu::Config>& c)
1293 {
1294  wire::ImuConfig w;
1295 
1296  Status status = waitData(wire::ImuGetConfig(), w);
1297  if (Status_Ok != status)
1298  return status;
1299 
1300  //
1301  // Wire --> API
1302 
1303  samplesPerMessage = w.samplesPerMessage;
1304  c.resize(w.configs.size());
1305  for(uint32_t i=0; i<w.configs.size(); i++) {
1306  c[i].name = w.configs[i].name;
1307  c[i].enabled = (w.configs[i].flags & wire::imu::Config::FLAGS_ENABLED);
1308  c[i].rateTableIndex = w.configs[i].rateTableIndex;
1309  c[i].rangeTableIndex = w.configs[i].rangeTableIndex;
1310  }
1311 
1312  return Status_Ok;
1313 }
1314 
1315 //
1316 // Set IMU configuration
1317 
1318 Status impl::setImuConfig(bool storeSettingsInFlash,
1319  uint32_t samplesPerMessage,
1320  const std::vector<imu::Config>& c)
1321 {
1322  wire::ImuConfig w;
1323 
1324  //
1325  // API --> wire
1326 
1327  w.storeSettingsInFlash = storeSettingsInFlash ? 1 : 0;
1328  w.samplesPerMessage = samplesPerMessage;
1329  w.configs.resize(c.size());
1330  for(uint32_t i=0; i<c.size(); i++) {
1331  w.configs[i].name = c[i].name;
1332  w.configs[i].flags = c[i].enabled ? wire::imu::Config::FLAGS_ENABLED : 0;
1333  w.configs[i].rateTableIndex = c[i].rateTableIndex;
1334  w.configs[i].rangeTableIndex = c[i].rangeTableIndex;
1335  }
1336 
1337  return waitAck(w);
1338 }
1339 
1340 //
1341 // Get recommended large buffer pool count/size
1342 
1343 Status impl::getLargeBufferDetails(uint32_t& bufferCount,
1344  uint32_t& bufferSize)
1345 {
1346  bufferCount = RX_POOL_LARGE_BUFFER_COUNT;
1347  bufferSize = RX_POOL_LARGE_BUFFER_SIZE;
1348 
1349  return Status_Ok;
1350 }
1351 
1352 //
1353 // Replace internal large buffers with user supplied
1354 
1355 Status impl::setLargeBuffers(const std::vector<uint8_t*>& buffers,
1356  uint32_t bufferSize)
1357 {
1358  if (buffers.size() < RX_POOL_LARGE_BUFFER_COUNT)
1359  CRL_DEBUG("WARNING: supplying less than recommended number of large buffers: %ld/%ld\n",
1360  static_cast<long int>(buffers.size()),
1361  static_cast<long int>(RX_POOL_LARGE_BUFFER_COUNT));
1362  if (bufferSize < RX_POOL_LARGE_BUFFER_SIZE)
1363  CRL_DEBUG("WARNING: supplying smaller than recommended large buffers: %ld/%ld bytes\n",
1364  static_cast<long int>(bufferSize),
1365  static_cast<long int>(RX_POOL_LARGE_BUFFER_SIZE));
1366 
1367  try {
1368 
1369  utility::ScopedLock lock(m_rxLock); // halt potential pool traversal
1370 
1371  //
1372  // Deletion is safe even if the buffer is in use elsewhere
1373  // (BufferStream is reference counted.)
1374 
1375  BufferPool::const_iterator it;
1376  for(it = m_rxLargeBufferPool.begin();
1377  it != m_rxLargeBufferPool.end();
1378  ++it)
1379  delete *it;
1380 
1381  m_rxLargeBufferPool.clear();
1382 
1383  for(uint32_t i=0; i<buffers.size(); i++)
1384  m_rxLargeBufferPool.push_back(new utility::BufferStreamWriter(buffers[i], bufferSize));
1385 
1386  } catch (const std::exception& e) {
1387  CRL_DEBUG("exception: %s\n", e.what());
1388  return Status_Exception;
1389  }
1390 
1391  return Status_Ok;
1392 }
1393 
1394 //
1395 // Retrieve the system-assigned local UDP port
1396 
1398 {
1399  port = m_serverSocketPort;
1400  return Status_Ok;
1401 }
1402 }}} // namespaces
d
std::list< ImageListener * > m_imageListeners
Definition: channel.hh:427
static uint32_t imagerWireToApi(uint32_t h)
Definition: channel.cc:484
virtual Status setNetworkConfig(const system::NetworkConfig &c)
Definition: public.cc:1035
static CRL_CONSTEXPR uint32_t OP_PROGRAM
Listener< image::Header, image::Callback > ImageListener
Definition: listeners.hh:226
static uint32_t hardwareWireToApi(uint32_t h)
Definition: channel.cc:449
#define CRL_DEBUG_RAW(fmt)
Definition: Exception.hh:90
virtual Status getPtpStatus(int64_t frameId, system::PtpStatus &ptpStatus)
Definition: public.cc:404
virtual Status getMtu(int32_t &mtu)
Definition: public.cc:1010
virtual Status verifyBitstream(const std::string &file)
Definition: public.cc:1231
virtual Status getLocalUdpPort(uint16_t &port)
Definition: public.cc:1397
virtual Status setImuConfig(bool storeSettingsInFlash, uint32_t samplesPerMessage, const std::vector< imu::Config > &c)
Definition: public.cc:1318
CRL_THREAD_LOCAL utility::BufferStream * dispatchBufferReferenceTP
Definition: public.cc:109
virtual Status verifyFirmware(const std::string &file)
Definition: public.cc:1241
static CRL_CONSTEXPR uint32_t HISTOGRAM_CHANNELS
virtual Status setTriggerSource(TriggerSource s)
Definition: public.cc:570
virtual Status getMotorPos(int32_t &mtu)
Definition: public.cc:1021
Listener< pps::Header, pps::Callback > PpsListener
Definition: listeners.hh:228
virtual Status getExternalCalibration(system::ExternalCalibration &calibration)
Definition: public.cc:1136
f
static CRL_CONSTEXPR TriggerSource Trigger_Internal
static CRL_CONSTEXPR uint32_t MAX_DIRECTED_STREAMS
Definition: channel.hh:296
virtual Status getLightingSensorStatus(lighting::SensorStatus &status)
Definition: public.cc:652
static CRL_CONSTEXPR TriggerSource Trigger_PTP
virtual Status networkTimeSynchronization(bool enabled)
Definition: public.cc:437
uint8_t intensity[lighting::MAX_LIGHTS]
virtual Status removeIsolatedCallback(image::Callback callback)
Definition: public.cc:205
void(* Callback)(const Header &header, void *userDataP)
CameraProfile cameraProfile() const
virtual Status ptpTimeSynchronization(bool enabled)
Definition: public.cc:446
virtual Status setExternalCalibration(const system::ExternalCalibration &calibration)
Definition: public.cc:1154
virtual Status getLightingConfig(lighting::Config &c)
Definition: public.cc:614
virtual Status getImageConfig(image::Config &c)
Definition: public.cc:703
float getDutyCycle(uint32_t i) const
static CRL_CONSTEXPR TriggerSource Trigger_External
wire::StatusResponse m_statusResponseMessage
Definition: channel.hh:464
virtual Status setLidarCalibration(const lidar::Calibration &c)
Definition: public.cc:943
static wire::SourceType sourceApiToWire(DataSource mask)
Definition: channel.cc:369
std::list< PpsListener * > m_ppsListeners
Definition: channel.hh:429
virtual Status getLargeBufferDetails(uint32_t &bufferCount, uint32_t &bufferSize)
Definition: public.cc:1343
virtual Status startDirectedStream(const DirectedStream &stream)
Definition: public.cc:504
virtual Status setMotorSpeed(float rpm)
Definition: public.cc:606
DepthCache< int64_t, wire::ImageMeta > m_imageMetaCache
Definition: channel.hh:389
static CRL_CONSTEXPR Status Status_Failed
virtual Status setMtu(int32_t mtu)
Definition: public.cc:985
virtual Status getDeviceStatus(system::StatusMessage &status)
Definition: public.cc:1103
void(* Callback)(const Header &header, void *userDataP)
uint16_t autoExposureRoiHeight() const
virtual Status stopStreams(DataSource mask)
Definition: public.cc:478
virtual Status getNetworkConfig(system::NetworkConfig &c)
Definition: public.cc:1042
uint32_t autoWhiteBalanceDecay() const
virtual Status getSensorCalibration(image::SensorCalibration &c)
Definition: public.cc:868
virtual Status setSensorCalibration(const image::SensorCalibration &c)
Definition: public.cc:885
virtual Status startDirectedStreams(const std::vector< DirectedStream > &streams)
Definition: public.cc:515
static CRL_CONSTEXPR uint32_t RGN_FIRMWARE
virtual Status addIsolatedCallback(image::Callback callback, DataSource imageSourceMask, void *userDataP)
Definition: public.cc:120
utility::Mutex m_dispatchLock
Definition: channel.hh:401
static CRL_CONSTEXPR uint32_t MAX_USER_PPS_QUEUE_SIZE
Definition: channel.hh:290
virtual Status getVersionInfo(system::VersionInfo &v)
Definition: public.cc:687
#define CPY_ARRAY_2(d_, s_, n_, m_)
Definition: Protocol.h:289
virtual Status getSensorVersion(VersionType &version)
Definition: public.cc:669
static CRL_CONSTEXPR uint32_t OP_VERIFY
static CRL_CONSTEXPR VersionType API_VERSION
Definition: channel.hh:258
static CRL_CONSTEXPR uint32_t HISTOGRAM_BINS
Definition: channel.cc:56
virtual Status getImuConfig(uint32_t &samplesPerMessage, std::vector< imu::Config > &c)
Definition: public.cc:1291
static CRL_CONSTEXPR uint32_t FLAGS_ENABLED
Type boundValue(Type const &value, Type const &minimum, Type const &maximum)
Definition: Functional.hh:61
static CRL_CONSTEXPR uint32_t RX_POOL_LARGE_BUFFER_COUNT
Definition: channel.hh:266
static CRL_CONSTEXPR Status Status_Ok
virtual Status getEnabledStreams(DataSource &mask)
Definition: public.cc:492
wire::VersionResponse m_sensorVersion
Definition: channel.hh:459
static CRL_CONSTEXPR uint32_t MAX_USER_IMU_QUEUE_SIZE
Definition: channel.hh:291
virtual Status getImageHistogram(int64_t frameId, image::Histogram &histogram)
Definition: public.cc:367
virtual Status setLargeBuffers(const std::vector< uint8_t * > &buffers, uint32_t bufferSize)
Definition: public.cc:1355
static CRL_CONSTEXPR TriggerSource Trigger_External_Inverted
static CRL_CONSTEXPR uint32_t STATUS_EXTERNAL_LED_OK
static uint32_t imagerApiToWire(uint32_t h)
Definition: channel.cc:469
utility::Mutex m_streamLock
Definition: channel.hh:406
uint16_t autoExposureRoiWidth() const
virtual Status startStreams(DataSource mask)
Definition: public.cc:464
Listener< lidar::Header, lidar::Callback > LidarListener
Definition: listeners.hh:227
virtual Status setDeviceInfo(const std::string &key, const system::DeviceInfo &i)
Definition: public.cc:1171
virtual void * reserveCallbackBuffer()
Definition: public.cc:317
virtual Status getApiVersion(VersionType &version)
Definition: public.cc:678
virtual Status setImageCalibration(const image::Calibration &c)
Definition: public.cc:843
static CRL_CONSTEXPR uint32_t MAX_USER_LASER_QUEUE_SIZE
Definition: channel.hh:284
#define CPY_ARRAY_1(d_, s_, n_)
Definition: Protocol.h:285
Status waitAck(const T &msg, wire::IdType id=MSG_ID(T::ID), const double &timeout=DEFAULT_ACK_TIMEOUT(), int32_t attempts=DEFAULT_ACK_ATTEMPTS)
Definition: query.hh:89
virtual Status stopDirectedStream(const DirectedStream &stream)
Definition: public.cc:530
#define CRL_DEBUG(fmt,...)
Definition: Exception.hh:83
virtual Status getImageCalibration(image::Calibration &c)
Definition: public.cc:814
static CRL_CONSTEXPR uint32_t RX_POOL_LARGE_BUFFER_SIZE
Definition: channel.hh:265
std::list< LidarListener * > m_lidarListeners
Definition: channel.hh:428
virtual Status getImuInfo(uint32_t &maxSamplesPerMessage, std::vector< imu::Info > &info)
Definition: public.cc:1251
virtual Status maxDirectedStreams(uint32_t &maximum)
Definition: public.cc:561
static CRL_CONSTEXPR uint32_t MAX_LIGHTS
Listener< imu::Header, imu::Callback > ImuListener
Definition: listeners.hh:229
virtual Status getDeviceModes(std::vector< system::DeviceMode > &modes)
Definition: public.cc:956
static uint32_t hardwareApiToWire(uint32_t h)
Definition: channel.cc:429
virtual Status flashBitstream(const std::string &file)
Definition: public.cc:1211
void(* Callback)(const Header &header, void *userDataP)
virtual Status setTransmitDelay(const image::TransmitDelay &c)
Definition: public.cc:914
std::list< ImuListener * > m_imuListeners
Definition: channel.hh:430
static CRL_CONSTEXPR Status Status_Exception
virtual Status getLidarCalibration(lidar::Calibration &c)
Definition: public.cc:926
virtual Status getTransmitDelay(image::TransmitDelay &c)
Definition: public.cc:899
static CRL_CONSTEXPR uint32_t MAX_USER_IMAGE_QUEUE_SIZE
Definition: channel.hh:283
Status waitData(const T &command, U &data, const double &timeout=DEFAULT_ACK_TIMEOUT(), int32_t attempts=DEFAULT_ACK_ATTEMPTS)
Definition: query.hh:120
virtual Status flashFirmware(const std::string &file)
Definition: public.cc:1221
static CRL_CONSTEXPR Status Status_Error
uint8_t intensity[lighting::MAX_LIGHTS]
Definition: LedSetMessage.h:63
static CRL_CONSTEXPR uint32_t RGN_BITSTREAM
virtual Status setLightingConfig(const lighting::Config &c)
Definition: public.cc:635
std::vector< imu::Details > details
virtual Status setImageConfig(const image::Config &c)
Definition: public.cc:769
virtual Status getDirectedStreams(std::vector< DirectedStream > &streams)
Definition: public.cc:541
static DataSource sourceWireToApi(wire::SourceType mask)
Definition: channel.cc:399
Status doFlashOp(const std::string &filename, uint32_t operation, uint32_t region)
Definition: flash.cc:185
virtual Status getDeviceInfo(system::DeviceInfo &info)
Definition: public.cc:1059
void(* Callback)(const Header &header, void *userDataP)
virtual Status releaseCallbackBuffer(void *referenceP)
Definition: public.cc:341


multisense_lib
Author(s):
autogenerated on Sun Mar 14 2021 02:34:50