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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user