GCC Code Coverage Report


Directory: ./
File: pdserv/src/msrproto/Channel.cpp
Date: 2023-11-12 04:06:57
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 2080 Channel::Channel(const PdServ::Signal *s, size_t index,
33 const PdServ::DataType& dtype,
34 const PdServ::DataType::DimType& dim,
35 2080 size_t offset):
36 Variable(s, index, dtype, dim, offset),
37 2080 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 2080 }
42
43 /////////////////////////////////////////////////////////////////////////////
44 110 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 110 setAttributes(element, shortReply, derived);
49
50
1/2
✓ Branch 0 taken 110 times.
✗ Branch 1 not taken.
110 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 110 times.
✗ Branch 18 not taken.
110 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 110 size_t bufsize = 10 * std::max(1U, (unsigned int)(freq + 0.5));
61
62 // bufsize=
63
2/4
✓ Branch 2 taken 110 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 110 times.
✗ Branch 7 not taken.
110 XmlElement::Attribute(element, "bufsize") << bufsize;
64
2/4
✓ Branch 2 taken 110 times.
✗ Branch 3 not taken.
✓ Branch 31 taken 110 times.
✗ Branch 32 not taken.
110 XmlElement::Attribute(element, "task") << signal->task->index;
65
2/4
✓ Branch 2 taken 110 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 110 times.
✗ Branch 7 not taken.
110 XmlElement::Attribute(element, "HZ") << freq;
66 }
67
68
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 85 times.
110 if (time)
69
1/2
✓ Branch 5 taken 25 times.
✗ Branch 6 not taken.
25 XmlElement::Attribute(element, "time") << *time;
70
71
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 85 times.
110 if (data) {
72
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 18 times.
25 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 36 XmlElement::Attribute(element, "value")
77
1/2
✓ Branch 6 taken 18 times.
✗ Branch 7 not taken.
36 .csv(this, data + offset, 1, precision);
78 }
79
80
1/2
✓ Branch 0 taken 110 times.
✗ Branch 1 not taken.
110 if (!shortReply)
81 110 addCompoundFields(element, dtype);
82 110 }
83