components/vnc_server/vnc-server.c

changeset 21
9e4cce24f6ff
parent 6
e84200edc852
child 30
3cc32f97410c
equal deleted inserted replaced
20:3fd5e0fc075f 21:9e4cce24f6ff
1002 /** 1002 /**
1003 * @brief Websocket task. Created on a websocket connection. 1003 * @brief Websocket task. Created on a websocket connection.
1004 */ 1004 */
1005 void task_WS(void *pvParameter) 1005 void task_WS(void *pvParameter)
1006 { 1006 {
1007 int i, j, num_of_encodings, rest_time; 1007 int i, j, num_of_encodings;
1008 uint16_t *ptr_to_uint16; 1008 uint16_t *ptr_to_uint16;
1009 struct strMessage _msg; 1009 struct strMessage _msg;
1010 1010
1011 // Do pin/pong.
1012
1013 VNC_WS_run = true; 1011 VNC_WS_run = true;
1014 rest_time = 0;
1015 1012
1016 while (VNC_WS_run) { 1013 while (VNC_WS_run) {
1017 1014
1018 /* 1015 /*
1019 * Wait until something is received from the client. Exit the queue receiver 1016 * Wait until something is received from the client. Exit the queue receiver
1020 * each 5 milliseconds to allow to evaluate the VNC_WS_run flag and to allow 1017 * each 5 milliseconds to allow to evaluate the VNC_WS_run flag and to allow
1021 * a clean exit of this task. 1018 * a clean exit of this task.
1022 */ 1019 */
1023 if (xQueueReceive(message_queue, &_msg, 5 / portTICK_PERIOD_MS) == pdTRUE) { 1020 if (xQueueReceive(message_queue, &_msg, 5 / portTICK_PERIOD_MS) == pdTRUE) {
1024 // dump_msg((char *)_msg.message, _msg.length, "pull");
1025 1021
1026 switch (_msg.message[0]) { 1022 switch (_msg.message[0]) {
1027 1023
1028 case SET_PIXEL_FORMAT: 1024 case SET_PIXEL_FORMAT:
1029 // printf("SET_PIXEL_FORMAT\n");
1030 /* Check total message length */ 1025 /* Check total message length */
1031 if (_msg.length >= 20) { 1026 if (_msg.length >= 20) {
1032 /* Check pixel format is as expected */ 1027 /* Check pixel format is as expected */
1033 i = 0; 1028 i = 0;
1034 if (_msg.message[4] != BITS_PER_PIXEL) { 1029 if (_msg.message[4] != BITS_PER_PIXEL) {
1129 break; 1124 break;
1130 default: /* Unknown coding type - do nothing */ 1125 default: /* Unknown coding type - do nothing */
1131 break; 1126 break;
1132 } 1127 }
1133 } 1128 }
1134
1135 if (encoding_type.corre) {
1136 ESP_LOGI(TAG, "SetEncodings use CORRE");
1137 } else {
1138 ESP_LOGI(TAG, "SetEncodings use RAW");
1139 }
1140 } 1129 }
1141 break; 1130 break;
1142 1131
1143 case FRAME_BUFFER_UPDATE_REQ: 1132 case FRAME_BUFFER_UPDATE_REQ:
1144 if (_msg.length == 10) { 1133 if (_msg.length == 10) {
1171 if (_msg.length == 6) { 1160 if (_msg.length == 6) {
1172 /* Set global variables that will be read by another task. */ 1161 /* Set global variables that will be read by another task. */
1173 VNC_pointer_button = _msg.message[1]; 1162 VNC_pointer_button = _msg.message[1];
1174 VNC_pointer_x = _msg.message[2]*255 + _msg.message[3]; 1163 VNC_pointer_x = _msg.message[2]*255 + _msg.message[3];
1175 VNC_pointer_y = _msg.message[4]*255 + _msg.message[5]; 1164 VNC_pointer_y = _msg.message[4]*255 + _msg.message[5];
1176 // printf("POINTER_EVENT button=%02x x=%d y=%d\n", VNC_pointer_button, VNC_pointer_x, VNC_pointer_y);
1177 } 1165 }
1178 _msg.length = 0; 1166 _msg.length = 0;
1179 break; 1167 break;
1180 1168
1181 case CLIENT_CUT_TEXT: 1169 case CLIENT_CUT_TEXT:
1182 printf("CLIENT_CUT_TEXT\n"); 1170 printf("CLIENT_CUT_TEXT\n");
1183 break; 1171 break;
1184 1172
1185 default: 1173 default:
1186 ESP_LOGI(TAG, "Unknown message %d from client", _msg.message[0]); 1174 ESP_LOGI(TAG, "Unknown message %d from client", _msg.message[0]);
1187 }
1188 rest_time = 0;
1189 } else {
1190 rest_time++; // Each 5 milliseconds
1191 if (rest_time == 2000) {
1192 // 10 seconds silence, send a PING
1193 rest_time = 0;
1194 // int rc = ws_server_ping(VNC_WS_num);
1195 // ESP_LOGI(TAG, "Send PING to %d, rc=%d", VNC_WS_num, rc);
1196 } 1175 }
1197 } 1176 }
1198 } 1177 }
1199 1178
1200 VNC_WS_num = -1; 1179 VNC_WS_num = -1;

mercurial