Beispiel #1
0
        public static unsafe GetRobotsProtoReply GetRobots(GetRobotsProtoRequest getRobots)
        {
            var buffer = getRobots.ToByteArray();

            fixed(byte *p = buffer)
            {
                IntPtr ptr       = (IntPtr)p;
                var    protoMsgC = new ProtoMessageC
                {
                    data = new SWIGTYPE_p_void(ptr, false),
                    len  = (uint)buffer.Length
                };
                var sdkReturn = animus_client_sdk.GetRobotsGo(protoMsgC);

                if (sdkReturn == null)
                {
                    return(new GetRobotsProtoReply
                    {
                        LocalSearchError = new Error {
                            Success = false
                        },
                        RemoteSearchError = new Error {
                            Success = false
                        },
                    });
                }

                var err = new GetRobotsProtoReply();

                err.MergeFrom(sdkReturn.GetBytes());
                return(err);
            }
        }
        private void ThreadedSearch(bool getLocal, bool getRemote, GeoStruct chosenRange)
        {
            searchSuccess          = false;
            searchResultsAvailable = false;
            searchReturn           = "";
            var errorFlag = false;

            var getRobotsRequest = new GetRobotsProtoRequest {
                GetLocal = false, GetRemote = true, Georange = chosenRange
            };
            var getRobotsReply = AnimusClient.AnimusClient.GetRobots(getRobotsRequest);

            if (getRobotsReply.LocalSearchError != null)
            {
                if (!getRobotsReply.LocalSearchError.Success)
                {
                    errorFlag    = true;
                    searchReturn = getRobotsReply.LocalSearchError.Description;
                }
            }

            if (getRobotsReply.RemoteSearchError != null)
            {
                if (!getRobotsReply.RemoteSearchError.Success)
                {
                    errorFlag     = true;
                    searchReturn += " " + getRobotsReply.RemoteSearchError.Description;
                }
            }

            if (errorFlag)
            {
                Debug.Log("Error searching robots: " + searchReturn);
                searchResultsAvailable = true;
                return;
            }


            if (getRobotsReply.Robots.Count > 0)
            {
                _norobotsCount = 0;

                foreach (Robot a in getRobotsReply.Robots)
                {
                    robotDetailsList.Add(a);
                    Debug.Log($"{a.Make} {a.Model} robot called {a.Name}");
                }

                Debug.Log("Finished search and robots found");
                searchSuccess = true;
            }
            else
            {
                Debug.Log("Robots not found");

                _norobotsCount += 1;
                if (_norobotsCount >= _norobotsMoreDetails)
                {
                    searchReturn =
                        "No robots found. Please search again.\nIf problem persists, check your WiFi connection or the robot's WiFi connection";
                }
                else
                {
                    searchReturn = "No robots found. Please search again.";
                }
            }

            searchResultsAvailable = true;
        }