Пример #1
0
boolean Radioino::execute()
{
	String tempAddress = "0000";
	int inByte;
	_commandCharIndex = 5; // just after command header
	_commandSize = _command.length();
	while (_commandCharIndex < _commandSize) {            
		switch (_command.charAt(_commandCharIndex)){
		case 'H'  :    // Activate a digital output         
			_commandCharIndex++;          
			// Get the param
			inByte = getNextInt();        
			write(inByte,HIGH);      
			break;
		case 'L'  :    // De-activate a digital output
			_commandCharIndex++;
			// Get the param
			inByte = getNextInt();        
			write(inByte,LOW);
			break;
		case 'S'  :    // Set the module address
			_commandCharIndex++;
			// we need more 4 characteres in setup mode
			if (!_setupMode || (_commandSize - _commandCharIndex <4))
				return false;
			// Set the new address			
			tempAddress[0] = _command.charAt(_commandCharIndex++);        
			tempAddress[1] = _command.charAt(_commandCharIndex++);        
			tempAddress[2] = _command.charAt(_commandCharIndex++);        
			tempAddress[3] = _command.charAt(_commandCharIndex++);        
			setAddress(tempAddress);
			break;
		case 'X'  :    // invert a digital output
			_commandCharIndex++;
			// Get the param
			inByte = getNextInt();        
			if (read(inByte)==LOW)
				write(inByte,HIGH);
			else write(inByte,LOW);
			break;
		case 'T'  :		// Play the module Tone
			_commandCharIndex++;
			// Get the param
			inByte = getNextInt();  
			toneNotify(inByte);
			break;    		
		default:     
			return false;
		}
	}    	
	
	// End the setup mode, if needed
	if (_setupMode)
	{	
		_setupMode = false;
	}
	
	return true;
}
Пример #2
0
pdf::Reference PdfReader::getNextReference(){
  TR_USE(PDF_Reader);
  pdf::Reference ret;
  ret.object = getNextInt();
  ret.generation = getNextInt();
  ASSERT_TOKEN("R");
  return ret;
}
Пример #3
0
boolean IOToaster::execute()
{
	int inByte;
	char customCommand;

	_commandCharIndex = 5; // just after command header
	_commandSize = _command.length();
	while (_commandCharIndex < _commandSize) {
		switch (_command.charAt(_commandCharIndex)){
		case 'H':    // Activate a digital output         
			_commandCharIndex++;
			// Get the param
			inByte = getNextInt();
			write(inByte, HIGH);
			break;
		case 'L':    // De-activate a digital output
			_commandCharIndex++;
			// Get the param
			inByte = getNextInt();
			write(inByte, LOW);
			break;
		case 'X':    // invert a digital output
			_commandCharIndex++;
			// Get the param
			inByte = getNextInt();
			if (read(inByte) == LOW)
				write(inByte, HIGH);
			else write(inByte, LOW);
			break;
		default:
			// Custom command
			if (_customCommandCallBack != NULL)
			{
				customCommand = _command.charAt(_commandCharIndex);
				_commandCharIndex++;
				inByte = getNextInt();
				if (!_customCommandCallBack(customCommand, inByte))
					return false;
			}
			else return false;
		}
	}

	return true;
}
Пример #4
0
pdf::Object* PdfReader::readObject(unsigned offset, pdf::Reference& refr){
  TR_USE(PDF_Reader);
  mReader->jumpTo(offset);
  int obj = getNextInt();
  if (obj != refr.object)
    TR_ERROR("expected to find %i at offset %i", refr.object, offset);
  int gen = getNextInt();
  if (gen != refr.generation)
    TR_ERROR("expected to find generation %i", refr.generation);
  ASSERT_TOKEN("obj");
  ASSERT_TOKEN("<<");
  const char* key = getNextDictEntry();
  while(key != NULL){
    key = getNextDictEntry();
  }
  ASSERT_TOKEN("endobj");
  return NULL;
}
Пример #5
0
PdfDocument* PdfReader::readDocument(){
  TR_USE(PDF_Reader);
  uint8 version[9];
  mReader->readBytes(version, 8);
  mReader->gotoEnd();
  findBackwards("startxref");
  ASSERT_TOKEN("startxref");
  unsigned crtOffset = (unsigned)getNextInt();
  //ASSERT_TOKEN("%%EOF");
  PdfDocument* doc = new PdfDocument(this, crtOffset);
  return doc;
}
Пример #6
0
pdf::Reference PdfReader::readCrt(unsigned crtOffset, pdf::CrossReferenceTable& crt){
  TR_USE(PDF_Reader);
  mReader->jumpTo(crtOffset);
  ASSERT_TOKEN("xref");
  crt.sections.push_back(pdf::CrossReferenceSection());
  pdf::CrossReferenceSection& sect = crt.sections.back();
  sect.object = getNextInt();
  sect.numObjects = getNextInt();
  for (unsigned i = 0; i < sect.numObjects; ++i){
    sect.entries.push_back(pdf::CrtEntry());
    pdf::CrtEntry& entry = sect.entries.back();
    entry.offset = getNextInt();
    entry.generation = getNextInt();
    const char* tok = getNextToken();
    entry.used = strcmp(tok, "n") == 0;
    crt.entries.push_back(entry);
  }
  //read trailer section
  int numObjects = 0;
  pdf::Reference root;
  ASSERT_TOKEN("trailer");
  ASSERT_TOKEN("<<");
  const char* key = getNextDictEntry();
  while(key != NULL){
    if (strcmp(key, "Size") == 0){
      numObjects = getNextInt();
    }
    else if (strcmp(key, "Root") == 0){
      root = getNextReference();
    }
    else
      TR_WARN("%s unexpected in trailer", key);
    key = getNextDictEntry();
  }
  return root;
}
Пример #7
0
void SArrayIndexSerializer::deserialize(SArrayIndex *index, const QString &indexFileName, TaskStateInfo& ti) {
    QFile file(indexFileName);
    if (!file.open(QIODevice::ReadOnly)) {
        ti.setError("Can't open file-index");
        return;
    }
    QByteArray data;
    bool eol = false;
    bool intErr = false;
    int lineIdx = 0;

    do {
        data = file.readLine().trimmed();
        lineIdx++;
    } while (data.length() > 0 && '#' == data[0]);

    if (0 == data.length()) {
        ti.setError("Empty parameters' line in the file-index");
        return;
    }
    index->w = getNextInt(data, eol, intErr);
    index->w4 = getNextInt(data, eol, intErr);
    index->wRest = getNextInt(data, eol, intErr);
    index->skipGap = getNextInt(data, eol, intErr);
    index->gapOffset = getNextInt(data, eol, intErr);
    index->arrLen = getNextInt(data, eol, intErr);
    index->seqLen = getNextInt(data, eol, intErr);
    index->bitFilter = getNextInt(data, eol, intErr);
    index->wCharsInMask = getNextInt(data, eol, intErr);
    index->wAfterBits = getNextInt(data, eol, intErr);
    index->l1Step = getNextInt(data, eol, intErr);
    if (eol) {
        ti.setError("Too little amount of parameters in the file-index");
        return;
    }
    index->L1_SIZE = getNextInt(data, eol, intErr);
    if (intErr) {
        ti.setError("Bad integer for some parameter in the file-index");
        return;
    }

    if (index->w <= 0 || index->arrLen <= 0) {
        ti.setError("Negative index's parameters");
        return;
    }

    index->sArray = new quint32[index->arrLen];
    QByteArray readBuffer(BUFF_SIZE, '\0');
    char *buff = readBuffer.data();
    lineIdx++;
    int len = 0;
    int pos = 0;
    int bytes = len;
    readArray(file, buff, &len, &pos, &bytes, &lineIdx, index->sArray, index->arrLen, ti);
    if (ti.cancelFlag || ti.hasError()) {
        file.close();
        return;
    }

    index->bitMask = new quint32[index->arrLen];
    readArray(file, buff, &len, &pos, &bytes, &lineIdx, index->bitMask, index->arrLen, ti);
    if (ti.cancelFlag || ti.hasError()) {
        file.close();
        return;
    }

    index->l1bitMask = new quint32[index->L1_SIZE];
    readArray(file, buff, &len, &pos, &bytes, &lineIdx, index->l1bitMask, index->L1_SIZE, ti);
    file.close();
}
Пример #8
0
void Interpreter::loadInt() {
    pushInt(getNextInt());
}
Пример #9
0
// command line argument(s) should be verbosity (optional) and input file
int main(int argv, char * argc[])
{
  int verbose = 0; // 0 = non-verbose, 1 = verbose, 2 = show-rand
  FILE * fp = 0;
  
  int numArgs = argv;
  
  // get file pointer and verbosity argument
  if(numArgs == 2){
    fp = fopen(argc[1], "r");
  }
  else if(numArgs == 3){
    verbose = getVerb(argc[1]);
    fp = fopen(argc[2], "r");
  }
  // check for invalid file
  if(fp == NULL){
    printf("FATAL ERROR: invalid file given\n");
    exit(1);
  }

  char nextChar = ' ';
  int NUMOFPROCS = 0;
  while(NUMOFPROCS == 0){
    nextChar = fgetc(fp);
    if(isdigit(nextChar)){
      NUMOFPROCS = nextChar - '0'; // subtracts the ascii value for 0 from int value
    }
  }

  int i = 0;
  struct process procs[NUMOFPROCS];
  
  while(i < NUMOFPROCS){
    procs[i].a = getNextInt(fp);
    procs[i].b = getNextInt(fp);
    procs[i].c = getNextInt(fp);
    procs[i].io = getNextInt(fp);
    i++;
  }
  
  fclose(fp);
  
  // sort processes by order of start time
  
  struct process sortedprocs[NUMOFPROCS];
  int sortflags[NUMOFPROCS]; // array to flag which processes have been sorted by time
  for(i = 0; i < NUMOFPROCS; i++){
  	sortflags[i] = 0; // set all to zero
  }
  int sortcount;
  int j;
  for(sortcount = 0; sortcount < NUMOFPROCS; sortcount++){
  	int minind;
  	int mintime = INT_MAX;
  	for(j = 0; j < NUMOFPROCS; j++){ // cycle through, checking each start against min
			if(procs[j].a < mintime && sortflags[j] == 0){
				minind = j;
				mintime = procs[j].a;
			}
  	}
  	// add it to the appropriate place in the sortedprocs array
  	sortedprocs[sortcount] = procs[minind];
  	sortflags[minind] = 1;
  }
  
  // ****** DO NOT EDIT PROCS OR SORTEDPROCS ******
  // actual scheduling here
  
	//runUni(verbose, NUMOFPROCS, &procs, &sortedprocs);
	//runfcfs(verbose, NUMOFPROCS, &procs, &sortedprocs);
	runsjf(verbose, NUMOFPROCS, &procs, &sortedprocs);
  //runrr(verbose, NUMOFPROCS, &procs, &sortedprocs);
  
}
Пример #10
0
void printNextInt()
{
    int nextInt = getNextInt();
    printf("%d\n", nextInt);
}