/[H7]/trunk/H7 Server/TcpClientClass.cpp
ViewVC logotype

Diff of /trunk/H7 Server/TcpClientClass.cpp

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

revision 32 by hedin, Wed Jan 31 12:42:51 2007 UTC revision 33 by hedin, Wed Jan 31 17:22:59 2007 UTC
# Line 6  Line 6 
6  #include "Resource.h"  #include "Resource.h"
7  #include "H7 serverDlg.h"  #include "H7 serverDlg.h"
8    
9    #include <exception>
10    
11  TcpClientClass::TcpClientClass(void)  TcpClientClass::TcpClientClass(void)
12  {  {
13            isClosed = false;
14  }  }
15    
16  TcpClientClass::~TcpClientClass(void)  TcpClientClass::~TcpClientClass(void)
# Line 18  void TcpClientClass::OnReceive(int nErro Line 21  void TcpClientClass::OnReceive(int nErro
21  {  {
22  //      MessageBox(0,"OnReceive","",MB_OK);  //      MessageBox(0,"OnReceive","",MB_OK);
23                    
24          int size = 1023;          int size = 4096;
25          char Buffer[1023];          char Buffer[4096];
26          CString Buff;          CString Buff;
27    
28          size = TcpClientClass::Receive(Buffer, size -1);          size = TcpClientClass::Receive(Buffer, size -1);
# Line 28  void TcpClientClass::OnReceive(int nErro Line 31  void TcpClientClass::OnReceive(int nErro
31    
32          CH7ServerDlg* parent = (CH7ServerDlg*) AfxGetMainWnd();          CH7ServerDlg* parent = (CH7ServerDlg*) AfxGetMainWnd();
33    
34                    CString debug;
35          switch( atoi(Buff) )          debug.Format("%d\n",atoi(Buff));
36            OutputDebugString( debug );
37    
38            try{
39                    switch( atoi(Buff) )
40                    {
41                    case 110:
42                            parent->H7Serial.writeTarget(LED3,OFF);
43                            break;
44                    case 111:
45                            parent->H7Serial.writeTarget(LED3,ON);
46                            break;
47                    case 120:
48                            parent->H7Serial.writeTarget(LED4,OFF);
49                            break;
50                    case 121:
51                            parent->H7Serial.writeTarget(LED4,ON);
52                            break;
53                    case 130:
54                            parent->H7Serial.writeTarget(LED5,OFF);
55                            break;
56                    case 131:
57                            parent->H7Serial.writeTarget(LED5,ON);
58                            break;
59                    case 100:
60                            SendReply(); // <--
61                            break;
62                    }
63                    Sleep(10);
64                    parent->UpdateClient();
65            }
66            catch (std::exception e)
67          {          {
68          case 110:                  CString msg;
69                  parent->H7Serial.writeTarget(LED3,OFF);                  msg.Format("%d : %s", atoi(Buff), e.what() );
70                  break;                  MessageBox(0, msg, "", MB_OK);
         case 111:  
                 parent->H7Serial.writeTarget(LED3,ON);  
                 break;  
         case 120:  
                 parent->H7Serial.writeTarget(LED4,OFF);  
                 break;  
         case 121:  
                 parent->H7Serial.writeTarget(LED4,ON);  
                 break;  
         case 130:  
                 parent->H7Serial.writeTarget(LED5,OFF);  
                 break;  
         case 131:  
                 parent->H7Serial.writeTarget(LED5,ON);  
                 break;  
71          }          }
72            
73          CSocket::OnReceive(nErrorCode);          CSocket::OnReceive(nErrorCode);
74  }  }
75    
76    void TcpClientClass::SendReply(void)
77    {
78            CH7ServerDlg* parent = (CH7ServerDlg*) AfxGetMainWnd();
79    
80            CString output;
81            short Tmp;
82            CString format;
83            const int timer = 10;
84    
85    Sleep(timer);
86            Tmp = parent->H7Serial.readTarget(0);
87            if( Tmp == 0 )
88                    output = "110|";
89            else if( Tmp == 1)
90                    output = "111|";
91            Send(output,output.GetLength(),0);
92    
93    Sleep(timer);  
94    
95            Tmp = parent->H7Serial.readTarget(1);
96            if( Tmp == 0 )
97                    output = "120|";
98            else if( Tmp == 1)
99                    output = "121|";
100            Send(output,output.GetLength(),0);
101    
102    Sleep(timer);
103            
104            Tmp = parent->H7Serial.readTarget(2);
105            if( Tmp == 0 )
106                    output = "130|";
107            else if( Tmp == 1)
108                    output = "131|";
109            Send(output,output.GetLength(),0);
110    Sleep(timer);
111    
112            Tmp = parent->H7Serial.readTarget(3);
113            if( Tmp == 0 )
114                    output = "140|";
115            else if( Tmp == 1 )
116                    output = "141|";
117            Send(output,output.GetLength(),0);
118    Sleep(timer);
119    
120            Tmp = parent->H7Serial.readTarget(4);
121            if( Tmp == 0 )
122                    output = "150|";
123            else if( Tmp == 1 )
124                    output = "151|";
125            Send(output,output.GetLength(),0);
126    Sleep(timer);
127    
128            Tmp = parent->H7Serial.readTarget(5);
129            Tmp += 2000;
130            format.Format("%d|",Tmp);
131            Send(format,format.GetLength(),0);
132    Sleep(timer);
133    
134            Tmp = parent->H7Serial.readTarget(6);
135            Tmp += 4000;
136            format.Format("%d|",Tmp);
137            Send(format,format.GetLength(),0);
138    Sleep(timer);
139    }
140    
141    void TcpClientClass::OnClose(int nErrorCode)
142    {
143            isClosed = true;
144    
145            CSocket::OnClose(nErrorCode);
146    }

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

  ViewVC Help
Powered by ViewVC 1.1.20