Added reboot support (#696)

This commit is contained in:
Uwe Seimet 2022-02-23 04:08:22 +01:00 committed by GitHub
parent 7290803ace
commit f5f5c002aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 7 deletions

View File

@ -164,18 +164,25 @@ void SCSIDEV::BusFree()
// When the bus is free RaSCSI or the Pi may be shut down
switch(shutdown_mode) {
case RASCSI:
case STOP_RASCSI:
LOGINFO("RaSCSI shutdown requested");
exit(0);
break;
case PI:
case STOP_PI:
LOGINFO("Raspberry Pi shutdown requested");
if (system("init 0") == -1) {
LOGERROR("Raspberry Pi shutdown failed: %s", strerror(errno));
}
break;
case RESTART_PI:
LOGINFO("Raspberry Pi restart requested");
if (system("init 6") == -1) {
LOGERROR("Raspberry Pi restart failed: %s", strerror(errno));
}
break;
default:
break;
}

View File

@ -29,8 +29,9 @@ public:
enum rascsi_shutdown_mode {
NONE,
RASCSI,
PI
STOP_RASCSI,
STOP_PI,
RESTART_PI
};
// Internal data definition

View File

@ -27,9 +27,10 @@
// uint8_t second; // 0-59
// } mode_page_datetime;
//
// 2. STOP UNIT shuts down RaSCSI or the Raspberry Pi
// 2. START/STOP UNIT shuts down RaSCSI or shuts down/reboots the Raspberry Pi
// a) !start && !load (STOP): Shut down RaSCSI
// b) !start && load (EJECT): Shut down the Raspberry Pi
// c) start && load (LOAD): Reboot the Raspberry Pi
//
#include "controllers/scsidev_ctrl.h"
@ -77,15 +78,23 @@ void HostServices::StartStopUnit(SCSIDEV *controller)
}
if (load) {
controller->ScheduleShutDown(SCSIDEV::rascsi_shutdown_mode::PI);
controller->ScheduleShutDown(SCSIDEV::rascsi_shutdown_mode::STOP_PI);
}
else {
controller->ScheduleShutDown(SCSIDEV::rascsi_shutdown_mode::RASCSI);
controller->ScheduleShutDown(SCSIDEV::rascsi_shutdown_mode::STOP_RASCSI);
}
controller->Status();
return;
}
else {
if (load) {
controller->ScheduleShutDown(SCSIDEV::rascsi_shutdown_mode::RESTART_PI);
controller->Status();
return;
}
}
controller->Error(ERROR_CODES::sense_key::ILLEGAL_REQUEST, ERROR_CODES::asc::INVALID_FIELD_IN_CDB);
}