Skip to content

Commit c7b713e

Browse files
committed
Add RDM SetFactoryDefaults and ConfigStore reset
Introduce a weak rdm::device::SetFactoryDefaults implementation (new lib-rdm/src/rdm_device.cpp) and expose its declaration in rdmdevice.h. Update RDMDeviceResponder to call rdm::device::SetFactoryDefaults and remove the old configstore forward declaration. Add ConfigStore::Reset() to zero stored data and mark status changed, and use it in RemoteConfig::HandleFactory to reset config and trigger reboot. Misc: switch to network_udp include, minor formatting/whitespace changes, and bump copyright year in remoteconfig.
1 parent 5610bc2 commit c7b713e

6 files changed

Lines changed: 102 additions & 29 deletions

File tree

lib-configstore/include/configstore.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,16 @@ class ConfigStore : StoreDevice
5555
kWriting
5656
};
5757

58-
[[maybe_unused]] static constexpr char kStateNames[7][16] = {"IDLE", "CHANGED", "CHANGED_WAITING", "ERASING", "ERASED", "ERASED_WAITING", "WRITING"};
58+
[[maybe_unused]] static constexpr char kStateNames[7][16] =
59+
{
60+
"IDLE",
61+
"CHANGED",
62+
"CHANGED_WAITING",
63+
"ERASING",
64+
"ERASED",
65+
"ERASED_WAITING",
66+
"WRITING"
67+
};
5968

6069
public:
6170
ConfigStore()
@@ -118,6 +127,12 @@ class ConfigStore : StoreDevice
118127
ConfigStore& operator=(ConfigStore&&) = delete;
119128

120129
~ConfigStore() = default;
130+
131+
void Reset()
132+
{
133+
memset(s_store, 0, sizeof(s_store));
134+
SetStatusChanged();
135+
}
121136

122137
bool Commit() { return Flash(); }
123138

lib-dmxnode/include/dmxnode_outputtype.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,23 @@ enum class OutputType
4848
kUndefined
4949
};
5050

51-
inline constexpr const char* kOutputTypeNames[static_cast<uint32_t>(OutputType::kUndefined)] = {
52-
"DMX", "DMX/RDM", "Pixel", "Pixel/DMX", "PWM", "RGB Panel", "Serial", "OSC", "Monitor", "Stepper", "Player", "Art-Net", "Timecode", "None"};
51+
inline constexpr const char* kOutputTypeNames[static_cast<uint32_t>(OutputType::kUndefined)] =
52+
{
53+
"DMX",
54+
"DMX/RDM",
55+
"Pixel",
56+
"Pixel/DMX",
57+
"PWM",
58+
"RGB Panel",
59+
"Serial",
60+
"OSC",
61+
"Monitor",
62+
"Stepper",
63+
"Player",
64+
"Art-Net",
65+
"Timecode",
66+
"None"
67+
};
5368

