7 #ifndef __ChrDataItem_h 8 #define __ChrDataItem_h 10 #include "vtkXMLDataElement.h" 31 if (GetStringValueFromChildElement(
"Name",m_Name,dataItemElem)!=
PLUS_SUCCESS)
35 if (GetUnsignedCharValueFromChildElement(
"Address",m_Address,dataItemElem)!=
PLUS_SUCCESS)
39 if (GetUnsignedCharValueFromChildElement(
"Bits",m_Bits,dataItemElem)!=
PLUS_SUCCESS)
43 if (GetUnsignedCharValueFromChildElement(
"Start",m_StartBit,dataItemElem)!=
PLUS_SUCCESS)
47 if (GetDoubleValueFromChildElement(
"ScaleFactor",m_ScaleFactor,dataItemElem)!=
PLUS_SUCCESS)
52 if (GetStringValueFromChildElement(
"DataType",typeStr,dataItemElem)!=
PLUS_SUCCESS)
58 if (typeStr.compare(
"int16")==0)
62 else if (typeStr.compare(
"uint16")==0)
66 else if (typeStr.compare(
"float")==0)
70 else if (typeStr.compare(
"en/dis")==0)
74 else if (typeStr.compare(
"binary")==0)
80 LOG_ERROR(
"Unknown data type: "<<typeStr);
93 unsigned int dwordAddress=(bitAddress/32)*4;
94 unsigned int remainingOffsetBit=bitAddress%32;
95 if (remainingOffsetBit<8)
97 return dwordAddress+2;
99 if (remainingOffsetBit<16)
101 return dwordAddress+3;
103 if (remainingOffsetBit<24)
105 return dwordAddress+0;
108 return dwordAddress+1;
113 switch (this->m_DataType)
119 int packetStartByteAddress=packet.
GetAddress()*4;
121 if (dataStartByteAddress<packetStartByteAddress
122 || dataEndByteAddress>packetEndByteAddress)
127 int intValue=
int(packet.
GetDataByte(dataStartByteAddress-packetStartByteAddress))*256
128 +
int(packet.
GetDataByte(dataStartByteAddress-packetStartByteAddress+1));
129 m_Value=intValue*m_ScaleFactor;
133 LOG_ERROR(
"Unsupported data type: "<<this->m_DataType);
151 PlusStatus GetUnsignedCharValueFromChildElement(
const std::string &childElemName,
unsigned char &childElemValue, vtkXMLDataElement* dataElem)
153 vtkXMLDataElement* childElem=dataElem->FindNestedElementWithName(childElemName.c_str());
156 LOG_ERROR(
"Child element name "<<childElemName<<
" not found");
159 if (igsioCommon::StringToInt<unsigned char>(childElem->GetCharacterData(), childElemValue)!=
PLUS_SUCCESS)
161 LOG_ERROR(
"Failed to read integer value from element "<<childElemName);
167 PlusStatus GetDoubleValueFromChildElement(
const std::string &childElemName,
double &childElemValue, vtkXMLDataElement* dataElem)
169 vtkXMLDataElement* childElem=dataElem->FindNestedElementWithName(childElemName.c_str());
172 LOG_ERROR(
"Child element name "<<childElemName<<
" not found");
175 if (igsioCommon::StringToDouble(childElem->GetCharacterData(), childElemValue)!=
PLUS_SUCCESS)
177 LOG_ERROR(
"Failed to read double value from element "<<childElemName);
183 PlusStatus GetStringValueFromChildElement(
const std::string &childElemName, std::string &childElemValue, vtkXMLDataElement* dataElem)
185 vtkXMLDataElement* childElem=dataElem->FindNestedElementWithName(childElemName.c_str());
188 LOG_ERROR(
"Child element name "<<childElemName<<
" not found");
191 const char* s=childElem->GetCharacterData();
194 LOG_ERROR(
"Failed to string value from element "<<childElemName);
202 unsigned char m_Address;
203 unsigned char m_Bits;
204 unsigned char m_StartBit;
206 double m_ScaleFactor;
unsigned char GetDataLength()
bool ReadValueFromPacket(ChrSerialPacket &packet)
PlusStatus ReadDescriptionFromXml(vtkXMLDataElement *dataItemElem)
int GetByteAddressFromBitAddress(unsigned int bitAddress)
unsigned char GetDataByte(int index)
unsigned char GetAddress()