Skip to content

Commit

Permalink
[#72] More Zcode variables and comments to Zscript
Browse files Browse the repository at this point in the history
  • Loading branch information
susanw1 committed Aug 2, 2023
1 parent 870754a commit d2e6441
Show file tree
Hide file tree
Showing 39 changed files with 130 additions and 141 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zscript.javaclient.responseParser;
package net.zscript.javaclient.responseparser;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -8,9 +8,9 @@
import java.util.Queue;
import java.util.function.Consumer;

import net.zscript.javaclient.responseParser.ResponseParser.ResponseHeader;
import net.zscript.javaclient.zcodeApi.CommandSeqElement;
import net.zscript.javaclient.zcodeApi.ZscriptCommandBuilder;
import net.zscript.javaclient.responseparser.ResponseParser.ResponseHeader;
import net.zscript.javaclient.zscriptapi.CommandSeqElement;
import net.zscript.javaclient.zscriptapi.ZscriptCommandBuilder;

public class CommandResponseQueue implements CommandResponseSystem {
private static final int MAX_SENT = 10;
Expand Down Expand Up @@ -166,14 +166,14 @@ public void send(final CommandSeqElement seq) {
}

@Override
public void send(final byte[] zcode, final Consumer<byte[]> callback) {
public void send(final byte[] zscript, final Consumer<byte[]> callback) {
if (sent.size() == 0) {
ByteArrEntry el = new ByteArrEntry(callback, zcode);
ByteArrEntry el = new ByteArrEntry(callback, zscript);
sent.add(el);
connection.send(el.compile());
canPipeline = false;
} else {
toSend.add(new ByteArrEntry(callback, zcode));
toSend.add(new ByteArrEntry(callback, zscript));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package net.zscript.javaclient.responseParser;
package net.zscript.javaclient.responseparser;

import java.util.function.Consumer;

import net.zscript.javaclient.zcodeApi.CommandSeqElement;
import net.zscript.javaclient.zscriptapi.CommandSeqElement;

public interface CommandResponseSystem {
void send(CommandSeqElement seq);

void send(ZscriptAddress addr, byte[] data);

void send(byte[] zcode, Consumer<byte[]> callback);
void send(byte[] zscript, Consumer<byte[]> callback);

ResponseAddressingSystem getResponseAddressingSystem();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zscript.javaclient.responseParser;
package net.zscript.javaclient.responseparser;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package net.zscript.javaclient.responseParser;
package net.zscript.javaclient.responseparser;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import net.zscript.javaclient.zcodeApi.CommandSeqElement;
import net.zscript.javaclient.zcodeApi.ZscriptCommand;
import net.zscript.javaclient.zcodeApi.ZscriptUnparsedCommandResponse;
import net.zscript.javaclient.zcodeApi.ZscriptCommand.ZcodeSequencePath;
import net.zscript.javaclient.zscriptapi.CommandSeqElement;
import net.zscript.javaclient.zscriptapi.ZscriptCommand;
import net.zscript.javaclient.zscriptapi.ZscriptUnparsedCommandResponse;
import net.zscript.javaclient.zscriptapi.ZscriptCommand.ZscriptSequencePath;
import net.zscript.javareceiver.tokenizer.OptIterator;
import net.zscript.javareceiver.tokenizer.TokenBuffer;
import net.zscript.javareceiver.tokenizer.TokenExtendingBuffer;
Expand Down Expand Up @@ -147,8 +147,8 @@ public static void parseFullResponse(final CommandSeqElement command, final byte

private static void matchMarkers(final CommandSeqElement command, final List<Byte> markers, final List<ReadToken> tokenAfterMarkers) {
ZscriptCommand current = null;
ZcodeSequencePath successPath = ZscriptCommand.findFirstCommand(command);
ZcodeSequencePath failPath = ZscriptCommand.findFirstCommand(command);
ZscriptSequencePath successPath = ZscriptCommand.findFirstCommand(command);
ZscriptSequencePath failPath = ZscriptCommand.findFirstCommand(command);
Set<ZscriptCommand> sentResponses = new HashSet<>();

int offset = 0;
Expand Down Expand Up @@ -199,7 +199,7 @@ private static void matchMarkers(final CommandSeqElement command, final List<Byt
current.response(new ZscriptUnparsedCommandResponse(tokenAfterMarkers.get(offset)));
sentResponses.add(current);
}
for (ZcodeSequencePath path = ZscriptCommand.findFirstCommand(command); path != null; path = path.getNext().findNext()) {
for (ZscriptSequencePath path = ZscriptCommand.findFirstCommand(command); path != null; path = path.getNext().findNext()) {
ZscriptCommand cmd = path.getNext();
if (!sentResponses.contains(cmd)) {
cmd.notExecuted();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zscript.javaclient.responseParser;
package net.zscript.javaclient.responseparser;

import java.util.Arrays;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zscript.javaclient.responseParser;
package net.zscript.javaclient.responseparser;

import java.util.function.Consumer;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zscript.javaclient.zcodeApi;
package net.zscript.javaclient.zscriptapi;

import java.nio.charset.StandardCharsets;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zscript.javaclient.zcodeApi;
package net.zscript.javaclient.zscriptapi;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zscript.javaclient.zcodeApi;
package net.zscript.javaclient.zscriptapi;

public class BlankCommand extends ZscriptCommand {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zscript.javaclient.zcodeApi;
package net.zscript.javaclient.zscriptapi;

public abstract class CommandSeqElement {
protected CommandSeqElement parent = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zscript.javaclient.zcodeApi;
package net.zscript.javaclient.zscriptapi;

import java.nio.charset.StandardCharsets;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zscript.javaclient.zcodeApi;
package net.zscript.javaclient.zscriptapi;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package net.zscript.javaclient.zcodeApi;
package net.zscript.javaclient.zscriptapi;

import java.util.ArrayList;
import java.util.List;

public abstract class ZscriptCommand extends CommandSeqElement {
public static class ZcodeSequencePath {
public static class ZscriptSequencePath {
private final List<Byte> markers;
private final ZscriptCommand next;

public ZcodeSequencePath(List<Byte> markers, ZscriptCommand next) {
public ZscriptSequencePath(List<Byte> markers, ZscriptCommand next) {
this.markers = markers;
this.next = next;
}

public ZcodeSequencePath(List<Byte> markers, ZcodeSequencePath rest) {
public ZscriptSequencePath(List<Byte> markers, ZscriptSequencePath rest) {
this.markers = new ArrayList<>(markers);
this.markers.addAll(rest.markers);
this.next = rest.next;
Expand All @@ -32,7 +32,7 @@ public ZscriptCommand getNext() {

public abstract void response(ZscriptUnparsedCommandResponse resp);

public static ZcodeSequencePath findFirstCommand(final CommandSeqElement start) {
public static ZscriptSequencePath findFirstCommand(final CommandSeqElement start) {
CommandSeqElement current = start;
CommandSeqElement prev = null;
List<Byte> markers = new ArrayList<>();
Expand All @@ -50,10 +50,10 @@ public static ZcodeSequencePath findFirstCommand(final CommandSeqElement start)
markers.add((byte) '(');
}
}
return new ZcodeSequencePath(markers, (ZscriptCommand) current);
return new ZscriptSequencePath(markers, (ZscriptCommand) current);
}

public ZcodeSequencePath findNext() {
public ZscriptSequencePath findNext() {
CommandSeqElement current = parent;
CommandSeqElement prev = this;
List<Byte> markers = new ArrayList<>();
Expand All @@ -63,7 +63,7 @@ public ZcodeSequencePath findNext() {
OrSeqElement orAncestor = (OrSeqElement) current;
if (prev == orAncestor.before) {
markers.add((byte) '|');
return new ZcodeSequencePath(markers, findFirstCommand(orAncestor.after));
return new ZscriptSequencePath(markers, findFirstCommand(orAncestor.after));
}
} else if (current.getClass() == AndSeqElement.class) {
AndSeqElement andAncestor = (AndSeqElement) current;
Expand All @@ -72,7 +72,7 @@ public ZcodeSequencePath findNext() {
if (prev.getClass() != OrSeqElement.class && next.getClass() != OrSeqElement.class) {
markers.add((byte) '&');
}
return new ZcodeSequencePath(markers, findFirstCommand(next));
return new ZscriptSequencePath(markers, findFirstCommand(next));
}
}
if (current.getClass() == OrSeqElement.class && current.getParent() != null && current.getParent().getClass() != OrSeqElement.class) {
Expand All @@ -84,7 +84,7 @@ public ZcodeSequencePath findNext() {
return null;
}

public ZcodeSequencePath findFailPath() {
public ZscriptSequencePath findFailPath() {
CommandSeqElement current = parent;
CommandSeqElement prev = this;
List<Byte> markers = new ArrayList<>();
Expand All @@ -94,7 +94,7 @@ public ZcodeSequencePath findFailPath() {
OrSeqElement orAncestor = (OrSeqElement) current;
if (prev == orAncestor.before) {
markers.add((byte) '|');
return new ZcodeSequencePath(markers, findFirstCommand(orAncestor.after));
return new ZscriptSequencePath(markers, findFirstCommand(orAncestor.after));
}
}
if (current.getClass() == OrSeqElement.class && current.getParent() != null && current.getParent().getClass() != OrSeqElement.class) {
Expand All @@ -106,7 +106,7 @@ public ZcodeSequencePath findFailPath() {
return null;
}

public ZcodeSequencePath findSuccessPath() {
public ZscriptSequencePath findSuccessPath() {
CommandSeqElement current = parent;
CommandSeqElement prev = this;
List<Byte> markers = new ArrayList<>();
Expand All @@ -119,7 +119,7 @@ public ZcodeSequencePath findSuccessPath() {
if (prev.getClass() != OrSeqElement.class && next.getClass() != OrSeqElement.class) {
markers.add((byte) '&');
}
return new ZcodeSequencePath(markers, findFirstCommand(next));
return new ZscriptSequencePath(markers, findFirstCommand(next));
}
}
if (current.getClass() == OrSeqElement.class && current.getParent() != null && current.getParent().getClass() != OrSeqElement.class) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zscript.javaclient.zcodeApi;
package net.zscript.javaclient.zscriptapi;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -10,10 +10,10 @@

public abstract class ZscriptCommandBuilder<T extends ZscriptResponse> {
private final List<ZscriptResponseListener<T>> listeners = new ArrayList<>();
private final List<BigField> bigFields = new ArrayList<>();
private final Map<Byte, Integer> fields = new HashMap<>();
private final List<BigField> bigFields = new ArrayList<>();
private final Map<Byte, Integer> fields = new HashMap<>();

public class ZcodeBuiltCommand extends ZscriptCommand {
public class ZscriptBuiltCommand extends ZscriptCommand {

@Override
public CommandSeqElement reEvaluate() {
Expand Down Expand Up @@ -112,9 +112,8 @@ public void write(ByteArrayOutputStream out) {
private static byte toHex(int nibble) {
if (nibble < 10) {
return (byte) (nibble + '0');
} else {
return (byte) (nibble + 'a' - 10);
}
return (byte) (nibble + 'a' - 10);
}

public static byte[] writeField(byte f, int value) {
Expand All @@ -123,9 +122,11 @@ public static byte[] writeField(byte f, int value) {
}
if (value == 0) {
return new byte[] { f };
} else if (value < 0x10) {
}
if (value < 0x10) {
return new byte[] { f, toHex(value) };
} else if (value < 0x100) {
}
if (value < 0x100) {
return new byte[] { f, toHex(value >> 4), toHex(value & 0xF) };
} else if (value < 0x1000) {
return new byte[] { f, toHex(value >> 8), toHex((value >> 4) & 0xF), toHex(value & 0xF) };
Expand All @@ -140,7 +141,7 @@ protected ZscriptCommandBuilder<T> setField(char key, int value) {

protected ZscriptCommandBuilder<T> setField(byte key, int value) {
if ((key & 0x80) != 0) {
throw new IllegalArgumentException("Key not a valid Zcode Command key");
throw new IllegalArgumentException("Key not a valid Zscript Command key");
}
fields.put(key, value);
return this;
Expand Down Expand Up @@ -178,6 +179,6 @@ public ZscriptCommandBuilder<T> addResponseListener(ZscriptResponseListener<T> l
}

public CommandSeqElement build() {
return new ZcodeBuiltCommand();
return new ZscriptBuiltCommand();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package net.zscript.javaclient.zscriptapi;

public interface ZscriptResponse {

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zscript.javaclient.zcodeApi;
package net.zscript.javaclient.zscriptapi;

public interface ZscriptResponseListener<T extends ZscriptResponse> {
void accept(T resp);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zscript.javaclient.zcodeApi;
package net.zscript.javaclient.zscriptapi;

import java.util.Iterator;
import java.util.NoSuchElementException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import net.zscript.javareceiver.execution.ZscriptField;

/**
* Defines the operations on the response OutStream available to a command via the ZcodeCommandContext.
* Defines the operations on the response OutStream available to a command via the CommandContext.
*/
public interface ZscriptCommandOutStream {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class ZscriptLocks {
public static final int LOCK_BYTENUM = 32;
private final byte[] locks = new byte[LOCK_BYTENUM];
private final byte[] locks = new byte[LOCK_BYTENUM];

public boolean lock(LockSet l) {
if (!canLock(l)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void activate() {
contextView.activate();
}

public Zscript getZcode() {
public Zscript getZscript() {
return zscript;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ private static int getVersion() {
public String platformFirmwareStr = "Java JRE " + System.getProperty("java.runtime.version");
public int platformHardwareVersion = 0;
public String platformHardwareStr = System.getProperty("os.arch") + " " + System.getProperty("os.name");
public int coreZcodeVersion = 0;
public String coreZcodeStr = "Prototype parsing/running system for JVM";
public int coreZscriptVersion = 0;
public String coreZscriptStr = "Prototype parsing/running system for JVM";

public void execute(CommandContext ctx) {
ZscriptCommandOutStream out = ctx.getOutStream();
Expand All @@ -55,8 +55,8 @@ public void execute(CommandContext ctx) {
ver = platformHardwareVersion;
break;
case 4:
str = coreZcodeStr;
ver = coreZcodeVersion;
str = coreZscriptStr;
ver = coreZscriptVersion;
break;
}
if (str != null) {
Expand All @@ -68,7 +68,7 @@ public void execute(CommandContext ctx) {
ctx.status(ZscriptStatus.VALUE_OUT_OF_RANGE);
}
out.writeField('C', ZscriptCoreModule.getCommands());
out.writeField('M', ctx.getZcode().getModuleRegistry().getCommandSwitchExistsBottom(0));
out.writeField('M', ctx.getZscript().getModuleRegistry().getCommandSwitchExistsBottom(0));
}

}
Loading

0 comments on commit d2e6441

Please sign in to comment.