BOOL sentStrategyRobotPosition(unsigned char status, unsigned int x, unsigned int y, int angleInDeciDegree) {
	OutputStream* debugOutputStream = getOutputStreamLogger(INFO);
	appendString(debugOutputStream, "sentStrategyRobotPosition:");

    OutputStream* outputStream = getDriverRequestOutputStream();

    append(outputStream, COMMAND_STRATEGY_SET_ROBOT_POSITION);
    appendHex2(outputStream, status);
    appendSeparator(outputStream);

    appendHex4(outputStream, x);
    appendSeparator(outputStream);

    appendHex4(outputStream, y);
    appendSeparator(outputStream);

    appendHex4(outputStream, angleInDeciDegree);

	appendStringAndDec(debugOutputStream, "status=", status);
	appendStringAndDec(debugOutputStream, ", x=", x);
	appendStringAndDec(debugOutputStream, ", y=", y);
	appendStringAndDec(debugOutputStream, ", angle=", angleInDeciDegree);
	println(debugOutputStream);

    BOOL result = transmitFromDriverRequestBuffer();

    return result;
}
Beispiel #2
0
void printDebugBuffer(OutputStream* outputStream, Buffer* buffer) {
    appendString(outputStream, "Buf:");

    if (buffer->name) {
        appendKeyAndName(outputStream, "name=", buffer->name);
    }

    if (buffer->type) {
        appendKeyAndName(outputStream, ",type=", buffer->type);
    }

	appendStringAndDec(outputStream, ",length=", buffer->length);
    appendStringAndDec(outputStream, ",writeIdx=", buffer->writeIndex);
    appendStringAndDec(outputStream, ",readIdx=", buffer->readIndex);

    appendString(outputStream, ",START=");
    int i;
	char* sPointer = (char*) buffer->s;
    for (i = 0; i < buffer->length; i++) {
		// Shift to the right cell index
        append(outputStream, *sPointer);
		sPointer++;
    }
    appendString(outputStream, "END");
}
void deviceTrajectoryHandleRawData(char header,
        InputStream* inputStream,
        OutputStream* outputStream) {
    if (header == COMMAND_GET_ABSOLUTE_POSITION) {
        appendAck(outputStream);

        updateTrajectoryWithNoThreshold();
        append(outputStream, COMMAND_GET_ABSOLUTE_POSITION);
        notifyAbsolutePositionWithoutHeader(outputStream);

    }
    else if (header == COMMAND_DEBUG_GET_ABSOLUTE_POSITION) {
        appendAck(outputStream);

        updateTrajectoryWithNoThreshold();
        append(outputStream, COMMAND_DEBUG_GET_ABSOLUTE_POSITION);

        OutputStream* debugOutputStream = getOutputStreamLogger(ALWAYS);
        printPosition(debugOutputStream);
    }

    else if (header == COMMAND_SET_ABSOLUTE_POSITION) {
        long newX = readHex4(inputStream);
        inputStream->readChar(inputStream);
        long newY = readHex4(inputStream);
        inputStream->readChar(inputStream);
        long newAngle = readHex4(inputStream);

        appendAck(outputStream);

        OutputStream* debugOutputStream = getDebugOutputStreamLogger();

        appendStringAndDec(debugOutputStream, "newX=", newX);
        appendStringAndDec(debugOutputStream, ",newY=", newY);
        appendStringAndDec(debugOutputStream, ",newAngle=", newAngle);

        float fX = (float) newX;
        float fY = (float) newY;
        float fAngle = PI_DIVIDE_1800 * (float) newAngle;

        appendStringAndDecf(debugOutputStream, "fX=", fX);
        appendStringAndDecf(debugOutputStream, ",fY=", fY);
        appendStringAndDecf(debugOutputStream, ",fAngle=", fAngle);

        setPosition(fX, fY, fAngle);

        append(outputStream, COMMAND_SET_ABSOLUTE_POSITION);
    }
}
Beispiel #4
0
void mainBoardDeviceHandleNotification(const Device* device, const char commandHeader, InputStream* inputStream) {
    appendString(getDebugOutputStreamLogger(), "Notification ! commandHeader=");
    append(getDebugOutputStreamLogger(), commandHeader);
    appendCRLF(getDebugOutputStreamLogger());
    if (commandHeader == NOTIFY_TEST) {
        unsigned char value = readHex2(inputStream);
        appendStringAndDec(getDebugOutputStreamLogger(), "value=", value);
    }
}
BOOL sendStrategyOpponentRobotPosition(Point* opponentRobotPosition) {
	OutputStream* debugOutputStream = getOutputStreamLogger(INFO);
	appendString(debugOutputStream, "sendStrategyOpponentRobotPosition: ");

    OutputStream* outputStream = getDriverRequestOutputStream();

    append(outputStream, COMMAND_STRATEGY_SET_OPPONENT_ROBOT_POSITION);
    appendHex4(outputStream, opponentRobotPosition->x);
    appendSeparator(outputStream);
    appendHex4(outputStream, opponentRobotPosition->y);

	appendStringAndDec(debugOutputStream, " x=", opponentRobotPosition->x);
	appendStringAndDec(debugOutputStream, ", y=", opponentRobotPosition->y);
	println(debugOutputStream);

    BOOL result = transmitFromDriverRequestBuffer();

    return result;
}
void printGameTargetList(OutputStream* outputStream) {
    int i;
    int size = targets.size;
    println(outputStream);    
    appendStringAndDec(outputStream, "targetHandledCount:", targets.targetHandledCount);
    println(outputStream);
    for (i = 0; i < size; i++) {
        GameTarget* target = targets.targets[i];
        printGameTarget(outputStream, target, true);
    }
}
Beispiel #7
0
void printGameTarget(OutputStream* outputStream, GameTarget* target, BOOL includeItems) {
	appendString(outputStream, "target:");
	appendKeyAndName(outputStream, "name=", target->name);
	appendStringAndDecf(outputStream, ", gain=", target->gain);
	appendStringAndDec(outputStream, ", status=", target->status);
	// TODO : Point
	println(outputStream);
	
	if (includeItems) {
		printGameTargetActionList(outputStream, &(target->actionList));
	}
}
void printSerialLinkList(OutputStream* outputStream) {
    int size = getSerialLinkCount();
    appendStringAndDec(outputStream, "serialLinkCount=", size);
    int i;
	println(outputStream);
	printSerialLinkDebugHeader(outputStream);
    for (i = 0; i < size; i++) {
        SerialLink* serialLink = getSerialLink(i);
        printSerialLink(outputStream, serialLink, i);
    }
	appendTableHeaderSeparatorLine(outputStream);
}
void writeBSplineDefinition(OutputStream* outputStream, BSplineCurve* bSplineCurve) {
    writeBSplineControlPoints(outputStream, bSplineCurve, 1.0f);

    float curveLength = bSplineCurve->curveLength;
    appendStringAndDecf(outputStream, "\ncurve.length=", curveLength);
    appendString(outputStream, " mm\n");

    /*
    appendString(outputStream, "lastPointData:\n");
    writeBSplinePointData(outputStream, &(bSplineCurve->lastPointData));

    appendString(outputStream, "tempPointData:\n");
    writeBSplinePointData(outputStream, &(bSplineCurve->tempPointData));
    */

    appendStringAndDec(outputStream, "acc Factor:", bSplineCurve->accelerationFactor);
    println(outputStream);

    appendStringAndDec(outputStream, "Speed Factor:", bSplineCurve->speedFactor);
    println(outputStream);
}
Beispiel #10
0
void printTimer(OutputStream* outputStream, Timer* timer) {
	appendStringAndDec(outputStream, "Timer:code=", timer->timerCode);
	appendStringAndDec(outputStream, ",div=", timer->timeDiviser);
	appendStringAndDec(outputStream, ",time=", timer->time);
	appendStringAndDec(outputStream, ",timeInternalCounter=", timer->timeInternalCounter);
	appendStringAndDec(outputStream, ",markTime=", timer->markTime);

	appendStringAndDec(outputStream, ",enabled=", timer->enabled);
	appendStringAndDec(outputStream, ",working=", timer->working);
}
Beispiel #11
0
void printPosition(OutputStream* outputStream) {
    // clearScreen();
    appendCRLF(outputStream);
    Position* p = getPosition();
    appendStringAndDec(outputStream, "left=", getCoderValue(CODER_LEFT));
    appendStringAndDec(outputStream, " | right=", getCoderValue(CODER_RIGHT));
    println(outputStream);
    printPoint(outputStream, &(p->pos), " mm");

    appendStringAndAngleInDeg(outputStream, "ang:", p->orientation);
    appendStringAndAngleInDeg(outputStream, "\r\nang init:", p->initialOrientation);

    appendStringAndDecf(outputStream, "\r\nlastLeft:", lastLeft);
    appendString(outputStream, " pulse");

    appendStringAndDecf(outputStream, "\r\nlastRight:", lastRight);
    appendString(outputStream, " pulse");

    appendStringAndAngleInDeg(outputStream, "\r\nlastAng:", lastAngle);

    println(outputStream);
}
Beispiel #12
0
/**
 * Gets the position of the laser by triangulation of the information gived by the both laser.
 * If information is not correct, we give a position of (0, 0).
 */
