Skip to content

Commit 56ddaba

Browse files
committed
Improved diagnostics
1 parent 739f5d2 commit 56ddaba

File tree

6 files changed

+169
-26
lines changed

6 files changed

+169
-26
lines changed

ArduinoFloppyReader/ArduinoFloppyReader/Main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ int wmain(int argc, wchar_t* argv[], wchar_t *envp[])
245245
int main(int argc, char* argv[], char *envp[])
246246
#endif
247247
{
248-
printf("Arduino Amiga ADF & SCP Floppy Disk Reader/Writer V2.5, Copyright (C) 2017-2021 Robert Smith\r\n");
248+
printf("Arduino Amiga ADF & SCP Floppy Disk Reader/Writer V2.6, Copyright (C) 2017-2021 Robert Smith\r\n");
249249
printf("Full sourcecode and documentation at https://amiga.robsmithdev.co.uk\r\n");
250250
printf("This is free software licenced under the GNU General Public Licence V3\r\n\r\n");
251251

Binary file not shown.

ArduinoFloppyReader/ArduinoFloppyReaderWin/ArduinoFloppyReaderWinDlg.h

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "afxwin.h"
2626
#include "afxcmn.h"
2727
#include <thread>
28+
#include <string>
2829

2930

3031
// CArduinoFloppyReaderWinDlg dialog

ArduinoFloppyReader/lib/ADFWriter.cpp

+123-24
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ bool ADFWriter::runDiagnostics(const std::wstring& portName, std::function<void(
514514
if (!messageOutput) return false;
515515
if (!askQuestion) return false;
516516

517-
if (!askQuestion(false, "Please insert a disk in the drive.\r\nUse a disk that you don't mind being erased.\nThis disk must contain data/formatted as an AmigaDOS disk")) {
517+
if (!askQuestion(false, "Please insert a *write protected* disk in the drive.\r\nUse a disk that you don't mind being erased.\nThis disk must contain data/formatted as an AmigaDOS disk")) {
518518
messageOutput(true, "Diagnostics aborted");
519519
return false;
520520
}
@@ -596,6 +596,20 @@ bool ADFWriter::runDiagnostics(const std::wstring& portName, std::function<void(
596596
messageOutput(false, "Read speed test passed. USB to serial converter is functioning correctly!");
597597
}
598598

599+
600+
if ((version.major > 1) || ((version.major == 1) && (version.minor >= 8))) {
601+
messageOutput(false, "Testing write-protect signal");
602+
for (;;) {
603+
604+
if (m_device.checkIfDiskIsWriteProtected(true) == DiagnosticResponse::drWriteProtected) break;
605+
606+
if (!askQuestion(false, "Inserted disk is not write protected. If it is, then check Arduino Pin A0. Please insert a write protected AmigaDOS disk in the drive")) {
607+
messageOutput(true, "Diagnostics aborted");
608+
return false;
609+
}
610+
}
611+
}
612+
599613
// Functions to test
600614
messageOutput(false, "Enabling the drive (please listen and watch the drive)");
601615
r = m_device.enableReading(true, false);
@@ -691,21 +705,7 @@ bool ADFWriter::runDiagnostics(const std::wstring& portName, std::function<void(
691705
if (r != DiagnosticResponse::drOK) {
692706
messageOutput(true, m_device.getLastErrorStr());
693707
return false;
694-
}
695-
696-
for (;;) {
697-
if (!askQuestion(false, "Please insert a write protected AmigaDOS disk in the drive")) {
698-
messageOutput(true, "Diagnostics aborted");
699-
return false;
700-
}
701-
702-
if ((version.major > 1) || ((version.major == 1) && (version.minor >= 8))) {
703-
if (m_device.checkIfDiskIsWriteProtected(true) == DiagnosticResponse::drWriteProtected) break;
704-
messageOutput(true, "Disk is not write protected.");
705-
messageOutput(true, "If it is, then check Arduin Pin A0");
706-
return false;
707-
}
708-
}
708+
}
709709

710710
messageOutput(false, "Starting drive, and seeking to track 40.");
711711
// Re-open the drive
@@ -838,7 +838,7 @@ bool ADFWriter::runDiagnostics(const std::wstring& portName, std::function<void(
838838
}
839839

840840
// Now ask.
841-
if (!askQuestion(true,"Would you like to test writing to a disk? (please ensure the disk inserted is not important as data will be erased)")) {
841+
if (!askQuestion(true,"Would you like to test writing to a disk? Please insert a WRITE ENABLED disk that you *do not mind* being overwritten")) {
842842
messageOutput(true, "Diagnostic aborted.");
843843
return false;
844844
}
@@ -860,6 +860,19 @@ bool ADFWriter::runDiagnostics(const std::wstring& portName, std::function<void(
860860

861861
} while (r == DiagnosticResponse::drWriteProtected);
862862
// Writing is enabled.
863+
864+
if ((version.major > 1) || ((version.major == 1) && (version.minor >= 8))) {
865+
for (;;) {
866+
867+
if (m_device.checkIfDiskIsWriteProtected(true) == DiagnosticResponse::drOK) break;
868+
869+
if (!askQuestion(false, "Inserted disk is write protected. If it isn't, then check Arduino Pin A0. Please insert a write *enabled* disk in the drive")) {
870+
messageOutput(true, "Diagnostics aborted");
871+
return false;
872+
}
873+
}
874+
}
875+
863876

864877
// Goto 41, we'll write some stuff
865878
r = m_device.selectTrack(41);
@@ -895,19 +908,28 @@ bool ADFWriter::runDiagnostics(const std::wstring& portName, std::function<void(
895908
encodeSector(41, ArduinoFloppyReader::DiskSurface::dsUpper, sector, track[sector], disktrack.sectors[sector], lastByte);
896909
}
897910

898-
// Attempt to write 10 times, with verify
911+
// Attempt to write, with verify
899912
messageOutput(false, "Writing and Verifying Track 41 (Upper Side).");
900913
bool writtenOK = false;
901914
for (int a = 1; a <= 10; a++) {
902915

916+
r = m_device.eraseCurrentTrack();
917+
if (r != DiagnosticResponse::drOK) {
918+
messageOutput(true, m_device.getLastErrorStr());
919+
messageOutput(true, "This can also be caused by insufficient power to the drive");
920+
return false;
921+
}
922+
903923
r = m_device.writeCurrentTrack((const unsigned char*)(&disktrack), sizeof(disktrack), false);
904924
if (r != DiagnosticResponse::drOK) {
905925
messageOutput(true, m_device.getLastErrorStr());
926+
messageOutput(true, "This can also be caused by insufficient power to the drive");
906927
return false;
907928
}
908929
r = m_device.readCurrentTrack(data, false);
909930
if (r != DiagnosticResponse::drOK) {
910931
messageOutput(true, m_device.getLastErrorStr());
932+
messageOutput(true, "This can also be caused by insufficient power to the drive");
911933
return false;
912934
}
913935

@@ -944,29 +966,106 @@ bool ADFWriter::runDiagnostics(const std::wstring& portName, std::function<void(
944966
}
945967
if (writtenOK) break;
946968
}
969+
if (writtenOK) break;
947970
}
971+
if (writtenOK) break;
948972
}
949973

950974
// Final results
951975
if (!writtenOK) {
952976
messageOutput(true, "Unable to detect written track. This could be for one of the following reasons:");
953977
messageOutput(true, "1. Please check the following PINS on the Arduino: 3, A0, A1");
954-
messageOutput(true, "2. Please check the Ardiono IDE config has not been modified from stock. This was tested using 1.8.4, compiler settings may affect performance");
978+
messageOutput(true, "2. Please check the Arduino IDE config has not been modified from stock. This was tested using 1.8.4, compiler settings may affect performance");
955979
messageOutput(true, "3. Check for poor connections, typically on a breadboard they may be intermittent which may pass the above results but still not work.");
956980
messageOutput(true, "4. Check for an electrically noisy environment. It is possible that electronic noise (eg: from a cell phone) may cause errors reading and writing to the disk");
957981
messageOutput(true, "5. Shorten the floppy disk cable to help reduce noise.");
958-
messageOutput(true, "6. Ensure your power supply is strong enough to power the floppy drive. Don't rely on the USB port for the 5V for the floppy drive!");
982+
messageOutput(true, "6. Ensure your power supply is strong enough to power the floppy drive. This drive may need too much power for the USB port");
959983
messageOutput(true, "7. You can contact me for help, but some basic electronics diagnostics will help, checkout YouTube for guides.");
960984

961985
m_device.enableWriting(false);
962986
return false;
963987
}
964-
else {
965-
messageOutput(false, "Hurray! Writing was successful. Your Arduino is ready for use! - Send us a photo!");
988+
989+
// Attempt to write, with verify
990+
messageOutput(false, "Writing (Precomp) and Verifying Track 41 (Upper Side).");
991+
writtenOK = false;
992+
for (int a = 1; a <= 10; a++) {
993+
994+
r = m_device.eraseCurrentTrack();
995+
if (r != DiagnosticResponse::drOK) {
996+
messageOutput(true, m_device.getLastErrorStr());
997+
return false;
998+
}
999+
1000+
r = m_device.writeCurrentTrackPrecomp((const unsigned char*)(&disktrack), sizeof(disktrack), false, true);
1001+
if (r != DiagnosticResponse::drOK) {
1002+
messageOutput(true, m_device.getLastErrorStr());
1003+
return false;
1004+
}
1005+
r = m_device.readCurrentTrack(data, false);
1006+
if (r != DiagnosticResponse::drOK) {
1007+
messageOutput(true, m_device.getLastErrorStr());
1008+
return false;
1009+
}
1010+
1011+
// Data read. See if any tracks were detected
1012+
DecodedTrack trk;
1013+
findSectors(data, 41, ArduinoFloppyReader::DiskSurface::dsUpper, AMIGA_WORD_SYNC, trk, true);
1014+
// Have a look at any of the found sectors and see if any are valid and matched the phrase we wrote onto the disk
1015+
for (const DecodedSector& sec : trk.validSectors) {
1016+
// See if we can find the sequence in here somewhere
1017+
std::string s;
1018+
s.resize(SECTOR_BYTES);
1019+
memcpy(&s[0], sec.data, SECTOR_BYTES);
1020+
1021+
if (s.find(TEST_BYTE_SEQUENCE) != std::string::npos) {
1022+
// Excellent
1023+
writtenOK = true;
1024+
break;
1025+
}
1026+
}
1027+
if (!writtenOK) {
1028+
// See if we can find the sequence in one of the partial sectors
1029+
for (int sector = 0; sector < NUM_SECTORS_PER_TRACK; sector++) {
1030+
for (const DecodedSector& sec : trk.invalidSectors[sector]) {
1031+
// See if we can find the sequence in here somewhere
1032+
std::string s;
1033+
s.resize(SECTOR_BYTES);
1034+
memcpy(&s[0], sec.data, SECTOR_BYTES);
1035+
1036+
if (s.find(TEST_BYTE_SEQUENCE) != std::string::npos) {
1037+
// Excellent
1038+
writtenOK = true;
1039+
break;
1040+
}
1041+
}
1042+
if (writtenOK) break;
1043+
}
1044+
if (writtenOK) break;
1045+
}
1046+
if (writtenOK) break;
1047+
}
1048+
1049+
// Final results
1050+
if (!writtenOK) {
1051+
messageOutput(true, "Unable to detect written track. This could be for one of the following reasons:");
1052+
messageOutput(true, "1. Please check the following PINS on the Arduino: 3, A0, A1");
1053+
messageOutput(true, "2. Please check the Arduino IDE config has not been modified from stock. This was tested using 1.8.4, compiler settings may affect performance");
1054+
messageOutput(true, "3. Check for poor connections, typically on a breadboard they may be intermittent which may pass the above results but still not work.");
1055+
messageOutput(true, "4. Check for an electrically noisy environment. It is possible that electronic noise (eg: from a cell phone) may cause errors reading and writing to the disk");
1056+
messageOutput(true, "5. Shorten the floppy disk cable to help reduce electrical noise.");
1057+
messageOutput(true, "6. Ensure your power supply is strong enough to power the floppy drive. This drive may need too much power for the USB port");
1058+
messageOutput(true, "7. If you are using a USB hub, try connecting directly to the computer or a different USB port");
1059+
messageOutput(true, "8. You can contact me for help, but some basic electronics diagnostics will help, checkout YouTube for guides.");
1060+
9661061
m_device.enableWriting(false);
967-
return true;
1062+
return false;
9681063
}
969-
1064+
1065+
messageOutput(false, "Hurray! Writing was successful. Your Arduino is ready for use! - Send us a photo");
1066+
messageOutput(false, "or join my Discord server at https://discord.gg/HctVgSFEXu");
1067+
m_device.enableWriting(false);
1068+
return true;
9701069
}
9711070

9721071
// Get the current firmware version. Only valid if openPort is successful

ArduinoFloppyReader/lib/ArduinoInterface.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ using namespace ArduinoFloppyReader;
5252
#define COMMAND_WRITETRACK '>'
5353
#define COMMAND_ENABLEWRITE '~'
5454
#define COMMAND_DIAGNOSTICS '&'
55+
#define COMMAND_ERASETRACK 'X'
5556
#define COMMAND_SWITCHTO_DD 'D' // Requires Firmware V1.6
5657
#define COMMAND_SWITCHTO_HD 'H' // Requires Firmware V1.6
5758
#define COMMAND_DETECT_DISK_TYPE 'M' // currently not implemented here
@@ -85,6 +86,7 @@ std::string lastCommandToName(LastCommand cmd) {
8586
case LastCommand::lcReadTrackStream: return "ReadTrackStream";
8687
case LastCommand::lcCheckDiskInDrive: return "CheckDiskInDrive";
8788
case LastCommand::lcCheckDiskWriteProtected: return "CheckDiskWriteProtected";
89+
case LastCommand::lcEraseTrack: return "EraseTrack";
8890

8991
default: return "Unknown";
9092
}
@@ -739,6 +741,43 @@ DiagnosticResponse ArduinoInterface::selectTrack(const unsigned char trackIndex,
739741
return m_lastError;
740742
}
741743

744+
// Erases the current track by writing 0xAA to it
745+
DiagnosticResponse ArduinoInterface::eraseCurrentTrack() {
746+
m_lastError = runCommand(COMMAND_ERASETRACK);
747+
if (m_lastError != DiagnosticResponse::drOK) {
748+
m_lastCommand = LastCommand::lcEraseTrack;
749+
return m_lastError;
750+
}
751+
752+
char result;
753+
if (!deviceRead(&result, 1, true)) {
754+
m_lastCommand = LastCommand::lcEraseTrack;
755+
m_lastError = DiagnosticResponse::drReadResponseFailed;
756+
return m_lastError;
757+
}
758+
759+
if (result == 'N') {
760+
m_lastCommand = LastCommand::lcEraseTrack;
761+
m_lastError = DiagnosticResponse::drWriteProtected;
762+
return m_lastError;
763+
}
764+
765+
// Check result
766+
if (!deviceRead(&result, 1, true)) {
767+
m_lastCommand = LastCommand::lcEraseTrack;
768+
m_lastError = DiagnosticResponse::drReadResponseFailed;
769+
return m_lastError;
770+
}
771+
772+
if (result != '1') {
773+
m_lastCommand = LastCommand::lcEraseTrack;
774+
m_lastError = DiagnosticResponse::drError;
775+
return m_lastError;
776+
}
777+
778+
return m_lastError;
779+
}
780+
742781
// Choose which surface of the disk to read from
743782
DiagnosticResponse ArduinoInterface::selectSurface(const DiskSurface side) {
744783
m_lastError = runCommand((side == DiskSurface::dsUpper) ? COMMAND_HEAD0 : COMMAND_HEAD1);

ArduinoFloppyReader/lib/ArduinoInterface.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ namespace ArduinoFloppyReader {
109109
drDiagnosticNotAvailable,
110110
drUSBSerialBad,
111111
drCTSFailure,
112-
drRewindFailure,
112+
drRewindFailure
113113
};
114114

115115
enum class LastCommand {
@@ -128,6 +128,7 @@ namespace ArduinoFloppyReader {
128128
lcReadTrackStream,
129129
lcCheckDiskInDrive,
130130
lcCheckDiskWriteProtected,
131+
lcEraseTrack
131132
};
132133

133134
class ArduinoInterface {
@@ -246,6 +247,9 @@ namespace ArduinoFloppyReader {
246247
// The precomp version of the above.
247248
DiagnosticResponse writeCurrentTrackPrecomp(const unsigned char* mfmData, const unsigned short numBytes, const bool writeFromIndexPulse, bool usePrecomp);
248249

250+
// Erases the current track by writing 0xAA to it
251+
DiagnosticResponse eraseCurrentTrack();
252+
249253
// Check CTS status - you must open with CTS disabled for this to work
250254
DiagnosticResponse testCTS();
251255

0 commit comments

Comments
 (0)