Skip to content

Commit e9e10fe

Browse files
committed
Unify undefined labels and JSON guards
Adds a shared `common::kUndefined` string and replaces scattered literal "Undefined" fallbacks across DMX, RDM, LTC, and MIDI-related code. The remote config JSON endpoints now enforce non-null/non-zero output buffers with assertions, and several small consistency cleanups were applied (macro style `#ifdef`, Art-Net node ID print usage, and minor formatting/log message tidy-ups).
1 parent ad0e8b3 commit e9e10fe

13 files changed

Lines changed: 58 additions & 53 deletions

File tree

common/include/common/utils/utils_string.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ inline constexpr char kWarning[] = "Warning";
3333
inline constexpr char kError[] = "Error";
3434
inline constexpr char kSuccess[] = "Success";
3535
inline constexpr char kUnknown[] = "Unknown";
36+
inline constexpr char kUndefined[] = "Undefined";
3637

3738
constexpr const char* IsSuccess(bool is_success) {
3839
return is_success ? kSuccess : kError;

lib-artnet/include/artnet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ inline constexpr uint32_t kNetSwitch = 0;
3838
inline constexpr uint32_t kSubnetSwitch = 0;
3939
inline constexpr uint32_t kSwitch = 1;
4040
} // namespace defaults
41-
#if !defined(ARTNET_VERSION)
41+
#ifndef ARTNET_VERSION
4242
inline constexpr uint32_t kVersion = 4;
4343
#else
4444
inline constexpr uint32_t kVersion = ARTNET_VERSION;

lib-artnet/src/node/artnetnode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,9 @@ void ArtNetNode::SetNetworkDataLossCondition() {
642642
}
643643

