int fromEth2Seri( char soc, int len )
{
  int r_port;
  char *s,*e_buf;
  long r_ip,dip = netcfg::DestIP();

  e_buf = GetReceiveBuffer( soc, 1 );
  r_ip = GetSenderIP( soc );
  r_port = GetSenderPort( soc );
  if( r_ip == dip && (r_port & 0xffff) == 40000 )
  {
    for( s = e_buf; len > 0; len-- )
    {
      if( *s == 0x1b )
      {
        MemoryFree( e_buf );
        return (-2);
      }

      PrChar( *s++ );
    }
  }
  MemoryFree( e_buf );

  return 0;
}

int fromSeri2Eth( char soc, char *buf, int len )
{
  long dip = netcfg::DestIP();

  len = SendTo( soc, dip, 40000, buf, len );
  if( len == 0 )
  {
    Sleep( 10 );
    len = SendTo( soc, dip, 40000, buf, len );
  }

  return len;
}

void mp3( void )
{
#stop 0
  int len,elen,r_port,limit,timout;
  char c,*e_buf,soc = CreateSocket( 0 );
  char *res = MemoryAlloc( 32 );
  char *fn = MemoryAlloc( 128 );
  char *RcvDat = MemoryAlloc( 1472 );
  long r_ip;
  unsigned long *lptr;
  unsigned short blk,temp;
  UserDriver(0,0);
  UserDriver(2,2);
  Bind( soc, 30000, 1 );
  PrStr("Ready\r\n");
  lptr = RcvDat;
  for( c = 0; c != 0x1b; c = Getc( 0 ) )
  {
    blk = 0;
    if( (elen = RecvFrom( soc, 10 )) == (-1) ) break;
    else if( elen == (-2) ) ;
    else
    {
      e_buf = GetReceiveBuffer( soc, 1 );
      r_ip = GetSenderIP( soc );
      r_port = GetSenderPort( soc );
      if( e_buf[1] == 6 && e_buf[0] == 0 )
      {
        UserDriver(2,e_buf[3]);
        MemoryFree( e_buf );
        continue;
      }
      else if( e_buf[1] == 2 && e_buf[0] == 0 )
      {
        StrCpy( fn, e_buf + 2 );
        MemoryFree( e_buf );
        res[0] = 0; res[1] = 4; res[2] = blk >> 8; res[3] = blk;
        blk++;
        len = 4;
      }
      else
      {
        MemoryFree( e_buf );
        res[0] = 0; res[1] = 5; res[2] = 0; res[3] = 0;
        StrCpy( res + 4, "not sopported request" );
        len = 26;
      }
      if( SendTo( soc, r_ip, r_port, res, len ) == 0 )
      {
        Sleep( 10 );
        SendTo( soc, r_ip, r_port, res, len );
      }
      if( res[1] == 5 && res[0] == 0 ) continue;
      for( c = 0,limit = 0,timout=10; c != 0x1b; c = Getc( 0 ) )
      {
        elen = RecvFrom( soc, timout );
        if( elen == (-2) )
        {
          if( ++limit > 5 )
          {
PrChar('A');
            break;
          }
          res[0] = 0; res[1] = 4; res[2] = (blk - 1) >> 8; res[3] = (blk - 1);
          SendTo( soc, r_ip, r_port, res, 4 );
PrChar('L');
          timout += 5;
          if(timout > 100) timout = 100;
        }
        else
        {
          if(--timout < 10) timout = 10;
          limit = 0;
          e_buf = GetReceiveBuffer( soc, 1 );
          if( e_buf[0] == 0 && e_buf[1] == 6 )
          {
            UserDriver(2,e_buf[3]);
            MemoryFree( e_buf );
            continue;
          }
          else
          {
            temp = e_buf[3];
            temp &= 0x00ff;
            temp |= e_buf[2] << 8;
            if( e_buf[0] == 0 && e_buf[1] == 3 && temp == blk )
            {
              *lptr = elen - 4;
              BufCopy( RcvDat + 4, e_buf + 4, elen - 4 );
              MemoryFree( e_buf );
              res[0] = 0; res[1] = 4; res[2] = blk >> 8; res[3] = blk;
              blk++;
              SendTo( soc, r_ip, r_port, res, 4 );
              UserDriver(3,RcvDat);
              if( elen < 1472 )
              {
                PrStr("Done\r\n");
                break;
              }
            }
            else
            {
/*PrHex(temp);PrChar(':');PrHex(blk);PrStr("\r\n");*/
/*memDump::dump( e_buf );*/
              MemoryFree( e_buf );
PrChar('M');
              res[0] = 0; res[1] = 4; res[2] = (blk - 1) >> 8; res[3] = (blk - 1);
              SendTo( soc, r_ip, r_port, res, 4 );
            }
          }
        }
      }
      SystemSleep();
    }
    SystemSleep();
  }
  CloseSocket( soc );
  MemoryFree( RcvDat );
  MemoryFree( fn );
  MemoryFree( res );
}
