Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qsh-wc
Project
Project
Details
Activity
Releases
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
honghuiliu
qsh-wc
Commits
31cdcd55
Commit
31cdcd55
authored
Sep 23, 2022
by
sven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加dtu数据接收
parent
f6cf64b0
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
3 deletions
+111
-3
config-prod.yaml
server/config-prod.yaml
+6
-1
config-test.yaml
server/config-test.yaml
+6
-1
config.yaml
server/config.yaml
+6
-1
main.go
server/main.go
+11
-0
dtu.go
server/server/dtu.go
+82
-0
No files found.
server/config-prod.yaml
View file @
31cdcd55
...
...
@@ -168,3 +168,8 @@ oss:
OssInternalHost
:
"
https://wensi-zhanlang.oss-cn-hangzhou-internal.aliyuncs.com"
EndPoint
:
"
oss-cn-hangzhou.aliyuncs.com"
prefix
:
"
qsh_wc/"
# dtu设备配置
dtuServer
:
addr
:
0.0.0.0:9804
enable
:
false
\ No newline at end of file
server/config-test.yaml
View file @
31cdcd55
...
...
@@ -168,3 +168,8 @@ oss:
OssInternalHost
:
"
https://wensi-zhanlang.oss-cn-hangzhou-internal.aliyuncs.com"
EndPoint
:
"
oss-cn-hangzhou.aliyuncs.com"
prefix
:
"
qsh_wc/"
# dtu设备配置
dtuServer
:
addr
:
0.0.0.0:9804
enable
:
true
\ No newline at end of file
server/config.yaml
View file @
31cdcd55
...
...
@@ -168,3 +168,8 @@ oss:
OssInternalHost
:
"
https://wensi-zhanlang.oss-cn-hangzhou-internal.aliyuncs.com"
EndPoint
:
"
oss-cn-hangzhou.aliyuncs.com"
prefix
:
"
qsh_wc/"
# dtu设备配置
dtuServer
:
addr
:
0.0.0.0:9804
enable
:
false
\ No newline at end of file
server/main.go
View file @
31cdcd55
package
main
import
(
"fmt"
"github.com/flipped-aurora/gin-vue-admin/server/core"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/initialize"
"github.com/flipped-aurora/gin-vue-admin/server/server"
"go.uber.org/zap"
)
...
...
@@ -33,5 +35,14 @@ func main() {
db
,
_
:=
global
.
GVA_DB
.
DB
()
defer
db
.
Close
()
}
// dtu服务器
if
global
.
GVA_VP
.
GetBool
(
"dtuServer.enable"
)
{
server
.
OnDtuMessage
(
func
(
data
server
.
YeWeiData
)
error
{
fmt
.
Println
(
data
)
// {9.300 860059054444117}
return
nil
})
go
server
.
InitDtuServer
(
global
.
GVA_VP
.
GetString
(
"dtuServer.addr"
))
}
core
.
RunWindowsServer
()
}
server/server/dtu.go
0 → 100644
View file @
31cdcd55
package
server
import
(
"fmt"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"log"
"net"
"regexp"
"strings"
)
type
YeWeiData
struct
{
YeWei
string
// 液位高度,单位m
DeviceId
string
// 设备编号
}
type
YeWeiCb
func
(
data
YeWeiData
)
error
var
yeWeiCb
YeWeiCb
func
InitDtuServer
(
address
string
)
{
server
,
err
:=
net
.
Listen
(
"tcp"
,
address
)
if
err
!=
nil
{
log
.
Fatalln
(
"dtu server init err:"
,
err
)
}
defer
server
.
Close
()
log
.
Println
(
"Dtu server is running, listened:"
,
address
)
for
{
conn
,
err
:=
server
.
Accept
()
if
err
!=
nil
{
log
.
Println
(
"dtu accept err:"
,
err
)
continue
}
go
dtuOnMessage
(
conn
)
}
}
// dtuOnMessage 处理dtu消息
func
dtuOnMessage
(
conn
net
.
Conn
)
{
defer
conn
.
Close
()
for
{
data
:=
make
([]
byte
,
1024
)
n
,
err
:=
conn
.
Read
(
data
)
if
err
!=
nil
{
global
.
GVA_LOG
.
Error
(
fmt
.
Sprintf
(
"dtu read data err: %s"
,
err
.
Error
()))
break
}
// 处理协议,解析数据
yeweiData
:=
YeWeiData
{}
strData
:=
string
(
data
[
0
:
n
])
reg
,
err
:=
regexp
.
Compile
(
"
\\
d*50000#SY6600"
)
yeweiData
.
DeviceId
=
strings
.
Replace
(
reg
.
FindString
(
strData
),
"50000#SY6600"
,
""
,
1
)
if
yeweiData
.
DeviceId
==
""
{
global
.
GVA_LOG
.
Error
(
fmt
.
Sprintf
(
"协议解析失败 strData: %s"
,
strData
))
continue
}
reg
,
_
=
regexp
.
Compile
(
"0/0,0/0,0/0,0/0,0,0,.*,0,0,0,0,0,0,0,0,0,0,0,0,0,0,Protocol:NKCSBYE$"
)
value
:=
strings
.
Replace
(
reg
.
FindString
(
strData
),
"0/0,0/0,0/0,0/0,0,0,"
,
""
,
1
)
value
=
strings
.
Replace
(
value
,
",0,0,0,0,0,0,0,0,0,0,0,0,0,0,Protocol:NKCSBYE"
,
""
,
1
)
if
values
:=
strings
.
Split
(
value
,
","
);
len
(
values
)
==
2
{
yeweiData
.
YeWei
=
values
[
1
]
}
if
yeweiData
.
YeWei
==
""
{
global
.
GVA_LOG
.
Error
(
fmt
.
Sprintf
(
"协议解析失败 strData: %s"
,
strData
))
continue
}
// 调用业务处理
if
yeWeiCb
!=
nil
{
err
=
yeWeiCb
(
yeweiData
)
if
err
!=
nil
{
global
.
GVA_LOG
.
Error
(
fmt
.
Sprintf
(
"处理液位回调失败 strData: %s"
,
strData
))
}
}
}
}
// OnDtuMessage 注册回调函数
func
OnDtuMessage
(
cb
YeWeiCb
)
{
yeWeiCb
=
cb
}
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