Directory: | ./ |
---|---|
File: | pdserv/src/msrproto/StatSignal.cpp |
Date: | 2025-08-17 04:10:43 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 4 | 32 | 12.5% |
Branches: | 3 | 24 | 12.5% |
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 "StatSignal.h" | ||
23 | #include "Session.h" | ||
24 | #include "TaskStatistics.h" | ||
25 | #include "SubscriptionManager.h" | ||
26 | #include "../TaskStatistics.h" | ||
27 | #include "../Task.h" | ||
28 | #include "../DataType.h" | ||
29 | |||
30 | using namespace MsrProto; | ||
31 | |||
32 | ///////////////////////////////////////////////////////////////////////////// | ||
33 | 924 | StatSignal::StatSignal(const PdServ::Task *task, Type type, size_t index): | |
34 | PdServ::Signal("StatSignal", task, 1U, PdServ::DataType::float64), | ||
35 | Channel(this, index, | ||
36 | 924 | this->PdServ::Signal::dtype, this->PdServ::Signal::dim, 0), | |
37 |
3/6✓ Branch 5 taken 924 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 924 times.
✗ Branch 10 not taken.
✓ Branch 19 taken 924 times.
✗ Branch 20 not taken.
|
1848 | type(type) |
38 | { | ||
39 | 924 | } | |
40 | |||
41 | ///////////////////////////////////////////////////////////////////////////// | ||
42 | ✗ | void StatSignal::subscribe(PdServ::SessionTask *session) const | |
43 | { | ||
44 | ✗ | session->newSignal(this); | |
45 | } | ||
46 | |||
47 | ///////////////////////////////////////////////////////////////////////////// | ||
48 | ✗ | void StatSignal::unsubscribe(PdServ::SessionTask *) const | |
49 | { | ||
50 | } | ||
51 | |||
52 | ///////////////////////////////////////////////////////////////////////////// | ||
53 | ✗ | double StatSignal::getValue ( | |
54 | const PdServ::Session *s, struct timespec *t) const | ||
55 | { | ||
56 | ✗ | const Session *session = static_cast<const Session*>(s); | |
57 | const PdServ::TaskStatistics* stats = | ||
58 | ✗ | session->getTaskStatistics(task); | |
59 | |||
60 | ✗ | if (t) | |
61 | ✗ | *t = *session->getTaskTime(task); | |
62 | |||
63 | ✗ | if (stats) { | |
64 | ✗ | switch (type) { | |
65 | ✗ | case ExecTime: | |
66 | ✗ | return stats->exec_time; | |
67 | break; | ||
68 | |||
69 | ✗ | case Period: | |
70 | ✗ | return stats->cycle_time; | |
71 | break; | ||
72 | |||
73 | ✗ | case Overrun: | |
74 | ✗ | return stats->overrun; | |
75 | } | ||
76 | } | ||
77 | |||
78 | ✗ | return 0; | |
79 | } | ||
80 | |||
81 | ///////////////////////////////////////////////////////////////////////////// | ||
82 | ✗ | double StatSignal::poll(const PdServ::Session *session, | |
83 | void *buf, struct timespec *t) const | ||
84 | { | ||
85 | ✗ | *reinterpret_cast<double*>(buf) = getValue(session, t); | |
86 | |||
87 | ✗ | return 0; | |
88 | } | ||
89 | |||
90 | ///////////////////////////////////////////////////////////////////////////// | ||
91 | ✗ | const char *StatSignal::getValue(const PdServ::SessionTask* std) const | |
92 | { | ||
93 | const SubscriptionManager* sm = | ||
94 | ✗ | static_cast<const SubscriptionManager*>(std); | |
95 | ✗ | double* value = sm->session->getDouble(); | |
96 | |||
97 | ✗ | poll(sm->session, value, 0); | |
98 | |||
99 | ✗ | return reinterpret_cast<const char*>(value); | |
100 | } | ||
101 | |||
102 | ///////////////////////////////////////////////////////////////////////////// | ||
103 | ✗ | int StatSignal::getValue( const PdServ::Session *session, | |
104 | void *buf, struct timespec* t) const | ||
105 | { | ||
106 | // cout << __PRETTY_FUNCTION__ << endl; | ||
107 | ✗ | poll(session, buf, t); | |
108 | ✗ | return 0; | |
109 | } | ||
110 |