bosko lekovic
/
ETHtoCOM_10
nova verzija tcp+udp->serial com
UdpToScom.cpp@9:893843262a1f, 2020-04-22 (annotated)
- Committer:
- bosko001
- Date:
- Wed Apr 22 13:21:50 2020 +0000
- Revision:
- 9:893843262a1f
- Parent:
- 2:45b351b4fc2a
- Child:
- 10:15f7fea18a2f
novo 22.04.2020.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bosko001 | 2:45b351b4fc2a | 1 | #include "mbed.h" |
bosko001 | 2:45b351b4fc2a | 2 | #include "clubbing.h" |
bosko001 | 2:45b351b4fc2a | 3 | #include "UdpToScom.h" |
bosko001 | 2:45b351b4fc2a | 4 | #include "EthernetSetup.h" |
bosko001 | 9:893843262a1f | 5 | #include "Udp.h" |
bosko001 | 9:893843262a1f | 6 | #include "SerialCom.h" |
bosko001 | 2:45b351b4fc2a | 7 | |
bosko001 | 2:45b351b4fc2a | 8 | |
bosko001 | 2:45b351b4fc2a | 9 | struct S_EthernetAddress_Remote |
bosko001 | 2:45b351b4fc2a | 10 | /*{ |
bosko001 | 2:45b351b4fc2a | 11 | char ip[16]; |
bosko001 | 2:45b351b4fc2a | 12 | int port; |
bosko001 | 9:893843262a1f | 13 | }*/ //s_EthAddRemote = {"192.168.1.14", 13000 }, *ps_ear = &s_EthAddRemote, |
bosko001 | 2:45b351b4fc2a | 14 | s_EthAddBroadcast = {"0.0.0.0", 13000 }, *ps_eab = &s_EthAddBroadcast; |
bosko001 | 2:45b351b4fc2a | 15 | |
bosko001 | 2:45b351b4fc2a | 16 | |
bosko001 | 2:45b351b4fc2a | 17 | /* globalni pointeri*/ |
bosko001 | 2:45b351b4fc2a | 18 | |
bosko001 | 2:45b351b4fc2a | 19 | |
bosko001 | 9:893843262a1f | 20 | extern EthernetInterface *gp_eth; |
bosko001 | 2:45b351b4fc2a | 21 | |
bosko001 | 2:45b351b4fc2a | 22 | |
bosko001 | 2:45b351b4fc2a | 23 | |
bosko001 | 2:45b351b4fc2a | 24 | /******************* Broadcast thread **********************/ |
bosko001 | 2:45b351b4fc2a | 25 | Thread udpBroadcast_thread; |
bosko001 | 2:45b351b4fc2a | 26 | void udpBroadcast_fun( void ) |
bosko001 | 2:45b351b4fc2a | 27 | { |
bosko001 | 2:45b351b4fc2a | 28 | while(true) |
bosko001 | 2:45b351b4fc2a | 29 | { |
bosko001 | 9:893843262a1f | 30 | // sendUdp( ps_eab, (char *)"test broadcast", 14); |
bosko001 | 2:45b351b4fc2a | 31 | wait(5); |
bosko001 | 2:45b351b4fc2a | 32 | } |
bosko001 | 2:45b351b4fc2a | 33 | } |
bosko001 | 2:45b351b4fc2a | 34 | |
bosko001 | 2:45b351b4fc2a | 35 | |
bosko001 | 2:45b351b4fc2a | 36 | |
bosko001 | 2:45b351b4fc2a | 37 | void inic_1(void) |
bosko001 | 2:45b351b4fc2a | 38 | { |
bosko001 | 2:45b351b4fc2a | 39 | |
bosko001 | 2:45b351b4fc2a | 40 | printf("\n\r -------- REINICIJALIZACIJA ------------- \n\r"); |
bosko001 | 2:45b351b4fc2a | 41 | |
bosko001 | 2:45b351b4fc2a | 42 | /* Gasenje UDP threada */ |
bosko001 | 9:893843262a1f | 43 | // if( gp_udpRxThread->get_state( ) && gp_udpRxThread->get_state( )<16 ) |
bosko001 | 9:893843262a1f | 44 | // gp_udpRxThread->flags_set( 1 ); |
bosko001 | 9:893843262a1f | 45 | // gp_udpRxThread->join( ); |
bosko001 | 9:893843262a1f | 46 | // if(gp_udpRxThread) {delete gp_udpRxThread; gp_udpRxThread = NULL;} |
bosko001 | 9:893843262a1f | 47 | // printf("udp thread zavrsio\n\r"); |
bosko001 | 2:45b351b4fc2a | 48 | |
bosko001 | 9:893843262a1f | 49 | udpRxThreadCancel( ); |
bosko001 | 9:893843262a1f | 50 | |
bosko001 | 2:45b351b4fc2a | 51 | /* gasenje serial com thread-a */ |
bosko001 | 9:893843262a1f | 52 | // int st = gp_scomRxThread->get_state(); |
bosko001 | 9:893843262a1f | 53 | // if( st && st<16 )gp_scomRxThread->flags_set(1); |
bosko001 | 9:893843262a1f | 54 | // gp_scomRxThread->join(); |
bosko001 | 9:893843262a1f | 55 | // printf("ScomRx Thread upravo zavrsio\n\r"); |
bosko001 | 9:893843262a1f | 56 | // if(gp_scomRxThread) { delete gp_scomRxThread; gp_scomRxThread = NULL;} |
bosko001 | 9:893843262a1f | 57 | scomRxThreadCancel( ); |
bosko001 | 2:45b351b4fc2a | 58 | |
bosko001 | 2:45b351b4fc2a | 59 | gp_eth->disconnect(); /* gasenje ethernta */ |
bosko001 | 2:45b351b4fc2a | 60 | |
bosko001 | 2:45b351b4fc2a | 61 | gp_eth = ethernet_setup( ); /*paljenje etherneta*/ |
bosko001 | 2:45b351b4fc2a | 62 | if(gp_eth == NULL) printf("ethernet greska\n\r"); |
bosko001 | 2:45b351b4fc2a | 63 | else printf("eth OK\n\r"); |
bosko001 | 2:45b351b4fc2a | 64 | |
bosko001 | 2:45b351b4fc2a | 65 | /* paljenje UDP thread-a */ |
bosko001 | 9:893843262a1f | 66 | // gp_udpRxThread = new Thread( udpRx_fun ); |
bosko001 | 9:893843262a1f | 67 | // udpRxThreadRiseUp( ); |
bosko001 | 2:45b351b4fc2a | 68 | |
bosko001 | 2:45b351b4fc2a | 69 | |
bosko001 | 9:893843262a1f | 70 | // /* paljenje serial com thread-a */ |
bosko001 | 9:893843262a1f | 71 | // gp_scomRxThread = new Thread(scomrx_fun); |
bosko001 | 9:893843262a1f | 72 | scomRxThreadRiseUp( ); |
bosko001 | 2:45b351b4fc2a | 73 | |
bosko001 | 2:45b351b4fc2a | 74 | |
bosko001 | 2:45b351b4fc2a | 75 | // |
bosko001 | 2:45b351b4fc2a | 76 | fflush(stdout); |
bosko001 | 2:45b351b4fc2a | 77 | |
bosko001 | 2:45b351b4fc2a | 78 | } |
bosko001 | 2:45b351b4fc2a | 79 | |
bosko001 | 2:45b351b4fc2a | 80 | void init_EthToScom( void ) |
bosko001 | 2:45b351b4fc2a | 81 | { |
bosko001 | 2:45b351b4fc2a | 82 | gp_eth = ethernet_setup( ); |
bosko001 | 2:45b351b4fc2a | 83 | |
bosko001 | 2:45b351b4fc2a | 84 | if(gp_eth == NULL) printf("ethernet greska"); |
bosko001 | 2:45b351b4fc2a | 85 | else printf("eth OK\n\r"); |
bosko001 | 2:45b351b4fc2a | 86 | |
bosko001 | 2:45b351b4fc2a | 87 | |
bosko001 | 9:893843262a1f | 88 | // if(gp_scomRxThread) delete gp_scomRxThread; |
bosko001 | 9:893843262a1f | 89 | // gp_scomRxThread = new Thread(scomrx_fun); |
bosko001 | 9:893843262a1f | 90 | scomRxThreadRiseUp( ); |
bosko001 | 2:45b351b4fc2a | 91 | |
bosko001 | 2:45b351b4fc2a | 92 | |
bosko001 | 2:45b351b4fc2a | 93 | /* |
bosko001 | 2:45b351b4fc2a | 94 | TCPSocket socket; |
bosko001 | 2:45b351b4fc2a | 95 | socket.open(ð); |
bosko001 | 2:45b351b4fc2a | 96 | socket.connect( |
bosko001 | 2:45b351b4fc2a | 97 | */ |
bosko001 | 2:45b351b4fc2a | 98 | |
bosko001 | 2:45b351b4fc2a | 99 | |
bosko001 | 9:893843262a1f | 100 | // gp_udpRxThread = new Thread( udpRx_fun ); |
bosko001 | 9:893843262a1f | 101 | udpRxThreadRiseUp( ); |
bosko001 | 2:45b351b4fc2a | 102 | |
bosko001 | 2:45b351b4fc2a | 103 | } |