Exemple #1
0
OSCMessage& OSCMessage::start(char * _address, uint8_t * buffer, int maximumBytes, int len){
	//set the msg data to the beginning of the received buffer
	setBuffer(buffer);
	maxBytes(maximumBytes);
	//the length of the address
	int addrLen = strlen(_address);
	//set the address in memory
	addToBuffer((uint8_t *) _address, addrLen );
	//pad address
	addPadToBuffer(padSize(addrLen));
	//comma delimiter
	addToBuffer(uint8_t(','));
	//beginning of type section
	typePtr = currentBufferPosition();
	//jump to beginning of padding
	msgBytes+=len;
	//pad the type section
	addPadToBuffer(padSize(len+1));
	//beginning of data section
	dataPtr = currentBufferPosition();
	//number of datum
	dataSize = len;
	//read/write position in the message
	position = 0;
	return *this;
}
Exemple #2
0
    void Scanner::handleOperationState()
    {
        loc_ = getTokenLocation();
        bool matched = false;
        // add current symbol char
        addToBuffer(currentChar_);
        // add next one symbol char
        addToBuffer(peekChar());

        if (dictionary_.haveToken(buffer_))
        {
            matched = true;
            getNextChar();
        }
        else
        {
            reduceBuffer();
        }

        auto tokenMeta = dictionary_.lookup(buffer_);
        // token type, token value, name, symbol precedence
        makeToken(std::get<0>(tokenMeta), std::get<1>(tokenMeta), loc_, buffer_, std::get<2>(tokenMeta));
        // update currentChar_
        getNextChar();
    }
Exemple #3
0
OSCMessage& OSCMessage::add(uint8_t * data, int len) {
	//first put in the type
	addType('b');
	//then the length
	addToBuffer(int32_t(len)); 
	//then the data
	addToBuffer(data, len); 
	//pad the blob;
	addPadToBuffer(padSize(len));
	return *this;
}
Exemple #4
0
OSCMessage& OSCMessage::add(double data){
	//add type
	addType('f');
	//add data;
	addToBuffer(float(data));
	return *this;
}
void startScanning()
{
	char buffer[513];
    int i = 0;
    
	while(!feof(file_list)) {
		
        pthread_mutex_lock(&mutex_one);
		while(buffer_amount > 0)
			pthread_cond_wait(&empty_cond, &mutex_one);
        
		for(i = 0; i < scan_buffer_size; ++i){
            if (fgets(buffer, 512, file_list) != NULL) {
                if(buffer[strlen(buffer) - 1] == '\n')
                    buffer[strlen(buffer) - 1] = '\0';
                //printf("Add %d\n",buffer_amount);
                addToBuffer(buffer);
                continue;
                // else not actually needed, but used as a safety net
            }else{
                break;
            }
        }
        
		pthread_cond_broadcast(&fill_cond);
        pthread_mutex_unlock(&mutex_one);
	}
    
	pthread_mutex_lock(&mutex_one);
	scanning_done = TRUE;
    pthread_cond_broadcast(&fill_cond);
	pthread_mutex_unlock(&mutex_one);
    
	fclose(file_list);
}
Exemple #6
0
//put data onto the dataPtr of the data array
OSCMessage& OSCMessage::add(int32_t data){
	//add type
	addType('i');
	//add data;
	addToBuffer(data);
	return *this;
}
Exemple #7
0
//put data onto the data part of the data array
OSCMessage& OSCMessage::add(unsigned int data){
	//add type
	addType('i');
	//add data;
	addToBuffer(int32_t(data));
	return *this;
}
Exemple #8
0
    void Scanner::handleDigit()
    {
        // add first number of integer
        addToBuffer(currentChar_);
        getNextChar();

        while (std::isdigit(currentChar_))
        {
            addToBuffer(currentChar_);
            getNextChar();
        }

        // end while. currentChar_ is not digit.
        // notice maybe currentChar_ is .(dot) or E/e,
        // so the NumberState can be changed into
        // NumberState::Fraction or NumberState::Exponent.
    }
