Exemplo n.º 1
0
void TraceLoader::findFrameStart(ApiTraceFrame *frame)
{
    if (!frame->isLoaded()) {
        loadFrame(frame);
    }
    emit foundFrameStart(frame);
}
Exemplo n.º 2
0
bool DataLink::receive(NetworkFrame& frame)
{
	if(m_initialised)
	{
		if(not foundFrameStart())
		{
			return false;
		}
		
		uint16_t maxSize = maxFrameSize();
		uint8_t* buffer = new uint8_t[maxSize];
		bool foundEnd;
		uint16_t index = 0;
		bool slipEscape = false;
		int c = 0;

		/* Try and find the frame end, our two exit conditions are:
		 * 		- Found the end frame character (SUCCESS)
		 * 		- Gone over the max frame size (FAILURE)
		*/
		while(not foundEnd && index < maxSize)
		{
			c = readByte();

			// No characters left to read
			if(c == -1)
			{
				break;
			}
			// We found the end
			if(not slipEscape && SLIP::isEndCharacter(c))
			{
				foundEnd = true;
			}
			// The last character is escaping a special character
			else if(slipEscape)
			{
				buffer[index] = SLIP::getEscapedCharacter(c);
				index++;
				slipEscape = false;
			}
			// Check if the character is an escape character
			else if((uint8_t)c == SLIP_PACKET_ESCAPE)
			{
				slipEscape = true;
			}
			// Its a normal character, just store it
			else
			{
				buffer[index] = c;
				index++;
			}
		}

		// Found a full frame
		if(foundEnd)
		{
			uint8_t frameSize = index + 1;
			uint8_t* frameData = new uint8_t[frameSize];
			memcpy(frameData, buffer, frameSize);
			delete[] buffer;
			frame.setData(frameData, frameSize);
			return true;
		}

		delete[] buffer;
	}
	
	return false;
}