nova verzija tcp+udp->serial com

Committer:
bosko001
Date:
Mon May 25 22:19:36 2020 +0200
Revision:
21:2232f5a34eb4
Parent:
18:5ee53205451a
zapocet tcp socket

Signed-off-by: Bosko Lekovic <bosko001@gmail.com>

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Bosko Lekovic 18:5ee53205451a 1 #include "mbed.h"
bosko001 2:45b351b4fc2a 2 #include "EthernetSetup.h"
bosko001 2:45b351b4fc2a 3 #include "clubbing.h"
bosko001 9:893843262a1f 4 #include "doHTML.h"
bosko001 2:45b351b4fc2a 5
Bosko Lekovic 18:5ee53205451a 6 //EthernetInterface eth, *gp_eth= &eth;
Bosko Lekovic 18:5ee53205451a 7 EthernetInterface *gp_eth = NULL;
Bosko Lekovic 18:5ee53205451a 8
bosko001 9:893843262a1f 9 extern C_HTMLparse * gpc_html;
bosko001 2:45b351b4fc2a 10
bosko001 2:45b351b4fc2a 11 struct S_EthernetAddress
bosko001 2:45b351b4fc2a 12 /*{
bosko001 2:45b351b4fc2a 13 char ip[16];
bosko001 2:45b351b4fc2a 14 char mask[16];
bosko001 2:45b351b4fc2a 15 char gate[16];
bosko001 2:45b351b4fc2a 16 }*/ s_EthAdd = {"192.168.1.20", "255.255.255.0", "192.168.1.1"},
bosko001 2:45b351b4fc2a 17 s_EthAddFlash = {"xxx.168.1.20", "yyy.255.255.0", "zzz.168.1.1"};
bosko001 2:45b351b4fc2a 18
bosko001 2:45b351b4fc2a 19
bosko001 2:45b351b4fc2a 20
bosko001 2:45b351b4fc2a 21 struct S_net
bosko001 2:45b351b4fc2a 22 /*{
bosko001 2:45b351b4fc2a 23 struct S_EthernetAddress *ps_ea;
bosko001 2:45b351b4fc2a 24 EthernetInterface *p_eth;
Bosko Lekovic 18:5ee53205451a 25 }*/ s_net = { &s_EthAdd, gp_eth};
bosko001 2:45b351b4fc2a 26
bosko001 2:45b351b4fc2a 27
bosko001 2:45b351b4fc2a 28 nsapi_error_t err;
bosko001 2:45b351b4fc2a 29
bosko001 2:45b351b4fc2a 30 int test_EthAdd( struct S_EthernetAddress* ps_ea)
bosko001 2:45b351b4fc2a 31 {
bosko001 9:893843262a1f 32
bosko001 2:45b351b4fc2a 33 return 1;
bosko001 2:45b351b4fc2a 34 }
bosko001 2:45b351b4fc2a 35
Bosko Lekovic 18:5ee53205451a 36
Bosko Lekovic 18:5ee53205451a 37 int getEthernetStatus( void )
bosko001 9:893843262a1f 38 {
Bosko Lekovic 18:5ee53205451a 39 return gp_eth->get_connection_status();
bosko001 9:893843262a1f 40 }
bosko001 9:893843262a1f 41
Bosko Lekovic 18:5ee53205451a 42 void ethCancel( void )
Bosko Lekovic 18:5ee53205451a 43 {
Bosko Lekovic 18:5ee53205451a 44
Bosko Lekovic 18:5ee53205451a 45 if( gp_eth )
Bosko Lekovic 18:5ee53205451a 46 { gp_eth->disconnect(); /* gasenje ethernta */
Bosko Lekovic 18:5ee53205451a 47 // delete gp_eth;
Bosko Lekovic 18:5ee53205451a 48 // gp_eth = NULL;
Bosko Lekovic 18:5ee53205451a 49 }
Bosko Lekovic 18:5ee53205451a 50
Bosko Lekovic 18:5ee53205451a 51 printf( " Ethernet disconnect-ovan\n\r");
Bosko Lekovic 18:5ee53205451a 52 }
Bosko Lekovic 18:5ee53205451a 53
bosko001 9:893843262a1f 54
bosko001 9:893843262a1f 55
bosko001 9:893843262a1f 56
bosko001 9:893843262a1f 57 void do_ethAddr( void )
bosko001 9:893843262a1f 58 {
bosko001 9:893843262a1f 59 strcpy( s_net.ps_ea->ip, gpc_html->get_myIP( ));
bosko001 9:893843262a1f 60 strcpy( s_net.ps_ea->mask, gpc_html->get_myMASK( ));
bosko001 9:893843262a1f 61 strcpy( s_net.ps_ea->gate, gpc_html->get_myGATE( ));
bosko001 9:893843262a1f 62
bosko001 9:893843262a1f 63 }
bosko001 9:893843262a1f 64
bosko001 21:2232f5a34eb4 65 bool ethernet_setup( void )
bosko001 2:45b351b4fc2a 66 {
bosko001 2:45b351b4fc2a 67 // if( (err = eth.disconnect()) != NSAPI_ERROR_OK ) { printf(" greska diskonekcije %d \n\r", err); return 1; }
bosko001 2:45b351b4fc2a 68 // ((NetworkInterface *)&eth)->set_network("192.168.1.11","255.255.255.0","192.168.1.1");
bosko001 2:45b351b4fc2a 69
bosko001 9:893843262a1f 70 // if( test_EthAdd( &s_EthAddFlash )) { printf("upisana ip adresa sa DataFlash-a\n\r"); }
bosko001 9:893843262a1f 71 // else if( test_EthAdd( &s_EthAdd )) { printf("upisana ip adresa sa ProgFlash-a\n\r"); }
bosko001 9:893843262a1f 72 // else { printf("neispravne ip adrese!!!\n\r"); return NULL;}
Bosko Lekovic 18:5ee53205451a 73 printf("ETH setup\n\r");
Bosko Lekovic 18:5ee53205451a 74 if( gp_eth == NULL) gp_eth = new EthernetInterface;
Bosko Lekovic 18:5ee53205451a 75 else
Bosko Lekovic 18:5ee53205451a 76 {
Bosko Lekovic 18:5ee53205451a 77 // delete gp_eth;
Bosko Lekovic 18:5ee53205451a 78 // gp_eth = new EthernetInterface;
Bosko Lekovic 18:5ee53205451a 79 }
Bosko Lekovic 18:5ee53205451a 80 printf("novi gp_eth pointer %d\n\r", gp_eth);
bosko001 9:893843262a1f 81 do_ethAddr( );
Bosko Lekovic 18:5ee53205451a 82 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); }
bosko001 2:45b351b4fc2a 83
Bosko Lekovic 18:5ee53205451a 84 else if( (err = gp_eth->connect()) != NSAPI_ERROR_OK ) { printf(" greska ethernet konekcije %d \n\r", err); }
bosko001 2:45b351b4fc2a 85
bosko001 2:45b351b4fc2a 86 else
bosko001 2:45b351b4fc2a 87 {
bosko001 2:45b351b4fc2a 88
Bosko Lekovic 18:5ee53205451a 89 printf( "MAC adresa: %s\n\r", gp_eth->get_mac_address() );
Bosko Lekovic 18:5ee53205451a 90 printf( "IP adresa: %s\n\r", gp_eth->get_ip_address() );
Bosko Lekovic 18:5ee53205451a 91 printf( "net mask: %s\n\r", gp_eth->get_netmask() );
Bosko Lekovic 18:5ee53205451a 92 printf( "GW adresa: %s\n\r", gp_eth->get_gateway() );
bosko001 2:45b351b4fc2a 93
bosko001 21:2232f5a34eb4 94 return true;
bosko001 2:45b351b4fc2a 95 }
Bosko Lekovic 18:5ee53205451a 96 // delete gp_eth;
Bosko Lekovic 18:5ee53205451a 97 // return gp_eth = NULL;
bosko001 21:2232f5a34eb4 98 return false;
bosko001 2:45b351b4fc2a 99 }
bosko001 2:45b351b4fc2a 100
bosko001 2:45b351b4fc2a 101
bosko001 2:45b351b4fc2a 102
bosko001 2:45b351b4fc2a 103
bosko001 2:45b351b4fc2a 104
bosko001 2:45b351b4fc2a 105
bosko001 2:45b351b4fc2a 106 //
bosko001 2:45b351b4fc2a 107 //enum nsapi_error {
bosko001 2:45b351b4fc2a 108 // NSAPI_ERROR_OK = 0, /*!< no error */
bosko001 2:45b351b4fc2a 109 // NSAPI_ERROR_WOULD_BLOCK = -3001, /*!< no data is not available but call is non-blocking */
bosko001 2:45b351b4fc2a 110 // NSAPI_ERROR_UNSUPPORTED = -3002, /*!< unsupported functionality */
bosko001 2:45b351b4fc2a 111 // NSAPI_ERROR_PARAMETER = -3003, /*!< invalid configuration */
bosko001 2:45b351b4fc2a 112 // NSAPI_ERROR_NO_CONNECTION = -3004, /*!< not connected to a network */
bosko001 2:45b351b4fc2a 113 // NSAPI_ERROR_NO_SOCKET = -3005, /*!< socket not available for use */
bosko001 2:45b351b4fc2a 114 // NSAPI_ERROR_NO_ADDRESS = -3006, /*!< IP address is not known */
bosko001 2:45b351b4fc2a 115 // NSAPI_ERROR_NO_MEMORY = -3007, /*!< memory resource not available */
bosko001 2:45b351b4fc2a 116 // NSAPI_ERROR_NO_SSID = -3008, /*!< ssid not found */
bosko001 2:45b351b4fc2a 117 // NSAPI_ERROR_DNS_FAILURE = -3009, /*!< DNS failed to complete successfully */
bosko001 2:45b351b4fc2a 118 // NSAPI_ERROR_DHCP_FAILURE = -3010, /*!< DHCP failed to complete successfully */
bosko001 2:45b351b4fc2a 119 // NSAPI_ERROR_AUTH_FAILURE = -3011, /*!< connection to access point failed */
bosko001 2:45b351b4fc2a 120 // NSAPI_ERROR_DEVICE_ERROR = -3012, /*!< failure interfacing with the network processor */
bosko001 2:45b351b4fc2a 121 // NSAPI_ERROR_IN_PROGRESS = -3013, /*!< operation (eg connect) in progress */
bosko001 2:45b351b4fc2a 122 // NSAPI_ERROR_ALREADY = -3014, /*!< operation (eg connect) already in progress */
bosko001 2:45b351b4fc2a 123 // NSAPI_ERROR_IS_CONNECTED = -3015, /*!< socket is already connected */
bosko001 2:45b351b4fc2a 124 // NSAPI_ERROR_CONNECTION_LOST = -3016, /*!< connection lost */
bosko001 2:45b351b4fc2a 125 // NSAPI_ERROR_CONNECTION_TIMEOUT = -3017, /*!< connection timed out */
bosko001 2:45b351b4fc2a 126 //};