644644
void ArtNetNode::Print() {
645-
printf("Art-Net %u V%u.%u\n", static_cast<unsigned int>(artnet::kVersion), static_cast<unsigned int>(ArtNetConst::kVersion[0]), static_cast<unsigned int>(ArtNetConst::kVersion[1]));
645+
printf("%s %u V%u.%u\n", artnet::kNodeId, static_cast<unsigned int>(artnet::kVersion), static_cast<unsigned int>(ArtNetConst::kVersion[0]), static_cast<unsigned int>(ArtNetConst::kVersion[1]));
646646
printf(" Long name : %s\n", reinterpret_cast<char*>(art_poll_reply_.long_name));
647-
#if defined(ARTNET_HAVE_TIMECODE)
647+
#ifdef ARTNET_HAVE_TIMECODE
648648
printf(" TimeCode IP: " IPSTR "\n", IP2STR(node_.ip_timecode));
649649
#endif
650650

lib-displayudf/src/artnet/displayudfshowartnet.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void DisplayUdf::ShowArtNetNode() {
4040
auto* artnet_node = ArtNetNode::Get();
4141

4242
ShowUniverseArtNetNode();
43-
#if defined(ARTNET_HAVE_DMXIN)
43+
#ifdef ARTNET_HAVE_DMXIN
4444
ShowDestinationIpArtNetNode();
4545
#endif
4646
Printf(labels_[static_cast<uint32_t>(displayudf::Labels::kAp)], "AP: %d", artnet_node->GetActiveOutputPorts() + artnet_node->GetActiveInputPorts());
@@ -49,7 +49,7 @@ void DisplayUdf::ShowArtNetNode() {
4949
}
5050

5151
void DisplayUdf::ShowUniverseArtNetNode() {
52-
#if defined(DMX_MAX_PORTS)
52+
#ifdef DMX_MAX_PORTS
5353
DISPLAYUDF_DEBUG_ENTRY();
5454
if constexpr (dmxnode::kConfigPortCount != 0) {
5555
auto* artnet_node = ArtNetNode::Get();
@@ -68,18 +68,19 @@ void DisplayUdf::ShowUniverseArtNetNode() {
6868
if (artnet_node->GetPortAddress(kPortIndex, universe, dmxnode::Direction::kOutput)) {
6969
ClearEndOfLine();
7070
Printf(labels_[kLabelIndex],
71-
#if defined(OUTPUT_HAVE_STYLESWITCH)
71+
#ifdef OUTPUT_HAVE_STYLESWITCH
7272
"%c %d %s %s %c %s",
7373
#else
7474
"%c %d %s %s %s",
7575
#endif
7676
'A' + config_port_index, universe, dmxnode::GetMergeMode(artnet_node->GetMergeMode(kPortIndex), true),
77+
7778
#if (ARTNET_VERSION >= 4)
7879
artnet::GetProtocolMode(artnet_node->GetPortProtocol4(kPortIndex), true),
7980
#else
80-
"Art-Net",
81+
artnet::kNodeId,
8182
#endif
82-
#if defined(OUTPUT_HAVE_STYLESWITCH)
83+
#ifdef OUTPUT_HAVE_STYLESWITCH
8384
artnet_node->GetOutputStyle(kPortIndex) == dmxnode::OutputStyle::kConstant ? 'C' : 'D',
8485
#endif
8586
artnet_node->Rdm(kPortIndex) ? "RDM" : "");

lib-dmxnode/include/dmxnode_nodetype.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#define DMXNODE_NODETYPE_H_
2727

2828
#include <cstdint>
29+
#include "common/utils/utils_string.h"
2930

3031
namespace dmxnode {
3132
enum class NodeType {
@@ -60,7 +61,7 @@ inline const char* GetNodeType(NodeType type) {
6061
return kNodeTypeNames[static_cast<uint32_t>(type)];
6162
}
6263

63-
return "Undefined";
64+
return common::kUndefined;
6465
}
6566
} // namespace dmxnode
6667

lib-dmxnode/include/dmxnode_outputtype.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,25 @@
2626
#define DMXNODE_OUTPUTTYPE_H_
2727

2828
#include <cstdint>
29+
#include "common/utils/utils_string.h"
2930

3031
namespace dmxnode {
3132
enum class OutputType {
32-
kDmx, //
33-
kDmxRdm, //
34-
kPixel, //
35-
kPixelDmx, //
36-
kPwm, //
37-
kRgbPanel, //
38-
kSerial, //
39-
kOsc, //
40-
kMonitor, //
41-
kStepper, //
42-
kPlayer, //
43-
kArtNet, //
44-
kTimeCode, //
45-
kNone, //
46-
kUndefined //
33+
kDmx, //
34+
kDmxRdm, //
35+
kPixel, //
36+
kPixelDmx, //
37+
kPwm, //
38+
kRgbPanel, //
39+
kSerial, //
40+
kOsc, //
41+
kMonitor, //
42+
kStepper, //
43+
kPlayer, //
44+
kArtNet, //
45+
kTimeCode, //
46+
kNone, //
47+
kUndefined, //
4748
};
4849

4950
inline constexpr const char* kOutputTypeNames[static_cast<uint32_t>(OutputType::kUndefined)] = {
@@ -60,15 +61,15 @@ inline constexpr const char* kOutputTypeNames[static_cast<uint32_t>(OutputType::
6061
"Player", //
6162
"Art-Net", //
6263
"Timecode", //
63-
"None" //
64+
"None", //
6465
};
6566

6667
inline const char* GetOutputType(OutputType type) {
6768
if (type < OutputType::kUndefined) {
6869
return kOutputTypeNames[static_cast<uint32_t>(type)];
6970
}
7071

71-
return "Undefined";
72+
return common::kUndefined;
7273
}
7374
} // namespace dmxnode
7475

lib-network/src/core/network_memory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Allocator {
8787

8888
uint8_t* Allocate() {
8989
if (IsFull()) {
90-
ERROR("Allocate:Full!");
90+
ERROR("Full");
9191
return nullptr;
9292
}
9393

@@ -105,7 +105,7 @@ class Allocator {
105105
assert(size <= kBlockSize);
106106

107107
if (IsFull()) {
108-
ERROR("Allocate:Full!");
108+
ERROR("Full");
109109
return UINT16_MAX;
110110
}
111111

lib-remoteconfig/src/http/json_action.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ static void SetDisplay(const char* val, uint32_t len) {
3737
}
3838

3939
static void SetIdentify(const char* val, uint32_t len) {
40-
if (len != 1) return;
40+
if (len != 1) {
41+
return;
42+
}
4143

4244
if (val[0] != '0') {
4345
board::statusled::SetMode(board::statusled::Mode::kFast);
@@ -48,7 +50,9 @@ static void SetIdentify(const char* val, uint32_t len) {
4850

4951
// TODO (a) Subject for deletion
5052
static void SetReboot(const char* val, uint32_t len) {
51-
if (len != 1) return;
53+
if (len != 1) {
54+
return;
55+
}
5256
if (val[0] != '0') board::Reboot();
5357
}
5458

lib-remoteconfig/src/http/json_config_directory.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@
2525
#include <cstddef>
2626
#include <cstdint>
2727
#include <cstdio>
28+
#include <cassert>
2829

2930
#include "http/json_infos.h"
3031

3132
namespace json::config {
3233
uint32_t Directory(char* out_buffer, uint32_t out_buffer_size) {
34+
assert(out_buffer != nullptr);
35+
assert(out_buffer_size != 0);
36+
3337
uint32_t total = 0;
3438

3539
total += static_cast<uint32_t>(snprintf(out_buffer + total, out_buffer_size - total, "{\"files\":{"));

lib-remoteconfig/src/http/json_getlist.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <cstring>
2727
#include <cstdio>
2828

29+
#include "common/utils/utils_string.h"
2930
#include "configstore.h"
3031
#include "configurationstore.h"
3132
#include "dmxnode_nodetype.h"
@@ -35,9 +36,8 @@
3536

3637
namespace json {
3738
uint32_t GetList(char* out_buffer, uint32_t out_buffer_size) {
38-
if ((out_buffer == nullptr) || (out_buffer_size == 0U)) {
39-
return 0U;
40-
}
39+
assert(out_buffer != nullptr);
40+
assert(out_buffer_size != 0);
4141

4242
uint8_t display_name[common::store::remoteconfig::kDisplayNameLength];
4343

@@ -47,10 +47,10 @@ uint32_t GetList(char* out_buffer, uint32_t out_buffer_size) {
4747

4848
#ifdef DMXNODE_NODETYPE_DEFINED
4949
if (display_name[0] == '\0') {
50-
const char* const long_name = DmxNodeNodeType::Get()->GetLongName();
50+
const char* const kLongName = DmxNodeNodeType::Get()->GetLongName();
5151

52-
if (long_name != nullptr) {
53-
strncpy(reinterpret_cast<char*>(display_name), long_name, common::store::remoteconfig::kDisplayNameLength - 1U);
52+
if (kLongName != nullptr) {
53+
strncpy(reinterpret_cast<char*>(display_name), kLongName, common::store::remoteconfig::kDisplayNameLength - 1U);
5454

5555
display_name[common::store::remoteconfig::kDisplayNameLength - 1U] = '\0';
5656
}
@@ -67,11 +67,11 @@ uint32_t GetList(char* out_buffer, uint32_t out_buffer_size) {
6767
const char* output_type = dmxnode::GetOutputType(dmxnode::kOutputType);
6868

6969
if (node_type == nullptr) {
70-
node_type = "Undefined";
70+
node_type = common::kUndefined;
7171
}
7272

7373
if (output_type == nullptr) {
74-
output_type = "Undefined";
74+
output_type = common::kWarning;
7575
}
7676

7777
const int kLength = snprintf(out_buffer, out_buffer_size,

0 commit comments

Comments
 (0)