Example #1
0
void Parser::parseLeft(const std::string & str, size_t & pos, Object* eoserial)
{
    std::string key = parseString(str, pos);
    ++pos; // the colon
    DEBUG("We've read the key ")
    (*eoserial)[ key ] = parseRight( str, pos ); 
}
Example #2
0
Entity* Parser::parseRight(const std::string & str, size_t & pos)
{
    Entity* value = 0;

    if ( str[ pos ] == '{' )
    {
        // next one is an object
        DEBUG("We read an object.")
        Object* obj = new Object;
        pos += 1;
        while( pos < str.size() && str[ pos ] != '}' )
        {
            parseLeft( str, pos, obj );
            ignoreChars( str, pos );
        }
        DEBUG("We just finished to read an object ! ")
        pos += 1; // we're on the }, go to the next char
        value = obj;
    }
    else if ( str[ pos ] == '"' )
    {
        // next one is a string
        DEBUG("We read a string")
        value = parseJsonString( str, pos );
    }
    else if ( str[ pos ] == '[' )
    {
        // next one is an array
        DEBUG("We read an array")
        Array* array = new Array;
        pos += 1;
        while( pos < str.size() && str[ pos ] != ']' )
        {
            Entity* child = parseRight( str, pos );
            if ( child )
                array->push_back( child );
        }
        DEBUG("We've finished to read our array.")
        pos += 1; // we're on the ], go to the next char
        value = array;
    }
    ignoreChars( str, pos );
    return value;
}
Example #3
0
Object* Parser::parse(const std::string & str)
{
    size_t initial(0); // we begin at position 0
    return static_cast<Object*>( parseRight(str, initial) );
}
void threadedSerial::serialparse(unsigned char *c)
{
	int i, j;
	long sum;
    char tempBuf[20];
	
    dParserStartT = ofGetElapsedTimeMicros();
    // do the circular buffer thing three times independently
    for (j = 0; j < 3; j++) {
        // push bytes forward in the three circular buffers "serialStream[j]"
        for (i = 0; i < streamSize[j]-1; i++) {
            serialStream[j][i] = serialStream[j][i+1];
        }
        serialStream[j][streamSize[j]-1] = c[0]; // append new byte to each serialStream[j] buffer
    }
    dParserStopT = ofGetElapsedTimeMicros();
    dParserSum += (dParserStopT - dParserStartT);

	// pattern matching
	if (serialStream[0][0] == 65) { // packet start marker
        if(serialStream[0][1] == 240) {	// left hand packet
            if(serialStream[0][22] == 90) {
                for(i = 0; i < 20; i++) { // collect n-2 bytes into buffer
                    input[0][i] = serialStream[0][i+2];
                }
                
                printf("LEFT - serial parsing time: %lld us\n", dParserSum);
                dBuffer.append("LEFT; ");
                sprintf(tempBuf, "%lld", dParserSum);
                dBuffer.append(tempBuf);
                dBuffer.append("; ");
                dParserSum = 0;
                dLhStartT = ofGetElapsedTimeMicros();
                dLhParsing = true;
                haveInput[0] = true;
                parseLeft();
                calcKeycode();
            }
        }
    }
    
    // v3.5 comm structure
    if (serialStream[1][0] == 65) { // packet start marker
        if(serialStream[1][1] == 241) { // right hand packet
            if(serialStream[1][41] == 90) {
                for(i = 0; i < 39; i++) { // collect n-2 bytes into buffer
                    input[1][i] = serialStream[1][i+2];
                }
                printf("RIGHT - serial parsing time: %lld us\n", dParserSum);
                dBuffer.append("RIGHT; ");
                sprintf(tempBuf, "%lld", dParserSum);
                dBuffer.append(tempBuf);
                dBuffer.append("; ");
                dParserSum = 0;
                dRhStartT = ofGetElapsedTimeMicros();
                dRhParsing = true;
                haveInput[1] = true;
//                printf("input[1][35] = %x\n", input[1][35]);
                parseRight();
                calcKeycode();
                parseIMU();
            }
        }
    }
    
//    // v3.4 comm structure
//    if (serialStream[1][0] == 65) { // packet start marker
//        if(serialStream[1][1] == 241) { // right hand packet
//            if(serialStream[1][39] == 90) {
//                for(i = 0; i < 37; i++) { // collect n-2 bytes into buffer
//                    input[1][i] = serialStream[1][i+2];
//                }
//                haveInput[1] = true;
//                parseRight();
//                calcKeycode();
//                parseIMU();
//            }
//        }
//    }
    
    if (serialStream[2][0] == 65) { // packet start marker
        if(serialStream[2][1] == 242) { // AirMems packet
            if(serialStream[2][14] == 90) {
                for(i = 0; i < 12; i++) { // collect n-2 bytes into buffer
                    input[2][i] = serialStream[2][i+2];
                }
                printf("AM - serial parsing time: %lld us\n", dParserSum);
                dBuffer.append("airMEMS; ");
                sprintf(tempBuf, "%lld", dParserSum);
                dBuffer.append(tempBuf);
                dBuffer.append("; ");
                dParserSum = 0;
                dAmStartT = ofGetElapsedTimeMicros();
                dAmParsing = true;
                haveInput[2] = true;
                parseAir();
           }
        }
    }
}