Skip to content

Commit 8c42eaf

Browse files
authored
Merge pull request #5 from bringauto/fix_command_and_status_validation
Fix command and status validation
2 parents 9c4739c + bb1d713 commit 8c42eaf

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ PROJECT(example_module CXX)
33

44
SET(CMAKE_CXX_STANDARD 20)
55

6-
SET(EXAMPLE_MODULE_VERSION 1.1.0)
6+
SET(EXAMPLE_MODULE_VERSION 1.1.1)
77

88
OPTION(BRINGAUTO_PACKAGE "Package creation" OFF)
99
OPTION(BRINGAUTO_INSTALL "Disable install" OFF)

source/module_gateway/module_manager.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ int aggregate_status(struct buffer *aggregated_status, const struct buffer curre
5454

5555
int aggregate_error(struct buffer *error_message, const struct buffer current_error_message, const struct buffer status,
5656
unsigned int device_type) {
57+
allocate(error_message, current_error_message.size_in_bytes);
58+
std::memcpy(error_message->data, current_error_message.data,
59+
current_error_message.size_in_bytes );
5760
return OK;
5861
}
5962

@@ -71,9 +74,13 @@ int status_data_valid(const struct buffer status, unsigned int device_type) {
7174
if(data == nullptr) {
7275
return NOT_OK;
7376
}
77+
const std::string pressed_false = "{\"pressed\": false}";
78+
const std::string pressed_true = "{\"pressed\": true}";
79+
7480
switch(device_type) {
7581
case BUTTON_DEVICE_TYPE:
76-
if(strncmp(data, "{\"pressed\": false}", status.size_in_bytes) == 0 || strncmp(data, "{\"pressed\": true}", status.size_in_bytes) == 0) {
82+
if ((status.size_in_bytes == pressed_false.size() && strncmp(pressed_false.c_str(), data, status.size_in_bytes) == 0) ||
83+
(status.size_in_bytes == pressed_true.size() && strncmp(pressed_true.c_str(), data, status.size_in_bytes) == 0)) {
7784
return OK;
7885
}
7986
break;
@@ -89,9 +96,13 @@ int command_data_valid(const struct buffer command, unsigned int device_type) {
8996
if(data == nullptr) {
9097
return NOT_OK;
9198
}
99+
const std::string lit_up_false = "{\"lit_up\": false}";
100+
const std::string lit_up_true = "{\"lit_up\": true}";
101+
92102
switch(device_type) {
93103
case BUTTON_DEVICE_TYPE:
94-
if(strncmp(data, "{\"lit_up\": false}", command.size_in_bytes) == 0 || strncmp(data, "{\"lit_up\": true}", command.size_in_bytes) == 0) {
104+
if ((command.size_in_bytes == lit_up_false.size() && strncmp(lit_up_false.c_str(), data, command.size_in_bytes) == 0) ||
105+
(command.size_in_bytes == lit_up_true.size() && strncmp(lit_up_true.c_str(), data, command.size_in_bytes) == 0)) {
95106
return OK;
96107
}
97108
break;

0 commit comments

Comments
 (0)