-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathBrennenstuhl3600.cpp
209 lines (188 loc) · 5.49 KB
/
Brennenstuhl3600.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// Copyright (c) 2016-2016 Josh Blum
// SPDX-License-Identifier: BSL-1.0
#include <Pothos/Framework.hpp>
#include <iostream>
#include <complex>
#include <cmath>
#include <queue>
#include <map>
#include "Brennenstuhl3600Codes.hpp"
/***********************************************************************
* |PothosDoc Brennenstuhl 3600
*
* Generate wireless remote control packets for the Brennenstuhl 3600.
* This block outputs multiple wireless control packets in a burst
* when a change to the on/off mode is made (or on activation).
*
* |category /Control
* |keywords brennenstuhl power control
*
* |param mode The mode is either on (true) or off (false)
* |default false
* |option [On] true
* |option [Off] false
*
* |param group Which group to control A, B, C, D, or ALL.
* |default "A"
* |option [A] "A"
* |option [B] "B"
* |option [C] "C"
* |option [D] "D"
* |option [All] "ALL"
*
* |param rate The sample rate of the output stream
* |units Sps
* |default 250e3
*
* |param gain The level of the output samples.
* |default 0.7
*
* |param repeat The number of times to repeat a control packet.
* |default 10
*
* |param startLabel[Start Label] An optional start of burst label.
* |widget StringEntry()
* |default ""
* |preview valid
*
* |param endLabel[End Label] An optional end of burst label.
* |widget StringEntry()
* |default "txEnd"
* |preview valid
*
* |factory /btle/brennenstuhl_3600()
* |setter setMode(mode)
* |setter setGroup(group)
* |setter setRate(rate)
* |setter setGain(gain)
* |setter setRepeat(repeat)
* |setter setStartLabel(startLabel)
* |setter setEndLabel(endLabel)
**********************************************************************/
class Brennenstuhl3600 : public Pothos::Block
{
public:
Brennenstuhl3600(void):
_mode(false),
_group("A"),
_rate(1.0),
_gain(1.0),
_repeat(1)
{
this->setupOutput(0, typeid(std::complex<float>));
this->registerCall(this, POTHOS_FCN_TUPLE(Brennenstuhl3600, setMode));
this->registerCall(this, POTHOS_FCN_TUPLE(Brennenstuhl3600, setGroup));
this->registerCall(this, POTHOS_FCN_TUPLE(Brennenstuhl3600, setRate));
this->registerCall(this, POTHOS_FCN_TUPLE(Brennenstuhl3600, setGain));
this->registerCall(this, POTHOS_FCN_TUPLE(Brennenstuhl3600, setRepeat));
this->registerCall(this, POTHOS_FCN_TUPLE(Brennenstuhl3600, setStartLabel));
this->registerCall(this, POTHOS_FCN_TUPLE(Brennenstuhl3600, setEndLabel));
loadCodes(_codeMap);
}
static Block *make(void)
{
return new Brennenstuhl3600();
}
void setMode(const bool mode)
{
_mode = mode;
this->trigger();
}
void setGroup(const std::string &group)
{
_group = group;
}
void setRate(const double rate)
{
_rate = rate;
}
void setGain(const float gain)
{
_gain = gain;
}
void setRepeat(const size_t repeat)
{
_repeat = repeat;
}
void setStartLabel(const std::string &label)
{
_startLabel = label;
}
void setEndLabel(const std::string &label)
{
_endLabel = label;
}
void activate(void)
{
this->trigger();
}
void work(void)
{
auto outPort = this->output(0);
size_t N = outPort->elements();
if (N == 0) return;
if (_toTransmit.empty()) return;
if (_doStartBurst and not _startLabel.empty())
{
const size_t elemsInBurst = _toTransmit.size()*_sampsPerSym;
outPort->postLabel(Pothos::Label(_startLabel, elemsInBurst, 0));
_doStartBurst = false;
}
auto out = outPort->buffer().as<std::complex<float> *>();
for (size_t i = 0; i < N; i++)
{
//std::cout << "_sampsPerSym " << _sampsPerSym << std::endl;
//std::cout << "_samplesCount " << _samplesCount << std::endl;
//std::cout << "_toTransmit.size() " << _toTransmit.size() << std::endl;
//std::cout << "_toTransmit.front() " << _toTransmit.front() << std::endl;
out[i] = _toTransmit.front();
_samplesCount++;
if (_samplesCount == _sampsPerSym)
{
_toTransmit.pop();
_samplesCount = 0;
}
if (_toTransmit.empty())
{
if (not _endLabel.empty())
outPort->postLabel(Pothos::Label(_endLabel, Pothos::Object(), i));
N = i+1;
break;
}
}
outPort->produce(N);
}
private:
void trigger(void)
{
_toTransmit = std::queue<float>(); //clear
_sampsPerSym = size_t(_rate/CODE_RATE);
_samplesCount = 0;
_doStartBurst = true;
const auto &code = _codeMap[_mode][_group];
for (size_t i = 0; i < _repeat; i++)
{
for (const auto &ch : code)
{
_toTransmit.push((ch=='0')?0.0:_gain);
}
}
}
//current state
std::queue<float> _toTransmit;
size_t _sampsPerSym;
size_t _samplesCount;
bool _doStartBurst;
//config
bool _mode;
std::string _group;
double _rate;
float _gain;
size_t _repeat;
std::string _startLabel;
std::string _endLabel;
//map enable to group to list of codes
std::map<bool, std::map<std::string, std::string>> _codeMap;
};
static Pothos::BlockRegistry registerBrennenstuhl3600(
"/btle/brennenstuhl_3600", &Brennenstuhl3600::make);