|
2 | 2 | * @file json_config_rdmsensors.cpp |
3 | 3 | * |
4 | 4 | */ |
5 | | -/* Copyright (C) 2025 by Arjan van Vught mailto:info@gd32-dmx.org |
| 5 | +/* Copyright (C) 2025-2026 by Arjan van Vught mailto:info@gd32-dmx.org |
6 | 6 | * |
7 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
8 | 8 | * of this software and associated documentation files (the "Software"), to deal |
|
31 | 31 | #include "configstore.h" |
32 | 32 | #include "common/utils/utils_hex.h" |
33 | 33 |
|
34 | | -namespace json::config |
35 | | -{ |
36 | | -uint32_t GetRdmSensors(char* buffer, uint32_t length) |
37 | | -{ |
38 | | - return json::helpers::Serialize(buffer, length, [&](JsonDoc& doc) { |
39 | | - char a[32]; |
40 | | - for (size_t types = 0; types < json::RdmSensorsParams::KeysSize(); types++) |
41 | | - { |
42 | | - a[0] = '['; |
43 | | - uint32_t k = 1; |
44 | | - for (uint32_t j = 0; j < common::store::rdm::sensors::kMaxDevices; j++) |
45 | | - { |
46 | | - if ((k + 3) > 31) break; |
47 | | - const auto kType = ConfigStore::Instance().RdmSensorsIndexedGetType(j); |
48 | | - if (kType == types) |
49 | | - { |
50 | | - const auto kAddress = ConfigStore::Instance().RdmSensorsIndexedGetAddress(j); |
51 | | - if (kAddress != 0) |
52 | | - { |
53 | | - a[k++] = common::hex::ToCharLowercase(kAddress >> 4); |
54 | | - a[k++] = common::hex::ToCharLowercase(kAddress); |
55 | | - a[k++] = ','; |
56 | | - } |
57 | | - } |
58 | | - } |
59 | | - |
60 | | - if (a[k - 1] == ',') k -= 1; |
61 | | - |
62 | | - a[k++] = ']'; |
63 | | - a[k] = '\0'; |
64 | | - |
65 | | - const auto& keys = json::RdmSensorsParams::Keys(); |
66 | | - doc[keys[types].GetName()] = a; |
67 | | - } |
| 34 | +namespace json::config { |
| 35 | +uint32_t GetRdmSensors(char* buffer, uint32_t length) { |
| 36 | + return json::helpers::Serialize(buffer, length, [&](JsonDoc& doc) { |
| 37 | + char a[32]; |
| 38 | + for (size_t types = 0; types < json::RdmSensorsParams::KeysSize(); types++) { |
| 39 | + a[0] = '['; |
| 40 | + uint32_t k = 1; |
| 41 | + for (uint32_t j = 0; j < common::store::rdm::sensors::kMaxDevices; j++) { |
| 42 | + if ((k + 3) > 31) break; |
| 43 | + const auto kType = ConfigStore::Instance().RdmSensorsIndexedGetType(j); |
| 44 | + if (kType == types) { |
| 45 | + const auto kAddress = ConfigStore::Instance().RdmSensorsIndexedGetAddress(j); |
| 46 | + if (kAddress != 0) { |
| 47 | + a[k++] = common::hex::ToCharLowercase(kAddress >> 4); |
| 48 | + a[k++] = common::hex::ToCharLowercase(kAddress); |
| 49 | + a[k++] = ','; |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + if (a[k - 1] == ',') k -= 1; |
| 55 | + |
| 56 | + a[k++] = ']'; |
| 57 | + a[k] = '\0'; |
| 58 | + |
| 59 | + const auto& keys = json::RdmSensorsParams::Keys(); |
| 60 | + doc[keys[types].GetName()] = a; |
| 61 | + } |
68 | 62 | }); |
69 | 63 | } |
70 | 64 |
|
71 | | -void SetRdmSensors(const char* buffer, uint32_t buffer_size) |
72 | | -{ |
| 65 | +void SetRdmSensors(const char* buffer, uint32_t buffer_size) { |
73 | 66 | ::json::RdmSensorsParams rdmsensors_params; |
74 | 67 | rdmsensors_params.Store(buffer, buffer_size); |
75 | 68 | } |
|
0 commit comments