Skip to content

Commit

Permalink
project refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
crocsg committed Dec 2, 2018
1 parent 5d10443 commit 542dbfa
Show file tree
Hide file tree
Showing 33 changed files with 295 additions and 115 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
*~
lasercut_v0.5.zip
lasercut_v0.5.zip
NatBrailleTools/BrailleLogger/bin/Braille2GcodeEncoder.class
NatBrailleTools/BrailleLogger/bin/Braille6GcodeEncoding.class
NatBrailleTools/BrailleLogger/bin/BrailleLogger.class
NatBrailleTools/BrailleLogger/bin/GCodeGenerator.class
21 changes: 21 additions & 0 deletions NatBrailleTools/BrailleLogger/ant/braillelogger_ant_build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="create_run_jar" name="Create Runnable Jar for Project BrailleLogger with Jar-in-Jar Loader">
<!--this file was created by Eclipse Runnable JAR file Export Wizard-->
<!--ANT 1.7 is required-->
<!--define folder properties-->
<property name="dir.buildfile" value="."/>
<property name="dir.workspace" value="D:/Users/Stephane/eclipse-workspace"/>
<property name="dir.jarfile" value="I:/home/3d/braillerapsp.github/BrailleRapSP/NatBrailleTools/bin"/>
<target name="create_run_jar">
<jar destfile="${dir.jarfile}/braillelogger.jar">
<manifest>
<attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader"/>
<attribute name="Rsrc-Main-Class" value="BrailleLogger"/>
<attribute name="Class-Path" value="."/>
<attribute name="Rsrc-Class-Path" value="./"/>
</manifest>
<zipfileset src="jar-in-jar-loader.zip"/>
<fileset dir="I:/home/3d/braillerapsp.github/BrailleRapSP/NatBrailleTools/BrailleLogger/bin"/>
</jar>
</target>
</project>
Binary file not shown.
Binary file modified NatBrailleTools/BrailleLogger/bin/Braille2GcodeEncoder.class
Binary file not shown.
Binary file modified NatBrailleTools/BrailleLogger/bin/Braille6GcodeEncoding.class
Binary file not shown.
Binary file modified NatBrailleTools/BrailleLogger/bin/BrailleLogger.class
Binary file not shown.
Binary file modified NatBrailleTools/BrailleLogger/bin/GCodeGenerator.class
Binary file not shown.
21 changes: 21 additions & 0 deletions NatBrailleTools/BrailleLogger/bin/braillelogger_ant_build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="create_run_jar" name="Create Runnable Jar for Project BrailleLogger with Jar-in-Jar Loader">
<!--this file was created by Eclipse Runnable JAR file Export Wizard-->
<!--ANT 1.7 is required-->
<!--define folder properties-->
<property name="dir.buildfile" value="."/>
<property name="dir.workspace" value="D:/Users/Stephane/eclipse-workspace"/>
<property name="dir.jarfile" value="I:/home/3d/braillerapsp.github/BrailleRapSP/NatBrailleTools/bin"/>
<target name="create_run_jar">
<jar destfile="${dir.jarfile}/braillelogger.jar">
<manifest>
<attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader"/>
<attribute name="Rsrc-Main-Class" value="BrailleLogger"/>
<attribute name="Class-Path" value="."/>
<attribute name="Rsrc-Class-Path" value="./"/>
</manifest>
<zipfileset src="jar-in-jar-loader.zip"/>
<fileset dir="${dir.buildfile}"/>
</jar>
</target>
</project>
2 changes: 1 addition & 1 deletion NatBrailleTools/BrailleLogger/src/BrailleLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void main(String[] args) {
System.out.println(";" + s);
}