Point* getOpponentRobotPosition() {
    Timer* beaconTimer = getTimerByCode(BEACON_TIMER_CODE);

    // we want to avoid that position change during compute
    lockAndWaitForTimer(beaconTimer);

    Laser* laser1 = getLaser(LASER_INDEX_1);
    Laser* laser2 = getLaser(LASER_INDEX_2);

    // Updates the detected Position of the laser
    int detectedPosition1 = updateDetectedPosition(laser1);
    int detectedPosition2 = updateDetectedPosition(laser2);

	Point* opponentRobotPosition = &(beaconSystem.opponentRobotPosition);

    // if there is a detected object (by both laser)
    if (detectedPosition1 != 0 && detectedPosition2 != 0) {
		// Too obsolete Information
		if (getLastDetectionTimeInMillis() > getObsoleteDetectionTimeThreshold()) {
	        opponentRobotPosition->x = 0;
	        opponentRobotPosition->y = 0;
			OutputStream* outputStream = getOutputStreamLogger(INFO);
			appendStringAndDec(outputStream, "LOST OBJECT SINCE=", getLastDetectionTimeInMillis());
			println(outputStream);
		}
		else {
	        float angleInRadian1 = getAngleInRadian(laser1);
	        float angleInRadian2 = getAngleInRadian(laser2);
	        float a1 = tan(angleInRadian1);
	        float a2 = tan(angleInRadian2);
			// Compute the position
	        fillPositionWithValues(opponentRobotPosition, beaconSystem.distanceBetweenBeacon, a1, a2);
		}
    } else {
		// Reset Robot Position
        opponentRobotPosition->x = 0;
        opponentRobotPosition->y = 0;
    }
    unlockTimer(beaconTimer);

    return opponentRobotPosition;
}
Beispiel #13
0
/**
 * @private.
 * Print Argument Or Result
 * @return the size of the argument
 */
