/[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 29 by kevin, Tue Jan 30 13:44:42 2007 UTC revision 30 by kevin, Wed Jan 31 13:12:55 2007 UTC
# Line 10  Line 10 
10  #define new DEBUG_NEW  #define new DEBUG_NEW
11  #endif  #endif
12    
13            //Globale variabler osv. :-S    
14  CString Ip, Delay;  CString Ip, Delay, Updatevariable;
15  unsigned long Port;  unsigned long Port;
16  UINT Status( LPVOID Param );  UINT Status( LPVOID Param );
17    UINT Update( LPVOID Param );
18    void Buffcheck(CString);
19  void Start();  void Start();
20  void startthread();  void startthread();
21  CButton m_led1;  CButton m_led1;
22  CButton m_led2;  CButton m_led2;
23  CButton m_led3;  CButton m_led3;
24    CButton m_knap1;
25    CButton m_knap2;
26    CEdit m_temp;
27    CEdit m_pot;
28    
29  // CAboutDlg dialog used for App About  // CAboutDlg dialog used for App About
30    
# Line 82  BEGIN_MESSAGE_MAP(CClientDlg, CDialog) Line 88  BEGIN_MESSAGE_MAP(CClientDlg, CDialog)
88          //}}AFX_MSG_MAP          //}}AFX_MSG_MAP
89          ON_BN_CLICKED(IDC_IPPORT, OnBnClickedIpport)          ON_BN_CLICKED(IDC_IPPORT, OnBnClickedIpport)
90          ON_BN_CLICKED(IDC_Connect, OnBnClickedConnect)          ON_BN_CLICKED(IDC_Connect, OnBnClickedConnect)
91            ON_BN_CLICKED(IDC_LED1, OnBnClickedLed1)
92            ON_BN_CLICKED(IDC_LED2, OnBnClickedLed2)
93            ON_BN_CLICKED(IDC_LED3, OnBnClickedLed3)
94  END_MESSAGE_MAP()  END_MESSAGE_MAP()
95    
96    
# Line 91  class ClientSocket : public CSocket{ Line 100  class ClientSocket : public CSocket{
100  public:  public:
101          ClientSocket() { };          ClientSocket() { };
102          virtual void OnReceive(int nErrorCode);          virtual void OnReceive(int nErrorCode);
         virtual void OnSend(int nErrorCode);  
103  };  };
104  BOOL CClientDlg::OnInitDialog()  BOOL CClientDlg::OnInitDialog()
105  {  {
# Line 213  HCURSOR CClientDlg::OnQueryDragIcon() Line 221  HCURSOR CClientDlg::OnQueryDragIcon()
221    
222    
223  ClientSocket    sockClient;  ClientSocket    sockClient;
224  CString strIp, strPort;  CString strIp, strPort, buff;
225    
226  /*Clientsocket class used for client socket connections*/  /*Clientsocket class used for client socket connections*/
227  void ClientSocket::OnReceive( int nErrorCode )  void ClientSocket::OnReceive( int nErrorCode )
228  {  {
229          char buffer[4096];          char buffer[4096];
230          int size;          int size;
231          CString buff;          
232    
233          size = Receive(buffer,4095);          size = Receive(buffer,4095);
234          buffer[size] = 0;          buffer[size] = 0;
235          MessageBox(0,buffer,0,MB_OK);          MessageBox(0,buffer,0,MB_OK);
236          buff = buffer;          buff = buffer;
237          if( buff == "Tændt" )          Buffcheck(buff);
238          {          //Close();
                 char test[10];  
                 int i;  
                 i = m_led1.GetCheck();  
 //              _itot(i,test,10);               Fejltjeck  
 //              MessageBox(0,test,0,MB_OK);  
                 if(i == 0)  
                 {  
                 m_led1.SetCheck(1);  
                 }  
                 else  
                 {  
                 m_led1.SetCheck(0);  
                 }  
         }  
         else  
         {  
                 MessageBox(0,"FEJL i onrecive",0,MB_OK);  
         }  
         Close();  
 }  
 void ClientSocket::OnSend( int nErrorCode )  
 {  
 //      CString sendnu;         skal ikke sende nu  
   
 //      sendnu = Sendtekst;             skal ikke sende nu  
   
 //      Send(sendnu,sendnu.GetLength());        skal ikke sende nu  
239  }  }
240  void CClientDlg::OnBnClickedIpport()  void CClientDlg::OnBnClickedIpport()
241  {  {
# Line 288  void Start() Line 269  void Start()
269          sockClient.Create();          sockClient.Create();
270          if (sockClient.Connect(Ip,Port))          if (sockClient.Connect(Ip,Port))
271          {          {
272                  //sockClient.Send(strPort,strPort.GetLength(),NULL);  
                 //sockClient.Send(data,data.GetLength(),NULL);  
                 //sockClient.Close();  
273          }          }
274          else          else
275          {          {
# Line 301  void Start() Line 280  void Start()
280  }  }
281  void CClientDlg::OnBnClickedConnect()  void CClientDlg::OnBnClickedConnect()
282  {        {      
283            startthread();
284  }  }
285  UINT Status( LPVOID Param )  UINT Status( LPVOID Param )
286  {  {
287          CString status;          CString status;
288          status = "RB1";          status = "100";
         Sleep(atoi(Delay));  
289          sockClient.Send(status,status.GetLength(),NULL);          sockClient.Send(status,status.GetLength(),NULL);
290          startthread();          Sleep(atoi(Delay));
291            //startthread();
292          return TRUE;          return TRUE;
293  }  }
294  void startthread()  void startthread()
295  {  {
296          AfxBeginThread(Status,0,THREAD_PRIORITY_NORMAL,0,0,NULL);          AfxBeginThread(Status,0,THREAD_PRIORITY_NORMAL,0,0,NULL);
 }  
297    }
298    UINT Update( LPVOID param )
299    {
300            //Updatevariable = "11";
301            sockClient.Send(Updatevariable,Updatevariable.GetLength(),NULL);
302            //MessageBox(0,Updatevariable,0,MB_OK);
303            return TRUE;
304    }
305    void Buffcheck(CString)
306    {
307            int intbuff, temp, pot;
308            intbuff = atoi(buff);           // til standat case
309            temp = atoi(buff);                      // til temperatur case
310            pot = atoi(buff);                       // til potmeter case
311            switch (intbuff)
312            {
313                    case 110:               /*Led 1 Slukket*/
314                    {
315                            m_led1.SetCheck(0);
316                            break;
317                    }
318                    case 111:               /*Led 1 Tændt*/
319                    {
320                            m_led1.SetCheck(1);
321                            break;
322                    }
323                    case 120:               /*Led 2 Slukket*/
324                    {
325                            m_led2.SetCheck(0);
326                            break;
327                    }
328                    case 121:               /*Led 2 Tændt*/
329                    {
330                            m_led2.SetCheck(1);
331                            break;
332                    }
333                    case 130:               /*Led 3 Slukket*/
334                    {
335                            m_led3.SetCheck(0);
336                            break;
337                    }
338                    case 131:               /*Led 3 Tændt*/
339                    {
340                            m_led3.SetCheck(1);
341                            break;
342                    }
343                    case 140:               /*Knap 1 off*/
344                    {
345                            m_knap1.SetCheck(0);
346                            break;
347                    }
348                    case 141:               /*Knap 1 on*/
349                    {
350                            m_knap1.SetCheck(1);
351                            break;
352                    }
353                    case 150:               /*Knap 2 off*/
354                    {
355                            m_knap2.SetCheck(0);
356                            break;
357                    }
358                    case 151:               /*Knap 2 on*/
359                    {
360                            m_knap2.SetCheck(1);
361                            break;
362                    }              
363            }
364            if (temp > 3999 && temp < 5000)         //skriv temperaturen
365            {
366                    CString strtemp;
367                    temp = (temp-4000);
368                    strtemp.Format("%d",temp);
369                    m_temp.SetWindowText(strtemp);
370            }
371            if (pot > 1999 && pot < 3050)           //skriv potmeter værdien
372            {
373                    CString strpot;
374                    pot = (pot-2000);
375                    strpot.Format("%d",pot);
376                    m_temp.SetWindowText(strpot);
377            }
378    
379    }
380    void CClientDlg::OnBnClickedLed1()
381    {
382            int led, code, send;
383            led = 110;
384            code = m_led1.GetCheck();
385            send = (led+code);
386            Updatevariable.Format("%d",send);
387            AfxBeginThread(Update,0,THREAD_PRIORITY_NORMAL,0,0,NULL);
388    }
389    
390    void CClientDlg::OnBnClickedLed2()
391    {
392            int led, code, send;
393            led = 120;
394            code = m_led2.GetCheck();
395            send = (led+code);
396            Updatevariable.Format("%d",send);
397            AfxBeginThread(Update,0,THREAD_PRIORITY_NORMAL,0,0,NULL);
398    }
399    
400    void CClientDlg::OnBnClickedLed3()
401    {
402            int led, code, send;
403            led = 130;
404            code = m_led3.GetCheck();
405            send = (led+code);
406            Updatevariable.Format("%d",send);
407            AfxBeginThread(Update,0,THREAD_PRIORITY_NORMAL,0,0,NULL);
408    }

Legend:
Removed from v.29  
changed lines
  Added in v.30

  ViewVC Help
Powered by ViewVC 1.1.20