Add logging to a file for init

This commit is contained in:
Eric Helgeson 2020-12-21 11:22:13 -06:00 committed by Eric Helgeson
parent 10b2b71fad
commit ae269a522c

View File

@ -245,6 +245,11 @@ static const byte db2scsiid[256]={
}; };
#endif #endif
// Log File
#define VERSION "1.0-b"
#define LOG_FILENAME "LOG.txt"
FsFile LOG_FILE;
void onFalseInit(void); void onFalseInit(void);
void onBusReset(void); void onBusReset(void);
@ -282,31 +287,25 @@ bool hddimageOpen(HDDIMG *h,const char *image_name,int id,int lun,int blocksize)
if(h->m_file.isOpen()) if(h->m_file.isOpen())
{ {
h->m_fileSize = h->m_file.size(); h->m_fileSize = h->m_file.size();
#if DEBUG LOG_FILE.print("Imagefile: ");
Serial.print("Imagefile:"); LOG_FILE.print(file_path);
Serial.print(h->m_file.name() );
#endif
if(h->m_fileSize>0) if(h->m_fileSize>0)
{ {
// check blocksize dummy file // check blocksize dummy file
#if DEBUG LOG_FILE.print(" / ");
Serial.print(" / "); LOG_FILE.print(h->m_fileSize);
Serial.print(h->m_fileSize); LOG_FILE.print("bytes / ");
Serial.print("bytes / "); LOG_FILE.print(h->m_fileSize / 1024);
Serial.print(h->m_fileSize / 1024); LOG_FILE.print("KiB / ");
Serial.print("KiB / "); LOG_FILE.print(h->m_fileSize / 1024 / 1024);
Serial.print(h->m_fileSize / 1024 / 1024); LOG_FILE.println("MiB");
Serial.println("MiB"); return true; // File opened
#endif
return true; // ファイルが開けた
} }
else else
{ {
h->m_file.close(); h->m_file.close();
h->m_fileSize = h->m_blocksize = 0; // no file h->m_fileSize = h->m_blocksize = 0; // no file
#if DEBUG LOG_FILE.println("FileSizeError");
Serial.println("FileSizeError");
#endif
} }
} }
return false; return false;
@ -367,6 +366,7 @@ void setup()
#endif #endif
onFalseInit(); onFalseInit();
} }
initFileLog();
//Sector data overrun byte setting //Sector data overrun byte setting
m_buf[MAX_BLOCKSIZE] = 0xff; // DB0 all off,DBP off m_buf[MAX_BLOCKSIZE] = 0xff; // DB0 all off,DBP off
@ -394,45 +394,61 @@ void setup()
{ {
// Marked as a responsive ID // Marked as a responsive ID
scsi_id_mask |= 1<<id; scsi_id_mask |= 1<<id;
//totalImage++;
} }
} }
} }
// Error if there are 0 image files // Error if there are 0 image files
if(scsi_id_mask==0) onFalseInit(); if(scsi_id_mask==0) onFalseInit();
finalizeFileLog();
LED_OFF();
//Occurs when the RST pin state changes from HIGH to LOW
attachInterrupt(PIN_MAP[RST].gpio_bit, onBusReset, FALLING);
}
/*
* Setup initialization logfile
*/
void initFileLog() {
LOG_FILE = SD.open(LOG_FILENAME, O_WRONLY | O_CREAT);
LOG_FILE.print("VERSION: ");
LOG_FILE.println(VERSION);
LOG_FILE.println("Initialized SD Card - lets go!");
}
/*
* Finalize initialization logfile
*/
void finalizeFileLog() {
// View support drive map // View support drive map
#if DEBUG LOG_FILE.print("ID");
Serial.print("ID");
for(int lun=0;lun<NUM_SCSILUN;lun++) for(int lun=0;lun<NUM_SCSILUN;lun++)
{ {
Serial.print(":LUN"); LOG_FILE.print(":LUN");
Serial.print(lun); LOG_FILE.print(lun);
} }
Serial.println(":"); LOG_FILE.println(":");
// //
for(int id=0;id<NUM_SCSIID;id++) for(int id=0;id<NUM_SCSIID;id++)
{ {
Serial.print(" "); LOG_FILE.print(" ");
Serial.print(id); LOG_FILE.print(id);
for(int lun=0;lun<NUM_SCSILUN;lun++) for(int lun=0;lun<NUM_SCSILUN;lun++)
{ {
HDDIMG *h = &img[id][lun]; HDDIMG *h = &img[id][lun];
if( (lun<NUM_SCSILUN) && (h->m_file)) if( (lun<NUM_SCSILUN) && (h->m_file))
{ {
Serial.print((h->m_blocksize<1000) ? ": " : ":"); LOG_FILE.print((h->m_blocksize<1000) ? ": " : ":");
Serial.print(h->m_blocksize); LOG_FILE.print(h->m_blocksize);
} }
else else
Serial.print(":----"); LOG_FILE.print(":----");
} }
Serial.println(":"); LOG_FILE.println(":");
} }
#endif LOG_FILE.println("Finished initialization of SCSI Devices - Entering main loop.");
LED_OFF(); LOG_FILE.sync();
//Occurs when the RST pin state changes from HIGH to LOW LOG_FILE.close();
attachInterrupt(PIN_MAP[RST].gpio_bit, onBusReset, FALLING);
} }
/* /*