unsigned int printArgument(OutputStream* outputStream, DeviceArgument* deviceArgument, int argumentIndex) {
    if (argumentIndex > 0) {
        appendString(outputStream, ARGUMENTS_SEPARATOR);
    }    
    char* argumentName = deviceArgument->name;
    char type = deviceArgument->type;
    unsigned int result = getLengthOfType(type);
    if (result == -1) {
        writeError(DEVICE_INTERFACE_PROBLEM);
        appendStringAndDec(outputStream, "type length Problem !!! : ", type);
    }

    printTypeAsString(outputStream, type);
   
    // Argument name
    append(outputStream, ARGUMENTS_NAME_AND_TYPE_SEPARATOR);
    appendString(outputStream, argumentName);
    
    return result;
}
Beispiel #14
0
void setColor(enum TeamColor color) {
    GameStrategyContext* context = getStrategyContext();

    appendStringAndDec(getInfoOutputStreamLogger(), "setColor:", color);
    println(getInfoOutputStreamLogger());

    context->color = color;
    changeLocationsForColor();
    int angle = 675;
    if (!isGreen()) {
        angle = -angle;
        context->robotPosition.y = 2840;
    }
    else {
        context->robotPosition.y = 160;
    }
    context->robotPosition.x = 160;

    context->robotAngle = angle;

    printStrategyAllDatas(getInfoOutputStreamLogger());
}
Beispiel #15
0
void setColor(TEAM_COLOR color) {
	GameStrategyContext* context = getStrategyContext();

	appendStringAndDec(getOutputStreamLogger(INFO), "setColor:", color);
	println(getOutputStreamLogger(INFO));

	context->color = color;
	changeLocationsForColor();
	int angle = 675;
	if (!isViolet()) {
		angle = -angle;
		context->robotPosition.y = 2840;
	}
	else {
		context->robotPosition.y = 160;
	}
	context->robotPosition.x = 160;

	context->robotAngle = angle;

	printStrategyAllDatas(getOutputStreamLogger(INFO));
}
void printGameStrategyContext(OutputStream* outputStream, GameStrategyContext* context) {
    appendString(outputStream, "GameStrategyContext\n");
    appendString(outputStream, "\tstrategy.name=");

    // gameStrategy
    if (context->gameStrategy != NULL) {
        appendString(outputStream, context->gameStrategy->name);
    }
    else {
        appendString(outputStream, "NULL");
    }

    // elapsedMatchTime
    appendStringAndDecf(outputStream, "\n\telapsedMatchTime=", context->elapsedMatchTime);
    println(outputStream);
    
    // Robot Position
    appendString(outputStream, "\trobotPosition=");
    printPoint(outputStream, &(context->robotPosition), "");
    appendStringAndDec(outputStream, "\n\trobotAngle (ddeg)=", context->robotAngle);

    // nearestLocation
    appendString(outputStream, "\n\tnearestLocation=");
    if (context->nearestLocation != NULL) {
        printLocation(outputStream, context->nearestLocation);
    }
    else {
        appendString(outputStream, "NULL");
    }

    appendStringAndDec(outputStream, "\ntimeSinceLastCollision=", context->timeSinceLastCollision);
    // Robot Position
    appendString(outputStream, "\n\topponentRobotPosition=");
    printPoint(outputStream, &(context->opponentRobotPosition), "");

    // Obstacle Position
    appendString(outputStream, "\n\tlastObstaclePosition=");
    printPoint(outputStream, &(context->lastObstaclePosition), "");

    // current Target
    appendString(outputStream, "\n\tcurrentTarget=");
    if (context->currentTarget != NULL) {
        printGameTarget(outputStream, context->currentTarget, false);
    }
    else {
        appendString(outputStream, "NULL");
    }

    // currentTrajectory
    if (&(context->currentTrajectory) != NULL) {
        printLocationList(outputStream, "\n\tcurrentTrajectory:", &(context->currentTrajectory));
    }
    else {
        appendString(outputStream, "\n\tcurrentTrajectory=NULL");
    }
    appendStringAndDec(outputStream, "\n\tteamColor=", context->color);
    appendStringAndDec(outputStream, "\n\tstrategyIndex=", context->strategyIndex);
    appendStringAndDec(outputStream, "\n\tmaxTargetToHandle=", context->maxTargetToHandle);

//    appendStringAndDec(outputStream, "\n\tmustDoNextStep=", context->mustDoNextStep);
    appendStringAndDec(outputStream, "\n\thasMoreNextSteps=", context->hasMoreNextSteps);

    println(outputStream);
}
Beispiel #17
0
/**
 * The interrupt demo timer.
 */
