Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
rudern
物联大师
提交
e34b44ca
物
物联大师
项目概览
rudern
/
物联大师
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
物
物联大师
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
e34b44ca
编写于
3月 17, 2021
作者:
J
jason
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
协议小优化
上级
73ad0664
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
32 addition
and
25 deletion
+32
-25
protocol/adapter.go
protocol/adapter.go
+17
-0
protocol/modbus/rtu.go
protocol/modbus/rtu.go
+4
-4
protocol/protocol.go
protocol/protocol.go
+11
-21
未找到文件。
protocol/adapter.go
0 → 100644
浏览文件 @
e34b44ca
package
protocol
import
(
"iot-master/base"
)
type
Adapter
interface
{
Name
()
string
Version
()
string
Attach
(
link
base
.
Link
)
Read
(
slave
uint8
,
code
uint8
,
offset
uint16
,
size
uint16
)
([]
byte
,
error
)
Write
(
slave
uint8
,
code
uint8
,
offset
uint16
,
buf
[]
byte
)
error
}
protocol/modbus/rtu.go
浏览文件 @
e34b44ca
...
...
@@ -4,14 +4,14 @@ import (
"errors"
"fmt"
"iot-master/base"
"iot-master/protocol
/adapter
"
"iot-master/protocol"
"iot-master/protocol/helper"
)
func
init
()
{
adapter
.
RegisterAdapter
(
protocol
.
RegisterAdapter
(
"Modbus RTU"
,
[]
adapter
.
Code
{
[]
protocol
.
Code
{
{
"线圈"
,
1
},
{
"离散量"
,
2
},
{
"保持寄存器"
,
3
},
...
...
@@ -30,7 +30,7 @@ type RTU struct {
resp
chan
response
}
func
NewModbusRtu
(
opts
string
)
(
adapter
.
Adapter
,
error
)
{
func
NewModbusRtu
(
opts
string
)
(
protocol
.
Adapter
,
error
)
{
return
&
RTU
{
resp
:
make
(
chan
response
,
1
),
},
nil
...
...
protocol/
adapter/adapter
.go
→
protocol/
protocol
.go
浏览文件 @
e34b44ca
package
adapter
package
protocol
import
(
"errors"
"iot-master/base"
"sync"
)
type
Adapter
interface
{
Name
()
string
Version
()
string
Attach
(
link
base
.
Link
)
Read
(
slave
uint8
,
code
uint8
,
offset
uint16
,
size
uint16
)
([]
byte
,
error
)
Write
(
slave
uint8
,
code
uint8
,
offset
uint16
,
buf
[]
byte
)
error
}
type
Factory
func
(
opts
string
)
(
Adapter
,
error
)
//可以改为普通map
var
protocols
sync
.
Map
//adapters
//功能码
type
Code
struct
{
Name
string
`json:"name"`
Code
uint8
`json:"code"`
}
type
adapter
struct
{
type
adapter
s
struct
{
Name
string
`json:"name"`
Codes
[]
Code
`json:"codes"`
factory
Factory
}
//可以改为普通map
var
protocols
sync
.
Map
//adapter
type
Factory
func
(
opts
string
)
(
Adapter
,
error
)
func
GetProtocols
()
[]
adapter
{
ps
:=
make
([]
adapter
,
0
)
func
GetProtocols
()
[]
adapter
s
{
ps
:=
make
([]
adapter
s
,
0
)
protocols
.
Range
(
func
(
key
,
value
interface
{})
bool
{
ps
=
append
(
ps
,
value
.
(
adapter
))
ps
=
append
(
ps
,
value
.
(
adapter
s
))
return
true
})
return
ps
...
...
@@ -43,14 +33,14 @@ func GetProtocols() []adapter {
func
CreateAdapter
(
name
string
,
opts
string
)
(
Adapter
,
error
)
{
if
v
,
ok
:=
protocols
.
Load
(
name
);
ok
&&
v
!=
nil
{
p
:=
v
.
(
*
adapter
)
p
:=
v
.
(
*
adapter
s
)
return
p
.
factory
(
opts
)
}
return
nil
,
errors
.
New
(
"找不到协议"
)
}
func
RegisterAdapter
(
name
string
,
codes
[]
Code
,
factory
Factory
)
{
protocols
.
Store
(
name
,
&
adapter
{
protocols
.
Store
(
name
,
&
adapter
s
{
Name
:
name
,
Codes
:
codes
,
factory
:
factory
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录