Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

Commit 44a1adf

Browse files
committed
增加重连机制,标准化输出
1 parent e68676e commit 44a1adf

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/DexterCai/Feeyo_adsb/adsb.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"bytes"
66
"compress/zlib"
77
"encoding/base64"
8-
"fmt"
98
"io"
109
"io/ioutil"
1110
"net"
@@ -16,6 +15,7 @@ import (
1615
)
1716
var UUID, IpDump1090, PortDump1090,FeeyoUrl string
1817
func main() {
18+
println("敬告:请不要尝试将相关电波数据传送至FR24,RadarBox,FA等境外平台,这将严重违反无线电管理条例以及国家安全法!")
1919
var err error
2020
UUID, err = config.Config.GetValue("config", "UUID")
2121
IpDump1090, err = config.Config.GetValue("config", "ip")
@@ -27,19 +27,28 @@ func main() {
2727
}
2828
dump1090Conn, err := net.Dial("tcp", IpDump1090 + ":" + PortDump1090)
2929
if err != nil {
30-
fmt.Println("连接到Dump1090失败", err.Error())
30+
println(time.Now().Format("2006-01-02 15:04:05"), "\t连接到Dump1090失败\t", err.Error())
3131
return
32+
}else{
33+
println(time.Now().Format("2006-01-02 15:04:05"), "\t连接成功\t")
3234
}
3335
var buf [1024]byte
3436
for {
3537
read, err := dump1090Conn.Read(buf[0:])
3638
if err != nil {
37-
println("读取错误", err.Error())
39+
println(time.Now().Format("2006-01-02 15:04:05"), "\t读取错误\t", err.Error())
3840
_ = dump1090Conn.Close()
39-
return
41+
println(time.Now().Format("2006-01-02 15:04:05"), "\t断开链接\t")
42+
dump1090Conn, err = net.Dial("tcp", IpDump1090 + ":" + PortDump1090)
43+
println(time.Now().Format("2006-01-02 15:04:05"), "\t尝试重连\t")
44+
if err!=nil{
45+
println(time.Now().Format("2006-01-02 15:04:05"), "\t重连成功\t")
46+
}
47+
}else{
48+
if buf[read-1] == 10 {
49+
sendMessage(buf[0:read])
50+
}
4051
}
41-
sendMessage(buf[0:read])
42-
4352
}
4453
}
4554

@@ -52,9 +61,9 @@ func sendMessage(line []byte){
5261
defer resp.Body.Close()
5362
body, _ := ioutil.ReadAll(resp.Body)
5463
if err != nil{
55-
println(time.Now().String(), "上传错误", err.Error())
64+
println(time.Now().Format("2006-01-02 15:04:05"), "\t上传错误\t", err.Error())
5665
}else{
57-
println(time.Now().String(), "上传成功", string(body))
66+
print("\r",time.Now().Format("2006-01-02 15:04:05"), "\t上传成功\t", string(body))
5867
}
5968
}
6069

0 commit comments

Comments
 (0)