nova verzija tcp+udp->serial com

Revision:
7:7ea932eb31f6
Parent:
5:c9a908749d4c
Child:
8:c0f54b381346
--- a/DataFlash/dataFlash.cpp	Tue Apr 14 13:32:02 2020 +0000
+++ b/DataFlash/dataFlash.cpp	Sat Apr 18 22:32:13 2020 +0000
@@ -53,104 +53,154 @@
 
 void showFlashData( void )
 {
-   P_str( "FLASH IP ", gps_rd->s_EthAdd.ip ); 
-   P_str( "FLASH MASK ", gps_rd->s_EthAdd.mask ); 
-   P_str( "FLASH GATE ", gps_rd->s_EthAdd.gate ); 
+  refreshDataFromFlash( );
+   P_str( "FLASH IP ", gps_rd->myIP ); 
+   P_str( "FLASH MASK ", gps_rd->myMask ); 
+   P_str( "FLASH GATE ", gps_rd->myGate ); 
 
-   P_str( "FLASH UDP PORT ", gps_rd->serverPortUdp ); 
-   P_str( "FLASH TCP PORT ", gps_rd->serverPortTcp ); 
+   P_str( "FLASH UDP PORT ", gps_rd->myUdpPort ); 
+   P_str( "FLASH TCP PORT ", gps_rd->myTcpPort ); 
    
-   P_str( "FLASH UDP IP[0] ", gps_rd->s_EthAddRemUdp[0].ip ); 
-   P_int( "FLASH UDP PORT[0] ", gps_rd->s_EthAddRemUdp[0].port ); 
-   P_str( "FLASH TCP IP[0] ", gps_rd->s_EthAddRemTcp[0].ip ); 
-   P_int( "FLASH TCP PORT[0] ", gps_rd->s_EthAddRemTcp[0].port ); 
+   P_str( "FLASH UDP IP[0] ", gps_rd->UdpIP[0] ); 
+   P_str( "FLASH UDP IP[1] ", gps_rd->UdpIP[1] ); 
+   P_str( "FLASH UDP IP[2] ", gps_rd->UdpIP[2] ); 
+   P_str( "FLASH UDP IP[3] ", gps_rd->UdpIP[3] ); 
+   P_str( "FLASH UDP IP[4] ", gps_rd->UdpIP[4] ); 
+
+   P_str( "FLASH UDP PORT[0] ", gps_rd->UdpPort[0] ); 
+   P_str( "FLASH UDP PORT[1] ", gps_rd->UdpPort[1] ); 
+   P_str( "FLASH UDP PORT[2] ", gps_rd->UdpPort[2] ); 
+   P_str( "FLASH UDP PORT[3] ", gps_rd->UdpPort[3] ); 
+
+   P_str( "FLASH TCP IP[0] ", gps_rd->TcpIP[0] ); 
+   P_str( "FLASH TCP IP[1] ", gps_rd->TcpIP[1] ); 
+   P_str( "FLASH TCP IP[2] ", gps_rd->TcpIP[2] ); 
+   P_str( "FLASH TCP IP[3] ", gps_rd->TcpIP[3] ); 
+   P_str( "FLASH TCP IP[4] ", gps_rd->TcpIP[4] ); 
+
+   P_str( "FLASH TCP PORT[0] ", gps_rd->TcpPort[0] ); 
+   P_str( "FLASH TCP PORT[1] ", gps_rd->TcpPort[1] ); 
+   P_str( "FLASH TCP PORT[2] ", gps_rd->TcpPort[2] ); 
+   P_str( "FLASH TCP PORT[3] ", gps_rd->TcpPort[3] ); 
    
-//   P_int( "FLASH SERIAL BAUD ", gps_rd->baudRate ); 
-//   P_int( "FLASH SERIAL BAUD ", gps_rd->parity ); 
-//   P_int( "FLASH SERIAL BAUD ", gps_rd->dataBits ); 
-//   P_int( "FLASH SERIAL BAUD ", gps_rd->stopBits ); 
+   P_str( "FLASH SERIAL BAUD ", gps_rd->baud_rate ); 
+   P_str( "FLASH SERIAL BAUD ", gps_rd->parity ); 
+   P_str( "FLASH SERIAL BAUD ", gps_rd->data_bits ); 
+   P_str( "FLASH SERIAL BAUD ", gps_rd->stop_bits ); 
 } 
 
 
