3535#include " json/json_parsehelper.h"
3636#include " dmxconst.h"
3737#include " configstore.h"
38- #include " dmx.h"
38+ #include " dmx.h" // IWYU pragma: keep
3939
40- namespace json
41- {
40+ namespace json {
4241using dmx::kChannelsMax ;
4342
44- static constexpr uint8_t RounddownSlots (uint16_t n)
45- {
43+ static constexpr uint8_t RounddownSlots (uint16_t n) {
4644 return static_cast <uint8_t >((n / 2U ) - 1 );
4745}
4846
49- static constexpr uint16_t RoundupSlots (uint8_t n)
50- {
47+ static constexpr uint16_t RoundupSlots (uint8_t n) {
5148 return static_cast <uint16_t >((n + 1U ) * 2U );
5249}
5350
54- DmxSendParams::DmxSendParams ()
55- {
51+ DmxSendParams::DmxSendParams () {
5652 ConfigStore::Instance ().Copy (&store_dmx_send, &ConfigurationStore::dmx_send);
5753}
5854
59- void DmxSendParams::SetBreakTime (const char * val, uint32_t len)
60- {
61- ParseAndApply< uint16_t >(val, len, []( uint16_t v) { store_dmx_send.break_time = v > dmx::transmit::kBreakTimeMin ? v : dmx::transmit::kBreakTimeMin ; }) ;
55+ void DmxSendParams::SetBreakTime (const char * val, uint32_t len) {
56+ const auto kV = ParseValue< uint16_t >(val, len);
57+ store_dmx_send.break_time = kV > dmx::transmit::kBreakTimeMin ? kV : dmx::transmit::kBreakTimeMin ;
6258}
6359
64- void DmxSendParams::SetMabTime (const char * val, uint32_t len)
65- {
66- ParseAndApply< uint16_t >(val, len, []( uint16_t v) { store_dmx_send.mab_time = v > dmx::transmit::kMabTimeMin ? v : dmx::transmit::kMabTimeMin ; }) ;
60+ void DmxSendParams::SetMabTime (const char * val, uint32_t len) {
61+ const auto kV = ParseValue< uint16_t >(val, len);
62+ store_dmx_send.mab_time = kV > dmx::transmit::kMabTimeMin ? kV : dmx::transmit::kMabTimeMin ;
6763}
6864
69- void DmxSendParams::SetRefreshRate (const char * val, uint32_t len)
70- {
71- ParseAndApply<uint16_t >(val, len, [](uint16_t v) { store_dmx_send.refresh_rate = v; });
65+ void DmxSendParams::SetRefreshRate (const char * val, uint32_t len) {
66+ uint8_t v;
67+
68+ if (ParseInRange<uint16_t , uint8_t >(val, len, 1U , 255U , &v)) {
69+ store_dmx_send.refresh_rate = v;
70+ }
7271}
7372
74- void DmxSendParams::SetSlotsCount (const char * val, uint32_t len)
75- {
76- ParseAndApply<uint16_t >(val, len,
77- [](uint16_t v)
78- {
79- if (v >= 2 && v < dmx::kChannelsMax )
80- {
81- store_dmx_send.slots_count = RounddownSlots (v);
82- }
83- else
84- {
85- store_dmx_send.slots_count = RounddownSlots (dmx::kChannelsMax );
86- }
87- });
73+ void DmxSendParams::SetSlotsCount (const char * val, uint32_t len) {
74+ const auto kV = ParseValue<uint16_t >(val, len);
75+
76+ if (kV >= 2U && kV <= dmx::kChannelsMax ) {
77+ store_dmx_send.slots_count = RounddownSlots (kV );
78+ } else {
79+ store_dmx_send.slots_count = RounddownSlots (dmx::kChannelsMax );
80+ }
8881}
8982
90- void DmxSendParams::Store (const char * buffer, uint32_t buffer_size)
91- {
83+ void DmxSendParams::Store (const char * buffer, uint32_t buffer_size) {
9284 ParseJsonWithTable (buffer, buffer_size, kDmxSendKeys );
9385 ConfigStore::Instance ().Store (&store_dmx_send, &ConfigurationStore::dmx_send);
9486}
9587
96- void DmxSendParams::Set ()
97- {
88+ void DmxSendParams::Set () {
9889 auto & dmx = *Dmx::Get ();
9990
10091 dmx.SetDmxBreakTime (store_dmx_send.break_time );
10192 dmx.SetDmxMabTime (store_dmx_send.mab_time );
10293 dmx.SetDmxSlots (RoundupSlots (store_dmx_send.slots_count ));
10394
10495 uint32_t period = 0 ;
105- if (store_dmx_send.refresh_rate != 0 )
106- {
96+ if (store_dmx_send.refresh_rate != 0 ) {
10797 period = 1000000U / store_dmx_send.refresh_rate ;
10898 }
99+
109100 dmx.SetDmxPeriodTime (period);
110101
111102#ifndef NDEBUG
112103 Dump ();
113104#endif
114105}
115106
116- void DmxSendParams::Dump ()
117- {
107+ void DmxSendParams::Dump () {
118108 printf (" %s::%s \' %s\' :\n " , __FILE__, __FUNCTION__, json::DmxSendParamsConst::kFileName );
119109 printf (" %s=%u\n " , DmxSendParamsConst::kBreakTime .name , store_dmx_send.break_time );
120110 printf (" %s=%u\n " , DmxSendParamsConst::kMabTime .name , store_dmx_send.mab_time );
121111 printf (" %s=%u\n " , DmxSendParamsConst::kRefreshRate .name , store_dmx_send.refresh_rate );
122112 printf (" %s=%u [%u]\n " , DmxSendParamsConst::kSlotsCount .name , RoundupSlots (store_dmx_send.slots_count ), store_dmx_send.slots_count );
123113}
124-
125114} // namespace json
0 commit comments