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 "../Signal.h" |
25 |
|
|
#include "../Debug.h" |
26 |
|
|
#include "XmlElement.h" |
27 |
|
|
#include "Channel.h" |
28 |
|
|
#include "SubscriptionManager.h" |
29 |
|
|
#include "Subscription.h" |
30 |
|
|
#include "../DataType.h" |
31 |
|
|
|
32 |
|
|
#include <algorithm> |
33 |
|
|
|
34 |
|
|
using namespace MsrProto; |
35 |
|
|
|
36 |
|
|
///////////////////////////////////////////////////////////////////////////// |
37 |
|
✗ |
Subscription::Subscription(const Channel *channel, bool event, |
38 |
|
|
unsigned int decimation, size_t blocksize, |
39 |
|
✗ |
bool base64, size_t precision): |
40 |
|
|
channel(channel), |
41 |
|
✗ |
event(event), decimation(event ? 1 : decimation), |
42 |
|
✗ |
bufferOffset(channel->offset) |
43 |
|
|
{ |
44 |
|
✗ |
trigger = 0; |
45 |
|
✗ |
nblocks = 0; |
46 |
|
|
|
47 |
|
✗ |
if (!decimation) |
48 |
|
✗ |
decimation = 1U; |
49 |
|
|
|
50 |
|
✗ |
if (!blocksize) |
51 |
|
✗ |
blocksize = 1U; |
52 |
|
|
|
53 |
|
✗ |
if (event) { |
54 |
|
✗ |
this->trigger_start = decimation; |
55 |
|
✗ |
this->trigger = 0; |
56 |
|
✗ |
this->blocksize = 1; |
57 |
|
|
} |
58 |
|
|
else { |
59 |
|
✗ |
this->blocksize = blocksize; |
60 |
|
|
} |
61 |
|
✗ |
this->precision = precision; |
62 |
|
✗ |
this->base64 = base64; |
63 |
|
|
|
64 |
|
✗ |
size_t dataLen = this->blocksize * channel->memSize; |
65 |
|
|
|
66 |
|
✗ |
data_bptr = new char[dataLen]; |
67 |
|
✗ |
data_eptr = data_bptr + dataLen; |
68 |
|
|
|
69 |
|
✗ |
data_pptr = data_bptr; |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
///////////////////////////////////////////////////////////////////////////// |
73 |
|
✗ |
Subscription::~Subscription() |
74 |
|
|
{ |
75 |
|
✗ |
delete data_bptr; |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
///////////////////////////////////////////////////////////////////////////// |
79 |
|
✗ |
bool Subscription::newValue (const char *buf) |
80 |
|
|
{ |
81 |
|
✗ |
const size_t n = channel->memSize; |
82 |
|
✗ |
buf += bufferOffset; |
83 |
|
✗ |
if (event) { |
84 |
|
✗ |
if (!std::equal(buf, buf + n, data_bptr)) { |
85 |
|
✗ |
std::copy(buf, buf + n, data_bptr); |
86 |
|
✗ |
nblocks = 1; |
87 |
|
✗ |
data_pptr = data_bptr + n; |
88 |
|
|
} |
89 |
|
|
|
90 |
|
✗ |
if (!trigger) { |
91 |
|
✗ |
if (nblocks) |
92 |
|
✗ |
trigger = trigger_start; |
93 |
|
✗ |
return nblocks; |
94 |
|
|
} |
95 |
|
✗ |
--trigger; |
96 |
|
✗ |
return false; |
97 |
|
|
} |
98 |
|
|
|
99 |
|
✗ |
std::copy(buf, buf + n, data_pptr); |
100 |
|
✗ |
data_pptr += n; |
101 |
|
✗ |
++nblocks; |
102 |
|
|
|
103 |
|
✗ |
return nblocks == blocksize; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
///////////////////////////////////////////////////////////////////////////// |
107 |
|
✗ |
void Subscription::print(XmlElement &parent) |
108 |
|
|
{ |
109 |
|
|
// if (!nblocks) |
110 |
|
|
// return; |
111 |
|
|
|
112 |
|
✗ |
XmlElement datum(parent.createChild(event ? "E" : "F")); |
113 |
|
✗ |
XmlElement::Attribute(datum, "c") << channel->index; |
114 |
|
|
|
115 |
|
✗ |
XmlElement::Attribute value(datum, "d"); |
116 |
|
✗ |
if (base64) |
117 |
|
✗ |
value.base64(data_bptr, nblocks * channel->memSize); |
118 |
|
|
else |
119 |
|
✗ |
value.csv(channel, data_bptr, nblocks, precision); |
120 |
|
|
|
121 |
|
✗ |
data_pptr = data_bptr; |
122 |
|
✗ |
nblocks = 0; |
123 |
|
3 |
} |
124 |
|
|
|