Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
Grbl v1.1 support and some other things
Browse files Browse the repository at this point in the history
  • Loading branch information
cncgoko committed Apr 21, 2017
1 parent 6d3beac commit 2995f9e
Show file tree
Hide file tree
Showing 73 changed files with 2,427 additions and 994 deletions.
841 changes: 0 additions & 841 deletions GokoFeature/Goko.product

This file was deleted.

16 changes: 15 additions & 1 deletion GokoFeature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ Public License instead of this License. But first, please read

<url>
<update label="Goko Update site" url="http://update.goko.fr/0.3.3"/>
<discovery label="Goko" url="http://www.goko.fr/"/>
<discovery label="Goko" url="https://www.goko.fr/"/>
</url>

<includes
Expand Down Expand Up @@ -925,4 +925,18 @@ Public License instead of this License. But first, please read
version="0.0.0"
unpack="false"/>

<plugin
id="org.goko.controller.grbl.commons"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="org.goko.controller.grbl.v11"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

</feature>
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,9 @@ public CompletionService<ProbeResult> probe(List<ProbeRequest> lstProbeRequest)
*/
@Override
public void handleProbeResult(boolean probeSuccess, Tuple6b probePosition) throws GkException {
probeUtility.handleProbeResult(probeSuccess, probePosition);
if(probeUtility != null){
probeUtility.handleProbeResult(probeSuccess, probePosition);
}
}


Expand Down
1 change: 1 addition & 0 deletions org.goko.controller.grbl.commons/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="ui"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions org.goko.controller.grbl.commons/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/bin/
/target/
2 changes: 2 additions & 0 deletions org.goko.controller.grbl.commons/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ Require-Bundle: org.goko.core,
Export-Package: org.goko.controller.grbl.commons,
org.goko.controller.grbl.commons.bean,
org.goko.controller.grbl.commons.configuration,
org.goko.controller.grbl.commons.configuration.editors,
org.goko.controller.grbl.commons.configuration.settings,
org.goko.controller.grbl.commons.jog,
org.goko.controller.grbl.commons.probe,
org.goko.controller.grbl.commons.schedule,
org.goko.controller.grbl.commons.topic
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public abstract class AbstractGrblCommunicator<C extends AbstractGrblConfigurati
/** UI Log service */
private IApplicativeLogService applicativeLogService;