void interruptDemoTimerCallbackFunc(Timer* timer) {
    appendStringAndDec(getAlwaysOutputStreamLogger(), "counter=", demoCounter);
    appendCRLF(getAlwaysOutputStreamLogger());
    demoCounter++;
}
bool handleStreamInstruction(Buffer* inputBuffer,
                            Buffer* outputBuffer,
                            OutputStream* outputStream,
                            filterCharFunction* inputFilterChar,
                            filterCharFunction* outputFilterChar) {

    if (inputBuffer == NULL) {
        writeError(DRIVER_STREAM_LISTENER_INPUT_BUFFER_NULL);
        return false;
    }
    if (outputBuffer == NULL) {
        writeError(DRIVER_STREAM_LISTENER_OUTPUT_BUFFER_NULL);
        return false;
    }

    // Try to clear the buffer if needed ('z' char)
    if (clearBufferIfNeeded(inputBuffer)) {
        return false;
    }

    // We received data
    int inputBufferCount = getBufferElementsCount(inputBuffer);

    if (inputBufferCount > 0) {

        if (filterFirstNextChar(inputBuffer, inputFilterChar)) {
            return false;
        }

        // As there is clear of char filtering, we must reload the size of the buffer
        int bufferSize = getBufferElementsCount(inputBuffer);

        if (bufferSize < DEVICE_HEADER_LENGTH) {
            return false;
        }

        // Get the header
        unsigned char deviceHeader = bufferGetCharAtIndex(inputBuffer, DEVICE_HEADER_INDEX);

        // Manage the dispatcher specifier (3 chars : Ex j01 before real command ...)
        unsigned char specifyDispatcherLength = 0;
        if (deviceHeader == DATA_DISPATCHER_DEVICE_HEADER) {
            specifyDispatcherLength += DISPATCHER_COMMAND_AND_INDEX_HEADER_LENGTH;
        }

        // Check if enough data
        if (bufferSize < specifyDispatcherLength + DEVICE_AND_COMMAND_HEADER_LENGTH) {
            return false;
        }

        // Reload the deviceHeader to take the dispatcher specifier if any
        deviceHeader = bufferGetCharAtIndex(inputBuffer, specifyDispatcherLength + DEVICE_HEADER_INDEX);
        unsigned char commandHeader = bufferGetCharAtIndex(inputBuffer, specifyDispatcherLength + COMMAND_HEADER_INDEX);

        // find the device corresponding to this header. It must at least be declared in local or in remote !
        unsigned char dataSize = bufferSize - specifyDispatcherLength;
        const Device* device = deviceDataDispatcherFindDevice(deviceHeader, commandHeader, dataSize, DEVICE_MODE_INPUT);

        // if the device was not found
        if (device == NULL) {
            return false;
        }

        // At this moment, device Interface is found
        DeviceInterface* deviceInterface = device->deviceInterface;

        // We must send device specifyDispatcherLength + Header + commandHeader + data => + 2
        int dataToTransferCount = deviceInterface->deviceGetInterface(commandHeader, DEVICE_MODE_INPUT, false) + specifyDispatcherLength + DEVICE_AND_COMMAND_HEADER_LENGTH;

        if (bufferSize < dataToTransferCount) {
            return false;
        }

        // We must receive ack + device header + command header + data => + 3
        int dataToReceiveCount = deviceInterface->deviceGetInterface(commandHeader, DEVICE_MODE_OUTPUT, false) + ACK_LENGTH + DEVICE_AND_COMMAND_HEADER_LENGTH;

        InputStream* bufferedInputStream = getInputStream(inputBuffer);
        OutputStream* bufferedOutputStream = getOutputStream(outputBuffer);

        TransmitMode transmitMode = device->transmitMode;

        // we handle locally the request
        if (specifyDispatcherLength == 0 && transmitMode == TRANSMIT_LOCAL) {

            // We need the implementation for local mode
            DeviceDescriptor* deviceDescriptor = device->descriptor;
            if (deviceDescriptor == NULL) {
                writeError(NO_DEVICE_DESC_FOUND_FOR);
                append(getErrorOutputStreamLogger(), deviceHeader);
                append(getErrorOutputStreamLogger(), commandHeader);
                return false;
            }

            // remove the first chars corresponding to the device header and command Header
            bufferClearLastChars(inputBuffer, DEVICE_AND_COMMAND_HEADER_LENGTH);

            // Call to the device
            deviceDescriptor->deviceHandleRawData(commandHeader, bufferedInputStream, bufferedOutputStream);

        } // we forward the request through Remote Operation with Dispatcher
        else if (specifyDispatcherLength > 0 || transmitMode == TRANSMIT_I2C || transmitMode == TRANSMIT_UART || transmitMode == TRANSMIT_ZIGBEE) {

            // Find dispatcher
            DriverDataDispatcher* dispatcher = NULL;

            if (specifyDispatcherLength > 0) {
                bufferClearLastChars(inputBuffer, DEVICE_HEADER_LENGTH);
                unsigned char dispatcherIndex = readHex2(bufferedInputStream);

                dispatcher = getDriverDataDispatcherByIndex(dispatcherIndex);
                if (dispatcher == NULL) {
                    writeError(NO_DISPATCHER_FOUND);
                    OutputStream* errorOutputStream = getErrorOutputStreamLogger();
                    appendStringAndDec(errorOutputStream, ", dispatcherIndex=", dispatcherIndex);
                    return false;
                }
            }
            else {
                TransmitMode transmitMode = device->transmitMode;
                int address = device->address;

                dispatcher = getDriverDataDispatcherByTransmitMode(transmitMode, address);
                
                if (dispatcher == NULL) {
                    writeError(NO_DISPATCHER_FOUND);
                    OutputStream* errorOutputStream = getErrorOutputStreamLogger();
                    appendStringAndDec(errorOutputStream, ", transmitMode=", transmitMode);
                    append(errorOutputStream, '(');
                    appendString(errorOutputStream, getTransmitModeAsString(transmitMode));
                    append(errorOutputStream, ')');
                    appendStringAndDec(errorOutputStream, ", addr=", address);
                    return false;
                }
            }

            // copy Driver buffer with remote Call
            dispatcher->driverDataDispatcherTransmitData(dispatcher,
                    inputBuffer,
                    outputBuffer,
                    dataToTransferCount,
                    dataToReceiveCount
                    );
        }
        
        // In All Cases (Local / I2C / UART / Zigbee ...)

        // Copy the data from bufferOutputStream to the outputStream
        if (outputStream != NULL) {
            copyInputToOutputStream(&(outputBuffer->inputStream), outputStream, outputFilterChar, dataToReceiveCount);
        }
        return true;
    }
    return false;
}
Beispiel #19
0
/**
 * @private
 * @return true if it's ok, false if there is an error
 */
