/*
UDPSear.c: demo08 for UDP Search
           Work with MiniOS7 utility 
  
Compiler: BC++ 3.1, 
          Turbo C++ 1.01(3.01) (free from http://cc.codegear.com/free/cpp)

Compile mode: Large

Project: Client.c
         ..\lib\7186el.Lib
         ..\lib\tcp_dm32.lib
         ..\lib\FW_nnnnn.LIB
         
Hordware: uPAC-7186EX

[Nov 04, 2008] by Liam
*/

#include<conio.h>
#include<stdio.h>
#include "..\lib\7186e.h"
#include "..\lib\Tcpip32.h"
#include "..\lib\MFW.h"

#define BUFSIZE 1460       /* read/write buffer size */

char *GetModuleName(void)   /* User's program must support this function for UDP search */ 
{
    return "uPAC-7186EX-FW";    //You can define any string you like
}

char *GetAliasName(void)    /* User's program must support this function for UDP search */ 
{
    return "test1" ;
} 

void XS_UserInit(int argc,char *argv[])
{
    extern int bAcceptBroadcast;
    extern unsigned long ACKDELAY;
    //extern long MAXTXTOUT;
    void UserLoop(void);
    char version[20];
    
    InitLib();

    bAcceptBroadcast=0;
    ACKDELAY=200;
/*  XS_GetVersion(version);
    Print("[X-Server library]: version=%s ",version);
    XS_GetLibDate(version);
    Print("date=%s\r\n",version);
    GetTcpipLibDate(version);
    Print("Tcpip library version:%X, Library Date is %s\r\n",GetTcpipLibVer(),version);
*/

    XS_AddSystemLoopFun(UserLoop);
    
    /* Add UDP search function */
    bAcceptBroadcast=1;     // allow to receive the UDP broadcast
    XS_AddUdpSocket(&XS_UdpSearch);
    
    /* if you using sockets, add the following two lines*/
    XS_AddSystemLoopFun(XS_SocketLoopFun); 
    XS_StartSocket();
    //MAXTXTOUT=6000UL; 
}

void XS_UserEnd(void)
{
    XS_StopSocket();
    DisableWDT();
}

void UserLoop(void)
{
    int key; 
    
    if(Kbhit()){
        switch((key=Getch())){
            case 27:
                QuitMain=1;
                break;
            default:
                break;
        }
    }
}

void main(int argc,char *argv[])
{
    XS_main(argc,argv);     // call the XS library main function.
}
