bosko lekovic
/
ETHtoCOM_10
nova verzija tcp+udp->serial com
Diff: DataFlash/dataFlash.cpp
- Revision:
- 8:c0f54b381346
- Parent:
- 7:7ea932eb31f6
- Child:
- 13:03617f6ed112
--- a/DataFlash/dataFlash.cpp Sat Apr 18 22:32:13 2020 +0000 +++ b/DataFlash/dataFlash.cpp Sun Apr 19 22:13:45 2020 +0000 @@ -55,8 +55,8 @@ { 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 MASK ", gps_rd->myMASK ); + P_str( "FLASH GATE ", gps_rd->myGATE ); P_str( "FLASH UDP PORT ", gps_rd->myUdpPort ); P_str( "FLASH TCP PORT ", gps_rd->myTcpPort ); @@ -106,47 +106,76 @@ -#define COPY_IP_TO_FLASH( dest, source ) if( test_ip( pch->get_myIP( ) ) ) strncpy( gps_rd->dest, pch->source, 16 ) +//#define COPY_IP_TO_FLASH( dest, source ) if( test_ip( pch->source ) ) strncpy( gps_rd->dest, pch->source, 16 ) + +#define COPY_IP_HTML_TO_FLASH( param ) if( test_ip( pch->get_##param() ) ) strncpy( gps_rd->param, pch->get_##param(), 16 ) +#define COPY_IP_HTML_TO_FLASH_idx( param, idx ) \ + if( test_ip( pch->get_##param(idx+1) ) ) strncpy( gps_rd->param[idx], pch->get_##param(idx+1), 16 ); \ + else strncpy( gps_rd->param[idx], " ", 16 ); + + +//#define COPY_PORT_TO_FLASH( dest, source ) if( test_num( pch->source)) strncpy( gps_rd->dest, pch->source, 6 ); +#define COPY_PORT_HTML_TO_FLASH( param ) if( test_num( pch->get_##param())) strncpy( gps_rd->param, pch->get_##param( ), 6 ); +#define COPY_PORT_HTML_TO_FLASH_idx( param, idx ) \ + if( test_num( pch->get_##param(idx+1))) strncpy( gps_rd->param[idx], pch->get_##param( idx+1 ), 6 ); \ + else strncpy( gps_rd->param[idx], " ", 6 ); void putHTMLintoFLASH( C_HTMLparse *pch ) { - - 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 ); + // COPY_IP_TO_FLASH( myIP, get_myIP() ); +COPY_IP_HTML_TO_FLASH( myIP ); +COPY_IP_HTML_TO_FLASH( myMASK ); +COPY_IP_HTML_TO_FLASH( myGATE ); + +// COPY_IP_TO_FLASH( myMASK, get_myMASK() ); +// COPY_IP_TO_FLASH( myGATE, get_myGATE() ); - 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->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 ); +COPY_PORT_HTML_TO_FLASH( myUdpPort ); +COPY_PORT_HTML_TO_FLASH( myTcpPort ); +// COPY_PORT_TO_FLASH( myUdpPort, get_myUdpPort() ); +// COPY_PORT_TO_FLASH( myTcpPort, get_myTcpPort() ); + +COPY_IP_HTML_TO_FLASH_idx( UdpIP, 0 ); +COPY_IP_HTML_TO_FLASH_idx( UdpIP, 1 ); +COPY_IP_HTML_TO_FLASH_idx( UdpIP, 2 ); +COPY_IP_HTML_TO_FLASH_idx( UdpIP, 3 ); +COPY_IP_HTML_TO_FLASH_idx( UdpIP, 4 ); +// COPY_IP_TO_FLASH( UdpIP[0], get_UdpIP(1) ); +// COPY_IP_TO_FLASH( UdpIP[1], get_UdpIP(2) ); +// COPY_IP_TO_FLASH( UdpIP[2], get_UdpIP(3) ); +// COPY_IP_TO_FLASH( UdpIP[3], get_UdpIP(4) ); +// COPY_IP_TO_FLASH( UdpIP[4], get_UdpIP(5) ); - 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 ); +COPY_PORT_HTML_TO_FLASH_idx( UdpPort, 0 ); +COPY_PORT_HTML_TO_FLASH_idx( UdpPort, 1 ); +COPY_PORT_HTML_TO_FLASH_idx( UdpPort, 2 ); +COPY_PORT_HTML_TO_FLASH_idx( UdpPort, 3 ); +// COPY_PORT_TO_FLASH( UdpPort[0], get_UdpPort(1) ); +// COPY_PORT_TO_FLASH( UdpPort[1], get_UdpPort(2) ); +// COPY_PORT_TO_FLASH( UdpPort[2], get_UdpPort(3) ); +// COPY_PORT_TO_FLASH( UdpPort[3], get_UdpPort(4) ); - 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); +COPY_IP_HTML_TO_FLASH_idx( TcpIP, 0 ); +COPY_IP_HTML_TO_FLASH_idx( TcpIP, 1 ); +COPY_IP_HTML_TO_FLASH_idx( TcpIP, 2 ); +COPY_IP_HTML_TO_FLASH_idx( TcpIP, 3 ); +COPY_IP_HTML_TO_FLASH_idx( TcpIP, 4 ); +// COPY_IP_TO_FLASH( TcpIP[0], get_TcpIP(1) ); +// COPY_IP_TO_FLASH( TcpIP[1], get_TcpIP(2) ); +// COPY_IP_TO_FLASH( TcpIP[2], get_TcpIP(3) ); +// COPY_IP_TO_FLASH( TcpIP[3], get_TcpIP(4) ); +// COPY_IP_TO_FLASH( TcpIP[4], get_TcpIP(5) ); + +COPY_PORT_HTML_TO_FLASH_idx( TcpPort, 0 ); +COPY_PORT_HTML_TO_FLASH_idx( TcpPort, 1 ); +COPY_PORT_HTML_TO_FLASH_idx( TcpPort, 2 ); +COPY_PORT_HTML_TO_FLASH_idx( TcpPort, 3 ); +// COPY_PORT_TO_FLASH( TcpPort[0], get_TcpPort(1) ); +// COPY_PORT_TO_FLASH( TcpPort[1], get_TcpPort(2) ); +// COPY_PORT_TO_FLASH( TcpPort[2], get_TcpPort(3) ); +// COPY_PORT_TO_FLASH( TcpPort[3], get_TcpPort(4) ); strncpy( gps_rd->baud_rate, pch->get_selected_option( "baud_rate" ), 7 ); strncpy( gps_rd->parity, pch->get_selected_option( "parity" ), 6 ); @@ -156,44 +185,71 @@ 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 ); } + +//#define COPY_IP_FLASH_TO_HTML( dest, source ) if( test_ip( gps_rd->source ) ) pch->dest( gps_rd->source ); +#define COPY_IP_FLASH_TO_HTML( param ) if( test_ip( gps_rd->param ) ) pch->set_##param( gps_rd->param ); +#define COPY_IP_FLASH_TO_HTML_idx( param, idx ) if( test_ip( gps_rd->param[idx] ) ) pch->set_##param( idx+1, gps_rd->param[idx] ); + +#define COPY_PORT_FLASH_TO_HTML( param ) if( test_num( gps_rd->param )) pch->set_##param(gps_rd->param); +#define COPY_PORT_FLASH_TO_HTML_idx( param, idx ) if( test_num( gps_rd->param[idx] )) pch->set_##param(idx+1, gps_rd->param[idx]); void putFLASHintoHTML( C_HTMLparse *pch ) { refreshDataFromFlash( ); - 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 ); + COPY_IP_FLASH_TO_HTML( myIP ); + COPY_IP_FLASH_TO_HTML( myIP ); + COPY_IP_FLASH_TO_HTML( myMASK ); + COPY_IP_FLASH_TO_HTML( myGATE ); +// 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->myUdpPort )) pch->set_myUdpPort(gps_rd->myUdpPort); - if( test_num( gps_rd->myTcpPort )) pch->set_myTcpPort(gps_rd->myTcpPort); + COPY_PORT_FLASH_TO_HTML( myUdpPort ); + COPY_PORT_FLASH_TO_HTML( myTcpPort ); +// 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->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]); + COPY_IP_FLASH_TO_HTML_idx( UdpIP, 0 ); + COPY_IP_FLASH_TO_HTML_idx( UdpIP, 1 ); + COPY_IP_FLASH_TO_HTML_idx( UdpIP, 2 ); + COPY_IP_FLASH_TO_HTML_idx( UdpIP, 3 ); + COPY_IP_FLASH_TO_HTML_idx( UdpIP, 4 ); +// 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_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] ); + COPY_PORT_FLASH_TO_HTML_idx( UdpPort, 0 ); + COPY_PORT_FLASH_TO_HTML_idx( UdpPort, 1 ); + COPY_PORT_FLASH_TO_HTML_idx( UdpPort, 2 ); + COPY_PORT_FLASH_TO_HTML_idx( UdpPort, 3 ); +// 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]); + COPY_IP_FLASH_TO_HTML_idx( TcpIP, 0 ); + COPY_IP_FLASH_TO_HTML_idx( TcpIP, 1 ); + COPY_IP_FLASH_TO_HTML_idx( TcpIP, 2 ); + COPY_IP_FLASH_TO_HTML_idx( TcpIP, 3 ); + COPY_IP_FLASH_TO_HTML_idx( TcpIP, 4 ); + // 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] ); + COPY_PORT_FLASH_TO_HTML_idx( TcpPort, 0 ); + COPY_PORT_FLASH_TO_HTML_idx( TcpPort, 1 ); + COPY_PORT_FLASH_TO_HTML_idx( TcpPort, 2 ); + COPY_PORT_FLASH_TO_HTML_idx( TcpPort, 3 ); +// 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 );