1 /** |
|
2 * @file vnc-server.h |
|
3 * @brief VNC server original written for eCos. |
|
4 * |
|
5 * The VNC server runs on the target platform and waits for a client |
|
6 * (vncviewer program running on a PC) to connect via an ethernet connection |
|
7 * (port 5900). Once a client has connected, the target platform has a |
|
8 * virtual screen, keyboard and mouse. |
|
9 * |
|
10 * This port of the VNC server has been designed with some limitations in |
|
11 * order to keep memory and processor power requirements to a minimum. |
|
12 * |
|
13 * The VNC client must accept the settings that the VNC server suggests (bits-per-pixel, |
|
14 * number-of-colours and so on as specified at build time with the eCos configuration |
|
15 * tool) or the VNC server will just disconnect. |
|
16 * |
|
17 * The VNC server only supports CoRRE encoding and RAW encoding for sending |
|
18 * display data to the client. |
|
19 * |
|
20 * The VNC server does not support password authentication, the client is able |
|
21 * to connect without the user typing in a password. |
|
22 * |
|
23 * Only one VNC client may connect to the VNC server at a time. |
|
24 * |
|
25 * In reality these limitations are not a problem. |
|
26 * |
|
27 * @author Chris Garry <cgarry@sweeneydesign.co.uk> |
|
28 * @author Michiel Broek. |
|
29 */ |
|
30 |
|
31 |
|
32 |
|
33 #include <stdio.h> |
|
34 #include <stdlib.h> |
|
35 #include <stdint.h> |
|
36 #include <string.h> |
|
37 #include <stdbool.h> |
|
38 #include <errno.h> |
|
39 #include <sys/unistd.h> |
|
40 #include "lwip/sockets.h" |
|
41 #include "lwip/netdb.h" |
|
42 #include "esp_log.h" |
|
43 #include "freertos/FreeRTOS.h" |
|
44 #include "freertos/task.h" |
|
45 #include "freertos/semphr.h" |
|
46 #include "freertos/event_groups.h" |
|
47 |
|
48 |
|
49 |
|
50 /** |
|
51 * @brief Type to hold the frame format details |
|
52 */ |
|
53 typedef struct |
|
54 { |
|
55 uint16_t frame_width; ///< Frame width |
|
56 uint16_t frame_height; ///< Frame height |
|
57 void *frame_buffer; ///< Frame buffer data |
|
58 bool rgb332; ///< 8 bits RGB format (only one is set). |
|
59 bool rgb555; ///< 15 bits RGB |
|
60 bool rgb565; ///< 16 bits RGB |
|
61 bool bgr233; ///< 8 bits BGR format |
|
62 bool truecolor0888; ///< 24 bits truecolor. |
|
63 } vnc_frame_format_t; |
|
64 |
|
65 |
|
66 |
|
67 typedef uint8_t vnc_color_t; |
|
68 |
|
69 |
|
70 |
|
71 /** |
|
72 * @brief Start the VNC server. Two tasks are started, one to handle the |
|
73 * clients and one that serves the updates of the framebuffer. |
|
74 */ |
|
75 void VncStartup(void); |
|
76 |
|
77 /** |
|
78 * @brief Clear the display and set a background color. |
|
79 * @param color Then RGB color for the background. |
|
80 */ |
|
81 void VncCls(vnc_color_t color); |
|
82 |
|
83 /** |
|
84 * @brief Draw a pixel on the display. |
|
85 * @param x The horizontal position of the pixel. |
|
86 * @param y The vertical position of the pixel. |
|
87 * @param color The RGB value of the pixel. |
|
88 */ |
|
89 void VncDrawPixel(uint16_t x, uint16_t y, vnc_color_t color); |
|
90 |
|
91 /** |
|
92 * @brief Draw a horizontal line on the display. |
|
93 * @param x1 Start horizontal position. |
|
94 * @param x2 End of the horizontal position. |
|
95 * @param y The vertical position of the line. |
|
96 * @param color The RGB color of the line. |
|
97 */ |
|
98 void VncDrawHorzLine(uint16_t x1, uint16_t x2, uint16_t y, vnc_color_t color); |
|
99 |
|
100 /** |
|
101 * @brief Draw a vertical line on the display. |
|
102 * @param x The jprizontal position of the line. |
|
103 * @param y1 The vertical top position of the line. |
|
104 * @param y2 The vertical bottom position of the line. |
|
105 * @param color The RGB color of the line. |
|
106 */ |
|
107 void VncDrawVertLine(uint16_t x, uint16_t y1, uint16_t y2, vnc_color_t color); |
|
108 |
|
109 /** |
|
110 * @brief Fill a rectangle with the given color. |
|
111 * @param x1 The top-left horizontal start position. |
|
112 * @param y1 The top-left vertical start position. |
|
113 * @param x2 The bottom-right horizontal end position. |
|
114 * @param y2 The bottom-right vertical end position. |
|
115 * @param color The RGB color of the line. |
|
116 */ |
|
117 void VncFillRect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, vnc_color_t color); |
|
118 |
|
119 /** |
|
120 * @brief Sound the bell on the client computer. |
|
121 */ |
|
122 void VncSoundBell(void); |
|
123 |
|
124 |
|
125 /** |
|
126 * @brief Macro to convert from RGB to colour values |
|
127 */ |
|
128 #define VNC_RGB2COL(r,g,b) (vnc_color_t)(((((uint8_t)r)&0xE0) >> 0) | ((((uint8_t)g)&0xE0) >> 3) | ((((uint8_t)b)&0xC0) >> 6)) |
|
129 |
|
130 |
|
131 /** |
|
132 * @brief Start task for a websocket client. |
|
133 */ |
|
134 int VncStartWS(int num); |
|
135 |
|
136 /** |
|
137 * @brief Stop task for a websocket client. |
|
138 */ |
|
139 void VncStopWS(int num); |
|
140 |
|
141 /** |
|
142 * @brief Remote websocket message to the VNC server. |
|
143 */ |
|
144 void VncGetWSmessage(char *msg, uint16_t len); |
|
145 |
|