diff --git a/Firmware/fibre/cpp/endpoints_template.j2 b/Firmware/fibre/cpp/endpoints_template.j2 index 0d880997..72b9afe0 100644 --- a/Firmware/fibre/cpp/endpoints_template.j2 +++ b/Firmware/fibre/cpp/endpoints_template.j2 @@ -50,7 +50,6 @@ bool endpoint_handler(int idx, cbufptr_t* input_buffer, bufptr_t* output_buffer) switch (idx) { [%- for endpoint in endpoints %] [%- if (endpoint.function.name == 'exchange' or endpoint.function.name == 'read') and endpoint.in_bindings | list == ['obj'] %] - //case [[endpoint.id]]: return FibrePropertyTypeInfo<[[endpoint.function.in['obj'].type.c_type]]>::make_introspectable([[endpoint.in_bindings['obj']]]); case [[endpoint.id]]: { return [[endpoint.function.fullname | to_snake_case]]([% for k, arg in endpoint.function.in.items() %][% if k in endpoint.in_bindings %]static_cast<[[arg.type.c_type]]>([[endpoint.in_bindings[k]]])[% else %]std::nullopt[% endif %], [% endfor %][% for k, arg in endpoint.function.out.items() %][% if k in endpoint.out_bindings %]static_cast<[[arg.type.c_type]]*>([[endpoint.out_bindings[k]]])[% else %]nullptr[% endif %], [% endfor %]input_buffer, output_buffer); } break; [%- else %] case [[endpoint.id]]: { return [[endpoint.function.fullname | to_snake_case]]([% for k, arg in endpoint.function.in.items() %][% if k in endpoint.in_bindings %]static_cast<[[arg.type.c_type]]>([[endpoint.in_bindings[k]]])[% else %]std::nullopt[% endif %], [% endfor %][% for k, arg in endpoint.function.out.items() %][% if k in endpoint.out_bindings %]static_cast<[[arg.type.c_type]]*>([[endpoint.out_bindings[k]]])[% else %]nullptr[% endif %], [% endfor %]input_buffer, output_buffer); } break; diff --git a/Firmware/fibre/cpp/include/fibre/cpp_utils.hpp b/Firmware/fibre/cpp/include/fibre/cpp_utils.hpp index b2d84256..af28a07f 100644 --- a/Firmware/fibre/cpp/include/fibre/cpp_utils.hpp +++ b/Firmware/fibre/cpp/include/fibre/cpp_utils.hpp @@ -82,9 +82,6 @@ public: #include #include #include -//#include -#include -#include /* Backport features from C++14 and C++17 ------------------------------------*/ @@ -950,69 +947,6 @@ bool hex_string_to_int_arr(const char * str, TInt (&output)[ICount]) { return hex_string_to_int_arr(str, hex_digits() * ICount, output); } -namespace fibre { - -// TODO: move to print_utils.hpp -template -class HexPrinter { -public: - HexPrinter(T val, bool prefix) : val_(val) /*, prefix_(prefix)*/ { - const char digits[] = "0123456789abcdef"; - size_t prefix_length = prefix ? 2 : 0; - if (prefix) { - str[0] = '0'; - str[1] = 'x'; - } - str[prefix_length + hex_digits()] = '\0'; - - for (size_t i = 0; i < hex_digits(); ++i) { - str[prefix_length + hex_digits() - i - 1] = digits[val & 0xf]; - val >>= 4; - } - } - std::string to_string() const { return str; } - void to_string(char* buf) const { - for (size_t i = 0; (i < sizeof(str)) && str[i]; ++i) - buf[i] = str[i]; - } - - T val_; - //bool prefix_; - char str[hex_digits() + 3]; // 3 additional characters 0x and \0 -}; - -template -std::ostream& operator<<(std::ostream& stream, const HexPrinter& printer) { - // TODO: specialize for char - return stream << printer.to_string(); -} - -template -HexPrinter as_hex(T val, bool prefix = true) { return HexPrinter(val, prefix); } - -template -class HexArrayPrinter { -public: - HexArrayPrinter(T* ptr, size_t length) : ptr_(ptr), length_(length) {} - T* ptr_; - size_t length_; -}; - -template -std::ostream& operator<<(std::ostream& stream, const HexArrayPrinter& printer) { - for (size_t pos = 0; pos < printer.length_; ++pos) { - stream << " " << as_hex(printer.ptr_[pos]); - if (((pos + 1) % 16) == 0) - stream << std::endl; - } - return stream; -} - -template -HexArrayPrinter as_hex(T (&val)[ILength]) { return HexArrayPrinter(val, ILength); } - -} - template class simple_iterator : std::iterator { diff --git a/Firmware/fibre/cpp/interfaces_template.j2 b/Firmware/fibre/cpp/interfaces_template.j2 index b8feeafa..eb5167a7 100644 --- a/Firmware/fibre/cpp/interfaces_template.j2 +++ b/Firmware/fibre/cpp/interfaces_template.j2 @@ -57,11 +57,11 @@ public: [%- for func in intf.functions.values() %] [%- for k, arg in func.in.items() | skip_first %] [[arg.type.c_type]] [[func.name | to_snake_case]]_in_[[arg.name]]_; // for internal use by Fibre - template static auto get_[[func.name | to_snake_case]]_in_[[arg.name]]_(T* obj) { return Property<[[arg.type.c_type]]>{obj, [](void* ctx){ return ([[arg.type.c_type]])((T*)ctx)->[[func.name | to_snake_case]]_in_[[arg.name]]_; }, [](void* ctx, [[arg.type.c_type]] value){ ((T*)ctx)->[[func.name | to_snake_case]]_in_[[arg.name]]_ = value; }}; } + template static auto get_[[func.name | to_snake_case]]_in_[[arg.name]]_(T* obj) { return Property<[[arg.type.c_type]]>{&obj->[[func.name | to_snake_case]]_in_[[arg.name]]_}; } [%- endfor %] [%- for k, arg in func.out.items() %] [[arg.type.c_type]] [[func.name | to_snake_case]]_out_[[arg.name]]_; // for internal use by Fibre - template static auto get_[[func.name | to_snake_case]]_out_[[arg.name]]_(T* obj) { return Property{obj, [](void* ctx){ return ([[arg.type.c_type]])((T*)ctx)->[[func.name | to_snake_case]]_out_[[arg.name]]_; }}; } + template static auto get_[[func.name | to_snake_case]]_out_[[arg.name]]_(T* obj) { return Property{&obj->[[func.name | to_snake_case]]_out_[[arg.name]]_}; } [%- endfor %] [%- endfor %] };