Line |
Branch |
Exec |
Source |
1 |
|
|
/***************************************************************************** |
2 |
|
|
* |
3 |
|
|
* $Id$ |
4 |
|
|
* |
5 |
|
|
* Copyright 2010 Richard Hacker (lerichi at gmx dot net) |
6 |
|
|
* |
7 |
|
|
* This file is part of the pdserv library. |
8 |
|
|
* |
9 |
|
|
* The pdserv library is free software: you can redistribute it and/or modify |
10 |
|
|
* it under the terms of the GNU Lesser General Public License as published |
11 |
|
|
* by the Free Software Foundation, either version 3 of the License, or (at |
12 |
|
|
* your option) any later version. |
13 |
|
|
* |
14 |
|
|
* The pdserv library is distributed in the hope that it will be useful, but |
15 |
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
16 |
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
17 |
|
|
* License for more details. |
18 |
|
|
* |
19 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
20 |
|
|
* along with the pdserv library. If not, see <http://www.gnu.org/licenses/>. |
21 |
|
|
* |
22 |
|
|
*****************************************************************************/ |
23 |
|
|
|
24 |
|
|
#include "Channel.h" |
25 |
|
|
#include "XmlElement.h" |
26 |
|
|
#include "../Signal.h" |
27 |
|
|
#include "../DataType.h" |
28 |
|
|
|
29 |
|
|
#include <sstream> |
30 |
|
|
|
31 |
|
|
using namespace MsrProto; |
32 |
|
|
|
33 |
|
|
///////////////////////////////////////////////////////////////////////////// |
34 |
|
✗ |
Channel::Channel(const PdServ::Signal *s, size_t index, |
35 |
|
|
const PdServ::DataType& dtype, |
36 |
|
|
const PdServ::DataType::DimType& dim, |
37 |
|
✗ |
size_t offset, Channel *parent): |
38 |
|
|
Variable(s, index, dtype, dim, offset, parent), |
39 |
|
✗ |
signal(s) |
40 |
|
|
{ |
41 |
|
|
// log_debug("new var %s idx=%u size=%zu, nelem=%zu offset=%zu", |
42 |
|
|
// path().c_str(), index, dtype.size, dim.nelem, offset); |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
///////////////////////////////////////////////////////////////////////////// |
46 |
|
✗ |
void Channel::setXmlAttributes( XmlElement &element, |
47 |
|
|
bool shortReply, const char *data, size_t precision) const |
48 |
|
|
{ |
49 |
|
✗ |
setAttributes(element, shortReply); |
50 |
|
|
|
51 |
|
✗ |
if (!shortReply) { |
52 |
|
|
// <channel name="/lan/World Time" alias="" index="0" typ="TDBL" |
53 |
|
|
// datasize="8" bufsize="500" HZ="50" unit="" |
54 |
|
|
// value="1283134199.93743"/> |
55 |
|
✗ |
double freq = 1.0 / signal->sampleTime / signal->decimation; |
56 |
|
|
|
57 |
|
|
// The MSR protocol wants a bufsize, the maximum number of |
58 |
|
|
// values that can be retraced. This artificial limitation does |
59 |
|
|
// not exist any more. Instead, choose a buffer size so that |
60 |
|
|
// at a maximum of 10 seconds has to be stored. |
61 |
|
✗ |
size_t bufsize = 10 * std::max(1U, (unsigned int)(freq + 0.5)); |
62 |
|
|
|
63 |
|
✗ |
if (shortReply) |
64 |
|
✗ |
return; |
65 |
|
|
|
66 |
|
|
// bufsize= |
67 |
|
✗ |
XmlElement::Attribute(element, "bufsize") << bufsize; |
68 |
|
✗ |
XmlElement::Attribute(element, "HZ") << freq; |
69 |
|
|
|
70 |
|
✗ |
if (data) |
71 |
|
✗ |
XmlElement::Attribute(element, "value").csv(this, |
72 |
|
✗ |
data + offset, 1, precision); |
73 |
|
|
} |
74 |
|
|
|
75 |
|
✗ |
addCompoundFields(element, dtype); |
76 |
|
|
} |
77 |
|
|
|