16 #define EDGE_SPACING 7 23 ON_BN_CLICKED( IDOK, OnBnClickedOk )
33 #if( FMI_SUPPORT_A602 ) 46 CLogViewerDlg::CLogViewerDlg
52 : CDialog(
IDD_LOG, aParentWnd )
53 , mSelectedPacketText( _T("") )
54 , mSearchDirection( SEARCH_DOWN )
55 , mLogParser( aLogParser )
57 mOpenOtherLog = aOpenOtherLog;
73 CDataExchange * aDataExchange
76 CDialog::DoDataExchange( aDataExchange );
79 DDX_Control( aDataExchange, IDC_LOG_LST_PACKETS, mPacketListBox );
81 DDX_Control( aDataExchange, IDOK, mCloseButton );
82 DDX_Control( aDataExchange, IDC_LOG_BTN_VIEW_OTHER, mViewOtherButton );
83 DDX_Control( aDataExchange, IDC_LOG_BTN_VIEW_CURRENT, mViewCurrentButton );
88 DDX_Control( aDataExchange, IDC_LOG_BTN_SAVE_AS, mSaveButton );
89 DDX_Control( aDataExchange, IDC_LOG_BTN_CLEAR, mClearButton );
90 DDX_Control( aDataExchange, IDC_LOG_BTN_FIND_NEXT, mFindNextButton );
91 DDX_Control( aDataExchange,
IDC_LOG_RDO_UP, mSearchUpRadioButton );
110 CDialog::OnInitDialog();
114 mOpenOtherLog =
FALSE;
115 OnBnClickedViewOther();
124 SetWindowPos( NULL, 500, 350, 0, 0, SWP_NOZORDER );
150 scrolledTo = mPacketListBox.GetScrollPos( SB_VERT );
151 maxScroll = mPacketListBox.GetScrollLimit( SB_VERT );
153 if( scrolledTo == maxScroll )
158 if( updateView() && scroll )
160 mPacketListBox.SetTopIndex( mPacketListBox.GetCount() - 1 );
173 mLogParser->readLog();
174 while( mPacketListBox.GetCount() < mLogParser->getLineCount() )
176 mPacketListBox.AddString( mLogParser->getPacketTitle( mPacketListBox.GetCount() ) );
212 CDialog::PostNcDestroy();
239 CDialog::OnSize( aType, aClientWidth, aClientHeight );
243 if( mPacketListTitleLabel.GetSafeHwnd() != NULL )
248 CRect searchGroupRect;
249 mSearchGroupBox.GetClientRect( &searchGroupRect );
251 searchGroupRect.MoveToY( aClientHeight - searchGroupRect.Height() -
EDGE_SPACING );
252 mSearchGroupBox.MoveWindow( searchGroupRect );
256 mSearchUpRadioButton.GetClientRect( &upRadioRect );
257 upRadioRect.MoveToX( searchGroupRect.CenterPoint().x - upRadioRect.Width() - 2 );
258 upRadioRect.MoveToY( searchGroupRect.top + 10 );
259 mSearchUpRadioButton.MoveWindow( upRadioRect );
262 mSearchDownRadioButton.GetClientRect( &downRadioRect );
263 downRadioRect.MoveToX( searchGroupRect.CenterPoint().x + 2 );
264 downRadioRect.MoveToY( upRadioRect.top );
265 mSearchDownRadioButton.MoveWindow( downRadioRect );
269 mSearchTextControl.GetWindowRect( &findEditRect );
270 findEditRect.MoveToX( searchGroupRect.left +
EDGE_SPACING );
271 findEditRect.MoveToY( upRadioRect.bottom + 2 );
272 mSearchTextControl.MoveWindow( findEditRect );
276 mFindNextButton.GetWindowRect( &findNextRect );
277 findNextRect.MoveToXY( findEditRect.right +
EDGE_SPACING, findEditRect.top );
278 mFindNextButton.MoveWindow( findNextRect );
282 CRect packetListTitleRect;
283 mPacketListTitleLabel.GetWindowRect( &packetListTitleRect );
285 mPacketListTitleLabel.MoveWindow( packetListTitleRect );
287 CRect packetListRect;
288 mPacketListBox.GetWindowRect( &packetListRect );
289 packetListRect.MoveToXY(
EDGE_SPACING, packetListTitleRect.bottom + 2 );
290 packetListRect.bottom = searchGroupRect.top - 15;
291 mPacketListBox.MoveWindow( packetListRect );
295 CRect logNameTitleRect;
296 mLogNameTitleLabel.GetWindowRect( &logNameTitleRect );
297 logNameTitleRect.MoveToXY
299 packetListRect.right + 15,
300 packetListRect.bottom - logNameTitleRect.Height()
302 mLogNameTitleLabel.MoveWindow( logNameTitleRect );
305 mLogNameControl.GetWindowRect( &logNameRect );
306 logNameRect.MoveToXY( logNameTitleRect.right + 4, logNameTitleRect.top );
308 mLogNameControl.MoveWindow( logNameRect );
313 CRect currentPacketTitleRect;
314 mCurrentPacketTitleLabel.GetWindowRect( ¤tPacketTitleRect );
315 currentPacketTitleRect.MoveToXY( packetListRect.right + 15, EDGE_SPACING );
316 mCurrentPacketTitleLabel.MoveWindow( currentPacketTitleRect );
318 CRect currentPacketRect;
319 mCurrentPacketControl.GetWindowRect( ¤tPacketRect );
320 currentPacketRect.MoveToXY( currentPacketTitleRect.left, packetListRect.top );
322 currentPacketRect.bottom = logNameRect.top -
EDGE_SPACING;
323 mCurrentPacketControl.MoveWindow( currentPacketRect );
325 mLogParser->setRenderWidth( currentPacketRect.Width() );
330 CRect buttonGroupRect;
331 buttonGroupRect.SetRect( currentPacketRect.left, searchGroupRect.top, aClientWidth - EDGE_SPACING, aClientHeight - EDGE_SPACING );
334 mCloseButton.GetWindowRect( &buttonRect );
335 int buttonSpacing = ( buttonGroupRect.Width() - 4 * buttonRect.Width() ) / 4;
339 buttonGroupRect.CenterPoint().x - 3 * buttonRect.Width() / 2 - buttonSpacing,
342 mResendButton.MoveWindow( buttonRect );
346 buttonGroupRect.CenterPoint().x - buttonRect.Width() / 2,
349 mClearButton.MoveWindow( buttonRect );
353 buttonGroupRect.CenterPoint().x + buttonRect.Width() / 2 + buttonSpacing,
356 mSaveButton.MoveWindow( buttonRect );
360 buttonGroupRect.CenterPoint().x - 3 * buttonRect.Width() / 2 - buttonSpacing,
361 buttonGroupRect.bottom - buttonRect.Height()
363 mViewOtherButton.MoveWindow( buttonRect );
367 buttonGroupRect.CenterPoint().x - buttonRect.Width() / 2,
368 buttonGroupRect.bottom - buttonRect.Height()
370 mViewCurrentButton.MoveWindow( buttonRect );
374 buttonGroupRect.CenterPoint().x + buttonRect.Width() / 2 + buttonSpacing,
375 buttonGroupRect.bottom - buttonRect.Height()
377 mCloseButton.MoveWindow( buttonRect );
381 this->RedrawWindow();
394 MINMAXINFO * aMinMaxInfo
397 aMinMaxInfo->ptMinTrackSize.x = 600;
398 aMinMaxInfo->ptMinTrackSize.y = 400;
407 int selectedIndex = mPacketListBox.GetCurSel();
408 mLogParser->resendPacket( selectedIndex );
421 int selectedIndex = mPacketListBox.GetCurSel();
422 if( selectedIndex >= 0 && selectedIndex < mPacketListBox.GetCount() )
424 mSelectedPacketText = mLogParser->getPacketDetail( selectedIndex );
427 mResendButton.EnableWindow(
TRUE );
441 TCHAR workingDirectory[200];
447 DWORD returnValue = GetCurrentDirectory( 200, workingDirectory );
448 if( returnValue == 0 || returnValue > 200 )
450 MessageBox( _T(
"Unable to get current directory"), _T(
"Severe Error") );
459 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
460 _T(
"Log Files (*.log)|*.log||")
462 if( dlg.DoModal() == IDOK )
464 mLogParser->init( dlg.GetPathName() );
469 SetCurrentDirectory( workingDirectory );
481 mPacketListBox.ResetContent();
482 mPacketListBox.SetTopIndex( mPacketListBox.GetCount() - 1 );
484 mSelectedPacketText = _T(
"");
487 mLogNameText.Format( _T(
" Current Execution's Packet Log") );
488 mLogNameControl.SetWindowText( mLogNameText );
489 mClearButton.EnableWindow(
TRUE );
493 mLogNameText.Format( _T(
" %s"), mLogParser->getFilename() );
494 mLogNameControl.SetWindowText( mLogNameText );
495 mClearButton.EnableWindow(
FALSE );
498 mResendButton.EnableWindow(
FALSE );
540 int filenameLength = WideCharToMultiByte( CP_ACP, 0, mLogParser->getFilename(), -1, NULL, 0, NULL, NULL );
541 char *filenameAnsi =
new char[filenameLength];
542 WideCharToMultiByte( CP_ACP, 0, mLogParser->getFilename(), -1, filenameAnsi, filenameLength, NULL, NULL );
543 ifstream logFile( filenameAnsi, ios_base::in );
549 TCHAR workingDirectory[200];
556 DWORD returnValue = GetCurrentDirectory( 200, workingDirectory );
557 if( returnValue == 0 || returnValue > 200 )
559 MessageBox( _T(
"Unable to get current directory"), _T(
"Severe Error") );
569 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
570 _T(
"Log Files (*.log)|*.log||")
573 if( dlg.DoModal() == IDOK && dlg.GetFileName() != mLogParser->getFilename() )
577 int filenameLength = WideCharToMultiByte( CP_ACP, 0, dlg.GetPathName(), -1, NULL, 0, NULL, NULL );
578 char *filename =
new char[filenameLength];
579 WideCharToMultiByte( CP_ACP, 0, dlg.GetPathName().GetBuffer(), -1, filename, filenameLength, NULL, NULL );
580 ofstream destinationFile( filename, ios_base::out );
582 if( destinationFile.good() )
585 while( !logFile.eof() )
587 getline( logFile, line );
588 destinationFile << line << endl;
591 destinationFile.close();
593 SetCurrentDirectory( workingDirectory );
608 if( mPacketListBox.GetCount() == 0 )
613 int selectedIndex = mPacketListBox.GetCurSel();
614 if( selectedIndex < 0 )
619 CString listItemText;
620 CString searchText = mSearchText;
622 searchText.MakeLower();
623 if( searchText != _T(
"") )
625 mPacketListBox.setSearchString( searchText );
627 switch( mSearchDirection )
631 for(nextIndex = selectedIndex - 1; nextIndex != selectedIndex; nextIndex-- )
635 nextIndex = mPacketListBox.GetCount() - 1;
637 mPacketListBox.GetText( nextIndex, listItemText );
638 listItemText.MakeLower();
639 if( listItemText.Find( searchText, 0 ) != -1 )
641 mPacketListBox.SetCurSel( nextIndex );
650 for( nextIndex = selectedIndex + 1; nextIndex != selectedIndex; nextIndex++ )
652 if( nextIndex >= mPacketListBox.GetCount() )
655 if (nextIndex == selectedIndex )
658 mPacketListBox.GetText( nextIndex, listItemText );
659 listItemText.MakeLower();
660 if( listItemText.Find( searchText, 0 ) != -1 )
662 mPacketListBox.SetCurSel( nextIndex );
672 if( nextIndex == selectedIndex )
674 mPacketListBox.GetText( selectedIndex, listItemText );
675 listItemText.MakeLower();
677 if( listItemText.Find( searchText, 0 ) != -1 )
679 error.Format( _T(
"No more occurrences of '%s' were found"), mSearchText );
683 error.Format( _T(
"'%s' was not found "), mSearchText );
685 MessageBox( error, _T(
"End of Search") );
690 mPacketListBox.setSearchString( _T(
"") );
691 MessageBox( _T(
"Search box is empty"), _T(
"Unable to search") );
693 mPacketListBox.RedrawWindow( 0, 0, RDW_FRAME|RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE );
afx_msg void OnBnClickedFindNext()
Click handler for the Find Next button.
afx_msg void OnBnClickedViewOther()
Click handler for the View Other button.
#define IDC_LOG_BTN_FIND_NEXT
void resetView()
Reset the log view.
Abstract base class for log item parsers.
static void clearLog()
Empties the packet log.
afx_msg void OnBnClickedOk()
Click handler for the OK button; destroys the window.
static const char * LOG_FILE
The log file that this Logger writes to.
afx_msg LPARAM OnPacketLogged(WPARAM, LPARAM)
Handles the Packet Logged event from Com; updates the packet list.
Modeless log viewer dialog.
void UpdateLogDisplay()
Reads the log file and updates the packet list. If a packet was selected, keeps the packet selected a...
#define IDC_LOG_EDIT_SEARCH_TEXT
#define IDC_LOG_LBL_PACKETS
#define IDC_LOG_TXT_SELECTED_PACKET
#define IDC_LOG_BTN_SAVE_AS
virtual ~CLogViewerDlg()
Destructor.
#define IDC_LOG_GRP_SEARCH
static SerialPort * getInstance()
Get the one and only serial port object.
afx_msg void OnBnClickedViewCurrent()
Click handler for the View Current button.
#define IDC_LOG_TXT_LOG_NAME
afx_msg void OnCancel()
Handler for the Cancel action; destroys the window.
void PostNcDestroy()
Perform final cleanup on the log viewer.
#define IDC_LOG_LST_PACKETS
afx_msg void OnLbnSelchangeLog()
Selection Changed handler for the packet list.
BOOL updateView()
Update the log view.
#define IDC_LOG_LBL_SELECTED_PACKET
afx_msg void OnGetMinMaxInfo(MINMAXINFO *aMinMaxInfo)
Called on every resize to get the resize bounds.
afx_msg void OnBnClickedClearLog()
Click handler for the Clear Log button.
virtual void DoDataExchange(CDataExchange *aDataExchange)
Perform dialog data exchange and validation.
#define IDC_LOG_BTN_VIEW_CURRENT
#define IDC_LOG_BTN_CLEAR
void resendPacket()
Retransmit the selected packet for debugging purposes.
#define IDC_LOG_BTN_VIEW_OTHER
#define WM_EVENT(_event)
Translation from an application event to the corresponding Windows message.
#define IDC_LOG_BTN_RESEND
afx_msg void OnSize(UINT aType, int aClientWidth, int aClientHeight)
Called after the dialog is resized; repositions the contents of the display.
afx_msg void OnBnClickedSaveAs()
Click handler for the Save As button.
BOOL OnInitDialog()
Initialize the dialog.
#define IDC_LOG_LBL_LOG_NAME
static void post(EventId aEventId, uint32 aEventData=0, void *aEventDataPtr=NULL, BOOL handleNow=FALSE)
Posts a message to all windows that have registered to get events.