nova proba

UdpToScom.cpp

Committer:
bosko001
Date:
2020-04-22
Revision:
9:893843262a1f
Parent:
2:45b351b4fc2a
Child:
10:15f7fea18a2f

File content as of revision 9:893843262a1f:

#include "mbed.h"
#include "clubbing.h"
#include "UdpToScom.h"
#include "EthernetSetup.h"
#include "Udp.h"
#include "SerialCom.h"


struct S_EthernetAddress_Remote
/*{
  char ip[16];
  int port;   
}*/ //s_EthAddRemote = {"192.168.1.14", 13000 }, *ps_ear = &s_EthAddRemote,
  s_EthAddBroadcast = {"0.0.0.0", 13000 }, *ps_eab = &s_EthAddBroadcast;


/* globalni pointeri*/


extern EthernetInterface *gp_eth;



/*******************  Broadcast thread  **********************/
Thread udpBroadcast_thread;
void udpBroadcast_fun( void )
{
    while(true)
    {
    //    sendUdp(  ps_eab, (char *)"test broadcast", 14);
        wait(5);
    }   
}



void inic_1(void)
{

  printf("\n\r --------  REINICIJALIZACIJA  ------------- \n\r");

     /* Gasenje UDP threada  */
   //  if( gp_udpRxThread->get_state( ) && gp_udpRxThread->get_state( )<16 )
//        gp_udpRxThread->flags_set( 1 );
//     gp_udpRxThread->join( );
//     if(gp_udpRxThread) {delete gp_udpRxThread; gp_udpRxThread = NULL;}
//     printf("udp thread zavrsio\n\r");
    
 udpRxThreadCancel(  );

    /* gasenje serial com thread-a */
//    int st = gp_scomRxThread->get_state();
//    if( st && st<16 )gp_scomRxThread->flags_set(1);
//    gp_scomRxThread->join();
//    printf("ScomRx Thread upravo zavrsio\n\r");
//    if(gp_scomRxThread) { delete gp_scomRxThread; gp_scomRxThread = NULL;}
    scomRxThreadCancel( );
    
     gp_eth->disconnect();           /* gasenje ethernta */
     
     gp_eth = ethernet_setup(  );    /*paljenje etherneta*/
     if(gp_eth == NULL) printf("ethernet greska\n\r"); 
     else printf("eth OK\n\r");
  
     /* paljenje UDP thread-a */
//     gp_udpRxThread = new Thread( udpRx_fun );
   //   udpRxThreadRiseUp( );

    
//    /* paljenje serial com thread-a */
//    gp_scomRxThread = new Thread(scomrx_fun);
      scomRxThreadRiseUp(  );

    
//    
    fflush(stdout);

}

void init_EthToScom( void )
{
 gp_eth = ethernet_setup(  );

 if(gp_eth == NULL) printf("ethernet greska"); 
 else printf("eth OK\n\r");
 

//  if(gp_scomRxThread) delete gp_scomRxThread;
//  gp_scomRxThread = new Thread(scomrx_fun);
      scomRxThreadRiseUp(  );
 
    
    /*
    TCPSocket socket;        
    socket.open(&eth);
    socket.connect(
    */
   
    
//    gp_udpRxThread = new Thread( udpRx_fun );
      udpRxThreadRiseUp(  );

}