Skip to content

Commit

Permalink
Fix buffer_t conflict on some systems
Browse files Browse the repository at this point in the history
  • Loading branch information
vshymanskyy committed Dec 8, 2023
1 parent 4057f79 commit 2cd37fe
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 40 deletions.
10 changes: 5 additions & 5 deletions docs/Direct usage of BlynkRPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ However, because BlynkRcpDriver is based on C99, the API syntax is different:
#### Blynk Cloud API
```cpp
Blynk.begin(...) -> rpc_blynk_initialize(tmpl_id, tmpl_name);
Blynk.virtualWrite(...) -> rpc_blynk_virtualWrite(vpin, buffer_t)
Blynk.virtualWrite(...) -> rpc_blynk_virtualWrite(vpin, rpc_buffer_t)
Blynk.syncAll() -> rpc_blynk_syncAll()
Blynk.syncVirtual(...) -> rpc_blynk_syncVirtual(buffer_t)
Blynk.setProperty(...) -> rpc_blynk_setProperty(vpin, property, buffer_t)
Blynk.syncVirtual(...) -> rpc_blynk_syncVirtual(rpc_buffer_t)
Blynk.setProperty(...) -> rpc_blynk_setProperty(vpin, property, rpc_buffer_t)
Blynk.logEvent(name) -> rpc_blynk_logEvent(name, "")
Blynk.logEvent(name,descr) -> rpc_blynk_logEvent(name, descr)
Blynk.resolveEvent(name) -> rpc_blynk_resolveEvent(name)
Expand Down Expand Up @@ -49,13 +49,13 @@ void rpc_client_blynkStateChange_impl(uint8_t state) {
### BLYNK_WRITE(VPIN)
```cpp
void rpc_client_blynkVPinChange_impl(uint16_t vpin, buffer_t param)
void rpc_client_blynkVPinChange_impl(uint16_t vpin, rpc_buffer_t param)
{
// Your handling
}
```

## `buffer_t` format
## `rpc_buffer_t` format

Most values will be plain strings: "Hello world", "1234", "123.456", etc.

Expand Down
2 changes: 1 addition & 1 deletion examples/BlynkNCP_LowLevel/ArduinoUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const char* ncpGetStateString(uint8_t state) {
}

void virtualWrite(int virtualPin, const char* value) {
buffer_t val = { (uint8_t*)value, strlen(value) };
rpc_buffer_t val = { (uint8_t*)value, strlen(value) };
rpc_blynk_virtualWrite(virtualPin, val);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/BlynkNCP_LowLevel/BlynkNCP_LowLevel.ino
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void loop()
}

// Handle Blynk Virtual Pin value updates
void rpc_client_blynkVPinChange_impl(uint16_t vpin, buffer_t param)
void rpc_client_blynkVPinChange_impl(uint16_t vpin, rpc_buffer_t param)
{
// NOTE: we could copy the buffer, but we use 0-copy instead
// But we need to 0-terminate it, overwriting the CRC8
Expand Down
4 changes: 2 additions & 2 deletions src/BlynkRpcClientWeakImpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bool rpc_mcu_reboot_impl(void) {
}

RPC_ATTR_WEAK
void rpc_client_blynkVPinChange_impl(uint16_t vpin, buffer_t param) {
void rpc_client_blynkVPinChange_impl(uint16_t vpin, rpc_buffer_t param) {

}

Expand All @@ -28,7 +28,7 @@ bool rpc_client_otaUpdateAvailable_impl(const char* filename, uint32_t filesize,
}

RPC_ATTR_WEAK
bool rpc_client_otaUpdateWrite_impl(uint32_t offset, buffer_t chunk, uint32_t crc32) {
bool rpc_client_otaUpdateWrite_impl(uint32_t offset, rpc_buffer_t chunk, uint32_t crc32) {
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions src/MessageBuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ size_t MessageBuffer_readString(MessageBuffer* self, const char** value) {
return len;
}

size_t MessageBuffer_readBinary(MessageBuffer* self, buffer_t* value) {
size_t MessageBuffer_readBinary(MessageBuffer* self, rpc_buffer_t* value) {
uint16_t len;
if (!MessageBuffer_readUInt16(self, &len)) {
if (value) {
memset(value, 0, sizeof(buffer_t));
memset(value, 0, sizeof(rpc_buffer_t));
}
return 0;
}
return (sizeof(len) + MessageBuffer_readFixedBuffer(self, value, len));
}

size_t MessageBuffer_readFixedBuffer(MessageBuffer* self, buffer_t* value, unsigned len) {
size_t MessageBuffer_readFixedBuffer(MessageBuffer* self, rpc_buffer_t* value, unsigned len) {
if (MessageBuffer_availableToRead(self) < len) {
if (value) {
memset(value, 0, sizeof(buffer_t));
memset(value, 0, sizeof(rpc_buffer_t));
}
self->_error = true;
return 0;
Expand Down
8 changes: 4 additions & 4 deletions src/MessageBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
extern "C" {
#endif

typedef struct buffer_t {
typedef struct rpc_buffer_t {
uint8_t* data;
size_t length;
} buffer_t;
} rpc_buffer_t;

typedef struct MessageBuffer {
uint8_t* _buffer;
Expand All @@ -37,8 +37,8 @@ bool MessageBuffer_getError(MessageBuffer* self);

/* Read */
size_t MessageBuffer_readString(MessageBuffer* self, const char** value);
size_t MessageBuffer_readBinary(MessageBuffer* self, buffer_t* value);
size_t MessageBuffer_readFixedBuffer(MessageBuffer* self, buffer_t* value, unsigned len);
size_t MessageBuffer_readBinary(MessageBuffer* self, rpc_buffer_t* value);
size_t MessageBuffer_readFixedBuffer(MessageBuffer* self, rpc_buffer_t* value, unsigned len);
size_t MessageBuffer_readBool(MessageBuffer* self, bool* value);
size_t MessageBuffer_readInt8(MessageBuffer* self, int8_t* value);
size_t MessageBuffer_readInt16(MessageBuffer* self, int16_t* value);
Expand Down
2 changes: 1 addition & 1 deletion src/MessageWriter.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ size_t MessageWriter_writeString(const char* value) {
return MessageWriter_write(value, length);
}

size_t MessageWriter_writeBinary(buffer_t value) {
size_t MessageWriter_writeBinary(rpc_buffer_t value) {
size_t len = sizeof(uint16_t) + value.length;
/*if (MessageBuffer_availableToWrite(self) < len) {
self->_error = true;
Expand Down
2 changes: 1 addition & 1 deletion src/MessageWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ size_t MessageWriter_begin (void);
size_t MessageWriter_end (void);

size_t MessageWriter_writeString (const char* value);
size_t MessageWriter_writeBinary (buffer_t value);
size_t MessageWriter_writeBinary (rpc_buffer_t value);
size_t MessageWriter_writeBool (bool value);
size_t MessageWriter_writeInt8 (const int8_t value);
size_t MessageWriter_writeInt16 (const int16_t value);
Expand Down
20 changes: 10 additions & 10 deletions src/idl/rpc_handler_blynk.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,14 @@ void rpc_blynk_otaUpdateGetCRC32_handler(MessageBuffer* _rpc_buff) {
}


bool rpc_blynk_otaUpdateGetMD5_impl(buffer_t* digest);
bool rpc_blynk_otaUpdateGetMD5_impl(rpc_buffer_t* digest);

static
void rpc_blynk_otaUpdateGetMD5_handler(MessageBuffer* _rpc_buff) {
uint16_t _rpc_seq;
MessageBuffer_readUInt16(_rpc_buff, &_rpc_seq);
/* Deserialize arguments */
buffer_t digest; memset(&digest, 0, sizeof(digest)); /* output */
rpc_buffer_t digest; memset(&digest, 0, sizeof(digest)); /* output */

if (MessageBuffer_getError(_rpc_buff) || MessageBuffer_availableToRead(_rpc_buff)) {
MessageWriter_sendResultStatus(_rpc_seq, RPC_STATUS_ERROR_ARGS_R);
Expand All @@ -441,14 +441,14 @@ void rpc_blynk_otaUpdateGetMD5_handler(MessageBuffer* _rpc_buff) {
}


bool rpc_blynk_otaUpdateGetSHA256_impl(buffer_t* digest);
bool rpc_blynk_otaUpdateGetSHA256_impl(rpc_buffer_t* digest);

static
void rpc_blynk_otaUpdateGetSHA256_handler(MessageBuffer* _rpc_buff) {
uint16_t _rpc_seq;
MessageBuffer_readUInt16(_rpc_buff, &_rpc_seq);
/* Deserialize arguments */
buffer_t digest; memset(&digest, 0, sizeof(digest)); /* output */
rpc_buffer_t digest; memset(&digest, 0, sizeof(digest)); /* output */

if (MessageBuffer_getError(_rpc_buff) || MessageBuffer_availableToRead(_rpc_buff)) {
MessageWriter_sendResultStatus(_rpc_seq, RPC_STATUS_ERROR_ARGS_R);
Expand Down Expand Up @@ -589,13 +589,13 @@ void rpc_blynk_getState_handler(MessageBuffer* _rpc_buff) {
}


void rpc_blynk_virtualWrite_impl(uint16_t vpin, buffer_t value);
void rpc_blynk_virtualWrite_impl(uint16_t vpin, rpc_buffer_t value);

static
void rpc_blynk_virtualWrite_handler(MessageBuffer* _rpc_buff) {
/* Deserialize arguments */
uint16_t vpin; MessageBuffer_readUInt16(_rpc_buff, &vpin);
buffer_t value; MessageBuffer_readBinary(_rpc_buff, &value);
rpc_buffer_t value; MessageBuffer_readBinary(_rpc_buff, &value);

if (MessageBuffer_getError(_rpc_buff) || MessageBuffer_availableToRead(_rpc_buff)) {
return;
Expand All @@ -608,14 +608,14 @@ void rpc_blynk_virtualWrite_handler(MessageBuffer* _rpc_buff) {
}


void rpc_blynk_setProperty_impl(uint16_t vpin, const char* property, buffer_t value);
void rpc_blynk_setProperty_impl(uint16_t vpin, const char* property, rpc_buffer_t value);

static
void rpc_blynk_setProperty_handler(MessageBuffer* _rpc_buff) {
/* Deserialize arguments */
uint16_t vpin; MessageBuffer_readUInt16(_rpc_buff, &vpin);
const char* property; MessageBuffer_readString(_rpc_buff, &property);
buffer_t value; MessageBuffer_readBinary(_rpc_buff, &value);
rpc_buffer_t value; MessageBuffer_readBinary(_rpc_buff, &value);

if (MessageBuffer_getError(_rpc_buff) || MessageBuffer_availableToRead(_rpc_buff)) {
return;
Expand All @@ -641,12 +641,12 @@ void rpc_blynk_syncAll_handler(MessageBuffer* _rpc_buff) {
}


void rpc_blynk_syncVirtual_impl(buffer_t vpins);
void rpc_blynk_syncVirtual_impl(rpc_buffer_t vpins);

static
void rpc_blynk_syncVirtual_handler(MessageBuffer* _rpc_buff) {
/* Deserialize arguments */
buffer_t vpins; MessageBuffer_readBinary(_rpc_buff, &vpins);
rpc_buffer_t vpins; MessageBuffer_readBinary(_rpc_buff, &vpins);

if (MessageBuffer_getError(_rpc_buff) || MessageBuffer_availableToRead(_rpc_buff)) {
return;
Expand Down
8 changes: 4 additions & 4 deletions src/idl/rpc_handler_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ extern "C" {
#endif


void rpc_client_blynkVPinChange_impl(uint16_t vpin, buffer_t param);
void rpc_client_blynkVPinChange_impl(uint16_t vpin, rpc_buffer_t param);

static
void rpc_client_blynkVPinChange_handler(MessageBuffer* _rpc_buff) {
/* Deserialize arguments */
uint16_t vpin; MessageBuffer_readUInt16(_rpc_buff, &vpin);
buffer_t param; MessageBuffer_readBinary(_rpc_buff, &param);
rpc_buffer_t param; MessageBuffer_readBinary(_rpc_buff, &param);

if (MessageBuffer_getError(_rpc_buff) || MessageBuffer_availableToRead(_rpc_buff)) {
return;
Expand Down Expand Up @@ -92,15 +92,15 @@ void rpc_client_otaUpdateAvailable_handler(MessageBuffer* _rpc_buff) {
}


bool rpc_client_otaUpdateWrite_impl(uint32_t offset, buffer_t chunk, uint32_t crc32);
bool rpc_client_otaUpdateWrite_impl(uint32_t offset, rpc_buffer_t chunk, uint32_t crc32);

static
void rpc_client_otaUpdateWrite_handler(MessageBuffer* _rpc_buff) {
uint16_t _rpc_seq;
MessageBuffer_readUInt16(_rpc_buff, &_rpc_seq);
/* Deserialize arguments */
uint32_t offset; MessageBuffer_readUInt32(_rpc_buff, &offset);
buffer_t chunk; MessageBuffer_readBinary(_rpc_buff, &chunk);
rpc_buffer_t chunk; MessageBuffer_readBinary(_rpc_buff, &chunk);
uint32_t crc32; MessageBuffer_readUInt32(_rpc_buff, &crc32);

if (MessageBuffer_getError(_rpc_buff) || MessageBuffer_availableToRead(_rpc_buff)) {
Expand Down
10 changes: 5 additions & 5 deletions src/idl/rpc_shim_blynk.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ bool rpc_blynk_otaUpdateGetCRC32(uint32_t* crc) {


static inline
bool rpc_blynk_otaUpdateGetMD5(buffer_t* digest) {
bool rpc_blynk_otaUpdateGetMD5(rpc_buffer_t* digest) {
RpcStatus _rpc_res;
/* Prepare return value */
bool _rpc_ret_val;
Expand Down Expand Up @@ -557,7 +557,7 @@ bool rpc_blynk_otaUpdateGetMD5(buffer_t* digest) {


static inline
bool rpc_blynk_otaUpdateGetSHA256(buffer_t* digest) {
bool rpc_blynk_otaUpdateGetSHA256(rpc_buffer_t* digest) {
RpcStatus _rpc_res;
/* Prepare return value */
bool _rpc_ret_val;
Expand Down Expand Up @@ -765,7 +765,7 @@ uint8_t rpc_blynk_getState(void) {


static inline
void rpc_blynk_virtualWrite(uint16_t vpin, buffer_t value) {
void rpc_blynk_virtualWrite(uint16_t vpin, rpc_buffer_t value) {
/* Send request */
MessageWriter_beginOneway(RPC_UID_BLYNK_VIRTUALWRITE);
MessageWriter_writeUInt16(vpin);
Expand All @@ -777,7 +777,7 @@ void rpc_blynk_virtualWrite(uint16_t vpin, buffer_t value) {


static inline
void rpc_blynk_setProperty(uint16_t vpin, const char* property, buffer_t value) {
void rpc_blynk_setProperty(uint16_t vpin, const char* property, rpc_buffer_t value) {
/* Send request */
MessageWriter_beginOneway(RPC_UID_BLYNK_SETPROPERTY);
MessageWriter_writeUInt16(vpin);
Expand All @@ -800,7 +800,7 @@ void rpc_blynk_syncAll(void) {


static inline
void rpc_blynk_syncVirtual(buffer_t vpins) {
void rpc_blynk_syncVirtual(rpc_buffer_t vpins) {
/* Send request */
MessageWriter_beginOneway(RPC_UID_BLYNK_SYNCVIRTUAL);
MessageWriter_writeBinary(vpins);
Expand Down
4 changes: 2 additions & 2 deletions src/idl/rpc_shim_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extern "C" {


static inline
void rpc_client_blynkVPinChange(uint16_t vpin, buffer_t param) {
void rpc_client_blynkVPinChange(uint16_t vpin, rpc_buffer_t param) {
/* Send request */
MessageWriter_beginOneway(RPC_UID_CLIENT_BLYNKVPINCHANGE);
MessageWriter_writeUInt16(vpin);
Expand Down Expand Up @@ -78,7 +78,7 @@ bool rpc_client_otaUpdateAvailable(const char* filename, uint32_t filesize, cons


static inline
bool rpc_client_otaUpdateWrite(uint32_t offset, buffer_t chunk, uint32_t crc32) {
bool rpc_client_otaUpdateWrite(uint32_t offset, rpc_buffer_t chunk, uint32_t crc32) {
RpcStatus _rpc_res;
/* Prepare return value */
bool _rpc_ret_val;
Expand Down

0 comments on commit 2cd37fe

Please sign in to comment.