nova proba

Ethernet/EthernetSetup.cpp

Committer:
bosko001
Date:
2020-04-22
Revision:
9:893843262a1f
Parent:
5:c9a908749d4c
Child:
12:cbfc10c15437

File content as of revision 9:893843262a1f:

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

EthernetInterface eth, *gp_eth= ð
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, &eth};    


nsapi_error_t err;

int test_EthAdd( struct S_EthernetAddress* ps_ea)
{

  return 1;  
}

void ethCancel( void )
{
     gp_eth->disconnect();           /* gasenje ethernta */
}

void ethRiseUp( void )
{     
     gp_eth = ethernet_setup(  );    /*paljenje etherneta*/
     if(gp_eth == NULL) printf("ethernet greska\n\r"); 
     else printf("eth OK\n\r");
}

void ethRestart( void )
{
    ethCancel(  );
    ethRiseUp(  );
}



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( ));
    
}

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