Skip to content

MockSpi.transfer() doesn't allow the tester to provide mock data #298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MMMMMNG opened this issue Oct 6, 2023 · 0 comments
Closed

MockSpi.transfer() doesn't allow the tester to provide mock data #298

MMMMMNG opened this issue Oct 6, 2023 · 0 comments

Comments

@MMMMMNG
Copy link
Contributor

MMMMMNG commented Oct 6, 2023

https://github.com/Pi4J/pi4j-v2/blob/8d8f1574f926dfd2961356cf015dcbd58e50664e/plugins/pi4j-plugin-mock/src/main/java/com/pi4j/plugin/mock/provider/spi/MockSpi.java#L84

The current implementation of MockSpi.transfer() doesn't read or write to the data buffer. That makes it impossible for the tester to provide mock data.
For reference, the current implementation:

    @Override
    public int transfer(byte[] write, int writeOffset, byte[] read, int readOffset, int numberOfBytes) {
        int readIndex = readOffset;
        // simply just echo out the write data back to the read buffer            <<<<<<<<<<-- that's the problem -MNG
        for(int n = writeOffset; n < numberOfBytes - writeOffset; n++){
            read[readIndex] = write[n];
            readIndex++;
        }
        // return number of byte returned
        return readIndex - readOffset;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant