-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkyChart.cs
147 lines (115 loc) · 4.26 KB
/
SkyChart.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace EAACtrl
{
internal class SkyChart
{
private string sMsg = "";
public string Message
{
get
{
return sMsg;
}
}
public string IPAddress = "127.0.0.1";
public string Port = "3292";
private string TCPMessage(String server, Int32 port, String message)
{
// String to store the response ASCII representation.
String responseData = String.Empty;
try
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
TcpClient client = new TcpClient(server, port);
// Get a client stream for reading and writing.
NetworkStream stream = client.GetStream();
// Translate the passed message into ASCII and store it as a Byte array.
//Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);
Byte[] data = System.Text.Encoding.UTF8.GetBytes(message);
// Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length);
// Receive the server response.
// Buffer to store the response bytes.
data = new Byte[1024];
// Read the first batch of the TcpServer response bytes.
Int32 bytes = stream.Read(data, 0, data.Length);
//responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
responseData = System.Text.Encoding.UTF8.GetString(data, 0, bytes);
stream.Close();
client.Close();
TimeSpan ts = stopwatch.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}.{2:00}",
ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
sMsg = "TCP Message (" + elapsedTime + ")\r\n";
}
catch (Exception e)
{
sMsg = "TCP Exception: " + e.Message + "\r\n";
}
return responseData;
}
public void SkychartRedraw()
{
string sAddr = IPAddress;
int iPort = Int32.Parse(Port);
TCPMessage(sAddr, iPort, "REDRAW\r\n");
}
public void SkychartFOV(double FOV, bool Redraw = true)
{
string sAddr = IPAddress;
int iPort = Int32.Parse(Port);
string sFOVCmd = "SETFOV " + FOV.ToString() + "\r\n";
TCPMessage(sAddr, iPort, sFOVCmd);
if (Redraw)
{
SkychartRedraw();
}
}
public void SkychartViewDirection(string Direction, bool ReDraw = true)
{
string sAddr = IPAddress;
int iPort = Int32.Parse(Port);
string sCmd = Direction + "\r\n";
TCPMessage(sAddr, iPort, sCmd);
if (ReDraw)
{
SkychartRedraw();
}
}
public void SkychartTargetPosition(string id, string RA, string Dec, double FOV)
{
try
{
string sSearchCmd = "SEARCH \"" + id + "\" LOCK\r\n";
string sResult = "";
string sAddr = IPAddress;
int iPort = Int32.Parse(Port);
sResult = TCPMessage(sAddr, iPort, sSearchCmd);
if (sResult.Contains("Not found!"))
{
string sRADec = "SETRA " + RA + "\r\n";
sResult = TCPMessage(sAddr, iPort, sRADec);
sRADec = "SETDEC " + Dec + "\r\n";
sResult = TCPMessage(sAddr, iPort, sRADec);
}
if (FOV > 0)
{
SkychartFOV(FOV, false);
}
SkychartRedraw();
sMsg = "CdC Target Id=" + id + " RA:" + RA.ToString() + " Dec:" + Dec.ToString() + " FOV:" + FOV.ToString() + "\r\n";
}
catch (Exception)
{
sMsg = "CdC Target fail!\r\n";
}
}
}
}