nova verzija tcp+udp->serial com

Revision:
4:7abcf4543282
Parent:
2:45b351b4fc2a
diff -r 1196befeace0 -r 7abcf4543282 EthernetSetup.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetSetup.cpp	Sat Apr 11 17:11:38 2020 +0000
@@ -0,0 +1,86 @@
+#include "EthernetSetup.h"
+#include "clubbing.h"
+
+
+EthernetInterface eth;
+
+
+struct S_EthernetAddress
+/*{
+  char ip[16];
+  char mask[16];
+  char gate[16]; 
+}*/ s_EthAdd = {"192.168.1.20", "255.255.255.0", "192.168.1.1"},
+    s_EthAddFlash = {"xxx.168.1.20", "yyy.255.255.0", "zzz.168.1.1"};
+
+
+
+struct S_net
+/*{
+ struct S_EthernetAddress *ps_ea;
+ EthernetInterface *p_eth;
+}*/ s_net = { &s_EthAdd, &eth};    
+
+
+nsapi_error_t err;
+
+int test_EthAdd( struct S_EthernetAddress* ps_ea)
+{
+  if( !(test_ip(ps_ea->ip)) ) { printf("pogresan ip: %s\n\r", ps_ea->ip); return 0; } 
+  if( !(test_ip(ps_ea->mask)) )     { printf("pogresna maska: %s\r\n", ps_ea->mask); return 0; } 
+  if( !(test_ip(ps_ea->gate)) )   { printf("pogresan gate: %s\n\r", ps_ea->gate); return 0; }
+  return 1;  
+}
+
+EthernetInterface * ethernet_setup( void )
+{
+  //  if( (err = eth.disconnect()) != NSAPI_ERROR_OK )  { printf(" greska diskonekcije %d \n\r", err); return 1; } 
+  //  ((NetworkInterface *)&eth)->set_network("192.168.1.11","255.255.255.0","192.168.1.1");
+     
+     if( test_EthAdd( &s_EthAddFlash )) { printf("upisana ip adresa sa DataFlash-a\n\r"); }
+     else if( test_EthAdd( &s_EthAdd )) { printf("upisana ip adresa sa ProgFlash-a\n\r"); }
+     else                            { printf("neispravne ip adrese!!!\n\r"); return NULL;}
+     
+     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);  } 
+     
+     else  if( (err = s_net.p_eth->connect())  != NSAPI_ERROR_OK )  { printf(" greska konekcije %d \n\r", err); }
+     
+     else
+     {
+        
+        printf( "MAC adresa: %s\n\r", s_net.p_eth->get_mac_address() );
+        printf( "IP adresa:  %s\n\r", s_net.p_eth->get_ip_address() );
+        printf( "net mask:   %s\n\r", s_net.p_eth->get_netmask() );
+        printf( "GW adresa:  %s\n\r", s_net.p_eth->get_gateway() );
+     
+        return s_net.p_eth;
+     }
+     return NULL;
+}
+
+
+
+
+
+
+//
+//enum nsapi_error {
+//    NSAPI_ERROR_OK                  =  0,        /*!< no error */
+//    NSAPI_ERROR_WOULD_BLOCK         = -3001,     /*!< no data is not available but call is non-blocking */
+//    NSAPI_ERROR_UNSUPPORTED         = -3002,     /*!< unsupported functionality */
+//    NSAPI_ERROR_PARAMETER           = -3003,     /*!< invalid configuration */
+//    NSAPI_ERROR_NO_CONNECTION       = -3004,     /*!< not connected to a network */
+//    NSAPI_ERROR_NO_SOCKET           = -3005,     /*!< socket not available for use */
+//    NSAPI_ERROR_NO_ADDRESS          = -3006,     /*!< IP address is not known */
+//    NSAPI_ERROR_NO_MEMORY           = -3007,     /*!< memory resource not available */
+//    NSAPI_ERROR_NO_SSID             = -3008,     /*!< ssid not found */
+//    NSAPI_ERROR_DNS_FAILURE         = -3009,     /*!< DNS failed to complete successfully */
+//    NSAPI_ERROR_DHCP_FAILURE        = -3010,     /*!< DHCP failed to complete successfully */
+//    NSAPI_ERROR_AUTH_FAILURE        = -3011,     /*!< connection to access point failed */
+//    NSAPI_ERROR_DEVICE_ERROR        = -3012,     /*!< failure interfacing with the network processor */
+//    NSAPI_ERROR_IN_PROGRESS         = -3013,     /*!< operation (eg connect) in progress */
+//    NSAPI_ERROR_ALREADY             = -3014,     /*!< operation (eg connect) already in progress */
+//    NSAPI_ERROR_IS_CONNECTED        = -3015,     /*!< socket is already connected */
+//    NSAPI_ERROR_CONNECTION_LOST     = -3016,     /*!< connection lost */
+//    NSAPI_ERROR_CONNECTION_TIMEOUT  = -3017,     /*!< connection timed out */
+//};
\ No newline at end of file