From 1ffba79e4df7cbf2b51a4c54b57a89af13e8072b Mon Sep 17 00:00:00 2001 From: Sergey Musikhin <musihin_sergei@mail.ru> Date: Mon, 7 Jun 2021 20:26:20 +0000 Subject: [PATCH] show power in form --- apps/fm_receiver.grc | 50 ++++++++++++++++++++++----------- lib/bladerf/bladerf_common.cc | 32 ++++++++++++++++++++- lib/bladerf/bladerf_common.h | 1 + lib/bladerf/bladerf_source_c.cc | 6 +++- 4 files changed, 70 insertions(+), 19 deletions(-) diff --git a/apps/fm_receiver.grc b/apps/fm_receiver.grc index 9c6ed09..1fcd706 100644 --- a/apps/fm_receiver.grc +++ b/apps/fm_receiver.grc @@ -41,7 +41,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [312, 4.0] + coordinate: [280, 12.0] rotation: 0 state: true - name: freq @@ -62,7 +62,23 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [512, 12.0] + coordinate: [568, 12.0] + rotation: 0 + state: true +- name: power + id: variable_qtgui_label + parameters: + comment: '' + formatter: None + gui_hint: '' + label: '' + type: real + value: '0' + states: + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [456, 12.0] rotation: 0 state: true - name: samp_rate @@ -86,7 +102,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [416, 4.0] + coordinate: [368, 12.0] rotation: 0 state: true - name: volume @@ -107,7 +123,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [712, 4.0] + coordinate: [704, 12.0] rotation: 0 state: true - name: analog_fm_demod_cf_0 @@ -197,35 +213,35 @@ blocks: coordinate: [88, 100.0] rotation: 0 state: true -- name: blocks_message_debug_0 - id: blocks_message_debug +- name: blocks_message_strobe_0 + id: blocks_message_strobe parameters: affinity: '' alias: '' comment: '' - en_uvec: 'True' + maxoutbuf: '0' + minoutbuf: '0' + msg: pmt.intern("POWER") + period: '1000' states: bus_sink: false bus_source: false bus_structure: null - coordinate: [576, 440.0] + coordinate: [88, 540.0] rotation: 0 state: true -- name: blocks_message_strobe_0 - id: blocks_message_strobe +- name: blocks_msgpair_to_var_0 + id: blocks_msgpair_to_var parameters: affinity: '' alias: '' comment: '' - maxoutbuf: '0' - minoutbuf: '0' - msg: pmt.intern("TEST") - period: '1000' + target: power states: bus_sink: false bus_source: false bus_structure: null - coordinate: [64, 532.0] + coordinate: [408, 140.0] rotation: 0 state: true - name: blocks_multiply_const_vxx_0 @@ -263,14 +279,14 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [384, 188.0] + coordinate: [408, 228.0] rotation: 0 state: true connections: - [analog_fm_demod_cf_0, '0', blocks_multiply_const_vxx_0, '0'] - [bladeRF_source_0, '0', rational_resampler_xxx_0, '0'] -- [bladeRF_source_0, pmic_out, blocks_message_debug_0, print] +- [bladeRF_source_0, pmic_out, blocks_msgpair_to_var_0, inpair] - [blocks_message_strobe_0, strobe, bladeRF_source_0, pmic_in] - [blocks_multiply_const_vxx_0, '0', audio_sink_0, '0'] - [rational_resampler_xxx_0, '0', analog_fm_demod_cf_0, '0'] diff --git a/lib/bladerf/bladerf_common.cc b/lib/bladerf/bladerf_common.cc index 8615d34..7fde952 100644 --- a/lib/bladerf/bladerf_common.cc +++ b/lib/bladerf/bladerf_common.cc @@ -426,7 +426,37 @@ void bladerf_common::set_channel_enable(bladerf_channel ch, bool enable) bool bladerf_common::get_channel_enable(bladerf_channel ch) { - return _enables[ch]; + return _enables[ch]; +} + +std::string bladerf_common::get_pmic_value(const std::string ®_name) +{ + bladerf_pmic_register reg; + if(reg_name == "CONFIGURATION") + reg = BLADERF_PMIC_CONFIGURATION; + else if(reg_name == "VOLTAGE_SHUNT") + reg = BLADERF_PMIC_VOLTAGE_SHUNT; + else if(reg_name == "VOLTAGE_BUS") + reg = BLADERF_PMIC_VOLTAGE_BUS; + else if(reg_name == "POWER") + reg = BLADERF_PMIC_POWER; + else if(reg_name == "CURRENT") + reg = BLADERF_PMIC_CURRENT; + else if(reg_name == "CALIBRATION") + reg = BLADERF_PMIC_CALIBRATION; + else return {}; + if(reg == BLADERF_PMIC_CONFIGURATION || reg == BLADERF_PMIC_CALIBRATION) + { + //https://github.com/Nuand/bladeRF/blob/master/host/libraries/libbladeRF/src/board/bladerf2/bladerf2.c#L3581 + //while not supported + //return std::to_string(get_pmic<uint16_t>(reg)); + return {}; + } + else + { + return std::to_string(get_pmic<float>(reg)); + } + } void bladerf_common::set_verbosity(std::string const &verbosity) diff --git a/lib/bladerf/bladerf_common.h b/lib/bladerf/bladerf_common.h index 86aef27..54d1f88 100644 --- a/lib/bladerf/bladerf_common.h +++ b/lib/bladerf/bladerf_common.h @@ -162,6 +162,7 @@ protected: void set_channel_enable(bladerf_channel ch, bool enable); bool get_channel_enable(bladerf_channel ch); + std::string get_pmic_value(const std::string & reg_name); template<typename T> T get_pmic(bladerf_pmic_register reg) diff --git a/lib/bladerf/bladerf_source_c.cc b/lib/bladerf/bladerf_source_c.cc index 0481628..535dd03 100644 --- a/lib/bladerf/bladerf_source_c.cc +++ b/lib/bladerf/bladerf_source_c.cc @@ -84,7 +84,11 @@ bladerf_source_c::bladerf_source_c(const std::string &args) : set_msg_handler(pmt::mp("pmic_in"),[=](const pmt::pmt_t & msg) { - message_port_pub(pmt::mp("pmic_out"), msg); + auto type = pmt::symbol_to_string(msg); + auto value = get_pmic_value(type); + auto pair = pmt::cons(msg,pmt::string_to_symbol(value)); + message_port_pub(pmt::mp("pmic_out"), pair); + }); /* Handle setting of sampling mode */ -- GitLab