//Allows interaction with pod control parameters //Can be used from the pod state classes or more //directly from the gui during developement public bool setParameters(string node, List <DataParameter> parameters) { rPodI2CTX formatter = new rPodI2CTX(); rPodNetworkNode n = rPodNodeDiscovery.ActiveNodes.FirstOrDefault(x => x.NodeNamePretty == node); if (n == null) { return(false); } string ip = n.IP; if (n.RequestSocket == null) { n.RequestSocket = new RequestSocket(); } n.RequestSocket.Connect("tcp://" + ip + ":6789"); n.RequestSocket.TrySendFrame(TimeSpan.FromSeconds(1), formatter.formatTransmitParameters(parameters)); string reply; if (!n.RequestSocket.TryReceiveFrameString(TimeSpan.FromSeconds(1), out reply)) { n.RequestSocket.Disconnect("tcp://" + ip + ":6789"); return(false); } else if (reply == "Got It") { return(true); } return(false); }
//Allows interaction with pod control parameters //Can be used from the pod state classes or more //directly from the gui during developement public static bool setParameters(string node, List <DataParameter> parameters) { rPodI2CTX formatter = new rPodI2CTX(); //catch if that list is empty if (rPodNodeDiscovery.ActiveNodes == null || rPodNodeDiscovery.ActiveNodes.Count == 0) { return(false); //No nodes is definitely a failure } rPodNetworkNode n = rPodNodeDiscovery.ActiveNodes.FirstOrDefault(x => x.NodeNamePretty == node); if (n == null) { return(false); } string ip = n.IP; //Catch any wonky network exceptions and indicate that we failed try { if (n.RequestSocket == null) { n.RequestSocket = new RequestSocket(); } n.RequestSocket.Connect("tcp://" + ip + ":6789"); n.RequestSocket.TrySendFrame(TimeSpan.FromSeconds(1), formatter.formatTransmitParameters(parameters)); string reply; if (!n.RequestSocket.TryReceiveFrameString(TimeSpan.FromSeconds(1), out reply)) { n.RequestSocket.Disconnect("tcp://" + ip + ":6789"); n.RequestSocket.Close(); return(false); } else if (reply == "Got It") { return(true); } return(false); }catch { return(false); } }