bool printMethodOrNotificationMetaData(OutputStream* outputStream, DeviceInterface* deviceInterface, char commandHeader, char argumentLength, char resultLength, bool notification) {
    bool result = true;
    if (argumentLength != DEVICE_HEADER_NOT_HANDLED) {
        DeviceMethodMetaData* deviceMethodMetaData = getDeviceMethodMetaData();
        char deviceHeader = deviceInterface->deviceHeader;

        // DeviceName
        const char* deviceName = deviceInterface->deviceGetName();
        appendString(outputStream, deviceName);
        append(outputStream, DEVICE_NAME_AND_HEADER_SEPARATOR);

        // Header
        append(outputStream, deviceHeader);
        append(outputStream, commandHeader);
        append(outputStream, DEVICE_HEADER_AND_TYPE_SEPARATOR);

        // functionName
        appendString(outputStream, deviceMethodMetaData->functionName);
        append(outputStream,  ARGUMENTS_START_CHAR);

        // arguments
        int argumentCount = deviceMethodMetaData->argumentsSize;
        int argumentIndex;
        int realArgumentLength = 0;
        for (argumentIndex = 0; argumentIndex < argumentCount; argumentIndex++) {
            DeviceArgument deviceArgument = deviceMethodMetaData->arguments[argumentIndex];
            realArgumentLength += printArgument(outputStream, &deviceArgument, argumentIndex);
        }
        append(outputStream,  ARGUMENTS_STOP_CHAR);

        if (argumentLength != realArgumentLength) {
            writeError(DEVICE_INTERFACE_PROBLEM);
            result = false;
            appendString(outputStream, "Arguments Definition ERROR !!!!!!\n");
            appendCRLF(outputStream);
            appendStringAndDec(outputStream, "argumentCount=", argumentCount);
            appendCRLF(outputStream);
            appendStringAndDec(outputStream, "argumentLength=", argumentLength);
            appendCRLF(outputStream);
            appendStringAndDec(outputStream, "realArgumentLength=", realArgumentLength);
            appendCRLF(outputStream);
        }

        // results
        if (!notification) {
            appendString(outputStream, ARGUMENTS_AND_RESULTS_SEPARATOR);
            append(outputStream,  ARGUMENTS_START_CHAR);
            int resultCount = deviceMethodMetaData->resultsSize;
            int realResultLength = 0;
            int resultIndex;
            for (resultIndex = 0; resultIndex < resultCount; resultIndex++) {
                DeviceArgument resultArgument = deviceMethodMetaData->results[resultIndex];
                realResultLength += printArgument(outputStream, &resultArgument, resultIndex);
            }

            if (resultLength != realResultLength) {
                result = false;
                writeError(DEVICE_INTERFACE_PROBLEM);
                appendString(outputStream, "Result Parameters Definition ERROR !!!!!!");
                appendCRLF(outputStream);
                appendStringAndDec(outputStream, "resultCount=", resultCount);
                appendCRLF(outputStream);
                appendStringAndDec(outputStream, "resultLength=", resultLength);
                appendCRLF(outputStream);
                appendStringAndDec(outputStream, "realResultLength=", realResultLength);
                appendCRLF(outputStream);
            }

            if (resultCount == 0) {
                appendString(outputStream, "void");
            }
        }
        append(outputStream,  ARGUMENTS_STOP_CHAR);
        appendString(outputStream, ":");
        appendDec(outputStream, argumentLength);
        appendString(outputStream, "=>");
        appendDec(outputStream, resultLength);
        println(outputStream);
    }
    return result;
}
Beispiel #20
0
/**
 * @private
 * @return true if it's ok, false if there is an error
 */
