bosko lekovic
/
EthToCom_11
nova proba
Ethernet/EthernetSetup.cpp@5:c9a908749d4c, 2020-04-12 (annotated)
- Committer:
- bosko001
- Date:
- Sun Apr 12 17:59:57 2020 +0000
- Revision:
- 5:c9a908749d4c
- Parent:
- EthernetSetup.cpp@4:7abcf4543282
- Child:
- 9:893843262a1f
12.04.2020; napravljena class C_HTMLparse; treba napraviti obradu POST upita
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 | 2:45b351b4fc2a | 3 | |
bosko001 | 2:45b351b4fc2a | 4 | |
bosko001 | 2:45b351b4fc2a | 5 | EthernetInterface eth; |
bosko001 | 2:45b351b4fc2a | 6 | |
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 | 2:45b351b4fc2a | 29 | if( !(test_ip(ps_ea->ip)) ) { printf("pogresan ip: %s\n\r", ps_ea->ip); return 0; } |
bosko001 | 2:45b351b4fc2a | 30 | if( !(test_ip(ps_ea->mask)) ) { printf("pogresna maska: %s\r\n", ps_ea->mask); return 0; } |
bosko001 | 2:45b351b4fc2a | 31 | if( !(test_ip(ps_ea->gate)) ) { printf("pogresan gate: %s\n\r", ps_ea->gate); return 0; } |
bosko001 | 2:45b351b4fc2a | 32 | return 1; |
bosko001 | 2:45b351b4fc2a | 33 | } |
bosko001 | 2:45b351b4fc2a | 34 | |
bosko001 | 2:45b351b4fc2a | 35 | EthernetInterface * ethernet_setup( void ) |
bosko001 | 2:45b351b4fc2a | 36 | { |
bosko001 | 2:45b351b4fc2a | 37 | // if( (err = eth.disconnect()) != NSAPI_ERROR_OK ) { printf(" greska diskonekcije %d \n\r", err); return 1; } |
bosko001 | 2:45b351b4fc2a | 38 | // ((NetworkInterface *)ð)->set_network("192.168.1.11","255.255.255.0","192.168.1.1"); |
bosko001 | 2:45b351b4fc2a | 39 | |
bosko001 | 2:45b351b4fc2a | 40 | if( test_EthAdd( &s_EthAddFlash )) { printf("upisana ip adresa sa DataFlash-a\n\r"); } |
bosko001 | 2:45b351b4fc2a | 41 | else if( test_EthAdd( &s_EthAdd )) { printf("upisana ip adresa sa ProgFlash-a\n\r"); } |
bosko001 | 2:45b351b4fc2a | 42 | else { printf("neispravne ip adrese!!!\n\r"); return NULL;} |
bosko001 | 2:45b351b4fc2a | 43 | |
bosko001 | 2:45b351b4fc2a | 44 | 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 | 45 | |
bosko001 | 2:45b351b4fc2a | 46 | else if( (err = s_net.p_eth->connect()) != NSAPI_ERROR_OK ) { printf(" greska konekcije %d \n\r", err); } |
bosko001 | 2:45b351b4fc2a | 47 | |
bosko001 | 2:45b351b4fc2a | 48 | else |
bosko001 | 2:45b351b4fc2a | 49 | { |
bosko001 | 2:45b351b4fc2a | 50 | |
bosko001 | 2:45b351b4fc2a | 51 | printf( "MAC adresa: %s\n\r", s_net.p_eth->get_mac_address() ); |
bosko001 | 2:45b351b4fc2a | 52 | printf( "IP adresa: %s\n\r", s_net.p_eth->get_ip_address() ); |
bosko001 | 2:45b351b4fc2a | 53 | printf( "net mask: %s\n\r", s_net.p_eth->get_netmask() ); |
bosko001 | 2:45b351b4fc2a | 54 | printf( "GW adresa: %s\n\r", s_net.p_eth->get_gateway() ); |
bosko001 | 2:45b351b4fc2a | 55 | |
bosko001 | 2:45b351b4fc2a | 56 | return s_net.p_eth; |
bosko001 | 2:45b351b4fc2a | 57 | } |
bosko001 | 2:45b351b4fc2a | 58 | return NULL; |
bosko001 | 2:45b351b4fc2a | 59 | } |
bosko001 | 2:45b351b4fc2a | 60 | |
bosko001 | 2:45b351b4fc2a | 61 | |
bosko001 | 2:45b351b4fc2a | 62 | |
bosko001 | 2:45b351b4fc2a | 63 | |
bosko001 | 2:45b351b4fc2a | 64 | |
bosko001 | 2:45b351b4fc2a | 65 | |
bosko001 | 2:45b351b4fc2a | 66 | // |
bosko001 | 2:45b351b4fc2a | 67 | //enum nsapi_error { |
bosko001 | 2:45b351b4fc2a | 68 | // NSAPI_ERROR_OK = 0, /*!< no error */ |
bosko001 | 2:45b351b4fc2a | 69 | // NSAPI_ERROR_WOULD_BLOCK = -3001, /*!< no data is not available but call is non-blocking */ |
bosko001 | 2:45b351b4fc2a | 70 | // NSAPI_ERROR_UNSUPPORTED = -3002, /*!< unsupported functionality */ |
bosko001 | 2:45b351b4fc2a | 71 | // NSAPI_ERROR_PARAMETER = -3003, /*!< invalid configuration */ |
bosko001 | 2:45b351b4fc2a | 72 | // NSAPI_ERROR_NO_CONNECTION = -3004, /*!< not connected to a network */ |
bosko001 | 2:45b351b4fc2a | 73 | // NSAPI_ERROR_NO_SOCKET = -3005, /*!< socket not available for use */ |
bosko001 | 2:45b351b4fc2a | 74 | // NSAPI_ERROR_NO_ADDRESS = -3006, /*!< IP address is not known */ |
bosko001 | 2:45b351b4fc2a | 75 | // NSAPI_ERROR_NO_MEMORY = -3007, /*!< memory resource not available */ |
bosko001 | 2:45b351b4fc2a | 76 | // NSAPI_ERROR_NO_SSID = -3008, /*!< ssid not found */ |
bosko001 | 2:45b351b4fc2a | 77 | // NSAPI_ERROR_DNS_FAILURE = -3009, /*!< DNS failed to complete successfully */ |
bosko001 | 2:45b351b4fc2a | 78 | // NSAPI_ERROR_DHCP_FAILURE = -3010, /*!< DHCP failed to complete successfully */ |
bosko001 | 2:45b351b4fc2a | 79 | // NSAPI_ERROR_AUTH_FAILURE = -3011, /*!< connection to access point failed */ |
bosko001 | 2:45b351b4fc2a | 80 | // NSAPI_ERROR_DEVICE_ERROR = -3012, /*!< failure interfacing with the network processor */ |
bosko001 | 2:45b351b4fc2a | 81 | // NSAPI_ERROR_IN_PROGRESS = -3013, /*!< operation (eg connect) in progress */ |
bosko001 | 2:45b351b4fc2a | 82 | // NSAPI_ERROR_ALREADY = -3014, /*!< operation (eg connect) already in progress */ |
bosko001 | 2:45b351b4fc2a | 83 | // NSAPI_ERROR_IS_CONNECTED = -3015, /*!< socket is already connected */ |
bosko001 | 2:45b351b4fc2a | 84 | // NSAPI_ERROR_CONNECTION_LOST = -3016, /*!< connection lost */ |
bosko001 | 2:45b351b4fc2a | 85 | // NSAPI_ERROR_CONNECTION_TIMEOUT = -3017, /*!< connection timed out */ |
bosko001 | 2:45b351b4fc2a | 86 | //}; |