+//
+//struct S_FlashData
+//{
+//    char myIP[16];
+//    char myMask[16];
+//    char myGate[16];
+//    char myUdpPort[6];
+//    char myTcpPort[6];
+//    char UdpIP[5][16];
+//    char UdpPort[4][6];
+//    char TcpPort[4][6];
+//    char baud_rate[7], parity[6], data_bits[2], stop_bits[4];
+//};
+
+
+
+#define COPY_IP_TO_FLASH( dest, source )      if( test_ip( pch->get_myIP( ) ) ) strncpy( gps_rd->dest, pch->source, 16 )
+
 
 void putHTMLintoFLASH( C_HTMLparse *pch )
 {
     
     
-    if( test_ip( pch->get_myIP( ) ) ) strncpy( gps_rd->s_EthAdd.ip, pch->get_myIP( ), 16 );
-    if( test_ip( pch->get_myMASK( ) ) ) strncpy( gps_rd->s_EthAdd.mask, pch->get_myMASK(), 16 );
-    if( test_ip( pch->get_myGATE( ) ) ) strncpy( gps_rd->s_EthAdd.gate, pch->get_myGATE(), 16 );
+    if( test_ip( pch->get_myIP( ) ) ) strncpy( gps_rd->myIP, pch->get_myIP( ), 16 );
+    if( test_ip( pch->get_myMASK( ) ) ) strncpy( gps_rd->myMask, pch->get_myMASK(), 16 );
+    if( test_ip( pch->get_myGATE( ) ) ) strncpy( gps_rd->myGate, pch->get_myGATE(), 16 );
 
-    strncpy( gps_rd->serverPortUdp, pch->get_myUdpPort(), 6 );
-    strncpy( gps_rd->serverPortTcp, pch->get_myTcpPort(), 6 );
+    if( test_num( pch->get_myUdpPort())) strncpy( gps_rd->myUdpPort, pch->get_myUdpPort(), 6 );
+    if( test_num( pch->get_myTcpPort())) strncpy( gps_rd->myTcpPort, pch->get_myTcpPort(), 6 );
     
-    if( test_ip( pch->get_UdpIP(1) ) )strncpy( gps_rd->s_EthAddRemUdp[0].ip, pch->get_UdpIP(1), 16 ); 
-    gps_rd->s_EthAddRemUdp[0].port = atoi( pch->get_UdpPort(1) ); 
+    if( test_ip( pch->get_UdpIP(1) ) )  strncpy( gps_rd->UdpIP[0], pch->get_UdpIP(1), 16 ); 
+    if( test_ip( pch->get_UdpIP(2) ) )  strncpy( gps_rd->UdpIP[1], pch->get_UdpIP(2), 16 ); 
+    if( test_ip( pch->get_UdpIP(3) ) )  strncpy( gps_rd->UdpIP[2], pch->get_UdpIP(3), 16 ); 
+    if( test_ip( pch->get_UdpIP(4) ) )  strncpy( gps_rd->UdpIP[3], pch->get_UdpIP(4), 16 ); 
+    if( test_ip( pch->get_UdpIP(5) ) )  strncpy( gps_rd->UdpIP[4], pch->get_UdpIP(5), 16 ); 
+
+    if( test_num( pch->get_UdpPort(1))) strncpy( gps_rd->UdpPort[0], pch->get_UdpPort(1), 6 ); 
+    if( test_num( pch->get_UdpPort(2))) strncpy( gps_rd->UdpPort[1], pch->get_UdpPort(2), 6 ); 
+    if( test_num( pch->get_UdpPort(3))) strncpy( gps_rd->UdpPort[2], pch->get_UdpPort(3), 6 ); 
+    if( test_num( pch->get_UdpPort(4))) strncpy( gps_rd->UdpPort[3], pch->get_UdpPort(4), 6 ); 
+
+    if( test_ip( pch->get_TcpIP(1) ) ) strncpy( gps_rd->TcpIP[0], pch->get_TcpIP(1), 16 ); 
+    if( test_ip( pch->get_TcpIP(2) ) ) strncpy( gps_rd->TcpIP[1], pch->get_TcpIP(2), 16 ); 
+    if( test_ip( pch->get_TcpIP(3) ) ) strncpy( gps_rd->TcpIP[2], pch->get_TcpIP(3), 16 ); 
+    if( test_ip( pch->get_TcpIP(4) ) ) strncpy( gps_rd->TcpIP[3], pch->get_TcpIP(4), 16 ); 
+    if( test_ip( pch->get_TcpIP(5) ) ) strncpy( gps_rd->TcpIP[4], pch->get_TcpIP(5), 16 ); 
 
-    if( test_ip( pch->get_TcpIP(1) ) )strncpy( gps_rd->s_EthAddRemTcp[0].ip, pch->get_TcpIP(1), 16 ); 
-    gps_rd->s_EthAddRemTcp[0].port = atoi( pch->get_TcpPort(1) ); 
+    if( test_num(pch->get_TcpPort(1))) strncpy( gps_rd->TcpPort[0], pch->get_TcpPort(1), 6 ); 
+    if( test_num(pch->get_TcpPort(2))) strncpy( gps_rd->TcpPort[1], pch->get_TcpPort(2), 6 ); 
+    if( test_num(pch->get_TcpPort(3))) strncpy( gps_rd->TcpPort[2], pch->get_TcpPort(3), 6 ); 
+    if( test_num(pch->get_TcpPort(4))) strncpy( gps_rd->TcpPort[3], pch->get_TcpPort(4), 6 ); 
+//
+//    printf("baud = %s\n\r", pch->get_selected_option( "baud_rate" ));
+//    printf("parity = %s\n\r", pch->get_selected_option( "parity" ));
+//    printf("dataBits = %s\n\r", pch->get_selected_option( "data_bits" ));
+//    printf("stopBits = %s\n\r", pch->get_selected_option( "stop_bits" ));
+//fflush(stdout);
 
+    strncpy( gps_rd->baud_rate, pch->get_selected_option( "baud_rate" ), 7 );
+    strncpy( gps_rd->parity, pch->get_selected_option( "parity" ), 6 );
+    strncpy( gps_rd->data_bits, pch->get_selected_option( "data_bits" ), 2 );
+    strncpy( gps_rd->stop_bits, pch->get_selected_option( "stop_bits" ), 4 );
+    
     fillDataIntoFlash( );
 }
 
