7 #include "PlusConfigure.h" 13 #include "vtkImageData.h" 14 #include "vtkDICOMImageReader.h" 15 #include "vtkObjectFactory.h" 18 #include "vtkIGSIOTrackedFrameList.h" 21 #include <vtkImageFlip.h> 22 #include <vtkPointData.h> 23 #include <vtkDirectory.h> 30 static const std::string CAPISTRANO_COMMAND =
"CapistranoCommand";
35 : ResponseExpected(true)
38 this->SetName(CAPISTRANO_COMMAND);
50 cmdNames.push_back(CAPISTRANO_COMMAND);
57 if (commandName.empty() || igsioCommon::IsEqualInsensitive(commandName, CAPISTRANO_COMMAND))
59 desc += CAPISTRANO_COMMAND;
60 desc +=
": Send commands to Capistrano device.";
68 return this->DeviceId;
74 this->DeviceId = deviceId;
80 return this->CommandName;
86 this->CommandName =
text;
92 return this->CommandValue;
98 this->CommandValue =
text;
116 this->
SetDeviceId(aConfig->GetAttribute(
"UsDeviceId"));
119 for (
int elemIndex = 0; elemIndex < aConfig->GetNumberOfNestedElements(); ++elemIndex)
121 vtkXMLDataElement* currentElem = aConfig->GetNestedElement(elemIndex);
122 if (igsioCommon::IsEqualInsensitive(currentElem->GetName(),
"Parameter"))
124 const char* parameterName = currentElem->GetAttribute(
"Name");
125 const char* parameterValue = currentElem->GetAttribute(
"Value");
128 parameterValue =
"None";
132 LOG_ERROR(
"Unable to find required Name" << (currentElem->GetName() ? currentElem->GetName() :
"(undefined)") <<
" element in CapistranoCommand command");
150 XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(DeviceId, aConfig);
151 XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(CommandName, aConfig);
152 XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(CommandValue, aConfig);
160 LOG_DEBUG(
"vtkPlusSetUsParameterCommand::Execute: " << (!this->
Name.empty() ? this->
Name :
"(undefined)")
161 <<
", device: " << (this->DeviceId.empty() ?
"(undefined)" : this->DeviceId));
163 if (this->
Name.empty())
168 else if (!igsioCommon::IsEqualInsensitive(this->
Name, CAPISTRANO_COMMAND))
178 + (this->DeviceId.empty() ?
"(undefined)" : this->DeviceId) + std::string(
" is not found."));
184 std::string resultString =
"<CommandReply>";
185 std::string error =
"";
186 std::map < std::string, std::pair<IANA_ENCODING_TYPE, std::string> > metaData;
188 bool hasFailure =
false;
190 std::list<std::pair<std::string, std::string>>::iterator paramIt;
193 std::string parameterName = paramIt->first;
194 std::string
value = paramIt->second;
195 resultString +=
"<Parameter Name=\"" + parameterName +
"\"";
209 double parameterValue = vtkVariant(
value).ToDouble(&valid);
212 error +=
"Failed to parse " + parameterName +
". ";
213 resultString +=
" Success=\"false\"";
214 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"FAIL");
233 LOG_WARNING(
"This command does not require a value");
238 error +=
"Invalid parameter " + parameterName +
". ";
239 resultString +=
" Success=\"false\"";
240 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"FAIL");
246 int wobbleRate_int = std::stoi(
value);
247 status = device->
SetWobbleRate((
unsigned char)wobbleRate_int);
248 resultString +=
" Success=\"true\"";
249 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"SUCCESS");
254 resultString +=
" Success=\"true\"";
255 resultString +=
" Value=\"" +
value +
"\"";
256 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
value);
261 bool bidi = std::stoi(
value);
263 resultString +=
" Success=\"true\"";
264 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"SUCCESS");
269 resultString +=
" Success=\"true\"";
270 resultString +=
" Value=\"" +
value +
"\"";
271 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
value);
275 bool freezeProbe_bool = std::stoi(
value);
278 resultString +=
" Success=\"true\"";
279 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"SUCCESS");
283 LOG_ERROR(
"Failed to freeze probe");
284 resultString +=
" Success=\"false\"";
285 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"FAIL");
291 resultString +=
" Success=\"true\"";
292 resultString +=
" Value=\"" +
value +
"\"";
293 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
value);
298 int jitterCompensation_int = std::stoi(
value);
300 resultString +=
" Success=\"true\"";
301 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"SUCCESS");
306 resultString +=
" Success=\"true\"";
307 resultString +=
" Value=\"" +
value +
"\"";
308 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
value);
313 bool MISMode_bool = std::stoi(
value);
316 resultString +=
" Success=\"true\"";
317 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"SUCCESS");
321 LOG_ERROR(
"Failed to set MIS mode");
322 resultString +=
" Success=\"false\"";
323 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"FAIL");
332 resultString +=
" Success=\"true\"";
333 resultString +=
" Value=\"" +
value +
"\"";
334 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
value);
338 LOG_ERROR(
"Failed to get MIS mode");
339 resultString +=
" Success=\"false\"";
340 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"FAIL");
345 int misPulse_int = std::stoi(
value);
348 resultString +=
" Success=\"true\"";
349 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"SUCCESS");
353 LOG_ERROR(
"Failed to set MIS pulse period");
354 resultString +=
" Success=\"false\"";
355 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"FAIL");
360 unsigned int PulsePeriod;
364 resultString +=
" Success=\"true\"";
365 resultString +=
" Value=\"" +
value +
"\"";
366 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
value);
370 LOG_ERROR(
"Failed to get MIS pulse period");
371 resultString +=
" Success=\"false\"";
372 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"FAIL");
377 float sweepAngle = std::stof(
value);
379 resultString +=
" Success=\"true\"";
380 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"SUCCESS");
385 resultString +=
" Success=\"true\"";
386 resultString +=
" Value=\"" +
value +
"\"";
387 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
value);
392 int derComp = std::stoi(
value);
394 resultString +=
" Success=\"true\"";
395 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"SUCCESS");
400 resultString +=
" Success=\"true\"";
401 resultString +=
" Value=\"" +
value +
"\"";
402 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
value);
407 int servoGain = std::stoi(
value);
408 status = device->
SetServoGain((
unsigned char)servoGain);
409 resultString +=
" Success=\"true\"";
410 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"SUCCESS");
415 resultString +=
" Success=\"true\"";
416 resultString +=
" Value=\"" +
value +
"\"";
417 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
value);
422 int positionScale = std::stoi(
value);
424 resultString +=
" Success=\"true\"";
425 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"SUCCESS");
430 resultString +=
" Success=\"true\"";
431 resultString +=
" Value=\"" +
value +
"\"";
432 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
value);
437 error +=
"Failed to set " + parameterName +
". ";
438 resultString +=
" Success=\"false\"";
439 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"FAIL");
446 resultString +=
"/>";
448 resultString +=
"</CommandReply>";
452 LOG_WARNING(
"Failed to set some requested parameter(s), result string was: " << resultString);
455 vtkSmartPointer<vtkPlusCommandRTSCommandResponse> commandResponse = vtkSmartPointer<vtkPlusCommandRTSCommandResponse>::New();
456 commandResponse->UseDefaultFormatOff();
457 commandResponse->SetClientId(this->
ClientId);
458 commandResponse->SetOriginalId(this->
Id);
459 commandResponse->SetDeviceName(this->
DeviceName);
460 commandResponse->SetCommandName(this->GetName());
461 commandResponse->SetStatus(status);
463 commandResponse->SetErrorString(error);
464 commandResponse->SetResultString(resultString);
465 commandResponse->SetParameters(metaData);
virtual PlusStatus Execute()
virtual void PrintSelf(ostream &os, vtkIndent indent)
static const char * CAPISTRANO_GET_MIS_MODE
PlusStatus FreezeDevice(bool freeze)
virtual void PrintSelf(ostream &os, vtkIndent indent)
Abstract interface for tracker and video devices.
virtual ~vtkPlusCapistranoCommand()
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
static const char * CAPISTRANO_SET_SAMPLE_FREQUENCY
PlusStatus GetDevice(vtkPlusDevice *&aDevice, const std::string &aDeviceId) const
static const char * CAPISTRANO_GET_JITTER_COMPENSATION
PlusStatus SetSweepAngle(float sweepAngle)
static const char * CAPISTRANO_SET_MIS_MODE
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
PlusStatus GetMISPulsePeriod(unsigned int &PulsePeriod)
PlusStatus SetWobbleRate(unsigned char wobbleRate)
virtual std::string GetDescription(const std::string &commandName)
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
virtual std::string GetDeviceId() const
vtkPlusCapistranoCommand()
PlusStatus SetServoGain(unsigned char servoGain)
This command is for communicating with vtkPlusCapistranoDevice.This command is used for communicating...
PlusStatus GetMISMode(bool &MISMode)
std::string to_string(ClariusAvailability avail)
std::string GetCommandValue() const
vtkStandardNewMacro(vtkPlusCapistranoCommand)
static const char * CAPISTRANO_SET_BIDIRECTIONAL_MODE
unsigned char GetPositionScale()
unsigned char GetDerivativeCompensation()
static const char * CAPISTRANO_GET_POSITION_SCALE
static const char * CAPISTRANO_SET_MIS_PULSE_PERIOD
void SetCommandName(const std::string &text)
static const char * CAPISTRANO_SET_DERIVATIVE_COMPENSATION
virtual void SetDeviceId(const std::string &deviceId)
unsigned char GetJitterCompensation()
PhidgetLCD_Font int int const char * text
PlusStatus SetBidirectionalMode(bool mode)
PlusStatus SetMISMode(bool mode)
virtual void GetCommandNames(std::list< std::string > &cmdNames)
PlusStatus SetJitterCompensation(unsigned char jitterComp)
Manages devices that record image or positional data.
static const char * CAPISTRANO_SET_SERVO_GAIN
std::string GetCommandName() const
bool RespondWithCommandMessage
void SetCommandValue(const std::string &text)
static const char * CAPISTRANO_SET_POSITION_SCALE
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
virtual std::string GetDeviceId() const
void QueueCommandResponse(PlusStatus status, const std::string &message, const std::string &error="", const igtl::MessageBase::MetaDataMap *metaData=nullptr)
virtual vtkPlusDataCollector * GetDataCollector()
static const char * CAPISTRANO_FREEZE_PROBE
const char const char * value
static const char * CAPISTRANO_GET_MIS_PULSE_PERIOD
static const char * CAPISTRANO_GET_BIDIRECTIONAL_MODE
PlusStatus SetDerivativeCompensation(unsigned char derivativeCompensation)
unsigned char GetWobbleRate()
PlusStatus SetPositionScale(unsigned char scale)
unsigned char GetServoGain()
static const char * CAPISTRANO_SET_WOBBLE_RATE
static const char * CAPISTRANO_SET_SWEEP_ANGLE
static const char * CAPISTRANO_GET_SWEEP_ANGLE
PlusCommandResponseList CommandResponseQueue
Class for acquiring ultrasound images from Capistrano Labs USB ultrasound systems.
bool GetBidirectionalMode()
static const char * CAPISTRANO_GET_SERVO_GAIN
std::list< std::pair< std::string, std::string > > RequestedParameterChanges
static const char * CAPISTRANO_GET_SAMPLE_FREQUENCY
static const char * CAPISTRANO_GET_WOBBLE_RATE
static const char * CAPISTRANO_SET_JITTER_COMPENSATION
PlusStatus SetMISPulsePeriod(unsigned int val)
static const char * CAPISTRANO_IS_PROBE_FROZEN
static const char * CAPISTRANO_GET_DERIVATIVE_COMPENSATION