Browse Source

公共导出函数提出到ExportMethod

lijinwen 4 months ago
parent
commit
c108937d5f

+ 30 - 0
ExportMethod.cpp

@@ -0,0 +1,30 @@
+#include "ExportMethod.h"
+#include "ProtocolDecodeBase.h"
+#include "EdgePulseData.h"
+#include "QuantizeParams.h"
+#include "ProtocolRS232/Protocol.RS232.Options.h"
+#include "ProtocolRS232/RS232DecodeResult.h"
+
+
+namespace Protocol
+{
+    extern "C" {
+
+    LIBMATH_API bool decodeRS232(const ProtocolRS232Options& options,
+                                 const EdgePulseDataTwoLevels& edgePulseData,
+                                 RS232DecodeResult& decodeResult);
+
+    LIBMATH_API bool quantizeParamsDecodeRS232(const QuantizeParams& quantizeParams,
+                                               const ProtocolRS232Options& options,
+                                               RS232DecodeResult& decodeResult);
+        
+   
+    inline LIBMATH_API void setCancellationSignal(bool value)
+    {
+        canceled = value;
+    }
+    
+    LIBMATH_API void getVersionExport(uint8_t* version);
+
+    }
+}

+ 16 - 0
ExportMethod.h

@@ -0,0 +1,16 @@
+// // ******************************************************************
+// //       /\ /|       @File         ExportMethod.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-20
+// //      /  \\        @Modified      2024-05-20
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+
+#ifdef LIBMATH_EXPORTS
+#define LIBMATH_API __declspec(dllexport)
+#else
+#define LIBMATH_API __declspec(dllimport)
+#endif

+ 1 - 5
ProtocolDecodeBase.cpp

@@ -16,11 +16,7 @@
 
 namespace Protocol
 {
-
-    void cancel()
-    {
-        canceled = true;
-    }
+ 
 
 }
 

+ 1 - 18
ProtocolDecodeBase.h

@@ -22,12 +22,6 @@
 
 #define DLL_VERSION "0.1.0"
 
-#ifdef LIBMATH_EXPORTS
-#define LIBMATH_API __declspec(dllexport)
-#else
-#define LIBMATH_API __declspec(dllimport)
-#endif
-
 namespace Protocol
 {
     class QuantizeParams;
@@ -35,18 +29,7 @@ namespace Protocol
 
     // 取消解码
     void cancel();
-
+    inline bool canceled = false;// 取消标志
     inline auto status = ProtocolStatus::Canceled; // 解码状态
 
 };
-
-//外部调用
-extern "C" {
-inline std::atomic<bool> canceled(false);// 取消标志
-inline LIBMATH_API void setCancellationSignal(bool value)
-{
-    canceled = value;
-}
-    
-LIBMATH_API void getVersionExport(uint8_t* version);
-}

+ 4 - 2
ProtocolDecoder.vcxproj

@@ -311,6 +311,7 @@
         <ClCompile Include="dllmain.cpp"/>
         <ClCompile Include="EdgePulse.cpp"/>
         <ClCompile Include="EdgePulseData.cpp"/>
+        <ClCompile Include="ExportMethod.cpp" />
         <ClCompile Include="ProtocolDecodeBase.cpp"/>
         <ClCompile Include="ProtocolRS232\RS232Decode.cpp"/>
         <ClCompile Include="ProtocolRS232\RS232DecodeEvent.cpp"/>
@@ -318,7 +319,7 @@
         <ClCompile Include="ProtocolRS232\RS232Packet.cpp"/>
         <ClCompile Include="ProtocolUSB\Constants.cpp" />
         <ClCompile Include="ProtocolUSB\UsbDecodeEvent.cpp" />
-        <ClCompile Include="ProtocolUSB\USBDecodeModel.cpp" />
+        <ClCompile Include="ProtocolUSB\USBDecode.cpp" />
         <ClCompile Include="ProtocolUSB\UsbDecodeResult.cpp" />
         <ClCompile Include="ProtocolUSB\USBPacket.cpp" />
         <ClCompile Include="QuantizeParams.cpp"/>
@@ -338,6 +339,7 @@
         <ClInclude Include="DecodeResult.h"/>
         <ClInclude Include="EdgePulse.h"/>
         <ClInclude Include="EdgePulseData.h"/>
+        <ClInclude Include="ExportMethod.h" />
         <ClInclude Include="ProtocolDecodeBase.h"/>
         <ClInclude Include="ProtocolRS232\Constants.h"/>
         <ClInclude Include="ProtocolRS232\Protocol.RS232.Options.h"/>
