// // ****************************************************************** // // /\ /| @File ProtocolDecodeBase.cpp // // \ V/ @Brief // // | "") @Author lijinwen, ghz005@uni-trend.com.cn // // / | @Creation 2024-5-6 // // / \\ @Modified 2024-5-13 // // *(__\_\ // // ****************************************************************** #include "ProtocolDecodeBase.h" #include "DecodeParams.h" #include "QuantizeParams.h" #include "BaseHelper/Logger.h" #include "ProtocolUSB/UsbDecode.h" #include "ProtocolRS232/RS232Decode.h" namespace Protocol { /** * \brief */ ProtocolDecodeBase::~ProtocolDecodeBase() { Cancel(); } //解码过程 void ProtocolDecodeBase::DecodeAsync(const DecodeParams* decodeParams) { canceled_ = false; //decode_thread_ = std::thread(&ProtocolBase::Decode, this, decode_params); // 使用 std::bind 来绑定 this 指针和成员函数指针 decode_thread_ = std::thread([this, decodeParams] { Decode(decodeParams); }); } //带整型的解码过程 void ProtocolDecodeBase::QuantizeDecodeAsync(const QuantizeParams& decodeParams) { canceled_ = false; //decode_thread_ = std::thread(&ProtocolBase::Decode, this, decode_params); // 使用 std::bind 来绑定 this 指针和成员函数指针 decode_thread_ = std::thread([this, decodeParams] { QuantizeDecode(decodeParams); }); } void ProtocolDecodeBase::Cancel() { canceled_ = true; if (decode_thread_.joinable()) { decode_thread_.join(); // 确保解码线程已经结束 } } ProtocolStatus ProtocolDecodeBase::GetStatus() const { return status_; } DecodeResult* ProtocolDecodeBase::GetResult() { return nullptr; } void ProtocolDecodeBase::QuantizeDecode(const QuantizeParams& quantizeParams) { status_ = ProtocolStatus::QuantizeInProgress; // 默认实现,可以被子类覆盖 if (canceled_) { status_ = ProtocolStatus::Canceled; return; } // 虚函数没有实际解码 status_ = ProtocolStatus::Success; // 解码成功 } void ProtocolDecodeBase::Decode(const DecodeParams* decodeParams) { status_ = ProtocolStatus::DecodeInProgress; // 默认实现,可以被子类覆盖 if (canceled_) { status_ = ProtocolStatus::Canceled; return; } // 虚函数没有实际解码 status_ = ProtocolStatus::Success; // 解码成功 } }