if (args[0] != null)
if (args.length > 0)
{
FileReader fr;
Braille2GcodeEncoder encoder = new Braille2GcodeEncoder(new Braille6GcodeEncoding());
Expand Down
Binary file added NatBrailleTools/bin/braillelogger.jar
Binary file not shown.
Binary file added NatBrailleTools/bin/gcodestreamer.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions NatBrailleTools/gcodestreamer/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="I:/local/java/jSSC-2.8.0-Release/jssc.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>simpleJavaGrblStreamer</name>
<name>gcodestreamer</name>
<comment></comment>
<projects>
</projects>
Expand All @@ -10,14 +10,8 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions NatBrailleTools/gcodestreamer/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
22 changes: 22 additions & 0 deletions NatBrailleTools/gcodestreamer/ant/gcodestreamer_ant_build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="create_run_jar" name="Create Runnable Jar for Project gcodestreamer with Jar-in-Jar Loader">
<!--this file was created by Eclipse Runnable JAR file Export Wizard-->
<!--ANT 1.7 is required-->
<!--define folder properties-->
<property name="dir.buildfile" value="."/>
<property name="dir.workspace" value="D:/Users/Stephane/eclipse-workspace"/>
<property name="dir.jarfile" value="I:/home/3d/braillerapsp.github/BrailleRapSP/NatBrailleTools/bin"/>
<target name="create_run_jar">
<jar destfile="${dir.jarfile}/gcodestreamer.jar">
<manifest>
<attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader"/>
<attribute name="Rsrc-Main-Class" value="com.willwinder.sjgs.simplejavagrblstreamer.SimpleJavaGrblStreamer"/>
<attribute name="Class-Path" value="."/>
<attribute name="Rsrc-Class-Path" value="./ jssc.jar"/>
</manifest>
<zipfileset src="jar-in-jar-loader.zip"/>
<fileset dir="I:/home/3d/braillerapsp.github/BrailleRapSP/NatBrailleTools/gcodestreamer/bin"/>
<zipfileset dir="I:/local/java/jSSC-2.8.0-Release" includes="jssc.jar"/>
</jar>
</target>
</project>
Binary file not shown.
1 change: 1 addition & 0 deletions NatBrailleTools/gcodestreamer/bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/com/
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
package com.willwinder.sjgs.simplejavagrblstreamer;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import jssc.SerialPort;
import jssc.SerialPortEvent;
import jssc.SerialPortEventListener;
import jssc.SerialPortException;

/**
*
* @author wwinder
*/
public class SimpleJavaGrblStreamer {
static int GRBL_BUFFER_SIZE = 125;

public static void main(String argv[]) throws SerialPortException, IOException, InterruptedException {
if (argv.length == 0)
{
System.out.println("Arguments: <comm port> <baud> <file>");
return;
}
if (argv.length != 3 && argv.length != 2) {
System.out.println("Arguments: <comm port> <baud> <file>");
return;
}

String commPort = argv[0];
Integer baud = Integer.parseInt(argv[1]);
InputStream file = null;
if (argv.length == 2)
file = System.in;
else {
file = new FileInputStream(argv[2]);
System.out.println("Streaming file " + argv[2]);
}

System.out.println("Streaming to port <" + commPort + " : " + baud + ">");
SimpleJavaGrblStreamer s = new SimpleJavaGrblStreamer(commPort, baud);
s.send(file);

System.out.println("Done senting file.");
}

String commPort = null;
Integer baud = null;

private SimpleJavaGrblStreamer(String commPort, Integer baud) {
this.commPort = commPort;
this.baud = baud;
}

private void send(InputStream f) throws SerialPortException, IOException, InterruptedException {
BlockingQueue<Integer> commandComplete = new LinkedBlockingQueue();

SerialPort serialPort = new SerialPort(commPort);
serialPort.openPort();
serialPort.setParams(baud, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE, true, true);

Thread.sleep(5000);

serialPort.addEventListener(new GrblSerialListener(serialPort, commandComplete));
GrblSerialSender sender = new GrblSerialSender(f, serialPort, commandComplete, GRBL_BUFFER_SIZE);
sender.send();
serialPort.closePort();
}

private static class GrblSerialListener implements SerialPortEventListener {
SerialPort serialPort = null;
BlockingQueue<Integer> completedCommands;
StringBuilder inputBuffer;
private GrblSerialListener(SerialPort port, BlockingQueue<Integer> completedCommands) {
this.serialPort = port;
this.completedCommands = completedCommands;
inputBuffer = new StringBuilder();
}

@Override
public void serialEvent(SerialPortEvent event) {
if(event.isRXCHAR() && event.getEventValue() > 0){
try {
byte buffer[] = serialPort.readBytes();
for (byte b: buffer) {
if (b == '\n') {
//System.out.println("Received command: " + inputBuffer.toString());
if (inputBuffer.toString().startsWith("ok") || inputBuffer.toString().startsWith("error"))
completedCommands.add(1);
inputBuffer.setLength(0);
} else {
inputBuffer.append((char)b);
}
}
}
catch (SerialPortException ex) {
System.out.println(ex);
System.out.println("serialEvent");
}
}
}
}

private static class GrblSerialSender {
InputStream file = null;
SerialPort port = null;
Integer currentBufferSize = null;
Integer maxBufferSize = null;

BlockingQueue<Integer> completedCommands = null;
LinkedList<Integer> activeCommandSizes;

private GrblSerialSender(InputStream f, SerialPort sp, BlockingQueue<Integer> completedCommands, Integer activeBufferSize) {
file = f;
port = sp;
maxBufferSize = activeBufferSize;
currentBufferSize = 0;
this.completedCommands = completedCommands;
activeCommandSizes = new LinkedList<Integer>();
}

private void send() throws IOException {
// Java 8
//try(Stream<String> lines = Files.lines(Paths.get(file.getAbsolutePath()))){
// lines.forEach(s -> sendLine(s));
//}

BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new InputStreamReader(file));
while ((sCurrentLine = br.readLine()) != null) {
sendLine(sCurrentLine);
}
} finally {
if (br != null)br.close();
}
}

private void sendLine(String s) {
// Wait until there is room, if necessary.
while (maxBufferSize < (currentBufferSize + s.length() + 1)) {
try {
//System.out.println("waiting for room.... active command count: " + this.activeCommandSizes.size());

// Wait for a command to complete
completedCommands.take();
currentBufferSize -= this.activeCommandSizes.removeFirst();
} catch (InterruptedException ex) {
Logger.getLogger(SimpleJavaGrblStreamer.class.getName()).log(Level.SEVERE, null, ex);
return;
}
}

try {
System.out.println("Sending command: " + s.trim());
//System.out.printf(".");
this.port.writeString(s.trim() + "\n");
int commandSize = s.length() + 1;
activeCommandSizes.add(commandSize);
currentBufferSize += commandSize;
} catch (SerialPortException ex) {
Logger.getLogger(SimpleJavaGrblStreamer.class.getName()).log(Level.SEVERE, null, ex);
return;
}
}
}
}
26 changes: 0 additions & 26 deletions NatBrailleTools/simpleJavaGrblStreamer/.classpath

This file was deleted.

1 change: 0 additions & 1 deletion NatBrailleTools/simpleJavaGrblStreamer/.gitignore

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

21 changes: 0 additions & 21 deletions NatBrailleTools/simpleJavaGrblStreamer/LICENSE

This file was deleted.

9 changes: 0 additions & 9 deletions NatBrailleTools/simpleJavaGrblStreamer/README.md

This file was deleted.

0 comments on commit 542dbfa

Please sign in to comment.