/* * * Initial hack of an Arduino VNC server * * LGPL 2.0 * * follower@rancidbacon.com * */ #include // network configuration. gateway and subnet are optional. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte ip[] = { 169, 254, 254, 169 }; // vnc defaults to port 5900 Server server(5900); void setup() { // initialize the ethernet device Ethernet.begin(mac, ip); // start listening for clients server.begin(); } void loop() { Client client = server.connected(); // Note: Needs my Ethernet library edit if (client) { client.print("RFB 003.003\n"); // Hacky check for client response // requesting the protocol version we expect. // TODO: In all cases change to handle client disconnect etc while (1) { char c = client.read(); if (c == '\n') { break; } } // Specify security type = None // For 3.3 protocol client is expected to just accept this // and not acknowledge it. client.write(0); client.write(0); client.write(0); client.write(1); // Begin Initialisation phase while (!client.available()) { // Wait for ClientInit message from client } // Throw away shared-flag value in ClientInit message client.read(); // Send ServerInit message byte serverInitMsg[] = { 0,0xff, // framebuffer-width 0,0xff, // framebuffer-height // server-pixel-format 0x08, // bits-per-pixel 0x08, // depth 0x01, // big-endian-ßag (ignored for 8-bit) 0x01, // true-colour-ßag 0x00, 0x07,// red-max (2 bit) 0x00, 0x07,// green-max (2 bit) 0x00, 0x03,// blue-max (2 bit) 0x00, // red-shift -- assume bbgggrrr (bgr233) 0x03, // green-shift 0x06, // blue-shift 0x00, 0x00, 0x00, // padding 0x00, 0x00, 0x00, 0x07, // name-length 'A','r','d','u','i','n','o' // name-string }; for (int i = 0; i < sizeof(serverInitMsg); i++) { client.write(serverInitMsg[i]); } while (client.connected()) { } client.stop(); } }