|
| 1 | +#include "ESPEasy_Build_Description.h" |
| 2 | + |
| 3 | + |
| 4 | +#include "../Globals/CPlugins.h" |
| 5 | +#include "../Globals/NPlugins.h" |
| 6 | +#include "../Globals/Plugins.h" |
| 7 | + |
| 8 | +xPluginEnumerator::xPluginEnumerator() {} |
| 9 | + |
| 10 | +void xPluginEnumerator::setSize(unsigned int maxID) { |
| 11 | + const unsigned int wordSize = (maxID / 16) + 1; |
| 12 | + |
| 13 | + if (_bitmap.size() < wordSize) { |
| 14 | + _bitmap.resize(wordSize, 0); |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +void xPluginEnumerator::add(unsigned int ID) { |
| 19 | + setSize(ID); |
| 20 | + unsigned int wordIndex = ID / 16; |
| 21 | + unsigned int bitIndex = 15 - (ID % 16); |
| 22 | + |
| 23 | + bitSet(_bitmap[wordIndex], bitIndex); |
| 24 | +} |
| 25 | + |
| 26 | +String xPluginEnumerator::getString(char separator) const { |
| 27 | + String result; |
| 28 | + |
| 29 | + result.reserve(_bitmap.size() * 5); // 4 HEX characters per 16 bit value + separator |
| 30 | + size_t zeroCount = 0; |
| 31 | + |
| 32 | + for (size_t i = 0; i < _bitmap.size(); ++i) { |
| 33 | + if (_bitmap[i] == 0) { |
| 34 | + ++zeroCount; |
| 35 | + } else if (zeroCount > 0) { |
| 36 | + result += '('; |
| 37 | + result += zeroCount; |
| 38 | + result += ')'; |
| 39 | + result += separator; |
| 40 | + zeroCount = 0; |
| 41 | + } |
| 42 | + |
| 43 | + if (zeroCount == 0) { |
| 44 | + result += String(_bitmap[i], HEX); |
| 45 | + result += separator; |
| 46 | + } |
| 47 | + } |
| 48 | + return result; |
| 49 | +} |
| 50 | + |
| 51 | +String CreateBuildDescription(char separator) { |
| 52 | + String result; |
| 53 | + |
| 54 | + { |
| 55 | + result += 'T'; |
| 56 | + xPluginEnumerator cplugins; |
| 57 | + const unsigned int size = ProtocolIndex_to_CPlugin_id.size(); |
| 58 | + cplugins.setSize(size); |
| 59 | + |
| 60 | + for (size_t i = 0; i < size; ++i) { |
| 61 | + cplugins.add(ProtocolIndex_to_CPlugin_id[i]); |
| 62 | + } |
| 63 | + result += cplugins.getString(separator); |
| 64 | + } |
| 65 | + { |
| 66 | + result += 'P'; |
| 67 | + xPluginEnumerator plugins; |
| 68 | + const unsigned int size = DeviceIndex_to_Plugin_id.size(); |
| 69 | + plugins.setSize(size); |
| 70 | + |
| 71 | + for (size_t i = 0; i < size; ++i) { |
| 72 | + plugins.add(DeviceIndex_to_Plugin_id[i]); |
| 73 | + } |
| 74 | + result += plugins.getString(separator); |
| 75 | + } |
| 76 | + { |
| 77 | + // FIXME TD-er: Right now we don't have a notifierindex to ID vector |
| 78 | + |
| 79 | + /* |
| 80 | + result += 'N'; |
| 81 | + xPluginEnumerator plugins; |
| 82 | + const unsigned int size = DeviceIndex_to_Plugin_id.size(); |
| 83 | + plugins.setSize(size); |
| 84 | + for (size_t i = 0; i < size; ++i) { |
| 85 | + plugins.add(DeviceIndex_to_Plugin_id[i]); |
| 86 | + } |
| 87 | + result += plugins.getString(separator); |
| 88 | + */ |
| 89 | + } |
| 90 | + return result; |
| 91 | +} |
0 commit comments