bool printMethodOrNotificationMetaData(OutputStream* outputStream, DeviceInterface* deviceInterface, unsigned char commandHeader, char argumentLength, char resultLength, bool notification) {
    bool result = true;
    if (argumentLength != DEVICE_HEADER_NOT_HANDLED) {
        DeviceMethodMetaData* deviceMethodMetaData = getDeviceMethodMetaData();

        // Function Header
		appendCharTableData(outputStream, commandHeader, DEVICE_USAGE_HEADER_COLUMN_LENGTH);

        // functionName
		const char* functionName = deviceMethodMetaData->functionName;
		appendStringTableData(outputStream, functionName, DEVICE_USAGE_NAME_COLUMN_LENGTH);

        // arguments
		appendStringTableData(outputStream, "IN", DEVICE_USAGE_IO_COLUMN_LENGTH);
		int argumentCount = deviceMethodMetaData->argumentsSize;
		int argumentIndex;
		int realArgumentLength = 0;
		for (argumentIndex = 0; argumentIndex < argumentCount; argumentIndex++) {
			DeviceArgument deviceArgument = deviceMethodMetaData->arguments[argumentIndex];
			realArgumentLength += getLengthOfType(deviceArgument.type);
		}
		appendDecTableData(outputStream, realArgumentLength, DEVICE_USAGE_IO_SIZE_COLUMN_LENGTH);

		// param name empty
		appendStringTableData(outputStream, "", DEVICE_USAGE_PARAM_NAME_COLUMN_LENGTH);
		appendStringTableData(outputStream, "", DEVICE_USAGE_PARAM_SIZE_COLUMN_LENGTH);
		appendStringTableData(outputStream, "", DEVICE_USAGE_PARAM_TYPE_COLUMN_LENGTH);
		appendTableSeparator(outputStream);
		println(outputStream);

		for (argumentIndex = 0; argumentIndex < argumentCount; argumentIndex++) {
			DeviceArgument deviceArgument = deviceMethodMetaData->arguments[argumentIndex];
			printArgument(outputStream, &deviceArgument, argumentIndex);
		}
		// TODO : Error must be check at the beginning of the function and not Inside
        if (argumentLength != realArgumentLength) {
            writeError(DEVICE_INTERFACE_PROBLEM);
            result = false;
            appendStringLN(outputStream, "Arguments Definition ERROR !!!!!!");
            println(outputStream);
            appendStringAndDec(outputStream, "argumentCount=", argumentCount);
            println(outputStream);
            appendStringAndDec(outputStream, "argumentLength=", argumentLength);
            println(outputStream);
            appendStringAndDec(outputStream, "realArgumentLength=", realArgumentLength);
            println(outputStream);
        }
        // results
        if (!notification) {

			appendStringTableData(outputStream, "", DEVICE_USAGE_HEADER_COLUMN_LENGTH);
			appendStringTableData(outputStream, "", DEVICE_USAGE_NAME_COLUMN_LENGTH);
			appendStringTableData(outputStream, "OUT", DEVICE_USAGE_IO_COLUMN_LENGTH);

			int resultCount = deviceMethodMetaData->resultsSize;
			int realResultLength = 0;
			int resultIndex;
			for (resultIndex = 0; resultIndex < resultCount; resultIndex++) {
				DeviceArgument resultArgument = deviceMethodMetaData->results[resultIndex];
				realResultLength += getLengthOfType(resultArgument.type);
			}
			appendDecTableData(outputStream, realResultLength, DEVICE_USAGE_IO_SIZE_COLUMN_LENGTH);

			appendStringTableData(outputStream, "", DEVICE_USAGE_PARAM_NAME_COLUMN_LENGTH);
			appendStringTableData(outputStream, "", DEVICE_USAGE_PARAM_SIZE_COLUMN_LENGTH);
			appendStringTableData(outputStream, "", DEVICE_USAGE_PARAM_TYPE_COLUMN_LENGTH);
			appendTableSeparator(outputStream);
			println(outputStream);

            for (resultIndex = 0; resultIndex < resultCount; resultIndex++) {
                DeviceArgument resultArgument = deviceMethodMetaData->results[resultIndex];
                printArgument(outputStream, &resultArgument, resultIndex);
            }
            if (resultLength != realResultLength) {
                result = false;
                writeError(DEVICE_INTERFACE_PROBLEM);
                appendString(outputStream, "Result Parameters Definition ERROR !!!!!!");
                appendCRLF(outputStream);
                appendStringAndDec(outputStream, "resultCount=", resultCount);
                appendCRLF(outputStream);
                appendStringAndDec(outputStream, "resultLength=", resultLength);
                appendCRLF(outputStream);
                appendStringAndDec(outputStream, "realResultLength=", realResultLength);
                appendCRLF(outputStream);
            }
        }
		appendTableHeaderSeparatorLine(outputStream);
    }
    return result;
}