void EncodeMessage() { //encoded message to be written float cte = wpt.CrossTrackError(_carController); writeBuffer[0] = BitConverter.GetBytes(cte)[0]; writeBuffer[1] = BitConverter.GetBytes(cte)[1]; writeBuffer[2] = BitConverter.GetBytes(cte)[2]; writeBuffer[3] = BitConverter.GetBytes(cte)[3]; float speed = _carController.CurrentSpeed; writeBuffer[4] = BitConverter.GetBytes(speed)[0]; writeBuffer[5] = BitConverter.GetBytes(speed)[1]; writeBuffer[6] = BitConverter.GetBytes(speed)[2]; writeBuffer[7] = BitConverter.GetBytes(speed)[3]; string Image = Convert.ToBase64String(CameraHelper.CaptureFrame(FrontFacingCamera)); var encoding = Encoding.UTF8; encoding.GetBytes(Image, 0, Image.Length, writeBuffer, 8); writeBufferSize = 8 + Image.Length; //Debug.Log(writeBufferSize); }
void EmitTelemetry(SocketIOEvent obj) { UnityMainThreadDispatcher.Instance().Enqueue(() => { print("Attempting to Send..."); // send only if it's not being manually driven if ((Input.GetKey(KeyCode.W)) || (Input.GetKey(KeyCode.S))) { _socket.Emit("telemetry", new JSONObject()); } else { // Collect Data from the Car Dictionary <string, JSONObject> data = new Dictionary <string, JSONObject>(); var cte = wpt.CrossTrackError(_carController); data["steering_angle"] = new JSONObject(_carController.CurrentSteerAngle); data["throttle"] = new JSONObject(_carController.AccelInput); data["speed"] = new JSONObject(_carController.CurrentSpeed); data["cte"] = new JSONObject(cte); Dictionary <string, string> images = new Dictionary <string, string>(); images["camera0"] = Convert.ToBase64String(CameraHelper.CaptureFrame(FrontFacingCamera)); data["images"] = new JSONObject(images); _socket.Emit("telemetry", new JSONObject(data)); } }); }