// // Created by xtkuang on 2025/5/13. // #include "device_manager/device_factory.h" #include "biohead/biohead_esp32/biohead_esp32.h" #include "camera/uvc_camera/uvc_camera.h" #include "camera/mechmind/mechmind_camera.h" #include "speaker/ffmpeg_speaker/ffmpeg_speaker.h" #include "microphone/ffmpeg_microphone/ffmpeg_microphone.h" #include "camera/realsense_camera/realsense_camera.h" #include "dexhand/rh56dftp_dexhand/rh56dftp_dexhand.h" #include "robot/humanoid_robot/humanoid_robot.h" //#include "robot/ti5_robot/ti5_robot.h" #include "data_center/include/motors_info.h" using namespace std; using namespace cmvr::device; template std::shared_ptr DeviceFactory::create(const XmlNode&); template std::shared_ptr DeviceFactory::create(const XmlNode&); template std::shared_ptr DeviceFactory::create(const XmlNode&); template std::shared_ptr DeviceFactory::create(const XmlNode&); template std::shared_ptr DeviceFactory::create(const XmlNode&); template std::shared_ptr DeviceFactory::create(const XmlNode&); template std::shared_ptr DeviceFactory::create(const XmlNode&); template std::shared_ptr DeviceFactory::create(const XmlNode&); template std::shared_ptr DeviceFactory::create(const XmlNode&); template std::shared_ptr DeviceFactory::create(const XmlNode& cfg) { if constexpr (std::is_same_v) { return create_agv_(cfg); } else if constexpr (std::is_same_v) { return create_battery_(cfg); } else if constexpr (std::is_same_v) { return create_camera_(cfg); } else if constexpr (std::is_same_v) { return create_dexhand_(cfg); } else if constexpr (std::is_same_v) { return create_gripper_(cfg); } else if constexpr (std::is_same_v) { return create_mic_(cfg); } else if constexpr (std::is_same_v) { return create_robot_(cfg); } else if constexpr (std::is_same_v) { return create_speaker_(cfg); }else if constexpr (std::is_same_v){ return create_biohead_(cfg); } else { LOG(ERROR) << "[DeviceFactory]: Unsupported device type"; throw runtime_error("[DeviceFactory]: Unsupported device type"); } } std::shared_ptr DeviceFactory::create_agv_(const XmlNode& cfg) { return nullptr; } std::shared_ptr DeviceFactory::create_battery_(const XmlNode& cfg) { return nullptr; } std::shared_ptr DeviceFactory::create_camera_(const XmlNode& cfg) { try { if (cfg.getNodeName() == "UVCCamera") { return std::make_shared(cfg); } else if (cfg.getNodeName() == "MechMind") { return std::make_shared(cfg); } else if (cfg.getNodeName() == "RealsenseCamera") { return std::make_shared(cfg); } else { LOG(ERROR) << "[DeviceFactory]: Unsupported device type " << cfg.getNodeName(); return nullptr; } } catch (const exception &e) { return nullptr; } } std::shared_ptr DeviceFactory::create_dexhand_(const XmlNode& cfg) { try { if (cfg.getNodeName() == "RH56DFTP") { return std::make_shared(cfg); } else { LOG(ERROR) << "[DeviceFactory]: Unsupported device type " << cfg.getNodeName(); return nullptr; } } catch (const exception &e) { return nullptr; } } std::shared_ptr DeviceFactory::create_gripper_(const XmlNode& cfg) { return nullptr; } std::shared_ptr DeviceFactory::create_mic_(const XmlNode& cfg) { try { if (cfg.getNodeName() == "ffmpegMicPhone") { return std::make_shared(cfg); } else { LOG(ERROR) << "[DeviceFactory]: Unsupported device type " << cfg.getNodeName(); return nullptr; } } catch (const exception &e) { return nullptr; } return nullptr; } std::shared_ptr DeviceFactory::create_robot_(const XmlNode& cfg) { try { if (cfg.getNodeName() == "Humanoid") { auto motos_info = MotorsInfo::getInstance(); motos_info->init(cfg); return std::make_shared>(cfg); } else { LOG(ERROR) << "[DeviceFactory]: Unsupported device type " << cfg.getNodeName(); return nullptr; } } catch (const exception &e) { return nullptr; } } std::shared_ptrDeviceFactory::create_biohead_(const XmlNode& cfg) { try { if (cfg.getNodeName() == "esp32") { return std::make_shared(cfg); } else { LOG(ERROR) << "[DeviceFactory]: Unsupported device type " << cfg.getNodeName(); return nullptr; } } catch (const exception &e) { return nullptr; } } std::shared_ptr DeviceFactory::create_speaker_(const XmlNode& cfg) { try { if (cfg.getNodeName() == "ffmpegSpeaker") { return std::make_shared(cfg); } else { LOG(ERROR) << "[DeviceFactory]: Unsupported device type " << cfg.getNodeName(); return nullptr; } } catch (const exception &e) { return nullptr; } }