From b844e83b3798d8082a8c4ed55c0d12c737a1f090 Mon Sep 17 00:00:00 2001 From: rainer Date: Mon, 5 Apr 2021 12:26:15 +0200 Subject: [PATCH] Add BusConfig, which allows detailed configuration of the PJON backend. Also changed default bus configuration to be compatible to PJON defaults --- Bus.hpp | 11 ++++++++++- Bus.inl | 8 +++++++- BusConfig.hpp | 43 +++++++++++++++++++++++++++++++++++++++++++ test/TestBus.cpp | 13 +++++++++++++ 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 BusConfig.hpp diff --git a/Bus.hpp b/Bus.hpp index e2ed4cb..7a66096 100644 --- a/Bus.hpp +++ b/Bus.hpp @@ -29,6 +29,7 @@ #include "Expect.hpp" #include "Address.hpp" #include "Connection.hpp" +#include "BusConfig.hpp" template class PJON; @@ -38,6 +39,7 @@ namespace PjonHL template class Connection; + template class Bus { @@ -50,7 +52,14 @@ class Bus /// It will also be used to filter incoming packets. /// @param f_strategy the underlying physical bus strategy to use. /// e.g. an instance of ThroughSerial - Bus(Address f_localAddress, Strategy f_strategy); + /// @param f_config optional bus configuration, used to set up the bus. + // see BusConfig struct for default config values used, as + // well as additional details. + Bus( + Address f_localAddress, + Strategy f_strategy, + BusConfig f_config = BusConfig{} + ); /// Handle which will be returned by createConnection() calls. /// Holds ownership of a connection and can be used to send/receive packets. diff --git a/Bus.inl b/Bus.inl index 11b9bcd..ae162a6 100644 --- a/Bus.inl +++ b/Bus.inl @@ -61,12 +61,18 @@ Bus::~Bus() } template -Bus::Bus(Address f_localAddress, Strategy f_strategy) : +Bus::Bus(Address f_localAddress, Strategy f_strategy, BusConfig f_config) : m_pjon(f_localAddress.busId.data(), f_localAddress.id) { m_localAddress = f_localAddress; m_pjon.strategy = f_strategy; + // load config: + m_pjon.set_acknowledge(f_config.ackType == BusConfig::AckType::AckEnabled); + m_pjon.set_crc_32(f_config.crcType == BusConfig::CrcType::Crc32); + m_pjon.set_communication_mode(f_config.communicationMode == BusConfig::CommunicationMode::HalfDuplex); + m_pjon.set_shared_network(f_config.busTopology == BusConfig::BusTopology::Shared); + // TODO: Currently PJON does not provide any interface to set a "callable" object // Or a member function as error / receiver function. // Only Raw function pointers are supported. diff --git a/BusConfig.hpp b/BusConfig.hpp new file mode 100644 index 0000000..0437bf7 --- /dev/null +++ b/BusConfig.hpp @@ -0,0 +1,43 @@ +namespace PjonHL +{ + +/// Struct representing a PJON bus configuration. All participants in a network +/// should have the same configuration. +/// You can optionally pass an instance of the BusConfig into the PjonHL constructor. +/// All config options will be forwarded to the PJON backend. +/// For detailed documentation please have a look at the PJON protocol spec. +struct BusConfig +{ + enum class BusTopology + { + Local, + Shared + }; + + enum class AckType + { + AckEnabled, + AckDisabled + }; + + enum class CommunicationMode + { + Simplex, + HalfDuplex + }; + + enum class CrcType + { + Crc8, + Crc32 + }; + + BusTopology busTopology = BusTopology::Local; + CommunicationMode communicationMode = CommunicationMode::HalfDuplex; + AckType ackType = AckType::AckEnabled; + CrcType crcType = CrcType::Crc8; + + // Mac not yet suppored +}; + +} diff --git a/test/TestBus.cpp b/test/TestBus.cpp index 3a5e702..97c630f 100644 --- a/test/TestBus.cpp +++ b/test/TestBus.cpp @@ -179,6 +179,19 @@ class PJON return shadow().send(info, payload, length); }; + void set_acknowledge(bool) + { + } + void set_crc_32(bool) + { + } + void set_communication_mode(bool) + { + } + void set_shared_network(bool) + { + } + PJON_Error _error; PJON_Receiver _receiver; Strategy strategy;