Esempio n. 1
0
void ValueProcessor::interpolate(std::string &str,
                                 const ValueScope &scope) const {
  size_t start, end = 0;
  string key, value;
  const TokenList *var;
  TokenList variable;

  while ((start = str.find("@{", end)) != string::npos &&
         (end = str.find("}", start)) != string::npos) {
    key = "@";
    key.append(str.substr(start + 2, end - (start + 2)));

    var = scope.getVariable(key);

    if (var != NULL) {
      variable = *var;

      processValue(variable, scope);

      // Remove quotes off strings.
      if (variable.size() == 1 && variable.front().type == Token::STRING) {
        variable.front().removeQuotes();
      }

      value = variable.toString();

      str.replace(start, (end + 1) - start, value);
      end = start + value.length();
    }
  }
}
Esempio n. 2
0
const TokenList *ValueProcessor::processDeepVariable(
    TokenList::const_iterator &i,
    TokenList::const_iterator &end,
    const ValueScope &scope) const {
  const TokenList *var;
  TokenList variable;
  std::string key = "@";

  if (i == end || (*i).type != Token::OTHER || (*i) != "@")
    return NULL;

  i++;

  if (i == end || (*i).type != Token::ATKEYWORD ||
      (var = scope.getVariable((*i))) == NULL) {
    i--;
    return NULL;
  }

  variable = *var;
  processValue(variable, scope);

  if (variable.size() != 1 || variable.front().type != Token::STRING) {
    i--;
    return NULL;
  }

  i++;
  // generate key with '@' + var without quotes
  variable.front().removeQuotes();
  key.append(variable.front());

  return scope.getVariable(key);
}
int AX12::presentPSL (int* PSL) {                                // lee position, speed & load de una sola vez
    AX12data data = readData (PRESENT_POSITION, 6);
    for (byte f=0; f<3; f++) {
      PSL[f] = makeInt (&data.data[2*f], 2);  
      processValue (PRESENT_POSITION + 2*f, &PSL[f]);
    }
    return data.error;
}
int AX12::setPosVel (int pos, int vel) {
    processValue (GOAL_POSITION, &pos);
    byte values [4];
    values [0] = lowByte(pos);
    values[1] = highByte(pos);
    values [2] = lowByte(vel);
    values[3] = highByte(vel);
    return writeData (GOAL_POSITION, 4, values);
}
// seteando a "true" el parámetro adicional se transforma en un reg write
int AX12::writeInfo (byte registr, int value, bool isReg) {
    byte reglength = lengthWrite (registr);
    if (reglength==0) {return -2;}
    processValue (registr, &value);
    byte values [reglength];
    values [0] = lowByte(value);
    if (reglength > 1) {values[1] = highByte(value);}
    return writeData (registr, reglength, values, isReg);
}
Esempio n. 6
0
bool audio::algo::aec::Lms::process(float* _output, const float* _feedback, const float* _microphone, int32_t _nbSample) {
	// add sample in the feedback history:
	m_feedBack.resize(m_filter.size()+_nbSample, 0.0f);
	memcpy(&m_feedBack[m_filter.size()], _feedback, _nbSample*sizeof(float));
	for (int32_t iii=0; iii < _nbSample; iii++) {
		_output[iii] = processValue(&m_feedBack[m_filter.size()+iii], _microphone[iii]);
	}
	// remove old value:
	m_feedBack.erase(m_feedBack.begin(), m_feedBack.begin() + (m_feedBack.size()-m_filter.size()) );
	return true;
}
Esempio n. 7
0
/** "intelligent" read data */
AX12info AX12::readInfo (byte registr) {
    byte reglength = lengthRead (registr);
    AX12info returninfo;
    returninfo.error = -2;
    if (reglength == 0) {return returninfo;}
    AX12data returndata = readData (registr, reglength);
    returninfo.error = returndata.error;
    returninfo.value = makeInt (returndata.data, reglength);    
    processValue (registr, &returninfo.value);
    return returninfo;
}
Esempio n. 8
0
					bool processFloat(float* _output, const float* _microphone, const float* _feedback, int32_t _nbSample) {
						for (int8_t kkk=0; kkk<m_nbChannel; ++kkk) {
							// add sample in the feedback history:
							m_feedBack[kkk].resize(m_filter[kkk].size()+_nbSample, 0.0f);
							memcpy(&m_feedBack[kkk][m_filter[kkk].size()], _feedback, _nbSample*sizeof(float));
							for (int32_t iii=0; iii < _nbSample; iii++) {
								_output[iii] = processValue(&m_feedBack[kkk][m_filter[kkk].size()+iii], _microphone[iii], m_filter[kkk]);
							}
							// remove old value:
							m_feedBack[kkk].erase(m_feedBack[kkk].begin(), m_feedBack[kkk].begin() + (m_feedBack[kkk].size()-m_filter[kkk].size()) );
						}
						return true;
					}
