dissector

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DBMaxSizeWithoutNotify if more DataUnits than this in the buffer, then notity
	DBMaxSizeWithoutNotify = 4096

	// DissectorFlushAfterSecondsModbusRTU flush data if older than this [seconds]
	DissectorFlushAfterSecondsModbusRTU = 5
)
View Source
const (
	// ADUMinSize minium size of ADU in bytes
	ADUMinSize int = ADUSizePDUResponseException

	// ADUSizePDURequest size in bytes of a PDU request
	ADUSizePDURequest int = 8

	// ADUSizePDUResponseException size in bytes of a PDU exception
	ADUSizePDUResponseException int = 5
)

Variables

View Source
var (
	FunctionCode_name = map[int32]string{
		0:  "FuncCodeNouse",
		4:  "FuncCodeReadInputRegisters",
		3:  "FuncCodeReadHoldingRegisters",
		6:  "FuncCodeWriteSingleRegister",
		16: "FuncCodeWriteMultipleRegisters",
		23: "FuncCodeReadWriteMultipleRegisters",
		22: "FuncCodeMaskWriteRegister",
		24: "FuncCodeReadFIFOQueue",
	}
	FunctionCode_value = map[string]int32{
		"FuncCodeNouse":                      0,
		"FuncCodeReadInputRegisters":         4,
		"FuncCodeReadHoldingRegisters":       3,
		"FuncCodeWriteSingleRegister":        6,
		"FuncCodeWriteMultipleRegisters":     16,
		"FuncCodeReadWriteMultipleRegisters": 23,
		"FuncCodeMaskWriteRegister":          22,
		"FuncCodeReadFIFOQueue":              24,
	}
)

Enum value maps for FunctionCode.

View Source
var (
	ExceptionCode_name = map[int32]string{
		0:  "ExceptionCodeNouse",
		1:  "ExceptionCodeIllegalFunction",
		2:  "ExceptionCodeIllegalDataAddress",
		3:  "ExceptionCodeIllegalDataValue",
		4:  "ExceptionCodeServerDeviceFailure",
		5:  "ExceptionCodeAcknowledge",
		6:  "ExceptionCodeServerDeviceBusy",
		8:  "ExceptionCodeMemoryParityError",
		10: "ExceptionCodeGatewayPathUnavailable",
		11: "ExceptionCodeGatewayTargetDeviceFailedToRespond",
	}
	ExceptionCode_value = map[string]int32{
		"ExceptionCodeNouse":                              0,
		"ExceptionCodeIllegalFunction":                    1,
		"ExceptionCodeIllegalDataAddress":                 2,
		"ExceptionCodeIllegalDataValue":                   3,
		"ExceptionCodeServerDeviceFailure":                4,
		"ExceptionCodeAcknowledge":                        5,
		"ExceptionCodeServerDeviceBusy":                   6,
		"ExceptionCodeMemoryParityError":                  8,
		"ExceptionCodeGatewayPathUnavailable":             10,
		"ExceptionCodeGatewayTargetDeviceFailedToRespond": 11,
	}
)

Enum value maps for ExceptionCode.

View Source
var File_dissector_dissector_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type ADU

type ADU struct {
	Address uint32 `protobuf:"varint,1,opt,name=address,proto3" json:"address,omitempty"` // 8bit
	// Types that are assignable to PDU:
	//	*ADU_PduRequest
	//	*ADU_PduResponse
	//	*ADU_PduResponseException
	PDU   isADU_PDU            `protobuf_oneof:"PDU"`
	Crc16 uint32               `protobuf:"varint,15,opt,name=crc16,proto3" json:"crc16,omitempty"` // 16bit CRC
	Time  *timestamp.Timestamp `protobuf:"bytes,16,opt,name=time,proto3" json:"time,omitempty"`
	// contains filtered or unexported fields
}

ADU, Application Data Unit max size is 256 bytes

func NewADU

func NewADU(db *DissectorBuffer, index int) (adu *ADU, err error)

NewADU builds an ADU from DissectorBuffer at position index. Returns err==nil on success Can be utilized to check if there is a ADU at specific position, also in cobination with IsRequest(), IsResponse(), IsException()

func (*ADU) Descriptor deprecated

func (*ADU) Descriptor() ([]byte, []int)

Deprecated: Use ADU.ProtoReflect.Descriptor instead.

