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