DSOS Sensors
Dependencies: EthernetInterface SensorsTointegrate mbed-rtos mbed
Fork of MainTaskGus by
Coments.cpp@1:f3619e6e9e89, 2015-12-07 (annotated)
- Committer:
- Jorge_Beltran
- Date:
- Mon Dec 07 01:52:10 2015 +0000
- Revision:
- 1:f3619e6e9e89
- Parent:
- 0:5db5c980e717
DSOS Sensors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RoHe | 0:5db5c980e717 | 1 | /* |
RoHe | 0:5db5c980e717 | 2 | |
RoHe | 0:5db5c980e717 | 3 | TODO: |
RoHe | 0:5db5c980e717 | 4 | |
RoHe | 0:5db5c980e717 | 5 | 1.- Conectar a ambos servidores |
RoHe | 0:5db5c980e717 | 6 | 1.1 - si no solo conectar a uno y tener present la conección activa |
RoHe | 0:5db5c980e717 | 7 | 2.-hacer funciones para dvidir las cadenas de los mensajes |
RoHe | 0:5db5c980e717 | 8 | 3.-hace funcion para formar cadenas para enviar mensajes |
RoHe | 0:5db5c980e717 | 9 | 4. Formato de mensajes para que los pueda leer el server |
RoHe | 0:5db5c980e717 | 10 | |
RoHe | 0:5db5c980e717 | 11 | */ |
RoHe | 0:5db5c980e717 | 12 | |
RoHe | 0:5db5c980e717 | 13 | |
RoHe | 0:5db5c980e717 | 14 | /* |
RoHe | 0:5db5c980e717 | 15 | |
RoHe | 0:5db5c980e717 | 16 | |
RoHe | 0:5db5c980e717 | 17 | |
RoHe | 0:5db5c980e717 | 18 | /* |
RoHe | 0:5db5c980e717 | 19 | |
RoHe | 0:5db5c980e717 | 20 | // Receive message from server |
RoHe | 0:5db5c980e717 | 21 | char buf1[256]; |
RoHe | 0:5db5c980e717 | 22 | int n1 = socketTCP1.receive(buf1, 256); |
RoHe | 0:5db5c980e717 | 23 | buf1[n1] = '\0'; |
RoHe | 0:5db5c980e717 | 24 | |
RoHe | 0:5db5c980e717 | 25 | if(n1>0) { |
RoHe | 0:5db5c980e717 | 26 | pc.printf("Received message from server1 IF: '%s'\n\r", buf1); |
RoHe | 0:5db5c980e717 | 27 | socketTCP1.close(); |
RoHe | 0:5db5c980e717 | 28 | //isConnectedServer1=false; |
RoHe | 0:5db5c980e717 | 29 | } else { |
RoHe | 0:5db5c980e717 | 30 | //_isConnectedServer1==false; //quiere decir que se desconecto del servidor |
RoHe | 0:5db5c980e717 | 31 | pc.printf("Not received ELSE value of lenght: '%u'\n\r",strlen(buf1)); |
RoHe | 0:5db5c980e717 | 32 | socketTCP1.close(); |
RoHe | 0:5db5c980e717 | 33 | //isConnectedServer1=false; |
RoHe | 0:5db5c980e717 | 34 | } |
RoHe | 0:5db5c980e717 | 35 | |
RoHe | 0:5db5c980e717 | 36 | if(bo_somethingWrong==true) { |
RoHe | 0:5db5c980e717 | 37 | return 0; |
RoHe | 0:5db5c980e717 | 38 | } |
RoHe | 0:5db5c980e717 | 39 | |
RoHe | 0:5db5c980e717 | 40 | //if(socketTCP.connect(ECHO_SERVER_ADDRESS1, ECHO_SERVER_PORT1) == -1 && _isConnectedServer1==false ) { |
RoHe | 0:5db5c980e717 | 41 | if(socketTCP.connect(ECHO_SERVER_ADDRESS1, ECHO_SERVER_PORT1) == -1) { |
RoHe | 0:5db5c980e717 | 42 | _isConnectedServer1=socketTCP.is_connected(); |
RoHe | 0:5db5c980e717 | 43 | //_isConnectedServer1=false; |
RoHe | 0:5db5c980e717 | 44 | pc.printf("Unable to connect to (%s) on port (%d)\n\r", ECHO_SERVER_ADDRESS1, ECHO_SERVER_PORT1); |
RoHe | 0:5db5c980e717 | 45 | wait(1); |
RoHe | 0:5db5c980e717 | 46 | } else { |
RoHe | 0:5db5c980e717 | 47 | _isConnectedServer1=socketTCP.is_connected(); |
RoHe | 0:5db5c980e717 | 48 | //_isConnectedServer1=true; |
RoHe | 0:5db5c980e717 | 49 | //pc.printf("Connected to Server at %s\n\r",ECHO_SERVER_ADDRESS1); |
RoHe | 0:5db5c980e717 | 50 | pc.printf("Connected to Server at %s\n\r",socketTCP.get_address()); |
RoHe | 0:5db5c980e717 | 51 | pc.printf("Connected to PORT at %u\n\r",socketTCP.get_port()); |
RoHe | 0:5db5c980e717 | 52 | |
RoHe | 0:5db5c980e717 | 53 | |
RoHe | 0:5db5c980e717 | 54 | |
RoHe | 0:5db5c980e717 | 55 | //TODO: split strings |
RoHe | 0:5db5c980e717 | 56 | |
RoHe | 0:5db5c980e717 | 57 | char hello[] = "reply:get:status:192.168.1.77:door:1\n\r"; |
RoHe | 0:5db5c980e717 | 58 | |
RoHe | 0:5db5c980e717 | 59 | pc.printf("Sending message to Server : %s \n\r",hello); |
RoHe | 0:5db5c980e717 | 60 | socketTCP.send_all(hello, sizeof(hello)- 1); |
RoHe | 0:5db5c980e717 | 61 | |
RoHe | 0:5db5c980e717 | 62 | |
RoHe | 0:5db5c980e717 | 63 | |
RoHe | 0:5db5c980e717 | 64 | // Receive message from server |
RoHe | 0:5db5c980e717 | 65 | char buf[256]; |
RoHe | 0:5db5c980e717 | 66 | int n = socketTCP.receive(buf, 256); |
RoHe | 0:5db5c980e717 | 67 | buf[n] = '\0'; |
RoHe | 0:5db5c980e717 | 68 | pc.printf("Received message from server: '%s'\n\r", buf); |
RoHe | 0:5db5c980e717 | 69 | |
RoHe | 0:5db5c980e717 | 70 | if(bo_somethingWrong==true) { |
RoHe | 0:5db5c980e717 | 71 | return 0; |
RoHe | 0:5db5c980e717 | 72 | } |
RoHe | 0:5db5c980e717 | 73 | |
RoHe | 0:5db5c980e717 | 74 | |
RoHe | 0:5db5c980e717 | 75 | } |
RoHe | 0:5db5c980e717 | 76 | |
RoHe | 0:5db5c980e717 | 77 | |
RoHe | 0:5db5c980e717 | 78 | |
RoHe | 0:5db5c980e717 | 79 | } |
RoHe | 0:5db5c980e717 | 80 | |
RoHe | 0:5db5c980e717 | 81 | // Clean up |
RoHe | 0:5db5c980e717 | 82 | socketTCP1.close(); |
RoHe | 0:5db5c980e717 | 83 | socketTCP2.close(); |
RoHe | 0:5db5c980e717 | 84 | */ |
RoHe | 0:5db5c980e717 | 85 | |
RoHe | 0:5db5c980e717 | 86 | |
RoHe | 0:5db5c980e717 | 87 | |
RoHe | 0:5db5c980e717 | 88 | // Send message to server |
RoHe | 0:5db5c980e717 | 89 | /* |
RoHe | 0:5db5c980e717 | 90 | strcat(s_myIP,"\n\r"); |
RoHe | 0:5db5c980e717 | 91 | pc.printf("Sending message to Server : %s \n\r",s_myIP); |
RoHe | 0:5db5c980e717 | 92 | socketTCP.send_all(s_myIP, sizeof(s_myIP) - 1); |
RoHe | 0:5db5c980e717 | 93 | */ |
RoHe | 0:5db5c980e717 | 94 | /* |
RoHe | 0:5db5c980e717 | 95 | c_myIP = "192.168.1.77\n\r"; |
RoHe | 0:5db5c980e717 | 96 | //strcat(c_myIP,"\n\r"); |
RoHe | 0:5db5c980e717 | 97 | pc.printf("Sending message to Server : %s \n\r",c_myIP); |
RoHe | 0:5db5c980e717 | 98 | socketTCP.send_all(c_myIP, sizeof(c_myIP) - 1); |
RoHe | 0:5db5c980e717 | 99 | */ |
RoHe | 0:5db5c980e717 | 100 | |
RoHe | 0:5db5c980e717 | 101 | //char hello[] = "reply:get:"; |
RoHe | 0:5db5c980e717 | 102 | //char hello2[] = "status:192.168.1.77:door:1\n\r" ; |
RoHe | 0:5db5c980e717 | 103 | //strcat(hello,hello2); |
RoHe | 0:5db5c980e717 | 104 | |
RoHe | 0:5db5c980e717 | 105 | |
RoHe | 0:5db5c980e717 | 106 | //THREADS CSDECLARATION |
RoHe | 0:5db5c980e717 | 107 | //Thread thread2(conect_Server); |
RoHe | 0:5db5c980e717 | 108 | //Thread *thread2; |
RoHe | 0:5db5c980e717 | 109 | //thread2 = new Thread(conect_Server); |
RoHe | 0:5db5c980e717 | 110 | |
RoHe | 0:5db5c980e717 | 111 | |
RoHe | 0:5db5c980e717 | 112 | |
RoHe | 0:5db5c980e717 | 113 | |
RoHe | 0:5db5c980e717 | 114 | //IMPORT FROM LIBRARY |
RoHe | 0:5db5c980e717 | 115 | /* |
RoHe | 0:5db5c980e717 | 116 | cad = driver.echo(); |
RoHe | 0:5db5c980e717 | 117 | pc.printf("libraryECHO: %s\n\r",cad); |
RoHe | 0:5db5c980e717 | 118 | int var = driver.is_good(); |
RoHe | 0:5db5c980e717 | 119 | pc.printf("libraryVAR: %u\n\r",var); |
RoHe | 0:5db5c980e717 | 120 | */ |
RoHe | 0:5db5c980e717 | 121 | |
RoHe | 0:5db5c980e717 | 122 |