nova verzija tcp+udp->serial com

Revision:
18:5ee53205451a
Parent:
12:cbfc10c15437
Child:
21:2232f5a34eb4
diff -r 74c41e3f10b8 -r 5ee53205451a Ethernet/EthernetSetup.cpp
--- a/Ethernet/EthernetSetup.cpp	Wed May 06 00:42:53 2020 +0200
+++ b/Ethernet/EthernetSetup.cpp	Sun May 17 17:16:03 2020 +0200
@@ -1,8 +1,11 @@
+#include "mbed.h"
 #include "EthernetSetup.h"
 #include "clubbing.h"
 #include "doHTML.h"
 
-EthernetInterface eth, *gp_eth= ð
+//EthernetInterface eth, *gp_eth= ð
+EthernetInterface *gp_eth = NULL;
+
 extern C_HTMLparse * gpc_html;
 
 struct S_EthernetAddress
@@ -19,7 +22,7 @@
 /*{
  struct S_EthernetAddress *ps_ea;
  EthernetInterface *p_eth;
-}*/ s_net = { &s_EthAdd, &eth};    
+}*/ s_net = { &s_EthAdd, gp_eth};    
 
 
 nsapi_error_t err;
@@ -30,22 +33,41 @@
   return 1;  
 }
 
-void ethCancel( void )
+
+int getEthernetStatus( void )
 {
-     gp_eth->disconnect();           /* gasenje ethernta */
+    return gp_eth->get_connection_status();
 }
 
-void ethRiseUp( void )
+void ethCancel( void )
+{
+
+    if( gp_eth )
+    { gp_eth->disconnect();           /* gasenje ethernta */
+    //  delete gp_eth;
+    //  gp_eth = NULL;
+    }
+
+     printf( " Ethernet disconnect-ovan\n\r");
+}
+
+int ethRiseUp( void )
 {     
+    printf("Rise Up\n\r");
      gp_eth = ethernet_setup(  );    /*paljenje etherneta*/
-     if(gp_eth == NULL) printf("ethernet greska\n\r"); 
-     else printf("eth OK\n\r");
+     if(gp_eth == NULL) { printf("ethernet greska\n\r"); return 0;}
+     else               { printf("eth OK\n\r");     return 1;}
 }
 
 void ethRestart( void )
 {
-    ethCancel(  );
-    ethRiseUp(  );
+    do 
+    {
+//        thread_sleep_for(5000);
+        printf("Ethernet start\n\r"); fflush(stdout);
+        ethCancel(  );
+    }
+    while( !ethRiseUp(  )  );
 }
 
 
@@ -66,23 +88,32 @@
 //     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;}
-     
+printf("ETH setup\n\r");
+if( gp_eth == NULL)     gp_eth = new EthernetInterface;
+else 
+{
+    // delete gp_eth;
+    // gp_eth = new EthernetInterface;
+}
+printf("novi gp_eth pointer %d\n\r", gp_eth);
      do_ethAddr( );
-     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 ethernet mreze %d \n\r", err);  } 
+     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);  } 
      
-     else  if( (err = s_net.p_eth->connect())  != NSAPI_ERROR_OK )  { printf(" greska ethernet konekcije %d \n\r", err); }
+     else  if( (err = gp_eth->connect())  != NSAPI_ERROR_OK )  { printf(" greska ethernet 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() );
+        printf( "MAC adresa: %s\n\r", gp_eth->get_mac_address() );
+        printf( "IP adresa:  %s\n\r", gp_eth->get_ip_address() );
+        printf( "net mask:   %s\n\r", gp_eth->get_netmask() );
+        printf( "GW adresa:  %s\n\r", gp_eth->get_gateway() );
      
-        return s_net.p_eth;
+        return gp_eth;
      }
-     return NULL;
+    //  delete gp_eth;
+    //  return gp_eth = NULL;
+    return NULL;
 }