Operating System

Dependencies:   UnitTest mDNS

This is an operating system for K64F. It includes ssh server, POST, a web-server and mDNS.

Revision:
0:97ba3e2cd071
Child:
1:4059ac7ebc65
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jun 13 13:08:37 2019 +0000
@@ -0,0 +1,203 @@
+#include "mbed.h"
+#include <EthernetInterface.h>
+#include <FreescaleIAP.h>
+#include <drivers/vga.h>
+#include <gui/desktop.h>
+
+//#define DEBUG
+//#define GRAPHICSMODE
+
+const int PORT = 8000;
+
+static const char* SERVER_IP = "172.26.10.207"; //IP of server board
+char screen[3840];
+
+DigitalOut red(LED_RED);
+DigitalOut blue(LED_BLUE);
+DigitalOut green(LED_GREEN);
+
+/*class TransmissionControlProtocolHandler
+        {
+        public:
+            TransmissionControlProtocolHandler();
+            ~TransmissionControlProtocolHandler();
+            virtual bool HandleTransmissionControlProtocolMessage(TCPSocket* socket, char* data, uint16_t size);
+        };
+        
+class PrintfTCPHandler : public TransmissionControlProtocolHandler
+{
+public:*/
+    bool HandleTransmissionControlProtocolMessage(TCPSocket* socket, char* data, uint16_t size)
+    {
+        if(size > 9
+            && data[0] == 'G'
+            && data[1] == 'E'
+            && data[2] == 'T'
+            && data[3] == ' '
+            && data[4] == '/'
+            && data[5] == ' '
+            && data[6] == 'H'
+            && data[7] == 'T'
+            && data[8] == 'T'
+            && data[9] == 'P'
+        )
+        {
+            socket->send((uint8_t*)"HTTP/1.1 200 OK\r\nServer: MyOS\r\nContent-Type: text/html\r\n\r\n<html><head><title>My Operating System</title></head><body><b>My Operating System</b> http://www.AlgorithMan.de</body></html>\r\n", 184);
+            socket->close();
+        }
+
+        return true;
+    }
+//};
+
+int main() {
+    red = 1;
+    blue = 0;
+    green = 1;
+    
+    printf("Hello World! --- http://www.AlgorithMan.de\n");
+
+    //TaskManager taskManager;
+    /*
+    Task task1(&gdt, taskA);
+    Task task2(&gdt, taskB);
+    taskManager.AddTask(&task1);
+    taskManager.AddTask(&task2);
+    */
+
+    //InterruptManager interrupts(0x20, &gdt, &taskManager);
+    //SyscallHandler syscalls(&interrupts, 0x80);
+
+    printf("Initializing Hardware, Stage 1\n");
+    
+    #ifdef GRAPHICSMODE
+        Desktop desktop(320, 200, 0x00, 0x00, 0xA8);
+    #endif
+    
+    //DriverManager drvManager;
+
+        #ifdef GRAPHICSMODE
+            //KeyboardDriver keyboard(&interrupts, &desktop);
+        #else
+            //PrintfKeyboardEventHandler kbhandler;
+            //KeyboardDriver keyboard(&interrupts, &kbhandler);
+        #endif
+        //drvManager.AddDriver(&keyboard);
+
+
+        #ifdef GRAPHICSMODE
+            //MouseDriver mouse(&interrupts, &desktop);
+        #else
+            //MouseToConsole mousehandler;
+            //MouseDriver mouse(&interrupts, &mousehandler);
+        #endif
+        //drvManager.AddDriver(&mouse);
+
+        //PeripheralComponentInterconnectController PCIController;
+        //PCIController.SelectDrivers(&drvManager, &interrupts);
+        
+        #ifdef GRAPHICSMODE
+            VideoGraphicsArray vga;
+        #endif
+        
+    printf("Initializing Hardware, Stage 2\n");
+        //drvManager.ActivateAll();
+
+    printf("Initializing Hardware, Stage 3\n");
+
+    #ifdef GRAPHICSMODE
+        vga.SetMode(320, 200, 8);
+        Window win1(&desktop, 10, 10, 20, 20, 0xA8, 0x00, 0x00);
+        desktop.AddChild(&win1);
+        Window win2(&desktop, 40, 15, 30, 30, 0x00, 0xA8, 0x00);
+        desktop.AddChild(&win2);
+    #endif
+
+
+    /*
+    printf("\nS-ATA primary master: ");
+    AdvancedTechnologyAttachment ata0m(true, 0x1F0);
+    ata0m.Identify();
+
+    printf("\nS-ATA primary slave: ");
+    AdvancedTechnologyAttachment ata0s(false, 0x1F0);
+    ata0s.Identify();
+    ata0s.Write28(0, (uint8_t*)"http://www.AlgorithMan.de", 25);
+    ata0s.Flush();
+    ata0s.Read28(0, 25);
+
+    printf("\nS-ATA secondary master: ");
+    AdvancedTechnologyAttachment ata1m(true, 0x170);
+    ata1m.Identify();
+
+    printf("\nS-ATA secondary slave: ");
+    AdvancedTechnologyAttachment ata1s(false, 0x170);
+    ata1s.Identify();
+    // third: 0x1E8
+    // fourth: 0x168
+    */
+    EthernetInterface interface;
+    interface.disconnect();
+    interface.connect();
+       
+    // Show the network address
+    const char *ip = interface.get_ip_address();
+    printf("IP address is: %s\n", ip ? ip : "No IP");
+    
+    //AddressResolutionProtocol arp(&etherframe);
+
+    //InternetProtocolProvider ipv4(&etherframe, &arp, gip_be, subnet_be);
+    //InternetControlMessageProtocol icmp(&ipv4);
+    //UserDatagramProtocolProvider udp(&ipv4);
+    //TransmissionControlProtocolProvider tcp(&ipv4);
+
+
+    //interrupts.Activate();
+
+    printf("\n\n\n\n");
+
+    //PrintfTCPHandler tcphandler;
+    TCPServer server;
+    UDPSocket sockUDP(&interface);                 //creat Ethernet socket
+    SocketAddress sockAddr(SERVER_IP, PORT);
+
+    server.open(&interface);
+    
+    server.bind(interface.get_ip_address(), 80);
+    server.listen();
+    server.set_blocking(false);
+    TCPSocket client;            //!< client class
+    SocketAddress clt_addr;
+    int bufferSize = 512;
+    char buffer[bufferSize];
+    
+    //TransmissionControlProtocolSocket* tcpsocket = tcp.Connect(ip2_be, 1234);
+    //tcpsocket->Send((uint8_t*)"Hello TCP!", 10);
+
+    //icmp.RequestEchoReply(gip_be);
+
+    //PrintfUDPHandler udphandler;
+    //UserDatagramProtocolSocket* udpsocket = udp.Connect(ip2_be, 1234);
+    //udp.Bind(udpsocket, &udphandler);
+    //udpsocket->Send((uint8_t*)"Hello UDP!", 10);
+
+    //UserDatagramProtocolSocket* udpsocket = udp.Listen(1234);
+    //udp.Bind(udpsocket, &udphandler);
+    
+    while (true){
+          //printf("\nCLIENT - Sending '%i' to server %s\r\n", screen[0], SERVER_IP);       //print message to send
+          sockUDP.sendto(SERVER_IP, PORT, screen, sizeof(screen));
+          server.accept(&client, &clt_addr);
+          int len = client.recv(&buffer, bufferSize);
+          
+#ifdef DEBUG
+      printf("%d: ", len);
+      for (int i = 0; i < len; i++)
+          printf("%d ", buffer[i]);
+      printf("\r\n");
+#endif
+
+          HandleTransmissionControlProtocolMessage(&client, (char*)buffer, len);
+          wait(0.03333333);
+       }
+}
\ No newline at end of file