split pub and priv
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
/// Types for the BLK_BOX expantion devices
|
||||
|
||||
#ifndef _BB_EXPANTIONS_H
|
||||
#define _BB_EXPANTIONS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/// The expantion device ids in the BLK_BOX ecosystem.
|
||||
enum class BlkBoxExpantion: uint16_t {
|
||||
NONE = 0,
|
||||
WIRES = 1,
|
||||
TENS = 2,
|
||||
MAX = 2,
|
||||
};
|
||||
|
||||
#endif /* _BB_EXPANTIONS_H */
|
||||
@@ -0,0 +1,9 @@
|
||||
/// Types for the BLK_BOX NOW protocol
|
||||
|
||||
#ifndef _BBNOW_H
|
||||
#define _BBNOW_H
|
||||
|
||||
#include "bbnow_pub.hpp" // IWYU pragma: keep
|
||||
#include "bbnow_priv.hpp" // IWYU pragma: keep
|
||||
|
||||
#endif /* _BBNOW_H */
|
||||
@@ -0,0 +1,6 @@
|
||||
/// Types for the BLK_BOX NOW priv protocol
|
||||
|
||||
#ifndef _BBNOW_PRIV_H
|
||||
#define _BBNOW_PRIV_H
|
||||
|
||||
#endif /* _BBNOW_PRIV_H */
|
||||
@@ -0,0 +1,67 @@
|
||||
/// Types for the BLK_BOX NOW pub protocol
|
||||
|
||||
#ifndef _BBNOW_PUB_H
|
||||
#define _BBNOW_PUB_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
|
||||
#include "bb_expantions.hpp"
|
||||
|
||||
///////////////////////////////////////
|
||||
// (1) DISCOVERY //
|
||||
/////////////////////////////////////
|
||||
|
||||
/// The data associated with the `DISCOVERY` type.
|
||||
struct BlkBoxNowPubDiscoveryData {
|
||||
BlkBoxExpantion expantion_type{};
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////
|
||||
// PUB PACKET //
|
||||
/////////////////////////////////////
|
||||
|
||||
/// The packet type for `BBNowPubPacket`s.
|
||||
enum class BBNowPubPacketType: uint16_t {
|
||||
NONE = 0,
|
||||
DISCOVERY = 1,
|
||||
MAX = 1,
|
||||
};
|
||||
|
||||
/// The data field for the packet
|
||||
union BlkBoxNowPubPacketData {
|
||||
BlkBoxNowPubDiscoveryData discovery;
|
||||
};
|
||||
|
||||
struct BBNowPubPacket {
|
||||
const static uint32_t PUB_MAGIC_NUMBER = 0x6262'6E70;
|
||||
// DISCOVERY packet size
|
||||
const static size_t DISCOVERY_PACKET_SIZE = sizeof(PUB_MAGIC_NUMBER) + sizeof(BBNowPubPacketType) + sizeof(BlkBoxNowPubDiscoveryData);
|
||||
static_assert(DISCOVERY_PACKET_SIZE == 8, "Discovery packet should be 8 bytes");
|
||||
|
||||
/// The type of packet this is.
|
||||
BBNowPubPacketType packet_type{};
|
||||
/// The data held by the packet.
|
||||
BlkBoxNowPubPacketData packet_data{};
|
||||
|
||||
/// The size of the serialized packet (in bytes).
|
||||
size_t serialize_size();
|
||||
/// Serializes the packet to a vector.
|
||||
std::vector<uint8_t> serialize();
|
||||
/// Serializes the packet into the given vector.
|
||||
///
|
||||
/// Returns the number of bytes written into the buffer.
|
||||
size_t serialize_into(std::vector<uint8_t>& buf);
|
||||
/// Deserializes a packet from the given bytes.
|
||||
static std::optional<BBNowPubPacket> deserialize(std::span<const uint8_t> bytes);
|
||||
|
||||
/// Constructs an empty packet.
|
||||
BBNowPubPacket() = default;
|
||||
/// Constructs a new `Discovery` type packet with the given data.
|
||||
static BBNowPubPacket new_discovery(BlkBoxNowPubDiscoveryData data);
|
||||
};
|
||||
|
||||
#endif /* _BBNOW_PUB_H */
|
||||
@@ -1,62 +0,0 @@
|
||||
/// Types common across the blk_box ecosystem
|
||||
|
||||
#ifndef _BLK_BOX_COMMON_H
|
||||
#define _BLK_BOX_COMMON_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include <span>
|
||||
#include <optional>
|
||||
|
||||
/// The different expantions to the BLK_BOX.
|
||||
enum class BlkBoxExpantion: uint16_t {
|
||||
NONE = 0,
|
||||
WIRES = 1,
|
||||
TENS = 2,
|
||||
MAX = 2,
|
||||
};
|
||||
|
||||
/// The packet type for `BlkBoxNowPubPacket`s.
|
||||
enum class BlkBoxNowPubPacketType: uint8_t {
|
||||
NONE = 0,
|
||||
DISCOVERY = 1,
|
||||
MAX = 1,
|
||||
};
|
||||
|
||||
/// The data associated with the `DISCOVERY` type.
|
||||
struct BlkBoxNowPubDiscoveryData {
|
||||
BlkBoxExpantion expantion_type{};
|
||||
};
|
||||
|
||||
union BlkBoxNowPubPacketData {
|
||||
BlkBoxNowPubDiscoveryData discovery;
|
||||
};
|
||||
|
||||
struct BlkBoxNowPubPacket {
|
||||
const static uint32_t PUB_MAGIC_NUMBER = 0x8934'DBE3;
|
||||
// DISCOVERY packet size
|
||||
const static size_t DISCOVERY_PACKET_SIZE = sizeof(PUB_MAGIC_NUMBER) + sizeof(BlkBoxNowPubPacketType) + sizeof(BlkBoxNowPubDiscoveryData);
|
||||
static_assert(DISCOVERY_PACKET_SIZE == 7, "Discovery packet should be 7 bytes");
|
||||
|
||||
|
||||
/// The type of packet this is.
|
||||
BlkBoxNowPubPacketType packet_type{};
|
||||
/// The data held by the packet.
|
||||
BlkBoxNowPubPacketData packet_data{};
|
||||
|
||||
/// The size of the serialized packet (in bytes).
|
||||
size_t serialize_size();
|
||||
/// Serializes the packet to a vector.
|
||||
std::vector<uint8_t> serialize();
|
||||
/// Serializes the packet into the given vector.
|
||||
size_t serialize_into(std::vector<uint8_t>& buf);
|
||||
/// Deserializes a packet from the given bytes.
|
||||
static std::optional<BlkBoxNowPubPacket> deserialize(std::span<const uint8_t> bytes);
|
||||
|
||||
/// Constructs an empty packet.
|
||||
BlkBoxNowPubPacket() = default;
|
||||
static BlkBoxNowPubPacket new_discovery(BlkBoxNowPubDiscoveryData data);
|
||||
};
|
||||
|
||||
#endif /* _BLK_BOX_COMMON_H */
|
||||
Reference in New Issue
Block a user