diff --git a/CHANGELOG.md b/CHANGELOG.md index aecc53f7..9a53fb02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ Please add a note of your changes below this heading if you make a Pull Request. * Print function imported from future * Using new hooks to calculate: * `motor.config.current_control_bandwidth` - * This depricates `motor.set_current_control_bandwidth()` + * This deprecates `motor.set_current_control_bandwidth()` * `encoder.config.bandwidth` # Releases diff --git a/Firmware/fibre/cpp/include/fibre/protocol.hpp b/Firmware/fibre/cpp/include/fibre/protocol.hpp index a2d15825..7f9aa992 100644 --- a/Firmware/fibre/cpp/include/fibre/protocol.hpp +++ b/Firmware/fibre/cpp/include/fibre/protocol.hpp @@ -431,8 +431,9 @@ private: typedef std::function EndpointHandler; +// @brief Default endpoint handler for endpoint_ref_t types template -void default_readwrite_endpoint_handler(endpoint_ref_t* value, const uint8_t* input, size_t input_length, StreamSink* output) { +bool default_readwrite_endpoint_handler(endpoint_ref_t* value, const uint8_t* input, size_t input_length, StreamSink* output) { constexpr size_t size = sizeof(value->endpoint_id) + sizeof(value->json_crc); if (output) { // TODO: make buffer size dependent on the type @@ -447,13 +448,17 @@ void default_readwrite_endpoint_handler(endpoint_ref_t* value, const uint8_t* in if (input_length >= size) { read_leendpoint_id)>(&value->endpoint_id, input); read_lejson_crc)>(&value->json_crc, input + 2); + return true; + } else { + return false; } } // @brief Default endpoint handler for const types +// @return: True if endpoint was written to, False otherwise template -std::enable_if_t::value && std::is_const::value> +std::enable_if_t::value && std::is_const::value, bool> default_readwrite_endpoint_handler(T* value, const uint8_t* input, size_t input_length, StreamSink* output) { // If the old value was requested, call the corresponding little endian serialization function if (output) { @@ -463,23 +468,26 @@ default_readwrite_endpoint_handler(T* value, const uint8_t* input, size_t input_ if (cnt <= output->get_free_space()) output->process_bytes(buffer, cnt, nullptr); } + return false; // We don't ever write to const types } // @brief Default endpoint handler for non-const types template -std::enable_if_t::value && !std::is_const::value> +std::enable_if_t::value && !std::is_const::value, bool> default_readwrite_endpoint_handler(T* value, const uint8_t* input, size_t input_length, StreamSink* output) { // Read the endpoint value into output default_readwrite_endpoint_handler(const_cast(value), input, input_length, output); // If a new value was passed, call the corresponding little endian deserialization function uint8_t buffer[sizeof(T)] = { 0 }; // TODO: make buffer size dependent on the type - if (input_length >= sizeof(buffer)) + if (input_length >= sizeof(buffer)) { read_le(value, input); + return true; + } else { + return false; + } } - - template static inline const char* get_default_json_modifier(); @@ -893,8 +901,8 @@ public: list[id] = this; } void handle(const uint8_t* input, size_t input_length, StreamSink* output) final { - default_readwrite_endpoint_handler(property_, input, input_length, output); - if (written_hook_ != nullptr && input_length >= sizeof(TProperty)) { + bool wrote = default_readwrite_endpoint_handler(property_, input, input_length, output); + if (wrote && written_hook_ != nullptr) { written_hook_(ctx_); } }