bosko lekovic
/
ETHtoCOM_10
nova verzija tcp+udp->serial com
Ethernet/EthernetSetup.cpp@18:5ee53205451a, 2020-05-17 (annotated)
- Committer:
- Bosko Lekovic
- Date:
- Sun May 17 17:16:03 2020 +0200
- Revision:
- 18:5ee53205451a
- Parent:
- 12:cbfc10c15437
- Child:
- 21:2232f5a34eb4
udp i serial zakomentarisani
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bosko Lekovic |
18:5ee53205451a | 1 | #include "mbed.h" |
bosko001 | 2:45b351b4fc2a | 2 | #include "EthernetSetup.h" |
bosko001 | 2:45b351b4fc2a | 3 | #include "clubbing.h" |
bosko001 | 9:893843262a1f | 4 | #include "doHTML.h" |
bosko001 | 2:45b351b4fc2a | 5 | |
Bosko Lekovic |
18:5ee53205451a | 6 | //EthernetInterface eth, *gp_eth= ð |
Bosko Lekovic |
18:5ee53205451a | 7 | EthernetInterface *gp_eth = NULL; |
Bosko Lekovic |
18:5ee53205451a | 8 | |
bosko001 | 9:893843262a1f | 9 | extern C_HTMLparse * gpc_html; |
bosko001 | 2:45b351b4fc2a | 10 | |
bosko001 | 2:45b351b4fc2a | 11 | struct S_EthernetAddress |
bosko001 | 2:45b351b4fc2a | 12 | /*{ |
bosko001 | 2:45b351b4fc2a | 13 | char ip[16]; |
bosko001 | 2:45b351b4fc2a | 14 | char mask[16]; |
bosko001 | 2:45b351b4fc2a | 15 | char gate[16]; |
bosko001 | 2:45b351b4fc2a | 16 | }*/ s_EthAdd = {"192.168.1.20", "255.255.255.0", "192.168.1.1"}, |
bosko001 | 2:45b351b4fc2a | 17 | s_EthAddFlash = {"xxx.168.1.20", "yyy.255.255.0", "zzz.168.1.1"}; |
bosko001 | 2:45b351b4fc2a | 18 | |
bosko001 | 2:45b351b4fc2a | 19 | |
bosko001 | 2:45b351b4fc2a | 20 | |
bosko001 | 2:45b351b4fc2a | 21 | struct S_net |
bosko001 | 2:45b351b4fc2a | 22 | /*{ |
bosko001 | 2:45b351b4fc2a | 23 | struct S_EthernetAddress *ps_ea; |
bosko001 | 2:45b351b4fc2a | 24 | EthernetInterface *p_eth; |
Bosko Lekovic |
18:5ee53205451a | 25 | }*/ s_net = { &s_EthAdd, gp_eth}; |
bosko001 | 2:45b351b4fc2a | 26 | |
bosko001 | 2:45b351b4fc2a | 27 | |
bosko001 | 2:45b351b4fc2a | 28 | nsapi_error_t err; |
bosko001 | 2:45b351b4fc2a | 29 | |
bosko001 | 2:45b351b4fc2a | 30 | int test_EthAdd( struct S_EthernetAddress* ps_ea) |
bosko001 | 2:45b351b4fc2a | 31 | { |
bosko001 | 9:893843262a1f | 32 | |
bosko001 | 2:45b351b4fc2a | 33 | return 1; |
bosko001 | 2:45b351b4fc2a | 34 | } |
bosko001 | 2:45b351b4fc2a | 35 | |
Bosko Lekovic |
18:5ee53205451a | 36 | |
Bosko Lekovic |
18:5ee53205451a | 37 | int getEthernetStatus( void ) |
bosko001 | 9:893843262a1f | 38 | { |
Bosko Lekovic |
18:5ee53205451a | 39 | return gp_eth->get_connection_status(); |
bosko001 | 9:893843262a1f | 40 | } |
bosko001 | 9:893843262a1f | 41 | |
Bosko Lekovic |
18:5ee53205451a | 42 | void ethCancel( void ) |
Bosko Lekovic |
18:5ee53205451a | 43 | { |
Bosko Lekovic |
18:5ee53205451a | 44 | |
Bosko Lekovic |
18:5ee53205451a | 45 | if( gp_eth ) |
Bosko Lekovic |
18:5ee53205451a | 46 | { gp_eth->disconnect(); /* gasenje ethernta */ |
Bosko Lekovic |
18:5ee53205451a | 47 | // delete gp_eth; |
Bosko Lekovic |
18:5ee53205451a | 48 | // gp_eth = NULL; |
Bosko Lekovic |
18:5ee53205451a | 49 | } |
Bosko Lekovic |
18:5ee53205451a | 50 | |
Bosko Lekovic |
18:5ee53205451a | 51 | printf( " Ethernet disconnect-ovan\n\r"); |
Bosko Lekovic |
18:5ee53205451a | 52 | } |
Bosko Lekovic |
18:5ee53205451a | 53 | |
Bosko Lekovic |
18:5ee53205451a | 54 | int ethRiseUp( void ) |
bosko001 | 9:893843262a1f | 55 | { |
Bosko Lekovic |
18:5ee53205451a | 56 | printf("Rise Up\n\r"); |
bosko001 | 9:893843262a1f | 57 | gp_eth = ethernet_setup( ); /*paljenje etherneta*/ |
Bosko Lekovic |
18:5ee53205451a | 58 | if(gp_eth == NULL) { printf("ethernet greska\n\r"); return 0;} |
Bosko Lekovic |
18:5ee53205451a | 59 | else { printf("eth OK\n\r"); return 1;} |
bosko001 | 9:893843262a1f | 60 | } |
bosko001 | 9:893843262a1f | 61 | |
bosko001 | 9:893843262a1f | 62 | void ethRestart( void ) |
bosko001 | 9:893843262a1f | 63 | { |
Bosko Lekovic |
18:5ee53205451a | 64 | do |
Bosko Lekovic |
18:5ee53205451a | 65 | { |
Bosko Lekovic |
18:5ee53205451a | 66 | // thread_sleep_for(5000); |
Bosko Lekovic |
18:5ee53205451a | 67 | printf("Ethernet start\n\r"); fflush(stdout); |
Bosko Lekovic |
18:5ee53205451a | 68 | ethCancel( ); |
Bosko Lekovic |
18:5ee53205451a | 69 | } |
Bosko Lekovic |
18:5ee53205451a | 70 | while( !ethRiseUp( ) ); |
bosko001 | 9:893843262a1f | 71 | } |
bosko001 | 9:893843262a1f | 72 | |
bosko001 | 9:893843262a1f | 73 | |
bosko001 | 9:893843262a1f | 74 | |
bosko001 | 9:893843262a1f | 75 | void do_ethAddr( void ) |
bosko001 | 9:893843262a1f | 76 | { |
bosko001 | 9:893843262a1f | 77 | strcpy( s_net.ps_ea->ip, gpc_html->get_myIP( )); |
bosko001 | 9:893843262a1f | 78 | strcpy( s_net.ps_ea->mask, gpc_html->get_myMASK( )); |
bosko001 | 9:893843262a1f | 79 | strcpy( s_net.ps_ea->gate, gpc_html->get_myGATE( )); |
bosko001 | 9:893843262a1f | 80 | |
bosko001 | 9:893843262a1f | 81 | } |
bosko001 | 9:893843262a1f | 82 | |
bosko001 | 2:45b351b4fc2a | 83 | EthernetInterface * ethernet_setup( void ) |
bosko001 | 2:45b351b4fc2a | 84 | { |
bosko001 | 2:45b351b4fc2a | 85 | // if( (err = eth.disconnect()) != NSAPI_ERROR_OK ) { printf(" greska diskonekcije %d \n\r", err); return 1; } |
bosko001 | 2:45b351b4fc2a | 86 | // ((NetworkInterface *)ð)->set_network("192.168.1.11","255.255.255.0","192.168.1.1"); |
bosko001 | 2:45b351b4fc2a | 87 | |
bosko001 | 9:893843262a1f | 88 | // if( test_EthAdd( &s_EthAddFlash )) { printf("upisana ip adresa sa DataFlash-a\n\r"); } |
bosko001 | 9:893843262a1f | 89 | // else if( test_EthAdd( &s_EthAdd )) { printf("upisana ip adresa sa ProgFlash-a\n\r"); } |
bosko001 | 9:893843262a1f | 90 | // else { printf("neispravne ip adrese!!!\n\r"); return NULL;} |
Bosko Lekovic |
18:5ee53205451a | 91 | printf("ETH setup\n\r"); |
Bosko Lekovic |
18:5ee53205451a | 92 | if( gp_eth == NULL) gp_eth = new EthernetInterface; |
Bosko Lekovic |
18:5ee53205451a | 93 | else |
Bosko Lekovic |
18:5ee53205451a | 94 | { |
Bosko Lekovic |
18:5ee53205451a | 95 | // delete gp_eth; |
Bosko Lekovic |
18:5ee53205451a | 96 | // gp_eth = new EthernetInterface; |
Bosko Lekovic |
18:5ee53205451a | 97 | } |
Bosko Lekovic |
18:5ee53205451a | 98 | printf("novi gp_eth pointer %d\n\r", gp_eth); |
bosko001 | 9:893843262a1f | 99 | do_ethAddr( ); |
Bosko Lekovic |
18:5ee53205451a | 100 | if( (err = gp_eth->set_network(s_net.ps_ea->ip, s_net.ps_ea->mask, s_net.ps_ea->gate))!= NSAPI_ERROR_OK ) { printf(" greska setovanja ethernet mreze %d \n\r", err); } |
bosko001 | 2:45b351b4fc2a | 101 | |
Bosko Lekovic |
18:5ee53205451a | 102 | else if( (err = gp_eth->connect()) != NSAPI_ERROR_OK ) { printf(" greska ethernet konekcije %d \n\r", err); } |
bosko001 | 2:45b351b4fc2a | 103 | |
bosko001 | 2:45b351b4fc2a | 104 | else |
bosko001 | 2:45b351b4fc2a | 105 | { |
bosko001 | 2:45b351b4fc2a | 106 | |
Bosko Lekovic |
18:5ee53205451a | 107 | printf( "MAC adresa: %s\n\r", gp_eth->get_mac_address() ); |
Bosko Lekovic |
18:5ee53205451a | 108 | printf( "IP adresa: %s\n\r", gp_eth->get_ip_address() ); |
Bosko Lekovic |
18:5ee53205451a | 109 | printf( "net mask: %s\n\r", gp_eth->get_netmask() ); |
Bosko Lekovic |
18:5ee53205451a | 110 | printf( "GW adresa: %s\n\r", gp_eth->get_gateway() ); |
bosko001 | 2:45b351b4fc2a | 111 | |
Bosko Lekovic |
18:5ee53205451a | 112 | return gp_eth; |
bosko001 | 2:45b351b4fc2a | 113 | } |
Bosko Lekovic |
18:5ee53205451a | 114 | // delete gp_eth; |
Bosko Lekovic |
18:5ee53205451a | 115 | // return gp_eth = NULL; |
Bosko Lekovic |
18:5ee53205451a | 116 | return NULL; |
bosko001 | 2:45b351b4fc2a | 117 | } |
bosko001 | 2:45b351b4fc2a | 118 | |
bosko001 | 2:45b351b4fc2a | 119 | |
bosko001 | 2:45b351b4fc2a | 120 | |
bosko001 | 2:45b351b4fc2a | 121 | |
bosko001 | 2:45b351b4fc2a | 122 | |
bosko001 | 2:45b351b4fc2a | 123 | |
bosko001 | 2:45b351b4fc2a | 124 | // |
bosko001 | 2:45b351b4fc2a | 125 | //enum nsapi_error { |
bosko001 | 2:45b351b4fc2a | 126 | // NSAPI_ERROR_OK = 0, /*!< no error */ |
bosko001 | 2:45b351b4fc2a | 127 | // NSAPI_ERROR_WOULD_BLOCK = -3001, /*!< no data is not available but call is non-blocking */ |
bosko001 | 2:45b351b4fc2a | 128 | // NSAPI_ERROR_UNSUPPORTED = -3002, /*!< unsupported functionality */ |
bosko001 | 2:45b351b4fc2a | 129 | // NSAPI_ERROR_PARAMETER = -3003, /*!< invalid configuration */ |
bosko001 | 2:45b351b4fc2a | 130 | // NSAPI_ERROR_NO_CONNECTION = -3004, /*!< not connected to a network */ |
bosko001 | 2:45b351b4fc2a | 131 | // NSAPI_ERROR_NO_SOCKET = -3005, /*!< socket not available for use */ |
bosko001 | 2:45b351b4fc2a | 132 | // NSAPI_ERROR_NO_ADDRESS = -3006, /*!< IP address is not known */ |
bosko001 | 2:45b351b4fc2a | 133 | // NSAPI_ERROR_NO_MEMORY = -3007, /*!< memory resource not available */ |
bosko001 | 2:45b351b4fc2a | 134 | // NSAPI_ERROR_NO_SSID = -3008, /*!< ssid not found */ |
bosko001 | 2:45b351b4fc2a | 135 | // NSAPI_ERROR_DNS_FAILURE = -3009, /*!< DNS failed to complete successfully */ |
bosko001 | 2:45b351b4fc2a | 136 | // NSAPI_ERROR_DHCP_FAILURE = -3010, /*!< DHCP failed to complete successfully */ |
bosko001 | 2:45b351b4fc2a | 137 | // NSAPI_ERROR_AUTH_FAILURE = -3011, /*!< connection to access point failed */ |
bosko001 | 2:45b351b4fc2a | 138 | // NSAPI_ERROR_DEVICE_ERROR = -3012, /*!< failure interfacing with the network processor */ |
bosko001 | 2:45b351b4fc2a | 139 | // NSAPI_ERROR_IN_PROGRESS = -3013, /*!< operation (eg connect) in progress */ |
bosko001 | 2:45b351b4fc2a | 140 | // NSAPI_ERROR_ALREADY = -3014, /*!< operation (eg connect) already in progress */ |
bosko001 | 2:45b351b4fc2a | 141 | // NSAPI_ERROR_IS_CONNECTED = -3015, /*!< socket is already connected */ |
bosko001 | 2:45b351b4fc2a | 142 | // NSAPI_ERROR_CONNECTION_LOST = -3016, /*!< connection lost */ |
bosko001 | 2:45b351b4fc2a | 143 | // NSAPI_ERROR_CONNECTION_TIMEOUT = -3017, /*!< connection timed out */ |
bosko001 | 2:45b351b4fc2a | 144 | //}; |