Exemple #9
0
void bufferPrint(const char* toBuffer)
{
	int len = strlen(toBuffer);
	addToBuffer(toBuffer, len);

	if(printf_handler)
		printf_handler(toBuffer);
}
//Get the Data from the input fields
void MainWindow::getData()
{
    eventData event;
    event.setName(ui->lineName->text());
    event.setEmailId(ui->lineEmail->text());
    event.setDate(ui->dateEdit->date().toString("dd - MMMM - yyyy"));
    event.setEventType(ui->comboBox->currentText());
    addToBuffer(event);
}
Exemple #11
0
OSCMessage& OSCMessage::add(char * data) {
	//first put in the type
	addType('s');
	//then the data
	addToBuffer((uint8_t *) data, strlen(data));
	//pad the string;
	addPadToBuffer(padSize(strlen(data)));
	return *this;
}
TParagraph *readParagraph( fstream& textFile, int& offset, TCrossRefNode *&xRefs )
{
    State state;
    Boolean flag;
    char line[MAXSTRSIZE];
    TParagraph *p;

    ofs = 0;
    state = undefined;
    strcpy(line, getLine(textFile));
    while (strlen(line) == 0)
        {
        flag = (state == wrapping)? True: False;
        addToBuffer(line, flag);
        strcpy(line, getLine(textFile));
        }

    if (isEndParagraph(state) == True)
        {
        unGetLine(line);
        return(0);
        }
    while (isEndParagraph(state) == False)
        {
        if (state == undefined )
            if (line[0] == ' ')
                state = notWrapping;
            else
                state = wrapping;
        scanForCrossRefs(line, offset, xRefs);
        flag = (state == wrapping)? True: False;
        addToBuffer(line, flag);
        strcpy(line, getLine(textFile));
        }
    unGetLine(line);
    p = new TParagraph;
    p->size = ofs;
    p->wrap = (state == wrapping)? True: False;
    p->text = new char[ofs];
    memmove(p->text, buffer, ofs);
    p->next = 0;
    offset += ofs;
    return(p);
}
Exemple #13
0
Platform* MapGenerator::generatePlatform(Vector2d* startVector)
{
	// 1. get possible set
	// 2. get allowed set
	// 3. modify chance (using buffer & deltaY)
	// 4. select GeneratedBlock
	// 5. add platformblock to platform
	// 6. add used GeneratedBlock to buffer

	Platform* platform = new Platform();

	set<GeneratedBlock> possibleSet = allZeroes;
	set<GeneratedBlock> allowedSet = getAllowedSet(possibleSet, startVector);
	modifyChances(allowedSet, startVector);
	GeneratedBlock* selectedBlock = selectBlock(allowedSet);

	PlatformBlock* block = new PlatformBlock(selectedBlock->type, startVector);
	platform->addPlatformBlock(block);

	Vector2d* newStartVector = block->getEndVector();

	addToBuffer(*selectedBlock);

	int length = (PLATFORM_LENGTH_MIN - 1) + (rand() % (2 + PLATFORM_LENGTH_MAX - PLATFORM_LENGTH_MIN));

	for (int i = 0; i < length; i++) {

		possibleSet = getPossibleSet(selectedBlock);
		allowedSet = getAllowedSet(possibleSet, newStartVector);
		modifyChances(allowedSet, newStartVector);
		selectedBlock = selectBlock(allowedSet);

		*newStartVector+=Vector2d(0.f, selectedBlock->dy);

		block = new PlatformBlock(selectedBlock->type, newStartVector);
		platform->addPlatformBlock(block);

		newStartVector = block->getEndVector();

		addToBuffer(*selectedBlock);
	}

	return platform;
}
Exemple #14
0
void bufferPrint(const char* toBuffer) {
	if(UartHasInit)
		uartPrint(toBuffer);

	if(FramebufferHasInit)
		framebuffer_print(toBuffer);

	int len = strlen(toBuffer);
	addToBuffer(toBuffer, len);
}
Exemple #15
0
void cmd_cat(int argc, char** argv) {
	if(argc < 3) {
		bufferPrintf("Usage: %s <address> <len>\r\n", argv[0]);
		return;
	}

	uint32_t address = parseNumber(argv[1]);
	uint32_t len = parseNumber(argv[2]);
	addToBuffer((char*) address, len);
}
Exemple #16
0
    void Scanner::handleExponent()
    {
        // eat E/e
        addToBuffer(currentChar_);
        getNextChar();

        // if number has +/-
        if (currentChar_ == '+' || currentChar_ == '-')
        {
            addToBuffer(currentChar_);
            getNextChar();
        }

        while (std::isdigit(currentChar_))
        {
            addToBuffer(currentChar_);
            getNextChar();
        }
    }
Exemple #17
0
bool OSCMessage::receiveFrom(Stream &s, int numBytes){
	if (s.available()){
		while(s.available() && numBytes){
			addToBuffer(uint8_t(s.read()));
			numBytes--;
		}
		//parse the buffer
		return parse();
	} else {
		return false;
	}
}
Exemple #18
0
    void Scanner::handleIdentifierState()
    {
        loc_ = getTokenLocation();
        // add first char
        addToBuffer(currentChar_);
        getNextChar();

        while (std::isalnum(currentChar_) || currentChar_ == '_')
        {
            addToBuffer(currentChar_);
            getNextChar();
        }

        // end while. currentChar_ is not alpha, number and _.
        // keyword or not
        // because Pascal is not case sensitive
        // we should transform it to lower case
        std::transform(buffer_.begin(), buffer_.end(), buffer_.begin(), std::tolower);
        // use dictionary to judge it is keyword or not
        auto tokenMeta = dictionary_.lookup(buffer_);
        makeToken(std::get<0>(tokenMeta), std::get<1>(tokenMeta), loc_, buffer_, std::get<2>(tokenMeta));
    }
Exemple #19
0
    void CloudAssembler::cloudCallback(const sensor_msgs::PointCloud2& cloud)
    {
      addToBuffer(cloud);
      assembleCloud();
     
      sensor_msgs::PointCloud2 cloud_msg;

      toROSMsg(assembled_PointCloudXYZ, cloud_msg);

      cloud_msg.header.frame_id = cloud.header.frame_id;
      cloud_msg.header.stamp = ros::Time::now();
     
     }
Exemple #20
0
void bufferPrint(const char* toBuffer) {
	if(UartHasInit)
		uartPrint(toBuffer);

	if(FramebufferHasInit)
		framebuffer_print(toBuffer);

	int len = strlen(toBuffer);
	addToBuffer(toBuffer, len);

	if(acm_is_ready)
		acm_buffer_notify();
}
Exemple #21
0
Q_ULONG TEDisplayBase::writeBlockSlow( const char *data, Q_ULONG len )
{
    if (m_pWriter==0)
    {
        return writeBlock(data,len);
    }
    else
    {
        if (m_pBuffer->size()<100)
            addToBuffer(data,len);
        return len;
    };
};
int rrd_xport_format_sv(char sep, stringbuffer_t *buffer,image_desc_t *im,time_t start, time_t end, unsigned long step, unsigned long col_cnt, char **legend_v, rrd_value_t* data) {
  /* define the time format */
  char* timefmt=NULL;
  if (im->xlab_user.minsec!=-1.0) { timefmt=im->xlab_user.stst; }

  /* row count */
  unsigned long row_cnt=(end-start)/step;

  /* estimate buffer size (to avoid multiple allocations) */
  buffer->allocated=
    1024 /* bytes of overhead /header/footer */
    +(12+19*col_cnt) /* 12 bytes overhead/line plus 19 bytes per column*/
    *(1+row_cnt) /* number of columns + 1 (for header) */
    ;

  char buf[256];

  /* now start writing the header*/
  if (addToBuffer(buffer,"\"time\"",6)) { return 1; }
  for(unsigned long i=0;i<col_cnt;i++) {
    /* strip leading spaces */
    char *t=legend_v[i]; while (isspace(*t)) { t++;}
    /* and print it */
    snprintf(buf,255,"%c\"%s\"",sep,t);
    if (addToBuffer(buffer,buf,0)) { return 1;}
  }
  if (addToBuffer(buffer,"\r\n",2)) { return 1; }
  /* and now write the data */
  rrd_value_t *ptr=data;
  for(time_t ti=start+step;ti<end;ti+=step) {
    /* write time */
    if (timefmt) {
      struct tm loc;
      localtime_r(&ti,&loc);
      strftime(buf,254,timefmt,&loc);
    } else {
      snprintf(buf,254,"%lld",(long long int)ti);
    }
    if (addToBuffer(buffer,buf,0)) { return 1; }
    /* write the columns */
    for(unsigned long i=0;i<col_cnt;i++) {
      /* get the value */
      rrd_value_t v=*ptr;ptr++;
      /* and print it */
      if (isnan(v)) {
        snprintf(buf,255,"%c\"NaN\"",sep);
      } else {
        rrd_snprintf(buf,255,"%c\"%0.10e\"",sep,v);
      }
      if (addToBuffer(buffer,buf,0)) { return 1;}
    }
    /* and add a newline */
    if (addToBuffer(buffer,"\r\n",2)) { return 1; }
  }

  /* and return OK */
  return 0;
}
Exemple #23
0
    void Scanner::handleFraction()
    {
        // currentChar_ is . (dot)

        // if we have number 4..12. just simple error condition.
        // our compiler has one big difference compared with
        // commercial compiler, that is about error conditions.
        if (peekChar() == '.')
        {
            errorToken(getTokenLocation().toString() + "Fraction number can not have dot after dot");
            errorFlag_ = true;
        }

        // eat .
        addToBuffer(currentChar_);
        getNextChar();

        while (std::isdigit(currentChar_))
        {
            addToBuffer(currentChar_);
            getNextChar();
        }
    }
