void mainBoardDeviceHandleMotionDeviceNotification(const Device* device, const unsigned char commandHeader, InputStream* notificationInputStream) {
    if (device->deviceInterface->deviceHeader == MOTION_DEVICE_HEADER) {
        if (
                commandHeader == NOTIFY_MOTION_STATUS_FAILED
                || commandHeader == NOTIFY_MOTION_STATUS_MOVING
                || commandHeader == NOTIFY_MOTION_STATUS_OBSTACLE
                || commandHeader == NOTIFY_MOTION_STATUS_REACHED
                || commandHeader == NOTIFY_MOTION_STATUS_BLOCKED
                || commandHeader == NOTIFY_MOTION_STATUS_SHOCKED) {
            updateNewPositionFromNotification(notificationInputStream);
            // FAKE DATA To Align with TrajectoryDevice
            checkIsSeparator(notificationInputStream);
            checkIsChar(notificationInputStream, 'F');
            
            gameStrategyContext->trajectoryType = TRAJECTORY_TYPE_NONE;
            
            appendStringCRLF(getDebugOutputStreamLogger(), "Motion Device Notification !");

        }
        else {
            writeError(NOTIFICATION_BAD_DEVICE_COMMAND_HANDLER_NOT_HANDLE);
            appendString(getAlwaysOutputStreamLogger(), "header");
            append(getAlwaysOutputStreamLogger(), commandHeader);
            println(getAlwaysOutputStreamLogger());
        }
    }
    else {
        writeError(NOTIFICATION_BAD_DEVICE);
    }
}
bool transmitFromDriverRequestBuffer() {
    // Handle redirection
    if (redirectFunction != NULL) {
        bool result = redirectFunction();
        return result;
    }
    // We do exactly as if the data was written by a end-user
    // requestBuffer must be filled before calling this method
    Buffer* requestBuffer = getDriverRequestBuffer();
    Buffer* responseBuffer = getDriverResponseBuffer();

    InputStream* inputStream = getDriverResponseInputStream();
    if (inputStream == NULL) {
        writeError(DRIVER_INPUT_STREAM_NULL);
        return false;
    }

    // The first char is the device header
    unsigned dataDispacherLength = 0;
    unsigned char deviceHeader = bufferGetCharAtIndex(requestBuffer, DEVICE_HEADER_INDEX);

    if (deviceHeader == DISPATCHER_COMMAND_HEADER) {
        dataDispacherLength = DISPATCHER_COMMAND_AND_INDEX_HEADER_LENGTH;
        // Reload the real Device Header
        deviceHeader = bufferGetCharAtIndex(requestBuffer, dataDispacherLength + DEVICE_HEADER_INDEX);
    }

    // The second char is the command header
    unsigned char commandHeader = bufferGetCharAtIndex(requestBuffer, dataDispacherLength + COMMAND_HEADER_INDEX);

    bool result = handleStreamInstruction(
            requestBuffer,
            responseBuffer,
            // Don't copy to an outputStream, because, we
            // want to read the content of responseBuffer
            NULL,
            // TODO : Check why we don't provide any NotificationOutputStream
            NULL,
            // No Input Filter
            NULL,
            // No Output Filter
            NULL);

    // We need ack
    result = checkIsAck(inputStream);
    if (!result) {
        // The buffer is corrupted, but we would like to avoid further problem
        clearInputStream(inputStream);
        return false;
    }
    // Device header answer with the same header as the request
    checkIsChar(inputStream, deviceHeader);
    if (!result) {
        // The buffer is corrupted, but we would like to avoid further problem
        clearInputStream(inputStream);
        return false;
    }
    // Command header answer with the same header as the request
    checkIsChar(inputStream, commandHeader);
    if (!result) {
        // The buffer is corrupted, but we would like to avoid further problem
        clearInputStream(inputStream);
        return false;
    }

    return result;
}
示例#3
0
bool checkIsSeparator(InputStream* inputStream) {
    return checkIsChar(inputStream, '-');
}