今日は一日中雨の予報なので、朝から無線小屋に籠っています。先日から作り始めたWSJT-X/JTDXのUDPメッセージを解読して表示するプログラムのデバッグを兼ねて、6mバンドのEsマルチホップによるDXをワッチしていたところ、TF3ML(アイスランド)が入感してきました。
右側がJTDXのBandActivityウィンドウで左側がコンソールアプリとして製作したプログラムの画面です。何回か呼びましたが、20分ほどでフェードアウトしました。
あぁあ残念・・・Esマルチホップ伝搬もせいぜい今月一杯でしょうから、今期中にDXCCを達成するのは無理そうです。(現在LoTWのみで79コンファームできています。)
以下に、VB.NETで記述してソースコードを掲載します。興味のある方は参考にしてください。(このブログではインデント無しで表示されていますが、Visual Studioにコピペすればちゃんとインデント付きで表示されます。)
Module Module1
Function ConvertToUint32(ByRef rxbuf As Byte(), ByVal index As Integer) As UInt32
Dim bytes4(4) As Byte
Dim bytes4rev(4) As Byte
For i = 0 To 3
bytes4(i) = rxbuf(i + index)
Next
bytes4rev(0) = bytes4(3)
bytes4rev(1) = bytes4(2)
bytes4rev(2) = bytes4(1)
bytes4rev(3) = bytes4(0)
Return BitConverter.ToUInt32(bytes4rev, 0)
End Function
Function ConvertToInt32(ByRef rxbuf As Byte(), ByVal index As Integer) As Int32
Dim bytes4(4) As Byte
Dim bytes4rev(4) As Byte
For i = 0 To 3
bytes4(i) = rxbuf(i + index)
Next
bytes4rev(0) = bytes4(3)
bytes4rev(1) = bytes4(2)
bytes4rev(2) = bytes4(1)
bytes4rev(3) = bytes4(0)
Return BitConverter.ToInt32(bytes4rev, 0)
End Function
Function ConvertToDouble(ByRef rxbuf As Byte(), ByVal index As Integer) As Double
Dim bytes8(8) As Byte
Dim bytes8rev(8) As Byte
For i = 0 To 7
bytes8(i) = rxbuf(i + index)
Next
bytes8rev(0) = bytes8(7)
bytes8rev(1) = bytes8(6)
bytes8rev(2) = bytes8(5)
bytes8rev(3) = bytes8(4)
bytes8rev(4) = bytes8(3)
bytes8rev(5) = bytes8(2)
bytes8rev(6) = bytes8(1)
bytes8rev(7) = bytes8(0)
Return BitConverter.ToDouble(bytes8rev, 0)
End Function
Function ConvertUTF8ToString(ByVal buf As Byte(), ByRef count As Integer) As String
Dim len As Integer = ConvertToUint32(buf, 0)
Dim rStr As String = ""
Dim bArray(len) As Byte
Array.Copy(buf, 4, bArray, 0, len)
count = 4 + len
Return System.Text.Encoding.ASCII.GetString(bArray, 0, len)
End Function
Sub showDecodeMsg(ByRef rxbuf As Byte())
Dim rBytes(rxbuf.Length) As Byte
Dim count As Integer = 0
Array.Copy(rxbuf, 12, rBytes, 0, rxbuf.Length - 12)
Dim id As String = ConvertUTF8ToString(rBytes, count)
Dim index As Integer = 12 + count + 1
Dim Qtime As UInt32 = ConvertToUint32(rxbuf, index) \ 1000
index += 4
Dim hour As Integer = Qtime \ 3600
Dim min As Integer = (Qtime - (hour * 3600)) \ 60
Dim sec As Integer = Qtime Mod 60
Dim SNR As Integer = ConvertToInt32(rxbuf, index)
index += 4
Dim DT As Double = ConvertToDouble(rxbuf, index)
index += 8
Dim DF As UInt32 = ConvertToUint32(rxbuf, index)
index += 4
Array.Copy(rxbuf, index, rBytes, 0, rxbuf.Length - index)
Dim MODE As String = ConvertUTF8ToString(rBytes, count)
index += count
Array.Copy(rxbuf, index, rBytes, 0, rxbuf.Length - index)
Dim MESSAGE As String = ConvertUTF8ToString(rBytes, count)
index += count
Console.WriteLine(hour.ToString + ":" + min.ToString + ":" + sec.ToString _
+ " " + SNR.ToString + " " + DT.ToString("N1") _
+ " " + DF.ToString + " " + MODE + " " + MESSAGE)
End Sub
Sub showLoggedMsg(ByRef rxbuf As Byte())
Dim rBytes(rxbuf.Length) As Byte
Dim count As Integer = 0
Array.Copy(rxbuf, 12, rBytes, 0, rxbuf.Length - 12)
Debug.Print("rBytes=" + BitConverter.ToString(rBytes))
Dim id As String = ConvertUTF8ToString(rBytes, count)
Debug.Print("id:" + id.ToString)
Dim index As Integer = 12 + count + 4
Dim JD As UInt32 = ConvertToUint32(rxbuf, index)
index += 4
Dim Qtime As UInt32 = ConvertToUint32(rxbuf, index) \ 1000
index += 5
Array.Copy(rxbuf, index, rBytes, 0, rxbuf.Length - index)
Dim callsign As String = ConvertUTF8ToString(rBytes, count)
index += count
Array.Copy(rxbuf, index, rBytes, 0, rxbuf.Length - index)
Dim grid As String = ConvertUTF8ToString(rBytes, count)
index += count + 4
Dim Freq As UInt32 = ConvertToUint32(rxbuf, index)
index += 4
Array.Copy(rxbuf, index, rBytes, 0, rxbuf.Length - index)
Dim mode As String = ConvertUTF8ToString(rBytes, count)
index += count
Array.Copy(rxbuf, index, rBytes, 0, rxbuf.Length - index)
Dim sent As String = ConvertUTF8ToString(rBytes, count)
index += count
Array.Copy(rxbuf, index, rBytes, 0, rxbuf.Length - index)
Dim recv As String = ConvertUTF8ToString(rBytes, count)
index += count
Dim hour As Integer = Qtime \ 3600
Dim min As Integer = (Qtime - (hour * 3600)) \ 60
Dim sec As Integer = Qtime Mod 60
Dim JD20000101 As Integer = JD - 2451545
Dim ts20000101 As New TimeSpan(JD20000101, hour, min, sec)
Dim dt20000101 As New DateTime(2000, 1, 1, 0, 0, 0)
Dim dtQSO As DateTime = dt20000101 + ts20000101
Console.WriteLine(dtQSO.ToString + " " + callsign.ToString + " " _
+ grid.ToString + " " + Freq.ToString + " " _
+ mode.ToString + " " + sent.ToString + " " + recv.ToString)
End Sub
Sub analyzeMsg(ByRef rxBuf As Byte())
Dim magic As UInt32 = ConvertToUint32(rxBuf, 0)
If magic <> 2914831322 Then ' 2914831322 = &H adbccbda
Console.WriteLine("wrong packet, magic: " + magic.ToString("X"))
Exit Sub
End If
Dim msgType As UInt32 = ConvertToUint32(rxBuf, 8)
Select Case msgType
'Case 0 'heatbeat
'Case 1 'status
Case 2 'decode
showDecodeMsg(rxBuf)
'Case 3 'clear
'Case 4 'reply
Case 5 'QSO logged
showLoggedMsg(rxBuf)
Case Else
End Select
End Sub
Sub Main()
Dim localIpString As String = "127.0.0.1"
Dim localAddress As System.Net.IPAddress = System.Net.IPAddress.Parse(localIpString)
Dim localPort As Integer = 2237
Dim localEP As New System.Net.IPEndPoint(localAddress, localPort)
Dim udp As New System.Net.Sockets.UdpClient(localEP)
While True
Dim remoteEP As System.Net.IPEndPoint = Nothing
Dim rcvBytes As Byte() = udp.Receive(remoteEP)
analyzeMsg(rcvBytes)
'Console.WriteLine("sender IP:{0} port:{1}", remoteEP.Address, remoteEP.Port)
End While
End Sub
End Module
Function ConvertToUint32(ByRef rxbuf As Byte(), ByVal index As Integer) As UInt32
Dim bytes4(4) As Byte
Dim bytes4rev(4) As Byte
For i = 0 To 3
bytes4(i) = rxbuf(i + index)
Next
bytes4rev(0) = bytes4(3)
bytes4rev(1) = bytes4(2)
bytes4rev(2) = bytes4(1)
bytes4rev(3) = bytes4(0)
Return BitConverter.ToUInt32(bytes4rev, 0)
End Function
Function ConvertToInt32(ByRef rxbuf As Byte(), ByVal index As Integer) As Int32
Dim bytes4(4) As Byte
Dim bytes4rev(4) As Byte
For i = 0 To 3
bytes4(i) = rxbuf(i + index)
Next
bytes4rev(0) = bytes4(3)
bytes4rev(1) = bytes4(2)
bytes4rev(2) = bytes4(1)
bytes4rev(3) = bytes4(0)
Return BitConverter.ToInt32(bytes4rev, 0)
End Function
Function ConvertToDouble(ByRef rxbuf As Byte(), ByVal index As Integer) As Double
Dim bytes8(8) As Byte
Dim bytes8rev(8) As Byte
For i = 0 To 7
bytes8(i) = rxbuf(i + index)
Next
bytes8rev(0) = bytes8(7)
bytes8rev(1) = bytes8(6)
bytes8rev(2) = bytes8(5)
bytes8rev(3) = bytes8(4)
bytes8rev(4) = bytes8(3)
bytes8rev(5) = bytes8(2)
bytes8rev(6) = bytes8(1)
bytes8rev(7) = bytes8(0)
Return BitConverter.ToDouble(bytes8rev, 0)
End Function
Function ConvertUTF8ToString(ByVal buf As Byte(), ByRef count As Integer) As String
Dim len As Integer = ConvertToUint32(buf, 0)
Dim rStr As String = ""
Dim bArray(len) As Byte
Array.Copy(buf, 4, bArray, 0, len)
count = 4 + len
Return System.Text.Encoding.ASCII.GetString(bArray, 0, len)
End Function
Sub showDecodeMsg(ByRef rxbuf As Byte())
Dim rBytes(rxbuf.Length) As Byte
Dim count As Integer = 0
Array.Copy(rxbuf, 12, rBytes, 0, rxbuf.Length - 12)
Dim id As String = ConvertUTF8ToString(rBytes, count)
Dim index As Integer = 12 + count + 1
Dim Qtime As UInt32 = ConvertToUint32(rxbuf, index) \ 1000
index += 4
Dim hour As Integer = Qtime \ 3600
Dim min As Integer = (Qtime - (hour * 3600)) \ 60
Dim sec As Integer = Qtime Mod 60
Dim SNR As Integer = ConvertToInt32(rxbuf, index)
index += 4
Dim DT As Double = ConvertToDouble(rxbuf, index)
index += 8
Dim DF As UInt32 = ConvertToUint32(rxbuf, index)
index += 4
Array.Copy(rxbuf, index, rBytes, 0, rxbuf.Length - index)
Dim MODE As String = ConvertUTF8ToString(rBytes, count)
index += count
Array.Copy(rxbuf, index, rBytes, 0, rxbuf.Length - index)
Dim MESSAGE As String = ConvertUTF8ToString(rBytes, count)
index += count
Console.WriteLine(hour.ToString + ":" + min.ToString + ":" + sec.ToString _
+ " " + SNR.ToString + " " + DT.ToString("N1") _
+ " " + DF.ToString + " " + MODE + " " + MESSAGE)
End Sub
Sub showLoggedMsg(ByRef rxbuf As Byte())
Dim rBytes(rxbuf.Length) As Byte
Dim count As Integer = 0
Array.Copy(rxbuf, 12, rBytes, 0, rxbuf.Length - 12)
Debug.Print("rBytes=" + BitConverter.ToString(rBytes))
Dim id As String = ConvertUTF8ToString(rBytes, count)
Debug.Print("id:" + id.ToString)
Dim index As Integer = 12 + count + 4
Dim JD As UInt32 = ConvertToUint32(rxbuf, index)
index += 4
Dim Qtime As UInt32 = ConvertToUint32(rxbuf, index) \ 1000
index += 5
Array.Copy(rxbuf, index, rBytes, 0, rxbuf.Length - index)
Dim callsign As String = ConvertUTF8ToString(rBytes, count)
index += count
Array.Copy(rxbuf, index, rBytes, 0, rxbuf.Length - index)
Dim grid As String = ConvertUTF8ToString(rBytes, count)
index += count + 4
Dim Freq As UInt32 = ConvertToUint32(rxbuf, index)
index += 4
Array.Copy(rxbuf, index, rBytes, 0, rxbuf.Length - index)
Dim mode As String = ConvertUTF8ToString(rBytes, count)
index += count
Array.Copy(rxbuf, index, rBytes, 0, rxbuf.Length - index)
Dim sent As String = ConvertUTF8ToString(rBytes, count)
index += count
Array.Copy(rxbuf, index, rBytes, 0, rxbuf.Length - index)
Dim recv As String = ConvertUTF8ToString(rBytes, count)
index += count
Dim hour As Integer = Qtime \ 3600
Dim min As Integer = (Qtime - (hour * 3600)) \ 60
Dim sec As Integer = Qtime Mod 60
Dim JD20000101 As Integer = JD - 2451545
Dim ts20000101 As New TimeSpan(JD20000101, hour, min, sec)
Dim dt20000101 As New DateTime(2000, 1, 1, 0, 0, 0)
Dim dtQSO As DateTime = dt20000101 + ts20000101
Console.WriteLine(dtQSO.ToString + " " + callsign.ToString + " " _
+ grid.ToString + " " + Freq.ToString + " " _
+ mode.ToString + " " + sent.ToString + " " + recv.ToString)
End Sub
Sub analyzeMsg(ByRef rxBuf As Byte())
Dim magic As UInt32 = ConvertToUint32(rxBuf, 0)
If magic <> 2914831322 Then ' 2914831322 = &H adbccbda
Console.WriteLine("wrong packet, magic: " + magic.ToString("X"))
Exit Sub
End If
Dim msgType As UInt32 = ConvertToUint32(rxBuf, 8)
Select Case msgType
'Case 0 'heatbeat
'Case 1 'status
Case 2 'decode
showDecodeMsg(rxBuf)
'Case 3 'clear
'Case 4 'reply
Case 5 'QSO logged
showLoggedMsg(rxBuf)
Case Else
End Select
End Sub
Sub Main()
Dim localIpString As String = "127.0.0.1"
Dim localAddress As System.Net.IPAddress = System.Net.IPAddress.Parse(localIpString)
Dim localPort As Integer = 2237
Dim localEP As New System.Net.IPEndPoint(localAddress, localPort)
Dim udp As New System.Net.Sockets.UdpClient(localEP)
While True
Dim remoteEP As System.Net.IPEndPoint = Nothing
Dim rcvBytes As Byte() = udp.Receive(remoteEP)
analyzeMsg(rcvBytes)
'Console.WriteLine("sender IP:{0} port:{1}", remoteEP.Address, remoteEP.Port)
End While
End Sub
End Module
※コメント投稿者のブログIDはブログ作成者のみに通知されます