+//      else if( !strcmp( s_hpv[i].name, "baud_rate") ) set_selected_option(  "baud_rate" , s_hpv[i].value ); 
+//      else if( !strcmp( s_hpv[i].name, "parity") ) set_selected_option(  "parity" , s_hpv[i].value ); 
+//      else if( !strcmp( s_hpv[i].name, "data_bits") ) { set_selected_option(  "data_bits" , s_hpv[i].value ); } 
+//      else if( !strcmp( s_hpv[i].name, "stop_bits") ) { set_selected_option(  "stop_bits" , s_hpv[i].value ); }
 
 void putFLASHintoHTML( C_HTMLparse *pch )
 {
     
    refreshDataFromFlash( );
     
-    if( test_ip( gps_rd->s_EthAdd.ip ) ) pch->set_myIP( gps_rd->s_EthAdd.ip );
-    if( test_ip( gps_rd->s_EthAdd.mask ) ) pch->set_myMASK( gps_rd->s_EthAdd.mask );
-    if( test_ip( gps_rd->s_EthAdd.gate ) ) pch->set_myGATE( gps_rd->s_EthAdd.gate );
+    if( test_ip( gps_rd->myIP ) ) pch->set_myIP( gps_rd->myIP );
+    if( test_ip( gps_rd->myMask ) ) pch->set_myMASK( gps_rd->myMask );
+    if( test_ip( gps_rd->myGate ) ) pch->set_myGATE( gps_rd->myGate );
 
-    if( test_num( gps_rd->serverPortUdp )) pch->set_myUdpPort(gps_rd->serverPortUdp);
-    if( test_num( gps_rd->serverPortTcp )) pch->set_myTcpPort(gps_rd->serverPortTcp);
+    if( test_num( gps_rd->myUdpPort )) pch->set_myUdpPort(gps_rd->myUdpPort);
+    if( test_num( gps_rd->myTcpPort )) pch->set_myTcpPort(gps_rd->myTcpPort);
     
-    if( test_ip( gps_rd->s_EthAddRemUdp[0].ip ) ) pch->set_UdpIP(1,gps_rd->s_EthAddRemUdp[0].ip); 
-    
-    char port[10];
-    sprintf(port, "%d", gps_rd->s_EthAddRemUdp[0].port); 
-    pch->set_UdpPort( 1, port ); 
+    if( test_ip( gps_rd->UdpIP[0] ) ) pch->set_UdpIP(1,gps_rd->UdpIP[0]); 
+    if( test_ip( gps_rd->UdpIP[1] ) ) pch->set_UdpIP(2,gps_rd->UdpIP[1]); 
+    if( test_ip( gps_rd->UdpIP[2] ) ) pch->set_UdpIP(3,gps_rd->UdpIP[2]); 
+    if( test_ip( gps_rd->UdpIP[3] ) ) pch->set_UdpIP(4,gps_rd->UdpIP[3]); 
+    if( test_ip( gps_rd->UdpIP[4] ) ) pch->set_UdpIP(5,gps_rd->UdpIP[4]); 
 
-    if( test_ip( gps_rd->s_EthAddRemTcp[0].ip ) ) pch->set_TcpIP(1, gps_rd->s_EthAddRemTcp[0].ip ); 
-    sprintf( port, "%d", gps_rd->s_EthAddRemTcp[0].port);
-    pch->set_TcpPort( 1, port ); 
+    if( test_num( gps_rd->UdpPort[0] ))   pch->set_UdpPort( 1, gps_rd->UdpPort[0] );
+    if( test_num( gps_rd->UdpPort[1] ))   pch->set_UdpPort( 2, gps_rd->UdpPort[1] );
+    if( test_num( gps_rd->UdpPort[2] ))   pch->set_UdpPort( 3, gps_rd->UdpPort[2] );
+    if( test_num( gps_rd->UdpPort[3] ))   pch->set_UdpPort( 4, gps_rd->UdpPort[3] );
+     
+    if( test_ip( gps_rd->TcpIP[0] ) ) pch->set_TcpIP(1, gps_rd->TcpIP[0]); 
+    if( test_ip( gps_rd->TcpIP[1] ) ) pch->set_TcpIP(2, gps_rd->TcpIP[1]); 
+    if( test_ip( gps_rd->TcpIP[2] ) ) pch->set_TcpIP(3, gps_rd->TcpIP[2]); 
+    if( test_ip( gps_rd->TcpIP[3] ) ) pch->set_TcpIP(4, gps_rd->TcpIP[3]); 
+    if( test_ip( gps_rd->TcpIP[4] ) ) pch->set_TcpIP(5, gps_rd->TcpIP[4]); 
+
+    if( test_num( gps_rd->TcpPort[0] ))  pch->set_TcpPort( 1, gps_rd->TcpPort[0] ); 
+    if( test_num( gps_rd->TcpPort[1] ))  pch->set_TcpPort( 2, gps_rd->TcpPort[1] ); 
+    if( test_num( gps_rd->TcpPort[2] ))  pch->set_TcpPort( 3, gps_rd->TcpPort[2] ); 
+    if( test_num( gps_rd->TcpPort[3] ))  pch->set_TcpPort( 4, gps_rd->TcpPort[3] ); 
+
+
+    pch->set_selected_option( "baud_rate", gps_rd->baud_rate );
+    pch->set_selected_option( "parity", gps_rd->parity );
+    pch->set_selected_option( "data_bits", gps_rd->data_bits );
+    pch->set_selected_option( "stop_bits", gps_rd->stop_bits );
 
 }
 
 
-
-
-
-//
-//struct S_EthernetAddress
-//{
-//  char ip[16];
-//  char mask[16];
-//  char gate[16];
-// // int port;    
-//};
-//
-//struct S_EthernetAddress_Remote
-//{
-//  char ip[16];
-//  int port;   
-//};
-//
-//struct S_FlashData
-//{
-//    struct S_EthernetAddress s_EthAdd;
-//    char serverPortUdp[6];
-//    char serverPortTcp[6];
-//    struct S_EthernetAddress_Remote s_EthAddRemUdp[3];
-////    struct S_EthernetAddress_RangeRemote s_EthAddRangeRemUDP;
-//    struct S_EthernetAddress_Remote s_EthAddRemTcp[3];
-////    struct S_EthernetAddress_RangeRemote s_EthAddRangeRemTcp;
-//    int baudRate, parity, dataBits, stopBits;
-//};
-//
-//union U_FlashData
-//{
-//    struct S_FlashData s_flashData;
-//    char data[sizeof( struct S_FlashData )];
-//};
\ No newline at end of file