nova verzija tcp+udp->serial com

main.cpp

Committer:
bosko001
Date:
2020-07-10
Revision:
26:c14d034d7459
Parent:
24:ec9446d86668

File content as of revision 26:c14d034d7459:

#include "mbed.h"
#include "clubbing.h"
#include "EthernetSetup.h"
#include "UdpClients.h"
#include "TcpClients.h"
#include "SerialCom.h"
#include "TcpServerToFlash.h"
#include "TcpServer.h"
//#include "dxml.h"
#include "doHTML.h"
#include "dataFlash.h"

 extern "C" void mbed_reset();

void startUp( void)
{
   // mbed_reset();
   NVIC_SystemReset();
}


volatile PFV pfv = NULL; 


DigitalOut GLed(LED2,1);
DigitalOut BLed(LED3,1);
DigitalOut RLed(LED1,1);
DigitalOut *p_led;

void pfv_fun( void ) 
{
     while(true) 
     { 
        if(pfv) {pfv(); pfv = NULL;}
        cleanTcpServerToFlashThread( );

     } 
} 
Thread pfv_thread(pfv_fun, osPriorityNormal, 1000);


void input_fun( void ) 
{

     while(true) 
     { 
      unsigned char uc;
      int fltip, kanal, fleg;
wait(0.1);
        uc = (unsigned char)getchar( );
        printf( "\n\runesen karakter %c\n\r", uc);
        
        switch( uc )
        {
            case 'F': printf("while\n\r"); while(1); break;
            case 'h': 
            {
            extern C_HTMLparse *gpc_html;
                    auto c = gpc_html->getHTML_free( );
                    printf("\n\r%s\n\r", c);
                    free(c);
            }
                break;
            case 'c': 
                fltip = 1;
                break;
            case 'f':
                fltip = 2;
                break;
            case '0': case '1': case '2': case '3':
                if(fltip == 1) kanal = uc - '0';
                else           fleg = uc - '0';
                break;
            case 'd':
            {
                // extern void tcpRxThreadCancel( int i, int flag);
                // tcpRxThreadCancel( kanal, fleg );
                printf(" komanda za tred[%d] fleg=%d\n\r", kanal, fleg);
            }
                break;
            case 'P': case 'p':
               // restart_TcpClients( );
               //startUp();
               showFlashData( );
                break;
            case 'S': case 's':
            {
             //get_rxStatus( int i )
                     puts("TCP Clients Threads satatus:\n\r");
                     printf("\n\r TCP statusi T[0]=%d    T[1]=%d    T[2]=%d    T[3]=%d \n\r", get_rxStatus(0), get_rxStatus(1), get_rxStatus(2), get_rxStatus(3));
                     printf(" TCP validy  T[0]=%d    T[1]=%d    T[2]=%d    T[3]=%d \n\r", get_rxValidy(0), get_rxValidy(1), get_rxValidy(2), get_rxValidy(3));
                     printf("status ethernet mreze %d\n\r",  getEthernetStatus( ));
            }
                break;
            case 'T': case 't':
            {
                     puts("TCP Clients Thread controll, thread number input:");
                     char no = getchar()-'0';
                     puts("\n\rTCP Clients Thread controll, thread flag input:");
                     char fl = getchar()-'0';
                    // void restart_TcpClient( int noClient, int typeRestart );
                    // restart_TcpClientConnection( no, fl & 7 );
                    printf("\n\rthread = %d, flag =%d\n\r", no, fl);
            }
            break;            
            case 'R':
            printf("systemInit()\n\r");
                SystemInit();
                //goto __main;
            break;
            
            case 'q': case 'Q':
            {
              extern void print_serial( void );
                 print_serial( );
            }
            break;
        }
     } 
} 
Thread input_thread(input_fun, osPriorityNormal, 1000);


    C_HTMLparse *gpc_html;
    
    
#define WD_KICK     watchdog.kick()


int main(void)
{
  
    printf("\n\r\n\n----------  POCETAK  ------------- \n\n\r");

  Watchdog &watchdog = Watchdog::get_instance();
  watchdog.start(10000);

    doinit_FlashData( );

   gpc_html = new C_HTMLparse;
   C_HTMLparse  *p_temp_html = new C_HTMLparse;

//   PROVERA KONZISTENCIJE FLASH PODATAKA
    putFLASHintoHTML( p_temp_html );

    if( test_FlashDataProbity( ))
    {
        printf( "MAIN:  dobri Flash podaci\n\r");
        putFLASHintoHTML( gpc_html );    
    }
    else 
    {
        printf("MAIN: losi FLASH podaci - koristim static\n\r");
        putHTMLintoFLASH( gpc_html );
        putFLASHintoHTML( gpc_html );    
    }
    delete p_temp_html;

   // showFlashData(  );


   //extern EthernetInterface *gp_eth;


   WD_KICK;

  if( ethernet_setup(  ) )
  {
    start_TcpClients( );
    start_UdpClients( );
     inic_TcpServerToFlash(  );
     p_led = &GLed;
    
    
    extern void start_TcpServer( void );
    start_TcpServer( );

  }
  else p_led = &BLed;


WD_KICK;


  start_SerialCom( );

extern void test_HTML(void);
//    test_HTML( );

    
int i=0;

int s = getEthernetStatus();
if( s == 1 ) p_led = &GLed;
else         p_led = &BLed;
int k = s;

    while(true)
    {
       if(i++ >10 ) 
       { 
           i=0;  
           s = getEthernetStatus();
           if( s != k)
           {
               *p_led = 1;
                if( s == 1 )       startUp(); //p_led = &GLed;
                else if( s == 3)    p_led = &BLed; 
                k = s;
           }
           else *p_led = !*p_led;

        }

        WD_KICK;

        wait(0.01);  
    } 

  //   deinit_FlashData(  );


}








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