nova proba

Ethernet/EthernetSetup.cpp

Committer:
bosko001
Date:
2020-05-25
Revision:
21:2232f5a34eb4
Parent:
18:5ee53205451a

File content as of revision 21:2232f5a34eb4:

#include "mbed.h"
#include "EthernetSetup.h"
#include "clubbing.h"
#include "doHTML.h"

//EthernetInterface eth, *gp_eth= ð
EthernetInterface *gp_eth = NULL;

extern C_HTMLparse * gpc_html;

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, gp_eth};    


nsapi_error_t err;

int test_EthAdd( struct S_EthernetAddress* ps_ea)
{

  return 1;  
}


int getEthernetStatus( void )
{
    return gp_eth->get_connection_status();
}

void ethCancel( void )
{

    if( gp_eth )
    { gp_eth->disconnect();           /* gasenje ethernta */
    //  delete gp_eth;
    //  gp_eth = NULL;
    }

     printf( " Ethernet disconnect-ovan\n\r");
}




void do_ethAddr( void )
{
   strcpy( s_net.ps_ea->ip, gpc_html->get_myIP( ));
   strcpy( s_net.ps_ea->mask, gpc_html->get_myMASK( ));
   strcpy( s_net.ps_ea->gate, gpc_html->get_myGATE( ));
    
}

bool 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;}
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 = 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 = gp_eth->connect())  != NSAPI_ERROR_OK )  { printf(" greska ethernet konekcije %d \n\r", err); }
     
     else
     {
        
        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 true;
     }
    //  delete gp_eth;
    //  return gp_eth = NULL;
    return false;
}






//
//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 */
//};