Commit 346879e5 by zhangjiec

统计socket连接数量的变量改为原子操作

parent ab1316b4
......@@ -4,9 +4,8 @@ ServerMode = release
ServerPort = :50000
[http_client]
#BaseUrl = http://handandev.swaylink.cn/phone/2/server/
#BaseUrl = http://dev.lezhixy.com/phone/2/server/
BaseUrl = http://127.0.0.1:1234/phone/2/server/
BaseUrl = http://handandev.swaylink.cn/phone/2/server/
#BaseUrl = http://dev.lezhixy.com:5000/phone/2/server/
TimeOut = 5
[tcp_long_server]
......@@ -44,5 +43,5 @@ WarnWithMaxAge = 90
#Error级别日志最多保存多少份
ErrorMaxFileNum = 10
#Error日志最长保留天数
#Error日志最长保留天数s
ErrorWithMaxAge = 180
......@@ -289,11 +289,11 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) {
sTcpData.Data[0] = data.Value
sTcpData.Length = 1
sDevId = data.DevID
case "key_password", "online_dial", "update_firmware", "restart_device": //
case "key_password", "update_firmware", "restart_device": //
var data paraOneString
if err := c.ShouldBindJSON(&data); err != nil {
logger.Log.Error("c.ShouldBindJSON(&data)",
zap.String("Src", "case \"key_password\",\"online_dial\",\"update_firmware\",\"restart_device\""),
zap.String("Src", "case \"key_password\",\"update_firmware\",\"restart_device\""),
zap.Error(err))
sTcpData.CtrlCode = 0
returnState = 2002
......@@ -303,6 +303,23 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) {
sTcpData.Data = []byte(data.Value)
sTcpData.Length = byte(len(data.Value))
sDevId = data.DevID
case "online_dial":
var data structOnlineDial
if err := c.ShouldBindJSON(&data); err != nil {
logger.Log.Error("c.ShouldBindJSON(&data)",
zap.String("Src", "case \"online_dial\""),
zap.Error(err))
sTcpData.CtrlCode = 0
returnState = 2002
returnMsg = "参数内容错误"
break
}
sTcpData.Data[0] = data.Value.Time
sTcpData.Length = uint8(copy(sTcpData.Data[1:], data.Value.Number) + 1)
//sTcpData.Data = []byte(data.Value.Number)
//sTcpData.Length = byte(len(data.Value))
sDevId = data.DevID
break
case "work_time": // 工作时段
var data paraWorkTime
if err := c.ShouldBindJSON(&data); err != nil {
......
......@@ -143,3 +143,13 @@ type paraWorkTime struct {
WeekDay []bool `json:"week_day"`
} `json:"value"`
}
type structOnlineDial struct {
DevTime uint32 `json:"dev_send_time"`
DevID []uint32 `json:"devId"`
Value struct {
Result uint8 `json:"result"`
Time uint8 `json:"time"`
Number string `json:"number"`
} `json:"value"`
}
......@@ -50,6 +50,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("data.Length error",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data))
......@@ -69,6 +70,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("data.Length error",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data))
......@@ -87,6 +89,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("data.Length error",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data))
......@@ -114,6 +117,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("data.Length error",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data))
......@@ -202,6 +206,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("data.Length error",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data))
......@@ -223,6 +228,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("data.Data error",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("data.Data[0]", data.Data[0]),
zap.Uint8s("RecvData", data.Data))
......@@ -233,28 +239,23 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("data.Length error",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data))
}
case 0x30 | 0x80:
type AutoGenerated struct {
DevTime uint32 `json:"dev_send_time"`
DevID []uint32 `json:"devId"`
Value struct {
Result byte `json:"result"`
Number string `json:"number"`
} `json:"value"`
}
jsonStruct := AutoGenerated{
jsonStruct := structOnlineDial{
data.TimeUtc,
[]uint32{data.DevID},
struct {
Result byte `json:"result"`
Result uint8 `json:"result"`
Time uint8 `json:"time"`
Number string `json:"number"`
}{
data.Data[0],
string(data.Data[1:]),
data.Data[1],
string(data.Data[2:]),
},
}
x, _ := json.Marshal(jsonStruct)
......@@ -265,6 +266,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
DevTime: data.TimeUtc,
DevID: []uint32{data.DevID},
}
// todo 第0字节增加模组选择
if data.Data[0]&0x03 == 0x03 {
jsonStruct.Value.ResetReason = 0 // 正常上电
} else if data.Data[0] == 0x40 {
......@@ -296,6 +298,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("json.Unmarshal err OR jStruct.Status != 200",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data),
......@@ -307,6 +310,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("data.Length error",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data))
......@@ -372,6 +376,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("json.Unmarshal err OR jStruct.Status != 200",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data),
......@@ -383,6 +388,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("data.Length error",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data))
......@@ -429,6 +435,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
if json.Unmarshal(result, &jStruct) != nil {
logger.Log.Error("json.Unmarshal err",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data),
......@@ -481,6 +488,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("Status != 0 or 200",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data),
......@@ -492,6 +500,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("data.Length error",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data))
......@@ -523,6 +532,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
if json.Unmarshal(result, &jStruct) != nil {
logger.Log.Error("json.Unmarshal err",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data),
......@@ -588,6 +598,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("Status != 0 or 200",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data),
......@@ -599,6 +610,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("data.Length error",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data))
......@@ -636,6 +648,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("json.Unmarshal err OR jStruct.Status != 200",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data),
......@@ -645,8 +658,10 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
}
}
} else {
data.CtrlCode = ctrlCode | 0x80
logger.Log.Error("data.Length error",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data))
......@@ -686,6 +701,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
if json.Unmarshal(result, &jStruct) != nil {
logger.Log.Error("json.Unmarshal err",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data),
......@@ -723,6 +739,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else if jStruct.Status != 200 {
logger.Log.Error("Status != 0 or 200",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data),
......@@ -734,6 +751,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("data.Length error",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data))
......@@ -777,6 +795,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
} else {
logger.Log.Error("json.Unmarshal err OR jStruct.Status != 200",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data),
......@@ -786,8 +805,10 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
}
}
} else {
data.CtrlCode = ctrlCode | 0x80 //还是回硬件
logger.Log.Error("data.Length error",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data))
......@@ -795,12 +816,14 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
case 0xff: // 硬件被动上报异常
logger.Log.Warn("dev up error 0xff",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data))
default:
logger.Log.Error("ctrlCode error",
zap.String("Src", "TCP-SERVER-response"),
zap.Uint32("DevId", data.DevID),
zap.Uint8("CtrlCode", ctrlCode),
zap.Uint8("DataLen", data.Length),
zap.Uint8s("RecvData", data.Data))
......
......@@ -20,6 +20,7 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.18.1 // indirect
golang.org/dl v0.0.0-20210816190658-eea66df5a73d // indirect
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/text v0.3.6 // indirect
......
......@@ -77,6 +77,8 @@ go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec=
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
go.uber.org/zap v1.18.1 h1:CSUJ2mjFszzEWt4CdKISEuChVIXGBn3lAPwkRGyVrc4=
go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
golang.org/dl v0.0.0-20210816190658-eea66df5a73d h1:fY+sw1TVAhVSrszhxX7Ew04Y6V9Znfa8s5O1HTzTsOQ=
golang.org/dl v0.0.0-20210816190658-eea66df5a73d/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI=
......
......@@ -24,8 +24,11 @@ func TestHex2Cipher(t *testing.T) {
// }
// fmt.Println()
//}
a := []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
str := string(a)
fmt.Println(str)
fmt.Println(len(str))
var b [3]byte
for i := 10002; i <= 11001; i++ {
b[0] = byte(i)
b[1] = byte(i >> 8)
b[2] = byte(i >> 16)
fmt.Printf("3D%02X%02X%02X,", b[0], b[1], b[2])
}
}
package tcplongserver
import (
"fmt"
"go.uber.org/zap"
"jeff_workstation_1/jeffutil"
"jeff_workstation_1/logger"
......@@ -137,7 +136,7 @@ func (s *TCPLongServer) connectionHandle(conn *net.TCPConn, callBack receiveCall
}
_ = conn.SetReadDeadline(time.Time{}) // 设置回去,但是不知道需不需要这句话
_ = conn.Close()
fmt.Println("-----------------------------------Out ConnSocketCount:", s.ConnSocketCount)
// fmt.Println("-----------------------------------Out ConnSocketCount:", s.ConnSocketCount)
}()
//myDevId := -1
//waitTimeOut := 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment