public void Connect(string ip) { IPEndPoint iep = new IPEndPoint(IPAddress.Parse(ip), 1333); Socket clientSocket = new Socket(iep.AddressFamily, SocketType.Stream, ProtocolType.Tcp); Console.WriteLine(@"Connecting " + iep); clientSocket.Connect(iep); Console.WriteLine(iep + @" connected"); AuroraSensorData AuroraSensorData = new AuroraSensorData(); byte[] bytes = AuroraSensorData.FromByteArray(); while (true) { while (clientSocket.Available < bytes.Length) { //Console.WriteLine("clientSocket.Available = " + clientSocket.Available); } int size = clientSocket.Receive(bytes); //Console.WriteLine(string.Format("Data Received. Size = {0}", size)); AuroraSensorData = AuroraSensorData.FromByteArray(bytes); //Console.WriteLine(string.Format(AuroraSensorData.TimeStamp.ToLongTimeString())); if (IncomingAuroraSensorDataEvent != null) { IncomingAuroraSensorDataEvent(this, new IncomingAuroraSensorDataEntity(AuroraSensorData)); //Thread.Sleep(100); } } }
public static AuroraSensorData FromByteArray(byte[] byteArray) { AuroraSensorData ret = new AuroraSensorData(); int startIndex = sizeof(int); ret.TimeTick = BitConverter.ToInt64(byteArray, startIndex); startIndex += sizeof(long); ret.HasSignal = BitConverter.ToBoolean(byteArray, startIndex); startIndex += sizeof(bool); ret.SensorIdx = BitConverter.ToInt32(byteArray, startIndex); startIndex += sizeof(int); ret.Matrix11 = BitConverter.ToDouble(byteArray, startIndex); startIndex += sizeof(double); ret.Matrix12 = BitConverter.ToDouble(byteArray, startIndex); startIndex += sizeof(double); ret.Matrix13 = BitConverter.ToDouble(byteArray, startIndex); startIndex += sizeof(double); ret.Matrix14 = BitConverter.ToDouble(byteArray, startIndex); startIndex += sizeof(double); ret.Matrix21 = BitConverter.ToDouble(byteArray, startIndex); startIndex += sizeof(double); ret.Matrix22 = BitConverter.ToDouble(byteArray, startIndex); startIndex += sizeof(double); ret.Matrix23 = BitConverter.ToDouble(byteArray, startIndex); startIndex += sizeof(double); ret.Matrix24 = BitConverter.ToDouble(byteArray, startIndex); startIndex += sizeof(double); ret.Matrix31 = BitConverter.ToDouble(byteArray, startIndex); startIndex += sizeof(double); ret.Matrix32 = BitConverter.ToDouble(byteArray, startIndex); startIndex += sizeof(double); ret.Matrix33 = BitConverter.ToDouble(byteArray, startIndex); startIndex += sizeof(double); ret.Matrix34 = BitConverter.ToDouble(byteArray, startIndex); startIndex += sizeof(double); ret.Matrix41 = BitConverter.ToDouble(byteArray, startIndex); startIndex += sizeof(double); ret.Matrix42 = BitConverter.ToDouble(byteArray, startIndex); startIndex += sizeof(double); ret.Matrix43 = BitConverter.ToDouble(byteArray, startIndex); startIndex += sizeof(double); ret.Matrix44 = BitConverter.ToDouble(byteArray, startIndex); startIndex += sizeof(double); ret.FrameNumber = BitConverter.ToInt32(byteArray, startIndex); startIndex += sizeof(long); ret.Error = BitConverter.ToDouble(byteArray, startIndex); startIndex += sizeof(double); return(ret); }
public IncomingAuroraSensorDataEntity(AuroraSensorData auroraSensorData) { this.AuroraSensorData = auroraSensorData; }