Beispiel #1
0
QsoImpl::QsoImpl(const StationData &station, ModuleEchoLink *module)
  : m_qso(station.ip()), module(module), event_handler(0), msg_handler(0),
    output_sel(0), init_ok(false), reject_qso(false), last_message(""),
    last_info_msg(""), idle_timer(0), disc_when_done(false), idle_timer_cnt(0),
    idle_timeout(0), destroy_timer(0), station(station), sink_handler(0)
{
  assert(module != 0);

  Config &cfg = module->cfg();
  const string &cfg_name = module->cfgName();
  
  string local_callsign;
  if (!cfg.getValue(cfg_name, "CALLSIGN", local_callsign))
  {
    cerr << "*** ERROR: Config variable " << cfg_name << "/CALLSIGN not set\n";
    return;
  }
  m_qso.setLocalCallsign(local_callsign);
  
  bool use_gsm_only = false;
  if (cfg.getValue(cfg_name, "USE_GSM_ONLY", use_gsm_only) && use_gsm_only)
  {
    cout << module->name() << ": Using GSM codec only\n";
    m_qso.setUseGsmOnly();
  }

  if (!cfg.getValue(cfg_name, "SYSOPNAME", sysop_name))
  {
    cerr << "*** ERROR: Config variable " << cfg_name
      	 << "/SYSOPNAME not set\n";
    return;
  }
  m_qso.setLocalName(sysop_name);
  
  string description;
  if (!cfg.getValue(cfg_name, "DESCRIPTION", description))
  {
    cerr << "*** ERROR: Config variable " << cfg_name
      	 << "/DESCRIPTION not set\n";
    return;
  }
  m_qso.setLocalInfo(description);
  
  string event_handler_script;
  if (!cfg.getValue(module->logicName(), "EVENT_HANDLER", event_handler_script))
  {
    cerr << "*** ERROR: Config variable " << module->logicName()
      	 << "/EVENT_HANDLER not set\n";
    return;
  }
  
  string idle_timeout_str;
  if (cfg.getValue(cfg_name, "LINK_IDLE_TIMEOUT", idle_timeout_str))
  {
    idle_timeout = atoi(idle_timeout_str.c_str());
    idle_timer = new Timer(1000, Timer::TYPE_PERIODIC);
    idle_timer->expired.connect(mem_fun(*this, &QsoImpl::idleTimeoutCheck));
  }
  
  sink_handler = new AudioPassthrough;
  AudioSink::setHandler(sink_handler);

  msg_handler = new MsgHandler(INTERNAL_SAMPLE_RATE);
  msg_handler->allMsgsWritten.connect(
      	  mem_fun(*this, &QsoImpl::allRemoteMsgsWritten));
	  
  AudioPacer *msg_pacer = new AudioPacer(INTERNAL_SAMPLE_RATE,
      	      	                         160*4*(INTERNAL_SAMPLE_RATE / 8000),
					 500);
  msg_handler->registerSink(msg_pacer, true);
  
  output_sel = new AudioSelector;
  output_sel->addSource(sink_handler);
  output_sel->enableAutoSelect(sink_handler, 0);
  output_sel->addSource(msg_pacer);
  output_sel->enableAutoSelect(msg_pacer, 10);
  AudioSource *prev_src = output_sel;

#if INTERNAL_SAMPLE_RATE == 16000
  AudioDecimator *down_sampler = new AudioDecimator(
          2, coeff_16_8, coeff_16_8_taps);
  prev_src->registerSink(down_sampler, true);
  prev_src = down_sampler;
#endif

  prev_src->registerSink(&m_qso);
  prev_src = 0;
  
  event_handler = new EventHandler(event_handler_script, 0);
  event_handler->playFile.connect(
      sigc::bind(mem_fun(*msg_handler, &MsgHandler::playFile), false));
  event_handler->playSilence.connect(
      sigc::bind(mem_fun(*msg_handler, &MsgHandler::playSilence), false));
  event_handler->playTone.connect(
      sigc::bind(mem_fun(*msg_handler, &MsgHandler::playTone), false));

    // Workaround: Need to set the ID config variable and "logic_name"
    // variable to load the TCL script.
  event_handler->processEvent("namespace eval EchoLink {}");
  event_handler->setVariable("EchoLink::CFG_ID", "0");
  event_handler->setVariable("logic_name", "Default");

  event_handler->processEvent("namespace eval Logic {}");
  string default_lang;
  if (cfg.getValue(cfg_name, "DEFAULT_LANG", default_lang))
  {
    event_handler->setVariable("Logic::CFG_DEFAULT_LANG", default_lang);
  }
  
  event_handler->initialize();
  
  m_qso.infoMsgReceived.connect(mem_fun(*this, &QsoImpl::onInfoMsgReceived));
  m_qso.chatMsgReceived.connect(mem_fun(*this, &QsoImpl::onChatMsgReceived));
  m_qso.stateChange.connect(mem_fun(*this, &QsoImpl::onStateChange));
  m_qso.isReceiving.connect(sigc::bind(isReceiving.make_slot(), this));
  m_qso.audioReceivedRaw.connect(
      sigc::bind(audioReceivedRaw.make_slot(), this));
  
  prev_src = &m_qso;
  
  AudioFifo *input_fifo = new AudioFifo(2048);
  input_fifo->setOverwrite(true);
  input_fifo->setPrebufSamples(1024);
  prev_src->registerSink(input_fifo, true);
  prev_src = input_fifo;
  
#if INTERNAL_SAMPLE_RATE == 16000
  AudioInterpolator *up_sampler = new AudioInterpolator(
          2, coeff_16_8, coeff_16_8_taps);
  prev_src->registerSink(up_sampler, true);
  prev_src = up_sampler;
#endif

  AudioSource::setHandler(prev_src);
  
  init_ok = true;
  
} /* QsoImpl::QsoImpl */