func (*ADU) GetAddress

func (x *ADU) GetAddress() uint32

func (*ADU) GetCrc16

func (x *ADU) GetCrc16() uint32

func (*ADU) GetPDU

func (m *ADU) GetPDU() isADU_PDU

func (*ADU) GetPduRequest

func (x *ADU) GetPduRequest() *PDURequest

func (*ADU) GetPduResponse

func (x *ADU) GetPduResponse() *PDUResponse

func (*ADU) GetPduResponseException

func (x *ADU) GetPduResponseException() *PDUResponseException

func (*ADU) GetTime

func (x *ADU) GetTime() *timestamp.Timestamp

func (*ADU) GetTimeTime

func (adu *ADU) GetTimeTime() time.Time

func (*ADU) IsException

func (adu *ADU) IsException() bool

IsException return true if ADU is a Modbus Response with exceptions

func (*ADU) IsRequest

func (adu *ADU) IsRequest() bool

IsRequest return true if ADU is a Modbus Request

func (*ADU) IsResponse

func (adu *ADU) IsResponse() bool

IsResponse return true if ADU is a Modbus Response without exceptions

func (*ADU) PrettyString

func (adu *ADU) PrettyString() (s string)

func (*ADU) ProtoMessage

func (*ADU) ProtoMessage()

func (*ADU) ProtoReflect

func (x *ADU) ProtoReflect() protoreflect.Message

func (*ADU) Reset

func (x *ADU) Reset()

func (*ADU) Size

func (adu *ADU) Size() int

Size returns ADU size in bytes, return 0 in case of error

func (*ADU) String

func (x *ADU) String() string

type ADU_PduRequest

type ADU_PduRequest struct {
	PduRequest *PDURequest `protobuf:"bytes,2,opt,name=pduRequest,proto3,oneof"`
}

type ADU_PduResponse

type ADU_PduResponse struct {
	PduResponse *PDUResponse `protobuf:"bytes,3,opt,name=pduResponse,proto3,oneof"`
}

type ADU_PduResponseException

type ADU_PduResponseException struct {
	PduResponseException *PDUResponseException `protobuf:"bytes,4,opt,name=pduResponseException,proto3,oneof"`
}

type Dissector

type Dissector struct {
	DissectorBuffer

	Consumer chan logger.DataUnit

	Producer chan Result
	// contains filtered or unexported fields
}

func New

func New(c *logger.Config, filter ResultFilter) (d *Dissector, err error)

New builds new dissector and starts waiting for data. DataUnits should be sent to GetConsumer() channel. Results can be fetched with GetResults(). Should be closed with Close() at the end.

func (*Dissector) Close

func (d *Dissector) Close()

Close closes

func (*Dissector) GetConsumer

func (d *Dissector) GetConsumer() chan logger.DataUnit

GetConsumer return the channel to send DataUnits to

type DissectorBuffer

type DissectorBuffer struct {
	TimedBytes []*TimedByte `protobuf:"bytes,1,rep,name=timedBytes,proto3" json:"timedBytes,omitempty"`
	// contains filtered or unexported fields
}

Dissector

func (*DissectorBuffer) Descriptor deprecated

func (*DissectorBuffer) Descriptor() ([]byte, []int)

Deprecated: Use DissectorBuffer.ProtoReflect.Descriptor instead.

func (*DissectorBuffer) GetTimedBytes

func (x *DissectorBuffer) GetTimedBytes() []*TimedByte

func (*DissectorBuffer) PrettyString

func (db *DissectorBuffer) PrettyString() (s string)

func (*DissectorBuffer) ProtoMessage

func (*DissectorBuffer) ProtoMessage()

func (*DissectorBuffer) ProtoReflect

func (x *DissectorBuffer) ProtoReflect() protoreflect.Message

func (*DissectorBuffer) Reset

func (x *DissectorBuffer) Reset()

func (*DissectorBuffer) Size

func (db *DissectorBuffer) Size() int

Size in [TimedBytes]

func (*DissectorBuffer) String

func (x *DissectorBuffer) String() string

type ExceptionCode

type ExceptionCode int32

Exception Code, 8bit

