--- trunk/Client/ClientDlg.cpp 2007/01/31 13:19:36 31 +++ trunk/Client/ClientDlg.cpp 2007/01/31 17:05:15 32 @@ -17,7 +17,6 @@ UINT Update( LPVOID Param ); void Buffcheck(CString); void Start(); -void startthread(); CButton m_led1; CButton m_led2; CButton m_led3; @@ -28,6 +27,8 @@ // CAboutDlg dialog used for App About +bool continueThread; + class CAboutDlg : public CDialog { public: @@ -87,10 +88,11 @@ ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_IPPORT, OnBnClickedIpport) - ON_BN_CLICKED(IDC_Connect, OnBnClickedConnect) ON_BN_CLICKED(IDC_LED1, OnBnClickedLed1) ON_BN_CLICKED(IDC_LED2, OnBnClickedLed2) ON_BN_CLICKED(IDC_LED3, OnBnClickedLed3) + ON_BN_CLICKED(IDOK, OnBnClickedOk) + ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel) END_MESSAGE_MAP() @@ -142,6 +144,8 @@ { res=reg.QueryStringValue("IP", chaip, &size); } + + Ip = chaip; m_ip.SetWindowText(Ip); LONG res2=reg.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client",KEY_READ); @@ -165,6 +169,8 @@ //connect til server Start(); + continueThread = true; + AfxBeginThread(Status,0,THREAD_PRIORITY_NORMAL,0,0,NULL); return TRUE; // return TRUE unless you set the focus to a control @@ -229,12 +235,26 @@ char buffer[4096]; int size; - size = Receive(buffer,4095); buffer[size] = 0; - MessageBox(0,buffer,0,MB_OK); buff = buffer; - Buffcheck(buff); + + OutputDebugString(buff + "\n"); + + while (1) //homebrewed tokenizer + { + int pos = buff.Find('|',0); + if (pos != -1) + { + CString token = buff.Left(pos); + buff = buff.Right( buff.GetLength() - pos -1); + Buffcheck(token); + } + else + break; + } + + //Buffcheck(buff); //Close(); } void CClientDlg::OnBnClickedIpport() @@ -278,36 +298,30 @@ tmp.Format("%d", error); } } -void CClientDlg::OnBnClickedConnect() -{ - startthread(); -} UINT Status( LPVOID Param ) { - CString status; - status = "100"; - sockClient.Send(status,status.GetLength(),NULL); - Sleep(atoi(Delay)); - //startthread(); + while(continueThread) + { + CString status; + int statusint = 100; + status.Format("%d",statusint); + sockClient.Send(status,status.GetLength(),NULL); + Sleep(atoi(Delay)); + } return TRUE; } -void startthread() -{ - AfxBeginThread(Status,0,THREAD_PRIORITY_NORMAL,0,0,NULL); -} UINT Update( LPVOID param ) { - //Updatevariable = "11"; sockClient.Send(Updatevariable,Updatevariable.GetLength(),NULL); - //MessageBox(0,Updatevariable,0,MB_OK); return TRUE; } -void Buffcheck(CString) +void Buffcheck(CString data) { - int intbuff, temp, pot; - intbuff = atoi(buff); // til standat case - temp = atoi(buff); // til temperatur case - pot = atoi(buff); // til potmeter case + int intbuff=0, temp, pot; + intbuff = atoi(data); + + temp = intbuff; // til temperatur case + pot = intbuff; // til potmeter case switch (intbuff) { case 110: /*Led 1 Slukket*/ @@ -373,7 +387,7 @@ CString strpot; pot = (pot-2000); strpot.Format("%d",pot); - m_temp.SetWindowText(strpot); + m_pot.SetWindowText(strpot); } } @@ -406,3 +420,17 @@ Updatevariable.Format("%d",send); AfxBeginThread(Update,0,THREAD_PRIORITY_NORMAL,0,0,NULL); } + +void CClientDlg::OnBnClickedOk() +{ + sockClient.Close(); + continueThread = false; + OnOK(); +} + +void CClientDlg::OnBnClickedCancel() +{ + sockClient.Close(); + continueThread = false; + OnCancel(); +}