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