void HandleClient(object obj) { try { using (TcpClient client = (TcpClient)obj) using (NetworkStream stream = client.GetStream()) { while (isConnected) { try { long timeStamp = 0; string receivedData = ReadLine(stream); string parsedCommand = ParseCommand(receivedData); SCIPCommands command = (SCIPCommands)Enum.Parse(typeof(SCIPCommands), parsedCommand); switch (command) { case SCIPCommands.QT: distances.Clear(); intensities.Clear(); isConnected = false; break; case SCIPCommands.MD: distances.Clear(); SCIP_Reader.MD(receivedData, ref timeStamp, ref distances); break; case SCIPCommands.GD: distances.Clear(); SCIP_Reader.GD(receivedData, ref timeStamp, ref distances); break; case SCIPCommands.ME: distances.Clear(); intensities.Clear(); SCIP_Reader.ME(receivedData, ref timeStamp, ref distances, ref intensities); break; default: Debug.Log(receivedData); isConnected = false; break; } } catch (Exception e) { Debug.LogException(e); } } } } catch (Exception e) { Debug.LogException(e); } }
public static bool distance_strength_data(string[] lines, int start_line, ref List <long> distances, ref List <long> strengths) { StringBuilder sb = new StringBuilder(); for (int i = start_line; i < lines.Length; ++i) { sb.Append(lines[i].Substring(0, lines[i].Length - 1)); } return(SCIP_Reader.decode_array(sb.ToString(), 3, ref distances, ref strengths)); }
public static bool GD(string get_command, ref long time_stamp, ref List <long> distances) { //distances.Clear(); string[] split_command = get_command.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); // if (!split_command[0].StartsWith("GD")) { // return false; // } if (split_command[1].StartsWith("00")) { time_stamp = SCIP_Reader.decode(split_command[2], 4); distance_data(split_command, 3, ref distances); return(true); } else { return(false); } }
private void HandleClientComm(object obj) { try { using (TcpClient client = (TcpClient)obj) { using (NetworkStream stream = client.GetStream()) { // NetworkStream clientStream = client.GetStream(); while (true) { long time_stamp = 0; string receive_data = read_line(stream); // messageQueue.Enqueue( receive_data ); string cmd = GetCommand(receive_data); if (cmd == GetCMDString(CMD.MD)) { distances.Clear(); SCIP_Reader.MD(receive_data, ref time_stamp, ref distances); } else if (cmd == GetCMDString(CMD.ME)) { distances.Clear(); strengths.Clear(); SCIP_Reader.ME(receive_data, ref time_stamp, ref distances, ref strengths); } else { Debug.Log(">>" + receive_data); } } // client.Close(); } } } catch (System.Exception ex) { Debug.LogWarning("error: " + ex); } }