@@ -266,7 +266,18 @@ kis_adsb_phy::kis_adsb_phy(int in_phyid) :
266
266
try {
267
267
ss >> device_json;
268
268
269
- auto adsb_content = hex_to_bytes (device_json[" adsb_raw_msg" ]);
269
+ std::string adsb_content;
270
+
271
+ auto hex_j = device_json[" adsb" ];
272
+
273
+ if (hex_j.is_null () || !hex_j.is_string ()) {
274
+ hex_j = device_json[" adsb_raw_msg" ];
275
+ adsb_content = hex_to_bytes (hex_j);
276
+ } else {
277
+ const auto stradsb = hex_j.get <std::string>();
278
+ adsb_content = hex_to_bytes (stradsb.substr (1 , stradsb.size () - 2 ));
279
+ }
280
+
270
281
271
282
if (adsb_content.size () != 7 && adsb_content.size () != 14 ) {
272
283
_MSG_DEBUG (" unexpected content length {}" , adsb_content.size ());
@@ -301,11 +312,9 @@ kis_adsb_phy::kis_adsb_phy(int in_phyid) :
301
312
delete[] buf;
302
313
303
314
} catch (std::exception & e) {
304
- delete uptr;
305
315
return 0 ;
306
316
}
307
317
308
- delete uptr;
309
318
return 1 ;
310
319
}, uptr, CHAINPOS_LOGGING, 1000 );
311
320
@@ -318,6 +327,7 @@ kis_adsb_phy::kis_adsb_phy(int in_phyid) :
318
327
}
319
328
320
329
packetchain->remove_handler (beast_handler_id, CHAINPOS_LOGGING);
330
+ delete uptr;
321
331
}));
322
332
323
333
httpd->register_websocket_route (" /phy/ADSB/raw" , {httpd->RO_ROLE , " ADSB" }, {" ws" },
@@ -327,7 +337,7 @@ kis_adsb_phy::kis_adsb_phy(int in_phyid) :
327
337
auto ws =
328
338
std::make_shared<kis_net_web_websocket_endpoint>(con,
329
339
[](std::shared_ptr<kis_net_web_websocket_endpoint> ws,
330
- boost::beast::flat_buffer& buf, bool text) {
340
+ boost::beast::flat_buffer& buf, bool text) mutable {
331
341
// Do nothing on input
332
342
});
333
343
@@ -341,7 +351,7 @@ kis_adsb_phy::kis_adsb_phy(int in_phyid) :
341
351
uptr->ws = ws;
342
352
uptr->adsb = this ;
343
353
344
- auto beast_handler_id =
354
+ auto raw_handler_id =
345
355
packetchain->register_handler (
346
356
[](void *auxdata, const std::shared_ptr<kis_packet>& in_pack) -> int {
347
357
@@ -364,16 +374,20 @@ kis_adsb_phy::kis_adsb_phy(int in_phyid) :
364
374
try {
365
375
ss >> device_json;
366
376
377
+ auto hex_j = device_json[" adsb" ];
378
+
379
+ if (hex_j.is_null () || !hex_j.is_string ()) {
380
+ hex_j = device_json[" adsb_raw_msg" ];
381
+ }
382
+
367
383
auto adsb_content =
368
- fmt::format (" *{}; \n " , device_json[ " adsb_raw_msg " ] .get <std::string>());
384
+ fmt::format (" {} \n " , hex_j .get <std::string>());
369
385
370
386
uptr->ws ->write (adsb_content);
371
387
} catch (std::exception & e) {
372
- delete uptr;
373
388
return 0 ;
374
389
}
375
390
376
- delete uptr;
377
391
return 1 ;
378
392
}, uptr, CHAINPOS_LOGGING, 1000 );
379
393
@@ -384,8 +398,9 @@ kis_adsb_phy::kis_adsb_phy(int in_phyid) :
384
398
} catch (const std::exception & e) {
385
399
;
386
400
}
387
-
388
- packetchain->remove_handler (beast_handler_id, CHAINPOS_LOGGING);
401
+
402
+ packetchain->remove_handler (raw_handler_id, CHAINPOS_LOGGING);
403
+ delete (uptr);
389
404
}));
390
405
391
406
httpd->register_websocket_route (" /datasource/by-uuid/:uuid/adsb_raw" , {httpd->RO_ROLE , " ADSB" }, {" ws" },
@@ -417,7 +432,7 @@ kis_adsb_phy::kis_adsb_phy(int in_phyid) :
417
432
uptr->adsb = this ;
418
433
uptr->srcuuid = srcuuid;
419
434
420
- auto beast_handler_id =
435
+ auto raw_handler_id =
421
436
packetchain->register_handler (
422
437
[](void *auxdata, const std::shared_ptr<kis_packet>& in_pack) -> int {
423
438
@@ -449,7 +464,7 @@ kis_adsb_phy::kis_adsb_phy(int in_phyid) :
449
464
ss >> device_json;
450
465
451
466
auto adsb_content =
452
- fmt::format (" *{};\n " , device_json[" adsb_raw_msg " ].get <std::string>());
467
+ fmt::format (" *{};\n " , device_json[" adsb " ].get <std::string>());
453
468
454
469
uptr->ws ->write (adsb_content);
455
470
} catch (std::exception & e) {
@@ -469,7 +484,7 @@ kis_adsb_phy::kis_adsb_phy(int in_phyid) :
469
484
;
470
485
}
471
486
472
- packetchain->remove_handler (beast_handler_id , CHAINPOS_LOGGING);
487
+ packetchain->remove_handler (raw_handler_id , CHAINPOS_LOGGING);
473
488
}));
474
489
475
490
}
0 commit comments