-
Notifications
You must be signed in to change notification settings - Fork 6
/
Program.cs
158 lines (146 loc) · 6.46 KB
/
Program.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
148
149
150
151
152
153
154
155
156
157
158
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
namespace ReadWave
{
class Program
{
static void Main(string[] args)
{
if(args != null && args.Length > 0 && args[0] == "test6")
{
AFSK1200ModemTest.Test6();
Console.WriteLine("Press Enter to Exit");
Console.ReadLine();
return;
};
if (args != null && args.Length > 0 && args[0] == "test4")
{
AFSK1200ModemTest.Test4();
Console.WriteLine("Press Enter to Exit");
Console.ReadLine();
return;
};
if (args != null && args.Length > 0 && args[0] == "test3")
{
AFSK1200ModemTest.Test3();
Console.WriteLine("Press Enter to Exit");
Console.ReadLine();
return;
};
if (args != null && args.Length > 0 && args[0] == "test2")
{
AFSK1200ModemTest.Test2();
Console.WriteLine("Press Enter to Exit");
Console.ReadLine();
return;
};
if (args != null && args.Length > 0 && args[0] == "test1")
{
AFSK1200ModemTest.Test1();
Console.WriteLine("Press Enter to Exit");
Console.ReadLine();
return;
};
AFSK1200ModemTest.Test5(args == null || args.Length == 0 ? -1 : int.Parse(args[0]));
return;
// another tests: connect to remote servers //
bool test = false;
bool aprsis = true;
bool afwe = false;
bool sound = true;
if (test)
{
AFSK1200ModemTest.Test1();
AFSK1200ModemTest.Test2();
AFSK1200ModemTest.Test3();
AFSK1200ModemTest.Test4();
//AFSK1200ModemTest.Test5(-1);
AFSK1200ModemTest.Test6();
};
TcpClient tcpc = null;
if (aprsis)
{
tcpc = new TcpClient();
tcpc.Connect("127.0.0.1", 12015);
string auth = "user AFSKX25 pass -1 vers ASFKModem 0.1\r\n";
tcpc.Client.Send(System.Text.Encoding.ASCII.GetBytes(auth));
};
AgwpePort.AgwpePort agwe = null;
if (afwe)
{
agwe = new AgwpePort.AgwpePort();
agwe.Open((byte)0, "127.0.0.1", 8000);
agwe.SendUnproto((byte)0, "TESTER", "APRS", System.Text.Encoding.GetEncoding(1251).GetBytes("=5533.00N\03733.00Ek Testing"));
agwe.StartMonitoring();
agwe.FrameReceived += new AgwpePort.AgwpePort.AgwpeFrameReceivedEventHandler(agwe_client_FrameReceived);
};
ax25.AFSK1200Modulator mod = null;
if (sound)
{
mod = new ax25.AFSK1200Modulator(44100);
mod.txDelayMs = 750;
};
while ((tcpc != null) && tcpc.Client.Connected)
{
string rxText = "";
byte[] rxBuffer = new byte[4096];
int rxCount = 0;
int rxAvailable = tcpc.Client.Available;
while (rxAvailable > 0)
{
try { rxAvailable -= (rxCount = tcpc.Client.Receive(rxBuffer, 0, rxBuffer.Length > rxAvailable ? rxAvailable : rxBuffer.Length, SocketFlags.None)); }
catch { break; };
if (rxCount > 0) rxText += Encoding.ASCII.GetString(rxBuffer, 0, rxCount);
};
if (rxText != "")
{
string[] lines = rxText.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
List<ax25.Packet> packets = new List<ax25.Packet>();
foreach (string line in lines)
{
Console.WriteLine("{0}/{1}>> {2}","T",DateTime.UtcNow.ToString("HHmmss"),line);
if (line.IndexOf("#") != 0)
{
string from = line.Substring(0, line.IndexOf(">"));
string pckt = line.Substring(line.IndexOf(":") + 1);
if(agwe != null)
agwe.SendUnproto((byte)0, from, "APRS", System.Text.Encoding.ASCII.GetBytes(pckt));
if (sound)
{
packets.Add(new ax25.Packet(
"APRS", from, new String[] { "WIDE1-1", "WIDE2-2" },
ax25.Packet.AX25_CONTROL_APRS, ax25.Packet.AX25_PROTOCOL_NO_LAYER_3,
System.Text.Encoding.ASCII.GetBytes(pckt)
));
};
};
};
if (packets.Count > 0)
{
float[] samples;
mod.GetSamples(packets.ToArray(), out samples);
WaveStream.PlaySamples(44100, samples, false);
};
packets.Clear();
};
System.Threading.Thread.Sleep(10);
};
Console.ReadLine();
if(tcpc != null) tcpc.Close();
if(agwe != null) agwe.Close();
}
static void agwe_client_FrameReceived(object sender, AgwpePort.AgwpeEventArgs e)
{
// AGWPE Config and Information Frames
// Read AX25 Unproto (UI) frames and data sent from a remote packet radio station
if (e.FrameHeader.DataKind == ((byte)'U'))
{
AgwpePort.AgwpeMoniUnproto md = (AgwpePort.AgwpeMoniUnproto)e.FrameData;
string cmd = md.AX25CallFrom + "WE>>" + md.AX25CallTo.Replace(" Via ", ",").Replace(" ", "") + ":" + System.Text.Encoding.GetEncoding(1251).GetString(md.AX25Data);
Console.WriteLine("{0}{1} {2}", "A", DateTime.UtcNow.ToString("HHmmss"), cmd);
};
}
}
}