You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
465 B
Go
34 lines
465 B
Go
1 year ago
|
package protocol
|
||
|
|
||
|
import (
|
||
|
"git.noahlan.cn/noahlan/nnet/packet"
|
||
|
)
|
||
|
|
||
|
type (
|
||
|
Packet interface {
|
||
|
packet.IPacket
|
||
|
Copy() Packet
|
||
|
Modbus
|
||
|
SetBody(data []byte)
|
||
|
SetError(err *MError)
|
||
|
}
|
||
|
|
||
|
Modbus interface {
|
||
|
GetFunction() uint8
|
||
|
GetAddress() uint8
|
||
|
}
|
||
|
|
||
|
ModbusHeader struct {
|
||
|
Address uint8
|
||
|
Function uint8
|
||
|
}
|
||
|
)
|
||
|
|
||
|
func GetError(pkg Packet) (err MError) {
|
||
|
function := pkg.GetFunction()
|
||
|
if (function & 0x80) != 0 {
|
||
|
err = MError(pkg.GetBody()[0])
|
||
|
}
|
||
|
return
|
||
|
}
|