void 
nsHtml5MetaScanner::handleCharInAttributeValue(PRInt32 c)
{
  if (metaState == NS_HTML5META_SCANNER_A) {
    if (contentIndex == CONTENT.length || charsetIndex == CHARSET.length) {
      addToBuffer(c);
    } else if (httpEquivIndex == HTTP_EQUIV.length) {
      if (contentTypeIndex < CONTENT_TYPE.length && toAsciiLowerCase(c) == CONTENT_TYPE[contentTypeIndex]) {
        ++contentTypeIndex;
      } else {
        contentTypeIndex = PR_INT32_MAX;
      }
    }
  }
}
Exemple #25
0
void Ontology::update(const set<Statement>& statements){
    set<string> stringified_stmts;
    set<Statement>::const_iterator iterator = statements.begin();

    while( iterator != statements.end() ) {
        if (_bufferize) addToBuffer("update", (Statement)*iterator);
        stringified_stmts.insert(((Statement)*iterator).to_string());
        ++iterator;
    }

    if (!_bufferize) {
        ServerResponse res = _connector.execute("update", stringified_stmts, _waitForAck);

        if (res.status == ServerResponse::failed) throw OntologyServerException("Server" + res.exception_msg + " while updating statements. Server message was " + res.error_msg);
    }
}
Exemple #26
0
std::vector<float>* Synth::genChunk()
{
    clearBuffer();

    for (int osc = 0; osc < oscillators.size(); osc++)
    {
        tempOsc = &oscillators[osc];
        for (unsigned int i = 0; i < *CHUNK_SIZE; i++)
        {
            addToBuffer(i, wavetable[round(tempOsc->phaseTab)] * tempOsc->amplitude * masterVolume);
            tempOsc->nextSample();
        }
    }

    return &buffer;
}
    void Connection::readerThread() {

        char buffer[BUFFER_SIZE];

        int readStatus = 0;
        memset(buffer, 0, sizeof (buffer));
        while (this->isOpened && (readStatus = recv(this->socketDescriptor, buffer, sizeof (buffer), 0) > 0)) {

            addToBuffer(buffer);
            memset(buffer, 0, sizeof (buffer));
        }

        if (this->isOpened) {
            performClose();
            this->isOpened = false;
        }
    }
Exemple #28
0
    void Scanner::handleStringState()
    {
        loc_ = getTokenLocation();
        // eat ' and NOT update currentChar_
        // because we don't want ' (single quote).
        getNextChar();

        while (true)
        {
            if (currentChar_ == '\'')
            {
                // '''' condition
                // see pascal standard section 6.1.7
                if (peekChar() == '\'')
                {
                    getNextChar();
                }
                // otherwise, we have handle string literal completely.
                else
                {
                    break;
                }
            }

            addToBuffer(currentChar_);
            getNextChar();
        }

        // eat end ' and update currentChar_ .
        getNextChar();

        // just one char
        if (buffer_.length() == 1)
        {
            makeToken(TokenType::CHAR, TokenValue::UNRESERVED, loc_,
                      static_cast<long>(buffer_.at(0)), buffer_);
        }
        else
        {
            makeToken(TokenType::STRING_LITERAL, TokenValue::UNRESERVED,
                      loc_, buffer_, -1);
        }
    }
Exemple #29
0
    void Scanner::handleXDigit()
    {
        // notice: we have eat $ and update currentChar_
        // in the handleNumber function. so we need not
        // eat currentChar_ like handleDigit function.
        // only have $ or not
        bool readFlag = false;

        while (std::isxdigit(currentChar_))
        {
            readFlag = true;
            addToBuffer(currentChar_);
            getNextChar();
        }

        if (!readFlag)
        {
            errorToken(getTokenLocation().toString() + "Hexadecimal number format error.");
            errorFlag_ = true;
        }
    }
Exemple #30
0
// Main program where right now the producer is called
int main(int argc, char* argv []){
  // Check to make sure the number of args is right
  if (argc != 3){
    printErrorMessage();    
  } 
  //int numberOfThreads = (int)strtol(argv[1], NULL, 10);
  char* listOfFileNames = argv[2];
  // All of the following code is determine the number of filenames in the file
  FILE * counterFile;
  counterFile = fopen(listOfFileNames, "r");
  int numberOfLines = 0;
  char buffer[512];
  int buffer_len = 512;
  while (fgets(buffer, buffer_len, counterFile) != NULL){
    numberOfLines++;
  }
  fclose(counterFile);
  
  // Malloc the producerBuffer for future use
  producerBuffer = malloc(numberOfLines*sizeof(char*));
  addToBuffer(listOfFileNames);
  //indexer(blah);
  exit(0);
}