9#include <cfg/cs_StaticConfig.h>
26template <cs_buffer_
size_t PAYLOAD_SIZE = CS_CONTROL_PACKET_DEFAULT_PAYLOAD_SIZE>
34 return _buffer->header.protocolVersion;
42 _buffer->header.protocolVersion = protocol;
50 return _buffer->header.commandType;
58 _buffer->header.commandType = type;
83 return std::min(
_buffer->header.payloadSize, PAYLOAD_SIZE);
105 if (size > PAYLOAD_SIZE) {
109 if (size != 0 && payload ==
nullptr) {
110 LOGe(
"Null pointer");
113 _buffer->header.payloadSize = size;
114 if (size &&
_buffer->payload != payload) {
115 memmove(
_buffer->payload, payload, size);
Base class for a buffer accessor object.
Definition: cs_BufferAccessor.h:16
Definition: cs_ControlPacketAccessor.h:27
void checkInitialized() const
Definition: cs_ControlPacketAccessor.h:158
uint8_t getProtocolVersion() const
Get the protocol version.
Definition: cs_ControlPacketAccessor.h:32
void setProtocolVersion(uint8_t protocol)
Set the protocol version.
Definition: cs_ControlPacketAccessor.h:40
cs_ret_code_t assign(buffer_ptr_t buffer, cs_buffer_size_t size)
Assign the buffer used to hold the data.
Definition: cs_ControlPacketAccessor.h:124
void setType(cs_control_cmd_t type)
Set the command type.
Definition: cs_ControlPacketAccessor.h:56
cs_buffer_size_t getMaxPayloadSize()
Get the capacity of the payload.
Definition: cs_ControlPacketAccessor.h:91
cs_buffer_size_t getPayloadSize()
Get the size of the payload.
Definition: cs_ControlPacketAccessor.h:81
control_packet_t< PAYLOAD_SIZE > * _buffer
Pointer to the packet to be sent.
Definition: cs_ControlPacketAccessor.h:156
cs_control_cmd_t getType() const
Get the command type.
Definition: cs_ControlPacketAccessor.h:48
cs_buffer_size_t getBufferSize() const
Get the capacity of the buffer.
Definition: cs_ControlPacketAccessor.h:138
cs_ret_code_t setPayload(buffer_ptr_t payload, cs_buffer_size_t size)
Copy payload into the packet.
Definition: cs_ControlPacketAccessor.h:103
cs_data_t getPayload()
Get pointer to the payload.
Definition: cs_ControlPacketAccessor.h:66
cs_data_t getSerializedBuffer()
Get the pointer to the buffer.
Definition: cs_ControlPacketAccessor.h:144
cs_buffer_size_t getSerializedSize() const
Get the size of the serialized data in the buffer.
Definition: cs_ControlPacketAccessor.h:132
static constexpr size_t CS_CONTROL_PACKET_DEFAULT_PAYLOAD_SIZE
Default payload size for a control packet.
Definition: cs_ControlPacketAccessor.h:23
@ ERR_SUCCESS
Definition: cs_ErrorCodes.h:10
@ ERR_BUFFER_TOO_SMALL
Definition: cs_ErrorCodes.h:16
@ ERR_BUFFER_UNASSIGNED
Definition: cs_ErrorCodes.h:14
#define assert(expr, message)
Author: Crownstone Team Date: 21 Sep., 2013 License: LGPLv3+, Apache License 2.0, and/or MIT (triple-...
Definition: cs_Error.h:22
#define LOGd(fmt,...)
Definition: cs_Logger.h:90
#define LOGe(fmt,...)
Definition: cs_Logger.h:93
#define STR_ERR_BUFFER_NOT_LARGE_ENOUGH
Definition: cs_Strings.h:101
#define FMT_ASSIGN_BUFFER_LEN
Definition: cs_Strings.h:188
uint16_t cs_buffer_size_t
Definition: cs_Typedefs.h:20
uint16_t cs_control_cmd_t
Definition: cs_Typedefs.h:22
uint16_t cs_ret_code_t
Definition: cs_Typedefs.h:21
uint8_t * buffer_ptr_t
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: 10 May....
Definition: cs_Typedefs.h:19
Control packet.
Definition: cs_Packets.h:96
Packets (structs) that are used internally in the firmware, and can be changed freely.
Definition: cs_PacketsInternal.h:27
cs_buffer_size_t len
< Pointer to data.
Definition: cs_PacketsInternal.h:29
buffer_ptr_t data
Definition: cs_PacketsInternal.h:28