GCC Code Coverage Report


Directory: ./
File: pdserv/src/msrproto/Channel.cpp
Date: 2024-11-17 04:08:36
Exec Total Coverage
Lines: 23 23 100.0%
Branches: 18 30 60.0%

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 "../Task.h"
28
29 using namespace MsrProto;
30
31 /////////////////////////////////////////////////////////////////////////////
32 2772 Channel::Channel(const PdServ::Signal *s, size_t index,
33 const PdServ::DataType& dtype,
34 const PdServ::DataType::DimType& dim,
35 2772 size_t offset):
36 Variable(s, index, dtype, dim, offset),
37 2772 signal(s)
38 {
39 // log_debug("new var %s idx=%u size=%zu, nelem=%zu offset=%zu",
40 // path().c_str(), index, dtype.size, dim.nelem, offset);
41 2772 }
42
43 /////////////////////////////////////////////////////////////////////////////
44 152 void Channel::setXmlAttributes( XmlElement &element,
45 bool shortReply, bool hex, bool derived, const char *data,
46 std::streamsize precision, struct timespec* time) const
47 {
48 152 setAttributes(element, shortReply, derived);
49
50
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 if (!shortReply) {
51 // <channel name="/lan/World Time" alias="" index="0" typ="TDBL"
52 // datasize="8" bufsize="500" HZ="50" unit=""
53 // value="1283134199.93743"/>
54
1/2
✓ Branch 17 taken 152 times.
✗ Branch 18 not taken.
152 double freq = 1.0 / signal->sampleTime();
55
56 // The MSR protocol wants a bufsize, the maximum number of
57 // values that can be retraced. This artificial limitation does
58 // not exist any more. Instead, choose a buffer size so that
59 // at a maximum of 10 seconds has to be stored.
60 152 size_t bufsize = 10 * std::max(1U, (unsigned int)(freq + 0.5));
61
62 // bufsize=
63
2/4
✓ Branch 2 taken 152 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 152 times.
✗ Branch 7 not taken.
152 XmlElement::Attribute(element, "bufsize") << bufsize;
64
2/4
✓ Branch 2 taken 152 times.
✗ Branch 3 not taken.
✓ Branch 31 taken 152 times.
✗ Branch 32 not taken.
152 XmlElement::Attribute(element, "task") << signal->task->index;
65
2/4
✓ Branch 2 taken 152 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 152 times.
✗ Branch 7 not taken.
152 XmlElement::Attribute(element, "HZ") << freq;
66 }
67
68
2/2
✓ Branch 0 taken 57 times.
✓ Branch 1 taken 95 times.
152 if (time)
69
1/2
✓ Branch 5 taken 57 times.
✗ Branch 6 not taken.
57 XmlElement::Attribute(element, "time") << *time;
70
71
2/2
✓ Branch 0 taken 57 times.
✓ Branch 1 taken 95 times.
152 if (data) {
72
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 50 times.
57 if (hex)
73 14 XmlElement::Attribute(element, "hexvalue")
74
1/2
✓ Branch 9 taken 7 times.
✗ Branch 10 not taken.
14 .hexDec(data + offset, memSize);
75 else
76 100 XmlElement::Attribute(element, "value")
77
1/2
✓ Branch 6 taken 50 times.
✗ Branch 7 not taken.
100 .csv(this, data + offset, 1, precision);
78 }
79
80
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 if (!shortReply)
81 152 addCompoundFields(element, dtype);
82 152 }
83