Skip to content

Commit

Permalink
Added possibility of choice format data to capture.
Browse files Browse the repository at this point in the history
  • Loading branch information
opetany93 committed Jan 24, 2018
1 parent 47b6d96 commit 13a08c7
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/application/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import mainwindow.CaptureController;
import port.PortReader;

public class Main extends Application
Expand All @@ -20,7 +21,11 @@ public void start(Stage primaryStage) throws Exception
primaryStage.setMinHeight(450.0);
primaryStage.setMinWidth(620.0);

primaryStage.setOnCloseRequest(event -> PortReader.getInstance().setStopReading(true));
primaryStage.setOnCloseRequest(event ->
{
CaptureController.isActiveExport = false;
PortReader.getInstance().setStopReading(true);
});

primaryStage.show();
}
Expand Down
11 changes: 9 additions & 2 deletions src/classes/Frame.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,22 @@ public Date getTime() {
return date;
}

public String toString(boolean checks[])
public String toString(boolean checks[], String format)
{
StringBuilder s = new StringBuilder();

for(short i = 0; i < numberOfChannels;i++)
{
if (checks[i])
{
s.append(channelData.get(i).toString()).append(" ");
if(format.equals("hex"))
{
s.append(Integer.toHexString(channelData.get(i))).append(" ");
}
else if(format.equals("decimal"))
{
s.append(channelData.get(i).toString()).append(" ");
}
}
else
{
Expand Down
31 changes: 24 additions & 7 deletions src/mainwindow/CaptureController.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ public class CaptureController implements Initializable
public Button startAppendButton;
public Button stopButton;

public RadioButton asHexRadioButton;
public RadioButton asDecimalRadioButton;
public RadioButton asHexRadioButton;
private ToggleGroup formatOfValuesGroup;

public CheckBox channel1CheckBox;
public CheckBox channel2CheckBox;
Expand All @@ -38,7 +39,7 @@ public class CaptureController implements Initializable

private ArrayList<CheckBox> channelCheckBoxes;

private volatile boolean isActiveExport;
public static volatile boolean isActiveExport;

private File file;

Expand All @@ -55,6 +56,14 @@ public void initialize(URL location, ResourceBundle resources)
channelCheckBoxes.add(channel6CheckBox);
channelCheckBoxes.add(channel7CheckBox);
channelCheckBoxes.add(channel8CheckBox);

formatOfValuesGroup = new ToggleGroup();
asDecimalRadioButton.setToggleGroup(formatOfValuesGroup);
asDecimalRadioButton.setSelected(true);
asDecimalRadioButton.setUserData("decimal");

asHexRadioButton.setToggleGroup(formatOfValuesGroup);
asHexRadioButton.setUserData("hex");
}

public void chooseFileClick()
Expand Down Expand Up @@ -83,11 +92,15 @@ public void startOverwriteClick()
PortReader.getInstance().setExportBufferEnabled(true);
isActiveExport = true;

Log.getInstance().log("Capturing is started.");

stopButton.setDisable(false);
//startAppendButton.setDisable(true);
startOverwriteButton.setDisable(true);
asHexRadioButton.setDisable(true);
asDecimalRadioButton.setDisable(true);

new Thread(() ->
Thread capturingThread = new Thread(() ->
{
int i;

Expand Down Expand Up @@ -120,7 +133,7 @@ public void startOverwriteClick()
checks[i] = channelCheckBoxes.get(i).isSelected();
}

printWriter.println(frame.toString(checks));
printWriter.println(frame.toString(checks, formatOfValuesGroup.getSelectedToggle().getUserData().toString()));
}
}

Expand All @@ -131,8 +144,9 @@ public void startOverwriteClick()
e.printStackTrace();
}

}).start();

});
capturingThread.setName("Capturing Thread");
capturingThread.start();
}
else
{
Expand All @@ -155,7 +169,6 @@ public void startAppendClick()
stopButton.setDisable(false);
startAppendButton.setDisable(true);
startOverwriteButton.setDisable(true);

}
else
{
Expand All @@ -178,6 +191,10 @@ public void stopClick()
Platform.runLater(() -> channelCheckBoxes.get(finalI).setDisable(false));
}

asHexRadioButton.setDisable(false);
asDecimalRadioButton.setDisable(false);

Log.getInstance().log("Capturing is stopped.");
}

private void showInformationAlert(String information)
Expand Down
4 changes: 2 additions & 2 deletions src/mainwindow/captureView.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@
</Button>
</children>
</HBox>
<RadioButton fx:id="asHexRadioButton" focusTraversable="false" mnemonicParsing="false" text="as hex">
<RadioButton fx:id="asDecimalRadioButton" focusTraversable="false" mnemonicParsing="false" text="as decimal">
<font>
<Font size="11.0" />
</font>
</RadioButton>
<RadioButton fx:id="asDecimalRadioButton" focusTraversable="false" mnemonicParsing="false" text="as decimal">
<RadioButton fx:id="asHexRadioButton" focusTraversable="false" mnemonicParsing="false" text="as hex">
<font>
<Font size="11.0" />
</font>
Expand Down
14 changes: 2 additions & 12 deletions src/port/PortReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,9 @@ private Frame readFrame()

if ( CRC16.checksumIsAgree(bufferIn) )
{
System.out.println("The checksums agrees.");

try
{
frame = mapBufferToFrame(bufferIn);
System.out.println("Buffer is mapped to object of Frame type.");
listening = false;
}
catch (Exception e)
Expand All @@ -104,7 +101,6 @@ private Frame readFrame()
}
else
{
Log.getInstance().log("The checksums doesn't agrees.");
listening = false;
}
}
Expand Down Expand Up @@ -183,8 +179,6 @@ public void startReading()
// create a new thread and listen for frame, then add to frame buffer
Thread readingThread = new Thread(() ->
{
System.out.println("Started reading thread.");

while (!stopReading)
{
try
Expand All @@ -199,23 +193,19 @@ public void startReading()
{
exportFrameBuffer.put(frame);
}

System.out.println("New frame is added to the queue.");
}
else
{
System.out.println("Read frame is a null.");
//System.out.println("Read frame is a null.");
}
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}

System.out.println("Stopped reading thread.");
});
readingThread.setName("FrameReadingThread");
readingThread.setName("Frame Reading Thread");
readingThread.start();
}

Expand Down

0 comments on commit 13a08c7

Please sign in to comment.