25 #include <itksys/SystemTools.hxx>
29 :
itk::Object(), m_TrackingDevice(nullptr), m_UseCRC(true)
98 switch (hardwareHandshake)
108 return GenericCommand(
"COMM", ¶m);
114 return GenericCommand(
"INIT");
120 return GenericCommand(
"DSTART");
126 return GenericCommand(
"DSTOP");
132 return GenericCommand(
"IRINIT");
140 if (m_TrackingDevice ==
nullptr)
144 std::string fullcommand;
145 if (m_UseCRC ==
true)
146 fullcommand =
"IRCHK:0001";
148 fullcommand =
"IRCHK 0001";
150 returnValue = m_TrackingDevice->Send(&fullcommand, m_UseCRC);
154 m_TrackingDevice->ClearReceiveBuffer();
158 itksys::SystemTools::Delay(100);
166 m_TrackingDevice->ReceiveByte(&b);
168 if ((b ==
'0') || (b ==
'1'))
171 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
173 m_TrackingDevice->Receive(&readCRC, 4);
174 if (expectedCRC == readCRC)
190 std::string errorstring;
191 m_TrackingDevice->Receive(&errorstring, 4);
192 reply += errorstring;
193 static const std::string error(
"ERROR");
194 if (error.compare(0, 5, reply) == 0)
196 std::string errorcode;
197 m_TrackingDevice->Receive(&errorcode, 2);
200 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
202 m_TrackingDevice->Receive(&readCRC, 4);
203 if (expectedCRC == readCRC)
204 returnValue = this->GetErrorCode(&errorcode);
212 m_TrackingDevice->ClearReceiveBuffer();
221 if (m_TrackingDevice ==
nullptr)
226 char stringQueryType[3];
227 sprintf(stringQueryType,
"%02X", queryType);
229 if (m_UseCRC ==
true)
230 command = std::string(
"PHSR:") + std::string(stringQueryType);
232 command = std::string(
"PHSR ") + std::string(stringQueryType);
234 returnValue = m_TrackingDevice->Send(&command, m_UseCRC);
238 m_TrackingDevice->ClearReceiveBuffer();
242 itksys::SystemTools::Delay(100);
245 m_TrackingDevice->Receive(&reply, 2);
246 static const std::string error(
"ERROR");
247 if (error.compare(0, 2, reply) == 0)
250 m_TrackingDevice->Receive(&ror, 3);
252 std::string errorcode;
253 m_TrackingDevice->Receive(&errorcode, 2);
256 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
258 m_TrackingDevice->Receive(&readCRC, 4);
259 if (expectedCRC == readCRC)
260 returnValue = this->GetErrorCode(&errorcode);
266 unsigned int numberOfHandles = 0;
270 s >> numberOfHandles;
271 if (numberOfHandles > 16)
277 std::string handleInformation;
278 portHandles->clear();
279 for (
unsigned int i = 0; i < numberOfHandles; i++)
281 m_TrackingDevice->Receive(&handleInformation, 5);
282 *portHandles += handleInformation.substr(0, 2);
283 reply += handleInformation;
286 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
288 m_TrackingDevice->Receive(&readCRC, 4);
289 if (expectedCRC == readCRC)
296 m_TrackingDevice->ClearReceiveBuffer();
305 if (m_TrackingDevice ==
nullptr)
310 if (m_UseCRC ==
true)
311 command =
"PHRQ:*********1****";
313 command =
"PHRQ *********1****";
315 returnValue = m_TrackingDevice->Send(&command, m_UseCRC);
319 m_TrackingDevice->ClearReceiveBuffer();
323 itksys::SystemTools::Delay(100);
326 m_TrackingDevice->Receive(&reply, 2);
327 static const std::string error(
"ERROR");
328 if (error.compare(0, 2, reply) == 0)
331 m_TrackingDevice->Receive(&ror, 3);
333 std::string errorcode;
334 m_TrackingDevice->Receive(&errorcode, 2);
337 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
339 m_TrackingDevice->Receive(&readCRC, 4);
340 if (expectedCRC == readCRC)
341 returnValue = this->GetErrorCode(&errorcode);
349 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
351 m_TrackingDevice->Receive(&readCRC, 4);
352 if (expectedCRC == readCRC)
358 m_TrackingDevice->ClearReceiveBuffer();
367 if (m_TrackingDevice ==
nullptr)
370 if (sromDataLength > 1024)
373 if (sromDataLength == 0)
377 std::string basecommand;
378 if (m_UseCRC ==
true)
379 basecommand =
"PVWR:";
381 basecommand =
"PVWR ";
383 std::string hexSROMData;
384 hexSROMData.reserve(2 * sromDataLength);
385 char hexcharacter[20];
386 for (
unsigned int i = 0; i < sromDataLength; i++)
388 sprintf(hexcharacter,
"%02X", sromData[i]);
390 hexSROMData += hexcharacter;
393 unsigned int zerosToPad = 128 - (hexSROMData.size() % 128);
395 hexSROMData.append(zerosToPad,
'0');
397 std::string fullcommand;
398 for (
unsigned int j = 0; j < hexSROMData.size(); j += 128)
400 sprintf(hexcharacter,
"%s%04X", portHandle->c_str(), j/2);
401 fullcommand = basecommand + hexcharacter + hexSROMData.substr(j, 128);
402 returnValue = m_TrackingDevice->Send(&fullcommand, m_UseCRC);
403 itksys::SystemTools::Delay(50);
406 returnValue = this->ParseOkayError();
411 m_TrackingDevice->ClearReceiveBuffer();
420 if (m_TrackingDevice ==
nullptr)
424 std::string fullcommand;
425 if (m_UseCRC ==
true)
426 fullcommand = std::string(
"PINIT:") + *portHandle;
428 fullcommand = std::string(
"PINIT ") + *portHandle;
430 returnValue = m_TrackingDevice->Send(&fullcommand, m_UseCRC);
434 m_TrackingDevice->ClearReceiveBuffer();
439 itksys::SystemTools::Delay(100);
441 m_TrackingDevice->Receive(&reply, 4);
444 static const std::string okay(
"OKAYA896");
445 static const std::string error(
"ERROR");
446 static const std::string warning(
"WARNING7423");
448 if (okay.compare(0, 4, reply) == 0)
451 m_TrackingDevice->Receive(&reply, 4);
452 if (okay.compare(4, 4, reply, 0, 4) == 0)
457 else if (warning.compare(0, 4, reply) == 0)
460 m_TrackingDevice->Receive(&reply, 4);
461 if (warning.compare(4, 7, reply, 0, 7) == 0)
466 else if (error.compare(0, 4, reply) == 0)
469 m_TrackingDevice->ReceiveByte(&b);
471 std::string errorcode;
472 m_TrackingDevice->Receive(&errorcode, 2);
475 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
477 m_TrackingDevice->Receive(&readCRC, 4);
478 if (expectedCRC == readCRC)
479 returnValue = this->GetErrorCode(&errorcode);
488 m_TrackingDevice->ReceiveByte(&b);
491 m_TrackingDevice->ClearReceiveBuffer();
499 if (portHandle !=
nullptr)
500 param = *portHandle + (char) prio;
503 return this->GenericCommand(
"PENA", ¶m);
510 if (m_UseCRC) command =
"PHINF:" + portHandle;
511 else command =
"PHINF " + portHandle;
515 m_TrackingDevice->ClearReceiveBuffer();
516 m_TrackingDevice->Receive(portInfo, 33);
517 m_TrackingDevice->ClearReceiveBuffer();
519 else m_TrackingDevice->ClearReceiveBuffer();
526 return this->GenericCommand(
"PDIS", portHandle);
532 return this->GenericCommand(
"PHF", portHandle);
552 return this->GenericCommand(
"IRATE", ¶m);
560 if (m_TrackingDevice ==
nullptr)
564 if ((count >= 1) && (count <= 9))
570 std::string fullcommand;
571 if (m_UseCRC ==
true)
572 fullcommand =
"BEEP:" + p;
574 fullcommand =
"BEEP " + p;
576 returnValue = m_TrackingDevice->Send(&fullcommand, m_UseCRC);
580 m_TrackingDevice->ClearReceiveBuffer();
585 itksys::SystemTools::Delay(100);
589 m_TrackingDevice->ReceiveByte(&b);
591 if ((b ==
'0') || (b ==
'1'))
594 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
596 m_TrackingDevice->Receive(&readCRC, 4);
597 if (expectedCRC == readCRC)
604 std::string errorstring;
605 m_TrackingDevice->Receive(&errorstring, 4);
606 reply += errorstring;
607 static const std::string error(
"ERROR");
608 if (error.compare(0, 5, reply) == 0)
610 std::string errorcode;
611 m_TrackingDevice->Receive(&errorcode, 2);
614 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
616 m_TrackingDevice->Receive(&readCRC, 4);
617 if (expectedCRC == readCRC)
618 returnValue = this->GetErrorCode(&errorcode);
626 m_TrackingDevice->ClearReceiveBuffer();
633 std::string param =
"80";
634 if (resetFrameCounter ==
true)
635 return this->GenericCommand(
"TSTART", ¶m);
637 return this->GenericCommand(
"TSTART");
643 return this->GenericCommand(
"TSTOP");
649 std::string param = portHandle + state;
650 return this->GenericCommand(
"PSOUT", ¶m);
658 if(trackIndividualMarkers)
659 markerPositions->clear();
661 if (m_TrackingDevice ==
nullptr)
665 std::string fullcommand;
666 if (trackIndividualMarkers)
668 if (m_UseCRC ==
true)
669 fullcommand =
"TX:1001";
671 fullcommand =
"TX 1001";
674 if (m_UseCRC ==
true)
680 returnValue = m_TrackingDevice->Send(&fullcommand, m_UseCRC);
684 m_TrackingDevice->ClearReceiveBuffer();
690 m_TrackingDevice->Receive(&reply, 2);
692 static const std::string error(
"ERROR");
693 if (error.compare(0, 2, reply) == 0)
695 m_TrackingDevice->Receive(&s, 3);
697 std::string errorcode;
698 m_TrackingDevice->Receive(&errorcode, 2);
701 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
703 m_TrackingDevice->Receive(&readCRC, 4);
704 if (expectedCRC == readCRC)
706 returnValue = this->GetErrorCode(&errorcode);
716 std::stringstream converter;
717 unsigned int numberOfHandles = 0;
718 converter << std::hex << reply;
719 converter >> numberOfHandles;
724 for (
unsigned int i = 0; i < numberOfHandles; i++)
727 m_TrackingDevice->Receive(&s, 2);
736 static const std::string missing(
"MISSING");
737 static const std::string disabled(
"DISABLED");
738 static const std::string unoccupied(
"UNOCCUPIED");
740 m_TrackingDevice->Receive(&s, 6);
742 if (missing.compare(0, 6, s) == 0)
744 tool->SetErrorMessage(
"Tool is reported as 'missing'.");
745 tool->SetDataValid(
false);
746 m_TrackingDevice->Receive(&s, 18);
749 else if (disabled.compare(0, 6, s) == 0)
751 tool->SetErrorMessage(
"Tool is reported as 'disabled'.");
752 tool->SetDataValid(
false);
753 m_TrackingDevice->Receive(&s, 3);
756 else if (unoccupied.compare(0, 6, s) == 0)
758 tool->SetErrorMessage(
"Tool is reported as 'unoccupied'.");
759 tool->SetDataValid(
false);
760 m_TrackingDevice->Receive(&s, 21);
766 signed int number = 0;
767 float localPos[3] = {0.0, 0.0, 0.0};
768 float localQuat[4] = {0.0, 0.0, 0.0, 0.0};
769 float localError = 0.0;
770 unsigned long localPortStatus = 0;
771 unsigned int localFrameNumber = 0;
774 converter << std::dec << s;
779 localQuat[0] = number / 10000.0;
780 for (
unsigned int i = 1; i < 4; i++)
782 m_TrackingDevice->Receive(&s, 6);
784 converter << std::dec << s;
788 localQuat[i] = number / 10000.0;
791 for (
auto & localPo : localPos)
793 m_TrackingDevice->Receive(&s, 7);
795 converter << std::dec << s;
799 localPo = number / 100.0;
802 m_TrackingDevice->Receive(&s, 6);
804 converter << std::dec << s;
808 localError = number / 10000.0;
810 m_TrackingDevice->Receive(&s, 8);
812 converter << std::hex << s;
813 converter >> localPortStatus;
817 m_TrackingDevice->Receive(&s, 8);
819 converter << std::hex << s;
820 converter >> localFrameNumber;
825 mitk::Quaternion orientation(localQuat[1], localQuat[2], localQuat[3], localQuat[0]);
830 orientation[0] *= -1;
831 orientation[1] *= -1;
832 orientation[2] *= -1;
836 tool->SetOrientation(orientation);
838 position[0] = localPos[0];
839 position[1] = localPos[1];
840 position[2] = localPos[2];
841 tool->SetPosition(position);
842 tool->SetTrackingError(localError);
843 tool->SetErrorMessage(
"");
844 tool->SetDataValid(
true);
845 m_TrackingDevice->Receive(&s, 1);
852 if(trackIndividualMarkers)
855 m_TrackingDevice->Receive(&s, 2);
857 unsigned int numberOfMarkers = 0;
858 converter << std::hex << s;
859 converter >> numberOfMarkers;
863 unsigned int oovReplySize = (
unsigned int)ceil((
double)numberOfMarkers/4.0);
864 unsigned int nbMarkersInVolume = 0;
867 for (
unsigned int i = 0; i < oovReplySize; i++)
869 m_TrackingDevice->ReceiveByte(&c);
871 nbMarkersInVolume += ByteToNbBitsOn(c);
874 nbMarkersInVolume = numberOfMarkers-nbMarkersInVolume;
877 for (
unsigned int i = 0; i < nbMarkersInVolume; i++)
880 signed int number = 0;
883 for (
unsigned int i = 0; i < 3; i++)
885 m_TrackingDevice->Receive(&s, 7);
887 converter << std::dec << s;
891 markerPosition[i] = number / 100.0;
893 markerPositions->push_back(markerPosition);
900 m_TrackingDevice->Receive(&s, 4);
903 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
905 m_TrackingDevice->Receive(&readCRC, 4);
906 if (expectedCRC == readCRC)
914 m_TrackingDevice->InvalidateAll();
915 if(trackIndividualMarkers)
916 markerPositions->clear();
921 m_TrackingDevice->Receive(&s, 1);
922 m_TrackingDevice->ClearReceiveBuffer();
931 markerPositions->clear();
933 if (m_TrackingDevice ==
nullptr)
937 std::string fullcommand;
938 if (m_UseCRC ==
true)
939 fullcommand =
"TX:1001";
941 fullcommand =
"TX 1001";
943 returnValue = m_TrackingDevice->Send(&fullcommand, m_UseCRC);
948 m_TrackingDevice->Receive(&reply, 2);
950 static const std::string error(
"ERROR");
951 if (error.compare(0, 2, reply) == 0)
953 m_TrackingDevice->Receive(&s, 3);
955 std::string errorcode;
956 m_TrackingDevice->Receive(&errorcode, 2);
959 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
961 m_TrackingDevice->Receive(&readCRC, 4);
962 if (expectedCRC == readCRC)
964 returnValue = this->GetErrorCode(&errorcode);
974 std::stringstream converter;
975 unsigned int numberOfHandles = 0;
976 converter << std::hex << reply;
977 converter >> numberOfHandles;
982 for (
unsigned int i = 0; i < numberOfHandles; i++)
985 m_TrackingDevice->Receive(&s, 2);
994 static const std::string missing(
"MISSING");
995 static const std::string disabled(
"DISABLED");
996 static const std::string unoccupied(
"UNOCCUPIED");
998 m_TrackingDevice->Receive(&s, 6);
1000 if (missing.compare(0, 6, s) == 0)
1002 tool->SetErrorMessage(
"Tool is reported as 'missing'.");
1003 tool->SetDataValid(
false);
1004 m_TrackingDevice->Receive(&s, 18);
1007 else if (disabled.compare(0, 6, s) == 0)
1009 tool->SetErrorMessage(
"Tool is reported as 'disabled'.");
1010 tool->SetDataValid(
false);
1011 m_TrackingDevice->Receive(&s, 19);
1014 else if (unoccupied.compare(0, 6, s) == 0)
1016 tool->SetErrorMessage(
"Tool is reported as 'unoccupied'.");
1017 tool->SetDataValid(
false);
1018 m_TrackingDevice->Receive(&s, 21);
1024 signed int number = 0;
1025 float localPos[3] = {0.0, 0.0, 0.0};
1026 float localQuat[4] = {0.0, 0.0, 0.0, 0.0};
1027 float localError = 0.0;
1028 unsigned long localPortStatus = 0;
1029 unsigned int localFrameNumber = 0;
1032 converter << std::dec << s;
1033 converter >> number;
1037 localQuat[0] = number / 10000.0;
1038 for (
unsigned int i = 1; i < 4; i++)
1040 m_TrackingDevice->Receive(&s, 6);
1042 converter << std::dec << s;
1043 converter >> number;
1046 localQuat[i] = number / 10000.0;
1049 for (
auto & localPo : localPos)
1051 m_TrackingDevice->Receive(&s, 7);
1053 converter << std::dec << s;
1054 converter >> number;
1057 localPo = number / 100.0;
1060 m_TrackingDevice->Receive(&s, 6);
1062 converter << std::dec << s;
1063 converter >> number;
1066 localError = number / 10000.0;
1068 m_TrackingDevice->Receive(&s, 8);
1070 converter << std::hex << s;
1071 converter >> localPortStatus;
1075 m_TrackingDevice->Receive(&s, 8);
1077 converter << std::hex << s;
1078 converter >> localFrameNumber;
1083 mitk::Quaternion orientation(localQuat[1], localQuat[2], localQuat[3], localQuat[0]);
1084 tool->SetOrientation(orientation);
1086 position[0] = localPos[0];
1087 position[1] = localPos[1];
1088 position[2] = localPos[2];
1089 tool->SetPosition(position);
1090 tool->SetTrackingError(localError);
1091 tool->SetErrorMessage(
"");
1092 tool->SetDataValid(
true);
1093 m_TrackingDevice->Receive(&s, 1);
1100 m_TrackingDevice->Receive(&s, 2);
1102 unsigned int numberOfMarkers = 0;
1103 converter << std::hex << s;
1104 converter >> numberOfMarkers;
1108 unsigned int oovReplySize = (
unsigned int)ceil((
double)numberOfMarkers/4.0);
1109 unsigned int nbMarkersInVolume = 0;
1112 for (
unsigned int i = 0; i < oovReplySize; i++)
1114 m_TrackingDevice->ReceiveByte(&c);
1116 nbMarkersInVolume += ByteToNbBitsOn(c);
1119 nbMarkersInVolume = numberOfMarkers-nbMarkersInVolume;
1122 for (
unsigned int i = 0; i < nbMarkersInVolume; i++)
1125 signed int number = 0;
1128 for (
unsigned int i = 0; i < 3; i++)
1130 m_TrackingDevice->Receive(&s, 7);
1132 converter << std::dec << s;
1133 converter >> number;
1136 markerPosition[i] = number / 100.0;
1138 markerPositions->push_back(markerPosition);
1147 m_TrackingDevice->Receive(&s, 4);
1150 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
1151 std::string readCRC;
1152 m_TrackingDevice->Receive(&readCRC, 4);
1153 if (expectedCRC == readCRC)
1161 markerPositions->clear();
1162 m_TrackingDevice->InvalidateAll();
1167 m_TrackingDevice->Receive(&s, 1);
1168 m_TrackingDevice->ClearReceiveBuffer();
1175 std::cout <<
"BX() not implemented yet, using TX() instead." << std::endl;
1182 if (m_TrackingDevice ==
nullptr)
1187 std::string fullcommand;
1188 if (m_UseCRC ==
true)
1189 fullcommand =
"VER:4";
1191 fullcommand =
"VER 4";
1193 returnValue = m_TrackingDevice->Send(&fullcommand, m_UseCRC);
1197 m_TrackingDevice->ClearReceiveBuffer();
1202 m_TrackingDevice->Receive(&reply, 5);
1203 static const std::string error(
"ERROR");
1204 if (error.compare(0, 6, reply) == 0)
1206 std::string errorcode;
1207 m_TrackingDevice->Receive(&errorcode, 2);
1210 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
1211 std::string readCRC;
1212 m_TrackingDevice->Receive(&readCRC, 4);
1213 if (expectedCRC == readCRC)
1214 returnValue = this->GetErrorCode(&errorcode);
1221 m_TrackingDevice->ReceiveLine(&s);
1223 std::string upperCaseReply;
1224 upperCaseReply.resize(reply.size());
1225 std::transform (reply.begin(), reply.end(), upperCaseReply.begin(), toupper);
1226 if (upperCaseReply.find(
"POLARIS") != std::string::npos)
1228 else if (upperCaseReply.find(
"AURORA") != std::string::npos)
1234 itksys::SystemTools::Delay(500);
1235 m_TrackingDevice->ClearReceiveBuffer();
1246 if (m_TrackingDevice ==
nullptr)
1250 if (markerPositions ==
nullptr)
1252 std::cout <<
"ERROR: markerPositions==NULL" << std::endl;
1256 markerPositions->clear();
1258 if (m_TrackingDevice->GetToolCount() == 0)
1260 std::cout <<
"ERROR: no tools present" << std::endl;
1263 const TrackingTool* t = m_TrackingDevice->GetTool(static_cast<unsigned int>(0));
1267 std::cout <<
"ERROR: no tool present" << std::endl;
1271 if (portHandle.size() == 0)
1273 std::cout <<
"ERROR: no port handle" << std::endl;
1278 std::string fullcommand;
1279 if (m_UseCRC ==
true)
1280 fullcommand =
"3D:" + portHandle +
"5";
1282 fullcommand =
"3D " + portHandle +
"5";
1284 m_TrackingDevice->ClearReceiveBuffer();
1285 returnValue = m_TrackingDevice->Send(&fullcommand, m_UseCRC);
1294 std::cout <<
"ERROR: receive_value != NDIOKAY" << std::endl;
1295 return receivevalue;
1298 static const std::string error(
"ERROR");
1299 if (error.compare(0, 3, reply) == 0)
1301 m_TrackingDevice->Receive(&s, 2);
1303 std::string errorcode;
1304 m_TrackingDevice->Receive(&errorcode, 2);
1307 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
1308 std::string readCRC;
1309 m_TrackingDevice->Receive(&readCRC, 4);
1310 if (expectedCRC == readCRC)
1312 returnValue = this->GetErrorCode(&errorcode);
1321 signed int number = 0;
1327 std::stringstream converter;
1328 unsigned int numberOfMarkers = 0;
1329 converter << std::dec << reply;
1330 converter >> numberOfMarkers;
1334 for (
unsigned int markerID = 0; markerID < numberOfMarkers; markerID++)
1336 m_TrackingDevice->Receive(&s, 1);
1339 for (
unsigned int i = 0; i < 3; i++)
1341 receivevalue = m_TrackingDevice->Receive(&s, 9);
1344 markerPositions->clear();
1345 std::cout <<
"ERROR: receive_value != NDIOKAY" << std::endl;
1346 return receivevalue;
1349 converter << std::dec << s;
1350 converter >> number;
1353 p[i] = number / 10000.0;
1356 receivevalue = m_TrackingDevice->Receive(&s, 4);
1359 markerPositions->clear();
1360 std::cout <<
"ERROR: receive_value != NDIOKAY" << std::endl;
1361 return receivevalue;
1364 converter << std::dec << s;
1365 converter >> number;
1370 receivevalue = m_TrackingDevice->Receive(&s, 1);
1373 markerPositions->clear();
1374 std::cout << std::endl << std::endl << std::endl <<
"ERROR: POS3D != NDIOKAY" << std::endl;
1375 return receivevalue;
1379 markerPositions->push_back(p);
1384 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
1385 std::string readCRC;
1386 m_TrackingDevice->Receive(&readCRC, 4);
1387 if (expectedCRC == readCRC)
1394 std::cout <<
"ERROR: receive_value != NDIOKAY" << std::endl;
1396 markerPositions->clear();
1401 m_TrackingDevice->Receive(&s, 1);
1402 m_TrackingDevice->ClearReceiveBuffer();
1412 if (m_TrackingDevice ==
nullptr)
1416 if (parameter !=
nullptr)
1422 std::string fullcommand;
1423 if (m_UseCRC ==
true)
1424 fullcommand = command +
":" + p;
1426 fullcommand = command +
" " + p;
1429 m_TrackingDevice->ClearReceiveBuffer();
1433 returnValue = m_TrackingDevice->Send(&fullcommand, m_UseCRC);
1437 m_TrackingDevice->ClearReceiveBuffer();
1441 itksys::SystemTools::Delay(100);
1446 this->ParseOkayError();
1455 else if (c ==
'1' || c ==
'2' || c ==
'4' || c ==
'8')
1457 else if (c ==
'3' || c ==
'5' || c ==
'9' || c ==
'6' || c ==
'A' || c ==
'C')
1459 else if (c ==
'7' || c ==
'B' || c ==
'D' || c ==
'E')
1475 m_TrackingDevice->Receive(&reply, 4);
1478 static const std::string okay(
"OKAYA896");
1479 static const std::string error(
"ERROR");
1481 if (okay.compare(0, 4, reply) == 0)
1484 m_TrackingDevice->Receive(&reply, 4);
1485 if (okay.compare(4, 4, reply, 0, 4) == 0)
1490 else if (error.compare(0, 4, reply) == 0)
1493 m_TrackingDevice->ReceiveByte(&b);
1495 std::string errorcode;
1496 m_TrackingDevice->Receive(&errorcode, 2);
1499 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
1500 std::string readCRC;
1501 m_TrackingDevice->Receive(&readCRC, 4);
1502 if (expectedCRC == readCRC)
1503 returnValue = this->GetErrorCode(&errorcode);
1512 m_TrackingDevice->ReceiveByte(&b);
1513 m_TrackingDevice->ClearReceiveBuffer();
1520 if (input->compare(
"01") == 0)
1522 else if (input->compare(
"02") == 0)
1524 else if (input->compare(
"03") == 0)
1526 else if (input->compare(
"04") == 0)
1528 else if (input->compare(
"05") == 0)
1530 else if (input->compare(
"06") == 0)
1532 else if (input->compare(
"07") == 0)
1534 else if (input->compare(
"08") == 0)
1536 else if (input->compare(
"09") == 0)
1538 else if (input->compare(
"0A") == 0)
1540 else if (input->compare(
"0B") == 0)
1542 else if (input->compare(
"0C") == 0)
1544 else if (input->compare(
"0D") == 0)
1546 else if (input->compare(
"0E") == 0)
1550 else if (input->compare(
"10") == 0)
1552 else if (input->compare(
"11") == 0)
1554 else if (input->compare(
"12") == 0)
1556 else if (input->compare(
"13") == 0)
1558 else if (input->compare(
"14") == 0)
1560 else if (input->compare(
"16") == 0)
1562 else if (input->compare(
"1B") == 0)
1564 else if (input->compare(
"1F") == 0)
1566 else if (input->compare(
"22") == 0)
1568 else if (input->compare(
"23") == 0)
1570 else if (input->compare(
"2A") == 0)
1572 else if (input->compare(
"2B") == 0)
1574 else if (input->compare(
"2C") == 0)
1576 else if (input->compare(
"2D") == 0)
1578 else if (input->compare(
"2E") == 0)
1580 else if (input->compare(
"2F") == 0)
1582 else if (input->compare(
"32") == 0)
1591 if (m_TrackingDevice ==
nullptr)
1597 std::string command;
1599 command =
"APIREV:";
1601 command =
"APIREV ";
1603 returnValue = m_TrackingDevice->Send(&command, m_UseCRC);
1607 m_TrackingDevice->ClearReceiveBuffer();
1616 m_TrackingDevice->Receive(&reply, 5);
1619 static const std::string error(
"ERROR");
1620 if (error.compare(0, 6, reply) == 0)
1622 std::string errorcode;
1623 m_TrackingDevice->Receive(&errorcode, 2);
1627 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
1628 std::string readCRC;
1629 m_TrackingDevice->Receive(&readCRC, 4);
1631 if (expectedCRC == readCRC)
1632 returnValue = this->GetErrorCode(&errorcode);
1640 m_TrackingDevice->Receive(&s, 4);
1644 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
1645 std::string readCRC;
1646 m_TrackingDevice->Receive(&readCRC, 4);
1648 if (expectedCRC == readCRC)
1655 m_TrackingDevice->ClearReceiveBuffer();
1662 if (m_TrackingDevice ==
nullptr)
1668 std::string command;
1670 command =
"SFLIST:03";
1672 command =
"SFLIST 03";
1674 returnValue = m_TrackingDevice->Send(&command, m_UseCRC);
1678 m_TrackingDevice->ClearReceiveBuffer();
1684 m_TrackingDevice->Receive(&reply, 5);
1686 static const std::string error(
"ERROR");
1687 if (error.compare(0,6,reply) == 0)
1689 std::string errorcode;
1690 m_TrackingDevice->Receive(&errorcode, 2);
1694 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
1695 std::string readCRC;
1696 m_TrackingDevice->Receive(&readCRC, 4);
1698 if (expectedCRC == readCRC)
1699 returnValue = this->GetErrorCode(&errorcode);
1707 std::stringstream converter;
1708 unsigned int numberOfVolumes = 0;
1709 converter << std::hex << reply[0];
1710 converter >> numberOfVolumes;
1714 if ( numberOfVolumes > 9 )
1716 MITK_WARN <<
"Number of volumes (" << numberOfVolumes
1717 <<
") is not smaller then ten as it was expected. Cannot get supported volumes.";
1718 numberOfVolumes = 0;
1719 reply[0] = numberOfVolumes;
1723 if (numberOfVolumes>0)
1726 for (
unsigned int i = 0; i<numberOfVolumes; i++)
1728 std::string currentVolume;
1732 currentVolume.append(reply,1,4);
1734 m_TrackingDevice->Receive(&s, 69);
1744 m_TrackingDevice->ReceiveLine(&l);
1748 m_TrackingDevice->Receive(&s, 73);
1754 MITK_INFO <<
"Cannot get information of tracking volume " << i <<
". Abort getting of tracking volumes.";
1755 numberOfVolumes = 0;
1756 reply[0] = numberOfVolumes;
1763 MITK_INFO<<
"Standard volume supported \n";
1765 MITK_INFO<<
"Spectra pyramid volume supported \n";
1767 MITK_INFO<<
"Spectra extended pyramid volume supported \n";
1780 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
1781 std::string readCRC;
1782 m_TrackingDevice->Receive(&readCRC, 4);
1795 m_TrackingDevice->ClearReceiveBuffer();
1801 if (m_TrackingDevice ==
nullptr)
1808 unsigned int numberOfVolumes;
1811 if (!m_TrackingDevice->GetSupportedVolumes(&numberOfVolumes, &volumes, &volumesDimensions))
1815 if (volumes.empty())
1820 unsigned int index = 1;
1821 auto it = volumes.begin();
1822 while (it != volumes.end())
1824 if ((*it) == deviceData.
Model)
1831 if (it == volumes.end() || index > numberOfVolumes)
1837 std::string command;
1844 std::stringstream s;
1848 returnValue = m_TrackingDevice->Send(&command, m_UseCRC);
1852 m_TrackingDevice->ClearReceiveBuffer();
1858 m_TrackingDevice->Receive(&reply, 4);
1860 static const std::string error(
"ERRO");
1861 if (error.compare(reply) == 0)
1864 m_TrackingDevice->Receive(&s, 1);
1867 std::string errorcode;
1868 m_TrackingDevice->Receive(&errorcode, 2);
1872 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
1873 std::string readCRC;
1874 m_TrackingDevice->Receive(&readCRC, 4);
1876 if (expectedCRC == readCRC)
1877 returnValue = this->GetErrorCode(&errorcode);
1884 std::string expectedCRC = m_TrackingDevice->CalcCRC(&reply);
1885 std::string readCRC;
1886 m_TrackingDevice->Receive(&readCRC, 4);
1888 if (expectedCRC == readCRC)
1893 m_TrackingDevice->ClearReceiveBuffer();
NDIErrorCode TSTART(bool resetFrameCounter=false)
Start Tracking Mode. The tracking system must be in setup mode and must be initialized.
NDIErrorCode TX(bool trackIndividualMarkers=false, MarkerPointContainerType *markerPositions=nullptr)
Report transformations in text mode. Optionally, individual markers can be tracked.
NDIErrorCode INIT()
Initialize the Measurement System.
itk::SmartPointer< Self > Pointer
std::vector< std::string > NDITrackingVolumeContainerType
vector of tracking volumes
NDIErrorCode PDIS(std::string *portHandle)
Port Disable. Will disable a port that has been enabled with PENA.
IlluminationActivationRate
activation rate of IR illuminator for NDI Polaris tracking device
NDIErrorCode POS3D(MarkerPointContainerType *markerPositions)
Report 3D Positions of single markers. can only be used in diagnostics mode.
NDIErrorCode IRINIT()
Initialize the System to Check for Infrared.
itk::Point< double > MarkerPointType
PHSRQueryType
Query mode for NDI tracking devices.
NDIErrorCode VER(mitk::TrackingDeviceType &t)
returns if the tracking device is a Polaris or an Aurora system
static void info(const char *fmt,...)
NDIErrorCode TX1000(MarkerPointContainerType *markerPositions)
Report transformations in text mode.
NDIErrorCode BX()
Report transformations in binary mode.
std::vector< int > TrackingVolumeDimensionType
List of the supported tracking volume dimensions.
NDIErrorCode TSTOP()
Stop Tracking Mode. The tracking system must be in Tracking mode.
unsigned int ByteToNbBitsOn(char &c) const
NDIErrorCode VSEL(mitk::TrackingDeviceData deviceData)
Sets the tracking volume to the given type. Check available tracking volumes with SFLIST first...
NDIErrorCode PENA(std::string *portHandle, TrackingPriority prio)
Port Enable. Will enable a port that has been initialized with PINIT.
NDIErrorCode DSTOP()
Stop the Diagnostic Mode.
NDIErrorCode IRCHK(bool *IRdetected)
This version of IRCHK uses only the simple "presence of infrared light" call, that returns a binary "...
NDIErrorCode GenericCommand(const std::string command, const std::string *parameter=nullptr)
std::vector< MarkerPointType > MarkerPointContainerType
vnl_quaternion< ScalarType > Quaternion
NDIErrorCode COMM(mitk::SerialCommunication::BaudRate baudRate, mitk::SerialCommunication::DataBits dataBits, mitk::SerialCommunication::Parity parity, mitk::SerialCommunication::StopBits stopBits, mitk::SerialCommunication::HardwareHandshake hardwareHandshake)
Change Serial Communication Parameters.
NDIErrorCode PHRQ(std::string *portHandle)
Port Handle Request. Will request a Port Handle for a wireless tool and return it in the string portH...
NDIProtocol()
Set whether to append a CRC16 checksum to each message.
NDIErrorCode BEEP(unsigned char count)
Sounding the measurement system beeper. The tracking system will beep one to nine times...
NDIErrorCode PVWR(std::string *portHandle, const unsigned char *sromData, unsigned int sromDataLength)
Port Virtual Write. Writes an SROM Image data to a tool.
std::string TrackingDeviceType
NDIErrorCode PHF(std::string *portHandle)
Port Handle Free. Frees the port handle.
NDIErrorCode ParseOkayError()
NDIErrorCode PHSR(PHSRQueryType queryType, std::string *portHandles)
Port Handle Search. Will write returned port handles to the string portHandles.
NDIErrorCode GetErrorCode(const std::string *input)
returns the error code for an Error String returned from the NDI tracking device
NDIErrorCode
Error codes of NDI tracking devices.
NDIErrorCode PHINF(std::string portHandle, std::string *portInfo)
NDIErrorCode DSTART()
Start the Diagnostic Mode.
NDIErrorCode APIREV(std::string *revision)
Gives information about the tool which is assosiated with the port handle. Writes portInfo to the str...
NDIErrorCode PINIT(std::string *portHandle)
Port Initialize. Will initialize a Port that has been acquired with PHRQ and has been assigned a SROM...
NDIErrorCode PSOUT(std::string portHandle, std::string state)
Set GPIO Output (Aurora)
NDIErrorCode SFLIST(std::string *info)
Returns information about the supported feature of the tracking system.
NDIErrorCode IRATE(IlluminationActivationRate rate)
Setting the illuminator rate. Will set the refresh rate for the illuminator for wireless tools...