iCub-main
SkinConfigReader.cpp
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4  * Copyright (C) 2012 iCub Facility, Istituto Italiano di Tecnologia
5  * Authors: Valentina Gaggero
6  * CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
7  *
8  */
9 
10 #include <stdio.h>
11 #include <yarp/os/LogStream.h>
12 #include <yarp/os/Bottle.h>
13 #include "SkinConfigReader.h"
14 
15 using namespace yarp::os;
16 
18 
19 void SkinConfigReader::setName(char *name)
20 {
21  if (NULL != name)
22  {
23  strncpy(_name, name, sizeof(_name));
24  }
25 }
26 
27 
28 //bool SkinConfigReader::readPatchesList(yarp::os::Searchable& config, SkinConfig *skCfg)
29 //{
30 // if(NULL == skCfg)
31 // return false;
32 //
33 // Bottle bPatches, bPatchList, xtmp;
34 // //reset total num of cards
35 // skCfg->totalCardsNum = 0;
36 //
37 //
38 // bPatches = config.findGroup("patches", "skin patches connected to this device");
39 // if(bPatches.isNull())
40 // {
41 // yError() << "skin " << _name << "patches group is missed!";
42 // return(false);
43 // }
44 //
45 // bPatchList = bPatches.findGroup("patchesIdList");
46 // if(bPatchList.isNull())
47 // {
48 // yError() << "skin " << _name << "patchesList is missed!";
49 // return(false);
50 // }
51 //
52 // skCfg->numOfPatches = bPatchList.size()-1;
53 //
54 // skCfg->patchInfoList->clear();
55 // skCfg->patchInfoList->resize(skCfg->numOfPatches);
56 //
57 // for(int j=1; j<skCfg->numOfPatches+1; j++)
58 // {
59 // int id = bPatchList.get(j).asInt32();
60 //#warning VALE aggiungi questo controllo in embObjskin
66 // skCfg->patchInfoList[j-1].idPatch = id;
67 //#warning VALE metti in embObjSkin la conversione con indexNV
68 // //skCfg->patchInfoList[j-1].indexNv = convertIdPatch2IndexNv(id);
69 // }
70 //
71 // // //VALE solo per debug
72 // // yError() << "numOfPatches=" << numOfPatches;
73 // // for(int j=0; j<numOfPatches; j++ )
74 // // {
75 // // yError() << " patchInfoList[" << j << "]: patch=" << patchInfoList[j].idPatch << "indexNv=" << patchInfoList[j].indexNv;
76 // // }
77 //
78 //
79 // for(int i=0; i<skCfg->numOfPatches; i++)
80 // {
81 // char tmp[80];
82 // int id = skCfg->patchInfoList[i].idPatch;
83 // snprintf(tmp, sizeof(tmp), "skinCanAddrsPatch%d", id);
84 //
85 // xtmp = bPatches.findGroup(tmp);
86 // if(xtmp.isNull())
87 // {
88 // yError() << "skin " << _name << "doesn't find " << tmp << "in xml file";
89 // return false;
90 // }
91 //
92 // skCfg->patchInfoList[i].cardAddrList.resize(xtmp.size()-1);
93 //
94 // for(int j=1; j<xtmp.size(); j++)
95 // {
96 // int addr = xtmp.get(j).asInt32();
97 // skCfg->totalCardsNum++;
98 // skCfg->patchInfoList[i].cardAddrList[j-1] = addr;
99 // }
100 // }
101 //
102 // // //VALE solo per debug
103 // // yError() << "totalCardsNum=" << totalCardsNum;
104 // // for(int i=0; i<patchInfoList.size(); i++)
105 // // {
106 // // for(int j=0; j<patchInfoList[i].cardAddrList.size(); j++)
107 // // {
108 // // yError() << " elem num " << j << "of patch " <<patchInfoList[i].idPatch << "is " << patchInfoList[i].cardAddrList[j];
109 // // }
110 // // }
111 //
112 // return(true);
113 //}
114 bool SkinConfigReader::isDefaultBoardCfgPresent(yarp::os::Searchable& config)
115 {
116  Bottle boardCfgDefGroup =config.findGroup("defaultCfgBoard", "Default configuration for skin boards");
117  if (boardCfgDefGroup.isNull()==true)
118  return false;
119  else
120  return true;
121 }
122 
123 
124 bool SkinConfigReader::readDefaultBoardCfg(yarp::os::Searchable& config, SkinBoardCfgParam *boardCfg)
125 {
126  if(NULL == boardCfg)
127  return false;
128 
129  Bottle boardCfgDefGroup =config.findGroup("defaultCfgBoard", "Default configuration for skin boards");
130  if (boardCfgDefGroup.isNull()==true)
131  {
132  yError() << "skin " << _name << "defaultCfgBoard param is not present in config file";
133  return false;
134  }
135  Bottle xtmp;
136  xtmp = boardCfgDefGroup.findGroup("period");
137  if (xtmp.isNull())
138  {
139  yError() << "skin " << _name << "doesn't find period in defaultCfgBoard group in xml file";
140  return false;
141  }
142  boardCfg->period = xtmp.get(1).asInt32();
143 
144  xtmp = boardCfgDefGroup.findGroup("skinType");
145  if (xtmp.isNull())
146  {
147  yError() << "skin " << _name << "doesn't find skinType in defaultCfgBoard group in xml file";
148  return false;
149  }
150  boardCfg->skinType= xtmp.get(1).asInt32();
151 
152  xtmp = boardCfgDefGroup.findGroup("noLoad");
153  if (xtmp.isNull())
154  {
155  yError() << "skin " << _name << "doesn't find noLoad in defaultCfgBoard group in xml file";
156  return false;
157  }
158  boardCfg->noLoad= xtmp.get(1).asInt32();
159 
160  xtmp = boardCfgDefGroup.findGroup("diagnostic");
161  if (xtmp.isNull())
162  {
163  yError() << "skin " << _name << "doesn't find diagnostic in defaultCfgBoard group in xml file";
164  return false;
165  }
166  boardCfg->useDiagnostic = xtmp.get(1).asBool();
167  return true;
168 }
169 
170 bool SkinConfigReader::isDefaultTriangleCfgPresent(yarp::os::Searchable& config)
171 {
172  Bottle triangleCfgDefGroup =config.findGroup("defaultCfgTriangle", "Default configuration for skin triangle");
173 
174  if (triangleCfgDefGroup.isNull()==true)
175  return false;
176  else
177  return true;
178 }
179 
180 bool SkinConfigReader::readDefaultTriangleCfg(yarp::os::Searchable& config, SkinTriangleCfgParam *triangCfg)
181 {
182  if(NULL == triangCfg)
183  return false;
184 
185  Bottle triangleCfgDefGroup =config.findGroup("defaultCfgTriangle", "Default configuration for skin triangle");
186 
187  if (triangleCfgDefGroup.isNull()==true)
188  {
189  yError() << "skin " << _name << "defaultCfgTriangle param is not present in config file";
190  return false;
191  }
192 
193  Bottle xtmp;
194  xtmp = triangleCfgDefGroup.findGroup("enabled");
195  if (xtmp.isNull())
196  {
197  yError() << "skin " << _name << "doesn't find enabled in defaultCfgTriangle group in xml file";
198  return false;
199  }
200  triangCfg->enabled = xtmp.get(1).asBool();
201 
202  xtmp = triangleCfgDefGroup.findGroup("shift");
203  if (xtmp.isNull())
204  {
205  yError() << "skin " << _name << "doesn't find shift in defaultCfgTriangle group in xml file";
206  return false;
207  }
208  triangCfg->shift = xtmp.get(1).asInt32();
209 
210  xtmp = triangleCfgDefGroup.findGroup("cdcOffset");
211  if (xtmp.isNull())
212  {
213  yError() << "skin " << _name << "doesn't find cdcOffset in defaultCfgTriangle group in xml file";
214  return false;
215  }
216  triangCfg->cdcOffset = xtmp.get(1).asInt32();
217 
218  return true;
219 }
220 
221 bool SkinConfigReader::readSpecialBoardCfg(yarp::os::Searchable& config, SpecialSkinBoardCfgParam *boardCfg, unsigned int *numofcfg)
222 {
223  Bottle bNumOfset;
224  unsigned int numOfSets;
225 
226 
227  if((NULL == boardCfg) || (NULL == numofcfg))
228  return false;
229 
230  Bottle boardCfgSpecialGroup = config.findGroup("specialCfgBoards", "Special configuration for skin boards");
231  if(boardCfgSpecialGroup.isNull()==true) //not mandatory field
232  {
233  *numofcfg = 0;
234  return true;
235  }
236 
237 
238  bNumOfset = boardCfgSpecialGroup.findGroup("numOfSets", "number of special sets of triangles");
239  if(bNumOfset.isNull())
240  {
241  yError() << "skin " << _name << "numOfSet is missed from specialCfgBoards";
242  return(false);
243  }
244 
245  numOfSets = bNumOfset.get(1).asInt32();
246  if(numOfSets > *numofcfg)
247  {
248  yWarning() << "skin " << _name << "numOfSet is too big. Max is " << *numofcfg;
249  }
250  else
251  {
252  *numofcfg = numOfSets;
253  }
254 
255  for(unsigned int j=1;j<=*numofcfg;j++)
256  {
257  char tmp[80];
258  sprintf(tmp, "boardSetCfg%d", j);
259 
260  Bottle &xtmp = boardCfgSpecialGroup.findGroup(tmp);
261  if(xtmp.isNull())
262  {
263  yError() << "skin " << _name << "doesn't find " << tmp << "in specialCfgBoards group in xml file";
264  return false;
265  }
266 
267  boardCfg[j-1].patch = xtmp.get(1).asInt32();
268  boardCfg[j-1].boardAddrStart = xtmp.get(2).asInt32();
269  boardCfg[j-1].boardAddrEnd = xtmp.get(3).asInt32();
270  boardCfg[j-1].cfg.period = xtmp.get(4).asInt32();
271  boardCfg[j-1].cfg.skinType = xtmp.get(5).asInt32();
272  boardCfg[j-1].cfg.noLoad = xtmp.get(6).asInt32();
273  }
274  return true;
275 }
276 
277 
278 bool SkinConfigReader::readSpecialTriangleCfg(yarp::os::Searchable& config, SpecialSkinTriangleCfgParam *triangleCfg, unsigned int *numofcfg)
279 {
280  Bottle bNumOfset;
281  unsigned int numOfSets;
282 
283  if((NULL == triangleCfg) || (NULL == numofcfg))
284  return false;
285 
286  Bottle triangleCfgSpecialGroup = config.findGroup("specialCfgTriangles", "Special configuration for skin triangles");
287  if(triangleCfgSpecialGroup.isNull()) //not mandatory field
288  {
289  *numofcfg = 0;
290  return true;
291  }
292 
293  bNumOfset = triangleCfgSpecialGroup.findGroup("numOfSets", "number of special sets of triangles");
294  if(bNumOfset.isNull())
295  {
296  yError() << "skin "<< _name << "numOfSet is missed from SpecialCfgTriangles";
297  return(false);
298  }
299 
300  numOfSets = bNumOfset.get(1).asInt32();
301  if(numOfSets > *numofcfg)
302  {
303  yWarning() << "skin " << _name << "numOfSets for specialCfgTriangles is too big!! Max is " << *numofcfg;
304  }
305  else
306  {
307  *numofcfg = numOfSets;
308  }
309 
310  for(unsigned int j=1;j<=*numofcfg;j++)
311  {
312  char tmp[80];
313  sprintf(tmp, "triangleSetCfg%d", j);
314 
315  Bottle &xtmp = triangleCfgSpecialGroup.findGroup(tmp);
316  if(xtmp.isNull())
317  {
318  yError() << "skin " << _name << "doesn't find " << tmp << "in SpecialCfgTriangles group in xml file";
319  return false;
320  }
321 
322  triangleCfg[j-1].patch = xtmp.get(1).asInt32();
323  triangleCfg[j-1].boardAddr = xtmp.get(2).asInt32();
324  triangleCfg[j-1].triangleStart = xtmp.get(3).asInt32();
325  triangleCfg[j-1].triangleEnd = xtmp.get(4).asInt32();
326  triangleCfg[j-1].cfg.enabled = xtmp.get(5).asInt32()==1;
327  triangleCfg[j-1].cfg.shift = xtmp.get(6).asInt32();
328  triangleCfg[j-1].cfg.cdcOffset = xtmp.get(7).asInt32();
329 
330 
331 // //VALE: solo per debug:
332 // yError() << "num of set: " << j;
333 // yError() << "tcfg.patch" << triangleCfg[j-1].patch ;
334 // yError() << "tcfg.boardaddr" << triangleCfg[j-1].boardAddr ;
335 // yError() << "tcfg.idstart" << triangleCfg[j-1].triangleStart;
336 // yError() << "tcfg.idend" << triangleCfg[j-1].triangleEnd;
337 // yError() << "tcfg.cfg.enable" << triangleCfg[j-1].cfg.enabled;
338 // yError() << "tcfg.cfg.shift" << triangleCfg[j-1].cfg.shift;
339 // yError() << "tcfg.cfg.CDCoffset" << triangleCfg[j-1].cfg.cdcOffset;
340  }
341  return true;
342 }
uint8_t skinType
Definition: skinParams.h:36
void setName(char *name)
bool readDefaultBoardCfg(yarp::os::Searchable &config, SkinBoardCfgParam *boardCfg)
bool isDefaultBoardCfgPresent(yarp::os::Searchable &config)
bool readSpecialBoardCfg(yarp::os::Searchable &config, SpecialSkinBoardCfgParam *boardCfg, unsigned int *numofcfg)
bool readDefaultTriangleCfg(yarp::os::Searchable &config, SkinTriangleCfgParam *triangCfg)
bool readSpecialTriangleCfg(yarp::os::Searchable &config, SpecialSkinTriangleCfgParam *triangleCfg, unsigned int *numofcfg)
bool isDefaultTriangleCfgPresent(yarp::os::Searchable &config)
SkinTriangleCfgParam cfg