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
25namespace dcm {
26
27void
28set_value(AL::ALPtr<AL::DCMProxy> &dcm,
29 const std::string & device,
30 const std::string & kind,
31 float value,
32 int time)
33{
34 AL::ALValue cmd, actcmd, actpos;
35
36 cmd.arrayPush(device);
37 cmd.arrayPush(kind);
38 actpos.arrayPush(value);
39 actpos.arrayPush(time);
40 actcmd.arrayPush(actpos);
41 cmd.arrayPush(actcmd);
42
43 dcm->set(cmd);
44}
45
46std::vector<std::string>
47get_devices(AL::ALPtr<AL::DCMProxy> & dcm,
48 AL::ALPtr<AL::ALMemoryProxy> &almem,
49 const std::string & type)
50{
51 AL::ALValue names = almem->getDataListName();
52 std::string subd_prefix = dcm->getPrefix()[0];
53
54 std::vector<std::string> rv;
55
56 // Walk sub-device tree and extract joints
57 for (unsigned int i = 0; i < names.getSize(); ++i) {
58 std::string name = names[i];
59 if (name.compare(0, subd_prefix.length(), subd_prefix) == 0) {
60 if (name.compare(name.length() - 5, 5, "/Type") == 0) {
61 std::string dtype = almem->getData(name, 0);
62 std::string base_path = name.substr(0, name.length() - 5);
63 if (dtype == type) {
64 rv.push_back(base_path);
65 }
66 }
67 }
68 }
69
70 return rv;
71}
72
73} // end of namespace dcm