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