AREXPORT void ArClientHandlerConfig::handleGetConfigData(ArNetPacket *packet,
                                                         bool isMultiplePackets)
{
  char name[32000];
  char comment[32000];
  char type;
  std::string section;
  
  // The multiple packets method also sends display hints with the parameters;
  // the old single packet method does not.
  ArClientArg clientArg(isMultiplePackets, 
                        ArPriority::LAST_PRIORITY);
  bool isEmptyPacket = true;

  myDataMutex.lock();

  while (packet->getDataReadLength() < packet->getDataLength())
  {
    isEmptyPacket = false;

    type = packet->bufToByte();

    if (type == 'S')
    {
      packet->bufToStr(name, sizeof(name));
      packet->bufToStr(comment, sizeof(name));
      //printf("%c %s %s\n", type, name, comment);

      ArLog::log(ArLog::Verbose, "%sReceiving config section %s...", 
                 myLogPrefix.c_str(), name);
      
      section = name;
      myConfig.setSectionComment(name, comment);
    }
    else if (type == 'P')
    {
		  ArConfigArg configArg;

		  bool isSuccess = clientArg.createArg(packet,
											                     configArg);

		  if (isSuccess) {
        
			  myConfig.addParam(configArg,
							            section.c_str(),
							            configArg.getConfigPriority(),
                          configArg.getDisplayHint());
		  }
		  else
		  {
			  ArLog::log(ArLog::Terse, "ArClientHandlerConfig unknown param type");
		  }
    }
    else // unrecognized header
    {
      ArLog::log(ArLog::Terse, "ArClientHandlerConfig unknown type");
    }
  
  } // end while more to read

  if (!isMultiplePackets || isEmptyPacket) {

    ArLog::log(ArLog::Normal, "%sGot config from server.", myLogPrefix.c_str());
    IFDEBUG(myConfig.log());

    myHaveGottenConfig = true;
  }

  myDataMutex.unlock();



  if (myHaveGottenConfig) {

    myCallbackMutex.lock();

    for (std::list<ArFunctor *>::iterator it = myGotConfigCBList.begin(); 
        it != myGotConfigCBList.end(); 
        it++) {
      (*it)->invoke();
    }
    myCallbackMutex.unlock();

  } // end if config received

} // end method handleGetConfigData
Exemplo n.º 2
0
Startup::Startup(int argv, char* argc[]) {

    //QString configFileName=Static::getConfigDir()+"/"+APPNAME+".ini";

    // defaults
    receiver=0;

    host="127.0.0.1";
    serverPort=10600;
    localPort=10700;
    clientPort=10800;

    QRegExp rxArg("--receiver=([0-3])");
    QRegExp clientArg("--clientport=(\\d{1,6}$)");
    QRegExp serverArg("--serverport=(\\d{1,6}$)");
    QRegExp hostArg("--server=(\\S+$)");

    for (int i = 1; i < argv; ++i) {
        if (rxArg.indexIn(argc[i]) != -1 ) {
            receiver=rxArg.cap(1).toInt();
        } else if (clientArg.indexIn(argc[i]) != -1 ) {
            clientPort=clientArg.cap(1).toInt();
        } else if (serverArg.indexIn(argc[i]) != -1 ) {
            serverPort=serverArg.cap(1).toInt();
        } else if (hostArg.indexIn(argc[i]) != -1 ) {
            host=hostArg.cap(1);
        }
    }
    qDebug()<<"receiver:"<<receiver;
    qDebug()<<"clientPort:"<<clientPort;
    qDebug()<<"serverPort:"<<serverPort;
    qDebug()<<"host:"<<host;

    // startup the client listener
    connect(Connection::getInstance(),SIGNAL(setSampleRate(int)),this,SLOT(setSampleRate(int)));
    Connection::getInstance()->setConnection(host,serverPort);
    Data::getInstance();
    ClientListener::getInstance()->setup(clientPort,receiver);



    // Configure DttSP
    Setup_SDR();
    Release_Update();
    SetTRX(0,RX); // thread 0 is for receive
    SetTRX(1,TX);  // thread 1 is for transmit
    SetRingBufferOffset(0,0); // 0 for HPSDR
    SetThreadProcessingMode(0,RUN_PLAY);
    SetThreadProcessingMode(1,RUN_PLAY);
    SetSubRXSt(0,0,1);
    SetRXOutputGain(0,0,0.20);
    SetSampleRate(96000.0);
    reset_for_buflen(0,1024);
    reset_for_buflen(1,1024);

    SetRXOsc(0,0,0.0);
    SetRXOsc(0,1,0.0);
    SetTXOsc(1,0.0);


    QString command;
    command.append(QString("attach "));
    command.append(QString::number(receiver));
    Connection::getInstance()->sendCommand(command);

    command.clear();
    command.append(QString("frequency "));
    command.append(QString::number(receiver));
    command.append(QString(" 7056000"));
    Connection::getInstance()->sendCommand(command);

    // startup to receive the I, Q and microphone samples
    Data::getInstance()->setConnection(host,serverPort+receiver,localPort+receiver);

    // start the IQ and microphone samples
    command.clear();
    command.append(QString("start "));
    command.append(QString::number(receiver));
    command.append(QString(" iq "));
    command.append(QString(host));
    command.append(QString(" "));
    command.append(QString::number(localPort+receiver));
    Connection::getInstance()->sendCommand(command);

}
/**
 * @param client the ArServerClient * to which to send the config
 * @param packet the ArNetPacket * which accompanied the client's request
 * @param isMultiplePackets a bool set to true if the server should send a
 * packet for each config section followed by the empty packet; false if 
 * the server should send the entire config in one packet (i.e. the old style)
 * @param lastPriority the last ArPriority::Priority that should be sent 
 * to the client (this is the greatest numerical value and the least 
 * semantic priority).
**/
AREXPORT void ArServerHandlerConfig::handleGetConfig(ArServerClient *client, 
                                                     ArNetPacket *packet,
                                                     bool isMultiplePackets,
                                                     ArPriority::Priority lastPriority)
{

  ArConfigArg param;

 
  // The multiple packets method also sends display hints with the parameters;
  // the old single packet method does not.
  ArClientArg clientArg(isMultiplePackets,
                        lastPriority);

  std::set<std::string> sent;

  ArNetPacket sending;
  ArLog::log(ArLog::Normal, "Config requested.");

  std::list<ArConfigSection *> *sections = myConfig->getSections();
  for (std::list<ArConfigSection *>::iterator sIt = sections->begin(); 
       sIt != sections->end(); 
       sIt++)
  {
    // Clear the packet...
    if (isMultiplePackets) {
      sending.empty();
    }

    // clear out the sent list between sections
    sent.clear();

    ArConfigSection *section = (*sIt);
    if (section == NULL) {
      continue;
    }

    sending.byteToBuf('S');
    sending.strToBuf(section->getName());
    sending.strToBuf(section->getComment());

    ArLog::log(ArLog::Verbose, "Sending config section %s...", section->getName());

    //printf("S %s %s\n", section->getName(), section->getComment());
    std::list<ArConfigArg> *params = section->getParams();
    for (std::list<ArConfigArg>::iterator pIt = params->begin(); 
         pIt != params->end(); 
         pIt++)
    {
      param = (*pIt);

      bool isCheckableName = 
      (param.getType() != ArConfigArg::DESCRIPTION_HOLDER && 
       param.getType() != ArConfigArg::SEPARATOR &&
       param.getType() != ArConfigArg::STRING_HOLDER);

      // if we've already sent it don't send it again
      if (isCheckableName &&
          sent.find(param.getName()) != sent.end()) {
        continue;
      }
      else if (isCheckableName) {
        sent.insert(param.getName());
      }

      if (clientArg.isSendableParamType(param))
      {
        sending.byteToBuf('P');

        bool isSuccess = clientArg.createPacket(param,
                                                &sending);

      }
    } // end for each parameter

    if (!sending.isValid()) {

      ArLog::log(ArLog::Terse, "Config section %s cannot be sent; packet size exceeded",
                 section->getName());

    } // end if length exceeded...
    else if (isMultiplePackets) {

      client->sendPacketTcp(&sending);

    } // end else send in chunks...

  } // end for each section

  // If sending each section in individual packets, then send an empty packet 
  // to indicate the end of the config data.
  if (isMultiplePackets) {

    sending.empty();
    client->sendPacketTcp(&sending);
  }
  else { //  send the entire config in one packet

    // If the config is too big to fit in the packet, then just send an empty
    // packet (to try to prevent an older client from crashing)
    // TODO: Is there any better way to notify the user of an error....
    if (!sending.isValid()) {
      ArLog::log(ArLog::Terse, "Error sending config; packet size exceeded");
      sending.empty();
    }

    client->sendPacketTcp(&sending);

  } // end else send the entire packet

} // end method getConfigBySections