63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package ll
|
|
|
|
// MsgType of the lowlevel message
|
|
type MsgType uint8
|
|
|
|
// Msg holds a lowlevel message including data payload
|
|
type Msg struct {
|
|
Type MsgType
|
|
Data []byte
|
|
}
|
|
|
|
// Lowlevel message type constants
|
|
const (
|
|
MsgTypeUnknown MsgType = 0x00 // Unknown message
|
|
MsgTypeHsRequest MsgType = 0x01 // Handshake request message
|
|
MsgTypeReply MsgType = 0x02 // Reply message
|
|
MsgTypeRegister MsgType = 0x03 // Register message
|
|
MsgTypeUnregister MsgType = 0x04 // Unregister message
|
|
MsgTypePlain MsgType = 0x10 // Plain message
|
|
MsgTypeEncrypted MsgType = 0x20 // Encrypted message
|
|
MsgTypeTime MsgType = 0x40 // DI-Net time message
|
|
)
|
|
|
|
func (t MsgType) String() string {
|
|
switch t {
|
|
case MsgTypeHsRequest:
|
|
return "DNP_HS_REQUEST"
|
|
case MsgTypeReply:
|
|
return "DNP_REPLY"
|
|
case MsgTypePlain:
|
|
return "DNP_PLAIN"
|
|
case MsgTypeRegister:
|
|
return "DNP_REGISTER"
|
|
case MsgTypeUnregister:
|
|
return "DNP_UNREGISTER"
|
|
case MsgTypeEncrypted:
|
|
return "DNP_ENCRYPTED"
|
|
case MsgTypeTime:
|
|
return "DNP_TIME"
|
|
}
|
|
return "unknown"
|
|
}
|
|
|
|
// Valid checks if the message type is valid
|
|
func (t MsgType) Valid() bool {
|
|
switch t {
|
|
case MsgTypeHsRequest, MsgTypeReply, MsgTypePlain, MsgTypeEncrypted,
|
|
MsgTypeTime, MsgTypeRegister, MsgTypeUnregister:
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// IsReplySuccess checks if a low-level message is a reply and OK
|
|
func (m *Msg) IsReplySuccess() bool {
|
|
return m.Type == MsgTypeReply && string(m.Data) == "MKAY"
|
|
}
|
|
|
|
// IsReplyError checks if a low-level message is a reply and not OK
|
|
func (m *Msg) IsReplyError() bool {
|
|
return m.Type == MsgTypeReply && string(m.Data) == "WTF"
|
|
}
|