Skip to content

Commit

Permalink
Major refactoring
Browse files Browse the repository at this point in the history
- Code cleanup
  • Loading branch information
vanvught committed Jan 19, 2025
1 parent 0dace99 commit 52856cd
Show file tree
Hide file tree
Showing 267 changed files with 57,931 additions and 2,251 deletions.
204 changes: 95 additions & 109 deletions lib-artnet/include/artnetnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,100 @@ class ArtNetNode {
public:
ArtNetNode();

void SetOutput(LightSet *pLightSet) {
m_pLightSet = pLightSet;
#if (ARTNET_VERSION >= 4)
E131Bridge::SetOutput(pLightSet);
#endif
}
LightSet *GetOutput() const {
return m_pLightSet;
}

void SetDisableMergeTimeout(const bool bDisable) {
m_State.bDisableMergeTimeout = bDisable;
#if (ARTNET_VERSION >= 4)
E131Bridge::SetDisableMergeTimeout(bDisable);
#endif
}
bool GetDisableMergeTimeout() const {
return m_State.bDisableMergeTimeout;
}

void SetFailSafe(const artnetnode::FailSafe failsafe); /// TODO Subject for deletion
void SetFailSafe(const lightset::FailSafe failsafe);
lightset::FailSafe GetFailSafe();

void SetUniverse(const uint32_t nPortIndex, const lightset::PortDir dir, const uint16_t nUniverse);
bool GetUniverse(const uint32_t nPortIndex, uint16_t &nUniverse, const lightset::PortDir portDirection) {
if (m_Node.Port[nPortIndex].protocol == artnet::PortProtocol::ARTNET) {
return ArtNetNode::GetPortAddress(nPortIndex, nUniverse, portDirection);
}
#if (ARTNET_VERSION >= 4)
if (m_Node.Port[nPortIndex].protocol == artnet::PortProtocol::SACN) {
return E131Bridge::GetUniverse(nPortIndex, nUniverse, portDirection);
}
#endif
return false;
}

void SetMergeMode(const uint32_t nPortIndex, const lightset::MergeMode mergeMode);
lightset::MergeMode GetMergeMode(const uint32_t nPortIndex) const {
assert(nPortIndex < artnetnode::MAX_PORTS);
if ((m_OutputPort[nPortIndex].GoodOutput & artnet::GoodOutput::MERGE_MODE_LTP) == artnet::GoodOutput::MERGE_MODE_LTP) {
return lightset::MergeMode::LTP;
}
return lightset::MergeMode::HTP;
}

#if defined (OUTPUT_HAVE_STYLESWITCH)
void SetOutputStyle(const uint32_t nPortIndex, lightset::OutputStyle outputStyle);
lightset::OutputStyle GetOutputStyle(const uint32_t nPortIndex) const;
#endif

void SetRdm(const bool doEnable);
bool GetRdm() const {
return m_State.rdm.IsEnabled;
}

void SetRdm(const uint32_t nPortIndex, const bool bEnable);
bool GetRdm(const uint32_t nPortIndex) const {
assert(nPortIndex < artnetnode::MAX_PORTS);
return !((m_OutputPort[nPortIndex].GoodOutputB & artnet::GoodOutputB::RDM_DISABLED) == artnet::GoodOutputB::RDM_DISABLED);
}

#if (ARTNET_VERSION >= 4)
void SetPortProtocol4(const uint32_t nPortIndex, const artnet::PortProtocol portProtocol);
artnet::PortProtocol GetPortProtocol4(const uint32_t nPortIndex) const {
assert(nPortIndex < artnetnode::MAX_PORTS);
return m_Node.Port[nPortIndex].protocol;
}

void SetMapUniverse0(const bool bMapUniverse0 = false) {
m_Node.bMapUniverse0 = bMapUniverse0;
}
bool IsMapUniverse0() const {
return m_Node.bMapUniverse0;
}

void SetPriority4(const uint32_t nPriority) {
m_ArtPollReply.AcnPriority = static_cast<uint8_t>(nPriority);

for (uint32_t nPortIndex = 0; nPortIndex < e131bridge::MAX_PORTS; nPortIndex++) {
E131Bridge::SetPriority(nPortIndex, static_cast<uint8_t>(nPriority));
}
}

void SetPriority(const uint32_t nPortIndex, const uint8_t nPriority) {
E131Bridge::SetPriority(nPortIndex, nPriority);
}
uint8_t GetPriority(const uint32_t nPortIndex) const {
return E131Bridge::GetPriority(nPortIndex);
}
#endif

void Print();

void Start();
void Stop();

Expand Down Expand Up @@ -252,47 +346,6 @@ class ArtNetNode {
return artnet::VERSION;
}

void SetOutputStyle(const uint32_t nPortIndex, lightset::OutputStyle outputStyle);
lightset::OutputStyle GetOutputStyle(const uint32_t nPortIndex) const;

void SetFailSafe(const artnetnode::FailSafe failsafe);

artnetnode::FailSafe GetFailSafe() {
const auto networkloss = (m_ArtPollReply.Status3 & artnet::Status3::NETWORKLOSS_MASK);
switch (networkloss) {
case artnet::Status3::NETWORKLOSS_LAST_STATE:
return artnetnode::FailSafe::LAST;
break;
case artnet::Status3::NETWORKLOSS_OFF_STATE:
return artnetnode::FailSafe::OFF;
break;
case artnet::Status3::NETWORKLOSS_ON_STATE:
return artnetnode::FailSafe::ON;
break;
case artnet::Status3::NETWORKLOSS_PLAYBACK:
return artnetnode::FailSafe::PLAYBACK;
break;
default:
assert(0);
__builtin_unreachable();
break;
}

__builtin_unreachable();
return artnetnode::FailSafe::OFF;
}

void SetOutput(LightSet *pLightSet) {
m_pLightSet = pLightSet;
#if (ARTNET_VERSION >= 4)
E131Bridge::SetOutput(pLightSet);
#endif
}

LightSet *GetOutput() const {
return m_pLightSet;
}

uint32_t GetActiveInputPorts() const {
return m_State.nEnabledInputPorts;
}
Expand All @@ -314,8 +367,6 @@ class ArtNetNode {

void GetLongNameDefault(char *);

void SetUniverse(const uint32_t nPortIndex, const lightset::PortDir dir, const uint16_t nUniverse);

lightset::PortDir GetPortDirection(const uint32_t nPortIndex) const {
assert(nPortIndex < artnetnode::MAX_PORTS);
return m_Node.Port[nPortIndex].direction;
Expand Down Expand Up @@ -355,26 +406,6 @@ class ArtNetNode {
return false;
}

void SetMergeMode(const uint32_t nPortIndex, const lightset::MergeMode mergeMode);
lightset::MergeMode GetMergeMode(const uint32_t nPortIndex) const {
assert(nPortIndex < artnetnode::MAX_PORTS);
if ((m_OutputPort[nPortIndex].GoodOutput & artnet::GoodOutput::MERGE_MODE_LTP) == artnet::GoodOutput::MERGE_MODE_LTP) {
return lightset::MergeMode::LTP;
}
return lightset::MergeMode::HTP;
}

void SetRdm(const bool doEnable);
bool GetRdm() const {
return m_State.rdm.IsEnabled;
}

void SetRdm(const uint32_t nPortIndex, const bool bEnable);
bool GetRdm(const uint32_t nPortIndex) const {
assert(nPortIndex < artnetnode::MAX_PORTS);
return !((m_OutputPort[nPortIndex].GoodOutputB & artnet::GoodOutputB::RDM_DISABLED) == artnet::GoodOutputB::RDM_DISABLED);
}

void SetRdmDiscovery(const uint32_t nPortIndex, const bool bEnable);
bool GetRdmDiscovery(const uint32_t nPortIndex) const {
assert(nPortIndex < artnetnode::MAX_PORTS);
Expand Down Expand Up @@ -427,17 +458,6 @@ class ArtNetNode {
void SetRdmResponder(ArtNetRdmResponder *pArtNetRdmResponder, const bool doEnable = true);
#endif

void SetDisableMergeTimeout(bool bDisable) {
m_State.bDisableMergeTimeout = bDisable;
#if (ARTNET_VERSION >= 4)
E131Bridge::SetDisableMergeTimeout(bDisable);
#endif
}

bool GetDisableMergeTimeout() const {
return m_State.bDisableMergeTimeout;
}

#if defined (ARTNET_HAVE_TIMECODE)
void SendTimeCode(const struct artnet::TimeCode *pArtNetTimeCode) {
assert(pArtNetTimeCode != nullptr);
Expand Down Expand Up @@ -488,8 +508,6 @@ class ArtNetNode {
}
}

void Print();

static ArtNetNode* Get() {
return s_pThis;
}
Expand All @@ -505,37 +523,6 @@ class ArtNetNode {
/**
* Art-Net 4
*/
void SetMapUniverse0(const bool bMapUniverse0 = false) {
m_Node.bMapUniverse0 = bMapUniverse0;
}
bool IsMapUniverse0() const {
return m_Node.bMapUniverse0;
}

void SetPriority4(const uint32_t nPriority) {
m_ArtPollReply.AcnPriority = static_cast<uint8_t>(nPriority);

for (uint32_t nPortIndex = 0; nPortIndex < e131bridge::MAX_PORTS; nPortIndex++) {
E131Bridge::SetPriority(nPortIndex, static_cast<uint8_t>(nPriority));
}
}

void SetPortProtocol4(const uint32_t nPortIndex, const artnet::PortProtocol portProtocol);
artnet::PortProtocol GetPortProtocol4(const uint32_t nPortIndex) const {
assert(nPortIndex < artnetnode::MAX_PORTS);
return m_Node.Port[nPortIndex].protocol;
}

/**
* sACN E1.131
*/
void SetPriority4(uint32_t nPortIndex, uint8_t nPriority) {
E131Bridge::SetPriority(nPortIndex, nPriority);
}
uint8_t GetPriority4(uint32_t nPortIndex) const {
return E131Bridge::GetPriority(nPortIndex);
}

bool GetUniverse4(uint32_t nPortIndex, uint16_t &nUniverse, lightset::PortDir portDir) const {
return E131Bridge::GetUniverse(nPortIndex, nUniverse, portDir);
}
Expand All @@ -553,7 +540,6 @@ class ArtNetNode {
void SetUniverseSwitch(const uint32_t nPortIndex, const lightset::PortDir dir, const uint8_t nAddress);
void SetNetSwitch(const uint32_t nPortIndex, const uint8_t nNetSwitch);
void SetSubnetSwitch(const uint32_t nPortIndex, const uint8_t nSubnetSwitch);

void SendDiag([[maybe_unused]] const artnet::PriorityCodes priorityCode, [[maybe_unused]] const char *format, ...) {
#if defined (ARTNET_ENABLE_SENDDIAG)
if (!m_State.SendArtDiagData) {
Expand Down Expand Up @@ -635,7 +621,7 @@ class ArtNetNode {
}
}

void static staticCallbackFunctionLedPanelOff([[maybe_unused]] TimerHandle_t timerHandle) {
void static StaticCallbackFunctionLedPanelOff([[maybe_unused]] TimerHandle_t timerHandle) {
s_pThis->LedPanelOff();
}

Expand Down
2 changes: 1 addition & 1 deletion lib-artnet/include/artnetparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class ArtNetParams {
return lightset::PortDir::DISABLE;
}

static void staticCallbackFunction(void *p, const char *s);
static void StaticCallbackFunction(void *p, const char *s);

private:
lightset::PortDir portdir_get(const uint32_t nPortIndex) const {
Expand Down
2 changes: 1 addition & 1 deletion lib-artnet/src/node/4/artnetnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Art-Net Designed by and Copyright Artistic Licence Holdings Ltd.
*/
/* Copyright (C) 2023-2024 by Arjan van Vught mailto:[email protected]
/* Copyright (C) 2023-2025 by Arjan van Vught mailto:[email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions lib-artnet/src/node/artnetnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
*/

/* Copyright (C) 2016-2024 by Arjan van Vught mailto:[email protected]
/* Copyright (C) 2016-2025 by Arjan van Vught mailto:[email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -182,7 +182,7 @@ void ArtNetNode::Start() {
/*
* Status 3
*/
m_ArtPollReply.Status3 = artnet::Status3::NETWORKLOSS_LAST_STATE | artnet::Status3::FAILSAFE_CONTROL | artnet::Status3::SUPPORTS_BACKGROUNDDISCOVERY;
m_ArtPollReply.Status3 |= artnet::Status3::FAILSAFE_CONTROL | artnet::Status3::SUPPORTS_BACKGROUNDDISCOVERY;
#if defined (ARTNET_HAVE_DMXIN)
m_ArtPollReply.Status3 |= artnet::Status3::OUTPUT_SWITCH;
#endif
Expand Down Expand Up @@ -230,7 +230,7 @@ void ArtNetNode::Start() {
E131Bridge::Start();
#endif

SoftwareTimerAdd(200, staticCallbackFunctionLedPanelOff);
SoftwareTimerAdd(200, StaticCallbackFunctionLedPanelOff);

m_State.status = artnet::Status::ON;
Hardware::Get()->SetMode(hardware::ledblink::Mode::NORMAL);
Expand Down
57 changes: 55 additions & 2 deletions lib-artnet/src/node/artnetnodehandleaddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ void ArtNetNode::SetLocalMerging() {
(m_Node.Port[nInputPortIndex].PortAddress == m_Node.Port[nOutputPortIndex].PortAddress)) {

if (!m_Node.Port[nOutputPortIndex].bLocalMerge) {
m_OutputPort[nOutputPortIndex].SourceA.nIp = network::IPADDR_LOOPBACK;
m_OutputPort[nOutputPortIndex].SourceA.nIp = net::IPADDR_LOOPBACK;
DEBUG_PUTS("Local merge Source A");
} else {
m_OutputPort[nOutputPortIndex].SourceB.nIp = network::IPADDR_LOOPBACK;
m_OutputPort[nOutputPortIndex].SourceB.nIp = net::IPADDR_LOOPBACK;
DEBUG_PUTS("Local merge Source B");
}

Expand Down Expand Up @@ -216,6 +216,34 @@ void ArtNetNode::SetMergeMode(const uint32_t nPortIndex, const lightset::MergeMo
}
}

void ArtNetNode::SetFailSafe(const lightset::FailSafe lightset_failsafe) {
artnetnode::FailSafe failsafe;

switch (lightset_failsafe) {
case lightset::FailSafe::HOLD:
failsafe = artnetnode::FailSafe::LAST;
break;
case lightset::FailSafe::OFF:
failsafe = artnetnode::FailSafe::OFF;
break;
case lightset::FailSafe::ON:
failsafe = artnetnode::FailSafe::ON;
break;
case lightset::FailSafe::PLAYBACK:
failsafe = artnetnode::FailSafe::PLAYBACK;
break;
case lightset::FailSafe::RECORD:
failsafe = artnetnode::FailSafe::RECORD;
break;
default:
assert(0);
__builtin_unreachable();
break;
}

SetFailSafe(failsafe);
}

void ArtNetNode::SetFailSafe(const artnetnode::FailSafe failsafe) {
DEBUG_PRINTF("failsafe=%u", static_cast<uint32_t>(failsafe));

Expand Down Expand Up @@ -273,6 +301,31 @@ void ArtNetNode::SetFailSafe(const artnetnode::FailSafe failsafe) {
DEBUG_EXIT
}

lightset::FailSafe ArtNetNode::GetFailSafe() {
const auto networkloss = (m_ArtPollReply.Status3 & artnet::Status3::NETWORKLOSS_MASK);
switch (networkloss) {
case artnet::Status3::NETWORKLOSS_LAST_STATE:
return lightset::FailSafe::HOLD;
break;
case artnet::Status3::NETWORKLOSS_OFF_STATE:
return lightset::FailSafe::OFF;
break;
case artnet::Status3::NETWORKLOSS_ON_STATE:
return lightset::FailSafe::ON;
break;
case artnet::Status3::NETWORKLOSS_PLAYBACK:
return lightset::FailSafe::PLAYBACK;
break;
default:
assert(0);
__builtin_unreachable();
break;
}

__builtin_unreachable();
return lightset::FailSafe::OFF;
}

void ArtNetNode::HandleAddress() {
const auto *const pArtAddress = reinterpret_cast<artnet::ArtAddress *>(m_pReceiveBuffer);
m_State.reportCode = artnet::ReportCode::RCPOWEROK;
Expand Down
Loading

0 comments on commit 52856cd

Please sign in to comment.