Esempio n. 9
0
/**
 * Sum counts from the input workspace in lambda along lines of constant Q by
 * projecting to "virtual lambda" at a reference angle.
 *
 * @param detectorWS [in] :: the input workspace in wavelength
 * @param indices [in] :: an index set defining the foreground histograms
 * @return :: the single histogram output workspace in wavelength
 */
API::MatrixWorkspace_sptr
ReflectometrySumInQ::sumInQ(const API::MatrixWorkspace &detectorWS,
                            const Indexing::SpectrumIndexSet &indices) {

  const auto spectrumInfo = detectorWS.spectrumInfo();
  const auto refAngles = referenceAngles(spectrumInfo);
  // Construct the output workspace in virtual lambda
  API::MatrixWorkspace_sptr IvsLam =
      constructIvsLamWS(detectorWS, indices, refAngles);
  auto &outputE = IvsLam->dataE(0);
  // Loop through each spectrum in the detector group
  for (auto spIdx : indices) {
    if (spectrumInfo.isMasked(spIdx) || spectrumInfo.isMonitor(spIdx)) {
      continue;
    }
    // Get the size of this detector in twoTheta
    const auto twoThetaRange = twoThetaWidth(spIdx, spectrumInfo);
    // Check X length is Y length + 1
    const auto inputBinEdges = detectorWS.binEdges(spIdx);
    const auto inputCounts = detectorWS.counts(spIdx);
    const auto inputStdDevs = detectorWS.countStandardDeviations(spIdx);
    // Create a vector for the projected errors for this spectrum.
    // (Output Y values can simply be accumulated directly into the output
    // workspace, but for error values we need to create a separate error
    // vector for the projected errors from each input spectrum and then
    // do an overall sum in quadrature.)
    std::vector<double> projectedE(outputE.size(), 0.0);
    // Process each value in the spectrum
    const int ySize = static_cast<int>(inputCounts.size());
    for (int inputIdx = 0; inputIdx < ySize; ++inputIdx) {
      // Do the summation in Q
      processValue(inputIdx, twoThetaRange, refAngles, inputBinEdges,
                   inputCounts, inputStdDevs, *IvsLam, projectedE);
    }
    // Sum errors in quadrature
    const int eSize = static_cast<int>(outputE.size());
    for (int outIdx = 0; outIdx < eSize; ++outIdx) {
      outputE[outIdx] += projectedE[outIdx] * projectedE[outIdx];
    }
  }

  // Take the square root of all the accumulated squared errors for this
  // detector group. Assumes Gaussian errors
  double (*rs)(double) = std::sqrt;
  std::transform(outputE.begin(), outputE.end(), outputE.begin(), rs);

  return IvsLam;
}
Esempio n. 10
0
bool PosixProcess::wait( bool block )
{
    int pval,res;
    res = waitpid( m_pid, &pval, block ? 0 : WNOHANG );
    if( res == m_pid )
    {
        done(true);
        processValue( WEXITSTATUS(pval) );

        return true;
    }
    else if( res == 0 )
    {
        done(false);
        return true;
    }

    lastError( errno );
    return false;
}
Esempio n. 11
0
void ValueProcessor::processValue(TokenList &value,
                                  const ValueScope &scope) const {
  TokenList::iterator i;
  TokenList newvalue;
  Value *v;
  const TokenList *var;
  TokenList variable;
  const TokenList *oldvalue = &value;
  TokenList::const_iterator i2, itmp, end;

  if (!needsProcessing(value)) {
    // interpolate strings
    for (i = value.begin(); i != value.end(); i++) {
      if ((*i).type == Token::STRING)
        interpolate((*i), scope);
    }
    return;
  }

  end = oldvalue->end();
  for (i2 = oldvalue->begin(); i2 != end;) {
    try {
      itmp = i2;
      v = processStatement(itmp, end, scope);
      i2 = itmp;
    } catch (ValueException*) {
      v = NULL;
    }

    // add spaces between values
    if (v != NULL || i2 != end) {
      if (newvalue.size() == 0 || !needsSpace(newvalue.back(), false) ||
          (v == NULL && !needsSpace(*i2, true))) {
      } else {
        newvalue.push_back(Token::BUILTIN_SPACE);
      }
    }

    if (v != NULL) {
      var = v->getTokens();
      newvalue.insert(
          newvalue.end(), var->begin(), var->end());
      var = NULL;
      delete v;
    } else if (i2 != end) {
      // variable containing a non-value.
      if ((*i2).type == Token::ATKEYWORD &&
          (var = scope.getVariable(*i2)) != NULL) {
        variable = *var;
        processValue(variable, scope);

        newvalue.insert(newvalue.end(), variable.begin(), variable.end());
        i2++;

        // deep variable
      } else if ((var = processDeepVariable(i2, end, scope)) != NULL) {
        variable = *var;
        processValue(variable, scope);

        newvalue.insert(newvalue.end(), variable.begin(), variable.end());

      } else if ((*i2).type == Token::IDENTIFIER) {
        newvalue.push_back(*i2);
        i2++;

        if (i2 != end && (*i2).type == Token::PAREN_OPEN) {
          newvalue.push_back(*i2);
          i2++;
        }
      } else {
        newvalue.push_back(*i2);
        i2++;
      }
    }
  }

  value = newvalue;
  return;
}
Esempio n. 12
0
int main (int argc, char *argv[])
{

    char *device = NULL;

    int fd;

    int c;

    struct input_event event;

    int num = -1;
    int caps = -1;
    int scroll = -1;

    int tempValue;

    const struct option long_opts[] = {
      { "input", required_argument, NULL, 'i' },
      { "num", required_argument, NULL, 'n' },
      { "caps" , required_argument, NULL, 'c' },
      { "scroll"  , required_argument, NULL, 's' },
      { NULL, 0, NULL, 0 }
    };


    while ( (c = getopt_long(argc, argv, "i:n:c:s:", long_opts, NULL)) != EOF) {
        switch (c) {
            case 'i':
                device = optarg;
                break;
            case 'n':

                processValue(atoi(optarg),&num);
                break;
            case 'c':
                processValue(atoi(optarg),&caps);
                break;
		    case 's':
                processValue(atoi(optarg),&scroll);
                break;
            case '?':
                usage();
                return 0;

        }
    }


    if (device == NULL) {
        perror_exit("Not a valid input event device found");
    }

    if ((fd = open (device, O_RDWR | O_NONBLOCK)) == -1) {
        perror_exit("Unable to open input event device");
    }


    if (num != -1) {
        makeEvent(&event, LED_NUML, num);
        write(fd, &event, sizeof(struct input_event));
    }


    if (caps != -1) {
        makeEvent(&event, LED_CAPSL, caps);
        write(fd, &event, sizeof(struct input_event));
    }


    if (scroll != -1) {
        makeEvent(&event, LED_SCROLLL, scroll);
        write(fd, &event, sizeof(struct input_event));
    }


    return 0;

}