diff --git a/gd32_emac_artnet_pixel_dmx_multi/firmware/main.cpp b/gd32_emac_artnet_pixel_dmx_multi/firmware/main.cpp index d34f848..7356d2c 100644 --- a/gd32_emac_artnet_pixel_dmx_multi/firmware/main.cpp +++ b/gd32_emac_artnet_pixel_dmx_multi/firmware/main.cpp @@ -72,13 +72,15 @@ #include "remoteconfigparams.h" #include "configstore.h" -#include "storeartnet.h" - #include "firmwareversion.h" #include "software_version.h" -static constexpr uint32_t DMXPORT_OFFSET = 64; +namespace artnetnode { +namespace configstore { +uint32_t DMXPORT_OFFSET = 64; +} // namespace configstore +} // namespace artnetnode void Hardware::RebootHandler() { WS28xxMulti::Get()->Blackout(); @@ -109,14 +111,9 @@ void main() { ArtNetNode node; - StoreArtNet storeArtNet(DMXPORT_OFFSET); - node.SetArtNetStore(&storeArtNet); - ArtNetParams artnetParams; - - if (artnetParams.Load()) { - artnetParams.Set(DMXPORT_OFFSET); - } + artnetParams.Load(); + artnetParams.Set(); // LightSet A - Pixel - 64 Universes @@ -155,8 +152,8 @@ void main() { uint32_t nDmxUniverses = 0; - for (uint32_t nPortIndex = DMXPORT_OFFSET; nPortIndex < artnetnode::MAX_PORTS; nPortIndex++) { - const auto nDmxPortIndex = nPortIndex - DMXPORT_OFFSET; + for (uint32_t nPortIndex = artnetnode::configstore::DMXPORT_OFFSET; nPortIndex < artnetnode::MAX_PORTS; nPortIndex++) { + const auto nDmxPortIndex = nPortIndex - artnetnode::configstore::DMXPORT_OFFSET; if (artnetParams.GetDirection(nDmxPortIndex) == lightset::PortDir::OUTPUT) { const auto Universe = artnetParams.GetUniverse(nDmxPortIndex); @@ -165,14 +162,15 @@ void main() { } } - DmxParams dmxparams; + Dmx dmx; + DmxParams dmxparams; dmxparams.Load(); dmxparams.Set(&dmx); - for (uint32_t nPortIndex = DMXPORT_OFFSET; nPortIndex < artnetnode::MAX_PORTS; nPortIndex++) { - const auto nDmxPortIndex = nPortIndex - DMXPORT_OFFSET; + for (uint32_t nPortIndex = artnetnode::configstore::DMXPORT_OFFSET; nPortIndex < artnetnode::MAX_PORTS; nPortIndex++) { + const auto nDmxPortIndex = nPortIndex - artnetnode::configstore::DMXPORT_OFFSET; if (node.GetPortDirection(nPortIndex) == lightset::PortDir::OUTPUT) { dmx.SetPortDirection(nDmxPortIndex, dmx::PortDirection::OUTP, false); @@ -235,7 +233,7 @@ void main() { displayUdfParams.Load(); displayUdfParams.Set(&display); - display.Show(&node, DMXPORT_OFFSET); + display.Show(&node); display.Printf(7, "%s:%d G%d %s", PixelType::GetType(pixelDmxConfiguration.GetType()), diff --git a/gd32_emac_artnet_pixel_dmx_multi/include/sofware_version_id.h b/gd32_emac_artnet_pixel_dmx_multi/include/sofware_version_id.h index 68b52b5..9b0e87b 100644 --- a/gd32_emac_artnet_pixel_dmx_multi/include/sofware_version_id.h +++ b/gd32_emac_artnet_pixel_dmx_multi/include/sofware_version_id.h @@ -1 +1 @@ -constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1702811908; +constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1704222230; diff --git a/gd32_emac_artnet_pixel_multi/firmware/main.cpp b/gd32_emac_artnet_pixel_multi/firmware/main.cpp index 2fcc6c8..8718351 100644 --- a/gd32_emac_artnet_pixel_multi/firmware/main.cpp +++ b/gd32_emac_artnet_pixel_multi/firmware/main.cpp @@ -66,13 +66,15 @@ #include "remoteconfigparams.h" #include "configstore.h" -#include "storeartnet.h" - #include "firmwareversion.h" #include "software_version.h" -static constexpr uint32_t DMXPORT_OFFSET = LIGHTSET_PORTS; +namespace artnetnode { +namespace configstore { +uint32_t DMXPORT_OFFSET = LIGHTSET_PORTS; +} // namespace configstore +} // namespace artnetnode void Hardware::RebootHandler() { WS28xxMulti::Get()->Blackout(); @@ -100,14 +102,9 @@ void main() { ArtNetNode node; - StoreArtNet storeArtNet(DMXPORT_OFFSET); - node.SetArtNetStore(&storeArtNet); - ArtNetParams artnetParams; - - if (artnetParams.Load()) { - artnetParams.Set(DMXPORT_OFFSET); - } + artnetParams.Load(); + artnetParams.Set(); PixelDmxConfiguration pixelDmxConfiguration; @@ -189,7 +186,7 @@ void main() { displayUdfParams.Load(); displayUdfParams.Set(&display); - display.Show(&node, DMXPORT_OFFSET); + display.Show(&node); display.Printf(7, "%s:%d G%d %s", PixelType::GetType(pixelDmxConfiguration.GetType()), diff --git a/gd32_emac_artnet_pixel_multi/include/sofware_version_id.h b/gd32_emac_artnet_pixel_multi/include/sofware_version_id.h index 68b52b5..e92809a 100644 --- a/gd32_emac_artnet_pixel_multi/include/sofware_version_id.h +++ b/gd32_emac_artnet_pixel_multi/include/sofware_version_id.h @@ -1 +1 @@ -constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1702811908; +constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1704222259; diff --git a/gd32_emac_ddp_pixel_dmx_multi/firmware/main.cpp b/gd32_emac_ddp_pixel_dmx_multi/firmware/main.cpp index 7478159..74b6a35 100644 --- a/gd32_emac_ddp_pixel_dmx_multi/firmware/main.cpp +++ b/gd32_emac_ddp_pixel_dmx_multi/firmware/main.cpp @@ -124,9 +124,9 @@ void main() { // LightSet B - DMX - 2 Universes - DmxParams dmxparams; Dmx dmx; + DmxParams dmxparams; dmxparams.Load(); dmxparams.Set(&dmx); diff --git a/gd32_emac_ddp_pixel_dmx_multi/include/sofware_version_id.h b/gd32_emac_ddp_pixel_dmx_multi/include/sofware_version_id.h index 081a99f..735cbc0 100644 --- a/gd32_emac_ddp_pixel_dmx_multi/include/sofware_version_id.h +++ b/gd32_emac_ddp_pixel_dmx_multi/include/sofware_version_id.h @@ -1 +1 @@ -constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1702811913; +constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1704222269; diff --git a/gd32_emac_ddp_pixel_multi/include/sofware_version_id.h b/gd32_emac_ddp_pixel_multi/include/sofware_version_id.h index 22af23d..ecb17bc 100644 --- a/gd32_emac_ddp_pixel_multi/include/sofware_version_id.h +++ b/gd32_emac_ddp_pixel_multi/include/sofware_version_id.h @@ -1 +1 @@ -constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1702811915; +constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1704222278; diff --git a/gd32_emac_e131_pixel_dmx_multi/firmware/main.cpp b/gd32_emac_e131_pixel_dmx_multi/firmware/main.cpp index a45d87b..8099c50 100644 --- a/gd32_emac_e131_pixel_dmx_multi/firmware/main.cpp +++ b/gd32_emac_e131_pixel_dmx_multi/firmware/main.cpp @@ -72,11 +72,14 @@ #include "configstore.h" - #include "firmwareversion.h" #include "software_version.h" -static constexpr uint32_t DMXPORT_OFFSET = 64; +namespace e131bridge { +namespace configstore { +uint32_t DMXPORT_OFFSET = 64; +} // namespace configstore +} // namespace e131bridge void Hardware::RebootHandler() { WS28xxMulti::Get()->Blackout(); @@ -107,7 +110,7 @@ void main() { E131Params e131params; e131params.Load(); - e131params.Set(DMXPORT_OFFSET); + e131params.Set(); // LightSet A - Pixel - 64 Universes @@ -148,7 +151,7 @@ void main() { auto direction = e131params.GetDirection(0); if (direction == lightset::PortDir::OUTPUT) { - bridge.SetUniverse(DMXPORT_OFFSET, lightset::PortDir::OUTPUT, nUniverse); + bridge.SetUniverse(e131bridge::configstore::DMXPORT_OFFSET, lightset::PortDir::OUTPUT, nUniverse); nDmxUniverses++; } @@ -156,19 +159,19 @@ void main() { direction = e131params.GetDirection(1); if (direction == lightset::PortDir::OUTPUT) { - bridge.SetUniverse(DMXPORT_OFFSET + 1U, lightset::PortDir::OUTPUT, nUniverse); + bridge.SetUniverse(e131bridge::configstore::DMXPORT_OFFSET + 1U, lightset::PortDir::OUTPUT, nUniverse); nDmxUniverses++; } - DmxParams dmxparams; Dmx dmx; + DmxParams dmxparams; dmxparams.Load(); dmxparams.Set(&dmx); - for (uint32_t nPortIndex = DMXPORT_OFFSET; nPortIndex < e131bridge::MAX_PORTS; nPortIndex++) { + for (uint32_t nPortIndex = e131bridge::configstore::DMXPORT_OFFSET; nPortIndex < e131bridge::MAX_PORTS; nPortIndex++) { uint16_t nUniverse; - const auto nDmxPortIndex = nPortIndex - DMXPORT_OFFSET; + const auto nDmxPortIndex = nPortIndex - e131bridge::configstore::DMXPORT_OFFSET; if (bridge.GetUniverse(nPortIndex, nUniverse, lightset::PortDir::OUTPUT)) { dmx.SetPortDirection(nDmxPortIndex, dmx::PortDirection::OUTP, false); @@ -227,7 +230,7 @@ void main() { displayUdfParams.Load(); displayUdfParams.Set(&display); - display.Show(&bridge, DMXPORT_OFFSET); + display.Show(&bridge); display.Printf(7, "%s:%d G%d %s", PixelType::GetType(pixelDmxConfiguration.GetType()), diff --git a/gd32_emac_e131_pixel_dmx_multi/include/sofware_version_id.h b/gd32_emac_e131_pixel_dmx_multi/include/sofware_version_id.h index c08f99c..8bb33dd 100644 --- a/gd32_emac_e131_pixel_dmx_multi/include/sofware_version_id.h +++ b/gd32_emac_e131_pixel_dmx_multi/include/sofware_version_id.h @@ -1,2 +1 @@ -// Generated do 14 sep 2023 12:39:45 CEST -constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1694687985; +constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1704222298; diff --git a/gd32_emac_e131_pixel_multi/firmware/main.cpp b/gd32_emac_e131_pixel_multi/firmware/main.cpp index 6459a0c..5058373 100644 --- a/gd32_emac_e131_pixel_multi/firmware/main.cpp +++ b/gd32_emac_e131_pixel_multi/firmware/main.cpp @@ -70,7 +70,11 @@ #include "firmwareversion.h" #include "software_version.h" -static constexpr uint32_t DMXPORT_OFFSET = 32; +namespace e131bridge { +namespace configstore { +uint32_t DMXPORT_OFFSET = LIGHTSET_PORTS; +} // namespace configstore +} // namespace e131bridge void Hardware::RebootHandler() { WS28xxMulti::Get()->Blackout(); @@ -100,7 +104,7 @@ void main() { E131Params e131params; e131params.Load(); - e131params.Set(DMXPORT_OFFSET); + e131params.Set(); PixelDmxConfiguration pixelDmxConfiguration; diff --git a/gd32_emac_e131_pixel_multi/include/sofware_version_id.h b/gd32_emac_e131_pixel_multi/include/sofware_version_id.h index f678b71..bad0d6c 100644 --- a/gd32_emac_e131_pixel_multi/include/sofware_version_id.h +++ b/gd32_emac_e131_pixel_multi/include/sofware_version_id.h @@ -1,2 +1 @@ -// Generated do 14 sep 2023 12:39:46 CEST -constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1694687986; +constexpr uint32_t DEVICE_SOFTWARE_VERSION_ID=1704222308; diff --git a/lib-artnet/include/artnetnode.h b/lib-artnet/include/artnetnode.h index 1098ab8..20f62e5 100644 --- a/lib-artnet/include/artnetnode.h +++ b/lib-artnet/include/artnetnode.h @@ -5,7 +5,7 @@ /** * Art-Net Designed by and Copyright Artistic Licence Holdings Ltd. */ -/* Copyright (C) 2016-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl +/* Copyright (C) 2016-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -48,7 +48,6 @@ #include "artnet.h" #include "artnetnode_ports.h" #include "artnettimecode.h" -#include "artnetstore.h" #include "artnetdisplay.h" #include "artnettrigger.h" #if defined (RDM_CONTROLLER) @@ -273,6 +272,9 @@ 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() { @@ -300,58 +302,6 @@ class ArtNetNode { return artnetnode::FailSafe::OFF; } -#if defined (OUTPUT_HAVE_STYLESWITCH) - void SetOutputStyle(const uint32_t nPortIndex, lightset::OutputStyle outputStyle) { - assert(nPortIndex < artnetnode::MAX_PORTS); - - if (outputStyle == GetOutputStyle(nPortIndex)) { - return; - } - - if ((m_State.status == artnetnode::Status::ON) && (m_pLightSet != nullptr)) { - m_pLightSet->SetOutputStyle(nPortIndex, outputStyle); - outputStyle = m_pLightSet->GetOutputStyle(nPortIndex); - } - - if (outputStyle == lightset::OutputStyle::CONSTANT) { - m_OutputPort[nPortIndex].GoodOutputB |= artnet::GoodOutputB::STYLE_CONSTANT; - } else { - m_OutputPort[nPortIndex].GoodOutputB &= static_cast(~artnet::GoodOutputB::STYLE_CONSTANT); - } - -#if defined (OUTPUT_DMX_SEND) || defined (OUTPUT_DMX_SEND_MULTI) - /** - * FIXME I do not like this hack. It should be handled in dmx.cpp - */ - if ((m_Node.Port[nPortIndex].direction == lightset::PortDir::OUTPUT) - && (outputStyle == lightset::OutputStyle::CONSTANT) - && (m_pLightSet != nullptr)) { - if (m_OutputPort[nPortIndex].IsTransmitting) { - m_OutputPort[nPortIndex].IsTransmitting = false; - m_pLightSet->Stop(nPortIndex); - } - } -#endif - - m_State.IsSynchronousMode = false; - - if (m_State.status == artnetnode::Status::ON) { - if (m_pArtNetStore != nullptr) { - m_pArtNetStore->SaveOutputStyle(nPortIndex, outputStyle); - } - - artnet::display_outputstyle(nPortIndex, outputStyle); - } - } - - lightset::OutputStyle GetOutputStyle(const uint32_t nPortIndex) const { - assert(nPortIndex < artnetnode::MAX_PORTS); - - const auto isStyleConstant = (m_OutputPort[nPortIndex].GoodOutputB & artnet::GoodOutputB::STYLE_CONSTANT) == artnet::GoodOutputB::STYLE_CONSTANT; - return isStyleConstant ? lightset::OutputStyle::CONSTANT : lightset::OutputStyle::DELTA; - } -#endif - void SetOutput(LightSet *pLightSet) { m_pLightSet = pLightSet; #if (ARTNET_VERSION >= 4) @@ -498,10 +448,6 @@ class ArtNetNode { void SetTimeCodeIp(uint32_t nDestinationIp); - void SetArtNetStore(ArtNetStore *pArtNetStore) { - m_pArtNetStore = pArtNetStore; - } - void SetArtNetTrigger(ArtNetTrigger *pArtNetTrigger) { m_pArtNetTrigger = pArtNetTrigger; } @@ -725,7 +671,6 @@ class ArtNetNode { ArtNetTimeCode *m_pArtNetTimeCode { nullptr }; ArtNetTrigger *m_pArtNetTrigger { nullptr }; - ArtNetStore *m_pArtNetStore { nullptr }; artnetnode::Node m_Node; artnetnode::State m_State; diff --git a/lib-artnet/include/artnetparams.h b/lib-artnet/include/artnetparams.h index 342cb38..347097a 100644 --- a/lib-artnet/include/artnetparams.h +++ b/lib-artnet/include/artnetparams.h @@ -143,7 +143,7 @@ class ArtNetParams { Builder(nullptr, pBuffer, nLength, nSize); } - void Set(uint32_t nPortIndexOffset); + void Set(); bool IsRdm() const { return isMaskSet(artnetparams::Mask::ENABLE_RDM); diff --git a/lib-artnet/include/artnetstore.h b/lib-artnet/include/artnetstore.h index 4f0f85e..3b9508f 100644 --- a/lib-artnet/include/artnetstore.h +++ b/lib-artnet/include/artnetstore.h @@ -5,7 +5,7 @@ /** * Art-Net Designed by and Copyright Artistic Licence Holdings Ltd. */ -/* Copyright (C) 2018-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl +/* Copyright (C) 2018-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,28 +30,226 @@ #define ARTNETSTORE_H_ #include +#include -#include "artnet.h" -#include "lightset.h" +#include "artnetparams.h" +#include "configstore.h" +#include "artnetnode.h" + +#include "debug.h" + +namespace artnetnode { +namespace configstore { +extern uint32_t DMXPORT_OFFSET; +} // namespace configstore +} // namespace artnetnode class ArtNetStore { public: - virtual ~ArtNetStore() = default; + static void SaveLongName(const char *pLongName) { + DEBUG_ENTRY + ConfigStore::Get()->Update(configstore::Store::NODE, offsetof(struct artnetparams::Params, aLongName), pLongName, artnet::LONG_NAME_LENGTH, artnetparams::Mask::LONG_NAME); + DEBUG_EXIT + + } + + static void SaveShortName(uint32_t nPortIndex, const char *pShortName) { + DEBUG_ENTRY + DEBUG_PRINTF("%u, %s", nPortIndex, pShortName); + + if (nPortIndex >= artnetnode::configstore::DMXPORT_OFFSET) { + nPortIndex -= artnetnode::configstore::DMXPORT_OFFSET; + } else { + DEBUG_EXIT + return; + } + + DEBUG_PRINTF("nPortIndex=%u", nPortIndex); + + if (nPortIndex >= artnet::PORTS) { + DEBUG_EXIT + return; + } + + ConfigStore::Get()->Update(configstore::Store::NODE, (artnet::SHORT_NAME_LENGTH * nPortIndex) + offsetof(struct artnetparams::Params, aLabel), pShortName, artnet::SHORT_NAME_LENGTH, artnetparams::Mask::LABEL_A << nPortIndex); + + DEBUG_EXIT + } + + static void SaveUniverseSwitch(const uint32_t nPortIndex, __attribute__((unused)) const uint8_t nUniverseSwitch) { + DEBUG_ENTRY + SaveUniverse(nPortIndex); + DEBUG_EXIT + } + + static void SaveNetSwitch(const uint32_t nPortIndex, __attribute__((unused)) const uint8_t nNetSwitch) { + DEBUG_ENTRY + SaveUniverse(nPortIndex); + DEBUG_EXIT + } + + static void SaveSubnetSwitch(const uint32_t nPortIndex, __attribute__((unused)) const uint8_t nSubnetSwitch) { + DEBUG_ENTRY + SaveUniverse(nPortIndex); + DEBUG_EXIT + } + + static void SaveMergeMode(uint32_t nPortIndex, const lightset::MergeMode mergeMode) { + DEBUG_ENTRY + DEBUG_PRINTF("%u, %u", nPortIndex, static_cast(mergeMode)); + + if (nPortIndex >= artnetnode::configstore::DMXPORT_OFFSET) { + nPortIndex -= artnetnode::configstore::DMXPORT_OFFSET; + } else { + DEBUG_EXIT + return; + } + + DEBUG_PRINTF("nPortIndex=%u", nPortIndex); + + if (nPortIndex >= artnet::PORTS) { + DEBUG_EXIT + return; + } + + uint16_t nMergeMode; + ConfigStore::Get()->Copy(configstore::Store::NODE, &nMergeMode, sizeof(uint16_t), offsetof(struct artnetparams::Params, nMergeMode), false); + + nMergeMode &= artnetparams::mergemode_clear(nPortIndex); + nMergeMode |= artnetparams::mergemode_set(nPortIndex, mergeMode); + + ConfigStore::Get()->Update(configstore::Store::NODE, offsetof(struct artnetparams::Params, nMergeMode), &nMergeMode, sizeof(uint16_t)); + + DEBUG_EXIT + } + + static void SavePortProtocol(uint32_t nPortIndex, const artnet::PortProtocol portProtocol) { + DEBUG_ENTRY + DEBUG_PRINTF("artnetnode::configstore::DMXPORT_OFFSET=%u, nPortIndex=%u, portProtocol=%u", artnetnode::configstore::DMXPORT_OFFSET, nPortIndex, static_cast(portProtocol)); + + if (nPortIndex >= artnetnode::configstore::DMXPORT_OFFSET) { + nPortIndex -= artnetnode::configstore::DMXPORT_OFFSET; + } else { + DEBUG_EXIT + return; + } + + DEBUG_PRINTF("nPortIndex=%u", nPortIndex); + + if (nPortIndex >= artnet::PORTS) { + DEBUG_EXIT + return; + } + + uint16_t nPortProtocol; + ConfigStore::Get()->Copy(configstore::Store::NODE, &nPortProtocol, sizeof(uint16_t), offsetof(struct artnetparams::Params, nProtocol), false); + + nPortProtocol &= artnetparams::protocol_clear(nPortIndex); + nPortProtocol |= artnetparams::protocol_set(nPortIndex, portProtocol); + + ConfigStore::Get()->Update(configstore::Store::NODE, offsetof(struct artnetparams::Params, nProtocol), &nPortProtocol, sizeof(uint16_t)); + DEBUG_EXIT + } + + static void SaveOutputStyle(uint32_t nPortIndex, const lightset::OutputStyle outputStyle) { + DEBUG_ENTRY + DEBUG_PRINTF("artnetnode::configstore::DMXPORT_OFFSET=%u, nPortIndex=%u, outputStyle=%u", artnetnode::configstore::DMXPORT_OFFSET, nPortIndex, static_cast(outputStyle)); + + if (nPortIndex >= artnetnode::configstore::DMXPORT_OFFSET) { + nPortIndex -= artnetnode::configstore::DMXPORT_OFFSET; + } else { + DEBUG_EXIT + return; + } + + DEBUG_PRINTF("nPortIndex=%u", nPortIndex); + + if (nPortIndex >= artnet::PORTS) { + DEBUG_EXIT + return; + } + + uint8_t nOutputStyle; + ConfigStore::Get()->Copy(configstore::Store::NODE, &nOutputStyle, sizeof(uint8_t), offsetof(struct artnetparams::Params, nOutputStyle), false); + + if (outputStyle == lightset::OutputStyle::CONSTANT) { + nOutputStyle |= static_cast(1U << nPortIndex); + } else { + nOutputStyle &= static_cast(~(1U << nPortIndex)); + } + + ConfigStore::Get()->Update(configstore::Store::NODE, offsetof(struct artnetparams::Params, nOutputStyle), &nOutputStyle, sizeof(uint8_t)); + + DEBUG_EXIT + } + + static void SaveRdmEnabled(uint32_t nPortIndex, const bool isEnabled) { + DEBUG_ENTRY + DEBUG_PRINTF("artnetnode::configstore::DMXPORT_OFFSET=%u, nPortIndex=%u, isEnabled=%d", artnetnode::configstore::DMXPORT_OFFSET, nPortIndex, isEnabled); + + if (nPortIndex >= artnetnode::configstore::DMXPORT_OFFSET) { + nPortIndex -= artnetnode::configstore::DMXPORT_OFFSET; + } else { + DEBUG_EXIT + return; + } + + DEBUG_PRINTF("nPortIndex=%u", nPortIndex); + + if (nPortIndex >= artnet::PORTS) { + DEBUG_EXIT + return; + } + + uint16_t nRdm; + ConfigStore::Get()->Copy(configstore::Store::NODE, &nRdm, sizeof(uint16_t), offsetof(struct artnetparams::Params, nRdm), false); + + nRdm &= artnetparams::clear_mask(nPortIndex); + + if (isEnabled) { + nRdm |= artnetparams::shift_left(1, nPortIndex); + nRdm |= static_cast(1U << (nPortIndex + 8)); + } + + ConfigStore::Get()->Update(configstore::Store::NODE, offsetof(struct artnetparams::Params, nRdm), &nRdm, sizeof(uint16_t)); + + DEBUG_EXIT + } + + static void SaveFailSafe(uint8_t nFailSafe) { + DEBUG_ENTRY + ConfigStore::Get()->Update(configstore::Store::NODE, offsetof(struct artnetparams::Params, nFailSafe), &nFailSafe, sizeof(uint8_t), artnetparams::Mask::FAILSAFE); + DEBUG_EXIT + } + +private: + void static SaveUniverse(uint32_t nPortIndex) { + DEBUG_ENTRY + DEBUG_PRINTF("artnetnode::configstore::DMXPORT_OFFSET=%u, nPortIndex=%u", artnetnode::configstore::DMXPORT_OFFSET, nPortIndex); + + uint16_t nUniverse; - virtual void SaveLongName(const char *pLongName)=0; + if (ArtNetNode::Get()->GetPortAddress(nPortIndex, nUniverse)) { + if (nPortIndex >= artnetnode::configstore::DMXPORT_OFFSET) { + nPortIndex -= artnetnode::configstore::DMXPORT_OFFSET; + } else { + DEBUG_EXIT + return; + } - virtual void SaveShortName(const uint32_t nPortIndex, const char *pShortName)=0; + DEBUG_PRINTF("nPortIndex=%u", nPortIndex); - virtual void SaveUniverseSwitch(const uint32_t nPortIndex, const uint8_t nAddress)=0; - virtual void SaveNetSwitch(const uint32_t nPage, const uint8_t nAddress)=0; - virtual void SaveSubnetSwitch(const uint32_t nPage, const uint8_t nAddress)=0; + if (nPortIndex >= artnet::PORTS) { + DEBUG_EXIT + return; + } - virtual void SaveMergeMode(const uint32_t nPortIndex, const lightset::MergeMode mergeMode)=0; - virtual void SavePortProtocol(const uint32_t nPortIndex, const artnet::PortProtocol portProtocol)=0; - virtual void SaveOutputStyle(const uint32_t nPortIndex, const lightset::OutputStyle outputStyle)=0; - virtual void SaveRdmEnabled(const uint32_t nPortIndex, const bool isEnabled)=0; + DEBUG_PRINTF("nPortIndex=%u, nUniverse=%u", nPortIndex, nUniverse); + ConfigStore::Get()->Update(configstore::Store::NODE, (sizeof(uint16_t) * nPortIndex) + offsetof(struct artnetparams::Params, nUniverse), &nUniverse, sizeof(uint16_t), artnetparams::Mask::UNIVERSE_A << nPortIndex); + } - virtual void SaveFailSafe(const uint8_t nFailsafe)=0; + DEBUG_EXIT + } }; #endif /* ARTNETSTORE_H_ */ diff --git a/lib-artnet/src/node/4/artnetnode.cpp b/lib-artnet/src/node/4/artnetnode.cpp index 4e04c7e..28e0790 100755 --- a/lib-artnet/src/node/4/artnetnode.cpp +++ b/lib-artnet/src/node/4/artnetnode.cpp @@ -5,7 +5,7 @@ /** * Art-Net Designed by and Copyright Artistic Licence Holdings Ltd. */ -/* Copyright (C) 2023 by Arjan van Vught mailto:info@orangepi-dmx.nl +/* Copyright (C) 2023-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -34,6 +34,7 @@ #include "artnetnode.h" #include "artnet.h" +#include "artnetstore.h" #include "e131bridge.h" @@ -58,10 +59,7 @@ void ArtNetNode::SetPortProtocol4(const uint32_t nPortIndex, const artnet::PortP } if (m_State.status == artnetnode::Status::ON) { - if (m_pArtNetStore != nullptr) { - m_pArtNetStore->SavePortProtocol(nPortIndex, portProtocol); - } - + ArtNetStore::SavePortProtocol(nPortIndex, portProtocol); artnet::display_port_protocol(nPortIndex, portProtocol); } diff --git a/lib-artnet/src/node/artnetnode.cpp b/lib-artnet/src/node/artnetnode.cpp index 83db7c3..ab472c6 100644 --- a/lib-artnet/src/node/artnetnode.cpp +++ b/lib-artnet/src/node/artnetnode.cpp @@ -5,7 +5,7 @@ /** * Art-Net Designed by and Copyright Artistic Licence Holdings Ltd. */ -/* Copyright (C) 2016-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl +/* Copyright (C) 2016-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -34,6 +34,7 @@ #include "artnetnode.h" #include "artnetconst.h" #include "artnet.h" +#include "artnetstore.h" #if defined (ARTNET_HAVE_DMXIN) # include "dmx.h" @@ -281,9 +282,7 @@ void ArtNetNode::SetShortName(const uint32_t nPortIndex, const char *pShortName) m_Node.Port[nPortIndex].ShortName[artnet::SHORT_NAME_LENGTH - 1] = '\0'; if (m_State.status == artnetnode::Status::ON) { - if (m_pArtNetStore != nullptr) { - m_pArtNetStore->SaveShortName(nPortIndex, m_Node.Port[nPortIndex].ShortName); - } + ArtNetStore::SaveShortName(nPortIndex, m_Node.Port[nPortIndex].ShortName); } DEBUG_PUTS(m_Node.Port[nPortIndex].ShortName); @@ -323,10 +322,7 @@ void ArtNetNode::SetLongName(const char *pLongName) { m_ArtPollReply.LongName[artnet::LONG_NAME_LENGTH - 1] = '\0'; if (m_State.status == artnetnode::Status::ON) { - if (m_pArtNetStore != nullptr) { - m_pArtNetStore->SaveLongName(reinterpret_cast(m_ArtPollReply.LongName)); - } - + ArtNetStore::SaveLongName(reinterpret_cast(m_ArtPollReply.LongName)); artnet::display_longname(reinterpret_cast(m_ArtPollReply.LongName)); } @@ -334,6 +330,55 @@ void ArtNetNode::SetLongName(const char *pLongName) { DEBUG_EXIT } +#if defined (OUTPUT_HAVE_STYLESWITCH) +void ArtNetNode::SetOutputStyle(const uint32_t nPortIndex, lightset::OutputStyle outputStyle) { + assert(nPortIndex < artnetnode::MAX_PORTS); + + if (outputStyle == GetOutputStyle(nPortIndex)) { + return; + } + + if ((m_State.status == artnetnode::Status::ON) && (m_pLightSet != nullptr)) { + m_pLightSet->SetOutputStyle(nPortIndex, outputStyle); + outputStyle = m_pLightSet->GetOutputStyle(nPortIndex); + } + + if (outputStyle == lightset::OutputStyle::CONSTANT) { + m_OutputPort[nPortIndex].GoodOutputB |= artnet::GoodOutputB::STYLE_CONSTANT; + } else { + m_OutputPort[nPortIndex].GoodOutputB &= static_cast(~artnet::GoodOutputB::STYLE_CONSTANT); + } + +#if defined (OUTPUT_DMX_SEND) || defined (OUTPUT_DMX_SEND_MULTI) + /** + * FIXME I do not like this hack. It should be handled in dmx.cpp + */ + if ((m_Node.Port[nPortIndex].direction == lightset::PortDir::OUTPUT) + && (outputStyle == lightset::OutputStyle::CONSTANT) + && (m_pLightSet != nullptr)) { + if (m_OutputPort[nPortIndex].IsTransmitting) { + m_OutputPort[nPortIndex].IsTransmitting = false; + m_pLightSet->Stop(nPortIndex); + } + } +#endif + + m_State.IsSynchronousMode = false; + + if (m_State.status == artnetnode::Status::ON) { + ArtNetStore::SaveOutputStyle(nPortIndex, outputStyle); + artnet::display_outputstyle(nPortIndex, outputStyle); + } +} + +lightset::OutputStyle ArtNetNode::GetOutputStyle(const uint32_t nPortIndex) const { + assert(nPortIndex < artnetnode::MAX_PORTS); + + const auto isStyleConstant = (m_OutputPort[nPortIndex].GoodOutputB & artnet::GoodOutputB::STYLE_CONSTANT) == artnet::GoodOutputB::STYLE_CONSTANT; + return isStyleConstant ? lightset::OutputStyle::CONSTANT : lightset::OutputStyle::DELTA; +} +#endif + void ArtNetNode::SetNetworkDataLossCondition() { m_State.IsMergeMode = false; m_State.IsSynchronousMode = false; diff --git a/lib-artnet/src/node/artnetnodehandleaddress.cpp b/lib-artnet/src/node/artnetnodehandleaddress.cpp index 4087bd0..796898c 100644 --- a/lib-artnet/src/node/artnetnodehandleaddress.cpp +++ b/lib-artnet/src/node/artnetnodehandleaddress.cpp @@ -5,7 +5,7 @@ /** * Art-Net Designed by and Copyright Artistic Licence Holdings Ltd. */ -/* Copyright (C) 2021-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl +/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -33,6 +33,7 @@ #include "artnetnode.h" #include "artnetconst.h" #include "artnetnode_internal.h" +#include "artnetstore.h" #include "lightsetdata.h" #include "hardware.h" @@ -163,10 +164,7 @@ void ArtNetNode::SetUniverseSwitch(const uint32_t nPortIndex, const lightset::Po #endif if (m_State.status == artnetnode::Status::ON) { - if (m_pArtNetStore != nullptr) { - m_pArtNetStore->SaveUniverseSwitch(nPortIndex, nAddress); - } - + ArtNetStore::SaveUniverseSwitch(nPortIndex, nAddress); artnet::display_universe_switch(nPortIndex, nAddress); #if defined (ARTNET_HAVE_DMXIN) @@ -184,8 +182,8 @@ void ArtNetNode::SetSubnetSwitch(const uint32_t nPortIndex, const uint8_t nSubne m_Node.Port[nPortIndex].SubSwitch = nSubnetSwitch; m_Node.Port[nPortIndex].PortAddress = MakePortAddress(m_Node.Port[nPortIndex].PortAddress, nPortIndex); - if ((m_pArtNetStore != nullptr) && (m_State.status == artnetnode::Status::ON)) { - m_pArtNetStore->SaveSubnetSwitch(nPortIndex, nSubnetSwitch); + if (m_State.status == artnetnode::Status::ON) { + ArtNetStore::SaveSubnetSwitch(nPortIndex, nSubnetSwitch); } DEBUG_EXIT @@ -198,8 +196,8 @@ void ArtNetNode::SetNetSwitch(const uint32_t nPortIndex, const uint8_t nNetSwitc m_Node.Port[nPortIndex].NetSwitch = nNetSwitch; m_Node.Port[nPortIndex].PortAddress = MakePortAddress(m_Node.Port[nPortIndex].PortAddress, nPortIndex); - if ((m_pArtNetStore != nullptr) && (m_State.status == artnetnode::Status::ON)) { - m_pArtNetStore->SaveNetSwitch(nPortIndex, nNetSwitch); + if (m_State.status == artnetnode::Status::ON) { + ArtNetStore::SaveNetSwitch(nPortIndex, nNetSwitch); } DEBUG_EXIT @@ -219,10 +217,7 @@ void ArtNetNode::SetMergeMode(const uint32_t nPortIndex, const lightset::MergeMo #endif if (m_State.status == artnetnode::Status::ON) { - if (m_pArtNetStore != nullptr) { - m_pArtNetStore->SaveMergeMode(nPortIndex, mergeMode); - } - + ArtNetStore::SaveMergeMode(nPortIndex, mergeMode); artnet::display_merge_mode(nPortIndex, mergeMode); } } @@ -277,11 +272,7 @@ void ArtNetNode::SetFailSafe(const artnetnode::FailSafe failsafe) { if (m_State.status == artnetnode::Status::ON) { const auto nFailSafe = static_cast(static_cast(failsafe) & 0x3); - - if (m_pArtNetStore != nullptr) { - m_pArtNetStore->SaveFailSafe(nFailSafe); - } - + ArtNetStore::SaveFailSafe(nFailSafe); artnet::display_failsafe(nFailSafe); } diff --git a/lib-artnet/src/node/artnetparams.cpp b/lib-artnet/src/node/artnetparams.cpp index 626e2f1..72c26e7 100644 --- a/lib-artnet/src/node/artnetparams.cpp +++ b/lib-artnet/src/node/artnetparams.cpp @@ -59,6 +59,12 @@ #include "debug.h" +namespace artnetnode { +namespace configstore { +extern uint32_t DMXPORT_OFFSET; +} // namespace configstore +} // namespace artnetnode + static uint32_t s_nPortsMax; namespace artnetparams { @@ -360,6 +366,13 @@ void ArtNetParams::Builder(const struct Params *pParams, char *pBuffer, uint32_t builder.Add(LightSetParamsConst::FAILSAFE, lightset::get_failsafe(static_cast(m_Params.nFailSafe)), isMaskSet(Mask::FAILSAFE)); for (uint32_t nPortIndex = 0; nPortIndex < s_nPortsMax; nPortIndex++) { + const auto nOffset = nPortIndex + artnetnode::configstore::DMXPORT_OFFSET; + + if (nOffset >= artnetnode::MAX_PORTS) { + DEBUG_PUTS("break"); + break; + } + builder.Add(LightSetParamsConst::UNIVERSE_PORT[nPortIndex], m_Params.nUniverse[nPortIndex], isMaskSet(Mask::UNIVERSE_A << nPortIndex)); const auto portDir = portdir_get(nPortIndex); const auto isDefault = (portDir == lightset::PortDir::OUTPUT); @@ -368,8 +381,9 @@ void ArtNetParams::Builder(const struct Params *pParams, char *pBuffer, uint32_t const auto isLabelSet = isMaskSet(Mask::LABEL_A << nPortIndex); if (!isLabelSet) { - memcpy(m_Params.aLabel[nPortIndex], ArtNetNode::Get()->GetShortName(nPortIndex), artnet::SHORT_NAME_LENGTH); + memcpy(m_Params.aLabel[nPortIndex], ArtNetNode::Get()->GetShortName(nOffset), artnet::SHORT_NAME_LENGTH); } + builder.Add(LightSetParamsConst::NODE_LABEL[nPortIndex], reinterpret_cast(m_Params.aLabel[nPortIndex]), isLabelSet); } @@ -420,14 +434,14 @@ void ArtNetParams::Builder(const struct Params *pParams, char *pBuffer, uint32_t DEBUG_EXIT } -void ArtNetParams::Set(uint32_t nPortIndexOffset) { +void ArtNetParams::Set() { DEBUG_ENTRY - if (nPortIndexOffset <= artnetnode::MAX_PORTS) { - s_nPortsMax = std::min(artnet::PORTS, artnetnode::MAX_PORTS - nPortIndexOffset); + if (artnetnode::configstore::DMXPORT_OFFSET <= artnetnode::MAX_PORTS) { + s_nPortsMax = std::min(artnet::PORTS, artnetnode::MAX_PORTS - artnetnode::configstore::DMXPORT_OFFSET); } - DEBUG_PRINTF("artnetnode::MAX_PORTS=%u, nPortIndexOffset=%u, s_nPortsMax=%u", artnetnode::MAX_PORTS, nPortIndexOffset, s_nPortsMax); + DEBUG_PRINTF("artnetnode::MAX_PORTS=%u, artnetnode::configstore::DMXPORT_OFFSET=%u, s_nPortsMax=%u", artnetnode::MAX_PORTS, artnetnode::configstore::DMXPORT_OFFSET, s_nPortsMax); auto *const p = ArtNetNode::Get(); assert(p != nullptr); @@ -437,7 +451,7 @@ void ArtNetParams::Set(uint32_t nPortIndexOffset) { } for (uint32_t nPortIndex = 0; nPortIndex < s_nPortsMax; nPortIndex++) { - const auto nOffset = nPortIndex + nPortIndexOffset; + const auto nOffset = nPortIndex + artnetnode::configstore::DMXPORT_OFFSET; if (nOffset >= artnetnode::MAX_PORTS) { DEBUG_PUTS("break"); diff --git a/lib-artnet/src/node/rdm/setrdm.cpp b/lib-artnet/src/node/rdm/setrdm.cpp index ce1f9b3..24b3fb1 100755 --- a/lib-artnet/src/node/rdm/setrdm.cpp +++ b/lib-artnet/src/node/rdm/setrdm.cpp @@ -2,7 +2,7 @@ * @file setrdm.cpp * */ -/* Copyright (C) 2023 by Arjan van Vught mailto:info@gd32-dmx.org +/* Copyright (C) 2023-2024 by Arjan van Vught mailto:info@gd32-dmx.org * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,6 +26,7 @@ #include #include "artnetnode.h" +#include "artnetstore.h" #include "debug.h" @@ -47,13 +48,9 @@ void ArtNetNode::SetRdm(const uint32_t nPortIndex, const bool bEnable) { } if (m_State.status == artnetnode::Status::ON) { - if (m_pArtNetStore != nullptr) { - m_pArtNetStore->SaveRdmEnabled(nPortIndex, bEnable); - } - + ArtNetStore::SaveRdmEnabled(nPortIndex, bEnable); artnet::display_rdm_enabled(nPortIndex, bEnable); } - DEBUG_EXIT } diff --git a/lib-configstore/Rules.mk b/lib-configstore/Rules.mk index d2e044c..8c8fc20 100755 --- a/lib-configstore/Rules.mk +++ b/lib-configstore/Rules.mk @@ -1,6 +1,6 @@ $(info $$MAKE_FLAGS [${MAKE_FLAGS}]) -EXTRA_INCLUDES=../lib-flashcode/include ../lib-hal/include ../lib-properties/include ../lib-lightset/include ../lib-network/include +EXTRA_INCLUDES=../lib-flashcode/include ../lib-hal/include ifneq ($(MAKE_FLAGS),) ifneq (,$(findstring CONFIG_STORE_USE_FILE,$(MAKE_FLAGS))) @@ -22,105 +22,10 @@ ifneq ($(MAKE_FLAGS),) ifneq (,$(findstring CONFIG_STORE_USE_SPI,$(MAKE_FLAGS))) EXTRA_SRCDIR+=device/spi endif - - RDM= - - ifneq (,$(findstring ESP8266,$(MAKE_FLAGS))) - EXTRA_SRCDIR+=src/network - EXTRA_INCLUDES+=../lib-network/include - # Remote config is not used with ESP8266 - EXTRA_INCLUDES+=../lib-remoteconfig/include - endif - - ifeq (,$(findstring NO_EMAC,$(MAKE_FLAGS))) - EXTRA_SRCDIR+=src/network - EXTRA_INCLUDES+=../lib-network/include - EXTRA_INCLUDES+=../lib-remoteconfig/include - endif - - ifeq ($(findstring NODE_ARTNET,$(MAKE_FLAGS)), NODE_ARTNET) - EXTRA_SRCDIR+=src/artnet - EXTRA_INCLUDES+=../lib-artnet/include - RDM=1 - ifeq ($(findstring ARTNET_VERSION=4,$(MAKE_FLAGS)), ARTNET_VERSION=4) - EXTRA_INCLUDES+=../lib-e131/include - endif - endif - - ifeq ($(findstring NODE_E131,$(MAKE_FLAGS)), NODE_E131) - EXTRA_SRCDIR+=src/e131 - EXTRA_INCLUDES+=../lib-e131/include - endif - - ifeq ($(findstring NODE_NODE,$(MAKE_FLAGS)), NODE_NODE) - EXTRA_SRCDIR+=src/node - EXTRA_INCLUDES+=../lib-node/include ../lib-artnet/include ../lib-e131/include - RDM=1 - endif - - ifeq ($(findstring OUTPUT_DMX_PIXEL,$(MAKE_FLAGS)), OUTPUT_DMX_PIXEL) - EXTRA_SRCDIR+=src/pixel - EXTRA_INCLUDES+=../lib-ws28xxdmx/include ../lib-ws28xx/include - endif - - ifeq ($(findstring OUTPUT_DMX_STEPPER,$(MAKE_FLAGS)), OUTPUT_DMX_STEPPER) - EXTRA_SRCDIR+=src/stepper - EXTRA_INCLUDES+=../lib-l6470dmx/include ../lib-l6470/include - endif - - ifeq ($(findstring RDM_CONTROLLER,$(MAKE_FLAGS)), RDM_CONTROLLER) - ifdef RDM - else - RDM=1 - endif - endif - - ifeq ($(findstring RDM_RESPONDER,$(MAKE_FLAGS)), RDM_RESPONDER) - ifdef RDM - else - RDM=1 - endif - EXTRA_INCLUDES+=../lib-rdmresponder/include - EXTRA_INCLUDES+=../lib-rdmsensor/include - ifeq ($(findstring ENABLE_RDM_SUBDEVICES,$(MAKE_FLAGS)), ENABLE_RDM_SUBDEVICES) - EXTRA_INCLUDES+=../lib-rdmsubdevice/include - endif - endif - - ifeq ($(findstring NODE_RDMNET_LLRP_ONLY,$(MAKE_FLAGS)), NODE_RDMNET_LLRP_ONLY) - ifdef RDM - else - RDM=1 - endif - endif - - ifdef RDM - EXTRA_INCLUDES+=../lib-rdm/include - endif else - ifneq (, $(shell test -d '../lib-network/src/noemac' && echo -n yes)) - DEFINES+=NO_EMAC - else - DEFINES+=ARTNET_VERSION=4 - EXTRA_INCLUDES+=../lib-remoteconfig/include - EXTRA_SRCDIR+=src/artnet - EXTRA_INCLUDES+=../lib-artnet/include - EXTRA_SRCDIR+=src/e131 - EXTRA_INCLUDES+=../lib-e131/include - EXTRA_SRCDIR+=src/node - EXTRA_INCLUDES+=../lib-node/include ../lib-rdmdiscovery/include - endif - - EXTRA_INCLUDES+=../lib-ws28xx/include - EXTRA_INCLUDES+=../lib-rdm/include ../lib-rdmsensor/include ../lib-rdmsubdevice/include - EXTRA_SRCDIR+=src/stepper - EXTRA_INCLUDES+=../lib-l6470dmx/include ../lib-l6470/include - - DEFINES+=LIGHTSET_PORTS=4 - DEFINES+=CONFIG_PIXELDMX_MAX_PORTS=8 - DEFINES+=CONFIG_DDPDISPLAY_MAX_PORTS=8 + EXTRA_SRCDIR+=device/file + EXTRA_SRCDIR+=device/i2c + EXTRA_SRCDIR+=device/ram + EXTRA_SRCDIR+=device/rom + EXTRA_SRCDIR+=device/spi endif - -EXTRA_INCLUDES+=../lib-displayudf/include ../lib-display/include -EXTRA_INCLUDES+=../lib-dmxreceiver/include ../lib-dmx/include -EXTRA_INCLUDES+=../lib-device/include \ No newline at end of file diff --git a/lib-configstore/include/configstore.h b/lib-configstore/include/configstore.h index 7454d23..eb65583 100755 --- a/lib-configstore/include/configstore.h +++ b/lib-configstore/include/configstore.h @@ -85,7 +85,7 @@ class ConfigStore: StoreDevice { Update(store, 0, pData, nDataLength); } - void Copy(const configstore::Store store, void *pData, uint32_t nDataLength, uint32_t nOffset = 0); + void Copy(const configstore::Store store, void *pData, uint32_t nDataLength, uint32_t nOffset = 0, const bool doUpdate = true); void ResetSetList(configstore::Store store); diff --git a/lib-configstore/include/storeartnet.h b/lib-configstore/include/storeartnet.h deleted file mode 100755 index 3987b5a..0000000 --- a/lib-configstore/include/storeartnet.h +++ /dev/null @@ -1,100 +0,0 @@ -/** - * @file storeartnet.h - * - */ -/* Copyright (C) 2019-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef STOREARTNET_H_ -#define STOREARTNET_H_ - -#include -#include - -#include "artnetparams.h" -#include "artnetstore.h" -#include "configstore.h" - -#include "debug.h" - -class StoreArtNet final: public ArtNetStore { -public: - StoreArtNet(uint32_t nPortIndexOffset); - - void SaveLongName(const char* pLongName) override { - DEBUG_ENTRY - - ConfigStore::Get()->Update(configstore::Store::NODE, offsetof(struct artnetparams::Params, aLongName), pLongName, artnet::LONG_NAME_LENGTH, artnetparams::Mask::LONG_NAME); - - DEBUG_EXIT - } - - void SaveFailSafe(const uint8_t nFailSafe) override { - DEBUG_ENTRY - - ConfigStore::Get()->Update(configstore::Store::NODE, offsetof(struct artnetparams::Params, nFailSafe), &nFailSafe, sizeof(uint8_t), artnetparams::Mask::FAILSAFE); - - DEBUG_EXIT - } - - void SaveUniverseSwitch(const uint32_t nPortIndex, __attribute__((unused)) const uint8_t nAddress) override { - DEBUG_ENTRY - - SaveUniverse(nPortIndex); - - DEBUG_EXIT - } - - void SaveNetSwitch(const uint32_t nPortIndex, __attribute__((unused)) const uint8_t nAddress) override { - DEBUG_ENTRY - - SaveUniverse(nPortIndex); - - DEBUG_EXIT - } - - void SaveSubnetSwitch(const uint32_t nPortIndex, __attribute__((unused)) const uint8_t nAddress) override { - DEBUG_ENTRY - - SaveUniverse(nPortIndex); - - DEBUG_EXIT - } - - void SaveShortName(uint32_t nPortIndex, const char *pShortName) override; - void SaveMergeMode(uint32_t nPortIndex, const lightset::MergeMode tMerge) override; - void SavePortProtocol(uint32_t nPortIndex, const artnet::PortProtocol tPortProtocol) override; - void SaveOutputStyle(uint32_t nPortIndex, const lightset::OutputStyle outputStyle) override; - void SaveRdmEnabled(uint32_t nPortIndex, bool isEnabled) override; - - static StoreArtNet *Get() { - return s_pThis; - } - -private: - void SaveUniverse(uint32_t nPortIndex); - -private: - static uint32_t s_nPortIndexOffset; - static StoreArtNet *s_pThis; -}; - -#endif /* STOREARTNET_H_ */ diff --git a/lib-configstore/src/artnet/storeartnet.cpp b/lib-configstore/src/artnet/storeartnet.cpp deleted file mode 100755 index 1ca13c4..0000000 --- a/lib-configstore/src/artnet/storeartnet.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/** - * @file storeartnet.cpp - * - */ -/** - * Art-Net Designed by and Copyright Artistic Licence Holdings Ltd. - */ -/* Copyright (C) 2018-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include -#include -#include - -#include "storeartnet.h" - -#include "artnetstore.h" -#include "artnetparams.h" -#include "artnet.h" -#include "artnetnode.h" - -#include "configstore.h" - -#include "debug.h" - -#define UNUSED __attribute__((unused)) - -uint32_t StoreArtNet::s_nPortIndexOffset; -StoreArtNet *StoreArtNet::s_pThis; - -StoreArtNet::StoreArtNet(uint32_t nPortIndexOffset) { - DEBUG_ENTRY - DEBUG_PRINTF("nPortIndexOffset=%u", nPortIndexOffset); - - assert(s_pThis == nullptr); - s_pThis = this; - - s_nPortIndexOffset = nPortIndexOffset; - - DEBUG_PRINTF("%p", reinterpret_cast(s_pThis)); - DEBUG_EXIT -} - -void StoreArtNet::SaveShortName(uint32_t nPortIndex, const char *pShortName) { - DEBUG_ENTRY - DEBUG_PRINTF("%u, %s", nPortIndex, pShortName); - - if (nPortIndex >= s_nPortIndexOffset) { - nPortIndex -= s_nPortIndexOffset; - } else { - DEBUG_EXIT - return; - } - - DEBUG_PRINTF("nPortIndex=%u", nPortIndex); - - if (nPortIndex >= artnet::PORTS) { - DEBUG_EXIT - return; - } - - ConfigStore::Get()->Update(configstore::Store::NODE, (artnet::SHORT_NAME_LENGTH * nPortIndex) + offsetof(struct artnetparams::Params, aLabel), pShortName, artnet::SHORT_NAME_LENGTH, artnetparams::Mask::LABEL_A << nPortIndex); - - DEBUG_EXIT -} - -void StoreArtNet::SaveUniverse(uint32_t nPortIndex) { - DEBUG_ENTRY - DEBUG_PRINTF("s_nPortIndexOffset=%u, nPortIndex=%u", s_nPortIndexOffset, nPortIndex); - - if (nPortIndex >= s_nPortIndexOffset) { - nPortIndex -= s_nPortIndexOffset; - } else { - DEBUG_EXIT - return; - } - - DEBUG_PRINTF("nPortIndex=%u", nPortIndex); - - if (nPortIndex >= artnet::PORTS) { - DEBUG_EXIT - return; - } - - uint16_t nUniverse; - - if (ArtNetNode::Get()->GetPortAddress(nPortIndex, nUniverse)) { - DEBUG_PRINTF("nPortIndex=%u, nUniverse=%u", nPortIndex, nUniverse); - ConfigStore::Get()->Update(configstore::Store::NODE, (sizeof(uint16_t) * nPortIndex) + offsetof(struct artnetparams::Params, nUniverse), &nUniverse, sizeof(uint16_t), artnetparams::Mask::UNIVERSE_A << nPortIndex); - } - - DEBUG_EXIT -} - -void StoreArtNet::SaveMergeMode(uint32_t nPortIndex, const lightset::MergeMode mergeMode) { - DEBUG_ENTRY - DEBUG_PRINTF("%u, %u", nPortIndex, static_cast(mergeMode)); - - if (nPortIndex >= s_nPortIndexOffset) { - nPortIndex -= s_nPortIndexOffset; - } else { - DEBUG_EXIT - return; - } - - DEBUG_PRINTF("nPortIndex=%u", nPortIndex); - - if (nPortIndex >= artnet::PORTS) { - DEBUG_EXIT - return; - } - - uint16_t nMergeMode; - ConfigStore::Get()->Copy(configstore::Store::NODE, &nMergeMode, sizeof(uint16_t), offsetof(struct artnetparams::Params, nMergeMode)); - - nMergeMode &= artnetparams::mergemode_clear(nPortIndex); - nMergeMode |= artnetparams::mergemode_set(nPortIndex, mergeMode); - - ConfigStore::Get()->Update(configstore::Store::NODE, offsetof(struct artnetparams::Params, nMergeMode), &nMergeMode, sizeof(uint16_t)); - - DEBUG_EXIT -} - -void StoreArtNet::SavePortProtocol(uint32_t nPortIndex, const artnet::PortProtocol portProtocol) { - DEBUG_ENTRY - DEBUG_PRINTF("s_nPortIndexOffset=%u, nPortIndex=%u, portProtocol=%u", s_nPortIndexOffset, nPortIndex, static_cast(portProtocol)); - - if (nPortIndex >= s_nPortIndexOffset) { - nPortIndex -= s_nPortIndexOffset; - } else { - DEBUG_EXIT - return; - } - - DEBUG_PRINTF("nPortIndex=%u", nPortIndex); - - if (nPortIndex >= artnet::PORTS) { - DEBUG_EXIT - return; - } - - uint16_t nPortProtocol; - ConfigStore::Get()->Copy(configstore::Store::NODE, &nPortProtocol, sizeof(uint16_t), offsetof(struct artnetparams::Params, nProtocol)); - - nPortProtocol &= artnetparams::protocol_clear(nPortIndex); - nPortProtocol |= artnetparams::protocol_set(nPortIndex, portProtocol); - - ConfigStore::Get()->Update(configstore::Store::NODE, offsetof(struct artnetparams::Params, nProtocol), &nPortProtocol, sizeof(uint16_t)); - DEBUG_EXIT -} - -void StoreArtNet::SaveOutputStyle(uint32_t nPortIndex, const lightset::OutputStyle outputStyle) { - DEBUG_ENTRY - DEBUG_PRINTF("s_nPortIndexOffset=%u, nPortIndex=%u, outputStyle=%u", s_nPortIndexOffset, nPortIndex, static_cast(outputStyle)); - - if (nPortIndex >= s_nPortIndexOffset) { - nPortIndex -= s_nPortIndexOffset; - } else { - DEBUG_EXIT - return; - } - - DEBUG_PRINTF("nPortIndex=%u", nPortIndex); - - if (nPortIndex >= artnet::PORTS) { - DEBUG_EXIT - return; - } - - uint8_t nOutputStyle; - ConfigStore::Get()->Copy(configstore::Store::NODE, &nOutputStyle, sizeof(uint8_t), offsetof(struct artnetparams::Params, nOutputStyle)); - - if (outputStyle == lightset::OutputStyle::CONSTANT) { - nOutputStyle |= static_cast(1U << nPortIndex); - } else { - nOutputStyle &= static_cast(~(1U << nPortIndex)); - } - - ConfigStore::Get()->Update(configstore::Store::NODE, offsetof(struct artnetparams::Params, nOutputStyle), &nOutputStyle, sizeof(uint8_t)); - - DEBUG_EXIT -} - -void StoreArtNet::SaveRdmEnabled(uint32_t nPortIndex, const bool isEnabled) { - DEBUG_ENTRY - DEBUG_PRINTF("s_nPortIndexOffset=%u, nPortIndex=%u, isEnabled=%d", s_nPortIndexOffset, nPortIndex, isEnabled); - - if (nPortIndex >= s_nPortIndexOffset) { - nPortIndex -= s_nPortIndexOffset; - } else { - DEBUG_EXIT - return; - } - - DEBUG_PRINTF("nPortIndex=%u", nPortIndex); - - if (nPortIndex >= artnet::PORTS) { - DEBUG_EXIT - return; - } - - uint16_t nRdm; - ConfigStore::Get()->Copy(configstore::Store::NODE, &nRdm, sizeof(uint16_t), offsetof(struct artnetparams::Params, nRdm)); - - nRdm &= artnetparams::clear_mask(nPortIndex); - - if (isEnabled) { - nRdm |= artnetparams::shift_left(1, nPortIndex); - nRdm |= static_cast(1U << (nPortIndex + 8)); - } - - ConfigStore::Get()->Update(configstore::Store::NODE, offsetof(struct artnetparams::Params, nRdm), &nRdm, sizeof(uint16_t)); - - DEBUG_EXIT -} diff --git a/lib-configstore/src/configstore.cpp b/lib-configstore/src/configstore.cpp index a57e462..35b6ec8 100755 --- a/lib-configstore/src/configstore.cpp +++ b/lib-configstore/src/configstore.cpp @@ -171,9 +171,8 @@ void ConfigStore::Update(Store store, uint32_t nOffset, const void *pData, uint3 pSrc++; } - if ((0 != nOffset) && (bIsChanged) && (nSetList != 0)) { + if (bIsChanged){ auto *pSet = reinterpret_cast((&s_SpiFlashData[GetStoreOffset(store)] + nOffsetSetList)); - *pSet |= nSetList; } @@ -181,12 +180,13 @@ void ConfigStore::Update(Store store, uint32_t nOffset, const void *pData, uint3 s_State = State::CHANGED; } + debug_dump(&s_SpiFlashData[GetStoreOffset(store)] + nOffsetSetList, 8); DEBUG_EXIT } -void ConfigStore::Copy(const Store store, void *pData, uint32_t nDataLength, uint32_t nOffset) { +void ConfigStore::Copy(const Store store, void *pData, uint32_t nDataLength, uint32_t nOffset, const bool doUpdate) { DEBUG_ENTRY - DEBUG_PRINTF("[%s]:%u pData=%p, nDataLength=%u, nOffset=%u", s_aStoreName[static_cast(store)], static_cast(store), pData, nDataLength, nOffset); + DEBUG_PRINTF("[%s]:%u pData=%p, nDataLength=%u, nOffset=%u, doUpdate=%u", s_aStoreName[static_cast(store)], static_cast(store), pData, nDataLength, nOffset, doUpdate); assert(store < Store::LAST); assert(pData != nullptr); @@ -210,7 +210,9 @@ void ConfigStore::Copy(const Store store, void *pData, uint32_t nDataLength, uin return; } - Update(store, pData, nDataLength); + if (doUpdate) { + Update(store, pData, nDataLength); + } DEBUG_EXIT } diff --git a/lib-displayudf/include/displayudf.h b/lib-displayudf/include/displayudf.h index 1aae935..d10d26a 100644 --- a/lib-displayudf/include/displayudf.h +++ b/lib-displayudf/include/displayudf.h @@ -180,7 +180,7 @@ class DisplayUdf final: public Display { */ #if defined (NODE_ARTNET) - void Show(ArtNetNode *pArtNetNode, uint32_t nPortIndexOffset = 0); + void Show(ArtNetNode *pArtNetNode); void ShowUniverse(ArtNetNode *pArtNetNode); void ShowDestinationIp(ArtNetNode *pArtNetNode); #endif @@ -190,7 +190,7 @@ class DisplayUdf final: public Display { */ #if defined (NODE_E131) - void Show(E131Bridge *pE131Bridge, uint32_t nPortIndexOffset = 0); + void Show(E131Bridge *pE131Bridge); #endif /** @@ -308,9 +308,6 @@ class DisplayUdf final: public Display { private: char m_aTitle[32]; uint8_t m_aLabels[static_cast(displayudf::Labels::UNKNOWN)]; -#if defined (NODE_ARTNET) || defined (NODE_E131) - uint32_t m_nPortIndexOffset { 0 }; -#endif #if defined (DISPLAYUDF_DMX_INFO) struct DmxInfo { displayudf::dmx::PortDir portDir; diff --git a/lib-displayudf/src/artnet/displayudfshowartnet.cpp b/lib-displayudf/src/artnet/displayudfshowartnet.cpp index 93195b1..667d5e6 100644 --- a/lib-displayudf/src/artnet/displayudfshowartnet.cpp +++ b/lib-displayudf/src/artnet/displayudfshowartnet.cpp @@ -35,12 +35,15 @@ #include "debug.h" -void DisplayUdf::Show(ArtNetNode *pArtNetNode, uint32_t nDmxPortIndexOffset) { - DEBUG_ENTRY - - m_nPortIndexOffset = nDmxPortIndexOffset; +namespace artnetnode { +namespace configstore { +extern uint32_t DMXPORT_OFFSET; +} // namespace configstore +} // namespace artnetnode - DEBUG_PRINTF("m_nPortIndexOffset=%u", m_nPortIndexOffset); +void DisplayUdf::Show(ArtNetNode *pArtNetNode) { + DEBUG_ENTRY + DEBUG_PRINTF("artnetnode::configstore::DMXPORT_OFFSET=%u", artnetnode::configstore::DMXPORT_OFFSET); Show(); @@ -60,7 +63,7 @@ void DisplayUdf::ShowUniverse(ArtNetNode *pArtNetNode) { uint16_t nUniverse; for (uint32_t nArtNetPortIndex = 0; nArtNetPortIndex < std::min(artnet::PORTS, artnetnode::MAX_PORTS); nArtNetPortIndex++) { - const auto nPortIndex = nArtNetPortIndex + m_nPortIndexOffset; + const auto nPortIndex = nArtNetPortIndex + artnetnode::configstore::DMXPORT_OFFSET; if (nPortIndex >= std::min(artnet::PORTS, artnetnode::MAX_PORTS)) { break; diff --git a/lib-displayudf/src/e131/displayudfshowe131.cpp b/lib-displayudf/src/e131/displayudfshowe131.cpp index 3dced55..e090a71 100644 --- a/lib-displayudf/src/e131/displayudfshowe131.cpp +++ b/lib-displayudf/src/e131/displayudfshowe131.cpp @@ -32,19 +32,22 @@ #include "debug.h" -void DisplayUdf::Show(E131Bridge *pE131Bridge, uint32_t nDmxPortIndexOffset) { - DEBUG_ENTRY - - m_nPortIndexOffset = nDmxPortIndexOffset; +namespace e131bridge { +namespace configstore { +extern uint32_t DMXPORT_OFFSET; +} // namespace configstore +} // namespace e131bridge - DEBUG_PRINTF("m_nDmxPortIndexOffset=%u", m_nPortIndexOffset); +void DisplayUdf::Show(E131Bridge *pE131Bridge) { + DEBUG_ENTRY + DEBUG_PRINTF("e131bridge::configstore::DMXPORT_OFFSET=%u", e131bridge::configstore::DMXPORT_OFFSET); Show(); Printf(m_aLabels[static_cast(displayudf::Labels::AP)], "AP: %d", pE131Bridge->GetActiveOutputPorts() + pE131Bridge->GetActiveInputPorts()); for (uint32_t nBridgePortIndex = 0; nBridgePortIndex < std::min(static_cast(4), e131bridge::MAX_PORTS); nBridgePortIndex++) { - const auto nPortIndex = nBridgePortIndex + m_nPortIndexOffset; + const auto nPortIndex = nBridgePortIndex + e131bridge::configstore::DMXPORT_OFFSET; if (nPortIndex >= std::min(static_cast(4), e131bridge::MAX_PORTS)) { break; diff --git a/lib-e131/include/e131params.h b/lib-e131/include/e131params.h index ce8427d..a92f4ed 100644 --- a/lib-e131/include/e131params.h +++ b/lib-e131/include/e131params.h @@ -134,7 +134,7 @@ class E131Params { Builder(nullptr, pBuffer, nLength, nSize); } - void Set(uint32_t nPortIndexOffset); + void Set(); uint16_t GetUniverse(uint32_t nPortIndex, bool &IsSet) const { if (nPortIndex < e131params::MAX_PORTS) { diff --git a/lib-e131/src/node/e131params.cpp b/lib-e131/src/node/e131params.cpp index acc97ff..b61c5da 100644 --- a/lib-e131/src/node/e131params.cpp +++ b/lib-e131/src/node/e131params.cpp @@ -48,6 +48,12 @@ #include "debug.h" +namespace e131bridge { +namespace configstore { +extern uint32_t DMXPORT_OFFSET; +} // namespace configstore +} // namespace e131bridge + static uint32_t s_nPortsMax; namespace e131params { @@ -300,14 +306,14 @@ void E131Params::Builder(const struct Params *pParams, char *pBuffer, uint32_t n DEBUG_EXIT } -void E131Params::Set(uint32_t nPortIndexOffset) { +void E131Params::Set() { DEBUG_ENTRY - if (nPortIndexOffset <= e131bridge::MAX_PORTS) { - s_nPortsMax = std::min(e131params::MAX_PORTS, e131bridge::MAX_PORTS - nPortIndexOffset); + if (e131bridge::configstore::DMXPORT_OFFSET <= e131bridge::MAX_PORTS) { + s_nPortsMax = std::min(e131params::MAX_PORTS, e131bridge::MAX_PORTS - e131bridge::configstore::DMXPORT_OFFSET); } - DEBUG_PRINTF("e131bridge::MAX_PORTS=%u, nPortIndexOffset=%u, s_nPortsMax=%u", e131bridge::MAX_PORTS, nPortIndexOffset, s_nPortsMax); + DEBUG_PRINTF("e131bridge::MAX_PORTS=%u, e131bridge::configstore::DMXPORT_OFFSET=%u, s_nPortsMax=%u", e131bridge::MAX_PORTS, e131bridge::configstore::DMXPORT_OFFSET, s_nPortsMax); if (m_Params.nSetList == 0) { return; @@ -317,7 +323,7 @@ void E131Params::Set(uint32_t nPortIndexOffset) { assert(p != nullptr); for (uint32_t nPortIndex = 0; nPortIndex < s_nPortsMax; nPortIndex++) { - const auto nOffset = nPortIndex + nPortIndexOffset; + const auto nOffset = nPortIndex + e131bridge::configstore::DMXPORT_OFFSET; if (nOffset >= e131bridge::MAX_PORTS) { DEBUG_EXIT diff --git a/lib-rdm/Rules.mk b/lib-rdm/Rules.mk index 70ad121..39bbbcd 100644 --- a/lib-rdm/Rules.mk +++ b/lib-rdm/Rules.mk @@ -31,6 +31,6 @@ else EXTRA_SRCDIR+=src/responder endif DEFINES+=ENABLE_RDM_SUBDEVICES CONFIG_RDM_SUBDEVICES_USE_I2C CONFIG_RDM_SUBDEVICES_USE_SPI - DEFINES+=ENABLE_RDM_MANUFACTURER_PIDS + DEFINES+=ENABLE_RDM_MANUFACTURER_PIDS CONFIG_RDM_MANUFACTURER_PIDS_SET DEFINES+=RDM_RESPONDER endif \ No newline at end of file diff --git a/lib-rdm/include/rdm_manufacturer_pid.h b/lib-rdm/include/rdm_manufacturer_pid.h index 1b87b60..8ca4bc6 100755 --- a/lib-rdm/include/rdm_manufacturer_pid.h +++ b/lib-rdm/include/rdm_manufacturer_pid.h @@ -2,7 +2,7 @@ * @file rdm_manufacturer_pid.h * */ -/* Copyright (C) 2023 by Arjan van Vught mailto:info@gd32-dmx.org +/* Copyright (C) 2023-2024 by Arjan van Vught mailto:info@gd32-dmx.org * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -75,7 +75,7 @@ struct ManufacturerParamData { }; bool handle_manufactureer_pid_get(const uint16_t nPid, const ManufacturerParamData *pIn, ManufacturerParamData *pOut, uint16_t& nReason); -bool handle_manufactureer_pid_set(bool isBroadcast, const uint16_t nPid, const rdm::ParameterDescription ¶meterDescription, const ManufacturerParamData *pIn, ManufacturerParamData *pOut, uint16_t& nReason); +bool handle_manufactureer_pid_set(const bool isBroadcast, const uint16_t nPid, const rdm::ParameterDescription ¶meterDescription, const ManufacturerParamData *pIn, ManufacturerParamData *pOut, uint16_t& nReason); } // namespace rdm #endif /* RDM_MANUFACTURER_PID_H_ */ diff --git a/lib-rdm/include/rdmhandler.h b/lib-rdm/include/rdmhandler.h index 681fa37..68b0578 100644 --- a/lib-rdm/include/rdmhandler.h +++ b/lib-rdm/include/rdmhandler.h @@ -2,7 +2,7 @@ * @file rdmhandler.h * */ -/* Copyright (C) 2018-2023 by Arjan van Vught mailto:info@gd32-dmx.org +/* Copyright (C) 2018-2024 by Arjan van Vught mailto:info@gd32-dmx.org * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -129,7 +129,7 @@ class RDMHandler { #if defined (ENABLE_RDM_PRESET_PLAYBACK) void SetPresetPlayback(bool IsBroadcast, uint16_t nSubDevice); #endif -#if defined (ENABLE_RDM_MANUFACTURER_PIDS) +#if defined (ENABLE_RDM_MANUFACTURER_PIDS) && defined (CONFIG_RDM_MANUFACTURER_PIDS_SET) void SetManufacturerPid(bool IsBroadcast, uint16_t nSubDevice); #endif // ANSI E1.37-1 diff --git a/lib-rdm/src/rdmhandler.cpp b/lib-rdm/src/rdmhandler.cpp index f9bcb79..f9e7fe0 100644 --- a/lib-rdm/src/rdmhandler.cpp +++ b/lib-rdm/src/rdmhandler.cpp @@ -2,7 +2,7 @@ * @file rdmhandler.cpp * */ -/* Copyright (C) 2018-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl +/* Copyright (C) 2018-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -136,9 +136,9 @@ const RDMHandler::PidDefinition RDMHandler::PID_DEFINITIONS_SUB_DEVICES[] { #if defined (ENABLE_RDM_MANUFACTURER_PIDS) # if defined (CONFIG_RDM_MANUFACTURER_PIDS_SET) -const RDMHandler::PidDefinition RDMHandler::PID_DEFINITION_MANUFACTURER_GENERAL { 0, &RDMHandler::GetManufacturerPid, nullptr, 0, false, true, false }; +const RDMHandler::PidDefinition RDMHandler::PID_DEFINITION_MANUFACTURER_GENERAL { 0, &RDMHandler::GetManufacturerPid, &RDMHandler::SetManufacturerPid, 0, false, true, false }; # else -const RDMHandler::PidDefinition RDMHandler::PID_DEFINITION_MANUFACTURER_GENERAL { 0, &RDMHandler::GetManufacturerPid, nullptr, 0, false, true, false }; +const RDMHandler::PidDefinition RDMHandler::PID_DEFINITION_MANUFACTURER_GENERAL { 0, &RDMHandler::GetManufacturerPid, nullptr, 0, false, true, false }; # endif #endif @@ -573,6 +573,27 @@ void RDMHandler::GetManufacturerPid(__attribute__((unused)) uint16_t nSubDevice RespondMessageNack(nReason); } # if defined (CONFIG_RDM_MANUFACTURER_PIDS_SET) +void RDMHandler::SetManufacturerPid(bool IsBroadcast, __attribute__((unused)) uint16_t nSubDevice) { + const auto *pRdmDataIn = reinterpret_cast(m_pRdmDataIn); + auto *pRdmDataOut = reinterpret_cast(m_pRdmDataOut); + + const auto nPid = static_cast(pRdmDataIn->param_id[0] + (pRdmDataIn->param_id[1] << 8)); + const rdm::ManufacturerParamData pIn = { pRdmDataIn->param_data_length, const_cast(pRdmDataIn->param_data) }; + rdm::ManufacturerParamData pOut = { 0, pRdmDataOut->param_data }; + uint16_t nReason = E120_NR_UNKNOWN_PID; + + for (uint32_t nIndex = 0; nIndex < GetParameterDescriptionCount(); nIndex++) { + if (PARAMETER_DESCRIPTIONS[nIndex].pid == nPid) { + if (rdm::handle_manufactureer_pid_set(IsBroadcast, nPid, PARAMETER_DESCRIPTIONS[nIndex], &pIn, &pOut, nReason)) { + pRdmDataOut->param_data_length = pOut.nPdl; + RespondMessageAck(); + return; + } + } + } + + RespondMessageNack(nReason); +} # endif // CONFIG_RDM_MANUFACTURER_PIDS_SET # endif // ENABLE_RDM_MANUFACTURER_PIDS #endif diff --git a/lib-remoteconfig/src/remoteconfig.cpp b/lib-remoteconfig/src/remoteconfig.cpp index b718940..87a37a7 100644 --- a/lib-remoteconfig/src/remoteconfig.cpp +++ b/lib-remoteconfig/src/remoteconfig.cpp @@ -70,7 +70,6 @@ /* artnet.txt */ # include "artnetnode.h" # include "artnetparams.h" -# include "storeartnet.h" #endif #if defined (NODE_E131) @@ -110,7 +109,6 @@ /* node.txt */ # include "node.h" # include "nodeparams.h" -# include "storenode.h" #endif /** diff --git a/lib-ws28xxdmx/Rules.mk b/lib-ws28xxdmx/Rules.mk index 0649b27..6c54f00 100644 --- a/lib-ws28xxdmx/Rules.mk +++ b/lib-ws28xxdmx/Rules.mk @@ -18,7 +18,7 @@ ifneq ($(MAKE_FLAGS),) else DEFINES+=CONFIG_PIXELDMX_MAX_PORTS=8 DEFINES+=LIGHTSET_PORTS=32 - DEFINES+=ENABLE_RDM_MANUFACTURER_PIDS + DEFINES+=ENABLE_RDM_MANUFACTURER_PIDS CONFIG_RDM_MANUFACTURER_PIDS_SET DEFINES+=OUTPUT_DMX_PIXEL EXTRA_INCLUDES+=../lib-rdm/include EXTRA_SRCDIR+=src/dmx src/dmxmulti src/rdm diff --git a/lib-ws28xxdmx/src/rdm/rdm_manufacturer_pid.cpp b/lib-ws28xxdmx/src/rdm/rdm_manufacturer_pid.cpp index a80e608..c25594b 100755 --- a/lib-ws28xxdmx/src/rdm/rdm_manufacturer_pid.cpp +++ b/lib-ws28xxdmx/src/rdm/rdm_manufacturer_pid.cpp @@ -2,7 +2,7 @@ * @file rdm_manufacturer_pid.cpp * */ -/* Copyright (C) 2023 by Arjan van Vught mailto:info@orangepi-dmx.nl +/* Copyright (C) 2023-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -33,6 +33,7 @@ #include "rdm_e120.h" #include "pixeltype.h" +#include "pixeldmxstore.h" #include "debug.h" @@ -72,7 +73,11 @@ const rdm::ParameterDescription RDMHandler::PARAMETER_DESCRIPTIONS[] = { { rdm::E120_MANUFACTURER_PIXEL_TYPE::code, rdm::DEVICE_DESCRIPTION_MAX_LENGTH, E120_DS_ASCII, +#if defined (CONFIG_RDM_MANUFACTURER_PIDS_SET) + E120_CC_GET_SET, +#else E120_CC_GET, +#endif 0, E120_UNITS_NONE, E120_PREFIX_NONE, @@ -84,8 +89,12 @@ const rdm::ParameterDescription RDMHandler::PARAMETER_DESCRIPTIONS[] = { }, { rdm::E120_MANUFACTURER_PIXEL_COUNT::code, 2, - E120_DS_UNSIGNED_DWORD, + E120_DS_UNSIGNED_WORD, +#if defined (CONFIG_RDM_MANUFACTURER_PIDS_SET) + E120_CC_GET_SET, +#else E120_CC_GET, +#endif 0, E120_UNITS_NONE, E120_PREFIX_NONE, @@ -97,8 +106,12 @@ const rdm::ParameterDescription RDMHandler::PARAMETER_DESCRIPTIONS[] = { }, { rdm::E120_MANUFACTURER_PIXEL_GROUPING_COUNT::code, 2, - E120_DS_UNSIGNED_DWORD, + E120_DS_UNSIGNED_WORD, +#if defined (CONFIG_RDM_MANUFACTURER_PIDS_SET) + E120_CC_GET_SET, +#else E120_CC_GET, +#endif 0, E120_UNITS_NONE, E120_PREFIX_NONE, @@ -111,7 +124,11 @@ const rdm::ParameterDescription RDMHandler::PARAMETER_DESCRIPTIONS[] = { { rdm::E120_MANUFACTURER_PIXEL_MAP::code, rdm::DEVICE_DESCRIPTION_MAX_LENGTH, E120_DS_ASCII, +#if defined (CONFIG_RDM_MANUFACTURER_PIDS_SET) + E120_CC_GET_SET, +#else E120_CC_GET, +#endif 0, E120_UNITS_NONE, E120_PREFIX_NONE, @@ -140,20 +157,16 @@ bool handle_manufactureer_pid_get(const uint16_t nPid, __attribute__((unused)) c } case rdm::E120_MANUFACTURER_PIXEL_COUNT::code: { const auto nCount = WS28xxDmx::Get()->GetCount(); - pOut->nPdl = 4; - pOut->pParamData[0] = static_cast(nCount >> 24); - pOut->pParamData[1] = static_cast(nCount >> 16); - pOut->pParamData[2] = static_cast(nCount >> 8); - pOut->pParamData[3] = static_cast(nCount); + pOut->nPdl = 2; + pOut->pParamData[0] = static_cast(nCount >> 8); + pOut->pParamData[1] = static_cast(nCount); return true; } case rdm::E120_MANUFACTURER_PIXEL_GROUPING_COUNT::code: { const auto nGroupingCount = WS28xxDmx::Get()->GetGroupingCount(); - pOut->nPdl = 4; - pOut->pParamData[0] = static_cast(nGroupingCount >> 24); - pOut->pParamData[1] = static_cast(nGroupingCount >> 16); - pOut->pParamData[2] = static_cast(nGroupingCount >> 8); - pOut->pParamData[3] = static_cast(nGroupingCount); + pOut->nPdl = 2; + pOut->pParamData[0] = static_cast(nGroupingCount >> 8); + pOut->pParamData[1] = static_cast(nGroupingCount); return true; } case rdm::E120_MANUFACTURER_PIXEL_MAP::code: { @@ -169,4 +182,69 @@ bool handle_manufactureer_pid_get(const uint16_t nPid, __attribute__((unused)) c nReason = E120_NR_UNKNOWN_PID; return false; } +#if defined (CONFIG_RDM_MANUFACTURER_PIDS_SET) +// C++ attribute: maybe_unused (since C++17) +bool handle_manufactureer_pid_set(const bool isBroadcast, const uint16_t nPid, const rdm::ParameterDescription ¶meterDescription, const ManufacturerParamData *pIn, __attribute__((unused)) ManufacturerParamData *pOut, uint16_t& nReason) { + if (isBroadcast) { + return false; + } + + switch (nPid) { + case rdm::E120_MANUFACTURER_PIXEL_COUNT::code: { + if (pIn->nPdl == 2) { + const uint16_t nCount = pIn->pParamData[1] | pIn->pParamData[0] << 8; + + if ((nCount < parameterDescription.min_value) && (nCount > parameterDescription.max_value)) { + nReason = E120_NR_DATA_OUT_OF_RANGE; + return false; + } + + PixelDmxStore::SaveCount(nCount); + return true; + } + + nReason = E120_NR_FORMAT_ERROR; + return false; + } + case rdm::E120_MANUFACTURER_PIXEL_GROUPING_COUNT::code: { + if (pIn->nPdl == 2) { + const uint16_t nGroupingCount = pIn->pParamData[1] | pIn->pParamData[0] << 8; + + if ((nGroupingCount < parameterDescription.min_value) && (nGroupingCount > parameterDescription.max_value)) { + nReason = E120_NR_DATA_OUT_OF_RANGE; + return false; + } + + PixelDmxStore::SaveGroupingCount(nGroupingCount); + return true; + } + + nReason = E120_NR_FORMAT_ERROR; + return false; + } + case rdm::E120_MANUFACTURER_PIXEL_MAP::code: { + if (pIn->nPdl == 3) { + const auto map = ::PixelType::GetMap(reinterpret_cast(pIn->pParamData)); + + if (map == pixel::Map::UNDEFINED) { + nReason = E120_NR_DATA_OUT_OF_RANGE; + return false; + } + + PixelDmxStore::SaveMap(static_cast(map)); + return true; + } + + nReason = E120_NR_FORMAT_ERROR; + return false; + } + default: + break; + } + + nReason = E120_NR_UNKNOWN_PID; + return false; + +} +#endif } // namespace rdm