新增一些新的格式
This commit is contained in:
parent
4271f555bc
commit
0aafb68fcd
@ -211,6 +211,37 @@ func parseData(data string) (int, float64, float64, float64, float64, error) {
|
||||
return sensorID, x, y, z, temperature, nil
|
||||
}
|
||||
|
||||
// 尝试解析无包装符号的格式: 1602301014-01,1,1,31.1,-6.781,1.542
|
||||
plainPattern := regexp.MustCompile(`([^,]+)-(\d+),\d+,(\d+),([-]?\d+\.\d+),([-]?\d+\.\d+),([-]?\d+\.\d+)`)
|
||||
matches = plainPattern.FindStringSubmatch(data)
|
||||
|
||||
if len(matches) == 7 {
|
||||
// 无包装符号格式解析
|
||||
sensorID, err := strconv.Atoi(matches[3]) // 使用传感器地址编号
|
||||
if err != nil {
|
||||
return 0, 0, 0, 0, 0, fmt.Errorf("解析传感器ID失败: %v", err)
|
||||
}
|
||||
|
||||
temperature, err := strconv.ParseFloat(strings.TrimSpace(matches[4]), 64)
|
||||
if err != nil {
|
||||
return 0, 0, 0, 0, 0, fmt.Errorf("解析温度值失败: %v", err)
|
||||
}
|
||||
|
||||
x, err := strconv.ParseFloat(strings.TrimSpace(matches[5]), 64)
|
||||
if err != nil {
|
||||
return 0, 0, 0, 0, 0, fmt.Errorf("解析X值失败: %v", err)
|
||||
}
|
||||
|
||||
y, err := strconv.ParseFloat(strings.TrimSpace(matches[6]), 64)
|
||||
if err != nil {
|
||||
return 0, 0, 0, 0, 0, fmt.Errorf("解析Y值失败: %v", err)
|
||||
}
|
||||
|
||||
z := 0.0 // 这种格式没有Z值,设为0
|
||||
|
||||
return sensorID, x, y, z, temperature, nil
|
||||
}
|
||||
|
||||
// 尝试解析旧格式: 1:1.000, 2.000, 3.000
|
||||
oldPattern := regexp.MustCompile(`(\d+):([-]?\d+\.\d+),\s*([-]?\d+\.\d+),\s*([-]?\d+\.\d+)`)
|
||||
matches = oldPattern.FindStringSubmatch(data)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user