mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 10:46:31 +00:00
Merge pull request #15675 from s-hadinger/sbuffer_simplified
Simplified SBuffer
This commit is contained in:
commit
58d4b44dce
@ -48,7 +48,7 @@ public:
|
|||||||
inline uint8_t *buf(size_t i = 0) const { return &_buf->buf[i]; }
|
inline uint8_t *buf(size_t i = 0) const { return &_buf->buf[i]; }
|
||||||
inline char *charptr(size_t i = 0) const { return (char*) &_buf->buf[i]; }
|
inline char *charptr(size_t i = 0) const { return (char*) &_buf->buf[i]; }
|
||||||
|
|
||||||
virtual ~SBuffer(void) {
|
~SBuffer(void) {
|
||||||
delete[] _buf;
|
delete[] _buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,6 +258,12 @@ public:
|
|||||||
return buf2;
|
return buf2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SBuffer SBufferFromBytes(const uint8_t *bytes, size_t len2) {
|
||||||
|
SBuffer buf2(len2);
|
||||||
|
buf2.addBuffer(bytes, len2);
|
||||||
|
return buf2;
|
||||||
|
}
|
||||||
|
|
||||||
// nullptr accepted
|
// nullptr accepted
|
||||||
static bool equalsSBuffer(const class SBuffer * buf1, const class SBuffer * buf2) {
|
static bool equalsSBuffer(const class SBuffer * buf1, const class SBuffer * buf2) {
|
||||||
if (buf1 == buf2) { return true; }
|
if (buf1 == buf2) { return true; }
|
||||||
@ -290,18 +296,3 @@ protected:
|
|||||||
SBuffer_impl * _buf;
|
SBuffer_impl * _buf;
|
||||||
|
|
||||||
} SBuffer;
|
} SBuffer;
|
||||||
|
|
||||||
typedef class PreAllocatedSBuffer : public SBuffer {
|
|
||||||
|
|
||||||
public:
|
|
||||||
PreAllocatedSBuffer(const size_t size, void * buffer) {
|
|
||||||
_buf = (SBuffer_impl*) buffer;
|
|
||||||
_buf->size = size - 4;
|
|
||||||
_buf->len = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
~PreAllocatedSBuffer(void) {
|
|
||||||
// don't deallocate
|
|
||||||
_buf = nullptr;
|
|
||||||
}
|
|
||||||
} PreAllocatedSBuffer;
|
|
||||||
|
@ -300,11 +300,8 @@ void ZigbeeInitSerial(void)
|
|||||||
ZigbeeSerial->begin(115200);
|
ZigbeeSerial->begin(115200);
|
||||||
if (ZigbeeSerial->hardwareSerial()) {
|
if (ZigbeeSerial->hardwareSerial()) {
|
||||||
ClaimSerial();
|
ClaimSerial();
|
||||||
uint32_t aligned_buffer = ((uint32_t)TasmotaGlobal.serial_in_buffer + 3) & ~3;
|
|
||||||
zigbee_buffer = new PreAllocatedSBuffer(sizeof(TasmotaGlobal.serial_in_buffer) - 3, (char*) aligned_buffer);
|
|
||||||
} else {
|
|
||||||
zigbee_buffer = new SBuffer(ZIGBEE_BUFFER_SIZE);
|
|
||||||
}
|
}
|
||||||
|
zigbee_buffer = new SBuffer(ZIGBEE_BUFFER_SIZE);
|
||||||
|
|
||||||
zigbee.active = true;
|
zigbee.active = true;
|
||||||
zigbee.init_phase = true; // start the state machine
|
zigbee.init_phase = true; // start the state machine
|
||||||
|
Loading…
x
Reference in New Issue
Block a user