-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Added class md_attribute_parser_with_crc to dev #12424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,9 @@ | |
|
|
||
| #include "frame.h" | ||
| #include "metadata.h" | ||
| #include <cmath> | ||
|
|
||
| #include <cmath> | ||
| #include <rsutils/number/crc32.h> | ||
| #include <rsutils/string/from.h> | ||
|
|
||
|
|
||
|
|
@@ -321,6 +322,53 @@ namespace librealsense | |
| } | ||
| }; | ||
|
|
||
| template<class S, class Attribute, typename Flag> | ||
| class md_attribute_parser_with_crc : public md_attribute_parser<S, Attribute, Flag> | ||
| { | ||
| public: | ||
| md_attribute_parser_with_crc(Attribute S::* attribute_name, Flag flag, unsigned long long offset, attrib_modifyer mod, unsigned long long crc_offset) | ||
| : md_attribute_parser<S, Attribute, Flag>(attribute_name, flag, offset, mod), _crc_offset(crc_offset) {} | ||
|
|
||
| protected: | ||
| unsigned long long _crc_offset; // offset of the crc inside the S class | ||
| bool is_attribute_valid(const S* s) const override | ||
| { | ||
| if (!md_attribute_parser<S, Attribute, Flag>::is_attribute_valid(s)) | ||
| return false; | ||
|
|
||
| if (!is_crc_valid(s)) | ||
| { | ||
| LOG_DEBUG("Metadata CRC mismatch"); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| private: | ||
| md_attribute_parser_with_crc() = delete; | ||
| md_attribute_parser_with_crc(const md_attribute_parser_with_crc&) = delete; | ||
|
|
||
| bool is_crc_valid(const S* md_info) const | ||
| { | ||
| Attribute crc = *(Attribute*)(reinterpret_cast<const uint8_t*>(md_info) + _crc_offset); //Attribute = CRC's type (ex. uint32_t) | ||
| auto computed_crc32 = rsutils::number::calc_crc32(reinterpret_cast<const uint8_t*>(md_info), | ||
| sizeof(S) - sizeof(crc)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. S is the struct that have all of the attributes, including the crc. |
||
| return (crc == computed_crc32); | ||
| } | ||
| }; | ||
|
|
||
| /**\brief A helper function to create a specialized attribute parser. | ||
| * **Note that this class is assuming that the CRC is the last variable in the struct** | ||
| * Return it as a pointer to a base-class*/ | ||
| template<class S, class Attribute, typename Flag> | ||
| std::shared_ptr<md_attribute_parser_base> make_attribute_parser_with_crc(Attribute S::* attribute, Flag flag, unsigned long long offset, unsigned long long crc_offset, attrib_modifyer mod = nullptr) | ||
| { | ||
| std::shared_ptr<md_attribute_parser<S, Attribute, Flag>> parser(new md_attribute_parser_with_crc<S, Attribute, Flag>(attribute, flag, offset, mod, crc_offset)); | ||
| return parser; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| class ds_md_attribute_actual_fps : public md_attribute_parser_base | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'LOG_WARNING?'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the way it was originally, and it is also LOG_DEBUG in the parent class in is_attribute_valid function, when we find "metadata mismatch"