示例#1
0
//------------------------------------------------------------------------------
// serialize
//------------------------------------------------------------------------------
std::ostream& Radio::serialize(std::ostream& sout, const int i, const bool slotsOnly) const
{
   int j = 0;
   if ( !slotsOnly ) {
      indent(sout,i);
      sout << "( " << getFactoryName() << std::endl;
      j = 4;
   }

   indent(sout,i+j);
   sout << "numChannels: " << getNumberOfChannels() << std::endl;

   if (getNumberOfChannels() > 0) {
      indent(sout,i+j);
      sout << "channels: }" << std::endl;

      for (unsigned short chan = 1; chan <= getNumberOfChannels(); chan++) {
         double freq = getChannelFrequency(chan);
         indent(sout,i+j+4);
         sout << "( MegaHertz " << (freq * base::Frequency::Hz2MHz) << " )" << std::endl;
      }

      indent(sout,i+j);
      sout << "}" << std::endl;
   }

   indent(sout,i+j);
   sout << "channel: " << getChannel() << std::endl;

   indent(sout,i+j);
   sout << "maxDetectRange: ( NauticalMiles " << maxDetectRange << " )" << std::endl;

   if (radioId > 0) {
      indent(sout,i+j);
      sout << "radioID: " << radioId << std::endl;
   }

   BaseClass::serialize(sout,i+j,true);

   if ( !slotsOnly ) {
      indent(sout,i);
      sout << ")" << std::endl;
   }

   return sout;
}
示例#2
0
// Get a channel's frequency (Hz)
// Returns -1 if the channel is invalid
double Radio::getChannelFrequency(const unsigned short chan) const
{
   unsigned short nc = getNumberOfChannels();
   double freq = -1;
   if (chanFreqTbl != nullptr && nc > 0 && chan > 0 && chan <= nc) {
      freq = chanFreqTbl[chan-1];
   }
   return freq;
}
示例#3
0
 void DecoderMulti::setNumberOfChannels(unsigned int numberOfChannels)
 {
     if(numberOfChannels != getNumberOfChannels())
     {
         if(m_mode == Standard)
         {
             delete m_decoder_regular;
             m_decoder_regular = new DecoderStandard(m_order, numberOfChannels);
         }
     }
 }
示例#4
0
// Set a channel's frequency; channel numbers [ 1 .. getNumberOfChannels() ]
bool Radio::setChannelFrequency(const unsigned short chan, const double freq)
{
   bool ok = false;

   unsigned short nc = getNumberOfChannels();
   if (chanFreqTbl != nullptr && nc > 0 && chan > 0 && chan <= nc) {
      chanFreqTbl[chan-1] = freq;
      ok = true;
   }

   return ok;
}
示例#5
0
 void DecoderMulti::setNumberOfChannels(unsigned int numberOfChannels)
 {
     if(numberOfChannels != getNumberOfChannels())
     {
         if(m_mode == Regular && numberOfChannels >= m_decoder_regular->getNumberOfHarmonics())
         {
             delete m_decoder_regular;
             m_decoder_regular = new DecoderRegular(m_order, numberOfChannels);
         }
         else if(m_mode == Irregular)
         {
             delete m_decoder_irregular;
             m_decoder_irregular = new DecoderIrregular(m_order, numberOfChannels);
         }
     }
 }
