Esempio n. 1
0
SelectionHeuristic Controller::getMethod() {
  if (!adaptive) {
    if (currentMethod == RANDOM) {
      if ((rand() & 0x1) > 0) {
        return SECONDORDER;
      } else {
        return FIRSTORDER;
      }
    }
    return currentMethod;
  }

  
  if (timeSinceInspection >= inspectionPeriod) {
    int currentIteration = progress.size();
    gettimeofday(&start, 0);
    currentInspectionPhase = 1;
    timeSinceInspection = 0;
    beginningOfEpoch = currentIteration;
  } else if (currentInspectionPhase == 1) {
    int currentIteration = progress.size();

    middleOfEpoch = currentIteration;
    gettimeofday(&mid, 0);
    rates[currentMethod] = findRate(&start, &mid, beginningOfEpoch, middleOfEpoch);
    currentInspectionPhase++;

    if (currentMethod == FIRSTORDER) {
      currentMethod = SECONDORDER;
    } else {
      currentMethod = FIRSTORDER;
    }
    
  } else if (currentInspectionPhase == 2) {
    int currentIteration = progress.size();
        
    gettimeofday(&finish, 0);
    rates[currentMethod] = findRate(&mid, &finish, middleOfEpoch, currentIteration);
    timeSinceInspection = 0;
    currentInspectionPhase = 0;
    
    if (fabs(rates[1]) > fabs(rates[0])) {
      currentMethod = SECONDORDER;
    } else {
      currentMethod = FIRSTORDER;
    }
    //printf("Rate 0: %f, Rate 1: %f, choose method: %i\n", rates[0], rates[1], currentMethod);
  } else {
    timeSinceInspection++;
  }
  return currentMethod;
}
Esempio n. 2
0
fxStr
ModemConfig::parseATCmd(const char* cp)
{
    fxStr cmd(cp);
    u_int pos = 0;
    while ((pos = cmd.next(pos, '<')) != cmd.length()) {
	u_int epos = pos+1;
	fxStr esc = cmd.token(epos, '>');
	esc.lowercase();
	char ecode;
	if (esc == "xon")
	    ecode = (0x80|0xf) ;
	else if (esc == "rts")
	    ecode = (0x80|0xe) ;
	else if (esc == "none")
	    ecode = (0x80|0xd) ;
	else if (esc == "")		 
	    ecode = '<';
	else {
	    BaudRate br = findRate(esc);
	    if (br == FaxModem::BR0) {
		syslog(3 , "Unknown AT escape code \"%s\"", (char*) esc);
		pos = epos;
		continue;
	    }
	    ecode = 0x80| ((int)( br )) ;
	}
	cmd.remove(pos, epos-pos);
	cmd.insert(ecode, pos);
    }
    return (cmd);
}
Esempio n. 3
0
static BaudRate
getRate(const char* cp)
{
    BaudRate br = findRate(cp);
    if (br == FaxModem::BR0) {
	syslog(3 , "Unknown baud rate \"%s\", using 19200", cp);
	br = FaxModem::BR19200;			 
    }
    return (br);
}