|
|
@ -28,13 +28,12 @@ type (
|
|
|
|
FnCode() uint8
|
|
|
|
FnCode() uint8
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LogicFunc func(startAddr, number int, val any)
|
|
|
|
LogicFunc func(pkg protocol.Packet, startAddr, number int, val any)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func NewHandler(byteOrder binary.ByteOrder) *Handler {
|
|
|
|
func NewHandler(byteOrder binary.ByteOrder) *Handler {
|
|
|
|
p := &Handler{
|
|
|
|
p := &Handler{
|
|
|
|
byteOrder: byteOrder,
|
|
|
|
byteOrder: byteOrder,
|
|
|
|
//functions: make(map[uint8]FunctionFunc),
|
|
|
|
|
|
|
|
logics: make(map[uint8]LogicFunc),
|
|
|
|
logics: make(map[uint8]LogicFunc),
|
|
|
|
handlerMap: make(map[uint8]FunctionHandler),
|
|
|
|
handlerMap: make(map[uint8]FunctionHandler),
|
|
|
|
dataMap: make(map[uint8]*DataMgr),
|
|
|
|
dataMap: make(map[uint8]*DataMgr),
|
|
|
@ -97,10 +96,10 @@ func (p *Handler) Handle(conn *connection.Connection, pkg packet.IPacket) {
|
|
|
|
_ = conn.Send(resp.GetHeader(), resp.GetBody())
|
|
|
|
_ = conn.Send(resp.GetHeader(), resp.GetBody())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p *Handler) HandleLogic(fnCode uint8, startAddr, number int, val any) {
|
|
|
|
func (p *Handler) HandleLogic(fnCode uint8, pkg protocol.Packet, startAddr, number int, val any) {
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
if fn, ok := p.logics[fnCode]; ok {
|
|
|
|
if fn, ok := p.logics[fnCode]; ok {
|
|
|
|
fn(startAddr, number, val)
|
|
|
|
fn(pkg, startAddr, number, val)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
|
|
|