Reads just enough data to fulfill most extractions needed, but doesnt care about rotation position or index - pll should have the LinearExtractor configured
| 921 | |
| 922 | // Reads just enough data to fulfill most extractions needed, but doesnt care about rotation position or index - pll should have the LinearExtractor configured |
| 923 | SCPErr SCPInterface::readData(PLL::BridgePLL& pll) { |
| 924 | SCPResponse response; |
| 925 | |
| 926 | pll.rotationExtractor()->reset(m_isHDMode); |
| 927 | |
| 928 | // Issue a read-request |
| 929 | selectDrive(true); |
| 930 | |
| 931 | // Request real-time flux stream, 8-bit resolution, and 50ns timings. |
| 932 | const unsigned char payload[1] = { STREAMFLAGS_RESOLUTION_50NS | FLAGS_BITSIZE_8BIT | STREAMFLAGS_IMMEDIATEREAD | STREAMFLAGS_RAWFLUX }; |
| 933 | bool ret = sendCommand(SCPCommand::DoCMD_STARTSTREAM, payload, 1, response); |
| 934 | if (!ret) { |
| 935 | if (!m_motorIsEnabled) selectDrive(false); |
| 936 | if ((response == SCPResponse::pr_NotReady) || (response == SCPResponse::pr_NoDisk)) { |
| 937 | m_diskInDrive = false; |
| 938 | return SCPErr::scpNoDiskInDrive; |
| 939 | } |
| 940 | return SCPErr::scpUnknownError; |
| 941 | } |
| 942 | |
| 943 | applyCommTimeouts(true); |
| 944 | unsigned char tempReadBuffer[4096] = { 0 }; |
| 945 | |
| 946 | m_isStreaming = true; |
| 947 | m_abortStreaming = false; |
| 948 | m_abortSignalled = false; |
| 949 | |
| 950 | // Number of times we failed to read anything |
| 951 | int readFail = 0; |
| 952 | |
| 953 | // Sliding window for abort |
| 954 | unsigned char slidingWindow[4] = { 0,0,0,0 }; |
| 955 | bool timeout = false; |
| 956 | bool dataState = false; |
| 957 | bool isFirstByte = true; |
| 958 | unsigned char mfmSequences = 0; |
| 959 | int hitIndex = 0; |
| 960 | uint32_t tickInNS = 0; |
| 961 | |
| 962 | for (;;) { |
| 963 | |
| 964 | // More efficient to read several bytes in one go |
| 965 | unsigned int bytesAvailable = m_comPort.getBytesWaiting(); |
| 966 | if (bytesAvailable < 1) bytesAvailable = 1; |
| 967 | if (bytesAvailable > sizeof(tempReadBuffer)) bytesAvailable = sizeof(tempReadBuffer); |
| 968 | unsigned int bytesRead = m_comPort.read(tempReadBuffer, m_abortSignalled ? 1 : bytesAvailable); |
| 969 | for (size_t a = 0; a < bytesRead; a++) { |
| 970 | const unsigned char byteRead = tempReadBuffer[a]; |
| 971 | |
| 972 | if (m_abortSignalled) { |
| 973 | for (int s = 0; s < 3; s++) slidingWindow[s] = slidingWindow[s + 1]; |
| 974 | slidingWindow[3] = byteRead; |
| 975 | |
| 976 | // Watch the sliding window for the pattern we need |
| 977 | if ((slidingWindow[0] == 0xDE) && (slidingWindow[1] == 0xAD) && (slidingWindow[2] == (unsigned char)SCPCommand::DoCMD_STOPSTREAM)) { |
| 978 | m_isStreaming = false; |
| 979 | m_comPort.purgeBuffers(); |
| 980 | applyCommTimeouts(false); |
nothing calls this directly
no test coverage detected