const (
	ExceptionCode_ExceptionCodeNouse                              ExceptionCode = 0 // unused, protobuf3 requirement
	ExceptionCode_ExceptionCodeIllegalFunction                    ExceptionCode = 1
	ExceptionCode_ExceptionCodeIllegalDataAddress                 ExceptionCode = 2
	ExceptionCode_ExceptionCodeIllegalDataValue                   ExceptionCode = 3
	ExceptionCode_ExceptionCodeServerDeviceFailure                ExceptionCode = 4
	ExceptionCode_ExceptionCodeAcknowledge                        ExceptionCode = 5
	ExceptionCode_ExceptionCodeServerDeviceBusy                   ExceptionCode = 6
	ExceptionCode_ExceptionCodeMemoryParityError                  ExceptionCode = 8
	ExceptionCode_ExceptionCodeGatewayPathUnavailable             ExceptionCode = 10
	ExceptionCode_ExceptionCodeGatewayTargetDeviceFailedToRespond ExceptionCode = 11
)

func (ExceptionCode) Descriptor

func (ExceptionCode) Enum

func (x ExceptionCode) Enum() *ExceptionCode

func (ExceptionCode) EnumDescriptor deprecated

func (ExceptionCode) EnumDescriptor() ([]byte, []int)

Deprecated: Use ExceptionCode.Descriptor instead.

func (ExceptionCode) Number

func (ExceptionCode) String

func (x ExceptionCode) String() string

func (ExceptionCode) Type

type FilterAnyModbus

type FilterAnyModbus struct{}

type FilterOnlyModbusRequest

type FilterOnlyModbusRequest struct{}

type FilterOnlyModbusResponseOrException

type FilterOnlyModbusResponseOrException struct{}

type FunctionCode

type FunctionCode int32

Function Code, 16bit

const (
	FunctionCode_FuncCodeNouse                      FunctionCode = 0 // unused, protobuf3 requirement
	FunctionCode_FuncCodeReadInputRegisters         FunctionCode = 4
	FunctionCode_FuncCodeReadHoldingRegisters       FunctionCode = 3
	FunctionCode_FuncCodeWriteSingleRegister        FunctionCode = 6
	FunctionCode_FuncCodeWriteMultipleRegisters     FunctionCode = 16
	FunctionCode_FuncCodeReadWriteMultipleRegisters FunctionCode = 23
	FunctionCode_FuncCodeMaskWriteRegister          FunctionCode = 22
	FunctionCode_FuncCodeReadFIFOQueue              FunctionCode = 24
)

func (FunctionCode) Descriptor

func (FunctionCode) Enum

func (x FunctionCode) Enum() *FunctionCode

func (FunctionCode) EnumDescriptor deprecated

func (FunctionCode) EnumDescriptor() ([]byte, []int)

Deprecated: Use FunctionCode.Descriptor instead.

func (FunctionCode) Number

func (FunctionCode) String

func (x FunctionCode) String() string

func (FunctionCode) Type

type PDURequest

type PDURequest struct {
	FunctionCode uint32 `protobuf:"varint,1,opt,name=functionCode,proto3" json:"functionCode,omitempty"` // 8bit
	Data         []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
	// contains filtered or unexported fields
}

PDU, Protocol Data Unit max size is 253 bytes

func (*PDURequest) Descriptor deprecated

func (*PDURequest) Descriptor() ([]byte, []int)

Deprecated: Use PDURequest.ProtoReflect.Descriptor instead.

func (*PDURequest) GetData

func (x *PDURequest) GetData() []byte

func (*PDURequest) GetFunctionCode

func (x *PDURequest) GetFunctionCode() uint32

func (*PDURequest) ProtoMessage

func (*PDURequest) ProtoMessage()

func (*PDURequest) ProtoReflect

func (x *PDURequest) ProtoReflect() protoreflect.Message

func (*PDURequest) Reset

func (x *PDURequest) Reset()

func (*PDURequest) String

func (x *PDURequest) String() string

type PDUResponse

type PDUResponse struct {
	FunctionCode uint32 `protobuf:"varint,1,opt,name=functionCode,proto3" json:"functionCode,omitempty"` // 8bit
	Data         []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
	// contains filtered or unexported fields
}

func (*PDUResponse) Descriptor deprecated

func (*PDUResponse) Descriptor() ([]byte, []int)

Deprecated: Use PDUResponse.ProtoReflect.Descriptor instead.

func (*PDUResponse) GetData

func (x *PDUResponse) GetData() []byte

func (*PDUResponse) GetFunctionCode

