Skip to content

Commit

Permalink
[fix]Repair the temperature acquisition module
Browse files Browse the repository at this point in the history
  • Loading branch information
thun888 authored Jul 26, 2024
1 parent 8937686 commit 8f5eb71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func main() {
if err != nil {
return c.JSON(http.StatusOK, map[string]interface{}{"code": 1100, "msg": "参数错误"})
}
status, cpu_tp, fanspeed, w24g_tp, w5g_tp := tp.GetTemperature(c, routernum, hardwares[routernum])
status, cpu_tp, fanspeed, w24g_tp, w5g_tp := tp.GetTemperature(c, routernum, hardwares[routernum], dev)
if status {
return c.JSON(http.StatusOK, map[string]interface{}{
"code": 0,
Expand Down
15 changes: 10 additions & 5 deletions modules/tp/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"main/modules/config"
"os/exec"
"strconv"
"strings"

"github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
Expand All @@ -18,9 +20,9 @@ var (
)

// 获取温度
func GetTemperature(c echo.Context, routernum int, hardware string) (bool, string, string, string, string) {
func GetTemperature(c echo.Context, routernum int, hardware string, dev []config.Dev) (bool, int, int, int, int) {
if !dev[routernum].RouterUnit {
return false, "-233", "-233", "-233", "-233"
return false, -233, -233, -233, -233
}
var cpu_out, w24g_out, w5g_out []byte
var err1, err2, err3 error
Expand Down Expand Up @@ -64,12 +66,15 @@ func GetTemperature(c echo.Context, routernum int, hardware string) (bool, strin
w24g_tp = "-233"
w5g_tp = "-233"
default:
return false, "-233", "-233", "-233", "-233"
return false, -233, -233, -233, -233
}

if err1 != nil || err2 != nil || err3 != nil {
logrus.Error("获取温度失败,报错信息为" + err1.Error() + err2.Error() + err3.Error())
}

return true, cpu_tp, fanspeed, w24g_tp, w5g_tp
cpu_tp_int, _ := strconv.Atoi(strings.ReplaceAll(cpu_tp, "\n", ""))
fanspeed_int, _ := strconv.Atoi(strings.ReplaceAll(fanspeed, "\n", ""))
w24g_tp_int, _ := strconv.Atoi(strings.ReplaceAll(w24g_tp, "\n", ""))
w5g_tp_int, _ := strconv.Atoi(strings.ReplaceAll(w5g_tp, "\n", ""))
return true, cpu_tp_int, fanspeed_int, w24g_tp_int, w5g_tp_int
}

0 comments on commit 8f5eb71

Please sign in to comment.