@@ -351,7 +353,7 @@
         <ClInclude Include="ProtocolUSB\ProtocolUSBEnums.h" />
         <ClInclude Include="ProtocolUSB\SYNC.h" />
         <ClInclude Include="ProtocolUSB\UsbDecodeEvent.h" />
-        <ClInclude Include="ProtocolUSB\USBDecodeModel.h" />
+        <ClInclude Include="ProtocolUSB\USBDecode.h" />
         <ClInclude Include="ProtocolUSB\UsbDecodeOptions.h" />
         <ClInclude Include="ProtocolUSB\UsbDecodeResult.h" />
         <ClInclude Include="ProtocolUSB\USBPacket.h" />

+ 1 - 11
ProtocolRS232/RS232Decode.h

@@ -33,15 +33,5 @@ namespace Protocol
 
     std::vector<const char*> getEventInfoTitles();
      
-    extern "C" {
-
-    LIBMATH_API bool decodeRS232(const ProtocolRS232Options& options,
-                                 const EdgePulseDataTwoLevels& edgePulseData,
-                                 RS232DecodeResult& decodeResult);
-
-    LIBMATH_API bool quantizeParamsDecodeRS232(const QuantizeParams& quantizeParams,
-                                               const ProtocolRS232Options& options,
-                                               RS232DecodeResult& decodeResult);
-
-    }
+    
 }

+ 18 - 18
ProtocolUSB/USBDecodeModel.cpp → ProtocolUSB/USBDecode.cpp

@@ -1,5 +1,5 @@
 // // ******************************************************************
-// //       /\ /|       @File         USBDecodeModel.cpp
+// //       /\ /|       @File         USBDecode.cpp
 // //       \ V/        @Brief
 // //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
 // //       /  |        @Creation      2024-1-4
@@ -7,11 +7,11 @@
 // //    *(__\_\
 // // ******************************************************************
 
