components/vnc_server/vnc-server.c

changeset 30
3cc32f97410c
parent 21
9e4cce24f6ff
equal deleted inserted replaced
29:45647136ec95 30:3cc32f97410c
31 #include "vnc-server.h" 31 #include "vnc-server.h"
32 #include "websocket_server.h" 32 #include "websocket_server.h"
33 33
34 static const char *TAG = "vnc-server"; 34 static const char *TAG = "vnc-server";
35 35
36 #define BACKLOG 5 /* Number of pending connections queue will hold */ 36 #define BACKLOG 5 ///< Number of pending connections queue will hold
37 #define MESSAGE_BUFFER_SIZE 60 /* Was 50, but I have seen 52 bytes length */ 37 #define MESSAGE_BUFFER_SIZE 60 ///< Was 50, but I have seen 52 bytes length
38 #define TILE_SIZE 16 38 #define TILE_SIZE 16 ///< Tile dimension
39 #define TRUE_COLOUR_FLAG 1 /* True colour is set */ 39 #define TRUE_COLOUR_FLAG 1 ///< True colour is set
40 #define BIG_ENDIAN_FLAG 1 /* Always send colour data big endian */ 40 #define BIG_ENDIAN_FLAG 1 ///< Always send colour data big endian
41 41
42 /* Default display parameters */ 42 /* Default display parameters */
43 #define BITS_PER_PIXEL 8 /* Bits per pixel */ 43 #define BITS_PER_PIXEL 8 ///< Bits per pixel
44 #define PIXEL_DEPTH 8 /* Usefull bits per pixel */ 44 #define PIXEL_DEPTH 8 ///< Usefull bits per pixel
45 #define RED_MAX 7 45 #define RED_MAX 7 ///< Red maximum
46 #define GREEN_MAX 7 46 #define GREEN_MAX 7 ///< Green maximum
47 #define BLUE_MAX 3 47 #define BLUE_MAX 3 ///< Blue maximum, together 8 bits.
48 #define RED_SHIFT 5 48 #define RED_SHIFT 5 ///< Red shift in color byte
49 #define GREEN_SHIFT 2 49 #define GREEN_SHIFT 2 ///< Green shift in color byte
50 #define BLUE_SHIFT 0 50 #define BLUE_SHIFT 0 ///< Blue shift in color byte
51 51
52 52
53 /* Initial default RGB332 */ 53 /* Initial default RGB332 */
54 uint8_t Bits_Per_Pixel = 8; 54 uint8_t Bits_Per_Pixel = 8; ///< Current number of bits per pixel
55 55
56 uint16_t Red_Max = RED_MAX; 56 uint16_t Red_Max = RED_MAX; ///< Current Red maxmimum
57 uint16_t Green_Max = GREEN_MAX; 57 uint16_t Green_Max = GREEN_MAX; ///< Current Green maximum
58 uint16_t Blue_Max = BLUE_MAX; 58 uint16_t Blue_Max = BLUE_MAX; ///< Current Blue maximum
59 uint8_t Red_Shift = RED_SHIFT; 59 uint8_t Red_Shift = RED_SHIFT; ///< Current Red bits shift
60 uint8_t Green_Shift = GREEN_SHIFT; 60 uint8_t Green_Shift = GREEN_SHIFT; ///< Current Green bits shift
61 uint8_t Blue_Shift = BLUE_SHIFT; 61 uint8_t Blue_Shift = BLUE_SHIFT; ///< Current Blue bits shift
62 bool AltPixels = false; 62 bool AltPixels = false; ///< Alternate the pixels
63 63
64 /* Client to Server message types */ 64 /* Client to Server message types */
65 #define SET_PIXEL_FORMAT 0 65 #define SET_PIXEL_FORMAT 0 ///< Set pixel format
66 #define FIX_COLOUR_MAP_ENTRIES 1 66 #define FIX_COLOUR_MAP_ENTRIES 1 ///< Fix color map entries (not used)
67 #define SET_ENCODINGS 2 67 #define SET_ENCODINGS 2 ///< Set encodings
68 #define FRAME_BUFFER_UPDATE_REQ 3 68 #define FRAME_BUFFER_UPDATE_REQ 3 ///< Request frame buffer update
69 #define KEY_EVENT 4 69 #define KEY_EVENT 4 ///< Keyboard event (not used)
70 #define POINTER_EVENT 5 70 #define POINTER_EVENT 5 ///< Pointer event, translated to touch events
71 #define CLIENT_CUT_TEXT 6 71 #define CLIENT_CUT_TEXT 6 ///< Text editing, not used.
72 72
73 /* Macros to split colour to bytes */ 73 /* Macros to split colour to bytes */
74 #define COLOUR2BYTE1(col) ((col>>8)&0xFF) 74 #define COLOUR2BYTE1(col) ((col>>8)&0xFF) ///< High part
75 #define COLOUR2BYTE0(col) (col&0xFF) 75 #define COLOUR2BYTE0(col) (col&0xFF) ///< Low part
76 76
77 77
78 /* Thread function prototypes */ 78 /* Thread function prototypes */
79 static TaskHandle_t xTaskClientHandler = NULL; ///< Task for VNC clients 79 static TaskHandle_t xTaskClientHandler = NULL; ///< Task for VNC clients
80 static TaskHandle_t xTaskFrameUpdate = NULL; ///< Task for framebuffer updates 80 static TaskHandle_t xTaskFrameUpdate = NULL; ///< Task for framebuffer updates
92 int length; ///< Length of the message 92 int length; ///< Length of the message
93 uint8_t message[MESSAGE_BUFFER_SIZE]; ///< The message 93 uint8_t message[MESSAGE_BUFFER_SIZE]; ///< The message
94 }; 94 };
95 95
96 96
97 uint8_t VNC_pointer_button = 0; 97 uint8_t VNC_pointer_button = 0; ///< Button mask for the mouse pointer
98 uint16_t VNC_pointer_x = 0; 98 uint16_t VNC_pointer_x = 0; ///< Mouse position X
99 uint16_t VNC_pointer_y = 0; 99 uint16_t VNC_pointer_y = 0; ///< Mouse position Y
100 100
101 101
102 /* Define size of each thread's stack */ 102 /* Define size of each thread's stack */
103 #define MIN_STACK_SIZE 3072 103 #define MIN_STACK_SIZE 3072 ///< Minimal task stack size
104 104
105 105
106 /* Messages */ 106 /**
107 char server_ProtocolVersion[] = "RFB 003.003\n"; 107 * @brief Messages
108 char bad_protocol[] = "Unsupported ProtocolVersion"; 108 */
109 char server_busy[] = "Server is Busy"; 109 static char server_ProtocolVersion[] = "RFB 003.003\n";
110 char sound_bell[] = "\2"; 110 static char bad_protocol[] = "Unsupported ProtocolVersion";
111 char desktop_name[] = "MBSE BrewBoard"; // Hardcoded, don't change or the VNC webclient breaks. 111 static char server_busy[] = "Server is Busy";
112 112 static char sound_bell[] = "\2";
113 /* Frame Buffer */ 113 static char desktop_name[] = "MBSE BrewBoard"; // Hardcoded, don't change or the VNC webclient breaks.
114
115 /**
116 * @brief Frame Buffer
117 */
114 vnc_color_t frame_buffer[CONFIG_VNC_SERVER_FRAME_HEIGHT+1][CONFIG_VNC_SERVER_FRAME_WIDTH+1]; 118 vnc_color_t frame_buffer[CONFIG_VNC_SERVER_FRAME_HEIGHT+1][CONFIG_VNC_SERVER_FRAME_WIDTH+1];
115 119
116 /* Calculate the number of tiles in the X and Y directions */ 120 /* Calculate the number of tiles in the X and Y directions */
117 #if (CONFIG_VNC_SERVER_FRAME_HEIGHT % TILE_SIZE) != 0 121 #if (CONFIG_VNC_SERVER_FRAME_HEIGHT % TILE_SIZE) != 0
118 #define NUM_TILES_Y_AXIS (CONFIG_VNC_SERVER_FRAME_HEIGHT/TILE_SIZE + 1) 122 #define NUM_TILES_Y_AXIS (CONFIG_VNC_SERVER_FRAME_HEIGHT/TILE_SIZE + 1)
119 #define LAST_TILE_HEIGHT (CONFIG_VNC_SERVER_FRAME_HEIGHT % TILE_SIZE) 123 #define LAST_TILE_HEIGHT (CONFIG_VNC_SERVER_FRAME_HEIGHT % TILE_SIZE)
120 #else 124 #else
121 #define NUM_TILES_Y_AXIS (CONFIG_VNC_SERVER_FRAME_HEIGHT/TILE_SIZE) 125 #define NUM_TILES_Y_AXIS (CONFIG_VNC_SERVER_FRAME_HEIGHT/TILE_SIZE) ///< Nr of tiles on the Y axis.
122 #define LAST_TILE_HEIGHT TILE_SIZE 126 #define LAST_TILE_HEIGHT TILE_SIZE ///< Height of the last tile.
123 #endif 127 #endif
124 128
125 #if (CONFIG_VNC_SERVER_FRAME_WIDTH % TILE_SIZE) != 0 129 #if (CONFIG_VNC_SERVER_FRAME_WIDTH % TILE_SIZE) != 0
126 #define NUM_TILES_X_AXIS (CONFIG_VNC_SERVER_FRAME_WIDTH/TILE_SIZE + 1) 130 #define NUM_TILES_X_AXIS (CONFIG_VNC_SERVER_FRAME_WIDTH/TILE_SIZE + 1)
127 #define LAST_TILE_WIDTH (CONFIG_VNC_SERVER_FRAME_WIDTH % TILE_SIZE) 131 #define LAST_TILE_WIDTH (CONFIG_VNC_SERVER_FRAME_WIDTH % TILE_SIZE)
128 #else 132 #else
129 #define NUM_TILES_X_AXIS (CONFIG_VNC_SERVER_FRAME_WIDTH/TILE_SIZE) 133 #define NUM_TILES_X_AXIS (CONFIG_VNC_SERVER_FRAME_WIDTH/TILE_SIZE) ///< Nr of tiles on the X axis.
130 #define LAST_TILE_WIDTH TILE_SIZE 134 #define LAST_TILE_WIDTH TILE_SIZE ///< Width of the last tile.
131 #endif 135 #endif
132 136
133 /* Array for marking tiles that have been updated */ 137 /**
138 * @brief Array for marking tiles that have been updated
139 */
134 int tile_updated[NUM_TILES_Y_AXIS+1][NUM_TILES_X_AXIS+1]; 140 int tile_updated[NUM_TILES_Y_AXIS+1][NUM_TILES_X_AXIS+1];
135 141
136 /* Conditional variable to signal that a client is connected and initialised */ 142 EventGroupHandle_t xEventGroupVNC; ///< Variable to signal that a client is connected and initialised
137 EventGroupHandle_t xEventGroupVNC; 143 const int VNC_CLIENT_UPDATE_REQ = BIT0; ///< Client update request event
138 const int VNC_CLIENT_UPDATE_REQ = BIT0; 144 int vnc_client_sock = -1; ///< Client network socket
139 int vnc_client_sock = -1; 145 bool vnc_client_connected = false; ///< Client connected?
140 bool vnc_client_connected = false; 146 int SoundBellCount; ///< Count the client's bell
141 147 bool VNC_WS_run = false; ///< Websocket running
142 /* Variable for sounding the client's bell */ 148 int VNC_WS_num = -1; ///< Websocket connection number
143 int SoundBellCount; 149
144 150
145 /* Variables for the Websocket client */ 151
146 bool VNC_WS_run = false; 152 /**
147 int VNC_WS_num = -1; 153 * @brief Variable to hold the frame format details
148 154 */
149
150
151 /* Variable to hold the frame format details */
152 vnc_frame_format_t frame_format = {CONFIG_VNC_SERVER_FRAME_WIDTH, CONFIG_VNC_SERVER_FRAME_HEIGHT, frame_buffer, 155 vnc_frame_format_t frame_format = {CONFIG_VNC_SERVER_FRAME_WIDTH, CONFIG_VNC_SERVER_FRAME_HEIGHT, frame_buffer,
153 1, // RGB332 server native. 156 1, // RGB332 server native.
154 0, // RGB555 157 0, // RGB555
155 0, // RGB565 158 0, // RGB565
156 0, // BGR233 159 0, // BGR233
175 printf("\n"); 178 printf("\n");
176 } 179 }
177 #endif 180 #endif
178 181
179 182
180 /* Structure to hold the encoding type details */ 183 /**
184 * @brief Structure to hold the encoding type details
185 */
181 volatile struct encoding_type_struct 186 volatile struct encoding_type_struct
182 { 187 {
183 uint8_t raw; 188 uint8_t raw;
184 uint8_t copy_rectangle; 189 uint8_t copy_rectangle;
185 uint8_t rre; 190 uint8_t rre;

mercurial