sscp

package module
v0.0.0-...-521b157 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: MIT Imports: 7 Imported by: 0

README

SSCP Driver for Go

Test and Build Workflow Go Reference

SSCP protocol implmentation for Go.

This implementation heavily depends on the specification presented in the doc folder of the project root. SSCP protocol is simply a protocol for communicating with PLCs. Now, it is possible to read/write variables with go language.

Implementation

This implementation covers the features listed below. Please open an issue and check the repository regularly if you need a feature not implemented.

Feature Implemented Tested
GetBasicInfo
Login
Logout
LargeBinarySend
LargeBinaryRecv
GetPLCStatistics
GetTaskStatistics
GetChannelStatistics
ReadVariablesDirectly
WriteVariablesDirectly
ReadVariablesFileMode
WriteVariablesFileMode
TimeSetup
TimeSetupExtended

Example Usage

	conn, err := sscp.NewPLCConnecetion(os.Args[1], 1, true)

	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}


	res, err := c.Login("admin", "rw", "", 10240)

	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	vars := []*sscp.Variable{
		&sscp.Variable{
			Uid:    9980,
			Offset: 0,
			Length: 4,
			Value:  []byte{},
		},
		&sscp.Variable{
			Uid:    9982,
			Offset: 0,
			Length: 4,
			Value:  []byte{},
		},
	}

	err = c.ReadVariablesDirectly(vars)

	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	for _, v := range vars {
		var value float32
		binary.Read(bytes.NewReader(v.Value), binary.BigEndian, &value)
		fmt.Printf("%+v %+v\n", v, value)
	}

Documentation

Index

Constants

View Source
const (
	FILE_RT_IMAGE         = "/sys/sexm"
	FILE_RT_UPGRADE_IMAGE = "/sys/rt"
	FILE_SHARK_IMAGE_1    = "/sys/sex1"
	FILE_SHARK_IMAGE_2    = "/sys/sex2"
	FILE_PLC_CAPS         = "/sys/caps"
	FILE_VAR_DIRECT       = "/var/direct"
	FILE_LOGS             = "/log"
)
View Source
const (
	PROXY_DISABLED        = 0
	PROXY_NOTUSED         = 1
	PROXY_IDLE            = 2
	PROXY_CONNECTED       = 3
	PROXY_UNAUTHORIZED    = 4
	PROXY_NOTAVAILABLE    = 5
	PROXY_FAILEDTOCONNECT = 6
	PROXY_HOSTNOTFOUND    = 7
	PROXY_CONNECTING      = 8
	PROXY_PAGENOTFOUND    = 9
	PROXY_DBERROR         = 10
)
View Source
const (
	RUN_MODE_FULL_RUN                    = 0
	RUN_MODE_CommunicationOnly           = 1
	RUN_MODE_EvaluationOnly              = 2
	RUN_MODE_Commissioning               = 3
	RUN_MODE_CommunicationsWithTransform = 4
	RUN_MODE_PrepareOnly                 = 5
	RUN_MODE_StartDisabledBySwitch       = 32
	RUN_MODE_InvalidImageVersion         = 33
	RUN_MODE_NoMemoryForImage            = 34
)
View Source
const (
	EVAL_STATE_Stopped                     = 0
	EVAL_STATE_RunningNormalTasks          = 1
	EVAL_STATE_StoppingExecution           = 2
	EVAL_STATE_RunningExceptionStateTask   = 3
	EVAL_STATE_ExceptionStateTaskFailed    = 4
	EVAL_STATE_NoExceptionStateTaskDefined = 5
	EVAL_STATE_Commissioning               = 6
	EVAL_STATE_InvalidImage                = 7
	EVAL_STATE_NoImage                     = 8
	EVAL_STATE_WaitingForDebugger          = 9
	EVAL_STATE_PreparedForStart            = 10
)
View Source
const (
	RTC_GET_UTC             = 0x01
	RTC_GET_LOCAL           = 0x02
	RTC_SET_UTC             = 0x10
	RTC_SET_LOCAL           = 0x11
	RTC_GET_TIMEZONE_OFFSET = 0x20
	RTC_GET_DAYLIGHT_OFFSET = 0x21
)

Variables

This section is empty.

Functions

func DiscoverPLCs

func DiscoverPLCs()

TODO: Not implemented

func FromDateTime

func FromDateTime(t uint64) time.Time

Converts 100ns timestamp from 01-01-0001 to time data type https://msdn.microsoft.com/en-us/library/system.datetime.ticks(v=vs.110).aspx

func ToDateTime

func ToDateTime(t time.Time) uint64

Converts time data type to 100ns timestamp from 01-01-0001 https://msdn.microsoft.com/en-us/library/system.datetime.ticks(v=vs.110).aspx

Types

type ChannelStatistics

type ChannelStatistics struct {
	StatisticsVersion uint8
	SentPackets       uint32
	RecvPackets       uint32
	WrongPackets      uint32
	SentBytes         uint32
	RecvBytes         uint32
	Endpoints         []Endpoint
}

type Endpoint

type Endpoint struct {
	AvarageCycleTime uint32
	MaximalCycleTime uint32
	MinimalCycleTime uint32
}

type FileInfo

type FileInfo struct {
	Size uint32
	Time time.Time
	CRC  uint16
}

type Frame

type Frame struct {
	Addr       uint8
	FunctionId uint16
	Payload    []byte
}

type LoginResponse

type LoginResponse struct {
	ProtoVersion uint8
	MaxDataSize  uint16
	RightGroup   uint8
	ImageGUID    [16]byte

	// Optional Fields
	DeviceName  *string
	SSCPAddress *uint8
	SSCPTCPPort *uint16
	SSCPSSLPort *uint16
}

