MCPcopy Create free account
hub / github.com/BlitterStudio/amiberry / readData

Method readData

external/floppybridge/src/ArduinoInterface.cpp:988–1181  ·  view source on GitHub ↗

Reads just enough data to fulfill most extractions needed, but doesnt care about rotation position or index - pll should have the LinearExtractor configured

Source from the content-addressed store, hash-verified

986
987// Reads just enough data to fulfill most extractions needed, but doesnt care about rotation position or index - pll should have the LinearExtractor configured
988DiagnosticResponse ArduinoInterface::readData(PLL::BridgePLL& pll) {
989 pll.rotationExtractor()->reset(m_isHDMode);
990 LinearExtractor* linearExtractor = dynamic_cast<LinearExtractor*>(pll.rotationExtractor());
991 if (!linearExtractor) return DiagnosticResponse::drError;
992
993 if (!m_tempBuffer) {
994 m_tempBuffer = malloc(RAW_TRACKDATA_LENGTH_HD);
995 if (!m_tempBuffer) return DiagnosticResponse::drError;
996 }
997
998 const uint32_t sizeRequired = m_isHDMode ? RAW_TRACKDATA_LENGTH_HD : RAW_TRACKDATA_LENGTH_DD;
999 DiagnosticResponse response = readCurrentTrack(m_tempBuffer, sizeRequired, false);
1000 if (response != DiagnosticResponse::drOK) return response;
1001 linearExtractor->copyToBuffer(m_tempBuffer, sizeRequired);
1002 return response;
1003
1004 m_lastCommand = LastCommand::lcReadTrackStream;
1005
1006 if (m_version.major == 1 && m_version.minor < 8) {
1007 m_lastError = DiagnosticResponse::drOldFirmware;
1008 return m_lastError;
1009 }
1010
1011 const bool highPrecisionMode = !m_isHDMode && m_version.deviceFlags1 & FLAGS_HIGH_PRECISION_SUPPORT;
1012 char mode = highPrecisionMode ? COMMAND_READTRACKSTREAM_HIGHPRECISION : COMMAND_READTRACKSTREAM;
1013
1014 if (mode == COMMAND_READTRACKSTREAM_HIGHPRECISION && m_version.deviceFlags1 & FLAGS_FLUX_READ) mode = COMMAND_READTRACKSTREAM_HALFPLL;
1015 m_lastError = runCommand(mode);
1016 if (m_lastError != DiagnosticResponse::drOK) return m_lastError;
1017 m_isStreaming = true;
1018
1019 applyCommTimeouts(true);
1020 unsigned char tempReadBuffer[4096] = { 0 };
1021
1022 // Let the class know we're doing some streaming stuff
1023 m_abortStreaming = false;
1024 m_abortSignalled = false;
1025
1026 // Number of times we failed to read anything
1027 int32_t readFail = 0;
1028
1029 // Sliding window for abort
1030 char slidingWindow[5] = { 0,0,0,0,0 };
1031 bool timeout = false;
1032 bool dataState = false;
1033 bool isFirstByte = true;
1034 unsigned char mfmSequences = 0;
1035
1036 MFMExtractionTarget* extractor = pll.rotationExtractor();
1037
1038 for (;;) {
1039
1040 // More efficient to read several bytes in one go
1041 unsigned int bytesAvailable = m_comPort.getBytesWaiting();
1042 if (bytesAvailable < 1) bytesAvailable = 1;
1043 if (bytesAvailable > sizeof tempReadBuffer) bytesAvailable = sizeof tempReadBuffer;
1044 unsigned int bytesRead = m_comPort.read(tempReadBuffer, bytesAvailable);
1045 for (size_t a = 0; a < bytesRead; a++) {

Callers

nothing calls this directly

Calls 9

rotationExtractorMethod · 0.80
copyToBufferMethod · 0.80
getBytesWaitingMethod · 0.80
purgeBuffersMethod · 0.80
submitSequenceMethod · 0.80
resetMethod · 0.45
readMethod · 0.45
canExtractMethod · 0.45
totalTimeReceivedMethod · 0.45

Tested by

no test coverage detected