From 62b4952dedb0f1db10044d6bd729defff2e868a4 Mon Sep 17 00:00:00 2001 From: susanw1 Date: Mon, 20 Nov 2023 14:37:34 +0000 Subject: [PATCH] [#143] Updated script-space module to use generated C++ defs --- .../ScriptSpaceCapabilitiesCommand.hpp | 9 +++---- .../modules/scriptSpace/ScriptSpaceModule.hpp | 8 +++++-- .../scriptSpace/ScriptSpaceSetupCommand.hpp | 24 +++++++++++-------- .../scriptSpace/ScriptSpaceWriteCommand.hpp | 22 +++++++++++------ 4 files changed, 40 insertions(+), 23 deletions(-) diff --git a/receivers/native/generic-core/src/main/c++/zscript/modules/scriptSpace/ScriptSpaceCapabilitiesCommand.hpp b/receivers/native/generic-core/src/main/c++/zscript/modules/scriptSpace/ScriptSpaceCapabilitiesCommand.hpp index e0d3622b3..72c6e8103 100644 --- a/receivers/native/generic-core/src/main/c++/zscript/modules/scriptSpace/ScriptSpaceCapabilitiesCommand.hpp +++ b/receivers/native/generic-core/src/main/c++/zscript/modules/scriptSpace/ScriptSpaceCapabilitiesCommand.hpp @@ -9,6 +9,8 @@ #define SRC_MAIN_C___ZSCRIPT_MODULES_SCRIPTSPACE_SCRIPTSPACECAPABILITIESCOMMAND_HPP_ #include "../../ZscriptIncludes.hpp" + +#include #include "../../execution/ZscriptCommandContext.hpp" #include "../ZscriptModule.hpp" @@ -19,14 +21,13 @@ namespace Zscript { namespace GenericCore { template -class ScriptSpaceCapabilitiesCommand { +class ScriptSpaceCapabilitiesCommand: public script_space_module::Capabilities_CommandDefs { public: static void execute(ZscriptCommandContext ctx) { CommandOutStream out = ctx.getOutStream(); - out.writeField('C', MODULE_CAPABILITIES(002)); - out.writeField('P', Zscript::zscript.getScriptSpaceCount()); - + out.writeField(RespCommandsSet__C, MODULE_CAPABILITIES(002)); + out.writeField(RespScriptSpaceCount__P, Zscript::zscript.getScriptSpaceCount()); } }; diff --git a/receivers/native/generic-core/src/main/c++/zscript/modules/scriptSpace/ScriptSpaceModule.hpp b/receivers/native/generic-core/src/main/c++/zscript/modules/scriptSpace/ScriptSpaceModule.hpp index 9998aa712..eaeb59e0e 100644 --- a/receivers/native/generic-core/src/main/c++/zscript/modules/scriptSpace/ScriptSpaceModule.hpp +++ b/receivers/native/generic-core/src/main/c++/zscript/modules/scriptSpace/ScriptSpaceModule.hpp @@ -18,17 +18,18 @@ #define MODULE_EXISTS_002 EXISTENCE_MARKER_UTIL #define MODULE_SWITCH_002 MODULE_SWITCH_UTIL(ScriptSpaceModule::execute) + #include "ScriptSpaceSetupCommand.hpp" #include "ScriptSpaceWriteCommand.hpp" #include "ScriptSpaceCapabilitiesCommand.hpp" namespace Zscript { + namespace GenericCore { + template class ScriptSpaceModule: public ZscriptModule { - public: - static void execute(ZscriptCommandContext ctx, uint8_t bottomBits) { switch (bottomBits) { case 0x0: @@ -47,8 +48,11 @@ class ScriptSpaceModule: public ZscriptModule { } }; + } + } + #define ZSCRIPT_SUPPORT_SCRIPT_SPACE #define ZSCRIPT_SUPPORT_NOTIFICATIONS diff --git a/receivers/native/generic-core/src/main/c++/zscript/modules/scriptSpace/ScriptSpaceSetupCommand.hpp b/receivers/native/generic-core/src/main/c++/zscript/modules/scriptSpace/ScriptSpaceSetupCommand.hpp index de283640f..c35600f34 100644 --- a/receivers/native/generic-core/src/main/c++/zscript/modules/scriptSpace/ScriptSpaceSetupCommand.hpp +++ b/receivers/native/generic-core/src/main/c++/zscript/modules/scriptSpace/ScriptSpaceSetupCommand.hpp @@ -9,52 +9,56 @@ #define SRC_MAIN_C___ZSCRIPT_MODULES_SCRIPTSPACE_SCRIPTSPACESETUPCOMMAND_HPP_ #include "../../ZscriptIncludes.hpp" + +#include #include "../../execution/ZscriptCommandContext.hpp" #include "../ZscriptModule.hpp" #define COMMAND_EXISTS_0021 EXISTENCE_MARKER_UTIL namespace Zscript { + template class ScriptSpace; namespace GenericCore { + template -class ScriptSpaceSetupCommand { +class ScriptSpaceSetupCommand: public script_space_module::ScriptSpaceSetup_CommandDefs { public: - static void execute(ZscriptCommandContext ctx) { uint16_t spaceIndex = 0; - if (!ctx.getField('P', &spaceIndex)) { + if (!ctx.getField(ReqScriptSpaceId__P, &spaceIndex)) { ctx.status(ResponseStatus::MISSING_KEY); return; } else if (spaceIndex >= Zscript::zscript.getScriptSpaceCount()) { ctx.status(ResponseStatus::VALUE_OUT_OF_RANGE); return; } + CommandOutStream out = ctx.getOutStream(); ScriptSpace *target = Zscript::zscript.getScriptSpaces()[spaceIndex]; - out.writeField('P', target->getCurrentLength()); + out.writeField(RespCurrentWritePosition__P, target->getCurrentLength()); if (target->isRunning()) { - out.writeField('R', 0); + out.writeField(RespRunning__R, 0); } if (target->canBeWrittenTo()) { - out.writeField('W', 0); + out.writeField(RespWriteAllowed__W, 0); } - out.writeField('L', target->getMaxLength()); + out.writeField(RespAvailableLength__L, target->getMaxLength()); uint16_t runOpt = 0; - if (ctx.getField('R', &runOpt)) { + if (ctx.getField(ReqRun__R, &runOpt)) { if (runOpt != 0) { target->run(); } else { target->stop(); } } - } - }; + } + } #endif /* SRC_MAIN_C___ZSCRIPT_MODULES_SCRIPTSPACE_SCRIPTSPACESETUPCOMMAND_HPP_ */ diff --git a/receivers/native/generic-core/src/main/c++/zscript/modules/scriptSpace/ScriptSpaceWriteCommand.hpp b/receivers/native/generic-core/src/main/c++/zscript/modules/scriptSpace/ScriptSpaceWriteCommand.hpp index d7e4a2951..1d7f07317 100644 --- a/receivers/native/generic-core/src/main/c++/zscript/modules/scriptSpace/ScriptSpaceWriteCommand.hpp +++ b/receivers/native/generic-core/src/main/c++/zscript/modules/scriptSpace/ScriptSpaceWriteCommand.hpp @@ -7,20 +7,26 @@ #ifndef SRC_MAIN_C___ZSCRIPT_MODULES_SCRIPTSPACE_SCRIPTSPACEWRITECOMMAND_HPP_ #define SRC_MAIN_C___ZSCRIPT_MODULES_SCRIPTSPACE_SCRIPTSPACEWRITECOMMAND_HPP_ + #include "../../ZscriptIncludes.hpp" + +#include #include "../../execution/ZscriptCommandContext.hpp" #include "../ZscriptModule.hpp" #include "../../tokenizer/ZscriptTokenizer.hpp" + #define COMMAND_EXISTS_0022 EXISTENCE_MARKER_UTIL namespace Zscript { + template class ScriptSpace; namespace GenericCore { -template -class ScriptSpaceWriteCommand { +template +class ScriptSpaceWriteCommand: public script_space_module::ScriptSpaceWrite_CommandDefs { +private: static void writeToWriter(ZscriptCommandContext ctx, ScriptSpace *target, TokenRingBuffer writer) { ZscriptTokenizer tok(writer.getWriter(), 2); @@ -32,33 +38,35 @@ class ScriptSpaceWriteCommand { } target->commitChanges(&writer); } -public: +public: static void execute(ZscriptCommandContext ctx) { uint16_t spaceIndex; - if (!ctx.getField('P', &spaceIndex)) { + if (!ctx.getField(ReqScriptSpaceId__P, &spaceIndex)) { ctx.status(ResponseStatus::MISSING_KEY); return; } else if (spaceIndex >= Zscript::zscript.getScriptSpaceCount()) { ctx.status(ResponseStatus::VALUE_OUT_OF_RANGE); return; } + CommandOutStream out = ctx.getOutStream(); ScriptSpace *target = Zscript::zscript.getScriptSpaces()[spaceIndex]; if (target->isRunning()) { ctx.status(ResponseStatus::COMMAND_FAIL); return; } - if (ctx.hasField('R')) { + if (ctx.hasField(ReqReset__R)) { writeToWriter(ctx, target, target->overwrite()); } else { writeToWriter(ctx, target, target->append()); } - out.writeField('L', target->getRemainingLength()); + out.writeField(RespAvailableLength__L, target->getRemainingLength()); } - }; + } + } #endif /* SRC_MAIN_C___ZSCRIPT_MODULES_SCRIPTSPACE_SCRIPTSPACEWRITECOMMAND_HPP_ */