Skip to content

Commit

Permalink
[#72] Zcode filenames to Zscript
Browse files Browse the repository at this point in the history
  • Loading branch information
susanw1 committed Aug 1, 2023
1 parent 34dac28 commit 7fc0c65
Show file tree
Hide file tree
Showing 77 changed files with 608 additions and 612 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import net.zscript.javaclient.zcodeApi.ZcodeUnparsedCommandResponse;
import net.zscript.javaclient.zcodeApi.ZcodeCommand.ZcodeSequencePath;
import net.zscript.javareceiver.tokenizer.OptIterator;
import net.zscript.javareceiver.tokenizer.ZcodeTokenBuffer;
import net.zscript.javareceiver.tokenizer.ZcodeTokenExtendingBuffer;
import net.zscript.javareceiver.tokenizer.ZcodeTokenizer;
import net.zscript.javareceiver.tokenizer.ZcodeTokenBuffer.TokenReader;
import net.zscript.javareceiver.tokenizer.ZcodeTokenBuffer.TokenReader.ReadToken;
import net.zscript.javareceiver.tokenizer.TokenBuffer;
import net.zscript.javareceiver.tokenizer.TokenExtendingBuffer;
import net.zscript.javareceiver.tokenizer.Tokenizer;
import net.zscript.javareceiver.tokenizer.TokenBuffer.TokenReader;
import net.zscript.javareceiver.tokenizer.TokenBuffer.TokenReader.ReadToken;

public class ZcodeResponseParser {
static class ResponseHeader {
Expand Down Expand Up @@ -44,8 +44,8 @@ public int getEcho() {
}

public static ResponseHeader parseResponseHeader(byte[] resp) {
final ZcodeTokenBuffer buffer = new ZcodeTokenExtendingBuffer();
final ZcodeTokenizer in = new ZcodeTokenizer(buffer.getTokenWriter(), 4);
final TokenBuffer buffer = new TokenExtendingBuffer();
final Tokenizer in = new Tokenizer(buffer.getTokenWriter(), 4);
final TokenReader reader = buffer.getTokenReader();

ReadToken lastWritten = null;
Expand Down Expand Up @@ -95,15 +95,15 @@ public static ResponseHeader parseResponseHeader(byte[] resp) {
}

private static byte convertMarkers(byte encoded) {
if (encoded == ZcodeTokenizer.CMD_END_ANDTHEN) {
if (encoded == Tokenizer.CMD_END_ANDTHEN) {
return '&';
} else if (encoded == ZcodeTokenizer.CMD_END_ORELSE) {
} else if (encoded == Tokenizer.CMD_END_ORELSE) {
return '|';
} else if (encoded == ZcodeTokenizer.CMD_END_OPEN_PAREN) {
} else if (encoded == Tokenizer.CMD_END_OPEN_PAREN) {
return '(';
} else if (encoded == ZcodeTokenizer.CMD_END_CLOSE_PAREN) {
} else if (encoded == Tokenizer.CMD_END_CLOSE_PAREN) {
return ')';
} else if (encoded == ZcodeTokenizer.NORMAL_SEQUENCE_END) {
} else if (encoded == Tokenizer.NORMAL_SEQUENCE_END) {
return '\n';
} else {
throw new IllegalArgumentException("Unknown marker: " + Integer.toHexString(Byte.toUnsignedInt(encoded)));
Expand All @@ -112,8 +112,8 @@ private static byte convertMarkers(byte encoded) {

// TODO: Trim the sequence level stuff off of first command
public static void parseFullResponse(final CommandSeqElement command, final byte[] responce) {
final ZcodeTokenBuffer buffer = new ZcodeTokenExtendingBuffer();
final ZcodeTokenizer in = new ZcodeTokenizer(buffer.getTokenWriter(), 4);
final TokenBuffer buffer = new TokenExtendingBuffer();
final Tokenizer in = new Tokenizer(buffer.getTokenWriter(), 4);
for (final byte b : responce) {
in.accept(b);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.zscript.javareceiver.tokenizer.BlockIterator;
import net.zscript.javareceiver.tokenizer.OptIterator;
import net.zscript.javareceiver.tokenizer.Zchars;
import net.zscript.javareceiver.tokenizer.ZcodeTokenBuffer.TokenReader.ReadToken;
import net.zscript.javareceiver.tokenizer.TokenBuffer.TokenReader.ReadToken;

public class ZcodeUnparsedCommandResponse {
private final ReadToken first;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import java.nio.charset.StandardCharsets;

import net.zscript.javareceiver.execution.ZcodeField;
import net.zscript.javareceiver.execution.ZscriptField;
import net.zscript.javareceiver.tokenizer.BlockIterator;
import net.zscript.javareceiver.tokenizer.Zchars;

public abstract class ZcodeAbstractOutStream implements ZcodeOutStream, ZcodeCommandOutStream {
public abstract class AbstractOutStream implements OutStream, ZscriptCommandOutStream {
/**
* @param bytes the bytes to write
* @param count how many of the bytes to write
Expand Down Expand Up @@ -94,7 +94,7 @@ public void writeField(byte field, int value) {
}

@Override
public void writeField(ZcodeField field) {
public void writeField(ZscriptField field) {
if (field.isBigField()) {
if (field.getKey() == Zchars.Z_BIGFIELD_QUOTED) {
writeCharAsByte('"');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.zscript.javareceiver.core;

import java.util.Iterator;

public class LockSet {
private final byte[] locks;

public static LockSet from(Iterator<Byte> data) {
byte[] locks = new byte[ZscriptLocks.LOCK_BYTENUM];

int i = 0;
for (Iterator<Byte> iterator = data; i < ZscriptLocks.LOCK_BYTENUM && iterator.hasNext();) {
locks[i++] = iterator.next();
}
return new LockSet(locks);
}

public static LockSet empty() {
byte[] locks = new byte[ZscriptLocks.LOCK_BYTENUM];
for (int i = 0; i < locks.length; i++) {
locks[i] = (byte) 0;
}
return new LockSet(locks);
}

public static LockSet allLocked() {
byte[] locks = new byte[ZscriptLocks.LOCK_BYTENUM];
for (int i = 0; i < locks.length; i++) {
locks[i] = (byte) 0xFF;
}
return new LockSet(locks);
}

private LockSet(byte[] locks) {
this.locks = locks;
}

byte[] getLocks() {
return locks;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Defines the sequence-level life-cycle operations that allow responses to be sent back up to a channel.
*/
public interface ZcodeOutStream {
public interface OutStream {

/**
* Opens the stream. Until it is opened, other operations are undefined. Calling open() may perform tasks such as allocating buffers, establishing upstream connections etc.
Expand Down Expand Up @@ -41,7 +41,7 @@ public interface ZcodeOutStream {
*
* @return a command-oriented output stream
*/
default ZcodeCommandOutStream asCommandOutStream() {
return (ZcodeCommandOutStream) this;
default ZscriptCommandOutStream asCommandOutStream() {
return (ZscriptCommandOutStream) this;
};
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
import java.util.List;

import net.zscript.javareceiver.execution.ActionSource;
import net.zscript.javareceiver.execution.ZcodeExecutor;
import net.zscript.javareceiver.modules.ZcodeModule;
import net.zscript.javareceiver.modules.ZcodeModuleRegistry;
import net.zscript.javareceiver.notifications.ZcodeNotificationSource;
import net.zscript.javareceiver.execution.ZscriptExecutor;
import net.zscript.javareceiver.modules.ZscriptModule;
import net.zscript.javareceiver.modules.ZscriptModuleRegistry;
import net.zscript.javareceiver.notifications.ZscriptNotificationSource;

public class Zscript {
private final ZcodeModuleRegistry moduleRegistry = new ZcodeModuleRegistry();
private final ZcodeLocks locks = new ZcodeLocks();
private final List<ZcodeChannel> channels = new ArrayList<>();
private final ZscriptModuleRegistry moduleRegistry = new ZscriptModuleRegistry();
private final ZscriptLocks locks = new ZscriptLocks();
private final List<ZscriptChannel> channels = new ArrayList<>();
private final List<ActionSource> sources = new ArrayList<>();
private final ZcodeExecutor executor;
private final ZscriptExecutor executor;

private ZcodeOutStream notificationOutStream = new ZcodeAbstractOutStream() {
private OutStream notificationOutStream = new AbstractOutStream() {
private boolean open = false;

@Override
Expand All @@ -42,55 +42,55 @@ protected void writeBytes(byte[] bytes, int count, boolean hexMode) {
};

public Zscript() {
executor = new ZcodeExecutor(this);
executor = new ZscriptExecutor(this);
}

public void addModule(ZcodeModule m) {
public void addModule(ZscriptModule m) {
moduleRegistry.addModule(m);
}

public void addChannel(ZcodeChannel ch) {
public void addChannel(ZscriptChannel ch) {
ch.setChannelIndex((byte) channels.size());
channels.add(ch);
sources.add(ch);
}

public void addNotificationSource(ZcodeNotificationSource s) {
public void addNotificationSource(ZscriptNotificationSource s) {
sources.add(s);
}

public boolean lock(ZcodeLockSet l) {
public boolean lock(LockSet l) {
return locks.lock(l);
}

public boolean canLock(ZcodeLockSet l) {
public boolean canLock(LockSet l) {
return locks.canLock(l);
}

public void unlock(ZcodeLockSet l) {
public void unlock(LockSet l) {
locks.unlock(l);
}

public boolean progress() {
for (ZcodeChannel channel : channels) {
for (ZscriptChannel channel : channels) {
channel.moveAlong();
}
return executor.progress(sources);
}

public List<ZcodeChannel> getChannels() {
public List<ZscriptChannel> getChannels() {
return channels;
}

public ZcodeModuleRegistry getModuleRegistry() {
public ZscriptModuleRegistry getModuleRegistry() {
return moduleRegistry;
}

public ZcodeOutStream getNotificationOutStream() {
public OutStream getNotificationOutStream() {
return notificationOutStream;
}

public void setNotificationOutStream(ZcodeOutStream out) {
public void setNotificationOutStream(OutStream out) {
this.notificationOutStream = out;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
import net.zscript.javareceiver.semanticParser.ExecutionActionFactory;
import net.zscript.javareceiver.semanticParser.SemanticParser;
import net.zscript.javareceiver.semanticParser.SemanticAction;
import net.zscript.javareceiver.tokenizer.ZcodeTokenBuffer;
import net.zscript.javareceiver.tokenizer.TokenBuffer;

public abstract class ZcodeChannel implements ActionSource {
public abstract class ZscriptChannel implements ActionSource {
protected final SemanticParser p;
protected final ZcodeOutStream out;
protected final OutStream out;

public ZcodeChannel(final SemanticParser p, final ZcodeOutStream out) {
public ZscriptChannel(final SemanticParser p, final OutStream out) {
this.p = p;
this.out = out;
}

public ZcodeChannel(final ZcodeTokenBuffer buffer, final ZcodeOutStream out) {
public ZscriptChannel(final TokenBuffer buffer, final OutStream out) {
this(new SemanticParser(buffer.getTokenReader(), new ExecutionActionFactory()), out);
}

Expand All @@ -25,7 +25,7 @@ public SemanticParser getParser() {
}

@Override
public ZcodeOutStream getOutStream(Zscript zscript) {
public OutStream getOutStream(Zscript zscript) {
return out;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package net.zscript.javareceiver.core;

import net.zscript.javareceiver.execution.ZcodeField;
import net.zscript.javareceiver.execution.ZscriptField;

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

void writeField(byte field, int value);

default void writeField(char field, int value) {
writeField((byte) field, value);
}

void writeField(ZcodeField field);
void writeField(ZscriptField field);

/**
* Writes the supplied string as a quoted Big Field. It is assumed to represent actual text and will be UTF-8 encoded. Forbidden chars (eg '\n', '"', '=', '\0') will be
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package net.zscript.javareceiver.core;

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

public boolean lock(ZcodeLockSet l) {
public boolean lock(LockSet l) {
if (!canLock(l)) {
return false;
}
Expand All @@ -15,7 +15,7 @@ public boolean lock(ZcodeLockSet l) {
return true;
}

public boolean canLock(ZcodeLockSet l) {
public boolean canLock(LockSet l) {
byte[] toApply = l.getLocks();
for (int i = 0; i < toApply.length; i++) {
if ((locks[i] & toApply[i]) != 0) {
Expand All @@ -25,7 +25,7 @@ public boolean canLock(ZcodeLockSet l) {
return true;
}

public void unlock(ZcodeLockSet l) {
public void unlock(LockSet l) {
byte[] toApply = l.getLocks();
for (int i = 0; i < toApply.length; i++) {
locks[i] &= ~toApply[i];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package net.zscript.javareceiver.execution;

import net.zscript.javareceiver.core.Zscript;
import net.zscript.javareceiver.core.ZcodeOutStream;
import net.zscript.javareceiver.core.OutStream;

public interface ActionSource {
ZcodeAction getAction();
ZscriptAction getAction();

ZcodeOutStream getOutStream(Zscript zscript);
OutStream getOutStream(Zscript zscript);
}
Loading

0 comments on commit 7fc0c65

Please sign in to comment.