A bit more renames and debug things

This commit is contained in:
Dmitry Isaenko 2020-05-09 18:03:25 +03:00
parent 6816cff10d
commit dfcc2c9927

View file

@ -22,6 +22,7 @@ import javafx.concurrent.Task;
import nsusbloader.COM.USB.UsbErrorCodes;
import nsusbloader.ModelControllers.LogPrinter;
import nsusbloader.NSLDataTypes.EMsgType;
import nsusbloader.RainbowHexDump;
import org.usb4java.DeviceHandle;
import org.usb4java.LibUsb;
@ -67,7 +68,7 @@ class NxdtUsbAbi1 {
0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
private static final byte[] USBSTATUS_MALFORMED_CMD = { 0x4e, 0x58, 0x44, 0x54,
private static final byte[] USBSTATUS_MALFORMED_REQUEST = { 0x4e, 0x58, 0x44, 0x54,
0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
@ -99,9 +100,12 @@ class NxdtUsbAbi1 {
try {
byte[] directive;
int command;
while (true){
directive = readUsbCmd();
while (true){
directive = readUsbDirective();
RainbowHexDump.hexDumpUTF8(directive);
if (isInvalidDirective(directive))
continue;
@ -122,7 +126,7 @@ class NxdtUsbAbi1 {
}
}
}
catch (InterruptedException ioe){
catch (InterruptedException ie){
logPrinter.print("Execution interrupted", EMsgType.INFO);
}
catch (Exception e){
@ -135,12 +139,12 @@ class NxdtUsbAbi1 {
private boolean isInvalidDirective(byte[] message) throws Exception{
if (! Arrays.equals(Arrays.copyOfRange(message, 0,4), MAGIC_NXDT)){
writeUsb(USBSTATUS_INVALID_MAGIC);
logPrinter.print("Invalid magic command", EMsgType.INFO);
logPrinter.print("Invalid 'MAGIC'", EMsgType.INFO);
return true;
}
if (message.length != NXDT_COMMAND_SIZE){
writeUsb(USBSTATUS_MALFORMED_CMD);
logPrinter.print("Invalid command size. Expected size is 4096 while received is "+message.length, EMsgType.INFO);
writeUsb(USBSTATUS_MALFORMED_REQUEST);
logPrinter.print("Invalid directive size. Expected size is 4096 while received is "+message.length, EMsgType.INFO);
return true;
}
return false;
@ -213,6 +217,8 @@ class NxdtUsbAbi1 {
}
private void createPath(String path) throws Exception{
// QA NOTE: Clarify if exception is even possible on RO FS.
File resultingFile = new File(path);
File folderForTheFile = resultingFile.getParentFile();
folderForTheFile.mkdirs();
@ -283,7 +289,7 @@ class NxdtUsbAbi1 {
* @return byte array if data read successful
* 'null' if read failed
* */
private byte[] readUsbCmd() throws Exception{
private byte[] readUsbDirective() throws Exception{
ByteBuffer readBuffer = ByteBuffer.allocateDirect(NXDT_COMMAND_SIZE);
// We can limit it to 32 bytes, but there is a non-zero chance to got OVERFLOW from libusb.
IntBuffer readBufTransferred = IntBuffer.allocate(1);