diff --git a/commdll/Include/FileLog.h b/commdll/Include/FileLog.h index 2abc66d..b044e44 100644 --- a/commdll/Include/FileLog.h +++ b/commdll/Include/FileLog.h @@ -4,40 +4,34 @@ #pragma once #include +#include + +#include "spdlog/spdlog.h" class CFileLog { public: - CFileLog(); + CFileLog(const std::string& strName = R"(file_logger)"); virtual ~CFileLog(); - void SetFilename(std::string csFilename); - void SetHeaderString(std::string csHeaderString); - void LogData(std::string csData, bool bCreateNew = false); - void LogDataToFile(std::string csFileName, std::string csData, bool bCreateNew = false); - void EnableRunningNumber(bool bEnable, std::string csHeader); + void InitLogger(); + + void SetFilename(const std::string& csFilename); + void LogData(const std::string& csData); + private: - std::string GetLogFileNameWithRunningNumber(std::string csFileName); - std::string RemoveFileExtension(std::string csFullName, std::string csRemoveExt, std::string newExt); - std::string IncAndReturnRunningLotNumberFile(std::string csFileName); // - std::string GetTime(); - std::string GetYYYYMMDD(); ///// // Variables //// + std::string m_strName; std::string m_strFilename; - std::string m_strFilenameExt; std::string m_strFolderName; - std::string m_strPathFilename; std::string m_strFileExt; - std::string m_strHeaderString; - std::string m_strConfigHeader; - - long m_lFileNo; - bool m_bHeaderCreated; - bool m_bLogTimeStamp; - bool m_bLogDailyFormat; - bool m_bSaveWithRunningNumber; + std::string m_strPathFilename; + + bool m_bLogDailyFormat{ false }; + + std::shared_ptr m_logger; }; diff --git a/commdll/Include/GPVisionHS.h b/commdll/Include/GPVisionHS.h index 77a8837..1c8e314 100644 --- a/commdll/Include/GPVisionHS.h +++ b/commdll/Include/GPVisionHS.h @@ -22,15 +22,15 @@ #define COMMDLL_DLLCLASS __declspec(dllimport) #endif -constexpr auto MAX_UNIT = 2048; +constexpr auto MAX_UNIT = 2048; struct stGPMultiUnitDataResult { std::string strResult; - double dResult1; - double dResult2; - double dResult3; - double dResult4; + double dResult1; + double dResult2; + double dResult3; + double dResult4; }; using namespace std; @@ -169,7 +169,7 @@ public: bool StartLightVerification(int nStationNo); void ReceiveComm(const char* cpcBuffer, int nSize); - int WaitInTeachOrCapture(int nStationNo, DWORD dwTimeout); // Monitor Either InTeach or Capture + int WaitInTeachOrCapture(int nStationNo, DWORD dwTimeout); // Monitor Either InTeach or Capture bool Get2DMatrixResult(int nStationNo, std::string& str2DMatrixResult); bool StartTeachPosition(int nStationNo, int nIndexX, int nIndexY, int nColFOV, int nRowFOV); @@ -203,16 +203,16 @@ public: bool WaitStartBufferingLoopAck(int nStationNo, DWORD dwTimeout = 0); bool RequestEndBufferingGetReady(int nStationNo); bool WaitEndBufferingLoopAck(int nStationNo, DWORD dwTimeout = 0); - int GetNoOfBufferingCapture(int nStationNo); + int GetNoOfBufferingCapture(int nStationNo); // Get GP Info std::string GetInfo(int nPackageID, std::string csParameter, DWORD dwTimeout = 0, bool bWaitAck = false); - bool WaitInfoReady(DWORD dwTimeout = 0); - bool GetInfoResult(std::string& csPackageNameResult); + bool WaitInfoReady(DWORD dwTimeout = 0); + bool GetInfoResult(std::string& csPackageNameResult); std::string GetModelNameInfo(DWORD dwTimeout = 0); std::string GetPackageNameInfo(int nPackageID, DWORD dwTimeout = 0); - int GetPackageIdInfo(DWORD dwTimeout = 0); + int GetPackageIdInfo(DWORD dwTimeout = 0); // bool OpenLot(std::string csPackageName, DWORD dwTimeout = 5000); @@ -249,10 +249,10 @@ public: bool IsModuleEnable(int nStationNo, int nInspectionModule, int nSetNo = 1); double GetResolution(int nStationNo, bool bXResolution); - bool IsSemiT10Enable(int nStationNo); - bool IsRefLocateEnable(int nStationNo); + bool IsSemiT10Enable(int nStationNo); + bool IsRefLocateEnable(int nStationNo); - int GetInspectionSequence(int nStationNo); + int GetInspectionSequence(int nStationNo); bool IsDiagLogDataEnable(int nStationNo); bool IsDiagResultAlwaysGood(int nStationNo); @@ -274,11 +274,11 @@ public: // Data Logging void SetLogEnable(bool bEnable = true); - void SetLogFilename(std::string csFilename); + void SetLogFilename(const std::string& csFilename); // - void InitParameters(int nStationNo, int nNoOfUnitsResult, std::vector& pnGx, std::vector& pnLx, std::vector& pnDataSetType, int nNoOfDataSetType = 1); + void InitParameters(int nStationNo, int nNoOfUnitsResult, std::vector& pnGx, std::vector& pnLx, std::vector& pnDataSetType, int nNoOfDataSetType = 1); CVisionUnitResult* GetMultiUnitResult(int nStationNo, int nUnitNo, int nCat); - int GetTotalUnits(int nStationNo); + int GetTotalUnits(int nStationNo); // // Save the current reject image to the dedicated folder. Acknowledge R if OK or F if error. @@ -302,13 +302,13 @@ public: bool SetInspectionInfo(int nStationNo, std::string strID, CPoint ptXY); size_t GetMaxStnInUse() { return m_nMaxStnInUse; } - void SetMaxStnInUse(size_t nMaxStnInUse) { m_nMaxStnInUse = nMaxStnInUse; } + void SetMaxStnInUse(size_t nMaxStnInUse) { m_nMaxStnInUse = nMaxStnInUse; } private: void InitPviTokenConfig(); - int GetPviParamNo(int nDataSetNum, int nTokenPos); + int GetPviParamNo(int nDataSetNum, int nTokenPos); // virtual bool ProcessDollarUnitDataSet(string& strData, CVisionUnitResult* pVisionBuffer, int nDataSetType, bool bAbsPosition = false); // $ protocol @@ -321,10 +321,10 @@ private: bool IsValidStationNo(int nStationNo); - void ResetReceiveBuffer(); + void ResetReceiveBuffer(); string TranslateResCode(const string& strCode); - void SaveLogData(std::string strMsg); + void SaveLogData(const std::string& strMsg); // Attributes // Option @@ -348,8 +348,8 @@ private: vector m_vec2DMatrixResult; vector m_vecImageLoadResult; - string m_strInfoResult; - string m_strOcrParamValue; + string m_strInfoResult; + string m_strOcrParamValue; std::vector> m_stMultiUnitResult; //// @@ -376,8 +376,8 @@ private: size_t m_nMaxStnInUse; // Logging CCriticalSection m_criticalSectionFileLog; - CFileLog m_FileLog; - bool m_bLogEnable; + CFileLog m_FileLog; + bool m_bLogEnable; bool m_bLocalLoopback; // E30 @@ -386,8 +386,8 @@ private: // std::unique_ptr m_camId; - string m_strOneLine; - string m_strDryRunExceptionCode; + string m_strOneLine; + string m_strDryRunExceptionCode; std::vector m_ptPackageSize; diff --git a/commdll/Include/TCPIP/BufferedSocket.h b/commdll/Include/TCPIP/BufferedSocket.h index de645c4..3e64cdd 100644 --- a/commdll/Include/TCPIP/BufferedSocket.h +++ b/commdll/Include/TCPIP/BufferedSocket.h @@ -34,20 +34,20 @@ public: private: CConcurrentQueue* m_pMessageQueue; CConcurrentQueue* m_pSendQueue; - CBufferMessageThread* m_pMessageThread; - CBufferMessageThread* m_PSenderThread; - IBufferSocketCallBack* m_pCallBack; - CReceivingThread* m_pReceivingThread; - CEvt* m_hConnectedEvent; - SOCKET s; - bool bIsConnected; + CBufferMessageThread* m_pMessageThread; + CBufferMessageThread* m_PSenderThread; + IBufferSocketCallBack* m_pCallBack; + CReceivingThread* m_pReceivingThread; + CEvt* m_hConnectedEvent; + SOCKET s; + bool bIsConnected; // Private methods protected: void OnReceive(const char* buf, size_t len); void OnDisconnect(int errorCode); - int Read(char* buf, size_t size); - int Write(const char* buf, size_t len); + int Read(char* buf, size_t size); + int Write(const char* buf, size_t len); private: CBufferedSocket(const CBufferedSocket&); diff --git a/commdll/lib/commdll.lib b/commdll/lib/commdll.lib index 58cad02..9701018 100644 Binary files a/commdll/lib/commdll.lib and b/commdll/lib/commdll.lib differ diff --git a/commdll/lib/commdllD.lib b/commdll/lib/commdllD.lib index 7b683d3..921b951 100644 Binary files a/commdll/lib/commdllD.lib and b/commdll/lib/commdllD.lib differ diff --git a/dll/commdll.dll b/dll/commdll.dll index b34f8e5..259ed9c 100644 Binary files a/dll/commdll.dll and b/dll/commdll.dll differ diff --git a/dll/commdllD.dll b/dll/commdllD.dll index a0cd161..ffc723c 100644 Binary files a/dll/commdllD.dll and b/dll/commdllD.dll differ diff --git a/dll/iodll.dll b/dll/iodll.dll index 9733a9a..148f6d6 100644 Binary files a/dll/iodll.dll and b/dll/iodll.dll differ diff --git a/dll/iodllD.dll b/dll/iodllD.dll index ecb886b..524d893 100644 Binary files a/dll/iodllD.dll and b/dll/iodllD.dll differ diff --git a/dll/mcctrdll.dll b/dll/mcctrdll.dll index f254ba6..49409b1 100644 Binary files a/dll/mcctrdll.dll and b/dll/mcctrdll.dll differ diff --git a/dll/mcctrdllD.dll b/dll/mcctrdllD.dll index c5cbcee..fa09a35 100644 Binary files a/dll/mcctrdllD.dll and b/dll/mcctrdllD.dll differ diff --git a/dll/secsgemdll.dll b/dll/secsgemdll.dll index b050fc9..a6950d5 100644 Binary files a/dll/secsgemdll.dll and b/dll/secsgemdll.dll differ diff --git a/dll/secsgemdllD.dll b/dll/secsgemdllD.dll index c02da9c..5c25628 100644 Binary files a/dll/secsgemdllD.dll and b/dll/secsgemdllD.dll differ diff --git a/dll/utility.dll b/dll/utility.dll index 7fa11f5..6d3331f 100644 Binary files a/dll/utility.dll and b/dll/utility.dll differ diff --git a/dll/utilityD.dll b/dll/utilityD.dll index 4c7f250..8801089 100644 Binary files a/dll/utilityD.dll and b/dll/utilityD.dll differ diff --git a/iodll/Include/MotionController_GALIL.h b/iodll/Include/MotionController_GALIL.h index e3df86c..eb51f34 100644 --- a/iodll/Include/MotionController_GALIL.h +++ b/iodll/Include/MotionController_GALIL.h @@ -23,5 +23,5 @@ public: int m_nCurrentIndex; private: - CWinThread* m_pGalilIntThread[4]; + std::array m_pGalilIntThread; }; diff --git a/utility/Include/DebugLog.h b/utility/Include/DebugLog.h index 8627ed0..eb3feee 100644 --- a/utility/Include/DebugLog.h +++ b/utility/Include/DebugLog.h @@ -1,14 +1,66 @@ #pragma once +#include "fmt/format.h" + #include "DllDefines.h" -void UTILITYDLL DebugLog(LPSTR lpFormat, ...); -void UTILITYDLL DebugLog(bool bTraceData, LPSTR lpFormat, ...); -void UTILITYDLL DebugLog(LPCTSTR lpName, bool bTraceData, LPSTR lpFormat, ...); +#ifdef LEGACY_LOGGER +#include "LegacyDebugLog.h" +#include "LegacyDebugLogTiming.h" +#include "LegacyGuiEventLog.h" + +extern UTILITYDLL CLegacyDebugLog mitechDebug; +extern UTILITYDLL CLegacyDebugLogTiming mitechDebugLogTiming; +extern UTILITYDLL CLegacyGuiEventLog mitechGuiEventLog; +#else +#include "MitechDebugLog.h" +#include "MitechDebugLogTiming.h" +#include "MitechGuiEventLog.h" + +extern UTILITYDLL CMitechDebugLog mitechDebug; +extern UTILITYDLL CMitechDebugLogTiming mitechDebugLogTiming; +extern UTILITYDLL CMitechGuiEventLog mitechGuiEventLog; +#endif + +// + +template +void DebugLog(fmt::format_string _fmt, Args&&... args) +{ + mitechDebug.Log(_fmt, args...); +} -void UTILITYDLL DebugLogTiming(LPSTR lpFormat, ...); -void UTILITYDLL DebugLogTiming(bool bTraceData, LPSTR lpFormat, ...); -void UTILITYDLL DebugLogTiming(LPCTSTR lpName, bool bTraceData, LPSTR lpFormat, ...); +template +void DebugLogTrace(bool bTraceData, fmt::format_string _fmt, Args&&... args) +{ + if (bTraceData) + { + mitechDebug.Log(_fmt, args...); + } +} + +template +void DebugLogTiming(fmt::format_string _fmt, Args&&... args) +{ + mitechDebugLogTiming.Log(_fmt, args...); +} + +template +void DebugLogTimingTrace(bool bTraceData, fmt::format_string _fmt, Args&&... args) +{ + if (bTraceData) + { + mitechDebugLogTiming.Log(_fmt, args...); + } +} + +template +void GUIEventLog(fmt::format_string _fmt, Args&&... args) +{ + mitechGuiEventLog.Log(_fmt, args...); +} + +void UTILITYDLL ShutdownLogging(); void UTILITYDLL StartDebugLog(); void UTILITYDLL StopDebugLog(); @@ -20,7 +72,5 @@ bool UTILITYDLL IsDebugLogStarted(); bool UTILITYDLL IsDebugLogTimingStarted(); // All GUI Activities Events Log -void UTILITYDLL GUIEventLog(LPSTR lpFormat, ...); - void UTILITYDLL StartGUIEventLog(); void UTILITYDLL StopGUIEventLog(); \ No newline at end of file diff --git a/utility/Include/LegacyDebugLog.h b/utility/Include/LegacyDebugLog.h new file mode 100644 index 0000000..be4435b --- /dev/null +++ b/utility/Include/LegacyDebugLog.h @@ -0,0 +1,20 @@ +#pragma once +#include "Logger.h" +#include "dbg.h" +class CLegacyDebugLog : public CLogger +{ +public: + explicit CLegacyDebugLog(const std::string& strName); + ~CLegacyDebugLog() final; + +private: + void InitLogger(); + + // Inherited via CLogger + void DoStart() override; + void DoFlush() override; + void DoLogging(const std::string& strMsg) override; + + // + CDebugPrintf m_logger{ 0 }; +}; diff --git a/utility/Include/LegacyDebugLogTiming.h b/utility/Include/LegacyDebugLogTiming.h new file mode 100644 index 0000000..1992f08 --- /dev/null +++ b/utility/Include/LegacyDebugLogTiming.h @@ -0,0 +1,19 @@ +#pragma once +#include "Logger.h" +#include "dbg.h" +class CLegacyDebugLogTiming : public CLogger +{ +public: + CLegacyDebugLogTiming(const std::string& strName); + ~CLegacyDebugLogTiming() final; + +private: + void InitLogger(); + + // Inherited via CLogger + void DoStart() override; + void DoFlush() override; + void DoLogging(const std::string& strMsg) override; + + CDebugPrintf m_logger{ 1 }; +}; diff --git a/utility/Include/LegacyGuiEventLog.h b/utility/Include/LegacyGuiEventLog.h new file mode 100644 index 0000000..d3585e5 --- /dev/null +++ b/utility/Include/LegacyGuiEventLog.h @@ -0,0 +1,20 @@ +#pragma once +#include "Logger.h" +#include "dbg.h" +class CLegacyGuiEventLog : public CLogger +{ +public: + CLegacyGuiEventLog(const std::string& strName); + ~CLegacyGuiEventLog() final; + + +private: + void InitLogger(); + + // Inherited via CLogger + void DoStart() override; + void DoFlush() override; + void DoLogging(const std::string& strMsg) override; + + CDebugPrintf m_logger{ 2 }; +}; diff --git a/utility/Include/Logger.h b/utility/Include/Logger.h new file mode 100644 index 0000000..5771824 --- /dev/null +++ b/utility/Include/Logger.h @@ -0,0 +1,54 @@ +#pragma once + +#include + +#include "fmt/format.h" +#include "fmt/args.h" + +#include "DllDefines.h" + +class UTILITYDLL CLogger +{ +public: + CLogger(const std::string& strName); + virtual ~CLogger(); + + void Start(); + void Stop(); + void SetEnable(bool bEnable) { m_bEnable = bEnable; } + void Log(const std::string& strMsg); + + template + void Log(fmt::format_string _fmt, Args&&... args) + { + try + { + std::vector buf; + + fmt::vformat_to(std::back_inserter(buf), _fmt, fmt::make_format_args(args...)); + + std::string log_msg(std::string_view(buf.data(), buf.size())); + Log(log_msg); + } + catch (...) + { + } + } + +protected: + bool IsEnable() const { return m_bEnable; } + std::string GetName() { return m_strName; } + +private: + virtual void DoStart() = 0; + virtual void DoFlush() = 0; + virtual void DoLogging(const std::string& strMsg) = 0; + + std::string m_strName; + bool m_bEnable{ false }; + bool m_bRotating{ true }; + int m_nFileSizeMB{ 1 }; + + // +}; + diff --git a/utility/Include/MitechDebugLog.h b/utility/Include/MitechDebugLog.h new file mode 100644 index 0000000..2b8bfbd --- /dev/null +++ b/utility/Include/MitechDebugLog.h @@ -0,0 +1,28 @@ +#pragma once +#include +#include + +#include "spdlog/spdlog.h" + +#include "Logger.h" + +#include "DllDefines.h" + +class UTILITYDLL CMitechDebugLog : public CLogger +{ +public: + explicit CMitechDebugLog(const std::string& strName); + ~CMitechDebugLog() final; + +private: + void InitLogger(); + + // Inherited via CLogger + void DoStart() override; + void DoFlush() override; + void DoLogging(const std::string& strMsg) override; + + std::shared_ptr m_logger; + + std::string m_strPathFilename{ R"(d:\machine\log\DebugLog.log)" }; +}; diff --git a/utility/Include/MitechDebugLogTiming.h b/utility/Include/MitechDebugLogTiming.h new file mode 100644 index 0000000..31a8be2 --- /dev/null +++ b/utility/Include/MitechDebugLogTiming.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +#include "spdlog/spdlog.h" + +#include "Logger.h" + +class CMitechDebugLogTiming : public CLogger +{ +public: + CMitechDebugLogTiming(const std::string& strName); + ~CMitechDebugLogTiming() final; + +private: + void InitLogger(); + + // Inherited via CLogger + void DoStart() override; + void DoFlush() override; + void DoLogging(const std::string& strMsg) override; + + std::shared_ptr m_logger; + + std::string m_strPathFilename{ R"(d:\machine\log\DebugLogTiming.log)" }; +}; diff --git a/utility/Include/MitechGuiEventLog.h b/utility/Include/MitechGuiEventLog.h new file mode 100644 index 0000000..9a3bac3 --- /dev/null +++ b/utility/Include/MitechGuiEventLog.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +#include "spdlog/spdlog.h" + +#include "Logger.h" + +class CMitechGuiEventLog : public CLogger +{ +public: + CMitechGuiEventLog(const std::string& strName); + ~CMitechGuiEventLog() final; + +private: + void InitLogger(); + + // Inherited via CLogger + void DoStart() override; + void DoFlush() override; + void DoLogging(const std::string& strMsg) override; + + std::shared_ptr m_logger; + std::string m_strPathFilename{ R"(d:\machine\log\GuiEventLog.log)" }; +}; diff --git a/utility/Include/TimingFormatterFlag.h b/utility/Include/TimingFormatterFlag.h new file mode 100644 index 0000000..53529e6 --- /dev/null +++ b/utility/Include/TimingFormatterFlag.h @@ -0,0 +1,28 @@ +#pragma once + +// third party library +#include "fmt/format.h" +#include "spdlog/pattern_formatter.h" + +// mitech library +#include "utility.h" + +class CTimingFormatterFlag : public spdlog::custom_flag_formatter +{ +public: + void format(const spdlog::details::log_msg&, const std::tm&, spdlog::memory_buf_t& dest) override + { + auto myTime = m_HighResCounter.GetCurrentTimeSpanInMsec(); + + std::string strTime = fmt::format("{:d}.{:03d}", (myTime / 1000), (myTime % 1000)); + dest.append(strTime.data(), strTime.data() + strTime.size()); + } + + std::unique_ptr clone() const override + { + return spdlog::details::make_unique(); + } + +private: + CHighResPerformanceCounter m_HighResCounter; +}; \ No newline at end of file diff --git a/utility/Include/dbg.h b/utility/Include/dbg.h index 5fa58cb..ed11e88 100644 --- a/utility/Include/dbg.h +++ b/utility/Include/dbg.h @@ -54,7 +54,7 @@ class CDebugPrintf public: bool LogStarted(); void StopLog(); - void StartLog(char* cFilename = NULL); + void StartLog(char* cFilename = nullptr); CDebugPrintf(int nDebugType = 0); virtual ~CDebugPrintf(); diff --git a/utility/lib/utility.lib b/utility/lib/utility.lib index acdb2ef..c7f722b 100644 Binary files a/utility/lib/utility.lib and b/utility/lib/utility.lib differ diff --git a/utility/lib/utilityD.lib b/utility/lib/utilityD.lib index bedd384..f8a68f3 100644 Binary files a/utility/lib/utilityD.lib and b/utility/lib/utilityD.lib differ