-#include "USBDecodeModel.h"
+#include "USBDecode.h"
 
 namespace Protocol
 {
-    double USBDecodeModel::GetBitRateByPs() const
+    double USBDecode::GetBitRateByPs() const
     {
         double result = 1.0;
         switch (signalRate)
@@ -30,42 +30,42 @@ namespace Protocol
         return result;
     }
 
-    std::vector<std::string> USBDecodeModel::EventInfoTitles() const
+    std::vector<std::string> USBDecode::EventInfoTitles() const
     {
         return {"Index", "Start Time", "Sync", "PID", "Data", "Addr", "FNUM", "CRC5", "CRC16", "EOP", "Error"};
     }
 
-    Enums::SignalRate USBDecodeModel::SignalRate() const
+    Enums::SignalRate USBDecode::SignalRate() const
     {
         return signalRate;
     }
 
-    void USBDecodeModel::SetSignalRate(Enums::SignalRate value)
+    void USBDecode::SetSignalRate(Enums::SignalRate value)
     {
         signalRate = value;
     }
 
-    uint16_t USBDecodeModel::ByteCount() const
+    uint16_t USBDecode::ByteCount() const
     {
         return byteCount;
     }
 
-    void USBDecodeModel::SetByteCount(uint16_t value)
+    void USBDecode::SetByteCount(uint16_t value)
     {
         byteCount = value;
     }
 
-    uint16_t USBDecodeModel::MaxByteCount()
+    uint16_t USBDecode::MaxByteCount()
     {
         return 1023;
     }
 
-    uint16_t USBDecodeModel::MinByteCount()
+    uint16_t USBDecode::MinByteCount()
     {
         return 0;
     }
 
-    bool USBDecodeModel::ParseData(std::vector<Protocol::TwoLevelEdgePulse> edgePluses,
+    bool USBDecode::ParseData(std::vector<Protocol::TwoLevelEdgePulse> edgePluses,
                                      std::promise<void>& cancellationSignal)
     {
         if (edgePluses.empty()) return false;
@@ -97,7 +97,7 @@ namespace Protocol
         return true;
     }
 
-    bool USBDecodeModel::CheckDifferenceWithinThreshold(double* array, int32_t size, double threshold)
+    bool USBDecode::CheckDifferenceWithinThreshold(double* array, int32_t size, double threshold)
     {
         //threshold = 0.15;
         for (int i = 1; i < size; i++)
@@ -117,7 +117,7 @@ namespace Protocol
         return true; // 所有元素之间的差异都小于阈值
     }
 
-    void USBDecodeModel::ClearEdgeArray(Protocol::Edge* edges, int32_t size)
+    void USBDecode::ClearEdgeArray(Protocol::Edge* edges, int32_t size)
     {
         for (int i = 0; i < size; ++i)
         {
@@ -125,12 +125,12 @@ namespace Protocol
         }
     }
 
-    bool USBDecodeModel::CheckSyncEdges(Protocol::Edge startEdge, Protocol::Edge* edges)
+    bool USBDecode::CheckSyncEdges(Protocol::Edge startEdge, Protocol::Edge* edges)
     {
         return edges[0] == edges[1] && edges[0] == startEdge && edges[0] == edges[6];
     }
 
-    bool USBDecodeModel::CheckSyncSpans(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize
+    bool USBDecode::CheckSyncSpans(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize
                                         , const int32_t count, int32_t& avgSpans)
     {
         if (count < 1)
@@ -156,7 +156,7 @@ namespace Protocol
         return CheckSyncSpansByArrary(startIndexs, count, avgSpans);
     }
 
-    bool USBDecodeModel::CheckSyncSpansByArrary(int32_t* startIndexs, const int32_t count,
+    bool USBDecode::CheckSyncSpansByArrary(int32_t* startIndexs, const int32_t count,
                                                 int32_t& avgSpans)
     {
         if (count < 1)
@@ -177,7 +177,7 @@ namespace Protocol
         return CheckDifferenceWithinThreshold(tmpSpans, count - 1);
     }
 
-    bool USBDecodeModel::FindAllSyncs(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize,
+    bool USBDecode::FindAllSyncs(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize,
                                       std::vector<SYNC>& allSYNC, std::promise<void>& cancellationSignal,
                                       bool polarity)
     {
@@ -263,7 +263,7 @@ namespace Protocol
         return !allSYNC.empty();
     }
 
-    bool USBDecodeModel::FindPackets(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize,
+    bool USBDecode::FindPackets(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize,
                                      std::vector<USBPacket>& allPacket, std::promise<void>& cancellationSignal,
                                      bool polarity)
     {

+ 15 - 11
ProtocolUSB/USBDecodeModel.h → ProtocolUSB/USBDecode.h

@@ -1,5 +1,5 @@
 // // ******************************************************************
-// //       /\ /|       @File         USBDecodeModel.h
+// //       /\ /|       @File         USBDecode.h
 // //       \ V/        @Brief
 // //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
 // //       /  |        @Creation      2024-1-4
@@ -19,23 +19,18 @@
 
 #include "SYNC.h"
 #include "ProtocolUSBEnums.h"
-#include "UsbDecodeResult.h"
+#include "USBDecodeOptions.h"
+#include "USBDecodeResult.h"
 #include "USBPacket.h"
 
 namespace Protocol
 {
-    class USBDecodeModel
+    class USBDecode
     {
-    private:
-        UsbDecodeResult resultData;
-        Enums::SignalRate signalRate;
-
-        uint16_t byteCount;
-
-        std::vector<USBPacket> usbPackets;
+   
 
     public:
-        USBDecodeModel(): signalRate(), byteCount(0)
+        USBDecode(): signalRate(), byteCount(0)
         {
         }
 
@@ -57,7 +52,14 @@ namespace Protocol
 
         bool Parse_USB(UsbDecodeOptions option,std::vector<Protocol::TwoLevelEdgePulse> edgePluses1,
                          std::vector<Protocol::TwoLevelEdgePulse> edgePluses2,std::promise<void>& cancellationSignal);
+    private:
+        UsbDecodeResult resultData;
+        Enums::SignalRate signalRate;
 
+        uint16_t byteCount;
+
+        std::vector<USBPacket> usbPackets;
+        
     private:
         bool CheckDifferenceWithinThreshold(double* array, int32_t size, double threshold = 0.15);
 
@@ -76,5 +78,7 @@ namespace Protocol
         bool FindPackets(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize,
                          std::vector<USBPacket>& allPacket, std::promise<void>& cancellationSignal,
                          bool polarity = false);
+        bool ParseData(std::vector<Protocol::TwoLevelEdgePulse> edgePluses,
+                                     std::promise<void>& cancellationSignal);
     };
 }

+ 8 - 7
ProtocolUSB/USBPacket.cpp

@@ -8,7 +8,8 @@
 // // ******************************************************************
 
 #include "USBPacket.h"
-#include  "../BaseHelper/CommonHelper.h"
+#include "../BaseHelper/CommonHelper.h"
+ 
 namespace Protocol
 {
     USBPacket::USBPacket(): pid(0), lastNRBZDataBit(false), polarity(false), endPoint(0), crc5(0), isValid(false),
@@ -62,22 +63,22 @@ namespace Protocol
 
         pid = data;
 
-        if (EnumIsDefined<Enums::TokenPackageType>(
+        if (CommonHelper::EnumIsDefined<Enums::TokenPackageType>(
             static_cast<int>(RealPID())))
         {
             type = Enums::USBPacketType::Token;
         }
-        else if (Protocol::EnumIsDefined<Enums::DataPackageType>(
+        else if (CommonHelper::EnumIsDefined<Enums::DataPackageType>(
             static_cast<int>(RealPID())))
         {
             type = Enums::USBPacketType::Data;
         }
-        else if (Protocol::EnumIsDefined<Enums::HandshakePackageType>(
+        else if (CommonHelper::EnumIsDefined<Enums::HandshakePackageType>(
             static_cast<int>(RealPID())))
         {
             type = Enums::USBPacketType::HandShake;
         }
-        else if (Protocol::EnumIsDefined<Enums::SpecialPacketType>(
+        else if (CommonHelper::EnumIsDefined<Enums::SpecialPacketType>(
             static_cast<int>(RealPID())))
         {
             type = Enums::USBPacketType::Special;
@@ -99,7 +100,7 @@ namespace Protocol
 
         while (gotbitCount < 8)
         {
-            if (node == nullptr || leftOverSize <= 0 || (*node).Edge == CommonBase::Edge::None)
+            if (node == nullptr || leftOverSize <= 0 || (*node).Edge == Protocol::Edge::None)
             {
                 return false;
             }
@@ -117,7 +118,7 @@ namespace Protocol
                         continue;
                     }
                     nrzi_data[lastGotbitCount + i] = highPolarityEdge == ((*node).Edge ==
-                        CommonBase::Edge::Rise);
+                        Protocol::Edge::Rise);
 
                     gotbitCount++;
                 }

+ 9 - 9
ProtocolUSB/USBPacket.h

@@ -11,8 +11,8 @@
 #include <typeinfo>
 #include <vector>
 
-#include "../../CommonBase/CommonHelper.h"
-#include "../../CommonBase/EnumTypeInfo.h"
+#include "../BaseHelper//CommonHelper.h"
+#include "../BaseEnums/ProtocolEnums.h"
 #include "../EdgePulse.h"
 
 #include "SYNC.h"
@@ -59,17 +59,17 @@ namespace Protocol
 
         bool CheckNibblesInverse(uint8_t value);
 
-        bool GetPID(ProtocolBase::TwoLevelEdgePulse* pidNode, int32_t& leftOverSize);
+        bool GetPID(Protocol::TwoLevelEdgePulse* pidNode, int32_t& leftOverSize);
 
-        bool DecodeNextByte(ProtocolBase::TwoLevelEdgePulse* node, int32_t& leftOverSize, uint8_t& outData);
+        bool DecodeNextByte(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, uint8_t& outData);
 
-        void DecodeFields(ProtocolBase::TwoLevelEdgePulse* node, int32_t& leftOverSize, const SYNC& sync);
+        void DecodeFields(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, const SYNC& sync);
 
-        void DecodeFieldsByToken(ProtocolBase::TwoLevelEdgePulse* node, int32_t& leftOverSize, const SYNC& sync);
-        void DecodeFieldsByData(ProtocolBase::TwoLevelEdgePulse* node, int32_t& leftOverSize, const SYNC sync);
+        void DecodeFieldsByToken(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, const SYNC& sync);
+        void DecodeFieldsByData(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, const SYNC sync);
 
-        void DecodeFieldsByHandShake(ProtocolBase::TwoLevelEdgePulse* node, int32_t& leftOverSize, SYNC sync);
+        void DecodeFieldsByHandShake(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, SYNC sync);
 
-        void DecodeFieldsBySpecial(ProtocolBase::TwoLevelEdgePulse* node, int32_t& leftOverSize, SYNC sync);
+        void DecodeFieldsBySpecial(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, SYNC sync);
     };
 }

+ 1 - 1
ProtocolUSB/UsbDecodeEvent.h

@@ -8,7 +8,7 @@
 // // ******************************************************************
 
 #pragma once
-#include "DecodeEvent.h"
+#include "../DecodeEvent.h"
 
 namespace Protocol
 {

+ 7 - 7
ProtocolUSB/UsbDecodeResult.cpp

@@ -11,14 +11,14 @@
 
 namespace Protocol
 {
-    void UsbDecodeResult::Add(const UsbDecodeResultUnit* unit)
+    void UsbDecodeResult::Add(const UsbDecodeResultCell* cell)
     {
-        DecodeResultUnits.push_back(*unit);
+        DecodeResultCells.push_back(*cell);
     }
 
-    void UsbDecodeResult::ClearData()
-    {
-        DecodeResultUnits.clear();
-        ResultValid = false;
-    }
+    // void UsbDecodeResult::ClearData()
+    // {
+    //     DecodeResultCells.clear();
+    //     ResultValid = false;
+    // }
 }