17 IMPLEMENT_DYNAMIC(CCdtPingDlg, CDialog)
24 BEGIN_MESSAGE_MAP(CCdtPingDlg, CDialog)
26 ON_MESSAGE(
WM_EVENT( EVENT_CDT_PING_RECEIVED ), OnCDTPingReceived )
36 : CDialog( CCdtPingDlg::IDD, pParent ),
41 , mRepeatIterations( 1 )
42 , mRepeatFixed(
FALSE )
43 , mClearOnStart(
TRUE )
50 CCdtPingDlg::~CCdtPingDlg()
52 for(
int i=0; i<mResults.GetCount(); i++ )
63 void CCdtPingDlg::DoDataExchange(CDataExchange* pDX)
65 CDialog::DoDataExchange(pDX);
67 DDV_MinMaxUInt(pDX, mInterval, 100, 5000);
69 DDV_MinMaxUInt(pDX, mPayloadSize, 0, 246);
71 DDV_MinMaxUInt(pDX, mRepeatIterations, 1, 1000);
81 BOOL CCdtPingDlg::OnInitDialog()
83 CDialog::OnInitDialog();
85 mResultsView.InsertColumn( 0, _T(
"Sent On" ), LVCFMT_LEFT, 120);
86 mResultsView.InsertColumn( 1, _T(
"Responded On" ), LVCFMT_RIGHT, 120 );
87 mResultsView.InsertColumn( 2, _T(
"Elapsed Time" ), LVCFMT_RIGHT, 100 );
88 mResultsView.InsertColumn( 3, _T(
"Match" ), LVCFMT_CENTER, 50 );
94 OnBnClickedClearResults();
102 void CCdtPingDlg::OnBnClickedClearResults()
104 for(
int i=0; i<mResults.GetCount(); i++ )
108 mResults.RemoveAll();
110 mResultsView.DeleteAllItems();
119 void CCdtPingDlg::OnBnClickedToggleProcess()
129 OnBnClickedClearResults();
132 mTimer = SetTimer( PING_TIMER_ID, mInterval, NULL );
133 OnTimer( PING_TIMER_ID );
141 setStarted( mTimer != 0 );
147 void CCdtPingDlg::setStarted( BOOL started )
149 GetDlgItem(
IDC_TOGGLE_PROCESS )->SetWindowText( started ? _T(
"Stop" ) : _T(
"Start" ) );
163 void CCdtPingDlg::OnTimer
172 if( !mRepeatFixed || mIteration < mRepeatIterations )
174 COleDateTime now = COleDateTime::GetCurrentTime();
175 CdtPingTestPacket * packet =
new CdtPingTestPacket( mPayloadSize );
176 mResults.Add( packet );
177 mCom.txCdt( CDT_PING_REQUEST, packet->GetPayload(), packet->GetPayloadSize() );
179 mResultsView.InsertItem( mResultsView.GetItemCount(), now.Format( _T(
"%Y-%m-%d %H.%M.%S" ) ) );
198 LRESULT CCdtPingDlg::OnCDTPingReceived( WPARAM wParam, LPARAM lParam)
200 DWORD tickCount = GetTickCount();
201 COleDateTime now = COleDateTime::GetCurrentTime();
203 uint8 const * cdtPayload = (
uint8 const *) lParam;
206 if( cdtPayloadSize <
sizeof( DWORD ) )
211 memcpy( &
id, cdtPayload,
sizeof( DWORD ) );
212 for(
int i=0; i<mResults.GetCount(); i++ )
214 if( mResults[i]->GetId() == id )
216 mResults[i]->CompareResponse( tickCount, cdtPayloadSize, cdtPayload );
217 mResultsView.SetItemText( i, 1, now.Format( _T(
"%Y-%m-%d %H.%M.%S" ) ) );
219 elapsed.Format( _T(
"%d" ), mResults[i]->GetElapsedTimeMillis() );
220 mResultsView.SetItemText( i, 2, elapsed );
221 mResultsView.SetItemText( i, 3, mResults[i]->IsResponseMatched() ? _T(
"yes" ) : _T(
"no" ) );
226 double totalElapsed = 0;
227 int totalDelivered = 0;
228 int totalMismatched = 0;
229 for(
int i=0; i<mResults.GetCount(); i++ )
231 if( mResults[i]->IsResponded() )
234 totalElapsed += mResults[i]->GetElapsedTimeMillis();
235 if( !mResults[i]->IsResponseMatched() )
242 delivered.Format( _T(
"%d/%d" ), totalDelivered, mResults.GetCount() );
244 if( totalDelivered > 0 )
247 avgElapsed.Format( _T(
"%.0f" ), totalElapsed / (
double) totalDelivered );
251 mismatched.Format( _T(
"%d" ), totalMismatched );
256 static COleDateTime epoch(1970,1,1,0,0,0);
261 CdtPingTestPacket::CdtPingTestPacket( UINT payloadSize ) :
262 mPayloadSize( min( sizeof( mPayload ) - sizeof( DWORD ), payloadSize ) ),
264 mResponseMatched(
FALSE )
266 mId = GetTickCount();
267 memcpy( mPayload, &mId,
sizeof( DWORD ) );
268 for(
int i=0; i<mPayloadSize; i++ )
270 mPayload[i +
sizeof( DWORD )] = rand() % 256;
272 mPayloadSize +=
sizeof( DWORD );
275 CdtPingTestPacket::~CdtPingTestPacket() {}
280 void CdtPingTestPacket::CompareResponse( DWORD respondedOn,
const uint8 rightSize,
const uint8 * right )
282 mRespondedOn = respondedOn;
283 if( rightSize == mPayloadSize )
285 for(
int i=0; i<mPayloadSize; i++ )
287 if( mPayload[i] != right[i] )
292 mResponseMatched =
TRUE;
299 int CdtPingTestPacket::GetElapsedTimeMillis()
301 if( mRespondedOn != 0 )
303 return mRespondedOn - mId;
#define IDC_REPEAT_ITERATIONS_SPINNER
#define IDC_REPEAT_ITERATIONS
signed short int sint16
16-bit signed integer
#define IDC_PAYLOAD_SIZE_SPINNER
#define IDC_TOTAL_DELIVERED_STATIC
Serial communication controller for Garmin and FMI packets.
#define IDC_INTERVAL_SPINNER
unsigned char uint8
8-bit unsigned integer
#define IDC_CLEAR_RESULTS
#define IDC_AVG_ELAPSED_TIME_STATIC
#define IDC_TOTAL_MISMATCHED_STATIC
#define IDC_TOGGLE_PROCESS
#define WM_EVENT(_event)
Translation from an application event to the corresponding Windows message.
TimerIdType
Timer ID values used in the application.
#define IDC_CLEAR_ON_START
#define IDC_REPEAT_INDEFINITELY