11/* ArduinoFloppyReader (and writer)
22*
3- * Copyright (C) 2017 Robert Smith (@RobSmithDev)
3+ * Copyright (C) 2017-2018 Robert Smith (@RobSmithDev)
44* http://amiga.robsmithdev.co.uk
55*
66* This program is free software; you can redistribute it and/or
2525#include " stdafx.h"
2626#include < windows.h>
2727#include " ..\lib\ADFWriter.h"
28+ #include < conio.h>
2829
2930using namespace ArduinoFloppyReader ;
3031
3132ADFWriter writer;
3233
34+
3335// Read an ADF file and write it to disk
3436void adf2Disk (wchar_t * argv[], bool verify) {
3537 printf (" \n Write disk from ADF mode\n\n " );
@@ -58,7 +60,8 @@ void adf2Disk(wchar_t* argv[], bool verify) {
5860 case adfrCompletedWithErrors: printf (" \r ADF file written to disk but there were errors during verification " ); break ;
5961 case adfrAborted: printf (" \r Writing ADF file to disk " ); break ;
6062 case adfrFileError: printf (" \r Error opening ADF file. " ); break ;
61- case adfrDriveError: printf (" \r Error communicating with the Arduino interface. " ); break ;
63+ case adfrDriveError: printf (" \r Error communicating with the Arduino interface. " );
64+ printf (" \n %s " , writer.getLastError ().c_str ()); break ;
6265 case adfrDiskWriteProtected: printf (" \r Error, disk is write protected! " ); break ;
6366 }
6467}
@@ -90,22 +93,53 @@ void disk2ADF(wchar_t* argv[]) {
9093 case adfrFileError: printf (" \r Error creating ADF file. " ); break ;
9194 case adfrFileIOError: printf (" \r Error writing to ADF file. " ); break ;
9295 case adfrCompletedWithErrors: printf (" \r ADF file created with partial success. " ); break ;
93- case adfrDriveError: printf (" \r Error communicating with the Arduino interface. " ); break ;
96+ case adfrDriveError: printf (" \r Error communicating with the Arduino interface. " );
97+ printf (" \n %s " , writer.getLastError ().c_str ()); break ;
9498 }
9599}
96100
101+ // Run the diagnostics module
102+ void runDiagnostics (int comPort) {
103+ printf (" \r Running diagnostics on COM port: %i\n " ,comPort);
104+
105+ writer.runDiagnostics (comPort, [](bool isError, const std::string message)->void {
106+ if (isError)
107+ printf (" DIAGNOSTICS FAILED: %s\n " ,message.c_str ());
108+ else
109+ printf (" %s\n " , message.c_str ());
110+ }, [](bool isQuestion, const std::string question)->bool {
111+ if (isQuestion)
112+ printf (" %s [Y/N]: " , question.c_str ());
113+ else
114+ printf (" %s [Enter/ESC]: " , question.c_str ());
115+
116+ char c;
117+ do {
118+ c = _getch ();
119+ c=toupper (c);
120+ } while ((c != ' Y' ) && (c != ' N' ) && (c != ' \n ' ) && (c != ' \r ' ) && (c != ' \x1B ' ));
121+ printf (" %c\n " , c);
122+
123+ return (c == ' Y' ) || (c == ' \n ' ) || (c == ' \r ' ) || (c == ' \x1B ' );
124+ });
125+
126+ writer.closeDevice ();
127+ }
128+
97129int wmain (int argc, wchar_t * argv[], wchar_t *envp[])
98130{
99- printf (" Arduino Amiga ADF Floppy disk Reader/Writer, Copyright (C) 2017 Robert Smith\r\n " );
131+ printf (" Arduino Amiga ADF Floppy disk Reader/Writer, Copyright (C) 2017-2018 Robert Smith\r\n " );
100132 printf (" Full sourcecode and documentation at http://amiga.robsmithdev.co.uk\r\n " );
101133 printf (" This is free software licenced under the GNU General Public Licence V3\r\n\r\n " );
102134
103135 if (argc < 3 ) {
104136 printf (" Usage:\r\n\n " );
105137 printf (" To read a disk to an ADF file:\r\n " );
106- printf (" ArduinoFloppyReader COMPORT OutputFilename.ADF [READ]\r\n\r\n " );
138+ printf (" ArduinoFloppyReader < COMPORT> OutputFilename.ADF [READ]\r\n\r\n " );
107139 printf (" To write an ADF file to disk:\r\n " );
108- printf (" ArduinoFloppyReader COMPORT InputFilename.ADF WRITE [VERIFY]\r\n\r\n " );
140+ printf (" ArduinoFloppyReader <COMPORT> InputFilename.ADF WRITE [VERIFY]\r\n\r\n " );
141+ printf (" To start interface diagnostics:\r\n " );
142+ printf (" ArduinoFloppyReader DIAGNOSTIC <COMPORT>\r\n\r\n " );
109143 return 0 ;
110144 }
111145
@@ -120,12 +154,22 @@ int wmain(int argc, wchar_t* argv[], wchar_t *envp[])
120154 verify = wcscmp (argv[4 ], L" VERIFY" ) == 0 ;
121155 }
122156
123- writer.openDevice (_wtoi (argv[1 ]));
157+ _wcsupr (argv[1 ]);
158+ if (wcscmp (argv[1 ], L" DIAGNOSTIC" ) == 0 ) {
159+ runDiagnostics (_wtoi (argv[2 ]));
160+ }
161+ else {
124162
125- if (writeMode) adf2Disk (argv,verify); else disk2ADF (argv);
163+ if (!writer.openDevice (_wtoi (argv[1 ]))) {
164+ printf (" \r Error opening COM port: %s " , writer.getLastError ().c_str ());
165+ }
166+ else {
126167
127- writer. closeDevice ( );
168+ if (writeMode) adf2Disk (argv, verify); else disk2ADF (argv );
128169
170+ writer.closeDevice ();
171+ }
172+ }
129173
130174 getchar ();
131175 return 0 ;
0 commit comments