Skip to content

Commit

Permalink
Improved panel led support
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvught committed Jan 5, 2024
1 parent f4bb907 commit 45be1c2
Show file tree
Hide file tree
Showing 25 changed files with 386 additions and 166 deletions.
24 changes: 24 additions & 0 deletions lib-artnet/include/artnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ enum class OpCodes: uint16_t {
OP_TODDATA = 0x8100, ///< This is an ArtTodData packet. It is used to send a Table of Devices (ToD) for RDM discovery.
OP_TODCONTROL = 0x8200, ///< This is an ArtTodControl packet. It is used to send RDM discovery control messages
OP_RDM = 0x8300, ///< This is an ArtRdm packet. It is used to send all non discovery RDM messages.
OP_RDMSUB = 0x8400, ///< This is an ArtRdmSub packet. It is used to send compressed, RDM Sub-Device data.
OP_TIMECODE = 0x9700, ///< This is an ArtTimeCode packet. It is used to transport time code over the network.
OP_TIMESYNC = 0x9800, ///< Used to synchronize real time date and clock
OP_TRIGGER = 0x9900, ///< Used to send trigger macros
Expand Down Expand Up @@ -595,6 +596,29 @@ struct ArtRdm {
uint8_t RdmPacket[255]; ///< The RDM data packet excluding the DMX StartCode.
}PACKED;

/**
* The ArtRdmSub packet is used to transfer Get, Set, GetResponse and SetResponse data to and from multiple sub-devices within an RDM device.
*/
struct ArtRdmSub {
uint8_t Id[8]; ///< Array of 8 characters, the final character is a null termination. Value = ‘A’ ‘r’ ‘t’ ‘-‘ ‘N’ ‘e’ ‘t’ 0x00
uint16_t OpCode; ///< OpAddress \ref TOpCodes
uint8_t ProtVerHi; ///< High byte of the Art-Net protocol revision number.
uint8_t ProtVerLo; ///< Low byte of the Art-Net protocol revision number. Current value 14.
uint8_t RdmVer; ///< Art-Net Devices that only support RDM DRAFT V1.0 set field to 0x00. Devices that support RDM STANDARD V1.0 set field to 0x01.
uint8_t Filler2; ///< Transmit as zero, receivers don’t test.
uint8_t UID[6]; ///< UID of target RDM device.
uint8_t Spare1; ///< Transmit as zero, receivers don’t test.
uint8_t CommandClass; ///< As per RDM specification. This field defines whether this is a Get, Set, GetResponse, SetResponse.
uint8_t ParameterId[2]; ///< As per RDM specification. This field defines the type of parameter contained in this packet. Big- endian.
uint8_t SubDevice[2]; ///< Defines the first device information contained in packet. This follows the RDM convention that 0 = root device and 1 = first subdevice. Big-endian.
uint8_t SubCount[2]; ///< The number of sub devices packed into packet. Zero is illegal. Big-endian.
uint8_t Spare2; ///< Transmit as zero, receivers don’t test.
uint8_t Spare3; ///< Transmit as zero, receivers don’t test.
uint8_t Spare4; ///< Transmit as zero, receivers don’t test.
uint8_t Spare5; ///< Transmit as zero, receivers don’t test.
uint8_t Data[231];
}PACKED;

struct ArtIpProg {
uint8_t Id[8]; ///< Array of 8 characters, the final character is a null termination. Value = ‘A’ ‘r’ ‘t’ ‘-‘ ‘N’ ‘e’ ‘t’ 0x00
uint16_t OpCode; ///< The OpCode defines the class of data following ArtPoll within this UDP packet. Transmitted low byte first. See \ref TOpCodes for the OpCode listing.
Expand Down
2 changes: 1 addition & 1 deletion lib-artnet/include/artnetconst.h
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) 2019-2022 by Arjan van Vught mailto:[email protected]
/* Copyright (C) 2019-2023 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
134 changes: 58 additions & 76 deletions lib-artnet/include/artnetnode.h
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) 2016-2023 by Arjan van Vught mailto:[email protected]
/* Copyright (C) 2016-2024 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 @@ -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)
Expand All @@ -65,6 +64,8 @@
#include "hardware.h"
#include "network.h"

#include "panel_led.h"

#include "debug.h"

namespace artnetnode {
Expand Down Expand Up @@ -178,15 +179,19 @@ struct InputPort {
};

inline artnetnode::FailSafe convert_failsafe(const lightset::FailSafe failsafe) {
const auto fs = static_cast<FailSafe>(static_cast<uint32_t>(failsafe) + static_cast<uint32_t>(FailSafe::LAST));
DEBUG_PRINTF("failsafe=%u, fs=%u", static_cast<uint32_t>(failsafe), static_cast<uint32_t>(fs));
return fs;
if (failsafe > lightset::FailSafe::PLAYBACK) {
return artnetnode::FailSafe::LAST;
}

return static_cast<artnetnode::FailSafe>(static_cast<uint32_t>(failsafe) + static_cast<uint32_t>(artnetnode::FailSafe::LAST));
}

inline lightset::FailSafe convert_failsafe(const artnetnode::FailSafe failsafe) {
const auto fs = static_cast<lightset::FailSafe>(static_cast<uint32_t>(failsafe) - static_cast<uint32_t>(FailSafe::LAST));
DEBUG_PRINTF("failsafe=%u, fs=%u", static_cast<uint32_t>(failsafe), static_cast<uint32_t>(fs));
return fs;
if (failsafe > artnetnode::FailSafe::RECORD) {
return lightset::FailSafe::HOLD;
}

return static_cast<lightset::FailSafe>(static_cast<uint32_t>(failsafe) - static_cast<uint32_t>(artnetnode::FailSafe::LAST));
}
} // namespace artnetnode

Expand All @@ -212,36 +217,64 @@ class ArtNetNode {
#if (ARTNET_VERSION >= 4)
E131Bridge::Run();
#endif
#if defined (LIGHTSET_HAVE_RUN)
m_pLightSet->Run();
#endif
#if defined (RDM_CONTROLLER)
if (m_State.rdm.IsEnabled) {
if (__builtin_expect((m_State.rdm.IsEnabled), 0)) {
assert(m_pArtNetRdmController != nullptr);
m_pArtNetRdmController->Run();

if (!m_State.rdm.IsDiscoveryRunning && ((m_nCurrentPacketMillis - m_State.rdm.nDiscoveryMillis) > (1000 * 60 * 15))) {
if (__builtin_expect((!m_State.rdm.IsDiscoveryRunning && ((m_nCurrentPacketMillis - m_State.rdm.nDiscoveryMillis) > (1000 * 60 * 15))), 0)) {
DEBUG_PUTS("RDM Discovery -> START");
m_State.rdm.IsDiscoveryRunning = true;
}

if (m_State.rdm.IsDiscoveryRunning) {
if (__builtin_expect((m_State.rdm.IsDiscoveryRunning), 0)) {
m_State.rdm.IsDiscoveryRunning = RdmDiscoveryRun();

if (!m_State.rdm.IsDiscoveryRunning) {
DEBUG_PUTS("RDM Discovery -> DONE");
m_State.rdm.nDiscoveryPortIndex = 0;
m_State.rdm.nDiscoveryMillis = m_nCurrentPacketMillis;
}
} else {
uint32_t nPortIndex;
bool bIsIncremental;
if (m_pArtNetRdmController->IsFinished(nPortIndex, bIsIncremental)) {
SendTod(nPortIndex);

DEBUG_PRINTF("TOD sent -> %u", nPortIndex);

if (m_OutputPort[nPortIndex].IsTransmitting) {
DEBUG_PUTS("m_pLightSet->Stop/Start");
m_pLightSet->Stop(nPortIndex);
m_pLightSet->Start(nPortIndex);
}
}
}
}
#endif
if ((m_nCurrentPacketMillis - m_nPreviousLedpanelMillis) > 200) {
m_nPreviousLedpanelMillis = m_nCurrentPacketMillis;
for (uint32_t nPortIndex = 0; nPortIndex < artnetnode::MAX_PORTS; nPortIndex++) {
hal::panel_led_off(hal::panelled::PORT_A_TX << nPortIndex);
#if defined (ARTNET_HAVE_DMXIN)
hal::panel_led_off(hal::panelled::PORT_A_RX << nPortIndex);
#endif
#if defined(CONFIG_PANELLED_RDM_PORT)
hal::panel_led_off(hal::panelled::PORT_A_RDM << nPortIndex);
#elif defined(CONFIG_PANELLED_RDM_NO_PORT)
hal::panel_led_off(hal::panelled::RDM << nPortIndex);
#endif
}
}
}

uint8_t GetVersion() const {
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() {
Expand Down Expand Up @@ -269,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<uint8_t>(~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)
Expand Down Expand Up @@ -467,10 +448,6 @@ class ArtNetNode {

void SetTimeCodeIp(uint32_t nDestinationIp);

void SetArtNetStore(ArtNetStore *pArtNetStore) {
m_pArtNetStore = pArtNetStore;
}

void SetArtNetTrigger(ArtNetTrigger *pArtNetTrigger) {
m_pArtNetTrigger = pArtNetTrigger;
}
Expand Down Expand Up @@ -574,10 +551,11 @@ class ArtNetNode {
void SetNetSwitch(const uint32_t nPortIndex, const uint8_t nNetSwitch);
void SetSubnetSwitch(const uint32_t nPortIndex, const uint8_t nSubnetSwitch);

#undef UNUSED
#if defined (ARTNET_ENABLE_SENDDIAG)
# define UNUSED
#else
# define UNUSED __attribute__((unused))
# define UNUSED __attribute__((unused))
#endif

void SendDiag(UNUSED const artnet::PriorityCodes priorityCode, UNUSED const char *format, ...) {
Expand Down Expand Up @@ -609,10 +587,6 @@ class ArtNetNode {
#endif
}

#if defined (ARTNET_ENABLE_SENDDIAG)
# undef UNUSED
#endif

void HandlePoll();
void HandleDmx();
void HandleSync();
Expand All @@ -623,6 +597,7 @@ class ArtNetNode {
void HandleTodData();
void HandleTodRequest();
void HandleRdm();
void HandleRdmSub();
void HandleIpProg();
void HandleDmxIn();
void HandleInput();
Expand Down Expand Up @@ -659,7 +634,11 @@ class ArtNetNode {

SendTod(nPortIndex);

DEBUG_PUTS("TOD sent");

if (m_OutputPort[nPortIndex].IsTransmitting) {
DEBUG_PUTS("m_pLightSet->Stop/Start");
m_pLightSet->Stop(nPortIndex);
m_pLightSet->Start(nPortIndex);
}

Expand All @@ -686,12 +665,12 @@ class ArtNetNode {
uint32_t m_nIpAddressFrom;
uint32_t m_nCurrentPacketMillis { 0 };
uint32_t m_nPreviousPacketMillis { 0 };
uint32_t m_nPreviousLedpanelMillis { 0 };

LightSet *m_pLightSet { nullptr };

ArtNetTimeCode *m_pArtNetTimeCode { nullptr };
ArtNetTrigger *m_pArtNetTrigger { nullptr };
ArtNetStore *m_pArtNetStore { nullptr };

artnetnode::Node m_Node;
artnetnode::State m_State;
Expand Down Expand Up @@ -726,4 +705,7 @@ class ArtNetNode {
static ArtNetNode *s_pThis;
};

#if defined (UNUSED)
# undef UNUSED
#endif
#endif /* ARTNETNODE_H_ */
2 changes: 1 addition & 1 deletion lib-artnet/include/artnetrdmresponder.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "rdmdeviceresponder.h"
#include "rdmpersonality.h"
#include "rdmhandler.h"
#include "rdm.h"
#include "rdmconst.h"

#include "lightset.h"

Expand Down
7 changes: 2 additions & 5 deletions lib-artnet/include/artnettimecode.h
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) 2016-2020 by Arjan van Vught mailto:[email protected]
/* Copyright (C) 2016-2023 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 @@ -41,12 +41,9 @@ struct TArtNetTimeCode {

class ArtNetTimeCode {
public:
virtual ~ArtNetTimeCode() {
}

virtual ~ArtNetTimeCode() = default;
virtual void Start()= 0;
virtual void Stop()= 0;

virtual void Handler(const struct TArtNetTimeCode*)= 0;
};

Expand Down
5 changes: 2 additions & 3 deletions lib-artnet/include/artnettrigger.h
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) 2019-2020 by Arjan van Vught mailto:[email protected]
/* Copyright (C) 2019-2023 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 @@ -50,8 +50,7 @@ struct TArtNetTrigger {

class ArtNetTrigger {
public:
virtual ~ArtNetTrigger() {}

virtual ~ArtNetTrigger() = default;
virtual void Handler(const struct TArtNetTrigger *ptArtNetTrigger)= 0;
};

Expand Down
2 changes: 1 addition & 1 deletion lib-artnet/src/controller/artnetcontroller.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) 2017-2022 by Arjan van Vught mailto:[email protected]
/* Copyright (C) 2017-2023 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
8 changes: 3 additions & 5 deletions 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 by Arjan van Vught mailto:[email protected]
/* Copyright (C) 2023-2024 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 @@ -34,6 +34,7 @@

#include "artnetnode.h"
#include "artnet.h"
#include "artnetstore.h"

#include "e131bridge.h"

Expand All @@ -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);
}

Expand Down
Loading

0 comments on commit 45be1c2

Please sign in to comment.