Commit 5f865c50 by zhangjiec

增加业务服务器发来的内容错误返回

parent b5e7234d
File deleted
...@@ -38,6 +38,11 @@ func (dev *DCPhone10) getOnlineList(c *gin.Context) { ...@@ -38,6 +38,11 @@ func (dev *DCPhone10) getOnlineList(c *gin.Context) {
logger.Log.Error("c.ShouldBindJSON(&dataIn)", logger.Log.Error("c.ShouldBindJSON(&dataIn)",
zap.String("Src", "getOnlineList"), zap.String("Src", "getOnlineList"),
zap.Error(err)) zap.Error(err))
c.JSON(http.StatusOK, gin.H{
"status": 2002,
"message": "参数内容错误",
})
return
} }
type DataO struct { type DataO struct {
...@@ -119,6 +124,11 @@ func (dev *DCPhone10) putOnlineClose(c *gin.Context) { ...@@ -119,6 +124,11 @@ func (dev *DCPhone10) putOnlineClose(c *gin.Context) {
logger.Log.Error("c.ShouldBindJSON(&data)", logger.Log.Error("c.ShouldBindJSON(&data)",
zap.String("Src", "putOnlineClose"), zap.String("Src", "putOnlineClose"),
zap.Error(err)) zap.Error(err))
c.JSON(http.StatusOK, gin.H{
"status": 2002,
"message": "参数内容错误",
})
return
} }
type DataO struct { type DataO struct {
...@@ -160,6 +170,11 @@ func (dev *DCPhone10) getDevPara(c *gin.Context) { ...@@ -160,6 +170,11 @@ func (dev *DCPhone10) getDevPara(c *gin.Context) {
logger.Log.Error("c.ShouldBindJSON(&data)", logger.Log.Error("c.ShouldBindJSON(&data)",
zap.String("Src", "getDevPara"), zap.String("Src", "getDevPara"),
zap.Error(err)) zap.Error(err))
c.JSON(http.StatusOK, gin.H{
"status": 2002,
"message": "参数内容错误",
})
return
} }
type DataO struct { type DataO struct {
...@@ -180,6 +195,7 @@ func (dev *DCPhone10) getDevPara(c *gin.Context) { ...@@ -180,6 +195,7 @@ func (dev *DCPhone10) getDevPara(c *gin.Context) {
sData.DevID = id sData.DevID = id
if dev.TCPSend(&sData) == true { if dev.TCPSend(&sData) == true {
dataOut.DevID[id] = true dataOut.DevID[id] = true
dataOut.Count++
} else { } else {
dataOut.DevID[id] = false dataOut.DevID[id] = false
} }
...@@ -221,6 +237,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) { ...@@ -221,6 +237,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) {
logger.Log.Error("c.ShouldBindJSON(&data)", logger.Log.Error("c.ShouldBindJSON(&data)",
zap.String("Src", "case \"tcp_server_addr\""), zap.String("Src", "case \"tcp_server_addr\""),
zap.Error(err)) zap.Error(err))
sTcpData.CtrlCode = 0
returnState = 2002
returnMsg = "参数内容错误"
break
} }
sTcpData.Data = []byte("\"" + data.Value.IP + "\"," + strconv.Itoa(int(data.Value.Port))) sTcpData.Data = []byte("\"" + data.Value.IP + "\"," + strconv.Itoa(int(data.Value.Port)))
sTcpData.Length = byte(len(sTcpData.Data)) sTcpData.Length = byte(len(sTcpData.Data))
...@@ -231,6 +251,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) { ...@@ -231,6 +251,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) {
logger.Log.Error("c.ShouldBindJSON(&data)", logger.Log.Error("c.ShouldBindJSON(&data)",
zap.String("Src", "case \"select_sim_module\""), zap.String("Src", "case \"select_sim_module\""),
zap.Error(err)) zap.Error(err))
sTcpData.CtrlCode = 0
returnState = 2002
returnMsg = "参数内容错误"
break
} }
sTcpData.Data[0] = data.Value.Net<<1 | data.Value.Call sTcpData.Data[0] = data.Value.Net<<1 | data.Value.Call
sTcpData.Length = 1 sTcpData.Length = 1
...@@ -241,6 +265,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) { ...@@ -241,6 +265,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) {
logger.Log.Error("c.ShouldBindJSON(&data)", logger.Log.Error("c.ShouldBindJSON(&data)",
zap.String("Src", "case \"heart\""), zap.String("Src", "case \"heart\""),
zap.Error(err)) zap.Error(err))
sTcpData.CtrlCode = 0
returnState = 2002
returnMsg = "参数内容错误"
break
} }
sTcpData.Data[0] = byte(data.Value.Time) sTcpData.Data[0] = byte(data.Value.Time)
sTcpData.Data[1] = byte(data.Value.Time >> 8) sTcpData.Data[1] = byte(data.Value.Time >> 8)
...@@ -253,6 +281,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) { ...@@ -253,6 +281,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) {
logger.Log.Error("c.ShouldBindJSON(&data)", logger.Log.Error("c.ShouldBindJSON(&data)",
zap.String("Src", "case \"beep_volume\",\"speech_volume\",\"speech_speed\""), zap.String("Src", "case \"beep_volume\",\"speech_volume\",\"speech_speed\""),
zap.Error(err)) zap.Error(err))
sTcpData.CtrlCode = 0
returnState = 2002
returnMsg = "参数内容错误"
break
} }
sTcpData.Data[0] = data.Value sTcpData.Data[0] = data.Value
sTcpData.Length = 1 sTcpData.Length = 1
...@@ -263,6 +295,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) { ...@@ -263,6 +295,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) {
logger.Log.Error("c.ShouldBindJSON(&data)", logger.Log.Error("c.ShouldBindJSON(&data)",
zap.String("Src", "case \"key_password\",\"online_dial\",\"update_firmware\",\"restart_device\""), zap.String("Src", "case \"key_password\",\"online_dial\",\"update_firmware\",\"restart_device\""),
zap.Error(err)) zap.Error(err))
sTcpData.CtrlCode = 0
returnState = 2002
returnMsg = "参数内容错误"
break
} }
sTcpData.Data = []byte(data.Value) sTcpData.Data = []byte(data.Value)
sTcpData.Length = byte(len(data.Value)) sTcpData.Length = byte(len(data.Value))
...@@ -273,6 +309,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) { ...@@ -273,6 +309,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) {
logger.Log.Error("c.ShouldBindJSON(&data)", logger.Log.Error("c.ShouldBindJSON(&data)",
zap.String("Src", "case \"work_time\""), zap.String("Src", "case \"work_time\""),
zap.Error(err)) zap.Error(err))
sTcpData.CtrlCode = 0
returnState = 2002
returnMsg = "参数内容错误"
break
} }
i := 0 i := 0
for ; i < len(data.Value); i++ { for ; i < len(data.Value); i++ {
...@@ -319,6 +359,7 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) { ...@@ -319,6 +359,7 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) {
sTcpData.DevID = id sTcpData.DevID = id
if dev.TCPSend(&sTcpData) == true { if dev.TCPSend(&sTcpData) == true {
dataOut.DevID[id] = true dataOut.DevID[id] = true
dataOut.Count++
} else { } else {
dataOut.DevID[id] = false dataOut.DevID[id] = false
} }
......
...@@ -737,7 +737,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) { ...@@ -737,7 +737,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
DevSendTime uint32 `json:"dev_send_time"` DevSendTime uint32 `json:"dev_send_time"`
DevID []uint32 `json:"devId"` DevID []uint32 `json:"devId"`
Value struct { Value struct {
CardUID uint32 `json:"message_id"` CardUID uint32 `json:"card_uid"`
StartTime uint32 `json:"start_time"` StartTime uint32 `json:"start_time"`
TalkTime uint16 `json:"talk_time"` TalkTime uint16 `json:"talk_time"`
Number string `json:"number"` Number string `json:"number"`
...@@ -747,7 +747,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) { ...@@ -747,7 +747,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
data.TimeUtc, data.TimeUtc,
[]uint32{data.DevID}, []uint32{data.DevID},
struct { struct {
CardUID uint32 `json:"message_id"` CardUID uint32 `json:"card_uid"`
StartTime uint32 `json:"start_time"` StartTime uint32 `json:"start_time"`
TalkTime uint16 `json:"talk_time"` TalkTime uint16 `json:"talk_time"`
Number string `json:"number"` Number string `json:"number"`
......
...@@ -8,72 +8,24 @@ import ( ...@@ -8,72 +8,24 @@ import (
//测试用例文件使用 go test 指令来执行,没有也不需要 main() 作为函数入口 //测试用例文件使用 go test 指令来执行,没有也不需要 main() 作为函数入口
//所有在以_test结尾的源码内以Test开头的函数会自动被执行。 //所有在以_test结尾的源码内以Test开头的函数会自动被执行。
func TestHex2Cipher(t *testing.T) { func TestHex2Cipher(t *testing.T) {
a := "abcABC哈哈哈就glad就是理工科,的垃圾疯狂的建安费、放大算法。dfafajdf!!" //test := []byte{0x22, 0x64, 0x65, 0x76, 0x2E, 0x6C, 0x65, 0x7A, 0x68, 0x69, 0x78, 0x79, 0x2E, 0x63, 0x6F, 0x6D, 0x22, 0x2C, 0x34, 0x39, 0x39, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
fmt.Println(a) // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
fmt.Println(DBCtoSBC(a)) // 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x0A, 0x64, 0x31, 0x31, 0x30, 0x2F, 0x31, 0x32, 0x30, 0x2F, 0x31, 0x31, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x37, 0x09, 0x09, 0x7F, 0x00, 0x00,
//password := "DCRYM-2018-pswd." // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//iv := "I can't tell YOU" // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//type HexData struct { // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// TimeUtc uint32 // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x06, 0x02, 0x38, 0x35, 0x34, 0x30, 0x35, 0x35, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x53, 0x57, 0x41, 0x59, 0x32, 0x31,0,0}
// DevType uint8 //GetCRC(test, 254)
// DevID uint32 //for j:=0;j< len(test);{
// CtrlCode uint8 // for i:=0;i<16;i++{
// Length uint8 // fmt.Printf("%02X",test[j])
// Data []byte // j++
// }
// fmt.Println()
//} //}
//sData := HexData{ a := []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
// 1626766761, str := string(a)
// 0x3E, fmt.Println(str)
// 0x000001, fmt.Println(len(str))
// 0x41,
// 201,//15,
// []byte{
// 0, //通讯延迟
// 0x00, //状态码
// 0x01,0x00, //左电流
// 0x02,0x00, //右电流
// 0x03,0x00, //左电阻
// 0x04,0x00, //右电阻
// 0x05, //左温度
// 0x06, //右温度
// 0x07, //VCC_H
// 0x08, //VCC_L
// 0, //正在使用的用户数
// },
//}
//sData.Length = 243 // 255 267 362 // 243 255 346
//fmt.Println("sData.Length:",sData.Length)
//hexBuf := make([]byte, int(sData.Length) + 12)
//hexBuf[0] = byte(sData.TimeUtc >> 24)
//hexBuf[1] = byte(sData.TimeUtc >> 16)
//hexBuf[2] = byte(sData.TimeUtc >> 8)
//hexBuf[3] = byte(sData.TimeUtc)
//hexBuf[4] = sData.DevType
//hexBuf[5] = byte(sData.DevID >> 16)
//hexBuf[6] = byte(sData.DevID >> 8)
//hexBuf[7] = byte(sData.DevID)
//hexBuf[8] = sData.CtrlCode
//hexBuf[9] = sData.Length
//sData.Data = make([]byte,sData.Length)
////if sData.Length>0 {
//copy(hexBuf[10:],sData.Data[:sData.Length])
////}
//fmt.Println("len(hexBuf)",len(hexBuf))
//GetCRC(hexBuf,int(sData.Length)+10)
//sendStr := EncryptBytesToBase64(hexBuf,password,iv)
//
//sendStr[0] = '{'
//sendStr[len(sendStr) - 1] = '}'
//
//fmt.Printf("string(sendStr):%s\nlen:%d\n",string(sendStr),len(sendStr))
} }
//func main() {
// a := "4769676162697445746865726E6574302F302F323400"
// bs, err := hex.DecodeString(a)
// if err != nil {
// panic(err)
// }
// fmt.Println(string(bs))
//}
...@@ -34,7 +34,7 @@ var ( ...@@ -34,7 +34,7 @@ var (
LogErrorMaxFileDay int LogErrorMaxFileDay int
) )
func init() { func ConfigInit() {
file, err := ini.Load("./config.ini") file, err := ini.Load("./config.ini")
if err != nil { if err != nil {
// logger.Log.Panic("配置文件读取错误") // logger.Log.Panic("配置文件读取错误")
......
...@@ -10,55 +10,58 @@ import ( ...@@ -10,55 +10,58 @@ import (
) )
//windows //windows
var ( //var (
kernel32 = syscall.MustLoadDLL("kernel32.dll") // kernel32 = syscall.MustLoadDLL("kernel32.dll")
procSetStdHandle = kernel32.MustFindProc("SetStdHandle") // procSetStdHandle = kernel32.MustFindProc("SetStdHandle")
) //)
//
func setStdHandle(stdhandle int32, handle syscall.Handle) error { //func setStdHandle(stdhandle int32, handle syscall.Handle) error {
r0, _, e1 := syscall.Syscall(procSetStdHandle.Addr(), 2, uintptr(stdhandle), uintptr(handle), 0) // r0, _, e1 := syscall.Syscall(procSetStdHandle.Addr(), 2, uintptr(stdhandle), uintptr(handle), 0)
if r0 == 0 { // if r0 == 0 {
if e1 != 0 { // if e1 != 0 {
return error(e1) // return error(e1)
} // }
return syscall.EINVAL // return syscall.EINVAL
} // }
return nil // return nil
} //}
//
//// redirectStderr to the file passed in
//func redirectStderrWindows(f *os.File) {
// err := setStdHandle(syscall.STD_ERROR_HANDLE, syscall.Handle(f.Fd()))
// if err != nil {
// logger.Log.Panic(err.Error())
// }
// // SetStdHandle does not affect prior references to stderr
// os.Stderr = f
//}
//windows end
// redirectStderr to the file passed in func redirectStderrLinux(f *os.File) {
func redirectStderrWindows(f *os.File) { err := syscall.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
err := setStdHandle(syscall.STD_ERROR_HANDLE, syscall.Handle(f.Fd()))
if err != nil { if err != nil {
logger.Log.Panic(err.Error()) logger.Log.Panic(err.Error())
} }
// SetStdHandle does not affect prior references to stderr
os.Stderr = f
} }
//windows end //func init() {
//
//func redirectStderrLinux(f *os.File) {
// err := syscall.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
// if err != nil {
// logger.Log.Panic(err.Error())
// }
//} //}
func init() { // dcfan50 "jeff_workstation_1/devproduct/dcfan50"
// dcphone10 "jeff_workstation_1/devproduct/dcphone10"
func main() { //
jeffutil.ConfigInit()
logger.InitLogger() logger.InitLogger()
f, err := os.OpenFile(jeffutil.LogPath+"panic.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0755) f, err := os.OpenFile(jeffutil.LogPath+"panic.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0755)
if err != nil { if err != nil {
logger.Log.Panic(err.Error()) logger.Log.Panic(err.Error())
} }
redirectStderrWindows(f) //redirectStderrWindows(f)
// redirectStderrLinux(f) redirectStderrLinux(f)
}
// dcfan50 "jeff_workstation_1/devproduct/dcfan50"
// dcphone10 "jeff_workstation_1/devproduct/dcphone10"
func main() { //
gin.SetMode(jeffutil.HttpServerMode) gin.SetMode(jeffutil.HttpServerMode)
r := gin.New() r := gin.New()
r.Use(logger.HttpGinLog(), gin.Recovery()) r.Use(logger.HttpGinLog(), gin.Recovery())
...@@ -67,7 +70,7 @@ func main() { // ...@@ -67,7 +70,7 @@ func main() { //
// dcfan50.NewDCFan50(r) // dcfan50.NewDCFan50(r)
dcphone10.NewDCPhone10(r) dcphone10.NewDCPhone10(r)
err := r.Run(jeffutil.HttpServerPort) err = r.Run(jeffutil.HttpServerPort)
if err != nil { if err != nil {
panic(err) panic(err)
} }
......
. 编译成linux的可执行文件 . 编译成linux的可执行文件
. 编译成linux的可执行文件 . 编译成linux的可执行文件
1. set GOARCH=amd64 1. set GOARCH=amd64
2. set GOOS=linux set GOOS=windows 2. set GOOS=linux set GOOS=windows
3. go build -o TcpServer -ldflags "-w -s" main.go 3. go build -o tcpServer -ldflags "-w -s" main.go
windows编译 go build -o phoneDevServer.exe -ldflags "-w -s -H windowsgui" main.go windows编译 go build -o phoneDevServer.exe -ldflags "-w -s -H windowsgui" main.go
前台要打印 go build -ldflags "-w -s" main.go 前台要打印 go build -ldflags "-w -s" main.go
...@@ -21,7 +21,7 @@ top 查看服务器占用情况 ...@@ -21,7 +21,7 @@ top 查看服务器占用情况
// 仅监视进程,修改filename和路径/root/XXXXX // 仅监视进程,修改filename和路径/root/XXXXX
#!/bin/bash #!/bin/bash
filename=TcpServer filename=tcpServer
port=50000 port=50000
cnt=`netstat -tnlp|grep $port |grep -v grep |wc -l` cnt=`netstat -tnlp|grep $port |grep -v grep |wc -l`
#cne=`ps -ef|grep $filename|grep -v grep |wc -l` #cne=`ps -ef|grep $filename|grep -v grep |wc -l`
......
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