/[H7]/trunk/Client/ClientDlg.cpp
ViewVC logotype

Diff of /trunk/Client/ClientDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 31 by kevin, Wed Jan 31 13:12:55 2007 UTC revision 32 by kevin, Wed Jan 31 17:05:15 2007 UTC
# Line 17  UINT Status( LPVOID Param ); Line 17  UINT Status( LPVOID Param );
17  UINT Update( LPVOID Param );  UINT Update( LPVOID Param );
18  void Buffcheck(CString);  void Buffcheck(CString);
19  void Start();  void Start();
 void startthread();  
20  CButton m_led1;  CButton m_led1;
21  CButton m_led2;  CButton m_led2;
22  CButton m_led3;  CButton m_led3;
# Line 28  CEdit m_pot; Line 27  CEdit m_pot;
27    
28  // CAboutDlg dialog used for App About  // CAboutDlg dialog used for App About
29    
30    bool continueThread;
31    
32  class CAboutDlg : public CDialog  class CAboutDlg : public CDialog
33  {  {
34  public:  public:
# Line 87  BEGIN_MESSAGE_MAP(CClientDlg, CDialog) Line 88  BEGIN_MESSAGE_MAP(CClientDlg, CDialog)
88          ON_WM_QUERYDRAGICON()          ON_WM_QUERYDRAGICON()
89          //}}AFX_MSG_MAP          //}}AFX_MSG_MAP
90          ON_BN_CLICKED(IDC_IPPORT, OnBnClickedIpport)          ON_BN_CLICKED(IDC_IPPORT, OnBnClickedIpport)
         ON_BN_CLICKED(IDC_Connect, OnBnClickedConnect)  
91          ON_BN_CLICKED(IDC_LED1, OnBnClickedLed1)          ON_BN_CLICKED(IDC_LED1, OnBnClickedLed1)
92          ON_BN_CLICKED(IDC_LED2, OnBnClickedLed2)          ON_BN_CLICKED(IDC_LED2, OnBnClickedLed2)
93          ON_BN_CLICKED(IDC_LED3, OnBnClickedLed3)          ON_BN_CLICKED(IDC_LED3, OnBnClickedLed3)
94            ON_BN_CLICKED(IDOK, OnBnClickedOk)
95            ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
96  END_MESSAGE_MAP()  END_MESSAGE_MAP()
97    
98    
# Line 142  BOOL CClientDlg::OnInitDialog() Line 144  BOOL CClientDlg::OnInitDialog()
144          {          {
145                  res=reg.QueryStringValue("IP", chaip, &size);                  res=reg.QueryStringValue("IP", chaip, &size);
146          }          }
147    
148            
149          Ip = chaip;          Ip = chaip;
150          m_ip.SetWindowText(Ip);          m_ip.SetWindowText(Ip);
151          LONG res2=reg.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client",KEY_READ);          LONG res2=reg.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client",KEY_READ);
# Line 165  BOOL CClientDlg::OnInitDialog() Line 169  BOOL CClientDlg::OnInitDialog()
169                    
170          //connect til server          //connect til server
171          Start();          Start();
172            continueThread = true;
173            AfxBeginThread(Status,0,THREAD_PRIORITY_NORMAL,0,0,NULL);
174                    
175                                    
176          return TRUE;  // return TRUE  unless you set the focus to a control          return TRUE;  // return TRUE  unless you set the focus to a control
# Line 229  void ClientSocket::OnReceive( int nError Line 235  void ClientSocket::OnReceive( int nError
235          char buffer[4096];          char buffer[4096];
236          int size;          int size;
237                    
   
238          size = Receive(buffer,4095);          size = Receive(buffer,4095);
239          buffer[size] = 0;          buffer[size] = 0;
         MessageBox(0,buffer,0,MB_OK);  
240          buff = buffer;          buff = buffer;
241          Buffcheck(buff);          
242            OutputDebugString(buff + "\n");
243            
244            while (1) //homebrewed tokenizer
245            {
246                    int pos = buff.Find('|',0);
247                    if (pos != -1)
248                    {
249                            CString token = buff.Left(pos);
250                            buff = buff.Right( buff.GetLength() - pos -1);
251                            Buffcheck(token);
252                    }
253                    else
254                            break;
255            }
256            
257            //Buffcheck(buff);
258          //Close();          //Close();
259  }  }
260  void CClientDlg::OnBnClickedIpport()  void CClientDlg::OnBnClickedIpport()
# Line 278  void Start() Line 298  void Start()
298                  tmp.Format("%d", error);                  tmp.Format("%d", error);
299          }          }
300  }  }
 void CClientDlg::OnBnClickedConnect()  
 {        
         startthread();  
 }  
301  UINT Status( LPVOID Param )  UINT Status( LPVOID Param )
302  {  {
303          CString status;          while(continueThread)
304          status = "100";          {
305          sockClient.Send(status,status.GetLength(),NULL);                  CString status;
306          Sleep(atoi(Delay));                  int statusint = 100;
307          //startthread();                  status.Format("%d",statusint);
308                    sockClient.Send(status,status.GetLength(),NULL);
309                    Sleep(atoi(Delay));
310            }
311          return TRUE;          return TRUE;
312  }  }
 void startthread()  
 {  
         AfxBeginThread(Status,0,THREAD_PRIORITY_NORMAL,0,0,NULL);  
 }  
313  UINT Update( LPVOID param )  UINT Update( LPVOID param )
314  {  {
         //Updatevariable = "11";  
315          sockClient.Send(Updatevariable,Updatevariable.GetLength(),NULL);          sockClient.Send(Updatevariable,Updatevariable.GetLength(),NULL);
         //MessageBox(0,Updatevariable,0,MB_OK);  
316          return TRUE;          return TRUE;
317  }  }
318  void Buffcheck(CString)  void Buffcheck(CString data)
319  {  {
320          int intbuff, temp, pot;          int intbuff=0, temp, pot;
321          intbuff = atoi(buff);           // til standat case          intbuff = atoi(data);
322          temp = atoi(buff);                      // til temperatur case          
323          pot = atoi(buff);                       // til potmeter case          temp = intbuff;                 // til temperatur case
324            pot = intbuff;                  // til potmeter case
325          switch (intbuff)          switch (intbuff)
326          {          {
327                  case 110:               /*Led 1 Slukket*/                  case 110:               /*Led 1 Slukket*/
# Line 373  void Buffcheck(CString) Line 387  void Buffcheck(CString)
387                  CString strpot;                  CString strpot;
388                  pot = (pot-2000);                  pot = (pot-2000);
389                  strpot.Format("%d",pot);                  strpot.Format("%d",pot);
390                  m_temp.SetWindowText(strpot);                  m_pot.SetWindowText(strpot);
391          }          }
392    
393  }  }
# Line 406  void CClientDlg::OnBnClickedLed3() Line 420  void CClientDlg::OnBnClickedLed3()
420          Updatevariable.Format("%d",send);          Updatevariable.Format("%d",send);
421          AfxBeginThread(Update,0,THREAD_PRIORITY_NORMAL,0,0,NULL);          AfxBeginThread(Update,0,THREAD_PRIORITY_NORMAL,0,0,NULL);
422  }  }
423    
424    void CClientDlg::OnBnClickedOk()
425    {
426            sockClient.Close();
427            continueThread = false;
428            OnOK();
429    }
430    
431    void CClientDlg::OnBnClickedCancel()
432    {
433            sockClient.Close();
434            continueThread = false;
435            OnCancel();
436    }

Legend:
Removed from v.31  
changed lines
  Added in v.32

  ViewVC Help
Powered by ViewVC 1.1.20