Skip to content

Commit

Permalink
fix(plc4go/spi): Fixed issues in the "Serialize" function of PLCValue…
Browse files Browse the repository at this point in the history
…s and implemented the "GetRaw" for each of them.
  • Loading branch information
chrisdutz committed May 2, 2022
1 parent 82cbcfe commit d191a8e
Show file tree
Hide file tree
Showing 30 changed files with 176 additions and 7 deletions.
4 changes: 4 additions & 0 deletions plc4go/internal/plc4go/spi/values/BINT.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func NewPlcBINT(value *big.Int) PlcBINT {
}
}

func (m PlcBINT) GetRaw() []byte {
return m.value.Bytes()
}

func (m PlcBINT) GetBoolean() bool {
if m.isZero() {
return false
Expand Down
7 changes: 7 additions & 0 deletions plc4go/internal/plc4go/spi/values/BOOL.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ func NewPlcBOOL(value bool) PlcBOOL {
}
}

func (m PlcBOOL) GetRaw() []byte {
if m.value {
return []byte{0x01}
}
return []byte{0x00}
}

func (m PlcBOOL) IsBool() bool {
return true
}
Expand Down
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/BREAL.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ func NewPlcBREAL(value *big.Float) PlcBREAL {
}
}

func (m PlcBREAL) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcBREAL) GetBoolean() bool {
if m.isZero() {
return false
Expand Down
4 changes: 4 additions & 0 deletions plc4go/internal/plc4go/spi/values/BYTE.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func NewPlcBYTE(value byte) PlcBYTE {
}
}

func (m PlcBYTE) GetRaw() []byte {
return []byte{m.value}
}

func (m PlcBYTE) IsBool() bool {
return true
}
Expand Down
5 changes: 5 additions & 0 deletions plc4go/internal/plc4go/spi/values/CHAR.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
)

type PlcCHAR struct {
// TODO: Why is this a byte-array?
value []byte
PlcSimpleValueAdapter
}
Expand All @@ -34,6 +35,10 @@ func NewPlcCHAR(value uint8) PlcCHAR {
}
}

func (m PlcCHAR) GetRaw() []byte {
return m.value
}

func (m PlcCHAR) IsString() bool {
return true
}
Expand Down
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/DATE.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ func NewPlcDATE(value interface{}) PlcDATE {
}
}

func (m PlcDATE) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcDATE) IsDate() bool {
return true
}
Expand Down
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/DATE_AND_TIME.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func NewPlcDATE_AND_TIME(value time.Time) PlcDATE_AND_TIME {
}
}

func (m PlcDATE_AND_TIME) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcDATE_AND_TIME) IsDateTime() bool {
return true
}
Expand Down
8 changes: 7 additions & 1 deletion plc4go/internal/plc4go/spi/values/DINT.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func NewPlcDINT(value int32) PlcDINT {
}
}

func (m PlcDINT) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcDINT) GetBoolean() bool {
if m.value == 0 {
return false
Expand Down Expand Up @@ -132,5 +138,5 @@ func (m PlcDINT) GetString() string {
}

func (m PlcDINT) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteInt32("PlcDINT", 64, m.value)
return writeBuffer.WriteInt32("PlcDINT", 32, m.value)
}
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/DWORD.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func NewPlcDWORD(value uint32) PlcDWORD {
}
}

func (m PlcDWORD) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcDWORD) IsBool() bool {
return true
}
Expand Down
8 changes: 7 additions & 1 deletion plc4go/internal/plc4go/spi/values/INT.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func NewPlcINT(value int16) PlcINT {
}
}

func (m PlcINT) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcINT) GetBoolean() bool {
if m.value == 0 {
return false
Expand Down Expand Up @@ -125,5 +131,5 @@ func (m PlcINT) GetString() string {
}

func (m PlcINT) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteInt16("PlcINT", 32, m.value)
return writeBuffer.WriteInt16("PlcINT", 16, m.value)
}
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/LINT.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func NewPlcLINT(value int64) PlcLINT {
}
}

func (m PlcLINT) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcLINT) GetBoolean() bool {
if m.value == 0 {
return false
Expand Down
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/LREAL.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func NewPlcLREAL(value float64) PlcLREAL {
}
}

func (m PlcLREAL) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcLREAL) GetBoolean() bool {
if m.value == 0.0 {
return false
Expand Down
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/LTIME.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func NewPlcLTIME(value uint64) PlcLTIME {
}
}

func (m PlcLTIME) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcLTIME) IsDuration() bool {
return true
}
Expand Down
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/LWORD.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func NewPlcLWORD(value uint64) PlcLWORD {
}
}