/**
* Constructor
*/
Expand Down Expand Up @@ -124,7 +125,7 @@ public void onConnectionEvent(EnumConnectionEvent event) throws GkException {
* @throws GkException GkException
*/
protected void handleIncomingData(String data) throws GkException{
String trimmedData = StringUtils.trim(data);
String trimmedData = StringUtils.trim(StringUtils.defaultString(data));
if(StringUtils.isNotEmpty(trimmedData)){
/* Received OK response */
if(StringUtils.equals(trimmedData, Grbl.OK_RESPONSE)){
Expand All @@ -142,35 +143,59 @@ protected void handleIncomingData(String data) throws GkException{
}else if(StringUtils.startsWith(trimmedData, "Grbl")){
handleHeader(trimmedData);
/* Received a configuration confirmation */
}else if(StringUtils.defaultString(trimmedData).matches("\\$[0-9]*=.*")){
}else if(trimmedData.matches("\\$[0-9]*=.*")){
handleConfigurationReading(trimmedData);

/* Received a probe result */
}else if(StringUtils.defaultString(trimmedData).matches("\\$[PRB*]")){
}else if(trimmedData.matches("\\[PRB.*]")){
//[PRB:0.000,0.000,0.000:0]
handleProbeResult(trimmedData);
/* Received a work position report */
}else if(StringUtils.defaultString(trimmedData).matches("\\[G5.*\\]")){
}else if(trimmedData.matches("\\[TLO.*]")){
//[PRB:0.000,0.000,0.000:0]
handleToolLengthOffset(trimmedData);
/* Received a work position report */
}else if(trimmedData.matches("\\[G5.*\\]")){
handleCoordinateSystemOffset(trimmedData);


}else if(trimmedData.matches("\\[MSG:.*\\]")){
handleMessage(trimmedData);
/* Received an offset position report */
}else if(StringUtils.defaultString(trimmedData).matches("\\[(G92|G28|G30).*\\]")){
}else if(trimmedData.matches("\\[(G92|G28|G30).*\\]")){
// Tuple6b targetPoint = new Tuple6b().setNull();
// String coordinateSystemName = parseCoordinateSystem(trimmedData, targetPoint);
// grbl.setOffsetCoordinate(coordinateSystemName, targetPoint);
// TODO Handle G92
/* Parser state report */
}else if(StringUtils.defaultString(trimmedData).matches("\\[GC:.*\\]")){
//grbl.receiveParserState(StringUtils.substringBetween(trimmedData, "[","]"));
}else if(trimmedData.matches("\\[GC:.*\\]")){
handleParserState(trimmedData);
/* Unkown format received */
/* Unknown format received */
}else if(trimmedData.startsWith("ALARM")){
handleAlarm(trimmedData);
}else{
LOG.error("Ignoring received data "+ trimmedData);
applicativeLogService.warning("Ignoring received data "+ trimmedData, "Grbl Communicator");
if(!handleCustomIncomingData(trimmedData)){
LOG.error("Ignoring received data "+ trimmedData);
applicativeLogService.warning("Ignoring received data "+ trimmedData, "Grbl Communicator");
}
}
}
}

/**
* @param trimmedData
*/
protected abstract void handleMessage(String trimmedData) throws GkException;


/**
* Allow subclasses to handle custom data
* @param trimmedData the raw data
* @return <code>true</code> if data were processed, <code>false</code> otherwise
*/
protected boolean handleCustomIncomingData(String trimmedData) {
return false;
}

/**
* @param trimmedData
*/
Expand All @@ -181,6 +206,16 @@ protected void handleIncomingData(String data) throws GkException{
*/
protected abstract void handleParserState(String trimmedData) throws GkException;

/**
* @param trimmedData
*/
protected abstract void handleToolLengthOffset(String trimmedData) throws GkException;

/**
* @param trimmedData
*/
protected abstract void handleAlarm(String trimmedData) throws GkException;

/**
* @param trimmedData
* @throws GkException
Expand Down Expand Up @@ -351,6 +386,21 @@ public final void sendImmediately(String data, boolean useEndLineCharacter) thro
getConnectionService().send(lstBytes, DataPriority.IMPORTANT);
}

/**
* Sends the given byte over the connection service with high priority
* @param lstByte the list of byte to send
* @param useEndLineCharacter <code>true</code> to append end line characters before sending, <code>false</code> otherwise
* @throws GkException GkException
*/
public final void sendImmediately(byte data, boolean useEndLineCharacter) throws GkException{
List<Byte> lstBytes = new ArrayList<>();
lstBytes.add(data);
if(useEndLineCharacter){
addEndLineCharacter(lstBytes);
}
getConnectionService().send(lstBytes, DataPriority.IMPORTANT);
}

/**
* Sends the given list of byte over the connection service with high priority
* @param lstByte the list of byte to send
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.goko.core.gcode.rs274ngcv3.context.GCodeContextObservable;
import org.goko.core.gcode.rs274ngcv3.element.InstructionProvider;
import org.goko.core.gcode.service.IExecutionService;
import org.goko.core.gcode.service.IGCodeExecutionListener;
import org.goko.core.log.GkLog;
import org.goko.core.math.Tuple6b;

Expand All @@ -88,7 +89,7 @@ public abstract class AbstractGrblControllerService <M extends MachineState,
C extends AbstractGrblConfiguration<C>,
P extends AbstractGrblCommunicator<C, M, T>,
J extends AbstractGrblJogger<C, M, T>,
X extends AbstractGrblExecutor<T>> extends EventDispatcher implements IGrblControllerService<C, M> {
X extends AbstractGrblExecutor<T>> extends EventDispatcher implements IGrblControllerService<C, M>,IGCodeExecutionListener<ExecutionTokenState, IExecutionToken<ExecutionTokenState>> {
/** Log */
private static final GkLog LOG = GkLog.getLogger(AbstractGrblControllerService.class);
/** GCode service*/
Expand Down Expand Up @@ -134,6 +135,7 @@ public AbstractGrblControllerService(S internalState, C configuration) throws Gk
this.jogger = createJogger();
this.executor = createExecutor();
this.statusPoller = new GrblStatusPoller(this);
getInternalState().setActivePolling(true);
this.pendingCommandsCount = new AtomicInteger(0);
}

Expand Down Expand Up @@ -366,9 +368,7 @@ public void setConnectionService(ISerialConnectionService connectionService) thr
* @throws GkException GkException
*/
public void refreshStatus() throws GkException{
if(isActivePollingEnabled()){
communicator.send( Grbl.CURRENT_STATUS, false );
}
communicator.send( Grbl.CURRENT_STATUS, false );
}

public void refreshSpaceCoordinates() throws GkException{
Expand Down Expand Up @@ -569,6 +569,7 @@ public void applyConfiguration(C configuration) throws GkException {
// End of dirty hack to avoid flooding Grbl RX buffer. Need to work on a proper solution
}
}
notifyConfigurationChanged();
this.configuration = configuration;
}

Expand Down Expand Up @@ -715,6 +716,11 @@ public Unit<Length> getCurrentUnit() {
@Override
public void setActivePollingEnabled(boolean enabled) throws GkException {
getInternalState().setActivePolling(enabled);
if(enabled){
statusPoller.start();
}else{
statusPoller.stop();
}
}

/** (inheritDoc)
Expand Down Expand Up @@ -776,7 +782,7 @@ public void importFrom(InputStream inputStream) throws GkException {
}
}
scanner.close();
setConfiguration(cfg);
applyConfiguration(cfg);
}

/** (inheritDoc)
Expand Down Expand Up @@ -866,7 +872,7 @@ protected void notifyConfigurationSettingChanged(String identifier, String oldVa
*/
@Override
public void resetGrbl() throws GkException {
communicator.sendImmediately(String.valueOf(Grbl.RESET_COMMAND), false);
communicator.sendImmediately(Grbl.RESET_COMMAND, false);
}

/**
Expand All @@ -883,13 +889,6 @@ public P getCommunicator() {
return communicator;
}

/**
* @return the gcodeService
*/
public IRS274NGCService getGcodeService() {
return gcodeService;
}

/**
* @param communicator the communicator to set
*/
Expand Down Expand Up @@ -945,11 +944,81 @@ public int getPendingCommandsCount() {

protected void decreasePendingCommands(){
pendingCommandsCount.set(Math.max(0, pendingCommandsCount.get() - 1));
System.out.println( "pendingCommandsCount: -1 = "+pendingCommandsCount.get());
}

protected void increasePendingCommands(){
pendingCommandsCount.set(Math.max(0, pendingCommandsCount.get() + 1));
System.out.println( "pendingCommandsCount: +1 = "+pendingCommandsCount.get());
}

/** (inheritDoc)
* @see org.goko.core.gcode.service.IGCodeTokenExecutionListener#onQueueExecutionStart()
*/
@Override
public void onQueueExecutionStart() throws GkException {

}

/** (inheritDoc)
* @see org.goko.core.gcode.service.IGCodeTokenExecutionListener#onExecutionStart(org.goko.core.gcode.execution.IExecutionToken)
*/
@Override
public void onExecutionStart(IExecutionToken<ExecutionTokenState> token) throws GkException {

}

/** (inheritDoc)
* @see org.goko.core.gcode.service.IGCodeTokenExecutionListener#onExecutionCanceled(org.goko.core.gcode.execution.IExecutionToken)
*/
@Override
public void onExecutionCanceled(IExecutionToken<ExecutionTokenState> token) throws GkException {

}

/** (inheritDoc)
* @see org.goko.core.gcode.service.IGCodeTokenExecutionListener#onExecutionPause(org.goko.core.gcode.execution.IExecutionToken)
*/
@Override
public void onExecutionPause(IExecutionToken<ExecutionTokenState> token) throws GkException {

}

/** (inheritDoc)
* @see org.goko.core.gcode.service.IGCodeTokenExecutionListener#onExecutionResume(org.goko.core.gcode.execution.IExecutionToken)
*/
@Override
public void onExecutionResume(IExecutionToken<ExecutionTokenState> token) throws GkException {

}

/** (inheritDoc)
* @see org.goko.core.gcode.service.IGCodeTokenExecutionListener#onExecutionComplete(org.goko.core.gcode.execution.IExecutionToken)
*/
@Override
public void onExecutionComplete(IExecutionToken<ExecutionTokenState> token) throws GkException {

}

/** (inheritDoc)
* @see org.goko.core.gcode.service.IGCodeTokenExecutionListener#onQueueExecutionComplete()
*/
@Override
public void onQueueExecutionComplete() throws GkException {

}

/** (inheritDoc)
* @see org.goko.core.gcode.service.IGCodeTokenExecutionListener#onQueueExecutionCanceled()
*/
@Override
public void onQueueExecutionCanceled() throws GkException {

}

/** (inheritDoc)
* @see org.goko.core.gcode.service.IGCodeLineExecutionListener#onLineStateChanged(org.goko.core.gcode.execution.IExecutionToken, java.lang.Integer)
*/
@Override
public void onLineStateChanged(IExecutionToken<ExecutionTokenState> token, Integer idLine) throws GkException {

}
}
Loading

0 comments on commit 2995f9e

Please sign in to comment.