/// <summary> /// Processes the given json request. /// </summary> /// <param name="request">the json request in string format</param> private void ProcessRequest(string request) { Debug.Log("Message received from Base Station: " + request); int typeStartIndex = request.IndexOf("type") + 7; int typeEndIndex = request.Substring(typeStartIndex).IndexOf("\""); string type = request.Substring(typeStartIndex, typeEndIndex); switch (type) { case "drive": DriveRequest driveRequest = JsonUtility.FromJson <DriveRequest>(request); rover.SetVelocity(driveRequest.forward_backward, driveRequest.left_right); break; case "estop": EStopRequest eStopRequest = JsonUtility.FromJson <EStopRequest>(request); rover.EStop(eStopRequest.release); break; case "motor": // Need to convert key name to a valid field name request = request.Replace("PWM target", "PWM_target"); MotorRequest motorRequest = JsonUtility.FromJson <MotorRequest>(request); rover.SetMotorPower(motorRequest.motor, motorRequest.PWM_target); break; default: Debug.LogError("Unknown request type: " + request); break; } }
public static async Task <PnpFileModel> GetAsync(FileHandlerActivationParameters parameters, System.Web.Mvc.UrlHelper url) { // Retrieve an access token so we can make API calls string accessToken = null; try { accessToken = await AuthHelper.GetUserAccessTokenSilentAsync(parameters.ResourceId); } catch (Exception ex) { return(GetError(parameters, ex)); } // Read the details of the specified item GraphServiceClient graphServiceClient = GraphHelper.Default.GetGraphServiceClient(accessToken); IDriveRequest request = new DriveRequest(parameters.ItemUrls[0], graphServiceClient, Array.Empty <Option>()); Drive drive = await request.GetAsync(); return(new PnpFileModel(parameters) { Title = drive.Name, // Create uri to use to load the content PreviewUri = url.Action("PreviewInfo", new { resourceId = parameters.ResourceId, uri = parameters.ItemUrls[0] + "/content" }) }); }