Fawkes API  Fawkes Development Version
dcm_utils.cpp
1 
2 /***************************************************************************
3  * dcm_utils.cpp - DCM utility functions
4  *
5  * Created: Thu Aug 11 11:00:26 2011
6  * Copyright 2011 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include "dcm_utils.h"
24 
25 namespace dcm {
26 #if 0 /* just to make Emacs auto-indent happy */
27 }
28 #endif
29 
30 void
31 set_value(AL::ALPtr<AL::DCMProxy> &dcm,
32  const std::string &device, const std::string &kind,
33  float value, int time)
34 {
35  AL::ALValue cmd, actcmd, actpos;
36 
37  cmd.arrayPush(device); cmd.arrayPush(kind);
38  actpos.arrayPush(value); actpos.arrayPush(time);
39  actcmd.arrayPush(actpos); cmd.arrayPush(actcmd);
40 
41  dcm->set(cmd);
42 }
43 
44 
45 std::vector<std::string>
46 get_devices(AL::ALPtr<AL::DCMProxy> &dcm, AL::ALPtr<AL::ALMemoryProxy> &almem,
47  std::string type)
48 {
49  AL::ALValue names = almem->getDataListName();
50  std::string subd_prefix = dcm->getPrefix()[0];
51 
52  std::vector<std::string> rv;
53 
54  // Walk sub-device tree and extract joints
55  for (unsigned int i = 0; i < names.getSize(); ++i) {
56  std::string name = names[i];
57  if ( name.compare(0, subd_prefix.length(), subd_prefix) == 0 ) {
58  if ( name.compare(name.length() - 5, 5, "/Type") == 0 ) {
59  std::string dtype = almem->getData(name, 0);
60  std::string base_path = name.substr(0, name.length() - 5);
61  if ( dtype == type ) {
62  rv.push_back(base_path);
63  }
64  }
65  }
66  }
67 
68  return rv;
69 }
70 
71 } // end of namespace dcm