src/VirtualShield.cpp
/// <summary>
/// Gets zero or one available events for processing.
/// </summary>
/// <param name="shieldEvent">The address of ShieldEvent to populate.</param>
/// <returns>true if an event was populated</returns>

Gets zero or one available events for processing.

The address of ShieldEvent to populate.
true if an event was populated
Gets zero or one available events for processing . The address of ShieldEvent to populate . true if an event was populated
bool VirtualShield::getEvent(ShieldEvent* shieldEvent) {
	bool hasEvent = false;
	if (_VShieldSerial->available() == 0 && millis() > lastOpenRequest + requestInterval) 
	{
#ifdef debugSerial
		Serial.print(AWAITING_MESSAGE);
#endif
		_VShieldSerial->write(AWAITING_MESSAGE[0]);
        _VShieldSerial->write(AWAITING_MESSAGE[1]);
        _VShieldSerial->flush();
		lastOpenRequest = millis();
	}
	bool hadData = false;
	while (!inEvent && _VShieldSerial->available() > 0) {
		hadData = true;
		char c = static_cast<char>(_VShieldSerial->read());
#ifdef debugSerialIn
		Serial.print(c);
#endif
		if (readBufferIndex < maxReadBuffer-1) {
			readBuffer[readBufferIndex++] = c;
        } 
        else
        {
            int i = readBufferIndex;
            while (i >= 0)
            {
                if (readBuffer[i] == '{')
                {
                    memmove(readBuffer, readBuffer + i, maxReadBuffer - i);
                    readBufferIndex = maxReadBuffer - i;
                    readBuffer[readBufferIndex++] = c;
                    bracketCount = 0;
                    for (int j = 0; j<readBufferIndex; j++)
                    {
                        if (readBuffer[j] == '{')
                        {
                            processInChar(shieldEvent, hasEvent, c);
                        }
                    }
                    break;
                }
                i--;
            }
        }
        if (processInChar(shieldEvent, hasEvent, c))
        {
            break;
        }
	}
	if (hadData)
	{
		lastOpenRequest = millis() - requestInterval + perMessageInterval;
	}
    if (lastClosure - lastOpening > requestInterval)
    {
        readBufferIndex = 0;
        bracketCount = 0;
    }
	return hasEvent;
}
bool VirtualShield :: getEvent ( ShieldEvent * shieldEvent ) { bool hasEvent = false ; if ( _VShieldSerial -> available ( ) == 0 && millis ( ) > lastOpenRequest + requestInterval ) { #ifdef debugSerial Serial . print ( AWAITING_MESSAGE ) ; #endif _VShieldSerial -> write ( AWAITING_MESSAGE [ 0 ] ) ; _VShieldSerial -> write ( AWAITING_MESSAGE [ 1 ] ) ; _VShieldSerial -> flush ( ) ; lastOpenRequest = millis ( ) ; } bool hadData = false ; while ( ! inEvent && _VShieldSerial -> available ( ) > 0 ) { hadData = true ; char c = static_cast < char > ( _VShieldSerial -> read ( ) ) ; #ifdef debugSerialIn Serial . print ( c ) ; #endif if ( readBufferIndex < maxReadBuffer - 1 ) { readBuffer [ readBufferIndex ++ ] = c ; } else { int i = readBufferIndex ; while ( i >= 0 ) { if ( readBuffer [ i ] == ' ' ) { memmove ( readBuffer , readBuffer + i , maxReadBuffer - i ) ; readBufferIndex = maxReadBuffer - i ; readBuffer [ readBufferIndex ++ ] = c ; bracketCount = 0 ; for ( int j = 0 ; j < readBufferIndex ; j ++ ) { if ( readBuffer [ j ] == ' ' ) { processInChar ( shieldEvent , hasEvent , c ) ; } } break ; } i -- ; } } if ( processInChar ( shieldEvent , hasEvent , c ) ) { break ; } } if ( hadData ) { lastOpenRequest = millis ( ) - requestInterval + perMessageInterval ; } if ( lastClosure - lastOpening > requestInterval ) { readBufferIndex = 0 ; bracketCount = 0 ; } return hasEvent ; }
<summary>
Gets zero or one available events for processing.
<summary > Gets zero or one available events for processing .
//and timing!