bosko lekovic
/
EthToCom_11
nova proba
UdpClients.cpp@28:49bafc8bb056, 2021-01-18 (annotated)
- Committer:
- Bosko Lekovic
- Date:
- Mon Jan 18 14:46:46 2021 +0100
- Revision:
- 28:49bafc8bb056
- Parent:
- 27:0772451fb880
novije
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bosko Lekovic |
27:0772451fb880 | 1 | #include "mbed.h" |
Bosko Lekovic |
27:0772451fb880 | 2 | #include "platform/mbed_thread.h" |
Bosko Lekovic |
27:0772451fb880 | 3 | #include "clubbing.h" |
Bosko Lekovic |
27:0772451fb880 | 4 | #include "EthernetSetup.h" |
Bosko Lekovic |
27:0772451fb880 | 5 | #include "UdpClients.h" |
Bosko Lekovic |
27:0772451fb880 | 6 | #include "doHTML.h" |
Bosko Lekovic |
27:0772451fb880 | 7 | |
Bosko Lekovic |
27:0772451fb880 | 8 | extern EthernetInterface *gp_eth; |
Bosko Lekovic |
27:0772451fb880 | 9 | extern C_HTMLparse * gpc_html; |
Bosko Lekovic |
27:0772451fb880 | 10 | |
Bosko Lekovic |
27:0772451fb880 | 11 | #if NO_UDP |
Bosko Lekovic |
27:0772451fb880 | 12 | static struct S_EthernetAddress_Remote |
Bosko Lekovic |
27:0772451fb880 | 13 | { |
Bosko Lekovic |
27:0772451fb880 | 14 | char ip[16]; |
Bosko Lekovic |
27:0772451fb880 | 15 | int port; |
Bosko Lekovic |
27:0772451fb880 | 16 | int validy; |
Bosko Lekovic |
27:0772451fb880 | 17 | UDPSocket *p_udpSocket; |
Bosko Lekovic |
27:0772451fb880 | 18 | Thread *p_udpThread; |
Bosko Lekovic |
27:0772451fb880 | 19 | int txError; |
Bosko Lekovic |
27:0772451fb880 | 20 | int rxStatus; |
Bosko Lekovic |
27:0772451fb880 | 21 | |
Bosko Lekovic |
27:0772451fb880 | 22 | } s_EthAddRemote[NO_UDP] , *ps_ear[NO_UDP];// |
Bosko Lekovic |
27:0772451fb880 | 23 | |
Bosko Lekovic |
27:0772451fb880 | 24 | //static UDPSocket *gp_udpSocket[NO_UDP] = {NULL}; |
Bosko Lekovic |
27:0772451fb880 | 25 | //static Thread *gp_udpRxThread[NO_UDP] = {NULL}; |
Bosko Lekovic |
27:0772451fb880 | 26 | #endif |
Bosko Lekovic |
27:0772451fb880 | 27 | |
Bosko Lekovic |
27:0772451fb880 | 28 | static int myUdpPort = 11000; |
Bosko Lekovic |
27:0772451fb880 | 29 | |
Bosko Lekovic |
27:0772451fb880 | 30 | void udpRx_fun( int* par_i ); |
Bosko Lekovic |
27:0772451fb880 | 31 | |
Bosko Lekovic |
27:0772451fb880 | 32 | |
Bosko Lekovic |
27:0772451fb880 | 33 | /************* inicijalizacija parametara **********************/ |
Bosko Lekovic |
27:0772451fb880 | 34 | |
Bosko Lekovic |
27:0772451fb880 | 35 | void init_udp_param( void ) |
Bosko Lekovic |
27:0772451fb880 | 36 | { |
Bosko Lekovic |
27:0772451fb880 | 37 | // memset(ps_ear[0], 0, sizeof(struct S_EthernetAddress_Remote)*NO_UDP); |
Bosko Lekovic |
27:0772451fb880 | 38 | |
Bosko Lekovic |
27:0772451fb880 | 39 | if( test_num(gpc_html->get_myUdpPort( ))) myUdpPort = atoi( gpc_html->get_myUdpPort( )); |
Bosko Lekovic |
27:0772451fb880 | 40 | printf( " myUdpPort = %d\n\r", myUdpPort); |
Bosko Lekovic |
27:0772451fb880 | 41 | #if NO_UDP>0 |
Bosko Lekovic |
27:0772451fb880 | 42 | for( int i=1; i<= NO_UDP; i++) |
Bosko Lekovic |
27:0772451fb880 | 43 | { |
Bosko Lekovic |
27:0772451fb880 | 44 | const char *sp, *sip=gpc_html->get_UdpIP(i); |
Bosko Lekovic |
27:0772451fb880 | 45 | |
Bosko Lekovic |
27:0772451fb880 | 46 | |
Bosko Lekovic |
27:0772451fb880 | 47 | // treba popraviti, IP(4) i IP(5) su opseg adresa |
Bosko Lekovic |
27:0772451fb880 | 48 | if( i < 5 ) sp = gpc_html->get_UdpPort(i); |
Bosko Lekovic |
27:0772451fb880 | 49 | else |
Bosko Lekovic |
27:0772451fb880 | 50 | { |
Bosko Lekovic |
27:0772451fb880 | 51 | sp = gpc_html->get_UdpPort(4); |
Bosko Lekovic |
27:0772451fb880 | 52 | } |
Bosko Lekovic |
27:0772451fb880 | 53 | |
Bosko Lekovic |
27:0772451fb880 | 54 | |
Bosko Lekovic |
27:0772451fb880 | 55 | |
Bosko Lekovic |
27:0772451fb880 | 56 | ps_ear[i-1] = &(s_EthAddRemote[i-1]); |
Bosko Lekovic |
27:0772451fb880 | 57 | |
Bosko Lekovic |
27:0772451fb880 | 58 | if( test_ip( sip ) && test_num( sp ) ) |
Bosko Lekovic |
27:0772451fb880 | 59 | { |
Bosko Lekovic |
27:0772451fb880 | 60 | strncpy( ps_ear[i-1]->ip, sip, 16 ); |
Bosko Lekovic |
27:0772451fb880 | 61 | ps_ear[i-1]->port = atoi( sp ); |
Bosko Lekovic |
27:0772451fb880 | 62 | ps_ear[i-1]->validy = 1; |
Bosko Lekovic |
27:0772451fb880 | 63 | } |
Bosko Lekovic |
27:0772451fb880 | 64 | else |
Bosko Lekovic |
27:0772451fb880 | 65 | { |
Bosko Lekovic |
27:0772451fb880 | 66 | ps_ear[i-1]->validy = 0; |
Bosko Lekovic |
27:0772451fb880 | 67 | } |
Bosko Lekovic |
27:0772451fb880 | 68 | ps_ear[i-1]->rxStatus = 0; |
Bosko Lekovic |
27:0772451fb880 | 69 | |
Bosko Lekovic |
27:0772451fb880 | 70 | //printf(" UDP IP adresa: %s port = %d validy %d\n\r", ps_ear[i-1]->ip, ps_ear[i-1]->port, ps_ear[i-1]->validy ); |
Bosko Lekovic |
27:0772451fb880 | 71 | } |
Bosko Lekovic |
27:0772451fb880 | 72 | #endif |
Bosko Lekovic |
27:0772451fb880 | 73 | } |
Bosko Lekovic |
27:0772451fb880 | 74 | |
Bosko Lekovic |
27:0772451fb880 | 75 | void start_UdpClients( void ) |
Bosko Lekovic |
27:0772451fb880 | 76 | { |
Bosko Lekovic |
27:0772451fb880 | 77 | // start = false; |
Bosko Lekovic |
27:0772451fb880 | 78 | printf( "start UDP clients\n\r"); |
Bosko Lekovic |
27:0772451fb880 | 79 | F |
Bosko Lekovic |
27:0772451fb880 | 80 | init_udp_param( ); |
Bosko Lekovic |
27:0772451fb880 | 81 | |
Bosko Lekovic |
27:0772451fb880 | 82 | for( int i=0; i< NO_UDP; i++) |
Bosko Lekovic |
27:0772451fb880 | 83 | { |
Bosko Lekovic |
27:0772451fb880 | 84 | int *p_i = new int; |
Bosko Lekovic |
27:0772451fb880 | 85 | *p_i = i; |
Bosko Lekovic |
27:0772451fb880 | 86 | ps_ear[i]->p_udpThread = new Thread; |
Bosko Lekovic |
27:0772451fb880 | 87 | ps_ear[i]->p_udpThread->start(callback( udpRx_fun, p_i)); |
Bosko Lekovic |
27:0772451fb880 | 88 | // printf(" UDP Clients start: Thread[%d]=%d\n\r", i, ps_ear[i]->p_udpThread ); |
Bosko Lekovic |
27:0772451fb880 | 89 | |
Bosko Lekovic |
27:0772451fb880 | 90 | } |
Bosko Lekovic |
27:0772451fb880 | 91 | } |
Bosko Lekovic |
27:0772451fb880 | 92 | |
Bosko Lekovic |
27:0772451fb880 | 93 | |
Bosko Lekovic |
27:0772451fb880 | 94 | /***************** Predaja na UDP ****************************/ |
Bosko Lekovic |
27:0772451fb880 | 95 | |
Bosko Lekovic |
27:0772451fb880 | 96 | |
Bosko Lekovic |
27:0772451fb880 | 97 | void sendUdpi( int i, char *buffer, int val ) |
Bosko Lekovic |
27:0772451fb880 | 98 | { |
Bosko Lekovic |
27:0772451fb880 | 99 | #if NO_UDP>0 |
Bosko Lekovic |
27:0772451fb880 | 100 | if( ps_ear[i]->p_udpSocket && ps_ear[i]->validy && (ps_ear[i]->rxStatus == 3)) |
Bosko Lekovic |
27:0772451fb880 | 101 | { |
Bosko Lekovic |
27:0772451fb880 | 102 | ps_ear[i]->txError = ps_ear[i]->p_udpSocket->sendto(ps_ear[i]->ip, ps_ear[i]->port, (const uint8_t*)buffer, val); |
Bosko Lekovic |
27:0772451fb880 | 103 | //thread_sleep_for(1);//wait(0.001); |
Bosko Lekovic |
27:0772451fb880 | 104 | |
Bosko Lekovic |
27:0772451fb880 | 105 | // printf(" UDPpaket ip=%s port=%d val=%d err=%d stat=%d\n\r", ps_ear[i]->ip, ps_ear[i]->port, val, ps_ear[i]->txError , getEthernetStatus( ) ); |
Bosko Lekovic |
27:0772451fb880 | 106 | } |
Bosko Lekovic |
27:0772451fb880 | 107 | else printf("UDPsocket[%d] == NULL\n\r", i); |
Bosko Lekovic |
27:0772451fb880 | 108 | #endif |
Bosko Lekovic |
27:0772451fb880 | 109 | } |
Bosko Lekovic |
27:0772451fb880 | 110 | |
Bosko Lekovic |
27:0772451fb880 | 111 | void sendToUdp( char *buffer, int val ) |
Bosko Lekovic |
27:0772451fb880 | 112 | { |
Bosko Lekovic |
27:0772451fb880 | 113 | |
Bosko Lekovic |
27:0772451fb880 | 114 | #if NO_UDP>0 |
Bosko Lekovic |
27:0772451fb880 | 115 | ThisThread::yield(); |
Bosko Lekovic |
27:0772451fb880 | 116 | for( int i=0; i< NO_UDP; i++ ) |
Bosko Lekovic |
27:0772451fb880 | 117 | if( ps_ear[i]->validy ) { sendUdpi( i, buffer, val ); ThisThread::yield();} |
Bosko Lekovic |
27:0772451fb880 | 118 | #endif |
Bosko Lekovic |
27:0772451fb880 | 119 | } |
Bosko Lekovic |
27:0772451fb880 | 120 | |
Bosko Lekovic |
27:0772451fb880 | 121 | |
Bosko Lekovic |
27:0772451fb880 | 122 | |
Bosko Lekovic |
27:0772451fb880 | 123 | /*************** Prijem na UDP socket i predaja na Serial com ***************/ |
Bosko Lekovic |
27:0772451fb880 | 124 | |
Bosko Lekovic |
27:0772451fb880 | 125 | void udpRx_fun( int* par_i ) |
Bosko Lekovic |
27:0772451fb880 | 126 | { |
Bosko Lekovic |
27:0772451fb880 | 127 | int i = *par_i; |
Bosko Lekovic |
27:0772451fb880 | 128 | free(par_i); |
Bosko Lekovic |
27:0772451fb880 | 129 | |
Bosko Lekovic |
27:0772451fb880 | 130 | // nsapi_error_t err; |
Bosko Lekovic |
27:0772451fb880 | 131 | char inbuff[1500]; |
Bosko Lekovic |
27:0772451fb880 | 132 | |
Bosko Lekovic |
27:0772451fb880 | 133 | // printf("udpRxThread[%d] inicijalizovan \n\r",i); |
Bosko Lekovic |
27:0772451fb880 | 134 | |
Bosko Lekovic |
27:0772451fb880 | 135 | while( !(ThisThread::flags_get() & 4)) |
Bosko Lekovic |
27:0772451fb880 | 136 | { |
Bosko Lekovic |
27:0772451fb880 | 137 | ps_ear[i]->rxStatus=1; |
Bosko Lekovic |
27:0772451fb880 | 138 | nsapi_error_t err; |
Bosko Lekovic |
27:0772451fb880 | 139 | |
Bosko Lekovic |
27:0772451fb880 | 140 | if( ps_ear[i]->validy) |
Bosko Lekovic |
27:0772451fb880 | 141 | { |
Bosko Lekovic |
27:0772451fb880 | 142 | UDPSocket *p_sock = ps_ear[i]->p_udpSocket = new UDPSocket; |
Bosko Lekovic |
27:0772451fb880 | 143 | // printf("\n\rudpClient[%d]: novi UDP socket %x\n\r", i, p_sock); |
Bosko Lekovic |
27:0772451fb880 | 144 | |
Bosko Lekovic |
27:0772451fb880 | 145 | while( !(ThisThread::flags_get() & 2) ) |
Bosko Lekovic |
27:0772451fb880 | 146 | { |
Bosko Lekovic |
27:0772451fb880 | 147 | ps_ear[i]->rxStatus = 2; |
Bosko Lekovic |
27:0772451fb880 | 148 | if( (err= p_sock->open(gp_eth)) == NSAPI_ERROR_OK ) |
Bosko Lekovic |
27:0772451fb880 | 149 | { |
Bosko Lekovic |
27:0772451fb880 | 150 | char *ip = ps_ear[i]->ip; |
Bosko Lekovic |
27:0772451fb880 | 151 | int port = ps_ear[i]->port; |
Bosko Lekovic |
27:0772451fb880 | 152 | signed int n=0; |
Bosko Lekovic |
27:0772451fb880 | 153 | p_sock->bind( port ); |
Bosko Lekovic |
27:0772451fb880 | 154 | //!!! p_sock->set_timeout(100); |
Bosko Lekovic |
27:0772451fb880 | 155 | ps_ear[i]->rxStatus = 3; |
Bosko Lekovic |
27:0772451fb880 | 156 | sendToUdp( (char*)"Hallo Marko\n\r", 13 ); |
Bosko Lekovic |
27:0772451fb880 | 157 | while( !(ThisThread::flags_get( ) & 1) ) |
Bosko Lekovic |
27:0772451fb880 | 158 | { |
Bosko Lekovic |
27:0772451fb880 | 159 | SocketAddress sockAddr; |
Bosko Lekovic |
27:0772451fb880 | 160 | |
Bosko Lekovic |
27:0772451fb880 | 161 | ps_ear[i]->rxStatus = 3; |
Bosko Lekovic |
27:0772451fb880 | 162 | if( (n>=0) ) |
Bosko Lekovic |
27:0772451fb880 | 163 | { |
Bosko Lekovic |
27:0772451fb880 | 164 | n = p_sock->recvfrom(&sockAddr, &inbuff, sizeof(inbuff)); |
Bosko Lekovic |
27:0772451fb880 | 165 | |
Bosko Lekovic |
27:0772451fb880 | 166 | if(n>0) { extern void sendToScom( char *buffer, int val ); sendToScom( inbuff, n); } |
Bosko Lekovic |
27:0772451fb880 | 167 | //!!! else if(n==-3001) n = 0; |
Bosko Lekovic |
27:0772451fb880 | 168 | else |
Bosko Lekovic |
27:0772451fb880 | 169 | { |
Bosko Lekovic |
27:0772451fb880 | 170 | printf( "udpClient[%d]: Greska na prijemu = %d BREAK!\n\r", i, n); |
Bosko Lekovic |
27:0772451fb880 | 171 | break; |
Bosko Lekovic |
27:0772451fb880 | 172 | } |
Bosko Lekovic |
27:0772451fb880 | 173 | } |
Bosko Lekovic |
27:0772451fb880 | 174 | }// while 1 |
Bosko Lekovic |
27:0772451fb880 | 175 | ps_ear[i]->rxStatus = 2; |
Bosko Lekovic |
27:0772451fb880 | 176 | ThisThread::flags_clear(1); |
Bosko Lekovic |
27:0772451fb880 | 177 | //!!! p_sock->set_timeout(-1); |
Bosko Lekovic |
27:0772451fb880 | 178 | p_sock->close(); |
Bosko Lekovic |
27:0772451fb880 | 179 | } // open socket |
Bosko Lekovic |
27:0772451fb880 | 180 | else printf("udpClient[%d]: greska otvaranja soketa err=%d \n\r",i, err); |
Bosko Lekovic |
27:0772451fb880 | 181 | thread_sleep_for(1000); // dremni pre ponovnog pokusaja konekcije |
Bosko Lekovic |
27:0772451fb880 | 182 | break; // izlaz iz while 2, brisanje socket-a i ponovno otvaranje |
Bosko Lekovic |
27:0772451fb880 | 183 | } // while 2 |
Bosko Lekovic |
27:0772451fb880 | 184 | ps_ear[i]->rxStatus = 1; |
Bosko Lekovic |
27:0772451fb880 | 185 | ThisThread::flags_clear(2); |
Bosko Lekovic |
27:0772451fb880 | 186 | printf("udpClient[%d]:___zatvaranje UDP socket= %x\n\r",i, p_sock); |
Bosko Lekovic |
27:0772451fb880 | 187 | delete p_sock; |
Bosko Lekovic |
27:0772451fb880 | 188 | p_sock = NULL; |
Bosko Lekovic |
27:0772451fb880 | 189 | thread_sleep_for(1000); // dremni pre ponovnog konstrukcije socketa |
Bosko Lekovic |
27:0772451fb880 | 190 | |
Bosko Lekovic |
27:0772451fb880 | 191 | } // validy |
Bosko Lekovic |
27:0772451fb880 | 192 | } // while 4 |
Bosko Lekovic |
27:0772451fb880 | 193 | ThisThread::flags_clear(4); |
Bosko Lekovic |
27:0772451fb880 | 194 | ps_ear[i]->rxStatus = 0; |
Bosko Lekovic |
27:0772451fb880 | 195 | printf("udpClient[%d]: izlaz iz rxThread-a\n\r",i); |
Bosko Lekovic |
27:0772451fb880 | 196 | fflush(stdout); |
Bosko Lekovic |
27:0772451fb880 | 197 | } |
Bosko Lekovic |
27:0772451fb880 | 198 | |
Bosko Lekovic |
27:0772451fb880 | 199 | |
Bosko Lekovic |
27:0772451fb880 | 200 | void restart_UdpClientConnection( int noClient, int restartType ) |
Bosko Lekovic |
27:0772451fb880 | 201 | { |
Bosko Lekovic |
27:0772451fb880 | 202 | if( (noClient < NO_UDP) && (restartType <= (1+2+4)) ) |
Bosko Lekovic |
27:0772451fb880 | 203 | { |
Bosko Lekovic |
27:0772451fb880 | 204 | ps_ear[noClient]->p_udpThread->flags_set(restartType); |
Bosko Lekovic |
27:0772451fb880 | 205 | if( restartType & 4 ) |
Bosko Lekovic |
27:0772451fb880 | 206 | { |
Bosko Lekovic |
27:0772451fb880 | 207 | ps_ear[noClient]->p_udpThread->join(); |
Bosko Lekovic |
27:0772451fb880 | 208 | printf("UDP Client Thread[%d]=%d zavrsen\n\r",noClient, ps_ear[noClient]->p_udpThread); |
Bosko Lekovic |
27:0772451fb880 | 209 | } |
Bosko Lekovic |
27:0772451fb880 | 210 | } |
Bosko Lekovic |
27:0772451fb880 | 211 | } |
Bosko Lekovic |
27:0772451fb880 | 212 | |
Bosko Lekovic |
27:0772451fb880 | 213 | void restart_UdpClientsConnection( int restartType ) |
Bosko Lekovic |
27:0772451fb880 | 214 | { |
Bosko Lekovic |
27:0772451fb880 | 215 | init_udp_param( ); |
Bosko Lekovic |
27:0772451fb880 | 216 | for(int i=0; i<NO_UDP; i++) |
Bosko Lekovic |
27:0772451fb880 | 217 | { |
Bosko Lekovic |
27:0772451fb880 | 218 | if(ps_ear[i]->rxStatus) |
Bosko Lekovic |
27:0772451fb880 | 219 | restart_UdpClientConnection( i, restartType); |
Bosko Lekovic |
27:0772451fb880 | 220 | } |
Bosko Lekovic |
27:0772451fb880 | 221 | } |
Bosko Lekovic |
27:0772451fb880 | 222 | |
Bosko Lekovic |
27:0772451fb880 | 223 | void restart_UdpClients( void ) |
Bosko Lekovic |
27:0772451fb880 | 224 | { |
Bosko Lekovic |
27:0772451fb880 | 225 | restart_UdpClientsConnection(7); |
Bosko Lekovic |
27:0772451fb880 | 226 | start_UdpClients(); |
Bosko Lekovic |
27:0772451fb880 | 227 | } |
Bosko Lekovic |
27:0772451fb880 | 228 | |
Bosko Lekovic |
27:0772451fb880 | 229 | |
Bosko Lekovic |
27:0772451fb880 | 230 | |
Bosko Lekovic |
27:0772451fb880 | 231 | |
Bosko Lekovic |
27:0772451fb880 | 232 | |
Bosko Lekovic |
27:0772451fb880 | 233 | |
Bosko Lekovic |
27:0772451fb880 | 234 | // /* staro */ |
Bosko Lekovic |
27:0772451fb880 | 235 | // void udpRxThreadsCancel( void ) |
Bosko Lekovic |
27:0772451fb880 | 236 | // { |
Bosko Lekovic |
27:0772451fb880 | 237 | // /* Gasenje UDP threada */ |
Bosko Lekovic |
27:0772451fb880 | 238 | |
Bosko Lekovic |
27:0772451fb880 | 239 | // #if NO_UDP>0 |
Bosko Lekovic |
27:0772451fb880 | 240 | // for(int i =0; i<NO_UDP; i++ ) |
Bosko Lekovic |
27:0772451fb880 | 241 | // { |
Bosko Lekovic |
27:0772451fb880 | 242 | // if(ps_ear[i]->validy ) |
Bosko Lekovic |
27:0772451fb880 | 243 | // { |
Bosko Lekovic |
27:0772451fb880 | 244 | // if( gp_udpRxThread[i] ) |
Bosko Lekovic |
27:0772451fb880 | 245 | // { |
Bosko Lekovic |
27:0772451fb880 | 246 | // if( gp_udpRxThread[i]->get_state( ) && gp_udpRxThread[i]->get_state( )<16 ) |
Bosko Lekovic |
27:0772451fb880 | 247 | // gp_udpRxThread[i]->flags_set( 1 ); |
Bosko Lekovic |
27:0772451fb880 | 248 | // gp_udpRxThread[i]->join( ); |
Bosko Lekovic |
27:0772451fb880 | 249 | |
Bosko Lekovic |
27:0772451fb880 | 250 | // delete gp_udpRxThread[i]; |
Bosko Lekovic |
27:0772451fb880 | 251 | // gp_udpRxThread[i] = NULL; |
Bosko Lekovic |
27:0772451fb880 | 252 | // } |
Bosko Lekovic |
27:0772451fb880 | 253 | // } |
Bosko Lekovic |
27:0772451fb880 | 254 | |
Bosko Lekovic |
27:0772451fb880 | 255 | // printf("udp thread[%d] zavrsio\n\r", i); |
Bosko Lekovic |
27:0772451fb880 | 256 | // ps_ear[i]->validy = 0; |
Bosko Lekovic |
27:0772451fb880 | 257 | |
Bosko Lekovic |
27:0772451fb880 | 258 | // // !!!!! ugasiti i sockete |
Bosko Lekovic |
27:0772451fb880 | 259 | // } |
Bosko Lekovic |
27:0772451fb880 | 260 | // #endif |
Bosko Lekovic |
27:0772451fb880 | 261 | // } |
Bosko Lekovic |
27:0772451fb880 | 262 | |
Bosko Lekovic |
27:0772451fb880 | 263 | // void udpRxThreadsRiseUp( void ) |
Bosko Lekovic |
27:0772451fb880 | 264 | // { |
Bosko Lekovic |
27:0772451fb880 | 265 | // /* paljenje UDP thread-a */ |
Bosko Lekovic |
27:0772451fb880 | 266 | // #if NO_UDP>0 |
Bosko Lekovic |
27:0772451fb880 | 267 | |
Bosko Lekovic |
27:0772451fb880 | 268 | // nsapi_error_t err; |
Bosko Lekovic |
27:0772451fb880 | 269 | |
Bosko Lekovic |
27:0772451fb880 | 270 | // init_udp_param( ); |
Bosko Lekovic |
27:0772451fb880 | 271 | |
Bosko Lekovic |
27:0772451fb880 | 272 | // for(int i =0; i<NO_UDP; i++ ) |
Bosko Lekovic |
27:0772451fb880 | 273 | // if( ps_ear[i]->validy ) |
Bosko Lekovic |
27:0772451fb880 | 274 | // { |
Bosko Lekovic |
27:0772451fb880 | 275 | |
Bosko Lekovic |
27:0772451fb880 | 276 | |
Bosko Lekovic |
27:0772451fb880 | 277 | // gp_udpSocket[i] = new UDPSocket; |
Bosko Lekovic |
27:0772451fb880 | 278 | // printf("___novi UDP socket[%d] %x\n\r", i, gp_udpSocket[i]); |
Bosko Lekovic |
27:0772451fb880 | 279 | |
Bosko Lekovic |
27:0772451fb880 | 280 | // if( (err = gp_udpSocket[i]->open( gp_eth )) != NSAPI_ERROR_OK ) |
Bosko Lekovic |
27:0772451fb880 | 281 | // { printf(" greska otvaranja UDP soketa %d err=%d \n\r", i, err); |
Bosko Lekovic |
27:0772451fb880 | 282 | // gp_udpSocket[i] = NULL; |
Bosko Lekovic |
27:0772451fb880 | 283 | // gp_udpRxThread[i] = NULL; |
Bosko Lekovic |
27:0772451fb880 | 284 | // break; |
Bosko Lekovic |
27:0772451fb880 | 285 | // } |
Bosko Lekovic |
27:0772451fb880 | 286 | // gp_udpSocket[i]->bind(/* ps_ear[0]->port*/ myUdpPort); |
Bosko Lekovic |
27:0772451fb880 | 287 | // gp_udpSocket[i]->set_timeout(100); |
Bosko Lekovic |
27:0772451fb880 | 288 | // int *p_i = (int*)malloc(sizeof(int)); |
Bosko Lekovic |
27:0772451fb880 | 289 | // *p_i = i; |
Bosko Lekovic |
27:0772451fb880 | 290 | // gp_udpRxThread[i] = new Thread; |
Bosko Lekovic |
27:0772451fb880 | 291 | // gp_udpRxThread[i]->start( callback( udpRx_fun, p_i) ); |
Bosko Lekovic |
27:0772451fb880 | 292 | // printf( "startuje udpRxThread [%d] =%x\n\r", i, &gp_udpRxThread[i] ); |
Bosko Lekovic |
27:0772451fb880 | 293 | // } |
Bosko Lekovic |
27:0772451fb880 | 294 | // // gp_udpRxThread[i]->start( callback( udpRx_fun, &i ) ); |
Bosko Lekovic |
27:0772451fb880 | 295 | // // |
Bosko Lekovic |
27:0772451fb880 | 296 | // #endif |
Bosko Lekovic |
27:0772451fb880 | 297 | // } |
Bosko Lekovic |
27:0772451fb880 | 298 | |
Bosko Lekovic |
27:0772451fb880 | 299 | // void udpRxThreadsRestart( void ) |
Bosko Lekovic |
27:0772451fb880 | 300 | // { |
Bosko Lekovic |
27:0772451fb880 | 301 | // printf("gasi udp\n\r"); fflush(stdout); |
Bosko Lekovic |
27:0772451fb880 | 302 | // udpRxThreadsCancel( ); |
Bosko Lekovic |
27:0772451fb880 | 303 | // printf("pali udp\n\r"); fflush(stdout); |
Bosko Lekovic |
27:0772451fb880 | 304 | // udpRxThreadsRiseUp( ); |
Bosko Lekovic |
27:0772451fb880 | 305 | // } |
Bosko Lekovic |
27:0772451fb880 | 306 |