public SumoSender(string host, int port) { this.Host = host; this.Port = port; this.seq_ids = new DefaultDict <int, int>(); SumoRemote = new IPEndPoint(IPAddress.Parse(host), port); sumoSocket = new UdpClient(); // Initial command (no motion) this.cmd = SumoCommandsCustom._pack_frame(SumoCommandsCustom.Move_cmd(0, 0)); }
private void SumoSend() { try { LOGGER.GetInstance.Info("[SumoSender] Thread Started"); while (isConnected) { sumoSocket.Send(this.cmd, this.cmd.Length, SumoRemote); this.cmd = SumoCommandsCustom._pack_frame(SumoCommandsCustom.Move_cmd(0, 0)); Thread.Sleep(40); } } catch (Exception e) { LOGGER.GetInstance.Error(e.Message); } LOGGER.GetInstance.Info("[SumoSender] Thread Stopped"); }
/// <summary> /// Sends the given command to the Jumping Sumo. Non-PCMD commands are sent immediately /// while PCMD commands are sent at the next cycle(see run). cmd is the payload and the /// method creates a frame by prepending a header /// </summary> /// <param name="cmd"></param> public void Send(byte[] cmd) { if (isConnected) { if (cmd != null) { byte[] frame = this._update_seq(SumoCommandsCustom._pack_frame(cmd)); if (SumoCommandsCustom._is_pcmd(frame)) { this.cmd = frame; } else { sumoSocket.Send(frame, frame.Length, SumoRemote); } } } }