Buffer size could be set as hex value
This commit is contained in:
parent
abd52d5c0b
commit
d3a399c59f
6 changed files with 110 additions and 14 deletions
2
pom.xml
2
pom.xml
|
@ -8,7 +8,7 @@
|
||||||
<name>JavaUSBTool</name>
|
<name>JavaUSBTool</name>
|
||||||
|
|
||||||
<artifactId>javausbtool</artifactId>
|
<artifactId>javausbtool</artifactId>
|
||||||
<version>0.3-SNAPSHOT</version>
|
<version>0.4-SNAPSHOT</version>
|
||||||
|
|
||||||
<url>https://github.com/developersu/javausbtool/</url>
|
<url>https://github.com/developersu/javausbtool/</url>
|
||||||
<description>
|
<description>
|
||||||
|
|
|
@ -63,4 +63,7 @@ public class AppPreferences {
|
||||||
|
|
||||||
public int getReadBufferSize(){ return preferences.getInt("read_buffer_size", 512); }
|
public int getReadBufferSize(){ return preferences.getInt("read_buffer_size", 512); }
|
||||||
public void setReadBufferSize(int value){ preferences.putInt("read_buffer_size", value); }
|
public void setReadBufferSize(int value){ preferences.putInt("read_buffer_size", value); }
|
||||||
|
|
||||||
|
public boolean getBufAsHex(){ return preferences.getBoolean("buf_as_hex", false); }
|
||||||
|
public void setBufAsHex(boolean value){preferences.putBoolean("buf_as_hex", value);}
|
||||||
}
|
}
|
|
@ -28,7 +28,7 @@ import javausbtool.controllers.LandingPageController;
|
||||||
|
|
||||||
public class JFXMain extends Application {
|
public class JFXMain extends Application {
|
||||||
|
|
||||||
public static final String appVersion = "v0.3";
|
public static final String appVersion = "v0.4";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception{
|
public void start(Stage primaryStage) throws Exception{
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class LandingPageController implements Initializable {
|
||||||
readBufferSizeTf;
|
readBufferSizeTf;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Label saveToLbl, sendFileLbl;
|
private Label saveToLbl, sendFileLbl, decHexReprLbl;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private CheckBox handleKernelDrvDetachCb,
|
private CheckBox handleKernelDrvDetachCb,
|
||||||
|
@ -60,6 +60,9 @@ public class LandingPageController implements Initializable {
|
||||||
private RadioButton readOnStartRb,
|
private RadioButton readOnStartRb,
|
||||||
writeOnStartRb;
|
writeOnStartRb;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private MenuButton dexHexMenuItem;
|
||||||
|
|
||||||
private String previouslyOpenedPath;
|
private String previouslyOpenedPath;
|
||||||
private File writeOnStartFile;
|
private File writeOnStartFile;
|
||||||
private Task<Void> usbCommunications;
|
private Task<Void> usbCommunications;
|
||||||
|
@ -77,14 +80,89 @@ public class LandingPageController implements Initializable {
|
||||||
handleKernelDrvDetachCb.setSelected(pref.getHandleKernelDrvAutoDetach());
|
handleKernelDrvDetachCb.setSelected(pref.getHandleKernelDrvAutoDetach());
|
||||||
mandatorySoftResetCb.setSelected(pref.getSoftResetOnHandle());
|
mandatorySoftResetCb.setSelected(pref.getSoftResetOnHandle());
|
||||||
|
|
||||||
readBufferSizeTf.setText(Integer.toString(pref.getReadBufferSize()));
|
if (pref.getBufAsHex())
|
||||||
|
readBufferSizeTf.setText(String.format("%x", pref.getReadBufferSize()));
|
||||||
|
else
|
||||||
|
readBufferSizeTf.setText(String.format("%d", pref.getReadBufferSize()));
|
||||||
|
|
||||||
vidTf.setTextFormatter(getNumericTextFormatter());
|
vidTf.setTextFormatter(getNumericTextFormatter());
|
||||||
pidTf.setTextFormatter(getNumericTextFormatter());
|
pidTf.setTextFormatter(getNumericTextFormatter());
|
||||||
devConfigurationTf.setTextFormatter(getNumericTextFormatter());
|
devConfigurationTf.setTextFormatter(getNumericTextFormatter());
|
||||||
devConfigurationTf.setTextFormatter(getNumericTextFormatter());
|
devConfigurationTf.setTextFormatter(getNumericTextFormatter());
|
||||||
|
|
||||||
readBufferSizeTf.setTextFormatter(getNumericTextFormatter());
|
MenuItem decItem = new MenuItem("Dec");
|
||||||
|
decItem.setOnAction(event -> {
|
||||||
|
dexHexMenuItem.setText("Dec");
|
||||||
|
|
||||||
|
String oldValue = decHexReprLbl.getText();
|
||||||
|
|
||||||
|
readBufferSizeTf.setTextFormatter(new TextFormatter<>(change -> {
|
||||||
|
String text = change.getControlNewText();
|
||||||
|
if (text.matches("^[0-9]{0,}$")) {
|
||||||
|
if (! text.isEmpty()) {
|
||||||
|
try {
|
||||||
|
decHexReprLbl.setText(String.format("0x%x", Integer.parseInt(text)));
|
||||||
|
}
|
||||||
|
catch (Exception e){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return change;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (! oldValue.isEmpty()){
|
||||||
|
try {
|
||||||
|
int val = Integer.parseInt(oldValue, 10);
|
||||||
|
readBufferSizeTf.setText(Integer.toString(val));
|
||||||
|
decHexReprLbl.setText(String.format("0x%x", val));
|
||||||
|
}
|
||||||
|
catch (Exception e){
|
||||||
|
readBufferSizeTf.setText("0");
|
||||||
|
decHexReprLbl.setText("0x0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
MenuItem hexItem = new MenuItem("Hex");
|
||||||
|
|
||||||
|
hexItem.setOnAction(event -> {
|
||||||
|
dexHexMenuItem.setText("Hex");
|
||||||
|
|
||||||
|
String oldValue = decHexReprLbl.getText();
|
||||||
|
|
||||||
|
readBufferSizeTf.setTextFormatter(new TextFormatter<>(change -> {
|
||||||
|
String text = change.getControlNewText();
|
||||||
|
if (text.matches("^[0-9a-fA-F]{0,}$")) {
|
||||||
|
if (! text.isEmpty() ) {
|
||||||
|
try {
|
||||||
|
decHexReprLbl.setText(String.format("%d", Integer.parseInt(text, 16)));
|
||||||
|
}
|
||||||
|
catch (Exception e){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return change;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (! oldValue.isEmpty()){
|
||||||
|
try {
|
||||||
|
int val = Integer.decode(oldValue);
|
||||||
|
readBufferSizeTf.setText(String.format("%x", val));
|
||||||
|
decHexReprLbl.setText(Integer.toString(val));
|
||||||
|
}
|
||||||
|
catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
readBufferSizeTf.setText("0");
|
||||||
|
decHexReprLbl.setText("0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dexHexMenuItem.getItems().add(decItem);
|
||||||
|
dexHexMenuItem.getItems().add(hexItem);
|
||||||
|
|
||||||
saveToLbl.setText(pref.getSaveTo());
|
saveToLbl.setText(pref.getSaveTo());
|
||||||
changeSaveToBtn.setOnAction(event -> setSaveToFolder());
|
changeSaveToBtn.setOnAction(event -> setSaveToFolder());
|
||||||
|
@ -99,6 +177,11 @@ public class LandingPageController implements Initializable {
|
||||||
|
|
||||||
startBtn.setOnAction(event -> startProcess());
|
startBtn.setOnAction(event -> startProcess());
|
||||||
stopBtn.setOnAction(event -> stopProcess());
|
stopBtn.setOnAction(event -> stopProcess());
|
||||||
|
|
||||||
|
if (pref.getBufAsHex())
|
||||||
|
hexItem.fire();
|
||||||
|
else
|
||||||
|
decItem.fire();
|
||||||
}
|
}
|
||||||
|
|
||||||
private TextFormatter getNumericTextFormatter(){
|
private TextFormatter getNumericTextFormatter(){
|
||||||
|
@ -109,6 +192,12 @@ public class LandingPageController implements Initializable {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getBufferSize() throws NumberFormatException {
|
||||||
|
if (dexHexMenuItem.getText().equals("Dec"))
|
||||||
|
return Integer.parseInt(readBufferSizeTf.getText());
|
||||||
|
return Integer.parseInt(readBufferSizeTf.getText(), 16);
|
||||||
|
}
|
||||||
|
|
||||||
private void setSaveToFolder() {
|
private void setSaveToFolder() {
|
||||||
DirectoryChooser dirChooser = new DirectoryChooser();
|
DirectoryChooser dirChooser = new DirectoryChooser();
|
||||||
dirChooser.setTitle("Save files to...");
|
dirChooser.setTitle("Save files to...");
|
||||||
|
@ -140,6 +229,8 @@ public class LandingPageController implements Initializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startProcess(){
|
private void startProcess(){
|
||||||
|
System.out.println(getBufferSize());
|
||||||
|
|
||||||
logArea.clear();
|
logArea.clear();
|
||||||
if (writeOnStartRb.isSelected() && writeOnStartFile == null){
|
if (writeOnStartRb.isSelected() && writeOnStartFile == null){
|
||||||
logArea.appendText("'Write on start' option selected but no file defined\n");
|
logArea.appendText("'Write on start' option selected but no file defined\n");
|
||||||
|
@ -158,7 +249,7 @@ public class LandingPageController implements Initializable {
|
||||||
Integer.parseInt(devConfigurationTf.getText()),
|
Integer.parseInt(devConfigurationTf.getText()),
|
||||||
handleKernelDrvDetachCb.isSelected(),
|
handleKernelDrvDetachCb.isSelected(),
|
||||||
mandatorySoftResetCb.isSelected(),
|
mandatorySoftResetCb.isSelected(),
|
||||||
Integer.parseInt(readBufferSizeTf.getText()),
|
getBufferSize(),
|
||||||
saveToLbl.getText(),
|
saveToLbl.getText(),
|
||||||
readOnStartRb.isSelected(),
|
readOnStartRb.isSelected(),
|
||||||
writeOnStartFile
|
writeOnStartFile
|
||||||
|
@ -211,9 +302,11 @@ public class LandingPageController implements Initializable {
|
||||||
pref.setSaveTo(saveToLbl.getText());
|
pref.setSaveTo(saveToLbl.getText());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ((intValue = Integer.parseInt(readBufferSizeTf.getText())) > 0)
|
if ( (intValue = getBufferSize()) > 0)
|
||||||
pref.setReadBufferSize(intValue);
|
pref.setReadBufferSize(intValue);
|
||||||
}
|
}
|
||||||
catch (NumberFormatException e){ e.printStackTrace(); }
|
catch (NumberFormatException e){ e.printStackTrace(); }
|
||||||
|
|
||||||
|
pref.setBufAsHex(dexHexMenuItem.getText().equals("Hex"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,6 @@ import java.nio.IntBuffer;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
/**
|
|
||||||
* Tinfoil processing
|
|
||||||
* */
|
|
||||||
class UsbLoop {
|
class UsbLoop {
|
||||||
|
|
||||||
private LogPrinter logPrinter;
|
private LogPrinter logPrinter;
|
||||||
|
@ -55,7 +52,7 @@ class UsbLoop {
|
||||||
this.readBufferCapacity = readBufferCapacity;
|
this.readBufferCapacity = readBufferCapacity;
|
||||||
this.readCounter = 0;
|
this.readCounter = 0;
|
||||||
|
|
||||||
logPrinter.print("============= UsbProtocol =============");
|
logPrinter.print("============= USB =============");
|
||||||
|
|
||||||
this.saveRepliesFolder = new File(saveRepliesTo+File.separator+ LocalTime.now().format(DateTimeFormatter.ofPattern("HH-mm-ss")));
|
this.saveRepliesFolder = new File(saveRepliesTo+File.separator+ LocalTime.now().format(DateTimeFormatter.ofPattern("HH-mm-ss")));
|
||||||
saveRepliesFolder.mkdirs();
|
saveRepliesFolder.mkdirs();
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
<?import javafx.scene.control.Button?>
|
<?import javafx.scene.control.Button?>
|
||||||
<?import javafx.scene.control.CheckBox?>
|
<?import javafx.scene.control.CheckBox?>
|
||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.MenuButton?>
|
||||||
<?import javafx.scene.control.ProgressBar?>
|
<?import javafx.scene.control.ProgressBar?>
|
||||||
<?import javafx.scene.control.RadioButton?>
|
<?import javafx.scene.control.RadioButton?>
|
||||||
<?import javafx.scene.control.Separator?>
|
<?import javafx.scene.control.Separator?>
|
||||||
|
@ -70,13 +71,15 @@
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
<Separator prefWidth="200.0" />
|
<Separator prefWidth="200.0" />
|
||||||
<HBox alignment="CENTER_LEFT" spacing="5.0">
|
<HBox alignment="CENTER_LEFT" spacing="8.0">
|
||||||
<children>
|
<children>
|
||||||
<Label text="NS read buffer size:" />
|
<Label text="NS read buffer size (bytes):" />
|
||||||
<TextField fx:id="readBufferSizeTf" />
|
<TextField fx:id="readBufferSizeTf" />
|
||||||
<Label text="(e.g. 512 or 4096)" />
|
<MenuButton fx:id="dexHexMenuItem" mnemonicParsing="false" prefWidth="80.0" />
|
||||||
|
<Label fx:id="decHexReprLbl" prefWidth="150.0" />
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
|
<HBox alignment="CENTER_LEFT" spacing="5.0" />
|
||||||
<RadioButton fx:id="readOnStartRb" mnemonicParsing="false" text="Read on start" />
|
<RadioButton fx:id="readOnStartRb" mnemonicParsing="false" text="Read on start" />
|
||||||
<HBox alignment="CENTER_LEFT" spacing="5.0">
|
<HBox alignment="CENTER_LEFT" spacing="5.0">
|
||||||
<children>
|
<children>
|
||||||
|
|
Loading…
Reference in a new issue