@@ -40,7 +40,7 @@ bool doStop = false;
40
40
41
41
// Catch signals
42
42
void signalHandler (int signo) {
43
- if (_io_thread) _io_thread->stop ();
43
+ if (_io_thread) _io_thread->stop ();
44
44
doStop = true ;
45
45
}
46
46
@@ -112,12 +112,13 @@ int main(int argc, char **argv) {
112
112
SonarConfiguration config;
113
113
config.setPingRate (pingRateNormal);
114
114
config.setRange (range);
115
+
115
116
if (bitDepth == 8 ) {
116
117
config.setDataSize (dataSize8Bit);
117
118
} else if (bitDepth == 16 ) {
118
119
config.setDataSize (dataSize16Bit);
119
120
} else if (bitDepth == 32 ) {
120
- config.dontSendGain ()
121
+ config.sendGain ()
121
122
.noGainAssistance ()
122
123
.setDataSize (dataSize32Bit);
123
124
}
@@ -126,6 +127,7 @@ int main(int argc, char **argv) {
126
127
DataRx _data_rx (_io_thread->context ());
127
128
StatusRx _status_rx (_io_thread->context ());
128
129
130
+ // Callback for a SimplePingResultV1
129
131
_data_rx.setCallback <liboculus::SimplePingResultV1>([&](const liboculus::SimplePingResultV1 &ping) {
130
132
// Pings send to the callback are always valid
131
133
@@ -147,6 +149,7 @@ int main(int argc, char **argv) {
147
149
if ((stopAfter > 0 ) && (count >= stopAfter)) _io_thread->stop ();
148
150
});
149
151
152
+ // Callback for a SimplePingResultV2
150
153
_data_rx.setCallback <liboculus::SimplePingResultV2>([&](const liboculus::SimplePingResultV2 &ping) {
151
154
// Pings send to the callback are always valid
152
155
@@ -159,6 +162,15 @@ int main(int argc, char **argv) {
159
162
160
163
ping.dump ();
161
164
165
+ const auto bearings = ping.bearings ();
166
+ LOG (INFO) << " Azimuth range = " << bearings.front () << " - " << bearings.back ();
167
+
168
+ const auto gains = ping.gains ();
169
+ if (gains.size () > 0 ) {
170
+ LOG (INFO) << " First five gains " << gains[10 ] << " , " << gains[11 ] << " , "
171
+ << gains[12 ] << " , " << gains[13 ] << " , " << gains[14 ];
172
+ }
173
+
162
174
if (output.is_open ()) {
163
175
const char *cdata = reinterpret_cast <const char *>(ping.buffer ()->data ());
164
176
output.write (cdata, ping.buffer ()->size ());
@@ -168,13 +180,16 @@ int main(int argc, char **argv) {
168
180
if ((stopAfter > 0 ) && (count >= stopAfter)) doStop=true ;
169
181
});
170
182
183
+ // Callback when connection to a sonar
171
184
_data_rx.setOnConnectCallback ([&]() {
172
185
config.dump ();
173
186
_data_rx.sendSimpleFireMessage (config);
174
187
});
175
188
176
- // Connect client
189
+ // Connect the client
177
190
if (ipAddr == " auto" ) {
191
+ // To auto-detect, when the StatusRx connects,
192
+ // configure the DataRx
178
193
_status_rx.setCallback ([&](const SonarStatus &status, bool is_valid){
179
194
if (!is_valid || _data_rx.isConnected ()) return ;
180
195
_data_rx.connect (status.ipAddr ());
@@ -184,11 +199,11 @@ int main(int argc, char **argv) {
184
199
}
185
200
_io_thread->start ();
186
201
187
- // Imprecise statistic for now...
188
202
int lastCount = 0 ;
189
203
while (!doStop) {
190
- auto c = count;
191
204
205
+ // Very rough Hz calculation right now
206
+ const auto c = count;
192
207
LOG (INFO) << " Received pings at " << c-lastCount << " Hz" ;
193
208
194
209
lastCount = c;
0 commit comments