OpenCores
URL https://opencores.org/ocsvn/plasma/plasma/trunk

Subversion Repositories plasma

[/] [plasma/] [trunk/] [kernel/] [netutil.c] - Diff between revs 210 and 212

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 210 Rev 212
Line 539... Line 539...
}
}
 
 
 
 
//******************* Console ************************
//******************* Console ************************
 
 
static uint8 myBuffer[1024*3];
static uint8 myBuffer[1024*3], myString[80];
IPSocket *socketTelnet;
IPSocket *socketTelnet;
 
 
 
 
void TransferDone(uint8 *data, int bytes)
void TransferDone(uint8 *data, int bytes)
{
{
Line 583... Line 583...
   {
   {
      if(v2 != 0)
      if(v2 != 0)
         v1 /= v2;
         v1 /= v2;
   }
   }
   sprintf((char*)myBuffer, "%d\r\n", v1);
   sprintf((char*)myBuffer, "%d\r\n", v1);
   IPPrintf(socket, myBuffer);
   IPPrintf(socket, (char*)myBuffer);
}
}
 
 
 
 
void PingCallback(IPSocket *socket)
void PingCallback(IPSocket *socket)
{
{
   IPSocket *socket2 = socket->userPtr;
   IPSocket *socket2 = socket->userPtr;
   //printf("Ping Reply\n");
   //printf("Ping Reply\n");
   IPClose(socket);
   IPClose(socket);
   if(socket2)
   if(socket2)
      IPPrintf(socket2, "Ping Reply\r\n");
      IPPrintf(socket2, "Ping Reply\r\n");
 
   else
 
      printf("Ping Reply\n");
}
}
 
 
 
 
static void DnsResultCallback(IPSocket *socket, uint32 ip, void *arg)
static void DnsResultCallback(IPSocket *socket, uint32 ip, void *arg)
{
{
   char buf[80];
   char buf[80];
   IPSocket *socketTelnet = arg;
   IPSocket *socketTelnet = arg;
   IPSocket *socketPing;
   IPSocket *socketPing;
 
   (void)socket;
   sprintf(buf,  "ip=%d.%d.%d.%d\r\n",
   sprintf(buf,  "ip=%d.%d.%d.%d\r\n",
      (uint8)(ip >> 24), (uint8)(ip >> 16), (uint8)(ip >> 8), (uint8)ip);
      (uint8)(ip >> 24), (uint8)(ip >> 16), (uint8)(ip >> 8), (uint8)ip);
   IPPrintf(socketTelnet, buf);
   IPPrintf(socketTelnet, buf);
   socketPing = IPOpen(IP_MODE_PING, ip, 0, PingCallback);
   socketPing = IPOpen(IP_MODE_PING, ip, 0, PingCallback);
   socketPing->userPtr = socketTelnet;
   socketPing->userPtr = socketTelnet;
Line 677... Line 680...
   socketTelnet = socket;
   socketTelnet = socket;
   TftpTransfer(ip0, name, myBuffer, sizeof(myBuffer)-1, TelnetTransferDone);
   TftpTransfer(ip0, name, myBuffer, sizeof(myBuffer)-1, TelnetTransferDone);
}
}
 
 
 
 
 
static void TelnetHttpCallback(IPSocket *socket)
 
{
 
   int length;
 
   if(myString[0])
 
      IPPrintf(socket, myString);
 
   myString[0] = 0;
 
   length = strlen(myBuffer);
 
   length += IPRead(socket, myBuffer+length, sizeof(myBuffer)-length-1);
 
   myBuffer[length] = 0;
 
   if(length >= sizeof(myBuffer)-1 || socket->state > IP_TCP)
 
   {
 
      IPClose(socket);
 
      IPPrintf(socketTelnet, "Done\r\n");
 
   }
 
}
 
 
 
static void TelnetHttp(IPSocket *socket, char *command)
 
{
 
   char buf[80], name[80];
 
   int ip0, ip1, ip2, ip3;
 
   IPSocket *socketHttp;
 
   if(strlen(command) < 5)
 
   {
 
      IPPrintf(socket, "http #.#.#.# File\r\n");
 
      return;
 
   }
 
   sscanf(command, "%s %d.%d.%d.%d %s %s %s",
 
      buf, &ip0, &ip1, &ip2, &ip3, name);
 
   ip0 = (ip0 << 24) | (ip1 << 16) | (ip2 << 8) | ip3;
 
   socketTelnet = socket;
 
   sprintf(myString, "GET %s HTTP/1.0\r\n\r\n", name);
 
   myBuffer[0] = 0;
 
   socketHttp = IPOpen(IP_MODE_TCP, ip0, 80, TelnetHttpCallback);
 
}
 
 
 
 
static void TelnetShow(IPSocket *socket, char *command)
static void TelnetShow(IPSocket *socket, char *command)
{
{
   (char)command;
   int i;
   IPPrintf(socket, myBuffer);
   (void)command;
 
   // Insert '\r' before '\n'
 
   for(i = 0; myBuffer[i] && i < sizeof(myBuffer); ++i)
 
   {
 
      if(myBuffer[i] == '\n' && myBuffer[i-1] != '\r')
 
      {
 
         memcpy(myBuffer+i+1, myBuffer+i, sizeof(myBuffer)-2-i);
 
         myBuffer[i] = '\r';
 
      }
 
   }
 
   myBuffer[sizeof(myBuffer)-1] = 0;
 
   IPPrintf(socket, (char*)myBuffer);
   IPPrintf(socket, "\r\n");
   IPPrintf(socket, "\r\n");
}
}
 
 
 
 
static void TelnetClear(IPSocket *socket, char *command)
static void TelnetClear(IPSocket *socket, char *command)
{
{
 
   (void)socket;
 
   (void)command;
   memset(myBuffer, 0, sizeof(myBuffer));
   memset(myBuffer, 0, sizeof(myBuffer));
}
}
 
 
 
 
static TelnetFunc_t MyFuncs[] = {
static TelnetFunc_t MyFuncs[] = {
   "info", 0, TelnetInfo,
   "info", 0, TelnetInfo,
   "math", 0, TelnetMath,
   "math", 0, TelnetMath,
   "ping", 0, TelnetPing,
   "ping", 0, TelnetPing,
   "ftp", 0, TelnetFtp,
   "ftp", 0, TelnetFtp,
   "tftp", 0, TelnetTftp,
   "tftp", 0, TelnetTftp,
 
   "http", 0, TelnetHttp,
   "show", 0, TelnetShow,
   "show", 0, TelnetShow,
   "clear", 0, TelnetClear,
   "clear", 0, TelnetClear,
   NULL, 0, NULL
   NULL, 0, NULL
};
};
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.