project refactoring

This commit is contained in:
Stéphane Godin 2018-12-02 15:54:06 +01:00
parent 5d104432b8
commit 542dbfa0f7
33 changed files with 295 additions and 115 deletions

6
.gitignore vendored
View File

@ -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

View File

@ -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>

View File

@ -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>

View File

@ -29,7 +29,7 @@ public class BrailleLogger {
System.out.println(";" + s);
}
if (args[0] != null)
if (args.length > 0)
{
FileReader fr;
Braille2GcodeEncoder encoder = new Braille2GcodeEncoder(new Braille6GcodeEncoding());

Binary file not shown.

Binary file not shown.

View File

@ -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>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>simpleJavaGrblStreamer</name>
<name>gcodestreamer</name>
<comment></comment>
<projects>
</projects>
@ -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>

View File

@ -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

View File

@ -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>

View File

@ -0,0 +1 @@
/com/

View File

@ -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;
}
}
}
}

View File

@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -1 +0,0 @@
/target/

View File

@ -1,3 +0,0 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding/<project>=UTF-8

View File

@ -1,5 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6

View File

@ -1,4 +0,0 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2015 Will Winder
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,9 +0,0 @@
# simpleJavaGrblStreamer
A minimal Java application to stream a file to GRBL as quickly as possible.
Uses a blocking queue to send events from the serial event thread to the main thread which is sending the file.
Build with "mvn compile assembly:single"
Run with "java -jar <commPort> <baud> <file>"

View File

@ -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>

View File

@ -1,37 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.willwinder.sjgs</groupId>
<artifactId>simpleJavaGrblStreamer</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.scream3r</groupId>
<artifactId>jssc</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.willwinder.sjgs.simplejavagrblstreamer.SimpleJavaGrblStreamer</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -25,7 +25,12 @@ public class SimpleJavaGrblStreamer {
static int GRBL_BUFFER_SIZE = 125;
public static void main(String argv[]) throws SerialPortException, IOException, InterruptedException {
if (argv.length != 3 && argv.length != 2) {
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;
}

BIN
printed_parts_v0.5.zip Normal file

Binary file not shown.