7 #include "PlusConfigure.h" 17 static const std::string ENCODER_CMD =
"USDigitalEncoder";
22 : ResponseExpected(true)
24 this->SetName(ENCODER_CMD);
35 this->SetName(ENCODER_CMD);
42 cmdNames.push_back(ENCODER_CMD);
49 if (commandName.empty() || igsioCommon::IsEqualInsensitive(commandName, ENCODER_CMD))
52 desc +=
": Send commands to a USDigital Encoder device.";
60 return this->DeviceId;
66 this->DeviceId = deviceId;
73 os << indent <<
"Device Id: " << this->DeviceId;
84 XML_READ_STRING_ATTRIBUTE_OPTIONAL(DeviceId, aConfig);
87 for (
int elemIndex = 0; elemIndex < aConfig->GetNumberOfNestedElements(); ++elemIndex)
89 vtkXMLDataElement* currentElem = aConfig->GetNestedElement(elemIndex);
92 const char* encoderId = currentElem->GetAttribute(
"EncoderId");
95 LOG_ERROR(
"Unable to find required EncoderId in " << (currentElem->GetName() ? currentElem->GetName() :
"(undefined)") <<
" element in USDigitalEncoder command");
106 const char* encoderId = currentElem->GetAttribute(
"EncoderId");
109 LOG_ERROR(
"Unable to find required EncoderId in " << (currentElem->GetName() ? currentElem->GetName() :
"(undefined)") <<
" element in USDigitalEncoder command");
115 LOG_ERROR(
"Invalid command name (" << currentElem->GetName() <<
") provided to USDigitalEncoderCommand.");
128 XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(DeviceId, aConfig);
135 LOG_DEBUG(
"vtkPlusUSDigitalEncoderCommand::Execute: " << (!this->
Name.empty() ? this->
Name :
"(undefined)")
136 <<
", device: " << (this->DeviceId.empty() ?
"(undefined)" : this->DeviceId));
139 if (dataCollector == NULL)
146 if (this->DeviceId.empty())
155 + (this->DeviceId.empty() ?
"(undefined)" : this->DeviceId) + std::string(
" is not found."));
160 std::string resultString =
"<CommandReply>";
161 std::string error =
"";
162 std::map < std::string, std::pair<IANA_ENCODING_TYPE, std::string> > metaData;
165 std::list<std::pair<std::string, std::string>>::iterator commandIt;
168 std::string commandName = commandIt->first;
169 std::string encoderId = commandIt->second;
171 resultString +=
"<Command Name=\"" + commandName +
"\" ";
175 int encoderId_int = std::stoi(encoderId);
178 resultString +=
"Success=\"true\"/>";
182 resultString +=
"Success=\"false\"/>";
190 resultString +=
"Success=\"true\"/>";
194 resultString +=
"Success=\"false\"/>";
200 int encoderId_int = std::stoi(encoderId);
204 std::stringstream ss;
206 resultString +=
"Success=\"true\" EncoderId=\"" + encoderId +
"\" Position=\"" + ss.str() +
"\"/>";
210 resultString +=
"Success=\"false\" EncoderId=\"" + encoderId +
"\"/>";
215 resultString +=
"</CommandReply>";
220 +
" for device " + (this->DeviceId.empty() ?
"(undefined)" : this->DeviceId));
224 vtkSmartPointer<vtkPlusCommandRTSCommandResponse> commandResponse = vtkSmartPointer<vtkPlusCommandRTSCommandResponse>::New();
225 commandResponse->UseDefaultFormatOff();
226 commandResponse->SetClientId(this->
ClientId);
227 commandResponse->SetOriginalId(this->
Id);
228 commandResponse->SetDeviceName(this->
DeviceName);
229 commandResponse->SetCommandName(this->GetName());
230 commandResponse->SetStatus(status);
232 commandResponse->SetErrorString(error);
233 commandResponse->SetResultString(resultString);
234 commandResponse->SetParameters(metaData);
virtual void PrintSelf(ostream &os, vtkIndent indent)
static const char * USDIGITALENCODER_COMMAND_SET_ORIGIN
Abstract interface for tracker and video devices.
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
virtual PlusStatus Execute()
static const char * USDIGITALENCODER_COMMAND_SET_ALL_ORIGIN
PlusStatus GetDevice(vtkPlusDevice *&aDevice, const std::string &aDeviceId) const
PlusStatus SetUSDigitalA2EncoderOriginWithID(long id)
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
void SetNameToEncoderCommand()
vtkPlusUSDigitalEncoderCommand()
This command controls USDigitalEncodersTracker devices.This command is used for controlling a USDigit...
PlusStatus GetUSDigitalA2EncoderPositionWithID(long id, long *pos)
PlusStatus SetAllUSDigitalA2EncoderOrigin()
Manages devices that record image or positional data.
virtual std::string GetDeviceId() const
Interface for multiple US Digital A2, A2T, A4, HBA2, HBA4 or HD25A encoders to generate pose informat...
bool RespondWithCommandMessage
void QueueCommandResponse(PlusStatus status, const std::string &message, const std::string &error="", const igtl::MessageBase::MetaDataMap *metaData=nullptr)
virtual ~vtkPlusUSDigitalEncoderCommand()
virtual vtkPlusDataCollector * GetDataCollector()
virtual void GetCommandNames(std::list< std::string > &cmdNames)
vtkStandardNewMacro(vtkPlusUSDigitalEncoderCommand)
virtual void SetDeviceId(const std::string &deviceId)
std::list< std::pair< std::string, std::string > > CommandList
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
virtual void PrintSelf(ostream &os, vtkIndent indent)
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
PlusCommandResponseList CommandResponseQueue
virtual std::string GetDescription(const std::string &commandName)
static const char * USDIGITALENCODER_COMMAND_GET_POSITION