Skip to content

Commit

Permalink
[#72] More 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 cbe61cc commit ca723b6
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 71 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ZCODE
ZSCRIPT
===

##### What Is It?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
import java.util.HashMap;
import java.util.Map;

import net.zscript.model.datamodel.ZcodeDataModel.CommandModel;
import net.zscript.model.datamodel.ZcodeDataModel.ModuleModel;
import net.zscript.model.datamodel.ZscriptDataModel.CommandModel;
import net.zscript.model.datamodel.ZscriptDataModel.ModuleModel;
import net.zscript.model.loader.ModelLoader;
import net.zscript.model.loader.ModuleBank;

public class Zcode {
public class Zscript {

private Map<String, ModuleBank> moduleBanks;

private Zcode(ModelLoader modelLoader) {
private Zscript(ModelLoader modelLoader) {
moduleBanks = modelLoader.getModuleBanks();
}

public static Zcode forModel(ModelLoader modelLoader) {
return new Zcode(modelLoader);
public static Zscript forModel(ModelLoader modelLoader) {
return new Zscript(modelLoader);
}

public ModuleCommandFinder forModule(String moduleBankName, String moduleName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package net.zscript.javaclient.builders;

public class ZcodeModelException extends RuntimeException {
public class ZscriptModelException extends RuntimeException {
private static final long serialVersionUID = 1L;

public ZcodeModelException(String msg, Throwable cause) {
public ZscriptModelException(String msg, Throwable cause) {
super(msg, cause);
}

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

public interface ZcodeModule {
public interface ZscriptModule {
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

import net.zscript.javaclient.builders.Command;
import net.zscript.javaclient.builders.Response;
import net.zscript.javaclient.builders.Zcode;
import net.zscript.javaclient.builders.Zscript;
import net.zscript.model.loader.ModelLoader;

class ZcodeTest {
class ZscriptTest {

@BeforeEach
void setUp() throws Exception {
Expand All @@ -23,14 +23,14 @@ void setUp() throws Exception {
@Test
void shouldMakeCommandUsingNames() {
final ModelLoader modelLoader = ModelLoader.standardModel();
final Zcode zcode = Zcode.forModel(modelLoader);
final Zscript zscript = Zscript.forModel(modelLoader);

final Command c = zcode.forModule("Base", "Core")
final Command c = zscript.forModule("Base", "Core")
.makeCommand("activate")
.setField("key", 123)
.build();

final Response r = zcode.parseResponse(c, "SA1");
final Response r = zscript.parseResponse(c, "SA1");

assertThat(r.getResponseParamByKey('A', Optional.class)).hasValue(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import java.util.List;

import net.zscript.model.datamodel.ZcodeDataModel.RequestParamModel;
import net.zscript.model.datamodel.ZcodeDataModel.ResponseParamModel;
import net.zscript.model.datamodel.ZcodeDataModel.StatusModel;
import net.zscript.model.datamodel.ZscriptDataModel.RequestParamModel;
import net.zscript.model.datamodel.ZscriptDataModel.ResponseParamModel;
import net.zscript.model.datamodel.ZscriptDataModel.StatusModel;

public interface IntrinsicsDataModel {
Intrinsics getIntrinsics();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import com.fasterxml.jackson.annotation.JsonTypeInfo;

public interface ZcodeDataModel {
public interface ZscriptDataModel {
List<ModuleModel> getModules();

interface ModuleModel {
Expand Down
20 changes: 10 additions & 10 deletions model/src/main/java/net/zscript/model/loader/ModelLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
import com.fasterxml.jackson.module.mrbean.MrBeanModule;

import net.zscript.model.datamodel.DefinitionResources;
import net.zscript.model.datamodel.IntrinsicsDataModel;
import net.zscript.model.datamodel.ZcodeDataModel;
import net.zscript.model.datamodel.DefinitionResources.ModuleBankDef;
import net.zscript.model.datamodel.ZcodeDataModel.CommandModel;
import net.zscript.model.datamodel.ZcodeDataModel.GenericParam;
import net.zscript.model.datamodel.ZcodeDataModel.ModuleModel;
import net.zscript.model.datamodel.IntrinsicsDataModel;
import net.zscript.model.datamodel.ZscriptDataModel;
import net.zscript.model.datamodel.ZscriptDataModel.CommandModel;
import net.zscript.model.datamodel.ZscriptDataModel.GenericParam;
import net.zscript.model.datamodel.ZscriptDataModel.ModuleModel;

public class ModelLoader {
private JsonMapper jsonMapper;
private final JsonMapper jsonMapper;
private IntrinsicsDataModel intrinsicsDataModel;

private Map<String, ModuleBank> moduleBanks = new HashMap<>();
private final Map<String, ModuleBank> moduleBanks = new HashMap<>();

public static ModelLoader rawModel() {
return new ModelLoader();
Expand Down Expand Up @@ -67,10 +67,10 @@ public ModelLoader withModel(URL moduleListRoot) throws IOException {
ModuleBank moduleBank = moduleBanks.computeIfAbsent(mb.getName(), n -> new ModuleBank(mb));

for (String moduleDefinitionLocation : mb.getModuleDefinitions()) {
URL moduleDefinition = new URL(moduleListRoot, moduleDefinitionLocation);
ZcodeDataModel model;
URL moduleDefinition = new URL(moduleListRoot, moduleDefinitionLocation);
ZscriptDataModel model;
try (final InputStream openStream = moduleDefinition.openStream()) {
model = jsonMapper.readValue(openStream, ZcodeDataModel.class);
model = jsonMapper.readValue(openStream, ZscriptDataModel.class);
}
for (ModuleModel mm : model.getModules()) {
mm.setModuleBank(moduleBank);
Expand Down
4 changes: 2 additions & 2 deletions model/src/main/java/net/zscript/model/loader/ModuleBank.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.Map;

import net.zscript.model.datamodel.DefinitionResources.ModuleBankDef;
import net.zscript.model.datamodel.ZcodeDataModel.ModuleModel;
import net.zscript.model.datamodel.ZscriptDataModel.ModuleModel;

public class ModuleBank {
final ModuleBankDef mbDef;
Expand All @@ -30,4 +30,4 @@ public int getId() {
public ModuleModel getModule(String name) {
return modules.get(name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ modules:
description: selects which ident/version info to return
typeDefinition:
'@type': enum
allowedValues: [UserFirmware, UserHardware, PlatformFirmware, PlatformHardware, CoreZcodeLanguage]
allowedValues: [UserFirmware, UserHardware, PlatformFirmware, PlatformHardware, CoreZscriptLanguage]
required: no
responseParams:
- label: C
Expand Down Expand Up @@ -85,7 +85,7 @@ modules:

- name: activate
command: 2
description: Activates zcode system, allowing commands 0x10 onwards to be executed
description: Activates zscript system, allowing commands 0x10 onwards to be executed
operation: put
requestParams:
- label: K
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.module.mrbean.MrBeanModule;

import net.zscript.model.datamodel.ZcodeDataModel;
import net.zscript.model.datamodel.ZscriptDataModel;

public class ModuleTest {
private JsonMapper jsonMapper;
Expand All @@ -36,7 +36,7 @@ public void setup() {
})
public void shouldLoad_000x(String module, String expectedName) throws IOException {
InputStream resourceStream = requireNonNull(getClass().getResourceAsStream("/datamodel/00xx-base-modules/" + module), "resourceStream");
ZcodeDataModel model = jsonMapper.readValue(resourceStream, ZcodeDataModel.class);
ZscriptDataModel model = jsonMapper.readValue(resourceStream, ZscriptDataModel.class);

assertThat(model.getModules().get(0).getName()).isEqualTo(expectedName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.zscript.javasimulator.ProtocolCategory;
import net.zscript.javasimulator.ProtocolConnection;

public interface ZcodeSimulatorConsumer<U extends ProtocolCategory> {
public interface SimulatorConsumer<U extends ProtocolCategory> {

<T extends ProtocolConnection<U, T>> CommunicationResponse<T> acceptPacket(int index, CommunicationPacket<T> packet);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import net.zscript.javasimulator.ProtocolCategory;
import net.zscript.javasimulator.ProtocolConnection;

public class ZcodeEntityController extends EntityController {
private final Map<Class<? extends ProtocolConnection<?, ?>>, List<ZcodeSimulatorConsumer<? extends ProtocolCategory>>> modules = new HashMap<>();
public class ZscriptEntityController extends EntityController {
private final Map<Class<? extends ProtocolConnection<?, ?>>, List<SimulatorConsumer<? extends ProtocolCategory>>> modules = new HashMap<>();
private final ExecutorService mainExec = Executors.newSingleThreadExecutor();
private final ExecutorService interruptExec = Executors.newSingleThreadExecutor();
private final Thread mainCurrent = findCurrentMain();
Expand Down Expand Up @@ -132,17 +132,17 @@ public boolean hasActivity() {
return switchToMainThread(() -> hasNonWait);
}

public ZcodeEntityController() {
public ZscriptEntityController() {
addModule(new ZscriptCoreModule());
addModule(new ZscriptOuterCoreModule());
mainExec.submit(new ProgressForever());
}

public <U extends ProtocolCategory> void add(ZcodeSimulatorConsumer<U> consumer, int index) {
public <U extends ProtocolCategory> void add(SimulatorConsumer<U> consumer, int index) {
switchToInterruptThread(() -> {
for (Class<? extends ProtocolConnection<U, ?>> connection : consumer.getConnections()) {
modules.putIfAbsent(connection, new ArrayList<>());
List<ZcodeSimulatorConsumer<? extends ProtocolCategory>> list = modules.get(connection);
List<SimulatorConsumer<? extends ProtocolCategory>> list = modules.get(connection);
while (list.size() <= index) {
list.add(null);
}
Expand All @@ -160,16 +160,16 @@ public void addModule(ZscriptModule module) {
}

@SuppressWarnings("unchecked")
private <U extends ProtocolCategory, T extends ProtocolConnection<U, T>> ZcodeSimulatorConsumer<U> getModule(Class<T> type, int index) {
private <U extends ProtocolCategory, T extends ProtocolConnection<U, T>> SimulatorConsumer<U> getModule(Class<T> type, int index) {
hasNonWait = true;
return (ZcodeSimulatorConsumer<U>) modules.get(type).get(index);
return (SimulatorConsumer<U>) modules.get(type).get(index);
}

@Override
public <U extends ProtocolCategory, T extends ProtocolConnection<U, T>> CommunicationResponse<T> acceptIncoming(Class<U> type, int index, CommunicationPacket<T> packet) {
try {
return switchToInterruptThread(() -> {
ZcodeSimulatorConsumer<U> consumer = getModule(packet.getProtocolConnectionType(), index);
SimulatorConsumer<U> consumer = getModule(packet.getProtocolConnectionType(), index);

if (consumer == null) {
return new BlankCommunicationResponse<>(packet.getProtocolConnectionType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.zscript.javasimulator.connections.i2c.I2cResponse;
import net.zscript.javasimulator.connections.i2c.I2cSendPacket;

public class ZcodeI2cAddressAction {
public class I2cAddressAction {
public static void execute(AddressingContext ctx, I2cModule module) {
Entity entity = module.getEntity();
OptIterator<Integer> it = ctx.getAddressSegments();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.zscript.javasimulator.Entity;
import net.zscript.javasimulator.connections.i2c.I2cProtocolCategory;

public class ZcodeI2cCapabilitiesCommand {
public class I2cCapabilitiesCommand {

public static void execute(CommandContext ctx, Entity entity) {
ZscriptCommandOutStream out = ctx.getOutStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import java.util.concurrent.ConcurrentLinkedQueue;

import net.zscript.javareceiver.core.AbstractOutStream;
import net.zscript.javareceiver.core.ZscriptChannel;
import net.zscript.javareceiver.core.OutStream;
import net.zscript.javareceiver.core.ZscriptChannel;
import net.zscript.javareceiver.execution.CommandContext;
import net.zscript.javareceiver.tokenizer.TokenBuffer;
import net.zscript.javareceiver.tokenizer.TokenRingBuffer;
Expand All @@ -26,14 +26,14 @@
import net.zscript.javasimulator.connections.i2c.I2cSendResponse;
import net.zscript.javasimulator.connections.i2c.SmBusAlertConnection;
import net.zscript.javasimulator.connections.i2c.SmBusAlertPacket;
import net.zscript.javasimulator.zcode.ZcodeSimulatorConsumer;
import net.zscript.javasimulator.zcode.SimulatorConsumer;

public class I2cChannel extends ZscriptChannel implements ZcodeSimulatorConsumer<I2cProtocolCategory> {
private final Entity e;
private final I2cAddress addr;
private final Tokenizer in;
private final Queue<byte[]> outQueue;
private int cachePos = 0;
public class I2cChannel extends ZscriptChannel implements SimulatorConsumer<I2cProtocolCategory> {
private final Entity e;
private final I2cAddress addr;
private final Tokenizer in;
private final Queue<byte[]> outQueue;
private int cachePos = 0;

public static I2cChannel build(Entity e, I2cAddress addr, int index, int size) {
Queue<byte[]> outQueue = new ConcurrentLinkedQueue<>();
Expand Down Expand Up @@ -126,9 +126,8 @@ public <T extends ProtocolConnection<I2cProtocolCategory, T>> CommunicationRespo
cache = outQueue.peek();
cachePos = 0;
break;
} else {
data[dataIndex++] = cache[cachePos++];
}
data[dataIndex++] = cache[cachePos++];
}
if (cache != null && cachePos == cache.length) {
outQueue.poll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ public int getModuleID() {
public void execute(CommandContext ctx, int command) {
switch (command) {
case 0:
ZcodeI2cCapabilitiesCommand.execute(ctx, entity);
I2cCapabilitiesCommand.execute(ctx, entity);
break;
case 1:
ZcodeI2cSetupCommand.execute(ctx, this);
I2cSetupCommand.execute(ctx, this);
break;
case 2:
ZcodeI2cSendCommand.execute(ctx, this);
I2cSendCommand.execute(ctx, this);
break;
case 3:
ZcodeI2cReadCommand.execute(ctx, this);
I2cReadCommand.execute(ctx, this);
break;

default:
Expand All @@ -58,7 +58,7 @@ public void execute(CommandContext ctx, int command) {

@Override
public void address(AddressingContext ctx) {
ZcodeI2cAddressAction.execute(ctx, this);
I2cAddressAction.execute(ctx, this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import net.zscript.javasimulator.connections.i2c.I2cResponse;
import net.zscript.javasimulator.connections.i2c.SmBusAlertConnection;
import net.zscript.javasimulator.connections.i2c.SmBusAlertPacket;
import net.zscript.javasimulator.zcode.ZcodeSimulatorConsumer;
import net.zscript.javasimulator.zcode.SimulatorConsumer;

public class I2cNotificationHandler implements ZcodeSimulatorConsumer<I2cProtocolCategory> {
public class I2cNotificationHandler implements SimulatorConsumer<I2cProtocolCategory> {
private static final int CHUNK_LENGTH = 8;
private final ZscriptNotificationSource source = new ZscriptNotificationSource();
private int notificationSet = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.zscript.javasimulator.connections.i2c.I2cReceiveResponse;
import net.zscript.javasimulator.connections.i2c.I2cResponse;

public class ZcodeI2cReadCommand {
public class I2cReadCommand {

public static void execute(CommandContext ctx, I2cModule module) {
Entity entity = module.getEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.zscript.javasimulator.connections.i2c.I2cResponse;
import net.zscript.javasimulator.connections.i2c.I2cSendPacket;

public class ZcodeI2cSendCommand {
public class I2cSendCommand {

public static void execute(CommandContext ctx, I2cModule module) {
Entity entity = module.getEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.zscript.javareceiver.execution.CommandContext;
import net.zscript.javasimulator.connections.i2c.I2cProtocolCategory;

public class ZcodeI2cSetupCommand {
public class I2cSetupCommand {

public static void execute(CommandContext ctx, I2cModule module) {
ZscriptCommandOutStream out = ctx.getOutStream();
Expand Down
Loading

0 comments on commit ca723b6

Please sign in to comment.