type PLCConnection

type PLCConnection struct {
	// contains filtered or unexported fields
}

func NewPLCConnection

func NewPLCConnection(host string, addr uint8, reconnect bool) (*PLCConnection, error)

func NewPLCConnectionFrom

func NewPLCConnectionFrom(conn net.Conn, addr uint8, reconnect bool) PLCConnection

func (*PLCConnection) FinishDataSend

func (self *PLCConnection) FinishDataSend(crc uint16) error

This functionality defined on the section 5.6.1 of the specification

func (*PLCConnection) GetBasicInfo

func (self *PLCConnection) GetBasicInfo(_serialnumber string, _username string, _password string) (*PLCInfo, error)

This function simply gets basic information of the PLC. (This functionality defined on the section 5.4.1 of the specification)

func (*PLCConnection) GetChannelStatistics

func (self *PLCConnection) GetChannelStatistics(channelName string) (*ChannelStatistics, error)

This functionality defined on the section 5.7.3 of the specification

func (*PLCConnection) GetPLCStatistics

func (self *PLCConnection) GetPLCStatistics() (*PLCStatistics, error)

This functionality defined on the section 5.7.1 of the specification

func (*PLCConnection) GetTaskStatistics

func (self *PLCConnection) GetTaskStatistics(taskId uint8) (*TaskStatistics, error)

This functionality defined on the section 5.7.2 of the specification

func (*PLCConnection) InitiateDataReceive

func (self *PLCConnection) InitiateDataReceive(filename string) (*FileInfo, error)

This functionality defined on the section 5.6.2 of the specification

func (*PLCConnection) InitiateDataSend

func (self *PLCConnection) InitiateDataSend(filename string, size uint32, time time.Time) error

This functionality defined on the section 5.6.1 of the specification

func (*PLCConnection) Login

func (self *PLCConnection) Login(username string, password string, proxyId string, maxDataSize uint16) (*LoginResponse, error)

This functionality defined on the section 5.5.4 of the specification

func (*PLCConnection) Logout

func (self *PLCConnection) Logout() error

This functionality defined on the section 5.5.5 of the specification

func (*PLCConnection) ReadVariablesDirectly

func (self *PLCConnection) ReadVariablesDirectly(vars []*Variable, taskId *uint8) error

This functionality defined on the section 5.8.1.1 of the specification It simply takes a list of variables and mutates their values.

func (*PLCConnection) ReceiveDataChunk

func (self *PLCConnection) ReceiveDataChunk(offset uint32) (uint32, []byte, error)

This functionality defined on the section 5.6.2 of the specification

func (*PLCConnection) RecvFile

func (self *PLCConnection) RecvFile(filename string) ([]byte, error)

This function recieves a complete file.

func (*PLCConnection) SendDataChunk

func (self *PLCConnection) SendDataChunk(offset uint32, data []byte) error

This functionality defined on the section 5.6.1 of the specification

func (*PLCConnection) SendFile

func (self *PLCConnection) SendFile(filename string, content []byte) error

This function sends a complete file.

func (*PLCConnection) TimeSetup

func (self *PLCConnection) TimeSetup(t *time.Time) (*time.Time, error)

This functionality defined on the section 5.9.1 of the specification

func (*PLCConnection) TimeSetupExtended

func (self *PLCConnection) TimeSetupExtended(command byte, t *time.Time) (*time.Time, error)

func (*PLCConnection) WriteVariablesDirectly

func (self *PLCConnection) WriteVariablesDirectly(vars []*Variable) error

This functionality defined on the section 5.8.1.2 of the specification

type PLCInfo

type PLCInfo struct {
	SizeOfConfigBlock uint16
	SerialNumber      []byte
	Endianness        byte
	PlatformId        uint32
	RuntimeVersion    []byte
	Name              *string
	SlaveAddr         *uint8
	TCPPort           *uint16
	SSLTCPPort        *uint16
}

This type represents PLC Information

func (PLCInfo) GetPlatformString

func (self PLCInfo) GetPlatformString() string

type PLCStatistics

type PLCStatistics struct {
	StatisticsVersion  uint8
	BlockLength        uint16
	NormalTaskCount    uint8
	MaxTaskId          uint8
	EvaluatorState     uint8
	RunMode            uint8
	UpTime             uint64
	RunningTasks       uint64
	TasksWithException uint64
	TotalHeap          uint16
	FreeHeapBeforeLoad uint16
	FreeHeap           uint16
	TotalCodeSpace     uint16
	FreeCodeSpace      uint16
	RetainSize         uint16
	AllocatorTotalSize uint16
	AllocatorFreeSpace uint16
	VMEXSection        uint16
	RTCMSection        uint16
	OtherSections      uint16
	ClientStatus       uint8
	RecordsSaved       uint32
	LastSaveTime       uint64
	LastRequestTime    uint64
	ProxyStatus        uint8
	ProxyId            []byte
	SlotsTotal         uint8
	SlotsFree          uint8
}

type TaskStatistics

type TaskStatistics struct {
	StatisticsVersion    uint8
	CycleCount           uint64
	LastCycleDuration    uint64
	AvarageCycleDuration uint64
	MinimalCycleDuration uint64
	MaximalCycleDuration uint64
	WaitingForDebugger   bool
	DebuggerActualUID    uint32
	DebuggerActualOffset uint32
}

type Variable

type Variable struct {
	Uid    uint32
	Offset uint32
	Length uint32
	Value  []byte
}

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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