Skip to content

Commit

Permalink
fix library version
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkgos committed Jul 14, 2019
1 parent 6902f7d commit 4e59ca2
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 16 deletions.
114 changes: 105 additions & 9 deletions asdu/cproc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package asdu

import (
"encoding/binary"
"math"
"time"
)
Expand Down Expand Up @@ -134,7 +135,7 @@ func StepCmd(c Connect, typeID TypeID, coa CauseOfTransmission, ca CommonAddr,
type SetpointCommandNormalObject struct {
Ioa InfoObjAddr
Value Normalize
Qoc QualifierOfSetpointCmd
Qos QualifierOfSetpointCmd
Time time.Time
}

Expand All @@ -160,7 +161,7 @@ func SetpointCmdNormal(c Connect, typeID TypeID, coa CauseOfTransmission, ca Com
return err
}

u.infoObj = append(u.infoObj, byte(cmd.Value), byte(cmd.Value>>8), cmd.Qoc.Value())
u.infoObj = append(u.infoObj, byte(cmd.Value), byte(cmd.Value>>8), cmd.Qos.Value())
switch typeID {
case C_SE_NA_1:
case C_SE_TA_1:
Expand All @@ -174,7 +175,7 @@ func SetpointCmdNormal(c Connect, typeID TypeID, coa CauseOfTransmission, ca Com
type SetpointCommandScaledObject struct {
Ioa InfoObjAddr
Value int16
Qoc QualifierOfSetpointCmd
Qos QualifierOfSetpointCmd
Time time.Time
}

Expand All @@ -200,7 +201,7 @@ func SetpointCmdScaled(c Connect, typeID TypeID, coa CauseOfTransmission, ca Com
return err
}

u.infoObj = append(u.infoObj, byte(cmd.Value), byte(cmd.Value>>8), cmd.Qoc.Value())
u.infoObj = append(u.infoObj, byte(cmd.Value), byte(cmd.Value>>8), cmd.Qos.Value())
switch typeID {
case C_SE_NB_1:
case C_SE_TB_1:
Expand Down Expand Up @@ -348,29 +349,124 @@ func (this *ASDU) GetDoubleCmd() (DoubleCommandObject, error) {

func (this *ASDU) GetStepCmd() (StepCommandObject, error) {
var cmd StepCommandObject
// TODO:
var err error

if cmd.Ioa, err = this.ParseInfoObjAddr(this.infoObj); err != nil {
return cmd, err
}
value := this.infoObj[this.InfoObjAddrSize]
cmd.Value = StepCommand(value & 0x03)
cmd.Qoc = ParseQualifierOfCommand(value & 0xfc)

switch this.Type {
case C_RC_NA_1:
case C_RC_TA_1:
cmd.Time, err = ParseCP56Time2a(this.infoObj[this.InfoObjAddrSize+1:], this.InfoObjTimeZone)
if err != nil {
return cmd, ErrInvalidTimeTag
}
default:
return cmd, ErrTypeIDNotMatch
}

return cmd, nil
}

func (this *ASDU) GetSetpointNormalCmd() (SetpointCommandNormalObject, error) {
var cmd SetpointCommandNormalObject
// TODO:
var err error

if cmd.Ioa, err = this.ParseInfoObjAddr(this.infoObj); err != nil {
return cmd, err
}

cmd.Value = Normalize(binary.LittleEndian.Uint16(this.infoObj[this.InfoObjAddrSize:]))
cmd.Qos = ParseQualifierOfSetpointCmd(this.infoObj[this.InfoObjAddrSize+2])

switch this.Type {
case C_SE_NA_1:
case C_SE_TA_1:
cmd.Time, err = ParseCP56Time2a(this.infoObj[this.InfoObjAddrSize+3:], this.InfoObjTimeZone)
if err != nil {
return cmd, ErrInvalidTimeTag
}
default:
return cmd, ErrTypeIDNotMatch
}

return cmd, nil
}

func (this *ASDU) GetSetpointCmdScaled() (SetpointCommandScaledObject, error) {
var cmd SetpointCommandScaledObject
// TODO:
var err error

if cmd.Ioa, err = this.ParseInfoObjAddr(this.infoObj); err != nil {
return cmd, err
}

cmd.Value = int16(binary.LittleEndian.Uint16(this.infoObj[this.InfoObjAddrSize:]))
cmd.Qos = ParseQualifierOfSetpointCmd(this.infoObj[this.InfoObjAddrSize+2])

switch this.Type {
case C_SE_NB_1:
case C_SE_TB_1:
cmd.Time, err = ParseCP56Time2a(this.infoObj[this.InfoObjAddrSize+3:], this.InfoObjTimeZone)
if err != nil {
return cmd, ErrInvalidTimeTag
}
default:
return cmd, ErrTypeIDNotMatch
}

return cmd, nil
}
func (this *ASDU) GetSetpointFloatCmd() (SetpointCommandFloatObject, error) {
var cmd SetpointCommandFloatObject
// TODO:
var err error

if cmd.Ioa, err = this.ParseInfoObjAddr(this.infoObj); err != nil {
return cmd, err
}
bits := binary.LittleEndian.Uint32(this.infoObj[this.InfoObjAddrSize:])
cmd.Value = math.Float32frombits(bits)
cmd.Qos = ParseQualifierOfSetpointCmd(this.infoObj[this.InfoObjAddrSize+4])

switch this.Type {
case C_SE_NC_1:
case C_SE_TC_1:
cmd.Time, err = ParseCP56Time2a(this.infoObj[this.InfoObjAddrSize+5:], this.InfoObjTimeZone)
if err != nil {
return cmd, ErrInvalidTimeTag
}
default:
return cmd, ErrTypeIDNotMatch
}

return cmd, nil
}

func (this *ASDU) GetBitsString32Cmd() (BitsString32CommandObject, error) {
var cmd BitsString32CommandObject
// TODO:
var err error

if cmd.Ioa, err = this.ParseInfoObjAddr(this.infoObj); err != nil {
return cmd, err
}

cmd.Value = binary.LittleEndian.Uint32(this.infoObj[this.InfoObjAddrSize:])
cmd.Qos = ParseQualifierOfSetpointCmd(this.infoObj[this.InfoObjAddrSize+4])

switch this.Type {
case C_SC_NA_1:
case C_SC_TA_1:
cmd.Time, err = ParseCP56Time2a(this.infoObj[this.InfoObjAddrSize+5:], this.InfoObjTimeZone)
if err != nil {
return cmd, ErrInvalidTimeTag
}
default:
return cmd, ErrTypeIDNotMatch
}

return cmd, nil
}
1 change: 1 addition & 0 deletions asdu/msys.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func EndOfInitialization(c Connect, coa CauseOfTransmission, ca CommonAddr,
return c.Send(u)
}

// GetEndOfInitialization get GetEndOfInitialization for asud when the identification M_EI_NA_1
func (this *ASDU) GetEndOfInitialization() (InfoObjAddr, CauseOfInitial, error) {
var ioa InfoObjAddr
var coi CauseOfInitial
Expand Down
12 changes: 6 additions & 6 deletions cs104/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ func NewServer(conf *Config, conn net.Conn) (*Server, error) {

// RecvLoop feeds t.recv.
func (t *Server) recvLoop() {
t.Informational("cs104 server: recvLoop start!")
t.Info("cs104 server: recvLoop start!")
// 临时错误恢复,过长和过短不适合,这个需要再调试
retryTicker := time.NewTicker(200 * time.Millisecond)

defer func() {
close(t.recv)
retryTicker.Stop()
t.cancelFunc()
t.Informational("cs104 server: recvLoop stop!")
t.Info("cs104 server: recvLoop stop!")
}()

var deadline time.Time
Expand Down Expand Up @@ -155,10 +155,10 @@ func (t *Server) recvLoop() {

// SendLoop drains t.send.
func (t *Server) sendLoop() {
t.Informational("cs104 server: sendLoop start!")
t.Info("cs104 server: sendLoop start!")
defer func() {
t.cancelFunc()
t.Informational("cs104 server server: sendLoop stop!")
t.Info("cs104 server server: sendLoop stop!")
}()

for apdu := range t.send {
Expand All @@ -184,7 +184,7 @@ func (t *Server) sendLoop() {

// Run is the big fat state machine.
func (this *Server) run() {
this.Informational("cs104 server: run start!")
this.Info("cs104 server: run start!")
// when connected establish and not enable "data transfer" yet
// defualt: STOPDT
isActive := false
Expand Down Expand Up @@ -217,7 +217,7 @@ func (this *Server) run() {
}

close(this.In)
this.Informational("cs104 server: run stop!")
this.Info("cs104 server: run stop!")
}()

// transmission timestamps for timeout calculation
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/thinkgos/go-iecp5

go 1.12

require github.com/thinkgos/library v0.0.1
require github.com/thinkgos/library v0.1.0

0 comments on commit 4e59ca2

Please sign in to comment.