21 #include <glog/logging.h>
29 #include <linux/videodev2.h>
32 #include <sys/ioctl.h>
36 #include <unordered_map>
38 #define MAX_SUBFRAMES_COUNT \
39 10 // maximum number of subframes that are used to create a full frame (maximum total_captures of all modes)
40 #define EXTRA_BUFFERS_COUNT \
41 3 // how many extra buffers are sent to the driver in addition to the total_captures of a mode
43 #define CLEAR(x) memset(&(x), 0, sizeof(x))
45 #define V4L2_CID_AD_DEV_CHIP_CONFIG (0x9819e1)
46 #define CTRL_PACKET_SIZE 65537
47 #define CTRL_SET_MODE (0x9819e0)
48 #define CTRL_AB_AVG (0x9819e5)
49 #define CTRL_DEPTH_EN (0x9819e6)
50 #define CTRL_PHASE_DEPTH_BITS (0x9819e2)
51 #define CTRL_AB_BITS (0x9819e3)
52 #define CTRL_CONFIDENCE_BITS (0x9819e4)
54 #define CTRL_SET_FRAME_RATE (0x9a200b)
56 #define ADSD3500_CTRL_PACKET_SIZE 4099
58 #define TEMP_SENSOR_DEV_PATH "/dev/i2c-1"
59 #define LASER_TEMP_SENSOR_I2C_ADDR 0x49
60 #define AFE_TEMP_SENSOR_I2C_ADDR 0x4b
65 #define NR_OF_MODES_FROM_CCB 10
66 #define SIZE_OF_MODES_FROM_CCB 256
117 static int xioctl(
int fh,
unsigned int request,
void *arg) {
122 r = ioctl(fh, request, arg);
123 }
while (--tries > 0 &&
r == -1 &&
EINTR ==
errno);
131 : m_driverPath(driverPath), m_driverSubPath(driverSubPath),
133 m_firstRun(
true), m_adsd3500Queried(
false), m_depthComputeOnTarget(
true),
134 m_chipStatus(0), m_imagerStatus(0),
151 m_controls.emplace(
"depthComputeOpenSource",
"0");
156 m_implData->controlsCommands[
"abAveraging"] = 0x9819e5;
157 m_implData->controlsCommands[
"depthEnable"] = 0x9819e6;
158 m_implData->controlsCommands[
"phaseDepthBits"] = 0x9819e2;
159 m_implData->controlsCommands[
"abBits"] = 0x9819e3;
160 m_implData->controlsCommands[
"confidenceBits"] = 0x9819e4;
168 for (
unsigned int i = 0;
i <
m_implData->numVideoDevs;
i++) {
175 for (
unsigned int i = 0;
i <
m_implData->numVideoDevs;
i++) {
189 if (close(dev->
fd) == -1) {
191 <<
"close m_implData->fd error "
196 if (dev->
sfd != -1) {
197 if (close(dev->
sfd) == -1) {
199 <<
"close m_implData->sfd error "
214 std::weak_ptr<Adsd3500Sensor> wptr = shared_from_this();
221 struct v4l2_capability cap;
224 const char *devName, *subDevName, *cardName;
226 std::vector<std::string> driverPaths;
229 std::vector<std::string> driverSubPaths;
232 std::vector<std::string> cards;
234 Utils::splitIntoTokens(captureDeviceName,
'|', cards);
236 LOG(
INFO) <<
"Looking for the following cards:";
237 for (
const auto card : cards) {
241 m_implData->numVideoDevs = driverSubPaths.size();
244 for (
unsigned int i = 0;
i <
m_implData->numVideoDevs;
i++) {
245 devName = driverPaths.at(
i).c_str();
246 subDevName = driverSubPaths.at(
i).c_str();
247 cardName = cards.at(
i).c_str();
250 LOG(
INFO) <<
"device: " << devName <<
"\tsubdevice: " << subDevName;
255 if (stat(devName, &st) == -1) {
257 <<
"Cannot identify " << devName <<
"errno: " <<
errno
259 return Status::GENERIC_ERROR;
263 LOG(
WARNING) << devName <<
" is not a valid device";
264 return Status::GENERIC_ERROR;
267 dev->
fd =
::open(devName, O_RDWR | O_NONBLOCK, 0);
271 return Status::GENERIC_ERROR;
274 if (
xioctl(dev->
fd, VIDIOC_QUERYCAP, &cap) == -1) {
275 LOG(
WARNING) << devName <<
" VIDIOC_QUERYCAP error";
276 return Status::GENERIC_ERROR;
279 if (strncmp((
char *)cap.card, cardName, strlen(cardName))) {
280 LOG(
WARNING) <<
"CAPTURE Device " << cap.card;
282 return Status::GENERIC_ERROR;
285 if (!(cap.capabilities &
286 (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_CAPTURE_MPLANE))) {
287 LOG(
WARNING) << devName <<
" is not a video capture device";
288 return Status::GENERIC_ERROR;
291 if (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE) {
297 if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
298 LOG(
WARNING) << devName <<
" does not support streaming i/o";
299 return Status::GENERIC_ERROR;
303 if (stat(subDevName, &st) == -1) {
304 LOG(
WARNING) <<
"Cannot identify " << subDevName
305 <<
" errno: " <<
errno
307 return Status::GENERIC_ERROR;
311 LOG(
WARNING) << subDevName <<
" is not a valid device";
312 return Status::GENERIC_ERROR;
315 dev->
sfd =
::open(subDevName, O_RDWR | O_NONBLOCK);
316 if (dev->
sfd == -1) {
319 return Status::GENERIC_ERROR;
327 uint8_t dealiasCheck[32] = {0};
330 for (
int i = 0;
i < 10;
i++) {
337 LOG(
INFO) <<
"Could not read chip ID. Resetting ADSD3500 "
338 "to handle previous error.";
347 LOG(
INFO) <<
"Could not read Dealias Parameters. Resetting "
349 "to handle previous error.";
356 LOG(
INFO) <<
"ADSD3500 is ready to communicate with.";
362 LOG(
ERROR) <<
"Cannot read chip id! Latest ADSD3500 "
363 "programming might not be succesful";
368 LOG(
ERROR) <<
"Cannot read dealias parameters! Latest ADSD3500 "
369 "programming might not be succesful";
370 return dealiasStatus;
384 LOG(
ERROR) <<
"Failed to set input video device!";
390 LOG(
ERROR) <<
"Failed to open output video device!";
401 struct v4l2_buffer
buf;
403 for (
unsigned int i = 0;
i <
m_implData->numVideoDevs;
i++) {
406 LOG(
INFO) <<
"Device already started";
409 LOG(
INFO) <<
"Starting device " <<
i;
414 buf.memory = V4L2_MEMORY_MMAP;
423 return Status::GENERIC_ERROR;
430 return Status::GENERIC_ERROR;
444 for (
unsigned int i = 0;
i <
m_implData->numVideoDevs;
i++) {
448 LOG(
INFO) <<
"Device " <<
i <<
" already stopped";
451 LOG(
INFO) <<
"Stopping device";
456 return Status::GENERIC_ERROR;
468 if (availableMode.isPCM)
471 modes.emplace_back(availableMode.modeNumber);
482 if (modeDetails.modeNumber ==
mode) {
483 details = modeDetails;
496 LOG(
ERROR) <<
"Failed to set control in modeSelector!";
501 bool modeFound =
false;
511 LOG(
ERROR) <<
"Mode not found in ccb!";
518 LOG(
ERROR) <<
"Failed to get configuration table!";
525 LOG(
ERROR) <<
"Failed to update configuration table for currrent "
532 LOG(
ERROR) <<
"Failed to set mode for the current configuration!";
547 for (
unsigned int i = 0;
i <
m_implData->numVideoDevs;
i++) {
554 for (
unsigned int i = 0;
i <
m_implData->numVideoDevs;
i++) {
568 if (close(dev->
fd) == -1) {
570 <<
"close m_implData->fd error "
575 if (dev->
sfd != -1) {
576 if (close(dev->
sfd) == -1) {
578 <<
"close m_implData->sfd error "
586 LOG(
INFO) <<
"Failed to open sensor!";
594 for (
unsigned int i = 0;
i <
m_implData->numVideoDevs;
i++) {
598 struct v4l2_requestbuffers
req;
599 struct v4l2_buffer
buf;
600 struct v4l2_format
fmt;
603 static struct v4l2_control ctrl;
605 memset(&ctrl, 0,
sizeof(ctrl));
608 ctrl.value =
type.modeNumber;
611 if (
xioctl(dev->
sfd, VIDIOC_S_CTRL, &ctrl) == -1) {
613 <<
"Setting Mode error "
615 status = Status::GENERIC_ERROR;
626 <<
"errno: " <<
errno
628 return Status::GENERIC_ERROR;
636 req.memory = V4L2_MEMORY_MMAP;
640 <<
"VIDIOC_REQBUFS error "
642 return Status::GENERIC_ERROR;
648 __u32 pixelFormat = 0;
650 if (
type.pixelFormatIndex == 1) {
651 pixelFormat = V4L2_PIX_FMT_SBGGR12;
654 pixelFormat = V4L2_PIX_FMT_SBGGR8;
656 pixelFormat = V4L2_PIX_FMT_SRGGB8;
663 fmt.fmt.pix.pixelformat = pixelFormat;
664 fmt.fmt.pix.width =
type.frameWidthInBytes;
665 fmt.fmt.pix.height =
type.frameHeightInBytes;
669 return Status::GENERIC_ERROR;
676 req.memory = V4L2_MEMORY_MMAP;
680 <<
"VIDIOC_REQBUFS error "
682 return Status::GENERIC_ERROR;
689 <<
"Failed to allocate video m_implData->videoBuffers";
690 return Status::GENERIC_ERROR;
697 buf.memory = V4L2_MEMORY_MMAP;
702 if (
xioctl(dev->
fd, VIDIOC_QUERYBUF, &
buf) == -1) {
704 <<
"VIDIOC_QUERYBUF error "
706 return Status::GENERIC_ERROR;
718 mmap(
NULL,
length, PROT_READ | PROT_WRITE, MAP_SHARED,
725 return Status::GENERIC_ERROR;
736 type.baseResolutionWidth * 4,
type.baseResolutionHeight);
738 LOG(
ERROR) <<
"Failed to set bufferProcessor properties!";
756 LOG(
ERROR) <<
"Failed to process buffer!";
764 unsigned int buf_data_len;
784 memcpy(
buffer, pdata, buf_data_len);
800 controls.emplace_back(
item.first);
819 if (control ==
"fps") {
820 int fps = std::stoi(
value);
822 struct v4l2_ext_control extCtrl;
823 struct v4l2_ext_controls extCtrls;
824 memset(&extCtrls, 0,
sizeof(
struct v4l2_ext_controls));
825 memset(&extCtrl, 0,
sizeof(
struct v4l2_ext_control));
828 extCtrls.controls = &extCtrl;
829 extCtrl.id = CTRL_SET_FRAME_RATE;
832 if (
xioctl(dev->
sfd, VIDIOC_S_EXT_CTRLS, &extCtrls) == -1) {
833 LOG(
WARNING) <<
"Failed to set control: " << control <<
" "
835 status = Status::GENERIC_ERROR;
838 struct v4l2_streamparm fpsControl;
839 memset(&fpsControl, 0,
sizeof(
struct v4l2_streamparm));
841 fpsControl.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
842 fpsControl.parm.capture.timeperframe.numerator = 1;
843 fpsControl.parm.capture.timeperframe.denominator = fps;
845 if (
xioctl(dev->
fd, VIDIOC_S_PARM, &fpsControl) == -1) {
846 LOG(
WARNING) <<
"Failed to set control: " << control <<
" "
848 status = Status::GENERIC_ERROR;
855 LOG(
ERROR) <<
"Failed to set fps at: " << fps
856 <<
"via host commands!";
857 return Status::GENERIC_ERROR;
863 if (control ==
"imagerType") {
864 LOG(
WARNING) <<
"Control: " << control <<
" is read only!";
868 if (control ==
"depthComputeOpenSource") {
869 LOG(
WARNING) <<
"Control: " << control <<
" is read only!";
873 if (control ==
"availableCCBM") {
874 LOG(
WARNING) <<
"Control: " << control <<
" is read only!";
878 if (control ==
"disableCCBM") {
883 std::vector<std::string> convertor = {
"0",
"4",
"8",
"10",
886 if (control ==
"phaseDepthBits")
888 if (control ==
"abBits")
890 if (control ==
"confidenceBits")
892 if (control ==
"inputFormat") {
896 if (control ==
"netlinktest") {
900 struct v4l2_control ctrl;
901 memset(&ctrl, 0,
sizeof(ctrl));
903 ctrl.id =
m_implData->controlsCommands[control];
904 ctrl.value = std::stoi(
value);
906 if (
xioctl(dev->
sfd, VIDIOC_S_CTRL, &ctrl) == -1) {
907 LOG(
WARNING) <<
"Failed to set control: " << control <<
" "
909 status = Status::GENERIC_ERROR;
920 if (control ==
"imagerType") {
925 if (control ==
"depthComputeOpenSource") {
930 if (control ==
"inputFormat") {
935 if (control ==
"disableCCBM") {
940 if (control ==
"availableCCBM") {
946 struct v4l2_control ctrl;
947 memset(&ctrl, 0,
sizeof(ctrl));
949 ctrl.id =
m_implData->controlsCommands[control];
953 if (
xioctl(dev->
sfd, VIDIOC_G_CTRL, &ctrl) == -1) {
954 LOG(
WARNING) <<
"Failed to get control: " << control <<
" "
956 return Status::GENERIC_ERROR;
958 value = std::to_string(ctrl.value);
988 if (connectionType ==
"USB") {
990 }
else if (connectionType ==
"NETWORK") {
998 unsigned int usDelay) {
1003 static struct v4l2_ext_control extCtrl;
1004 static struct v4l2_ext_controls extCtrls;
1009 memset(&extCtrls, 0,
sizeof(
struct v4l2_ext_controls));
1010 extCtrls.controls = &extCtrl;
1016 buf[3] = uint8_t(cmd >> 8);
1017 buf[4] = uint8_t(cmd & 0xFF);
1020 if (
xioctl(dev->
sfd, VIDIOC_S_EXT_CTRLS, &extCtrls) == -1) {
1021 LOG(
WARNING) <<
"Could not set control: 0x" << std::hex << extCtrl.id
1022 <<
" with command: 0x" << std::hex << cmd
1024 return Status::GENERIC_ERROR;
1035 if (
xioctl(dev->
sfd, VIDIOC_S_EXT_CTRLS, &extCtrls) == -1) {
1036 LOG(
WARNING) <<
"Could not set control: 0x" << std::hex << extCtrl.id
1037 <<
" with command: 0x" << std::hex << cmd
1039 return Status::GENERIC_ERROR;
1042 if (
xioctl(dev->
sfd, VIDIOC_G_EXT_CTRLS, &extCtrls) == -1) {
1043 LOG(
WARNING) <<
"Could not get control: 0x" << std::hex << extCtrl.id
1044 <<
" with command: 0x" << std::hex << cmd
1046 return Status::GENERIC_ERROR;
1049 *
data = (uint16_t)(extCtrl.p_u8[3] << 8) + (uint16_t)(extCtrl.p_u8[4]);
1055 unsigned int usDelay) {
1060 static struct v4l2_ext_control extCtrl;
1061 static struct v4l2_ext_controls extCtrls;
1066 memset(&extCtrls, 0,
sizeof(
struct v4l2_ext_controls));
1067 extCtrls.controls = &extCtrl;
1073 buf[3] = uint8_t(cmd >> 8);
1074 buf[4] = uint8_t(cmd & 0xFF);
1076 buf[6] = uint8_t(
data & 0xFF);
1079 if (
xioctl(dev->
sfd, VIDIOC_S_EXT_CTRLS, &extCtrls) == -1) {
1080 LOG(
WARNING) <<
"Could not set control: 0x" << std::hex << extCtrl.id
1081 <<
" with command: 0x" << std::hex << cmd
1083 return Status::GENERIC_ERROR;
1095 uint8_t *readback_data,
1096 uint16_t payload_len) {
1102 uint32_t switchCmd = 0x0019;
1103 uint16_t switchPayload = 0x0000;
1107 LOG(
INFO) <<
"Failed to switch to burst mode!";
1111 static struct v4l2_ext_control extCtrl;
1112 static struct v4l2_ext_controls extCtrls;
1119 memset(&extCtrls, 0,
sizeof(
struct v4l2_ext_controls));
1120 extCtrls.controls = &extCtrl;
1128 buf[6] = uint8_t(cmd & 0xFF);
1130 uint32_t checksum = 0;
1131 for (
int i = 0;
i < 7;
i++) {
1132 checksum +=
buf[
i + 4];
1134 memcpy(
buf + 11, &checksum, 4);
1135 memcpy(
buf + 15, readback_data, 1);
1138 if (
xioctl(dev->
sfd, VIDIOC_S_EXT_CTRLS, &extCtrls) == -1) {
1139 LOG(
WARNING) <<
"Could not set control: 0x" << std::hex << extCtrl.id
1140 <<
" with command: 0x" << std::hex << cmd
1142 return Status::GENERIC_ERROR;
1147 else if (cmd == 0x19)
1150 memset(&extCtrls, 0,
sizeof(
struct v4l2_ext_controls));
1151 extCtrls.controls = &extCtrl;
1155 buf[1] = uint8_t(payload_len >> 8);
1156 buf[2] = uint8_t(payload_len & 0xFF);
1160 if (
xioctl(dev->
sfd, VIDIOC_S_EXT_CTRLS, &extCtrls) == -1) {
1161 LOG(
WARNING) <<
"Could not set control: 0x" << std::hex << extCtrl.id
1162 <<
" with command: 0x" << std::hex << cmd
1164 return Status::GENERIC_ERROR;
1167 if (
xioctl(dev->
sfd, VIDIOC_G_EXT_CTRLS, &extCtrls) == -1) {
1168 LOG(
WARNING) <<
"Could not get control: 0x" << std::hex << extCtrl.id
1169 <<
" with command: 0x" << std::hex << cmd
1171 return Status::GENERIC_ERROR;
1174 memcpy(readback_data, extCtrl.p_u8 + 3, payload_len);
1182 memset(&extCtrls, 0,
sizeof(
struct v4l2_ext_controls));
1183 extCtrls.controls = &extCtrl;
1186 uint8_t switchBuf[] = {0x01, 0x00, 0x10, 0xAD, 0x00, 0x00, 0x10,
1187 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
1188 0x00, 0x00, 0x00, 0x00, 0x00};
1190 memcpy(extCtrl.p_u8, switchBuf, 19);
1192 if (
xioctl(dev->
sfd, VIDIOC_S_EXT_CTRLS, &extCtrls) == -1) {
1193 LOG(
WARNING) <<
"Could not set control: 0x" << std::hex << extCtrl.id
1194 <<
" with command: 0x" << std::hex << cmd
1195 <<
" (switch to standard mode)"
1197 return Status::GENERIC_ERROR;
1204 uint16_t payload_len) {
1209 static struct v4l2_ext_control extCtrl;
1210 static struct v4l2_ext_controls extCtrls;
1217 memset(&extCtrls, 0,
sizeof(
struct v4l2_ext_controls));
1218 extCtrls.controls = &extCtrl;
1222 buf[1] = uint8_t(payload_len >> 8);
1223 buf[2] = uint8_t(payload_len & 0xFF);
1229 if (
xioctl(dev->
sfd, VIDIOC_S_EXT_CTRLS, &extCtrls) == -1) {
1230 LOG(
WARNING) <<
"Could not set control: 0x" << std::hex << extCtrl.id
1231 <<
" to read payload with length: " << payload_len
1233 return Status::GENERIC_ERROR;
1236 if (
xioctl(dev->
sfd, VIDIOC_G_EXT_CTRLS, &extCtrls) == -1) {
1237 LOG(
WARNING) <<
"Could not get control: 0x" << std::hex << extCtrl.id
1238 <<
" to read payload with length: " << payload_len
1240 return Status::GENERIC_ERROR;
1243 memcpy(payload, extCtrl.p_u8 + 3, payload_len);
1250 uint16_t payload_len) {
1256 uint32_t switchCmd = 0x0019;
1257 uint16_t switchPayload = 0x0000;
1261 LOG(
INFO) <<
"Failed to switch to burst mode!";
1264 static struct v4l2_ext_control extCtrl;
1265 static struct v4l2_ext_controls extCtrls;
1270 memset(&extCtrls, 0,
sizeof(
struct v4l2_ext_controls));
1271 extCtrls.controls = &extCtrl;
1276 buf[1] = uint8_t(payload_len >> 8);
1277 buf[2] = uint8_t(payload_len & 0xFF);
1281 buf[4] = uint8_t(payload_len >> 8);
1282 buf[5] = uint8_t(payload_len & 0xFF);
1283 buf[6] = uint8_t(cmd & 0xFF);
1285 uint32_t checksum = 0;
1286 for (
int i = 0;
i < 7;
i++) {
1287 checksum +=
buf[
i + 4];
1289 memcpy(
buf + 11, &checksum, 4);
1290 memcpy(
buf + 15, payload, payload_len);
1293 if (
xioctl(dev->
sfd, VIDIOC_S_EXT_CTRLS, &extCtrls) == -1) {
1294 LOG(
WARNING) <<
"Could not set control: 0x" << std::hex << extCtrl.id
1295 <<
" with command: 0x" << std::hex << cmd
1297 return Status::GENERIC_ERROR;
1301 memset(&extCtrls, 0,
sizeof(
struct v4l2_ext_controls));
1302 extCtrls.controls = &extCtrl;
1305 uint8_t switchBuf[] = {0x01, 0x00, 0x10, 0xAD, 0x00, 0x00, 0x10,
1306 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
1307 0x00, 0x00, 0x00, 0x00, 0x00};
1309 memcpy(extCtrl.p_u8, switchBuf, 19);
1311 if (
xioctl(dev->
sfd, VIDIOC_S_EXT_CTRLS, &extCtrls) == -1) {
1312 LOG(
WARNING) <<
"Could not set control: 0x" << std::hex << extCtrl.id
1313 <<
" with command: 0x" << std::hex << cmd
1314 <<
" (switch to standard mode)"
1316 return Status::GENERIC_ERROR;
1323 uint16_t payload_len) {
1328 static struct v4l2_ext_control extCtrl;
1329 static struct v4l2_ext_controls extCtrls;
1334 memset(&extCtrls, 0,
sizeof(
struct v4l2_ext_controls));
1335 extCtrls.controls = &extCtrl;
1339 buf[1] = uint8_t(payload_len >> 8);
1340 buf[2] = uint8_t(payload_len & 0xFF);
1342 memcpy(
buf + 3, payload, payload_len);
1345 if (
xioctl(dev->
sfd, VIDIOC_S_EXT_CTRLS, &extCtrls) == -1) {
1346 LOG(
WARNING) <<
"Could not set control: 0x" << std::hex << extCtrl.id
1347 <<
" to write payload with length: " << payload_len
1349 return Status::GENERIC_ERROR;
1369 bool interruptsAvailable = (status ==
Status::OK);
1372 system(
"echo 0 > /sys/class/gpio/gpio64/value");
1374 system(
"echo 1 > /sys/class/gpio/gpio64/value");
1376 system(
"echo 0 > /sys/class/gpio/gpio122/value");
1378 system(
"echo 1 > /sys/class/gpio/gpio122/value");
1381 if (interruptsAvailable) {
1382 LOG(
INFO) <<
"Waiting for ADSD3500 to reset.";
1383 int secondsTimeout = 10;
1384 int secondsWaited = 0;
1385 int secondsWaitingStep = 1;
1388 std::this_thread::sleep_for(
1389 std::chrono::seconds(secondsWaitingStep));
1390 secondsWaited += secondsWaitingStep;
1392 LOG(
INFO) <<
"Waited: " << secondsWaited <<
" seconds";
1397 #elif defined(NVIDIA)
1399 if (stat(
"/sys/class/gpio/PP.04/value", &st) == 0) {
1400 system(
"echo 0 > /sys/class/gpio/PP.04/value");
1402 system(
"echo 1 > /sys/class/gpio/PP.04/value");
1405 Gpio gpio11(
"/dev/gpiochip3", 11);
1420 uint16_t iniFileLength,
1422 uint16_t calDataLength) {
1427 iniFile, iniFileLength, calData, calDataLength,
1430 LOG(
ERROR) <<
"Failed to initialize depth compute on target!";
1434 uint8_t depthComputeStatus;
1437 LOG(
ERROR) <<
"Failed to get depth compute version!";
1441 m_controls[
"depthComputeOpenSource"] = std::to_string(depthComputeStatus);
1447 std::map<std::string, std::string> &
params) {
1467 params[
"jblfApplyFlag"] =
1469 params[
"jblfWindowSize"] =
1471 params[
"jblfGaussianSigma"] =
1473 params[
"jblfExponentialTerm"] =
1482 std::to_string(
static_cast<float>(ir_params.
headerSize));
1488 const std::map<std::string, std::string> &
params) {
1511 static_cast<int>(std::stof(
params.at(
"jblfApplyFlag")));
1513 static_cast<int>(std::stof(
params.at(
"jblfWindowSize")));
1516 std::stof(
params.at(
"jblfExponentialTerm"));
1533 FD_SET(dev->
fd, &fds);
1544 }
else if (
r == 0) {
1562 buf.memory = V4L2_MEMORY_MMAP;
1574 return Status::GENERIC_ERROR;
1579 LOG(
WARNING) <<
"Not enough buffers avaialable";
1580 return Status::GENERIC_ERROR;
1587 uint8_t **
buffer, uint32_t &buf_data_len,
const struct v4l2_buffer &
buf,
1593 buf_data_len =
buf.bytesused;
1617 if (dev->
fd != -1) {
1618 fileDescriptor = dev->
fd;
1637 const struct v4l2_buffer &
buf) {
1659 uint8_t fwData[44] = {0};
1660 fwData[0] = uint8_t(1);
1663 LOG(
ERROR) <<
"Failed to retrieve fw version and git hash for "
1669 uint16_t readValue = 0;
1675 if (majorVersion > 3) {
1678 status = Status::GENERIC_ERROR;
1681 uint8_t ccb_version = readValue & 0x00FF;
1682 switch (ccb_version) {
1696 LOG(
WARNING) <<
"Unknown CCB version read from ADSD3500: "
1701 uint8_t imager_version = (readValue & 0xFF00) >> 8;
1702 switch (imager_version) {
1719 LOG(
WARNING) <<
"Unknown imager type read from ADSD3500: "
1725 LOG(
ERROR) <<
"Failed to read imager type and CCB version (command "
1726 "0x0032). Possibly command is not implemented on the "
1727 "current adsd3500 firmware.";
1734 LOG(
ERROR) <<
"Old modes are no longer supported!";
1735 return Status::GENERIC_ERROR;
1743 <<
"Failed to check if ccb has mode map table support!";
1747 LOG(
INFO) <<
"CCB master is supported. Reading mode details "
1759 LOG(
ERROR) <<
"Failed to read mode map table from ccb!";
1775 modeDetails.
isPCM = modeStruct[
i].isPCM;
1783 if (!modeDetails.
isPCM) {
1785 "conf",
"xyz",
"metadata"};
1795 if (!modeDetails.
isPCM) {
1797 0x25, (uint8_t *)(&iniTableContent), 0x26);
1799 LOG(
ERROR) <<
"Failed to read ini content from nvm";
1803 if (iniTableContent.
INIIndex == 0xFF) {
1804 LOG(
INFO) <<
"No ini content for mode "
1805 << (int)modeDetails.
modeNumber <<
" in nvm!";
1818 LOG(
INFO) <<
"CCB master is disabled via control. Using "
1819 "sdk defined modes.";
1822 <<
"CCB master not supported. Using sdk defined modes.";
1826 uint8_t tempDealiasParams[32] = {0};
1827 tempDealiasParams[0] = modeToTest;
1830 uint16_t width1 = 512;
1831 uint16_t height1 = 512;
1833 uint16_t width2 = 320;
1834 uint16_t height2 = 256;
1839 LOG(
ERROR) <<
"Failed to read dealias parameters for adsd3500!";
1843 memcpy(&tempDealiasStruct, tempDealiasParams,
1847 if ((tempDealiasStruct.
n_rows == width1 &&
1848 tempDealiasStruct.
n_cols == height1) ||
1849 (tempDealiasStruct.
n_rows == width2 &&
1850 tempDealiasStruct.
n_cols == height2)) {
1859 LOG(
ERROR) <<
"Failed to get available frame types for the "
1860 "current configuration.";
1876 LOG(
ERROR) <<
"Failed to populate ini params struct!";
1905 uint16_t statusRegister;
1910 LOG(
ERROR) <<
"Failed to read status register!";
1916 DLOG(
INFO) <<
"statusRegister:" << statusRegister <<
"(" << adsd3500Status
1924 LOG(
ERROR) <<
"Failed to read imager status register!";
1929 LOG(
ERROR) <<
"Imager error detected. Error code: " << statusRegister;
1933 m_interruptCallback.second(adsd3500Status);
1940 int &imagerStatus) {
1955 LOG(
INFO) <<
"Using sensor configuration: " << sensorConf;
1957 LOG(
ERROR) <<
"Invalid sensor configuration provided!";
1970 return Adsd3500Status::INVALID_MODE;
1973 return Adsd3500Status::INVALID_JBLF_FILTER_SIZE;
1976 return Adsd3500Status::UNSUPPORTED_COMMAND;
1979 return Adsd3500Status::INVALID_MEMORY_REGION;
1982 return Adsd3500Status::INVALID_FIRMWARE_CRC;
1985 return Adsd3500Status::INVALID_IMAGER;
1988 return Adsd3500Status::INVALID_CCB;
1991 return Adsd3500Status::FLASH_HEADER_PARSE_ERROR;
1994 return Adsd3500Status::FLASH_FILE_PARSE_ERROR;
1997 return Adsd3500Status::SPIM_ERROR;
2000 return Adsd3500Status::INVALID_CHIPID;
2003 return Adsd3500Status::IMAGER_COMMUNICATION_ERROR;
2006 return Adsd3500Status::IMAGER_BOOT_FAILURE;
2009 return Adsd3500Status::FIRMWARE_UPDATE_COMPLETE;
2012 return Adsd3500Status::NVM_WRITE_COMPLETE;
2015 return Adsd3500Status::IMAGER_ERROR;
2018 LOG(
ERROR) <<
"Unknown ID: " << status;
2019 return Adsd3500Status::UNKNOWN_ERROR_ID;
2026 const void *p_tofi_cal_config) {
2031 status =
static_cast<Status>(ret);
2034 LOG(
ERROR) <<
"Failed getting ini parameters";
2035 return Status::GENERIC_ERROR;
2043 const void *p_tofi_cal_config) {
2048 status =
static_cast<Status>(ret);
2051 LOG(
ERROR) <<
"Failed setting ini parameters";
2052 return Status::GENERIC_ERROR;
2060 std::map<std::string, std::string> &
params) {
2062 auto it = std::find_if(
2065 return (iniF.imagerName == imager && iniF.modeName == mode);
2069 LOG(
WARNING) <<
"Cannot find default parameters for imager: " << imager
2070 <<
" and mode: " <<
mode;
2082 using namespace std;
2089 for (
auto &iniList : iniFileStructList) {
2091 if (iniList.modeName !=
"") {
2092 if (ccbmParams.modeNumber ==
2093 std::stoi(iniList.modeName.c_str())) {
2095 iniList.iniKeyValPairs[
"abThreshMin"] =
2096 std::to_string(ccbmParams.abThreshMin);
2097 iniList.iniKeyValPairs[
"confThresh"] =
2098 std::to_string(ccbmParams.confThresh);
2099 iniList.iniKeyValPairs[
"radialThreshMin"] =
2100 std::to_string(ccbmParams.radialThreshMin);
2101 iniList.iniKeyValPairs[
"radialThreshMax"] =
2102 std::to_string(ccbmParams.radialThreshMax);
2103 iniList.iniKeyValPairs[
"jblfApplyFlag"] =
2104 std::to_string(ccbmParams.jblfApplyFlag);
2105 iniList.iniKeyValPairs[
"jblfWindowSize"] =
2106 std::to_string(ccbmParams.jblfWindowSize);
2107 iniList.iniKeyValPairs[
"jblfGaussianSigma"] =
2108 std::to_string(ccbmParams.jblfGaussianSigma);
2109 iniList.iniKeyValPairs[
"jblfExponentialTerm"] =
2110 std::to_string(ccbmParams.jblfExponentialTerm);
2111 iniList.iniKeyValPairs[
"jblfMaxEdge"] =
2112 std::to_string(ccbmParams.jblfMaxEdge);
2113 iniList.iniKeyValPairs[
"jblfABThreshold"] =
2114 std::to_string(ccbmParams.jblfABThreshold);
2131 inistr += iniPairs.first +
"=" + iniPairs.second +
"\n";
2142 imager =
"adsd3100";
2144 imager =
"adtf3080";
2147 auto it = std::find_if(
2150 return (iniF.imagerName == imager && iniF.modeName == modestr);
2154 LOG(
WARNING) <<
"Cannot find default parameters for imager: " << imager
2155 <<
" and mode: " <<
mode;