Skip to content

Commit

Permalink
Renamed a couple of fields and made EepromData serialization optional
Browse files Browse the repository at this point in the history
  • Loading branch information
themarpe committed Apr 21, 2022
1 parent c6edc33 commit d18b6f6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
18 changes: 16 additions & 2 deletions include/depthai-shared/common/EepromData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,27 @@ namespace dai {
*/
struct EepromData {
uint32_t version = 7;
std::string productName, boardName, boardRev, boardId, hardwareId, customBoard, batchName;
std::string productName, boardCustom, boardName, boardRev, boardConf, hardwareConf, batchName;
uint64_t batchTime{0};
std::unordered_map<CameraBoardSocket, CameraInfo> cameraData;
StereoRectification stereoRectificationData;
Extrinsics imuExtrinsics;
std::vector<uint8_t> miscellaneousData;
DEPTHAI_SERIALIZE(EepromData, version, boardName, boardRev, boardId, hardwareId, productName, customBoard, batchName, batchTime, cameraData, stereoRectificationData, imuExtrinsics, miscellaneousData);
};

DEPTHAI_SERIALIZE_OPTIONAL_EXT(EepromData,
version,
boardCustom,
boardName,
boardRev,
boardConf,
hardwareConf,
productName,
batchName,
batchTime,
cameraData,
stereoRectificationData,
imuExtrinsics,
miscellaneousData);

} // namespace dai
29 changes: 27 additions & 2 deletions include/depthai-shared/utility/Serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,39 @@ inline bool deserialize(const std::vector<std::uint8_t>& data, T& obj) {

#define DEPTHAI_DEFERRED_EXPAND(x) x
#if defined(_MSC_VER) && (!defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL)

// Logic using the traditional preprocessor
// Logic using the traditional preprocessor
// This is for suppressing false positive warnings when compiling
// without /Zc:preprocessor
#pragma warning(disable : 4003)
#endif

#define DEPTHAI_NLOHMANN_JSON_OPTIONAL_TO(v1) nlohmann::to_json(nlohmann_json_j[#v1], nlohmann_json_t.v1);
#define DEPTHAI_NLOHMANN_JSON_OPTIONAL_FROM(v1) \
if(nlohmann_json_j.contains(#v1)) nlohmann_json_j[#v1].get_to(nlohmann_json_t.v1);
#define DEPTHAI_NLOHMANN_DEFINE_TYPE_OPTIONAL_NON_INTRUSIVE(Type, ...) \
inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { \
NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(DEPTHAI_NLOHMANN_JSON_OPTIONAL_TO, __VA_ARGS__)) \
} \
inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { \
NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(DEPTHAI_NLOHMANN_JSON_OPTIONAL_FROM, __VA_ARGS__)) \
}
#define DEPTHAI_NLOHMANN_DEFINE_TYPE_OPTIONAL_INTRUSIVE(Type, ...) \
friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { \
NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(DEPTHAI_NLOHMANN_JSON_OPTIONAL_TO, __VA_ARGS__)) \
} \
friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { \
NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(DEPTHAI_NLOHMANN_JSON_OPTIONAL_FROM, __VA_ARGS__)) \
}

// Macros
#define DEPTHAI_SERIALIZE_OPTIONAL_EXT(...) \
DEPTHAI_DEFERRED_EXPAND(DEPTHAI_NLOHMANN_DEFINE_TYPE_OPTIONAL_NON_INTRUSIVE(__VA_ARGS__)) \
DEPTHAI_DEFERRED_EXPAND(NOP_EXTERNAL_STRUCTURE(__VA_ARGS__))

#define DEPTHAI_SERIALIZE_OPTIONAL(...) \
DEPTHAI_DEFERRED_EXPAND(DEPTHAI_NLOHMANN_DEFINE_TYPE_OPTIONAL_INTRUSIVE(__VA_ARGS__)) \
DEPTHAI_DEFERRED_EXPAND(NOP_EXTERNAL_STRUCTURE(__VA_ARGS__))

#define DEPTHAI_SERIALIZE_EXT(...) \
DEPTHAI_DEFERRED_EXPAND(NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(__VA_ARGS__)) \
DEPTHAI_DEFERRED_EXPAND(NOP_EXTERNAL_STRUCTURE(__VA_ARGS__))
Expand Down

0 comments on commit d18b6f6

Please sign in to comment.