56 #include "rnr/rnrconfig.h" 59 #include "rnr/appkit/Xml.h" 72 int KuonXmlCfg::createTemplateFile(
const string &strXmlFileName)
76 if( strXmlFileName.empty() )
78 setErrorMsg(
"No file name.");
79 LOGERROR(
"%s", m_bufErrMsg);
83 m_strXmlFileName = strXmlFileName;
86 if( (fp = fopen(m_strXmlFileName.c_str(),
"w+")) == NULL )
88 setErrorMsg(
"%s: %s(errno=%d).",
89 m_strXmlFileName.c_str(), strerror(errno), errno);
90 LOGERROR(
"%s", m_bufErrMsg);
100 fprintf(fp,
" <!-- RoadNarrows Kuon Top-Level Configuration -->\n");
101 fprintf(fp,
"%s", m_strXmlHead.c_str());
106 fprintf(fp,
" <!-- Kuon robotic mobile platform -->\n");
107 fprintf(fp,
" <%s product_id=\"PRODID\">\n", m_strMajElemBase.c_str());
109 fprintf(fp,
" <%s>PRODNAME</%s>\n",
110 m_strElemProdName.c_str(), m_strElemProdName.c_str());
112 fprintf(fp,
" <%s>\n PRODBRIEF\n </%s>\n",
113 m_strElemProdBrief.c_str(), m_strElemProdBrief.c_str());
115 fprintf(fp,
" <%s>PRODHWVER</%s>\n",
116 m_strElemProdHwVer.c_str(), m_strElemProdHwVer.c_str());
118 fprintf(fp,
" <%s>FRONTTIRE</%s>\n",
119 m_strElemProdFrontTire.c_str(), m_strElemProdFrontTire.c_str());
121 fprintf(fp,
" <%s>REARTIRE</%s>\n",
122 m_strElemProdRearTire.c_str(), m_strElemProdRearTire.c_str());
124 fprintf(fp,
" </%s>\n\n", m_strMajElemBase.c_str());
130 fprintf(fp,
"%s", m_strXmlTail.c_str());
134 LOGDIAG3(
"Created file %s.", m_strXmlFileName.c_str());
156 if( m_pElemRoot == NULL )
158 setErrorMsg(
"Missing DOM and/or <%s> root element missing.",
159 m_strRootElemName.c_str());
160 LOGERROR(
"%s", m_bufErrMsg);
165 for(pElem = m_pElemRoot->FirstChildElement();
167 pElem = pElem->NextSiblingElement())
169 if( (sValue = pElem->Value()) == NULL )
175 if( !strcasecmp(sValue, m_strMajElemBase.c_str()) )
177 setKuonBaseDescFromDOM(pElem, pDescBase);
184 int KuonXmlCfg::setDOMFromKuonDesc(
const KuonDesc &desc)
190 int KuonXmlCfg::setKuonBaseDescFromDOM(TiXmlElement *pElemMaj,
200 double fFrontTire = 0.0;
201 double fRearTire = 0.0;
204 if( (rc = strToInt(elemAttr(pElemMaj, m_strAttrProdId), eProdId)) < 0 )
206 setErrorMsg(
"%s: No %s attribute of <%s> found or value not an integer.",
207 m_strXmlFileName.c_str(),
208 m_strAttrProdId.c_str(),
209 m_strMajElemBase.c_str());
210 LOGERROR(
"%s", m_bufErrMsg);
215 for(pElem = pElemMaj->FirstChildElement();
217 pElem = pElem->NextSiblingElement())
219 if( (sValue = pElem->Value()) == NULL )
225 else if( !strcasecmp(sValue, m_strElemProdName.c_str()) )
227 strProdName = elemText(pElem);
231 else if( !strcasecmp(sValue, m_strElemProdBrief.c_str()) )
233 strProdBrief = elemText(pElem);
237 else if( !strcasecmp(sValue, m_strElemProdHwVer.c_str()) )
239 strHwVer = elemText(pElem);
243 else if( !strcasecmp(sValue, m_strElemProdFrontTire.c_str()) )
245 str = elemText(pElem);
248 if( (rc = strToDouble(str, fFrontTire)) < 0 )
250 setErrorMsg(
"%s: Element <%s> text \"%s\" not an number.",
251 m_strXmlFileName.c_str(), m_strElemProdFrontTire.c_str(),
253 LOGERROR(
"%s", m_bufErrMsg);
260 else if( !strcasecmp(sValue, m_strElemProdRearTire.c_str()) )
262 str = elemText(pElem);
265 if( (rc = strToDouble(str, fRearTire)) < 0 )
267 setErrorMsg(
"%s: Element <%s> text \"%s\" not an number.",
268 m_strXmlFileName.c_str(), m_strElemProdRearTire.c_str(),
270 LOGERROR(
"%s", m_bufErrMsg);
277 pDesc->setDesc(eProdId, strProdName, strProdBrief, strHwVer,
278 fFrontTire, fRearTire);
280 LOGDIAG3(
"%s: Kuon robotic base description set.",
281 m_strXmlFileName.c_str());
static const int KUON_OK
not an error, success
Kuon robotic mobile base escription class.
static const int KUON_ECODE_XML
XML error.
Kuon robotic base mobile platform description class interface.
The <b><i>Kuon</i></b> namespace encapsulates all <b><i>Kuon</i></b> related constructs.
RoadNarrows Kuon robot top-level header file.
static const int KUON_ECODE_GEN
general, unspecified error
<b><i>Kuon</i></b> XML configuration class interface.
Kuon full robotic mobile platform descripition class interface.
Kuon robotic manipulator full description class.
void resetDesc()
Reset base description to the "unitialized" values.
KuonDescBase * getBaseDesc()
Get the <b><i>Kuon</i></b> base product description.