5469
inline const char* GetOutputType(OutputType type)
5570
{

lib-rdm/include/rdmdevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ uint32_t BootSoftwareVersionId();
4646
uint32_t SoftwareVersionId();
4747
const char* SoftwareVersionLabel(uint32_t& length);
4848
const char* RootLabel(uint8_t& length);
49+
void SetFactoryDefaults();
4950

5051
class Device
5152
{

lib-rdm/include/rdmdeviceresponder.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@
4040
#include "dmxnode.h"
4141
#include "dmxnode_outputtype.h"
4242

43-
namespace configstore
44-
{
45-
void SetFactoryDefaults();
46-
} // namespace configstore
47-
4843
class RDMDeviceResponder
4944
{
5045
static constexpr char kLanguage[2] = {'e', 'n'};
@@ -192,7 +187,7 @@ class RDMDeviceResponder
192187
checksum_ = CalculateChecksum();
193188
is_factory_defaults_ = true;
194189

195-
configstore::SetFactoryDefaults();
190+
rdm::device::SetFactoryDefaults();
196191

197192
DEBUG_EXIT();
198193
}

lib-rdm/src/rdm_device.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @file rdm_device.cpp
3+
*
4+
*/
5+
/* Copyright (C) 2026 by Arjan van Vught mailto:info@gd32-dmx.org
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
26+
#include "rdmdevice.h"
27+
#include "firmware/debug/debug_debug.h"
28+
29+
namespace rdm::device
30+
{
31+
__attribute__((weak)) void SetFactoryDefaults()
32+
{
33+
DEBUG_PUTS("Not implemented.");
34+
}
35+
} // namespace rdm::device

lib-remoteconfig/src/remoteconfig.cpp

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file remoteconfig.cpp
33
*
44
*/
5-
/* Copyright (C) 2019-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2019-2026 by Arjan van Vught mailto:info@gd32-dmx.org
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
88
* of this software and associated documentation files (the "Software"), to deal
@@ -35,7 +35,7 @@
3535
#include "remoteconfig.h"
3636
#include "firmwareversion.h"
3737
#include "hal.h"
38-
#include "network.h"
38+
#include "network_udp.h"
3939
#if !defined(CONFIG_REMOTECONFIG_MINIMUM)
4040
#include "apps/mdns.h"
4141
#include "dmxnode_nodetype.h"
@@ -44,7 +44,7 @@
4444
#include "display.h"
4545
#include "configstore.h"
4646
#include "firmware/debug/debug_dump.h"
47-
#include "firmware/debug/debug_debug.h"
47+
#include "firmware/debug/debug_debug.h"
4848

4949
namespace remoteconfig::udp
5050
{
@@ -91,11 +91,24 @@ constexpr struct RemoteConfig::Commands RemoteConfig::kSet[] = {
9191
{&RemoteConfig::HandleDisplaySet, "display#", 8, true} //
9292
};
9393

94-
static constexpr char kOutput[static_cast<uint32_t>(remoteconfig::Output::LAST)][12] = {"DMX", "RDM", "Monitor", "Pixel", "TimeCode", "OSC", "Config",
95-
"Stepper", "Player", "Art-Net", "Serial", "RGB Panel", "PWM"};
94+
static constexpr char kOutput[static_cast<uint32_t>(remoteconfig::Output::LAST)][12] =
95+
{
96+
"DMX",
97+
"RDM",
98+
"Monitor",
99+
"Pixel",
100+
"TimeCode",
101+
"OSC",
102+
"Config",
103+
"Stepper",
104+
"Player",
105+
"Art-Net",
106+
"Serial",
107+
"RGB Panel",
108+
"PWM"
109+
};
96110

97-
RemoteConfig::RemoteConfig(remoteconfig::Output output, uint32_t active_outputs)
98-
: output_(output), active_outputs_(active_outputs)
111+
RemoteConfig::RemoteConfig(remoteconfig::Output output, uint32_t active_outputs) : output_(output), active_outputs_(active_outputs)
99112
{
100113
DEBUG_ENTRY();
101114

@@ -104,7 +117,7 @@ RemoteConfig::RemoteConfig(remoteconfig::Output output, uint32_t active_outputs)
104117
assert(s_this == nullptr);
105118
s_this = this;
106119

107-
network::iface::CopyMacAddressTo(s_list.mac_address);
120+
network::iface::CopyMacAddressTo(s_list.mac_address);
108121
s_list.output = static_cast<uint8_t>(output);
109122
s_list.active_outputs = static_cast<uint8_t>(active_outputs);
110123

@@ -143,7 +156,6 @@ RemoteConfig::~RemoteConfig()
143156
delete http_daemon_;
144157
}
145158
#endif
146-
147159
network::apps::mdns::ServiceRecordDelete(network::apps::mdns::Services::kConfig);
148160
#endif
149161

@@ -156,31 +168,31 @@ RemoteConfig::~RemoteConfig()
156168
void RemoteConfig::SetDisplayName(const char* display_name)
157169
{
158170
DEBUG_ENTRY();
159-
171+
160172
char array[common::store::remoteconfig::kDisplayNameLength];
161173

162-
size_t len = strlen(display_name);
174+
size_t len = strlen(display_name);
163175
len = len > (common::store::remoteconfig::kDisplayNameLength - 1) ? common::store::remoteconfig::kDisplayNameLength - 1 : len;
164176
memcpy(reinterpret_cast<char*>(array), display_name, len);
165177

166178
for (uint32_t i = len; i < common::store::remoteconfig::kDisplayNameLength; i++)
167179
{
168180
array[i] = '\0';
169181
}
170-
171-
ConfigStore::Instance().RemoteConfigUpdateArray(&common::store::RemoteConfig::display_name, array, common::store::remoteconfig::kDisplayNameLength);
172182

173-
DEBUG_EXIT();
174-
}
183+
ConfigStore::Instance().RemoteConfigUpdateArray(&common::store::RemoteConfig::display_name, array, common::store::remoteconfig::kDisplayNameLength);
175184

176-
namespace configstore
177-
{
178-
void SetFactoryDefaults();
185+
DEBUG_EXIT();
179186
}
180187

181188
void RemoteConfig::HandleFactory()
182189
{
183-
configstore::SetFactoryDefaults();
190+
DEBUG_ENTRY();
191+
192+
ConfigStore::Instance().Reset();
193+
HandleReboot();
194+
195+
DEBUG_EXIT();
184196
}
185197

186198
void RemoteConfig::Input(const uint8_t* buffer, uint32_t size, uint32_t from_ip, [[maybe_unused]] uint16_t from_port)
@@ -301,7 +313,7 @@ void RemoteConfig::HandleList()
301313
#if !defined(CONFIG_REMOTECONFIG_MINIMUM)
302314
const auto* const kNodeTypeName = dmxnode::GetNodeType(dmxnode::kNodeType);
303315
#else
304-
const auto* const kNodeTypeName = "Bootloader TFTP";
316+
const auto* const kNodeTypeName = "Bootloader TFTP";
305317
#endif
306318

307319
if (display_name[0] != '\0')

0 commit comments

Comments
 (0)