Skip to content

Commit

Permalink
Add BusConfig, which allows detailed configuration of the PJON backend.
Browse files Browse the repository at this point in the history
Also changed default bus configuration to be compatible to PJON defaults
  • Loading branch information
rainerschoe committed Apr 5, 2021
1 parent 63d7519 commit b844e83
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Bus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "Expect.hpp"
#include "Address.hpp"
#include "Connection.hpp"
#include "BusConfig.hpp"

template<class Strategy>
class PJON;
Expand All @@ -38,6 +39,7 @@ namespace PjonHL
template<class Strategy>
class Connection;


template<class Strategy>
class Bus
{
Expand All @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion Bus.inl
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ Bus<Strategy>::~Bus()
}

template<class Strategy>
Bus<Strategy>::Bus(Address f_localAddress, Strategy f_strategy) :
Bus<Strategy>::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.
Expand Down
43 changes: 43 additions & 0 deletions BusConfig.hpp
Original file line number Diff line number Diff line change
@@ -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
};

}
13 changes: 13 additions & 0 deletions test/TestBus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b844e83

Please sign in to comment.