示例#6
0
//------------------------------------------------------------------------------
// copyData() -- copy member data
//------------------------------------------------------------------------------
void Radio::copyData(const Radio& org, const bool cc)
{
   BaseClass::copyData(org);
   if (cc) initData();

   // (Re)set the number of channels
   setNumberOfChannels(org.numChan);

   // Copy the channel frequencies
   unsigned short numChannels = getNumberOfChannels();
   for (unsigned short chan = 1; chan <= numChannels; chan++) {
      setChannelFrequency( chan, org.getChannelFrequency(chan) );
   }

   // Set the channel number
   setChannel(org.channel);

   radioId = org.radioId;
   maxDetectRange = org.maxDetectRange;
}
示例#7
0
bool Radio::setSlotChannels(const base::PairStream* const msg)
{
   // ---
   // Quick out if the number of channels hasn't been set.
   // ---
   unsigned short nc = getNumberOfChannels();
   if (nc == 0 || msg == nullptr) {
      std::cerr << "Radio::setSlotChannels() Number of channels is not set!" << std::endl;
      return false;
   }

   {
      unsigned short chan = 1;
      const base::List::Item* item = msg->getFirstItem();
      while (chan <= nc && item != nullptr) {

         const base::Pair* pair = static_cast<const base::Pair*>(item->getValue());
         const base::Frequency* p = static_cast<const base::Frequency*>(pair->object());
         if (p != nullptr) {
            double freq = base::Hertz::convertStatic( *p );
            bool ok = setChannelFrequency(chan, freq);
            if (!ok) {
               std::cerr << "Radio::setSlotChannels() Error setting frequency for channel " << chan << "; with freq = " << *p << std::endl;
            }
         }
         else {
            std::cerr << "Radio::setSlotChannels() channel# " << chan << " is not of type Frequency" << std::endl;
         }

         chan++;
         item = item->getNext();
      }
   }

   return true;
}
示例#8
0
// Sets the radio's channel number and changes the radio frequency
bool Radio::setChannel(const unsigned short chan)
{
   bool ok = false;

   unsigned short nc = getNumberOfChannels();
   if (nc > 0 && chan <= nc) {

      // Set a temporary channel number, c1, which defaults to the
      // current channel number
      unsigned short c1 = chan;
      if (chan == 0) c1 = channel;

      // If the temp channel number is greater than zero then try
      // to set the channel's frequency
      if (c1 > 0) {
         ok = setFrequency( getChannelFrequency(c1) );
      }

      // If we were able to tune to this channel then make it the current channel
      if (ok) channel = c1;

   }
   return ok;
}
  Matrix<double> IsobaricQuantitationMethod::stringListToIsotopCorrectionMatrix_(const StringList& stringlist) const
  {
    // check the string list
    if (stringlist.size() != getNumberOfChannels())
    {
      throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__, String("IsobaricQuantitationMethod: Invalid string representation of the isotope correction matrix. Expected ") + getNumberOfChannels() + " entries but got " + stringlist.size() + ".");
    }

    // create matrix to fill from stringlist
    Matrix<double> isotope_correction_matrix(getNumberOfChannels(), 4);

    // channel index
    Size channel_index = 0;

    // fill row-wise
    for (StringList::ConstIterator it = stringlist.begin(); it != stringlist.end(); ++it)
    {
      StringList corrections;
      it->split('/', corrections);
      if (corrections.size() != 4)
      {
        throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__, "IsobaricQuantitationMethod: Invalid entry in string representation of the isotope correction matrx. Expected four correction values separated by '/', got: '" + *it + "'");
      }

      // overwrite line in Matrix with custom values
      isotope_correction_matrix.setValue(channel_index, 0, corrections[0].toDouble());
      isotope_correction_matrix.setValue(channel_index, 1, corrections[1].toDouble());
      isotope_correction_matrix.setValue(channel_index, 2, corrections[2].toDouble());
      isotope_correction_matrix.setValue(channel_index, 3, corrections[3].toDouble());

      // increment channel index
      ++channel_index;
    }

    // compute frequency matrix based on the deviation matrix
    Matrix<double> channel_frequency(getNumberOfChannels(), getNumberOfChannels());

    // matrix element i, j == what contributes channel i to the intensity of channel j
    for (Size contributing_channel = 0; contributing_channel < getNumberOfChannels(); ++contributing_channel)
    {
      for (Size target_channel = 0; target_channel < getNumberOfChannels(); ++target_channel)
      {
        // as the isotope_correction_matrix encodes what channel i contributes to theoretical -2/-1/+1/+2 channels
        // hence we check if the target_channel corresponds to the contributing_channel -2/-1/+1/+2
        // if yes, we assign the corresponding contribution
        // contribution to itself is handled separately
        if ((getChannelInformation()[contributing_channel].name - 2) == getChannelInformation()[target_channel].name)
        {
          channel_frequency.setValue(target_channel, contributing_channel, isotope_correction_matrix.getValue(contributing_channel, 0) / 100);
        }
        else if ((getChannelInformation()[contributing_channel].name - 1) == getChannelInformation()[target_channel].name)
        {
          channel_frequency.setValue(target_channel, contributing_channel, isotope_correction_matrix.getValue(contributing_channel, 1) / 100);
        }
        else if ((getChannelInformation()[contributing_channel].name + 1) == getChannelInformation()[target_channel].name)
        {
          channel_frequency.setValue(target_channel, contributing_channel, isotope_correction_matrix.getValue(contributing_channel, 2) / 100);
        }
        else if ((getChannelInformation()[contributing_channel].name + 2) == getChannelInformation()[target_channel].name)
        {
          channel_frequency.setValue(target_channel, contributing_channel, isotope_correction_matrix.getValue(contributing_channel, 3) / 100);
        }
        else if (target_channel == contributing_channel)
        {
          double self_contribution = 100.0;
          for (Size column_idx = 0; column_idx < 4; ++column_idx)
          {
            self_contribution -= isotope_correction_matrix.getValue(contributing_channel, column_idx);
          }
          channel_frequency.setValue(contributing_channel, contributing_channel, (self_contribution / 100));
        }
      }
    }

    return channel_frequency;
  }