func (m PlcLWORD) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcLWORD) IsBool() bool {
return true
}
Expand Down
4 changes: 4 additions & 0 deletions plc4go/internal/plc4go/spi/values/NULL.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ type PlcNULL struct {
func NewPlcNULL() PlcNULL {
return PlcNULL{}
}

func (m PlcNULL) GetRaw() []byte {
return []byte{}
}
7 changes: 7 additions & 0 deletions plc4go/internal/plc4go/spi/values/PlcBitString.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package values

import (
"github.com/apache/plc4x/plc4go/internal/plc4go/spi/utils"
api "github.com/apache/plc4x/plc4go/pkg/plc4go/values"
)

Expand Down Expand Up @@ -57,6 +58,12 @@ func NewPlcBitString(value interface{}) PlcBitString {
}
}

func (m PlcBitString) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcBitString) IsList() bool {
return true
}
Expand Down
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/PlcList.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func NewPlcList(values []values.PlcValue) values.PlcValue {
}
}

func (m PlcList) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcList) IsList() bool {
return true
}
Expand Down
8 changes: 7 additions & 1 deletion plc4go/internal/plc4go/spi/values/REAL.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func NewPlcREAL(value float32) PlcREAL {
}
}

func (m PlcREAL) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcREAL) GetBoolean() bool {
if m.value == 0.0 {
return false
Expand Down Expand Up @@ -149,5 +155,5 @@ func (m PlcREAL) GetString() string {
}

func (m PlcREAL) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteFloat32("PlcREAL", 31, m.value)
return writeBuffer.WriteFloat32("PlcREAL", 32, m.value)
}
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/SINT.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func NewPlcSINT(value int8) PlcSINT {
}
}

func (m PlcSINT) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcSINT) GetBoolean() bool {
if m.value == 0 {
return false
Expand Down
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/STRING.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func NewPlcSTRING(value string) PlcSTRING {
}
}

func (m PlcSTRING) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcSTRING) IsString() bool {
return true
}
Expand Down
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/TIME.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func NewPlcTIME(value uint32) PlcTIME {
}
}

func (m PlcTIME) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcTIME) IsDuration() bool {
return true
}
Expand Down
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/TIME_OF_DAY.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ func NewPlcTIME_OF_DAY(value interface{}) PlcTIME_OF_DAY {
}
}

func (m PlcTIME_OF_DAY) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcTIME_OF_DAY) IsTime() bool {
return true
}
Expand Down
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/UDINT.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func NewPlcUDINT(value uint32) PlcUDINT {
}
}

func (m PlcUDINT) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcUDINT) GetBoolean() bool {
if m.value == 0 {
return false
Expand Down
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/UINT.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func NewPlcUINT(value uint16) PlcUINT {
}
}

func (m PlcUINT) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcUINT) GetBoolean() bool {
if m.value == 0 {
return false
Expand Down
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/ULINT.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func NewPlcULINT(value uint64) PlcULINT {
}
}

func (m PlcULINT) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcULINT) GetBoolean() bool {
if m.value == 0 {
return false
Expand Down
8 changes: 7 additions & 1 deletion plc4go/internal/plc4go/spi/values/USINT.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func NewPlcUSINT(value uint8) PlcUSINT {
}
}

func (m PlcUSINT) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcUSINT) GetBoolean() bool {
if m.value == 0 {
return false
Expand Down Expand Up @@ -97,5 +103,5 @@ func (m PlcUSINT) GetString() string {
}

func (m PlcUSINT) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteUint8("PlcUSINT", 64, m.value)
return writeBuffer.WriteUint8("PlcUSINT", 8, m.value)
}
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/WCHAR.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func NewPlcWCHAR(value uint16) PlcWCHAR {
}
}

func (m PlcWCHAR) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcWCHAR) IsString() bool {
return true
}
Expand Down
6 changes: 6 additions & 0 deletions plc4go/internal/plc4go/spi/values/WORD.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func NewPlcWORD(value uint16) PlcWORD {
}
}

func (m PlcWORD) GetRaw() []byte {
buf := utils.NewWriteBufferByteBased()
m.Serialize(buf)
return buf.GetBytes()
}

func (m PlcWORD) IsBool() bool {
return true
}
Expand Down
Loading

0 comments on commit d191a8e

Please sign in to comment.