Skip to content

Commit

Permalink
Add remote command to feature flag list
Browse files Browse the repository at this point in the history
  • Loading branch information
nekomona committed Jul 30, 2023
1 parent 66ec0a0 commit 986760a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/network/featureflags.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,21 @@

#include <cstring>
#include <algorithm>
#include "debug.h"

/**
* Bit packed flags, enum values start with 0 and indicate which bit it is.
*
*
* Change the enums and `flagsEnabled` inside to extend.
*/
struct ServerFeatures {
public:
enum EServerFeatureFlags: uint32_t {
// Server can parse bundle packets: `PACKET_BUNDLE` = 100 (0x64).
PROTOCOL_BUNDLE_SUPPORT,
PROTOCOL_BUNDLE_SUPPORT = 0,

// Add new flags here

BITS_TOTAL,
};

Expand Down Expand Up @@ -73,23 +74,26 @@ class FirmwareFeatures {
public:
enum EFirmwareFeatureFlags: uint32_t {
// EXAMPLE_FEATURE,
REMOTE_COMMAND = 0,
// Add new flags here

BITS_TOTAL,
};

// Flags to send
static constexpr const std::initializer_list<EFirmwareFeatureFlags> flagsEnabled = {
// EXAMPLE_FEATURE,
#ifdef USE_REMOTE_COMMAND
REMOTE_COMMAND,
#endif

// Add enabled flags here
};

static constexpr auto flags = []{
constexpr uint32_t flagsLength = EFirmwareFeatureFlags::BITS_TOTAL / 8 + 1;
std::array<uint8_t, flagsLength> packed{};

for (uint32_t bit : flagsEnabled) {
packed[bit / 8] |= 1 << (bit % 8);
}
Expand All @@ -98,4 +102,4 @@ class FirmwareFeatures {
}();
};

#endif
#endif

0 comments on commit 986760a

Please sign in to comment.