You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2020/11/19 09:17:14 UTC
[plc4x] branch feature/plc4go updated: - Made the PLC4Go work after
my changes in the protocol specs and PLC4J yesterday
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch feature/plc4go
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/feature/plc4go by this push:
new 11df07f - Made the PLC4Go work after my changes in the protocol specs and PLC4J yesterday
11df07f is described below
commit 11df07f0ca4040b6c10e5eb3ec9175706ba0b8a2
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Thu Nov 19 10:17:06 2020 +0100
- Made the PLC4Go work after my changes in the protocol specs and PLC4J yesterday
---
plc4go/internal/plc4go/model/values/DATE.go | 17 +++-
.../internal/plc4go/model/values/PlcBitString.go | 93 ++++++++++++++++++++++
plc4go/internal/plc4go/model/values/TIME_OF_DAY.go | 19 ++++-
3 files changed, 125 insertions(+), 4 deletions(-)
diff --git a/plc4go/internal/plc4go/model/values/DATE.go b/plc4go/internal/plc4go/model/values/DATE.go
index be64679..aa945f0 100644
--- a/plc4go/internal/plc4go/model/values/DATE.go
+++ b/plc4go/internal/plc4go/model/values/DATE.go
@@ -28,8 +28,21 @@ type PlcDATE struct {
PlcValueAdapter
}
-func NewPlcDATE(value time.Time) PlcDATE {
- safeValue := time.Date(value.Year(), value.Month(), value.Day(), 0, 0, 0, 0, value.Location())
+func NewPlcDATE(value interface{}) PlcDATE {
+ var timeValue time.Time
+ switch value.(type) {
+ case time.Time:
+ timeValue = value.(time.Time)
+ case uint16:
+ // In this case the date is the number of days since 1990-01-01
+ // So we gotta add 7305 days to the value to have it relative to epoch
+ // Then we also need to transform it from days to seconds by multiplying by 86400
+ timeValue = time.Unix((int64(value.(uint16)) + 7305) * 86400, 0)
+ case uint32:
+ // Interpreted as "seconds since epoch"
+ timeValue = time.Unix(int64(value.(uint32)), 0)
+ }
+ safeValue := time.Date(timeValue.Year(), timeValue.Month(), timeValue.Day(), 0, 0, 0, 0, timeValue.Location())
return PlcDATE{
value: safeValue,
}
diff --git a/plc4go/internal/plc4go/model/values/PlcBitString.go b/plc4go/internal/plc4go/model/values/PlcBitString.go
new file mode 100644
index 0000000..43ffba1
--- /dev/null
+++ b/plc4go/internal/plc4go/model/values/PlcBitString.go
@@ -0,0 +1,93 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+package values
+
+import (
+ "encoding/xml"
+ api "github.com/apache/plc4x/plc4go/pkg/plc4go/values"
+)
+
+type PlcBitString struct {
+ Values []api.PlcValue
+ PlcValueAdapter
+}
+
+func NewPlcBitString(value interface{}) PlcBitString {
+ var bools []api.PlcValue
+
+ switch value.(type) {
+ case uint8:
+ bools = make([]api.PlcValue, 8)
+ for i := 0; i < 8; i++ {
+ bools[0] = NewPlcBOOL(((value.(uint8) >> ((8 - 1) - i)) & 0x01) == 0x01)
+ }
+ case uint16:
+ bools = make([]api.PlcValue, 16)
+ for i := 0; i < 16; i++ {
+ bools[0] = NewPlcBOOL(((value.(uint16) >> ((16 - 1) - i)) & 0x01) == 0x01)
+ }
+ case uint32:
+ bools = make([]api.PlcValue, 32)
+ for i := 0; i < 32; i++ {
+ bools[0] = NewPlcBOOL(((value.(uint32) >> ((32 - 1) - i)) & 0x01) == 0x01)
+ }
+ case uint64:
+ bools = make([]api.PlcValue, 64)
+ for i := 0; i < 64; i++ {
+ bools[0] = NewPlcBOOL(((value.(uint64) >> ((64 - 1) - i)) & 0x01) == 0x01)
+ }
+ }
+
+ return PlcBitString{
+ Values: bools,
+ }
+}
+
+func (m PlcBitString) IsList() bool {
+ return true
+}
+
+func (m PlcBitString) GetLength() uint32 {
+ return uint32(len(m.Values))
+}
+
+func (m PlcBitString) GetIndex(i uint32) api.PlcValue {
+ return m.Values[i]
+}
+
+func (m PlcBitString) GetList() []api.PlcValue {
+ return m.Values
+}
+
+func (m PlcBitString) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
+ if err := e.EncodeToken(xml.StartElement{Name: xml.Name{Local: "PlcBitString"}}); err != nil {
+ return err
+ }
+
+ for _, value := range m.Values {
+ if err := e.EncodeElement(value, xml.StartElement{Name: xml.Name{Local: "-set-by-element-"}}); err != nil {
+ return err
+ }
+ }
+
+ if err := e.EncodeToken(xml.EndElement{Name: xml.Name{Local: "PlcBitString"}}); err != nil {
+ return err
+ }
+ return nil
+}
diff --git a/plc4go/internal/plc4go/model/values/TIME_OF_DAY.go b/plc4go/internal/plc4go/model/values/TIME_OF_DAY.go
index 90fddaa..3f6faae 100644
--- a/plc4go/internal/plc4go/model/values/TIME_OF_DAY.go
+++ b/plc4go/internal/plc4go/model/values/TIME_OF_DAY.go
@@ -28,8 +28,23 @@ type PlcTIME_OF_DAY struct {
PlcSimpleValueAdapter
}
-func NewPlcTIME_OF_DAY(value time.Time) PlcTIME_OF_DAY {
- safeValue := time.Date(0, 0, 0, value.Hour(), value.Minute(), value.Second(), value.Nanosecond(), value.Location())
+func NewPlcTIME_OF_DAY(value interface{}) PlcTIME_OF_DAY {
+ var safeValue time.Time
+ switch value.(type) {
+ case time.Time:
+ castedValue := value.(time.Time)
+ safeValue = time.Date(0, 0, 0, castedValue.Hour(), castedValue.Minute(), castedValue.Second(),
+ castedValue.Nanosecond(), castedValue.Location())
+ case uint32:
+ // Interpreted as milliseconds since midnight
+ castedValue := value.(uint32)
+ seconds := castedValue / 1000
+ nanoseconds := (castedValue % 1000) * 1000000
+ epochTime := time.Unix(int64(seconds), int64(nanoseconds))
+ safeValue = time.Date(0, 0, 0, epochTime.Hour(), epochTime.Minute(), epochTime.Second(),
+ epochTime.Nanosecond(), epochTime.Location())
+ }
+
return PlcTIME_OF_DAY{
value: safeValue,
}