Skip to content

Commit

Permalink
[#110] Ensure channel inclusion order is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
susanw1 committed Nov 10, 2023
1 parent 2c163cf commit 42225e6
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,22 @@
// INCLUDE ALL CHANNELS BELOW HERE!

#ifdef ZSCRIPT_HAVE_I2C_CHANNEL

#include <arduino/i2c-module/channels/I2cChannel.hpp>
#endif

#if defined(ZSCRIPT_HAVE_UART_CHANNEL)
#include "arduino/uart-module/channels/UartChannel.hpp"
#endif

#ifdef ZSCRIPT_HAVE_UDP_CHANNEL

#include <arduino/ethernet-module/channels/ZscriptUdpChannel.hpp>

#endif

#ifdef ZSCRIPT_HAVE_TCP_CHANNEL
#include <arduino/ethernet-module/channels/ZscriptTcpChannel.hpp>
Zscript::ZscriptTcpChannel<ZscriptParams> ZscriptTcpChannels[ZscriptParams::tcpChannelCount];
#endif

#if defined(ZSCRIPT_HAVE_UART_CHANNEL)

#include "arduino/uart-module/channels/UartChannel.hpp"

#endif

class ArduinoZscriptBasicSetup {
#if defined(ZSCRIPT_HAVE_UART_CHANNEL) or defined(ZSCRIPT_HAVE_I2C_CHANNEL) or defined(ZSCRIPT_HAVE_UDP_CHANNEL) or defined(ZSCRIPT_HAVE_TCP_CHANNEL)
Zscript::ZscriptChannel<ZscriptParams> *channels[0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
#ifndef SRC_MAIN_CPP_ARDUINO_SERIAL_MODULE_CHANNELS_ZSCRIPTSERIALCHANNEL_HPP_
#define SRC_MAIN_CPP_ARDUINO_SERIAL_MODULE_CHANNELS_ZSCRIPTSERIALCHANNEL_HPP_

#ifndef ZSCRIPT_HPP_INCLUDED
# error UartChannel.hpp needs to be included after Zscript.hpp
#endif

#include <ZscriptChannelBuilder.hpp>
#include "../../arduino-core-module/persistence/PersistenceSystem.hpp"

Expand Down Expand Up @@ -63,6 +59,8 @@ class UartChannel : public ZscriptChannel<ZP> {
uint8_t buffer[ZP::uartChannelBufferSize];
uint8_t tmp = 0;
bool usingTmp = false;
uint8_t currentFrequencyIndex;
uint8_t currentSerialMode;

public:
static uint8_t getNotifChannelPersistMaxLength() {
Expand All @@ -77,6 +75,11 @@ class UartChannel : public ZscriptChannel<ZP> {
Serial.begin(ZP::uartSupportedFreqs[0]);
}

uint8_t getCurrentFrequencyIndex() {
return currentFrequencyIndex;
}


bool setupStartupNotificationChannel() {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#define SRC_MAIN_CPP_ARDUINO_UART_MODULE_COMMANDS_ZSCRIPTUARTCAPABILITIESCOMMAND_HPP_

#include <zscript/modules/ZscriptCommand.hpp>
#include "UartUtil.hpp"
#include <net/zscript/model/components/ZscriptStatus.hpp>
#include <net/zscript/model/modules/base/UartModule.hpp>
#include "UartUtil.hpp"

#define COMMAND_EXISTS_0070 EXISTENCE_MARKER_UTIL

Expand All @@ -32,10 +32,10 @@ class ZscriptUartCapabilitiesCommand: public Capabilities_CommandDefs {
return;
}

out.writeField(RespCommandsSet__C, MODULE_CAPABILITIES(007));
UartUtil<ZP>::writeFrequencySelection(out, freqIndex);

// implements just a single Serial port at this time. Should be expanded to more...
out.writeField(RespCommandsSet__C, MODULE_CAPABILITIES(007));
out.writeField(RespInterfaceCount__I, ZP::uartCount);
out.writeField(RespFrequenciesSupported__F, freqCount);
out.writeField(RespBitsetCapabilities__B, static_cast<uint16_t>(RespBitsetCapabilities_Values::parityOn_field)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,36 @@

#include <zscript/modules/ZscriptCommand.hpp>
#include <net/zscript/model/modules/base/UartModule.hpp>
#include "UartUtil.hpp"

#define COMMAND_EXISTS_007c EXISTENCE_MARKER_UTIL

namespace Zscript {

template<class ZP>
class UartChannel;
class UartModule;

template<class ZP>
class UartModule;
class ZscriptChannel;

template<class ZP>
class UartChannel;

namespace uart_module {

template<class ZP>
class ZscriptUartChannelInfoCommand: public ChannelInfo_CommandDefs {
class ZscriptUartChannelInfoCommand : public ChannelInfo_CommandDefs {
public:
static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t channelIndex;
if (!ctx.getFieldCheckLimit(ReqChannel__C, Zscript<ZP>::zscript.getChannelCount(), ctx.getChannelIndex(), &channelIndex)) {
return;
}
UartChannel<ZP> *selectedChannel = Zscript<ZP>::zscript.getChannels()[channelIndex];
if (selectedChannel->getAssociatedModule() != MODULE) {
ctx.status(ResponseStatus::VALUE_OUT_OF_RANGE);
return;
}

constexpr uint8_t freqCount = sizeof(ZP::uartSupportedFreqs) / sizeof(ZP::uartSupportedFreqs[0]);
uint16_t freqIndex;
Expand All @@ -43,6 +52,11 @@ class ZscriptUartChannelInfoCommand: public ChannelInfo_CommandDefs {
out.writeField(RespChannelCount__N, 1);
out.writeField(RespChannel__C, UartModule<ZP>::channel.getParser()->getChannelIndex());
out.writeField(RespInterface__I, 0);
out.writeField(RespFrequenciesSupported__F, freqCount);
UartUtil<ZP>::writeFrequencySelection(out, freqIndex);
out.writeField(RespBitsetCapabilities__B, static_cast<uint16_t>(RespBitsetCapabilities_Values::parityOn_field)
| static_cast<uint16_t>(RespBitsetCapabilities_Values::doubleStop_field));

}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ class ZscriptUartChannelSetupCommand: public ChannelSetup_CommandDefs {
uint16_t channelIndex;
if (!ctx.getFieldCheckLimit(ReqChannel__C, Zscript<ZP>::zscript.getChannelCount(), ctx.getChannelIndex(), &channelIndex)) {
return;
}
ZscriptChannel<ZP> *selectedChannel = Zscript<ZP>::zscript.getChannels()[channelIndex];
if (selectedChannel->getAssociatedModule() != MODULE) {
ctx.status(ResponseStatus::VALUE_OUT_OF_RANGE);
return;
}

if (ctx.hasField(ReqFrequencySelection__F)) {

}
constexpr uint8_t freqCount = sizeof(ZP::uartSupportedFreqs) / sizeof(ZP::uartSupportedFreqs[0]);
uint16_t freqIndex;
Expand All @@ -38,15 +47,6 @@ class ZscriptUartChannelSetupCommand: public ChannelSetup_CommandDefs {
}


uint16_t address;
// if (ctx.getField(ReqAddress__A, &address)) {
// if (channel > 0x80) {
// ctx.status(ResponseStatus::VALUE_OUT_OF_RANGE);
// return;
// }
// UartModule<ZP>::channel.setAddress(address & 0x7F);
// }

}

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <ZscriptFullInclude.hpp>

void setup() {
Serial.begin(9600);
// Serial.begin(9600);
ZscriptSetup.setup();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#ifndef SRC_MAIN_C___ZSCRIPT_ZSCRIPTCHANNEL_HPP_
#define SRC_MAIN_C___ZSCRIPT_ZSCRIPTCHANNEL_HPP_

#ifndef ZSCRIPT_HPP_INCLUDED
# error Channels must be included only after Zscript.hpp
#endif

#include "semanticParser/SemanticParser.hpp"
#include "execution/ZscriptCommandContext.hpp"
#include "AbstractOutStream.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AsyncActionNotifier {
#endif

public:
AsyncActionNotifier(GenericCore::SemanticParser<ZP> *parser) :
explicit AsyncActionNotifier(GenericCore::SemanticParser<ZP> *parser) :
source(parser)

#ifdef ZSCRIPT_SUPPORT_NOTIFICATIONS
Expand All @@ -42,7 +42,7 @@ class AsyncActionNotifier {

#ifdef ZSCRIPT_SUPPORT_NOTIFICATIONS

AsyncActionNotifier(GenericCore::ZscriptNotificationSource<ZP> *notification) :
explicit AsyncActionNotifier(GenericCore::ZscriptNotificationSource<ZP> *notification) :
source(notification), isSemantic(false) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include "../test-defines.hpp"
#include "zscript/modules/scriptSpace/ScriptSpaceModule.hpp"
#include "zscript/modules/core/CoreModule.hpp"
#include "StringChannel.hpp"
#include "zscript/Zscript.hpp"
#include "StringChannel.hpp"

#include "zscript/scriptSpace/ScriptSpace.hpp"
#include "../semanticParser/BufferOutStream.hpp"
Expand Down

0 comments on commit 42225e6

Please sign in to comment.