Peak Manager
- renamed ports to status[0..N] - emiut gain messages PekaDetect - emit peak messages also on peak height changes git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@499 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -22,11 +22,6 @@
|
||||
<source>
|
||||
<name>status</name>
|
||||
<type>message</type>
|
||||
<optional>1</optional>
|
||||
</source>
|
||||
<source>
|
||||
<name>freq</name>
|
||||
<type>message</type>
|
||||
<nports>$numPeaksMax</nports>
|
||||
<optional>1</optional>
|
||||
</source>
|
||||
|
||||
@@ -293,6 +293,7 @@ namespace gr {
|
||||
{
|
||||
Peak &peak = m_peakHistory[j];
|
||||
peak.heightUpdate_rel(m_pXds, nitems_per_block);
|
||||
peak.heightUpdate_abs(m_pXs, nitems_per_block);
|
||||
|
||||
if (peak.height_rel >= (m_peak_height_min-10.f))
|
||||
{
|
||||
@@ -300,46 +301,49 @@ namespace gr {
|
||||
}
|
||||
else
|
||||
{
|
||||
// Output OFF-tags
|
||||
pmt::pmt_t dict = peak.msg(0);
|
||||
peak.setState(0);
|
||||
// Output tags
|
||||
pmt::pmt_t dict = peak.msg();
|
||||
message_port_pub(m_msg_port_out, dict);
|
||||
add_item_tag(DATA, nitems_written(DATA) + k, pmt::string_to_symbol(std::string("peak")), dict, m_tag_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_peakList.size(); i++)
|
||||
{
|
||||
Peak &peak = m_peakList[i];
|
||||
peak.heightUpdate_rel(m_pXds, nitems_per_block);
|
||||
peak.heightUpdate_abs(m_pXs, nitems_per_block);
|
||||
|
||||
bool found = false;
|
||||
for (int j=0; j < temp.size(); j++)
|
||||
{
|
||||
if (temp[j].isInRange(peak))
|
||||
{
|
||||
bool changed = temp[j].update(peak);
|
||||
found = true;
|
||||
if (changed)
|
||||
{
|
||||
pmt::pmt_t dict = temp[j].msg(1);
|
||||
message_port_pub(m_msg_port_out, dict);
|
||||
add_item_tag(DATA, nitems_written(DATA) + k, pmt::string_to_symbol(std::string("peak")), dict, m_tag_id);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
peak.setState(1);
|
||||
temp.push_back(peak);
|
||||
|
||||
// Output ON-tags
|
||||
pmt::pmt_t dict = peak.msg(1);
|
||||
message_port_pub(m_msg_port_out, dict);
|
||||
add_item_tag(DATA, nitems_written(DATA) + k, pmt::string_to_symbol(std::string("peak")), dict, m_tag_id);
|
||||
}
|
||||
}
|
||||
|
||||
for (int j=0; j < temp.size(); j++)
|
||||
{
|
||||
Peak &peak = temp[j];
|
||||
if (peak.isModified)
|
||||
{
|
||||
pmt::pmt_t dict = peak.msg();
|
||||
message_port_pub(m_msg_port_out, dict);
|
||||
add_item_tag(DATA, nitems_written(DATA) + k, pmt::string_to_symbol(std::string("peak")), dict, m_tag_id);
|
||||
}
|
||||
|
||||
}
|
||||
m_peakHistory.clear();
|
||||
m_peakHistory = temp;
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ namespace jay {
|
||||
}
|
||||
Peak(uint64_t _id, int _pos, int _pbh, float _frequency, float _height_rel, float _height_abs)
|
||||
: id(_id)
|
||||
, isModified(false)
|
||||
, state(0)
|
||||
, pos(_pos)
|
||||
, pbh(_pbh)
|
||||
, frequency(_frequency)
|
||||
@@ -51,6 +53,8 @@ namespace jay {
|
||||
|
||||
}
|
||||
uint64_t id;
|
||||
bool isModified;
|
||||
int state;
|
||||
int pos;
|
||||
int pbh;
|
||||
float height_rel;
|
||||
@@ -69,22 +73,60 @@ namespace jay {
|
||||
|
||||
void heightUpdate_rel(float const *pData, int length)
|
||||
{
|
||||
float newHeight = -100.f;
|
||||
for (int i=left(); i <= right(); i++)
|
||||
if (pbh)
|
||||
{
|
||||
newHeight = std::max(newHeight, pData[i]);
|
||||
int newPos = -1;
|
||||
float newHeight = -100.f;
|
||||
for (int i=left(); i <= right(); i++)
|
||||
{
|
||||
if (newHeight < pData[i])
|
||||
{
|
||||
newPos = i;
|
||||
newHeight = pData[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (pos != newPos)
|
||||
{
|
||||
isModified = true;
|
||||
pos = newPos;
|
||||
}
|
||||
|
||||
if (std::fabs(height_rel-newHeight) >= 3.0f)
|
||||
{
|
||||
isModified = true;
|
||||
height_rel = newHeight;
|
||||
}
|
||||
}
|
||||
height_rel = newHeight;
|
||||
}
|
||||
|
||||
void heightUpdate_abs(float const *pData, int length)
|
||||
{
|
||||
float newHeight = -100.f;
|
||||
for (int i=left(); i <= right(); i++)
|
||||
if (pbh)
|
||||
{
|
||||
newHeight = std::max(newHeight, pData[i]);
|
||||
int newPos = -1;
|
||||
float newHeight = -100.f;
|
||||
for (int i=left(); i <= right(); i++)
|
||||
{
|
||||
if (newHeight < pData[i])
|
||||
{
|
||||
newPos = i;
|
||||
newHeight = pData[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (pos != newPos)
|
||||
{
|
||||
isModified = true;
|
||||
height_abs = newHeight;
|
||||
}
|
||||
|
||||
if (std::fabs(height_abs-newHeight) >= 3.0f)
|
||||
{
|
||||
isModified = true;
|
||||
height_rel = newHeight;
|
||||
}
|
||||
}
|
||||
height_abs = newHeight;
|
||||
}
|
||||
|
||||
bool makeBox(int pbh_min, int pbh_max, float const *pData, int length)
|
||||
@@ -146,26 +188,30 @@ namespace jay {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// isModified = true;
|
||||
return pbh > 0;
|
||||
}
|
||||
|
||||
bool update(const Peak &other)
|
||||
{
|
||||
bool changed = false;
|
||||
if (std::fabs(height_rel-other.height_rel) >= 3.0f)
|
||||
{
|
||||
isModified = true;
|
||||
}
|
||||
if (std::fabs(height_abs-other.height_abs) >= 3.0f)
|
||||
{
|
||||
isModified = true;
|
||||
}
|
||||
if (pos != other.pos)
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
if (std::abs(frequency-other.frequency) >= (0.01*1e6))
|
||||
{
|
||||
changed = true;
|
||||
isModified = true;
|
||||
}
|
||||
frequency = other.frequency;
|
||||
pos = other.pos;
|
||||
pbh = other.pbh;
|
||||
height_rel = other.height_rel;
|
||||
height_abs = other.height_abs;
|
||||
return changed;
|
||||
return isModified;
|
||||
}
|
||||
|
||||
int left() const
|
||||
@@ -178,17 +224,27 @@ namespace jay {
|
||||
return pos + pbh;
|
||||
}
|
||||
|
||||
pmt::pmt_t msg(int state)
|
||||
pmt::pmt_t msg()
|
||||
{
|
||||
pmt::pmt_t dict = pmt::make_dict();
|
||||
dict = pmt::dict_add(dict, pmt::string_to_symbol(std::string("id")), pmt::from_long(id));
|
||||
dict = pmt::dict_add(dict, pmt::string_to_symbol(std::string("pos")), pmt::from_long(pos));
|
||||
dict = pmt::dict_add(dict, pmt::string_to_symbol(std::string("freq_Hz")), pmt::from_float(frequency));
|
||||
dict = pmt::dict_add(dict, pmt::string_to_symbol(std::string("height")), pmt::from_float(height_rel));
|
||||
dict = pmt::dict_add(dict, pmt::string_to_symbol(std::string("height")), pmt::from_float(height_abs));
|
||||
dict = pmt::dict_add(dict, pmt::string_to_symbol(std::string("state")), pmt::from_long(state));
|
||||
|
||||
isModified = false;
|
||||
return dict;
|
||||
}
|
||||
|
||||
void setState(int _state)
|
||||
{
|
||||
if (_state != state)
|
||||
{
|
||||
isModified = true;
|
||||
}
|
||||
state = _state;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
@@ -45,12 +45,12 @@ class peak_manager(gr.basic_block):
|
||||
self.message_port_register_out(pmt.intern("status"))
|
||||
|
||||
if self.numPeaksMax < 2:
|
||||
out_port_name = "freq"
|
||||
out_port_name = "status"
|
||||
self.ports_avail.append(out_port_name)
|
||||
self.message_port_register_out(pmt.intern(out_port_name))
|
||||
else:
|
||||
for n in range(0, self.numPeaksMax):
|
||||
out_port_name = "freq" + str(n)
|
||||
out_port_name = "status" + str(n)
|
||||
self.ports_avail.append(out_port_name)
|
||||
self.message_port_register_out(pmt.intern(out_port_name))
|
||||
|
||||
@@ -84,7 +84,7 @@ class peak_manager(gr.basic_block):
|
||||
if pmt.is_dict(msg):
|
||||
items = pmt.dict_items(msg)
|
||||
|
||||
peak = {}
|
||||
peakMsg = {}
|
||||
for n in range(0, pmt.length(items)):
|
||||
pair = pmt.nth(n, items)
|
||||
key = pmt.car(pair)
|
||||
@@ -94,41 +94,49 @@ class peak_manager(gr.basic_block):
|
||||
|
||||
if pmt.is_integer(val):
|
||||
value = pmt.to_long(val)
|
||||
peak[key_str] = value
|
||||
peakMsg[key_str] = value
|
||||
# print("{}={}".format(key_str, value))
|
||||
elif pmt.is_real(val):
|
||||
value = pmt.to_float(val)
|
||||
peak[key_str] = value
|
||||
peakMsg[key_str] = value
|
||||
# print("{}={}".format(key_str, value))
|
||||
elif pmt.is_bool(val):
|
||||
value = pmt.to_bool(val)
|
||||
peak[key_str] = value
|
||||
peakMsg[key_str] = value
|
||||
# print("{}={}".format(key_str, value))
|
||||
|
||||
id = peak['id']
|
||||
freq_MHz = peak['freq_Hz']*1e-6
|
||||
id = peakMsg['id']
|
||||
freq_MHz = peakMsg['freq_Hz']*1e-6
|
||||
|
||||
peak_key = 'peak' + str(id)
|
||||
peak0 = self.peak_get(peak_key)
|
||||
peakEntry = self.peak_get(peak_key)
|
||||
|
||||
if peak['state'] == 1:
|
||||
if peak0 is not None:
|
||||
pair = pmt.cons(pmt.intern("freq"), pmt.from_float(peak['freq_Hz']))
|
||||
portname = peak0['port_name']
|
||||
if peakMsg['state'] == 1:
|
||||
if peakEntry is not None:
|
||||
portname = peakEntry['port_name']
|
||||
print("Update " + peak_key + "(" + portname + ")")
|
||||
pair = pmt.cons(pmt.intern("freq"), pmt.from_float(peakMsg['freq_Hz']))
|
||||
self.message_port_pub(pmt.intern(portname), pair)
|
||||
pair = pmt.cons(pmt.intern("gain"), pmt.from_float(-peakMsg['height']))
|
||||
self.message_port_pub(pmt.intern(portname), pair)
|
||||
else:
|
||||
print ("New peak #{} at {:0.2f} MHz".format(id, freq_MHz))
|
||||
peak0 = self.peak_add(peak_key, peak)
|
||||
pair = pmt.cons(pmt.intern("freq"), pmt.from_float(peak['freq_Hz']))
|
||||
portname = peak0['port_name']
|
||||
print("Added " + peak_key + "(" + portname + ")")
|
||||
self.message_port_pub(pmt.intern(portname), pair)
|
||||
peakEntry = self.peak_add(peak_key, peakMsg)
|
||||
if peakEntry is not None:
|
||||
portname = peakEntry['port_name']
|
||||
print("Added " + peak_key + "(" + portname + ")")
|
||||
pair = pmt.cons(pmt.intern("freq"), pmt.from_float(peakMsg['freq_Hz']))
|
||||
self.message_port_pub(pmt.intern(portname), pair)
|
||||
pair = pmt.cons(pmt.intern("gain"), pmt.from_float(-peakMsg['height']))
|
||||
self.message_port_pub(pmt.intern(portname), pair)
|
||||
else:
|
||||
print ("Lost peak #{} at {:0.2f} MHz".format(id, freq_MHz))
|
||||
portname = peak0['port_name']
|
||||
if self.peak_del(peak_key):
|
||||
print("Deleted " + peak_key + "(" + portname + ")")
|
||||
if peakEntry is not None:
|
||||
print ("Lost peak #{} at {:0.2f} MHz".format(id, freq_MHz))
|
||||
portname = peakEntry['port_name']
|
||||
pair = pmt.cons(pmt.intern("gain"), pmt.from_float(-120.0))
|
||||
self.message_port_pub(pmt.intern(portname), pair)
|
||||
if self.peak_del(peak_key):
|
||||
print("Deleted " + peak_key + "(" + portname + ")")
|
||||
|
||||
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user