| SourceCode/Bond/SGMeasurement/Logger.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| SourceCode/Bond/SGMeasurement/Logger.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| SourceCode/Bond/SGMeasurement/SGMeasurement.vcxproj | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| SourceCode/Bond/SGMeasurement/SGMeasurement.vcxproj.filters | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| SourceCode/Bond/SGMeasurement/SGMeasurementDlg.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
SourceCode/Bond/SGMeasurement/Logger.cpp
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,79 @@ #include "pch.h" #include "Logger.h" CLogger& CLogger::Instance() { static CLogger instance; return instance; } CLogger::CLogger() { OpenLogFile(); } CLogger::~CLogger() { CloseLogFile(); } void CLogger::OpenLogFile() { CSingleLock lock(&m_csLogLock, TRUE); CTime now = CTime::GetCurrentTime(); CString strLogDir = _T("Log"); if (!PathFileExists(strLogDir)) { CreateDirectory(strLogDir, NULL); } CString strNewPath; strNewPath.Format(_T("%s\\SG_%04d%02d%02d.log"), strLogDir, now.GetYear(), now.GetMonth(), now.GetDay()); if (m_strCurrentLogPath.CompareNoCase(strNewPath) != 0 || m_logFile.m_pStream == nullptr) { if (m_logFile.m_pStream) { m_logFile.Flush(); m_logFile.Close(); } if (m_logFile.Open(strNewPath, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite | CFile::typeBinary)) { if (m_logFile.GetLength() == 0) { WCHAR bom = 0xFEFF; m_logFile.Write(&bom, sizeof(WCHAR)); } m_logFile.SeekToEnd(); m_strCurrentLogPath = strNewPath; } } } void CLogger::WriteLine(CString str) { CSingleLock lock(&m_csLogLock, TRUE); OpenLogFile(); if (m_logFile.m_pStream) { CTime now = CTime::GetCurrentTime(); CString strTime; strTime.Format(_T("[%02d:%02d:%02d]"), now.GetHour(), now.GetMinute(), now.GetSecond()); CString strLine = strTime + str + _T("\r\n"); m_logFile.Write((LPCTSTR)strLine, strLine.GetLength() * sizeof(WCHAR)); } } void CLogger::CloseLogFile() { CSingleLock lock(&m_csLogLock, TRUE); if (m_logFile.m_pStream) { m_logFile.Flush(); m_logFile.Close(); m_strCurrentLogPath.Empty(); } } SourceCode/Bond/SGMeasurement/Logger.h
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,28 @@ #pragma once #include <afx.h> class CLogger { public: static CLogger& Instance(); // è·ååä¾ void WriteLine(CString str); // åä¸è¡æ¥å¿ void CloseLogFile(); // å ³éæ¥å¿æä»¶ private: CLogger(); ~CLogger(); void OpenLogFile(); // å 鍿弿件 CCriticalSection m_csLogLock; CString m_strCurrentLogPath; CStdioFile m_logFile; }; #define LOG_LINE(x) CLogger::Instance().WriteLine(x) #define LOG_LINEF(fmt, ...) \ do { \ CString __log__; \ __log__.Format(fmt, __VA_ARGS__); \ CLogger::Instance().WriteLine(__log__); \ } while (0) SourceCode/Bond/SGMeasurement/SGMeasurement.vcxproj
@@ -196,6 +196,7 @@ </ItemDefinitionGroup> <ItemGroup> <ClInclude Include="framework.h" /> <ClInclude Include="Logger.h" /> <ClInclude Include="pch.h" /> <ClInclude Include="Resource.h" /> <ClInclude Include="SGMeasurement.h" /> @@ -203,6 +204,7 @@ <ClInclude Include="targetver.h" /> </ItemGroup> <ItemGroup> <ClCompile Include="Logger.cpp" /> <ClCompile Include="pch.cpp"> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> SourceCode/Bond/SGMeasurement/SGMeasurement.vcxproj.filters
@@ -33,6 +33,9 @@ <ClInclude Include="pch.h"> <Filter>头æä»¶</Filter> </ClInclude> <ClInclude Include="Logger.h"> <Filter>头æä»¶</Filter> </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="SGMeasurement.cpp"> @@ -44,6 +47,9 @@ <ClCompile Include="pch.cpp"> <Filter>æºæä»¶</Filter> </ClCompile> <ClCompile Include="Logger.cpp"> <Filter>æºæä»¶</Filter> </ClCompile> </ItemGroup> <ItemGroup> <ResourceCompile Include="SGMeasurement.rc"> SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
@@ -8,6 +8,7 @@ #include "SGMeasurementDlg.h" #include "afxdialogex.h" #include "SGIF.h" #include "Logger.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -175,7 +176,7 @@ m_editLog.ReplaceSel(_T("")); // å é¤ } void CSGMeasurementDlg::AppendLogLineRichStyled(const CString& content, COLORREF color /*= RGB(0, 0, 0)*/) void CSGMeasurementDlg::AppendLogLineRichStyled(const CString& strContent, COLORREF color /*= RGB(0, 0, 0)*/) { if (!::IsWindow(GetSafeHwnd()) || !::IsWindow(m_editLog.GetSafeHwnd())) { return; @@ -197,16 +198,41 @@ m_editLog.SetSelectionCharFormat(cfTime); m_editLog.ReplaceSel(strTimestamp); // çææ¥å¿çº§å«æ ç¾ CString strLevel; if (color == LOG_COLOR_WARNING) { strLevel = _T("[è¦å]"); } else if (color == LOG_COLOR_ERROR) { strLevel = _T("[é误]"); } else if (color == LOG_COLOR_NORMAL) { strLevel = _T("[ä¿¡æ¯]"); } else if (color == LOG_COLOR_SUCCESS) { strLevel = _T("[æå]"); } else { strLevel = _T("[æªç¥]"); } // æå ¥æ¥å¿æ£æï¼ä¼ å ¥é¢è²ï¼ CHARFORMAT2 cfMsg = {}; cfMsg.cbSize = sizeof(cfMsg); cfMsg.dwMask = CFM_COLOR; cfMsg.crTextColor = color; m_editLog.SetSelectionCharFormat(cfMsg); m_editLog.ReplaceSel(content + _T("\r\n")); m_editLog.ReplaceSel(strLevel + strContent + _T("\r\n")); // éå¶æå¤§è¡æ° TrimRichEditLineLimit(100); // æ¼æ¥å®æ´æ¥å¿è¡ CString strFullLogLine; strFullLogLine.Format(_T("%s %s"), strLevel, strContent); // åå ¥æ¥å¿æä»¶ LOG_LINE(strFullLogLine); } void CSGMeasurementDlg::HighlightAllMatches(const CString& strSearch, COLORREF clrHighlight/* = RGB(255, 165, 0)*/) @@ -614,6 +640,8 @@ return -1.0f; } clock_t startClock = clock(); // è®°å½å¼å§æ¶é´ std::vector<float> vecBuffer(m_nSavePointCount, 0.0f); int nReceived = 0; @@ -648,6 +676,13 @@ CalcGlassOffset(vecGlass1, vecGlass2, fAvg1, fAvg2, fOffset); } clock_t endClock = clock(); // è®°å½ç»ææ¶é´ double dElapsedMs = 1000.0 * (endClock - startClock) / CLOCKS_PER_SEC; CString strElapsed; strElapsed.Format(_T("AnalyzeStoredData æ§è¡èæ¶ï¼%.1f ms"), dElapsedMs); AppendLogLineRichStyled(strElapsed, LOG_COLOR_SUCCESS); return fOffset; } SourceCode/Bond/SGMeasurement/SGMeasurementDlg.h
@@ -49,6 +49,13 @@ DECLARE_MESSAGE_MAP() private: /** * @brief éåºç¨åºæ¶çæ¸ çæä½ã * * æ¤å½æ°å¨ç¨åºéåºå被è°ç¨ï¼ç¨äºæ§è¡å¿ è¦çèµæºéæ¾ä¸ç¶ææ¢å¤ï¼ * å æ¬æå¼è®¾å¤è¿æ¥ãç§»é¤æç徿 çã * æç»éæ¯ä¸»çªå£å¹¶éåºåºç¨ã */ void ExitApplication(); /** @@ -85,7 +92,7 @@ * @param content æ¥å¿å 容ã * @param color åä½é¢è²ï¼é»è®¤ä¸ºé»è²ã */ void AppendLogLineRichStyled(const CString& content, COLORREF color = RGB(0, 0, 0)); void AppendLogLineRichStyled(const CString& strContent, COLORREF color = RGB(0, 0, 0)); /** * @brief é«äº®æ¥å¿ä¸ææå¹é æå®å符串çé¨åã @@ -178,10 +185,33 @@ const std::vector<float>& vecGlass2, float& fAvg1, float& fAvg2, float& fOffset); /** * @brief åå§å设å¤ç«¯çæ°æ®åå¨ç¼å²åºã * * è°ç¨åºå±æ¥å£æ¸ é¤å½ååå¨åºå 容ï¼ä¸ºæ°ä¸è½®çæ°æ®ééååå¤ã * å¿ é¡»å¨è®¾å¤è¿æ¥æå䏿ªè¿è¡æ°æ®å卿¶è°ç¨ã * * @return true 表示åå§åæåï¼false 表示失败ï¼å¯è½æ¯è®¾å¤æªè¿æ¥æè°ç¨æ¥å£é误ï¼ã */ bool InitDataStorage(); /** * @brief å¯å¨è®¾å¤ç«¯æ°æ®ééååå¨ã * * è°ç¨æ¤å½æ°å设å¤å¼å§ééå¹¶ç¼åæ°æ®ã * é常é åè§¦åæ¨¡å¼è¿è¡ééã * * @return true 表示å¯å¨æåï¼false 表示å¯å¨å¤±è´¥ã */ bool StartDataStorage(); /** * @brief åæ¢æ°æ®ééå¹¶ä»è®¾å¤è·åå½åå卿°æ®ã * * è°ç¨å设å¤åæ¢ééï¼å¹¶å°è¯è¯»åæå®ç«¯å£çæ°æ®ï¼ä¾åç»åæå¤çã * * @return true è¡¨ç¤ºåæ¢å¹¶è¯»åæ°æ®æåï¼false 表示失败ï¼å¦è®¾å¤æªååºææ°æ®æ æï¼ã */ bool StopDataStorage(); /**