A program to Interact with Software Driver on the PC that work as a DDE server to be used with SoftPLC\'s it turn Mbed to an I/O card to the SoftPLC

Dependencies:   EthernetNetIf mbed

Committer:
mmohamed15
Date:
Fri May 06 01:02:44 2011 +0000
Revision:
0:69001bf3d843

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mmohamed15 0:69001bf3d843 1
mmohamed15 0:69001bf3d843 2 // MBED I/O Server FOR PC Based Control
mmohamed15 0:69001bf3d843 3 // 2011/2/7
mmohamed15 0:69001bf3d843 4
mmohamed15 0:69001bf3d843 5
mmohamed15 0:69001bf3d843 6 #include "mbed.h"
mmohamed15 0:69001bf3d843 7 #include "EthernetNetIf.h"
mmohamed15 0:69001bf3d843 8 #include "TCPSocket.h"
mmohamed15 0:69001bf3d843 9
mmohamed15 0:69001bf3d843 10 DigitalOut led4(LED4, "led4");
mmohamed15 0:69001bf3d843 11
mmohamed15 0:69001bf3d843 12 // Declaring Digital outputs Pins
mmohamed15 0:69001bf3d843 13 DigitalOut do1(p30);
mmohamed15 0:69001bf3d843 14 DigitalOut do2(p29);
mmohamed15 0:69001bf3d843 15 DigitalOut do3(p28);
mmohamed15 0:69001bf3d843 16 DigitalOut do4(p27);
mmohamed15 0:69001bf3d843 17 DigitalOut do5(p26);
mmohamed15 0:69001bf3d843 18 DigitalOut do6(p25);
mmohamed15 0:69001bf3d843 19 DigitalOut do7(p24);
mmohamed15 0:69001bf3d843 20 DigitalOut do8(p23);
mmohamed15 0:69001bf3d843 21 DigitalOut do9(p22);
mmohamed15 0:69001bf3d843 22 DigitalOut do10(p21);
mmohamed15 0:69001bf3d843 23 // Declaring Digital Inptus Pins
mmohamed15 0:69001bf3d843 24 DigitalIn di1(p5);
mmohamed15 0:69001bf3d843 25 DigitalIn di2(p6);
mmohamed15 0:69001bf3d843 26 DigitalIn di3(p7);
mmohamed15 0:69001bf3d843 27 DigitalIn di4(p8);
mmohamed15 0:69001bf3d843 28 DigitalIn di5(p9);
mmohamed15 0:69001bf3d843 29 DigitalIn di6(p10);
mmohamed15 0:69001bf3d843 30 DigitalIn di7(p11);
mmohamed15 0:69001bf3d843 31 DigitalIn di8(p12);
mmohamed15 0:69001bf3d843 32 DigitalIn di9(p13);
mmohamed15 0:69001bf3d843 33 DigitalIn di10(p14);
mmohamed15 0:69001bf3d843 34 DigitalIn di11(p15);
mmohamed15 0:69001bf3d843 35 DigitalIn di12(p16);
mmohamed15 0:69001bf3d843 36 DigitalIn di13(p17);
mmohamed15 0:69001bf3d843 37 DigitalIn di14(p18);
mmohamed15 0:69001bf3d843 38 DigitalIn di15(p19);
mmohamed15 0:69001bf3d843 39 DigitalIn di16(p20);
mmohamed15 0:69001bf3d843 40
mmohamed15 0:69001bf3d843 41 char x[10],y[16];
mmohamed15 0:69001bf3d843 42
mmohamed15 0:69001bf3d843 43 // EthernetNetIf eth;
mmohamed15 0:69001bf3d843 44 EthernetNetIf eth(
mmohamed15 0:69001bf3d843 45 IpAddr(192,168,1,25), //IP Address
mmohamed15 0:69001bf3d843 46 IpAddr(255,255,255,0), //Network Mask
mmohamed15 0:69001bf3d843 47 IpAddr(192,168,1,1), //Gateway
mmohamed15 0:69001bf3d843 48 IpAddr(192,168,1,1) //DNS
mmohamed15 0:69001bf3d843 49 );
mmohamed15 0:69001bf3d843 50
mmohamed15 0:69001bf3d843 51 #define TCP_LISTENING_PORT 12345
mmohamed15 0:69001bf3d843 52
mmohamed15 0:69001bf3d843 53 TCPSocket ListeningSock;
mmohamed15 0:69001bf3d843 54 TCPSocket* pConnectedSock; // for ConnectedSock
mmohamed15 0:69001bf3d843 55 Host client;
mmohamed15 0:69001bf3d843 56 TCPSocketErr err;
mmohamed15 0:69001bf3d843 57
mmohamed15 0:69001bf3d843 58 void onConnectedTCPSocketEvent(TCPSocketEvent e)
mmohamed15 0:69001bf3d843 59 {
mmohamed15 0:69001bf3d843 60 switch(e)
mmohamed15 0:69001bf3d843 61 {
mmohamed15 0:69001bf3d843 62 case TCPSOCKET_CONNECTED:
mmohamed15 0:69001bf3d843 63 printf("TCP Socket Connected\r\n");
mmohamed15 0:69001bf3d843 64 break;
mmohamed15 0:69001bf3d843 65 case TCPSOCKET_WRITEABLE:
mmohamed15 0:69001bf3d843 66 //Can now write some data...
mmohamed15 0:69001bf3d843 67 printf("TCP Socket Writable\r\n");
mmohamed15 0:69001bf3d843 68 break;
mmohamed15 0:69001bf3d843 69 case TCPSOCKET_READABLE:
mmohamed15 0:69001bf3d843 70 //Can now read dome data...
mmohamed15 0:69001bf3d843 71 printf("TCP Socket Readable\r\n");
mmohamed15 0:69001bf3d843 72 // Read in any available data into the buffer
mmohamed15 0:69001bf3d843 73
mmohamed15 0:69001bf3d843 74 //Parsing for the messege from I/O Server
mmohamed15 0:69001bf3d843 75 //1)Updating thr output status
mmohamed15 0:69001bf3d843 76 while ( pConnectedSock->recv(x, 10) ) {
mmohamed15 0:69001bf3d843 77 if(x[0]==0)
mmohamed15 0:69001bf3d843 78 {
mmohamed15 0:69001bf3d843 79 do1=0;
mmohamed15 0:69001bf3d843 80 }
mmohamed15 0:69001bf3d843 81 if(x[0]==1)
mmohamed15 0:69001bf3d843 82 {
mmohamed15 0:69001bf3d843 83
mmohamed15 0:69001bf3d843 84 do1=1;
mmohamed15 0:69001bf3d843 85 }
mmohamed15 0:69001bf3d843 86 if(x[1]==0)
mmohamed15 0:69001bf3d843 87 {
mmohamed15 0:69001bf3d843 88
mmohamed15 0:69001bf3d843 89 do2=0;
mmohamed15 0:69001bf3d843 90 }
mmohamed15 0:69001bf3d843 91 if(x[1]==1)
mmohamed15 0:69001bf3d843 92 {
mmohamed15 0:69001bf3d843 93
mmohamed15 0:69001bf3d843 94 do2=1;
mmohamed15 0:69001bf3d843 95 }
mmohamed15 0:69001bf3d843 96 if(x[2]==0)
mmohamed15 0:69001bf3d843 97 {
mmohamed15 0:69001bf3d843 98
mmohamed15 0:69001bf3d843 99 do3=0;
mmohamed15 0:69001bf3d843 100 }
mmohamed15 0:69001bf3d843 101 if(x[2]==1)
mmohamed15 0:69001bf3d843 102 {
mmohamed15 0:69001bf3d843 103
mmohamed15 0:69001bf3d843 104 do3=1;
mmohamed15 0:69001bf3d843 105 }
mmohamed15 0:69001bf3d843 106 if(x[3]==0)
mmohamed15 0:69001bf3d843 107 {
mmohamed15 0:69001bf3d843 108 do4=0;
mmohamed15 0:69001bf3d843 109 }
mmohamed15 0:69001bf3d843 110 if(x[3]==1)
mmohamed15 0:69001bf3d843 111 {
mmohamed15 0:69001bf3d843 112 do4=1;
mmohamed15 0:69001bf3d843 113 }
mmohamed15 0:69001bf3d843 114 if(x[4]==0)
mmohamed15 0:69001bf3d843 115 {
mmohamed15 0:69001bf3d843 116 do5=0;
mmohamed15 0:69001bf3d843 117 }
mmohamed15 0:69001bf3d843 118 if(x[4]==1)
mmohamed15 0:69001bf3d843 119 {
mmohamed15 0:69001bf3d843 120 do5=1;
mmohamed15 0:69001bf3d843 121 }
mmohamed15 0:69001bf3d843 122 if(x[5]==0)
mmohamed15 0:69001bf3d843 123 {
mmohamed15 0:69001bf3d843 124 do6=0;
mmohamed15 0:69001bf3d843 125 }
mmohamed15 0:69001bf3d843 126 if(x[5]==1)
mmohamed15 0:69001bf3d843 127 {
mmohamed15 0:69001bf3d843 128 do6=1;
mmohamed15 0:69001bf3d843 129 }
mmohamed15 0:69001bf3d843 130 if(x[6]==0)
mmohamed15 0:69001bf3d843 131 {
mmohamed15 0:69001bf3d843 132 do7=0;
mmohamed15 0:69001bf3d843 133 }
mmohamed15 0:69001bf3d843 134 if(x[6]==1)
mmohamed15 0:69001bf3d843 135 {
mmohamed15 0:69001bf3d843 136 do7=1;
mmohamed15 0:69001bf3d843 137 }
mmohamed15 0:69001bf3d843 138 if(x[7]==0)
mmohamed15 0:69001bf3d843 139 {
mmohamed15 0:69001bf3d843 140 do8=0;
mmohamed15 0:69001bf3d843 141 }
mmohamed15 0:69001bf3d843 142 if(x[7]==1)
mmohamed15 0:69001bf3d843 143 {
mmohamed15 0:69001bf3d843 144 do8=1;
mmohamed15 0:69001bf3d843 145 }
mmohamed15 0:69001bf3d843 146 if(x[8]==0)
mmohamed15 0:69001bf3d843 147 {
mmohamed15 0:69001bf3d843 148 do9=0;
mmohamed15 0:69001bf3d843 149 }
mmohamed15 0:69001bf3d843 150 if(x[8]==1)
mmohamed15 0:69001bf3d843 151 {
mmohamed15 0:69001bf3d843 152 do9=1;
mmohamed15 0:69001bf3d843 153 }
mmohamed15 0:69001bf3d843 154 if(x[9]==0)
mmohamed15 0:69001bf3d843 155 {
mmohamed15 0:69001bf3d843 156 do10=0;
mmohamed15 0:69001bf3d843 157 }
mmohamed15 0:69001bf3d843 158 if(x[9]==1)
mmohamed15 0:69001bf3d843 159 {
mmohamed15 0:69001bf3d843 160 do10=1;
mmohamed15 0:69001bf3d843 161 }
mmohamed15 0:69001bf3d843 162
mmohamed15 0:69001bf3d843 163
mmohamed15 0:69001bf3d843 164
mmohamed15 0:69001bf3d843 165 // 2) send the inputs status to I/O Server
mmohamed15 0:69001bf3d843 166 if (di1==1)
mmohamed15 0:69001bf3d843 167 {
mmohamed15 0:69001bf3d843 168 y[0]=1;
mmohamed15 0:69001bf3d843 169 }
mmohamed15 0:69001bf3d843 170 if (di1==0)
mmohamed15 0:69001bf3d843 171 {
mmohamed15 0:69001bf3d843 172 y[0]=0;
mmohamed15 0:69001bf3d843 173 }
mmohamed15 0:69001bf3d843 174 if (di2==1)
mmohamed15 0:69001bf3d843 175 {
mmohamed15 0:69001bf3d843 176 y[1]=1;
mmohamed15 0:69001bf3d843 177 }
mmohamed15 0:69001bf3d843 178 if (di2==0)
mmohamed15 0:69001bf3d843 179 {
mmohamed15 0:69001bf3d843 180 y[1]=0;
mmohamed15 0:69001bf3d843 181 }
mmohamed15 0:69001bf3d843 182 if (di3==1)
mmohamed15 0:69001bf3d843 183 {
mmohamed15 0:69001bf3d843 184 y[2]=1;
mmohamed15 0:69001bf3d843 185 }
mmohamed15 0:69001bf3d843 186 if (di3==0)
mmohamed15 0:69001bf3d843 187 {
mmohamed15 0:69001bf3d843 188 y[2]=0;
mmohamed15 0:69001bf3d843 189 }
mmohamed15 0:69001bf3d843 190 if (di4==1)
mmohamed15 0:69001bf3d843 191 {
mmohamed15 0:69001bf3d843 192 y[3]=1;
mmohamed15 0:69001bf3d843 193 }
mmohamed15 0:69001bf3d843 194 if (di4==0)
mmohamed15 0:69001bf3d843 195 {
mmohamed15 0:69001bf3d843 196 y[3]=0;
mmohamed15 0:69001bf3d843 197 }
mmohamed15 0:69001bf3d843 198 if (di1==5)
mmohamed15 0:69001bf3d843 199 {
mmohamed15 0:69001bf3d843 200 y[4]=1;
mmohamed15 0:69001bf3d843 201 }
mmohamed15 0:69001bf3d843 202 if (di5==0)
mmohamed15 0:69001bf3d843 203 {
mmohamed15 0:69001bf3d843 204 y[4]=0;
mmohamed15 0:69001bf3d843 205 }
mmohamed15 0:69001bf3d843 206 if (di6==1)
mmohamed15 0:69001bf3d843 207 {
mmohamed15 0:69001bf3d843 208 y[5]=1;
mmohamed15 0:69001bf3d843 209 }
mmohamed15 0:69001bf3d843 210 if (di6==0)
mmohamed15 0:69001bf3d843 211 {
mmohamed15 0:69001bf3d843 212 y[5]=0;
mmohamed15 0:69001bf3d843 213 }
mmohamed15 0:69001bf3d843 214 if (di7==1)
mmohamed15 0:69001bf3d843 215 {
mmohamed15 0:69001bf3d843 216 y[6]=1;
mmohamed15 0:69001bf3d843 217 }
mmohamed15 0:69001bf3d843 218 if (di7==0)
mmohamed15 0:69001bf3d843 219 {
mmohamed15 0:69001bf3d843 220 y[6]=0;
mmohamed15 0:69001bf3d843 221 }
mmohamed15 0:69001bf3d843 222 if (di8==1)
mmohamed15 0:69001bf3d843 223 {
mmohamed15 0:69001bf3d843 224 y[7]=1;
mmohamed15 0:69001bf3d843 225 }
mmohamed15 0:69001bf3d843 226 if (di8==0)
mmohamed15 0:69001bf3d843 227 {
mmohamed15 0:69001bf3d843 228 y[7]=0;
mmohamed15 0:69001bf3d843 229 }
mmohamed15 0:69001bf3d843 230 if (di9==1)
mmohamed15 0:69001bf3d843 231 {
mmohamed15 0:69001bf3d843 232 y[8]=1;
mmohamed15 0:69001bf3d843 233 }
mmohamed15 0:69001bf3d843 234 if (di9==0)
mmohamed15 0:69001bf3d843 235 {
mmohamed15 0:69001bf3d843 236 y[8]=0;
mmohamed15 0:69001bf3d843 237 }
mmohamed15 0:69001bf3d843 238 if (di10==1)
mmohamed15 0:69001bf3d843 239 {
mmohamed15 0:69001bf3d843 240 y[9]=1;
mmohamed15 0:69001bf3d843 241 }
mmohamed15 0:69001bf3d843 242 if (di10==0)
mmohamed15 0:69001bf3d843 243 {
mmohamed15 0:69001bf3d843 244 y[9]=0;
mmohamed15 0:69001bf3d843 245 }
mmohamed15 0:69001bf3d843 246 if (di11==1)
mmohamed15 0:69001bf3d843 247 {
mmohamed15 0:69001bf3d843 248 y[10]=1;
mmohamed15 0:69001bf3d843 249 }
mmohamed15 0:69001bf3d843 250 if (di11==0)
mmohamed15 0:69001bf3d843 251 {
mmohamed15 0:69001bf3d843 252 y[10]=0;
mmohamed15 0:69001bf3d843 253 }
mmohamed15 0:69001bf3d843 254 if (di12==1)
mmohamed15 0:69001bf3d843 255 {
mmohamed15 0:69001bf3d843 256 y[11]=1;
mmohamed15 0:69001bf3d843 257 }
mmohamed15 0:69001bf3d843 258 if (di12==0)
mmohamed15 0:69001bf3d843 259 {
mmohamed15 0:69001bf3d843 260 y[11]=0;
mmohamed15 0:69001bf3d843 261 }
mmohamed15 0:69001bf3d843 262 if (di13==1)
mmohamed15 0:69001bf3d843 263 {
mmohamed15 0:69001bf3d843 264 y[12]=1;
mmohamed15 0:69001bf3d843 265 }
mmohamed15 0:69001bf3d843 266 if (di13==0)
mmohamed15 0:69001bf3d843 267 {
mmohamed15 0:69001bf3d843 268 y[12]=0;
mmohamed15 0:69001bf3d843 269 }
mmohamed15 0:69001bf3d843 270 if (di14==1)
mmohamed15 0:69001bf3d843 271 {
mmohamed15 0:69001bf3d843 272 y[13]=1;
mmohamed15 0:69001bf3d843 273 }
mmohamed15 0:69001bf3d843 274 if (di14==0)
mmohamed15 0:69001bf3d843 275 {
mmohamed15 0:69001bf3d843 276 y[13]=0;
mmohamed15 0:69001bf3d843 277 }
mmohamed15 0:69001bf3d843 278 if (di15==1)
mmohamed15 0:69001bf3d843 279 {
mmohamed15 0:69001bf3d843 280 y[14]=1;
mmohamed15 0:69001bf3d843 281 }
mmohamed15 0:69001bf3d843 282 if (di15==0)
mmohamed15 0:69001bf3d843 283 {
mmohamed15 0:69001bf3d843 284 y[14]=0;
mmohamed15 0:69001bf3d843 285 }
mmohamed15 0:69001bf3d843 286 if (di16==1)
mmohamed15 0:69001bf3d843 287 {
mmohamed15 0:69001bf3d843 288 y[15]=1;
mmohamed15 0:69001bf3d843 289 }
mmohamed15 0:69001bf3d843 290 if (di16==0)
mmohamed15 0:69001bf3d843 291 {
mmohamed15 0:69001bf3d843 292 y[15]=0;
mmohamed15 0:69001bf3d843 293 }
mmohamed15 0:69001bf3d843 294
mmohamed15 0:69001bf3d843 295
mmohamed15 0:69001bf3d843 296 pConnectedSock->send(y, 16);
mmohamed15 0:69001bf3d843 297 // make terminater
mmohamed15 0:69001bf3d843 298
mmohamed15 0:69001bf3d843 299 }
mmohamed15 0:69001bf3d843 300 break;
mmohamed15 0:69001bf3d843 301 case TCPSOCKET_CONTIMEOUT:
mmohamed15 0:69001bf3d843 302 printf("TCP Socket Timeout\r\n");
mmohamed15 0:69001bf3d843 303 break;
mmohamed15 0:69001bf3d843 304 case TCPSOCKET_CONRST:
mmohamed15 0:69001bf3d843 305 printf("TCP Socket CONRST\r\n");
mmohamed15 0:69001bf3d843 306 break;
mmohamed15 0:69001bf3d843 307 case TCPSOCKET_CONABRT:
mmohamed15 0:69001bf3d843 308 printf("TCP Socket CONABRT\r\n");
mmohamed15 0:69001bf3d843 309 break;
mmohamed15 0:69001bf3d843 310 case TCPSOCKET_ERROR:
mmohamed15 0:69001bf3d843 311 printf("TCP Socket Error\r\n");
mmohamed15 0:69001bf3d843 312 break;
mmohamed15 0:69001bf3d843 313 case TCPSOCKET_DISCONNECTED:
mmohamed15 0:69001bf3d843 314 //Close socket...
mmohamed15 0:69001bf3d843 315 printf("TCP Socket Disconnected\r\n");
mmohamed15 0:69001bf3d843 316 pConnectedSock->close();
mmohamed15 0:69001bf3d843 317 break;
mmohamed15 0:69001bf3d843 318 default:
mmohamed15 0:69001bf3d843 319 printf("DEFAULT\r\n");
mmohamed15 0:69001bf3d843 320 }
mmohamed15 0:69001bf3d843 321 }
mmohamed15 0:69001bf3d843 322
mmohamed15 0:69001bf3d843 323
mmohamed15 0:69001bf3d843 324 void onListeningTCPSocketEvent(TCPSocketEvent e)
mmohamed15 0:69001bf3d843 325 {
mmohamed15 0:69001bf3d843 326 switch(e)
mmohamed15 0:69001bf3d843 327 {
mmohamed15 0:69001bf3d843 328 case TCPSOCKET_ACCEPT:
mmohamed15 0:69001bf3d843 329 printf("Listening: TCP Socket Accepted\r\n");
mmohamed15 0:69001bf3d843 330 // Accepts connection from client and gets connected socket.
mmohamed15 0:69001bf3d843 331 err=ListeningSock.accept(&client, &pConnectedSock);
mmohamed15 0:69001bf3d843 332 if (err) {
mmohamed15 0:69001bf3d843 333 printf("onListeningTcpSocketEvent : Could not accept connection.\r\n");
mmohamed15 0:69001bf3d843 334 return; //Error in accept, discard connection
mmohamed15 0:69001bf3d843 335 }
mmohamed15 0:69001bf3d843 336 // Setup the new socket events
mmohamed15 0:69001bf3d843 337 pConnectedSock->setOnEvent(&onConnectedTCPSocketEvent);
mmohamed15 0:69001bf3d843 338 // We can find out from where the connection is coming by looking at the
mmohamed15 0:69001bf3d843 339 // Host parameter of the accept() method
mmohamed15 0:69001bf3d843 340 IpAddr clientIp = client.getIp();
mmohamed15 0:69001bf3d843 341 printf("Listening: Incoming TCP connection from %d.%d.%d.%d\r\n",
mmohamed15 0:69001bf3d843 342 clientIp[0], clientIp[1], clientIp[2], clientIp[3]);
mmohamed15 0:69001bf3d843 343 break;
mmohamed15 0:69001bf3d843 344 // the following cases will not happen
mmohamed15 0:69001bf3d843 345 case TCPSOCKET_CONNECTED:
mmohamed15 0:69001bf3d843 346 printf("Listening: TCP Socket Connected\r\n");
mmohamed15 0:69001bf3d843 347 break;
mmohamed15 0:69001bf3d843 348 case TCPSOCKET_WRITEABLE:
mmohamed15 0:69001bf3d843 349 printf("Listening: TCP Socket Writable\r\n");
mmohamed15 0:69001bf3d843 350 break;
mmohamed15 0:69001bf3d843 351 case TCPSOCKET_READABLE:
mmohamed15 0:69001bf3d843 352 printf("Listening: TCP Socket Readable\r\n");
mmohamed15 0:69001bf3d843 353 break;
mmohamed15 0:69001bf3d843 354 case TCPSOCKET_CONTIMEOUT:
mmohamed15 0:69001bf3d843 355 printf("Listening: TCP Socket Timeout\r\n");
mmohamed15 0:69001bf3d843 356 break;
mmohamed15 0:69001bf3d843 357 case TCPSOCKET_CONRST:
mmohamed15 0:69001bf3d843 358 printf("Listening: TCP Socket CONRST\r\n");
mmohamed15 0:69001bf3d843 359 break;
mmohamed15 0:69001bf3d843 360 case TCPSOCKET_CONABRT:
mmohamed15 0:69001bf3d843 361 printf("Listening: TCP Socket CONABRT\r\n");
mmohamed15 0:69001bf3d843 362 break;
mmohamed15 0:69001bf3d843 363 case TCPSOCKET_ERROR:
mmohamed15 0:69001bf3d843 364 printf("Listening: TCP Socket Error\r\n");
mmohamed15 0:69001bf3d843 365 break;
mmohamed15 0:69001bf3d843 366 case TCPSOCKET_DISCONNECTED:
mmohamed15 0:69001bf3d843 367 //Close socket...
mmohamed15 0:69001bf3d843 368 printf("Listening: TCP Socket Disconnected\r\n");
mmohamed15 0:69001bf3d843 369 ListeningSock.close();
mmohamed15 0:69001bf3d843 370 break;
mmohamed15 0:69001bf3d843 371 default:
mmohamed15 0:69001bf3d843 372 printf("DEFAULT\r\n");
mmohamed15 0:69001bf3d843 373 };
mmohamed15 0:69001bf3d843 374 }
mmohamed15 0:69001bf3d843 375
mmohamed15 0:69001bf3d843 376
mmohamed15 0:69001bf3d843 377 int main() {
mmohamed15 0:69001bf3d843 378 printf("\r\n");
mmohamed15 0:69001bf3d843 379 printf("Setting up...\r\n");
mmohamed15 0:69001bf3d843 380 EthernetErr ethErr = eth.setup();
mmohamed15 0:69001bf3d843 381 if(ethErr)
mmohamed15 0:69001bf3d843 382 {
mmohamed15 0:69001bf3d843 383 printf("Error %d in setup.\r\n", ethErr);
mmohamed15 0:69001bf3d843 384 return -1;
mmohamed15 0:69001bf3d843 385 }
mmohamed15 0:69001bf3d843 386 printf("Setup OK\r\n");
mmohamed15 0:69001bf3d843 387
mmohamed15 0:69001bf3d843 388 IpAddr ip = eth.getIp();
mmohamed15 0:69001bf3d843 389 printf("mbed IP Address is %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]);
mmohamed15 0:69001bf3d843 390
mmohamed15 0:69001bf3d843 391
mmohamed15 0:69001bf3d843 392 // Set the callbacks for Listening
mmohamed15 0:69001bf3d843 393 ListeningSock.setOnEvent(&onListeningTCPSocketEvent);
mmohamed15 0:69001bf3d843 394
mmohamed15 0:69001bf3d843 395 // bind and listen on TCP
mmohamed15 0:69001bf3d843 396 err=ListeningSock.bind(Host(IpAddr(), TCP_LISTENING_PORT));
mmohamed15 0:69001bf3d843 397 printf("Binding..\r\n");
mmohamed15 0:69001bf3d843 398 if(err)
mmohamed15 0:69001bf3d843 399 {
mmohamed15 0:69001bf3d843 400 //Deal with that error...
mmohamed15 0:69001bf3d843 401 printf("Binding Error\n");
mmohamed15 0:69001bf3d843 402 }
mmohamed15 0:69001bf3d843 403 err=ListeningSock.listen(); // Starts listening
mmohamed15 0:69001bf3d843 404 printf("Listening...\r\n");
mmohamed15 0:69001bf3d843 405 if(err)
mmohamed15 0:69001bf3d843 406 {
mmohamed15 0:69001bf3d843 407 printf("Listening Error\r\n");
mmohamed15 0:69001bf3d843 408 }
mmohamed15 0:69001bf3d843 409
mmohamed15 0:69001bf3d843 410 Timer tmr;
mmohamed15 0:69001bf3d843 411 tmr.start();
mmohamed15 0:69001bf3d843 412
mmohamed15 0:69001bf3d843 413 while(true)
mmohamed15 0:69001bf3d843 414 {
mmohamed15 0:69001bf3d843 415 Net::poll();
mmohamed15 0:69001bf3d843 416 if(tmr.read() > 0.2) // sec
mmohamed15 0:69001bf3d843 417 {
mmohamed15 0:69001bf3d843 418 led4=!led4; //Show that we are alive
mmohamed15 0:69001bf3d843 419 tmr.reset();
mmohamed15 0:69001bf3d843 420 }
mmohamed15 0:69001bf3d843 421 }
mmohamed15 0:69001bf3d843 422 }