Skip to content

Commit f5b92df

Browse files
committed
Unconditionally set DMX slots; refactor status JSON
Always apply rounded up slot count when configuring DMX (move SetDmxSlots earlier and remove the conditional that skipped zero values). Refactor json_status_dmx to build the top-level Dmx array by delegating to the per-port Dmx(...) function (old PortInfo helper is commented out and array assembly/commas are handled here). Also apply a small whitespace/comment formatting tweak in dmxconst.h.
1 parent c67b284 commit f5b92df

3 files changed

Lines changed: 29 additions & 29 deletions

File tree

lib-dmx/include/dmxconst.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ inline constexpr uint32_t kMabTimeMin = 12; ///
6060
inline constexpr uint32_t kMabTimeMax = 1000000; ///< 1s
6161
inline constexpr uint32_t kRefreshRateDefault = 40; ///< 40 Hz
6262
inline constexpr uint32_t kPeriodDefault = (1000000U / kRefreshRateDefault); ///< 25000 us
63-
inline constexpr uint32_t kBreakToBreakTimeMin = 1204; ///< us
63+
inline constexpr uint32_t kBreakToBreakTimeMin = 1204; ///< us
6464
} // namespace transmit
6565
} // namespace dmx
6666

67-
#endif // DMXCONST_H_
67+
#endif // DMXCONST_H_

lib-dmx/src/json/dmxsendparams.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ void DmxSendParams::Set()
9999

100100
dmx.SetDmxBreakTime(store_dmx_send.break_time);
101101
dmx.SetDmxMabTime(store_dmx_send.mab_time);
102+
dmx.SetDmxSlots(RoundupSlots(store_dmx_send.slots_count));
102103

103104
uint32_t period = 0;
104105
if (store_dmx_send.refresh_rate != 0)
@@ -107,11 +108,6 @@ void DmxSendParams::Set()
107108
}
108109
dmx.SetDmxPeriodTime(period);
109110

110-
if (store_dmx_send.slots_count != 0)
111-
{
112-
dmx.SetDmxSlots(RoundupSlots(store_dmx_send.slots_count));
113-
}
114-
115111
#ifndef NDEBUG
116112
Dump();
117113
#endif

lib-dmx/src/json/json_status_dmx.cpp

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,18 @@
1111

1212
namespace json::status
1313
{
14-
static uint32_t PortInfo(char* out_buffer, uint32_t out_buffer_size, uint32_t port_index)
15-
{
16-
const auto kDirection = Dmx::Get()->GetPortDirection(port_index) == ::dmx::PortDirection::kInput ? ::dmxnode::PortDirection::kInput : ::dmxnode::PortDirection::kOutput;
17-
auto length = static_cast<uint32_t>(snprintf(out_buffer, out_buffer_size,
18-
"{\"port\":\"%c\",\"direction\":\"%s\"},",
19-
static_cast<char>('A' + port_index),
20-
dmxnode::GetPortDirection(kDirection)));
21-
22-
return length;
23-
}
24-
25-
uint32_t Dmx(char* out_buffer, uint32_t out_buffer_size) {
26-
out_buffer[0] = '[';
27-
uint32_t length = 1;
14+
//static uint32_t PortInfo(char* out_buffer, uint32_t out_buffer_size, uint32_t port_index)
15+
//{
16+
// const auto kDirection = Dmx::Get()->GetPortDirection(port_index) == ::dmx::PortDirection::kInput ? ::dmxnode::PortDirection::kInput : ::dmxnode::PortDirection::kOutput;
17+
// auto length = static_cast<uint32_t>(snprintf(out_buffer, out_buffer_size,
18+
// "{\"port\":\"%c\",\"direction\":\"%s\"},",
19+
// static_cast<char>('A' + port_index),
20+
// dmxnode::GetPortDirection(kDirection)));
21+
//
22+
// return length;
23+
//}
2824

29-
for (uint32_t port_index = 0; port_index < ::dmx::config::max::PORTS; port_index++)
30-
{
31-
length += PortInfo(&out_buffer[length], out_buffer_size - length, port_index);
32-
}
3325

34-
out_buffer[length - 1] = ']';
35-
36-
return length;
37-
}
3826
uint32_t Dmx(char* out_buffer, uint32_t out_buffer_size, uint32_t port_index) {
3927
if (port_index < ::dmx::config::max::PORTS)
4028
{
@@ -52,4 +40,20 @@ uint32_t Dmx(char* out_buffer, uint32_t out_buffer_size, uint32_t port_index) {
5240

5341
return 0;
5442
}
43+
44+
uint32_t Dmx(char* out_buffer, uint32_t out_buffer_size) {
45+
out_buffer[0] = '[';
46+
uint32_t length = 1;
47+
48+
for (uint32_t port_index = 0; port_index < ::dmx::config::max::PORTS; port_index++)
49+
{
50+
length += Dmx(&out_buffer[length], out_buffer_size - length, port_index);
51+
out_buffer[length++] = ',';
52+
}
53+
54+
out_buffer[length - 1] = ']';
55+
56+
return length;
57+
}
58+
5559
} // namespace json::status

0 commit comments

Comments
 (0)