func (x *PDUResponse) GetFunctionCode() uint32

func (*PDUResponse) ProtoMessage

func (*PDUResponse) ProtoMessage()

func (*PDUResponse) ProtoReflect

func (x *PDUResponse) ProtoReflect() protoreflect.Message

func (*PDUResponse) Reset

func (x *PDUResponse) Reset()

func (*PDUResponse) String

func (x *PDUResponse) String() string

type PDUResponseException

type PDUResponseException struct {
	FunctionExceptionCode uint32 `protobuf:"varint,1,opt,name=functionExceptionCode,proto3" json:"functionExceptionCode,omitempty"` // 8bit
	ExceptionCode         uint32 `protobuf:"varint,2,opt,name=exceptionCode,proto3" json:"exceptionCode,omitempty"`
	// contains filtered or unexported fields
}

func (*PDUResponseException) Descriptor deprecated

func (*PDUResponseException) Descriptor() ([]byte, []int)

Deprecated: Use PDUResponseException.ProtoReflect.Descriptor instead.

func (*PDUResponseException) GetExceptionCode

func (x *PDUResponseException) GetExceptionCode() uint32

func (*PDUResponseException) GetFunctionExceptionCode

func (x *PDUResponseException) GetFunctionExceptionCode() uint32

func (*PDUResponseException) ProtoMessage

func (*PDUResponseException) ProtoMessage()

func (*PDUResponseException) ProtoReflect

func (x *PDUResponseException) ProtoReflect() protoreflect.Message

func (*PDUResponseException) Reset

func (x *PDUResponseException) Reset()

func (*PDUResponseException) String

func (x *PDUResponseException) String() string

type Result

type Result struct {
	Adu *ADU `protobuf:"bytes,1,opt,name=adu,proto3" json:"adu,omitempty"`
	// contains filtered or unexported fields
}

this depends on dissected protocol. Now it only supports Modbus ADU. Can be extended with `oneof`

func (*Result) Descriptor deprecated

func (*Result) Descriptor() ([]byte, []int)

Deprecated: Use Result.ProtoReflect.Descriptor instead.

func (*Result) GetAdu

func (x *Result) GetAdu() *ADU

func (*Result) PrettyString

func (r *Result) PrettyString() string

func (*Result) ProtoMessage

func (*Result) ProtoMessage()

func (*Result) ProtoReflect

func (x *Result) ProtoReflect() protoreflect.Message

func (*Result) Reset

func (x *Result) Reset()

func (*Result) String

func (x *Result) String() string

type ResultFilter

type ResultFilter interface {
	// contains filtered or unexported methods
}

type Results

type Results struct {
	Results []*Result `protobuf:"bytes,1,rep,name=results,proto3" json:"results,omitempty"`
	// contains filtered or unexported fields
}

func (*Results) Descriptor deprecated

func (*Results) Descriptor() ([]byte, []int)

Deprecated: Use Results.ProtoReflect.Descriptor instead.

func (*Results) GetResults

func (x *Results) GetResults() []*Result

func (*Results) ProtoMessage

func (*Results) ProtoMessage()

func (*Results) ProtoReflect

func (x *Results) ProtoReflect() protoreflect.Message

func (*Results) Reset

func (x *Results) Reset()

func (*Results) String

func (x *Results) String() string

type TimedByte

type TimedByte struct {
	Time *timestamp.Timestamp `protobuf:"bytes,1,opt,name=time,proto3" json:"time,omitempty"`
	Byte uint32               `protobuf:"varint,2,opt,name=byte,proto3" json:"byte,omitempty"` // 8bit
	// contains filtered or unexported fields
}

func (*TimedByte) Descriptor deprecated

func (*TimedByte) Descriptor() ([]byte, []int)

Deprecated: Use TimedByte.ProtoReflect.Descriptor instead.

func (*TimedByte) GetByte

func (x *TimedByte) GetByte() uint32

func (*TimedByte) GetTime

func (x *TimedByte) GetTime() *timestamp.Timestamp

func (*TimedByte) ProtoMessage

func (*TimedByte) ProtoMessage()

func (*TimedByte) ProtoReflect

func (x *TimedByte) ProtoReflect() protoreflect.Message

func (*TimedByte) Reset

func (x *TimedByte) Reset()

func (*TimedByte) String

func (x *TimedByte) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL