feat: add a new 485 type weather station
This commit is contained in:
parent
43e71e4dd6
commit
d4bd14a91f
36
main.go
36
main.go
@ -121,7 +121,6 @@ func startUDP() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rawData := buffer[:n]
|
rawData := buffer[:n]
|
||||||
data := string(rawData)
|
|
||||||
log.Printf("从 %s 接收到 %d 字节数据", addr.String(), n)
|
log.Printf("从 %s 接收到 %d 字节数据", addr.String(), n)
|
||||||
|
|
||||||
hexDump := hexDump(rawData)
|
hexDump := hexDump(rawData)
|
||||||
@ -129,13 +128,44 @@ func startUDP() {
|
|||||||
asciiDump := asciiDump(rawData)
|
asciiDump := asciiDump(rawData)
|
||||||
log.Printf("ASCII码:\n%s", asciiDump)
|
log.Printf("ASCII码:\n%s", asciiDump)
|
||||||
|
|
||||||
|
// 首先尝试解析为WH65LP数据
|
||||||
|
if len(rawData) == 25 && rawData[0] == 0x24 {
|
||||||
|
wh65lpData, err := model.ParseWH65LPData(rawData)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("解析WH65LP数据失败: %v", err)
|
||||||
|
} else {
|
||||||
|
log.Println("成功解析WH65LP气象站数据:")
|
||||||
|
log.Println(wh65lpData)
|
||||||
|
|
||||||
|
// 更新内存中的设备信息
|
||||||
|
model.UpdateDeviceInMemory(wh65lpData.StationID, addr, model.DeviceTypeWH65LP)
|
||||||
|
// 注册设备到数据库
|
||||||
|
err = model.RegisterDeviceInDB(wh65lpData.StationID, addr)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("注册设备失败: %v", err)
|
||||||
|
}
|
||||||
|
log.Printf("设备 %s 已注册,IP: %s", wh65lpData.StationID, addr.String())
|
||||||
|
|
||||||
|
// 保存数据
|
||||||
|
err = model.SaveWH65LPData(wh65lpData, rawData)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("保存数据到数据库失败: %v", err)
|
||||||
|
} else {
|
||||||
|
log.Printf("数据已成功保存到数据库")
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果不是WH65LP数据,尝试解析为ECOWITT数据
|
||||||
|
data := string(rawData)
|
||||||
weatherData, err := model.ParseWeatherData(data)
|
weatherData, err := model.ParseWeatherData(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("解析数据失败: %v", err)
|
log.Printf("解析ECOWITT数据失败: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("成功解析气象站数据:")
|
log.Println("成功解析ECOWITT气象站数据:")
|
||||||
log.Println(weatherData)
|
log.Println(weatherData)
|
||||||
|
|
||||||
if weatherData.StationID != "" {
|
if weatherData.StationID != "" {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user