Cosmos/source/SSchockeTest/Program.cs
sschocke_cp f2ee6c3dd8 TCP/IP Stack now supports listening for incoming and sending outgoing UDP Packets. See Program.cs in my SSchockeTest project for example usage.
Cosmos.Sys project outputs XML documentation for classes that have documentation. This should be helpful for people playing around with the new User Kit.
2009-03-22 07:07:33 +00:00

74 lines
No EOL
2.5 KiB
C#

using System;
using Cosmos.Compiler.Builder;
using HW = Cosmos.Hardware;
using Cosmos.Kernel;
using System.Collections.Generic;
using Cosmos.Sys.Network;
namespace Cosmos.Playground.SSchocke {
class Program
{
#region Cosmos Builder logic
// Most users wont touch this. This will call the Cosmos Build tool
[STAThread]
static void Main(string[] args) {
BuildUI.Run();
}
#endregion
// Main entry point of the kernel
public static void Init() {
var xBoot = new Cosmos.Sys.Boot();
xBoot.Execute();
Console.WriteLine("Congratulations! You just booted SSchocke's C# code.");
Console.WriteLine("Scanning for AMD PCNET Networks Cards...");
HW.Network.NetworkDevice nic = null;
foreach (HW.PCIDevice dev in HW.PCIBus.Devices)
{
if ((dev.VendorID == 0x1022) && (dev.DeviceID == 0x2000))
{
nic = new HW.Network.Devices.AMDPCNetII.AMDPCNet(dev);
Console.WriteLine("Found AMD PCNet NIC on PCI " + dev.Bus + ":" + dev.Slot + ":" + dev.Function);
Console.WriteLine("NIC IRQ: " + dev.InterruptLine);
Console.WriteLine("NIC MAC Address: " + nic.MACAddress.ToString());
break;
}
}
Console.WriteLine("Initializing NIC...");
nic.Enable();
Console.WriteLine("Initializing TCP Stack...");
TCPIPStack.Init();
TCPIPStack.ConfigIP(nic, new IPv4Config(new IPv4Address(192, 168, 20, 123), new IPv4Address(255, 255, 255, 0)));
Console.WriteLine("Subscribing to UDP Port 1234...");
TCPIPStack.SubscribeUDPPort(1234, UDP1234_RecvData);
while (true)
{
TCPIPStack.Update();
}
Console.WriteLine("Press a key to shutdown...");
Console.Read();
Cosmos.Sys.Deboot.ShutDown();
}
private static void UDP1234_RecvData(IPv4EndPoint source, byte[] data)
{
Console.WriteLine("Received data on UDP port 1234 from " + source.ToString());
TCPIPStack.SendUDP(source.IPAddress, 1234, 1534, data);
}
/*private static void WriteBinaryBuffer(byte[] buffer)
{
foreach (byte b in buffer)
{
Console.Write(b.ToHex(2) + " ");
}
Console.WriteLine();
}*/
}
}