Exemplo n.º 1
0
void printSerialLinkBuffer(OutputStream* outputStream, const SerialLink* serialLink) {
    if (serialLink != NULL) {
        StreamLink* streamLink = serialLink->streamLink;

        // Serial Input Buffer
        appendCRLF(outputStream);
        Buffer* serialInputBuffer = streamLink->inputBuffer;
        appendString(outputStream, "SERIAL INPUT BUFFER : ");
        printDebugBuffer(outputStream, serialInputBuffer);

        // Serial Output Buffer
        appendCRLF(outputStream);
        Buffer* serialOutputBuffer = streamLink->outputBuffer;
        appendString(outputStream, "SERIAL OUTPUT BUFFER : ");
        printDebugBuffer(outputStream, serialOutputBuffer);
    }
}
Exemplo n.º 2
0
void bufferWriteChar(Buffer* buffer, char c) {
    int isFull = isBufferFull(buffer);
    if (!isFull) {
		char* sPointer = (char*) buffer->s;
		// Shift to the right cell index
		sPointer += buffer->writeIndex;
		*sPointer = c;
        buffer->writeIndex++;
        buffer->writeIndex %= buffer->length;
    } else {
        // We must log the problem
        writeError(IO_BUFFER_FULL);
        // Print Buffer
        printDebugBuffer(getErrorOutputStreamLogger(), buffer);
    }
}
/**
* @private
* Try to clear the buffer if it contains some 'z' char. Very usefull when we have made a mistake taping an instruction.
* @return true if it was cleared (=> buffer will be cleared), false else
*/
bool clearBufferIfNeeded(Buffer* inputBuffer) {
    
    int i;
    int inputBufferCount = getBufferElementsCount(inputBuffer);
    for (i = 0; i < inputBufferCount; i++) {
        char bufferElement = bufferGetCharAtIndex(inputBuffer, i);
        if (bufferElement == HEADER_CLEAR_INPUT_STREAM) {
            deepClearBuffer(inputBuffer);
            return true;
        }
        // remove all informations to the latest char
        if (bufferElement == HEADER_WRITE_CONTENT_AND_DEEP_CLEAR_BUFFER) {
            printDebugBuffer(getAlwaysOutputStreamLogger(), inputBuffer);
            deepClearBuffer(inputBuffer);
            return true;
        }
    }
    return false;
}