Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
golangphone10
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhangjie
golangphone10
Commits
5f865c50
Commit
5f865c50
authored
Aug 11, 2021
by
zhangjiec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加业务服务器发来的内容错误返回
parent
b5e7234d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
104 additions
and
108 deletions
+104
-108
TcpServer
TcpServer
+0
-0
dc_phone10_http_server.go
devproduct/dcphone10/dc_phone10_http_server.go
+41
-0
dc_phone10_tcp.go
devproduct/dcphone10/dc_phone10_tcp.go
+2
-2
jeffutil_test.go
jeffutil/jeffutil_test.go
+19
-67
setting.go
jeffutil/setting.go
+1
-1
main.go
main.go
+38
-35
操作命令.txt
操作命令.txt
+3
-3
No files found.
TcpServer
deleted
100644 → 0
View file @
b5e7234d
File deleted
devproduct/dcphone10/dc_phone10_http_server.go
View file @
5f865c50
...
...
@@ -38,6 +38,11 @@ func (dev *DCPhone10) getOnlineList(c *gin.Context) {
logger
.
Log
.
Error
(
"c.ShouldBindJSON(&dataIn)"
,
zap
.
String
(
"Src"
,
"getOnlineList"
),
zap
.
Error
(
err
))
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"status"
:
2002
,
"message"
:
"参数内容错误"
,
})
return
}
type
DataO
struct
{
...
...
@@ -119,6 +124,11 @@ func (dev *DCPhone10) putOnlineClose(c *gin.Context) {
logger
.
Log
.
Error
(
"c.ShouldBindJSON(&data)"
,
zap
.
String
(
"Src"
,
"putOnlineClose"
),
zap
.
Error
(
err
))
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"status"
:
2002
,
"message"
:
"参数内容错误"
,
})
return
}
type
DataO
struct
{
...
...
@@ -160,6 +170,11 @@ func (dev *DCPhone10) getDevPara(c *gin.Context) {
logger
.
Log
.
Error
(
"c.ShouldBindJSON(&data)"
,
zap
.
String
(
"Src"
,
"getDevPara"
),
zap
.
Error
(
err
))
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"status"
:
2002
,
"message"
:
"参数内容错误"
,
})
return
}
type
DataO
struct
{
...
...
@@ -180,6 +195,7 @@ func (dev *DCPhone10) getDevPara(c *gin.Context) {
sData
.
DevID
=
id
if
dev
.
TCPSend
(
&
sData
)
==
true
{
dataOut
.
DevID
[
id
]
=
true
dataOut
.
Count
++
}
else
{
dataOut
.
DevID
[
id
]
=
false
}
...
...
@@ -221,6 +237,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) {
logger
.
Log
.
Error
(
"c.ShouldBindJSON(&data)"
,
zap
.
String
(
"Src"
,
"case
\"
tcp_server_addr
\"
"
),
zap
.
Error
(
err
))
sTcpData
.
CtrlCode
=
0
returnState
=
2002
returnMsg
=
"参数内容错误"
break
}
sTcpData
.
Data
=
[]
byte
(
"
\"
"
+
data
.
Value
.
IP
+
"
\"
,"
+
strconv
.
Itoa
(
int
(
data
.
Value
.
Port
)))
sTcpData
.
Length
=
byte
(
len
(
sTcpData
.
Data
))
...
...
@@ -231,6 +251,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) {
logger
.
Log
.
Error
(
"c.ShouldBindJSON(&data)"
,
zap
.
String
(
"Src"
,
"case
\"
select_sim_module
\"
"
),
zap
.
Error
(
err
))
sTcpData
.
CtrlCode
=
0
returnState
=
2002
returnMsg
=
"参数内容错误"
break
}
sTcpData
.
Data
[
0
]
=
data
.
Value
.
Net
<<
1
|
data
.
Value
.
Call
sTcpData
.
Length
=
1
...
...
@@ -241,6 +265,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) {
logger
.
Log
.
Error
(
"c.ShouldBindJSON(&data)"
,
zap
.
String
(
"Src"
,
"case
\"
heart
\"
"
),
zap
.
Error
(
err
))
sTcpData
.
CtrlCode
=
0
returnState
=
2002
returnMsg
=
"参数内容错误"
break
}
sTcpData
.
Data
[
0
]
=
byte
(
data
.
Value
.
Time
)
sTcpData
.
Data
[
1
]
=
byte
(
data
.
Value
.
Time
>>
8
)
...
...
@@ -253,6 +281,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) {
logger
.
Log
.
Error
(
"c.ShouldBindJSON(&data)"
,
zap
.
String
(
"Src"
,
"case
\"
beep_volume
\"
,
\"
speech_volume
\"
,
\"
speech_speed
\"
"
),
zap
.
Error
(
err
))
sTcpData
.
CtrlCode
=
0
returnState
=
2002
returnMsg
=
"参数内容错误"
break
}
sTcpData
.
Data
[
0
]
=
data
.
Value
sTcpData
.
Length
=
1
...
...
@@ -263,6 +295,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) {
logger
.
Log
.
Error
(
"c.ShouldBindJSON(&data)"
,
zap
.
String
(
"Src"
,
"case
\"
key_password
\"
,
\"
online_dial
\"
,
\"
update_firmware
\"
,
\"
restart_device
\"
"
),
zap
.
Error
(
err
))
sTcpData
.
CtrlCode
=
0
returnState
=
2002
returnMsg
=
"参数内容错误"
break
}
sTcpData
.
Data
=
[]
byte
(
data
.
Value
)
sTcpData
.
Length
=
byte
(
len
(
data
.
Value
))
...
...
@@ -273,6 +309,10 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) {
logger
.
Log
.
Error
(
"c.ShouldBindJSON(&data)"
,
zap
.
String
(
"Src"
,
"case
\"
work_time
\"
"
),
zap
.
Error
(
err
))
sTcpData
.
CtrlCode
=
0
returnState
=
2002
returnMsg
=
"参数内容错误"
break
}
i
:=
0
for
;
i
<
len
(
data
.
Value
);
i
++
{
...
...
@@ -319,6 +359,7 @@ func (dev *DCPhone10) setDevPara(c *gin.Context) {
sTcpData
.
DevID
=
id
if
dev
.
TCPSend
(
&
sTcpData
)
==
true
{
dataOut
.
DevID
[
id
]
=
true
dataOut
.
Count
++
}
else
{
dataOut
.
DevID
[
id
]
=
false
}
...
...
devproduct/dcphone10/dc_phone10_tcp.go
View file @
5f865c50
...
...
@@ -737,7 +737,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
DevSendTime
uint32
`json:"dev_send_time"`
DevID
[]
uint32
`json:"devId"`
Value
struct
{
CardUID
uint32
`json:"
message_
id"`
CardUID
uint32
`json:"
card_u
id"`
StartTime
uint32
`json:"start_time"`
TalkTime
uint16
`json:"talk_time"`
Number
string
`json:"number"`
...
...
@@ -747,7 +747,7 @@ func (dev *DCPhone10) response(data *tcplongserver.HexData) {
data
.
TimeUtc
,
[]
uint32
{
data
.
DevID
},
struct
{
CardUID
uint32
`json:"
message_
id"`
CardUID
uint32
`json:"
card_u
id"`
StartTime
uint32
`json:"start_time"`
TalkTime
uint16
`json:"talk_time"`
Number
string
`json:"number"`
...
...
jeffutil/jeffutil_test.go
View file @
5f865c50
...
...
@@ -8,72 +8,24 @@ import (
//测试用例文件使用 go test 指令来执行,没有也不需要 main() 作为函数入口
//所有在以_test结尾的源码内以Test开头的函数会自动被执行。
func
TestHex2Cipher
(
t
*
testing
.
T
)
{
a
:=
"abcABC哈哈哈就glad就是理工科,的垃圾疯狂的建安费、放大算法。dfafajdf!!"
fmt
.
Println
(
a
)
fmt
.
Println
(
DBCtoSBC
(
a
))
//password := "DCRYM-2018-pswd."
//iv := "I can't tell YOU"
//
//type HexData struct {
// TimeUtc uint32
// DevType uint8
// DevID uint32
// CtrlCode uint8
// Length uint8
// Data []byte
//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,
// 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, 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,
// 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,
// 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,
// 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}
//GetCRC(test, 254)
//for j:=0;j< len(test);{
// for i:=0;i<16;i++{
// fmt.Printf("%02X",test[j])
// j++
// }
// fmt.Println()
//}
//sData := HexData{
// 1626766761,
// 0x3E,
// 0x000001,
// 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))
a
:=
[]
byte
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
}
str
:=
string
(
a
)
fmt
.
Println
(
str
)
fmt
.
Println
(
len
(
str
))
}
//func main() {
// a := "4769676162697445746865726E6574302F302F323400"
// bs, err := hex.DecodeString(a)
// if err != nil {
// panic(err)
// }
// fmt.Println(string(bs))
//}
jeffutil/setting.go
View file @
5f865c50
...
...
@@ -34,7 +34,7 @@ var (
LogErrorMaxFileDay
int
)
func
i
nit
()
{
func
ConfigI
nit
()
{
file
,
err
:=
ini
.
Load
(
"./config.ini"
)
if
err
!=
nil
{
// logger.Log.Panic("配置文件读取错误")
...
...
main.go
View file @
5f865c50
...
...
@@ -10,55 +10,58 @@ import (
)
//windows
var
(
kernel32
=
syscall
.
MustLoadDLL
(
"kernel32.dll"
)
procSetStdHandle
=
kernel32
.
MustFindProc
(
"SetStdHandle"
)
)
func
setStdHandle
(
stdhandle
int32
,
handle
syscall
.
Handle
)
error
{
r0
,
_
,
e1
:=
syscall
.
Syscall
(
procSetStdHandle
.
Addr
(),
2
,
uintptr
(
stdhandle
),
uintptr
(
handle
),
0
)
if
r0
==
0
{
if
e1
!=
0
{
return
error
(
e1
)
}
return
syscall
.
EINVAL
}
return
nil
}
//var (
// kernel32 = syscall.MustLoadDLL("kernel32.dll")
// procSetStdHandle = kernel32.MustFindProc("SetStdHandle")
//)
//
//func setStdHandle(stdhandle int32, handle syscall.Handle) error {
// r0, _, e1 := syscall.Syscall(procSetStdHandle.Addr(), 2, uintptr(stdhandle), uintptr(handle), 0)
// if r0 == 0 {
// if e1 != 0 {
// return error(e1)
// }
// return syscall.EINVAL
// }
// 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
redirectStderrWindows
(
f
*
os
.
File
)
{
err
:=
setStdHandle
(
syscall
.
STD_ERROR_HANDLE
,
syscall
.
Handle
(
f
.
Fd
()))
func
redirectStderrLinux
(
f
*
os
.
File
)
{
err
:=
syscall
.
Dup2
(
int
(
f
.
Fd
()),
int
(
os
.
Stderr
.
Fd
()))
if
err
!=
nil
{
logger
.
Log
.
Panic
(
err
.
Error
())
}
// SetStdHandle does not affect prior references to stderr
os
.
Stderr
=
f
}
//windows end
//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() {
//
//}
func
init
()
{
// dcfan50 "jeff_workstation_1/devproduct/dcfan50"
// dcphone10 "jeff_workstation_1/devproduct/dcphone10"
func
main
()
{
//
jeffutil
.
ConfigInit
()
logger
.
InitLogger
()
f
,
err
:=
os
.
OpenFile
(
jeffutil
.
LogPath
+
"panic.log"
,
os
.
O_CREATE
|
os
.
O_APPEND
|
os
.
O_WRONLY
,
0755
)
if
err
!=
nil
{
logger
.
Log
.
Panic
(
err
.
Error
())
}
redirectStderrWindows
(
f
)
// redirectStderrLinux(f)
}
//redirectStderrWindows(f)
redirectStderrLinux
(
f
)
// dcfan50 "jeff_workstation_1/devproduct/dcfan50"
// dcphone10 "jeff_workstation_1/devproduct/dcphone10"
func
main
()
{
//
gin
.
SetMode
(
jeffutil
.
HttpServerMode
)
r
:=
gin
.
New
()
r
.
Use
(
logger
.
HttpGinLog
(),
gin
.
Recovery
())
...
...
@@ -67,7 +70,7 @@ func main() { //
// dcfan50.NewDCFan50(r)
dcphone10
.
NewDCPhone10
(
r
)
err
:
=
r
.
Run
(
jeffutil
.
HttpServerPort
)
err
=
r
.
Run
(
jeffutil
.
HttpServerPort
)
if
err
!=
nil
{
panic
(
err
)
}
...
...
操作命令.txt
View file @
5f865c50
. 编译成
linux的可执行文件
. 编译成
linux的可执行文件
. 编译成linux的可执行文件
1. set GOARCH=amd64
2. set GOOS=linux set GOOS=windows
3. go build -o
T
cpServer -ldflags "-w -s" main.go
3. go build -o
t
cpServer -ldflags "-w -s" main.go
windows编译 go build -o phoneDevServer.exe -ldflags "-w -s -H windowsgui" main.go
前台要打印 go build -ldflags "-w -s" main.go
...
...
@@ -21,7 +21,7 @@ top 查看服务器占用情况
// 仅监视进程,修改filename和路径/root/XXXXX
#!/bin/bash
filename=
T
cpServer
filename=
t
cpServer
port=50000
cnt=`netstat -tnlp|grep $port |grep -v grep |wc -l`
#cne=`ps -ef|grep $filename|grep -v grep |wc -l`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment