initial commit lets start

This commit is contained in:
Adrian Zuercher
2026-08-28 17:59:35 +02:00
commit 3ba5a189f3
48 changed files with 100075 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
package models
import (
"encoding/xml"
"fmt"
"schema"
)
type Task struct {
XMLName xml.Name `xml:"task"`
Name string `xml:"name,attr"`
Interval string `xml:"interval,attr"`
Priority int `xml:"priority,attr"`
PouInstance []*PouInstance `xml:"pouInstance"`
AddData *AddData `xml:"addData"`
}
func (t *Task) AddAddData(kindOfTask, intervalUnit string, interval int) error {
if t.AddData != nil {
return nil
}
t.AddData = NewAddData()
_, err := t.AddData.AddTasksettings(URL_PLCOPENXML, HANDLE_IMPLEMENTATION, kindOfTask, intervalUnit, interval)
if err != nil {
return err
}
return nil
}
// convert interval to plcopenxml format in value in milliseconds
func (t *Task) SetInterval(interval int) {
//convert to secconts
i := interval / 1000
if i < 1 {
i = 0
}
t.Interval = fmt.Sprintf("PT%dS", i)
}
func (t *Task) AddPouInstances(task *schema.Task) {
for _, prg := range task.Programs {
t.AddPouInstance(prg.Name, prg.TypeName)
}
}
func (t *Task) AddPouInstance(name, typeName string) *PouInstance {
pI := &PouInstance{
Name: name,
TypeName: typeName,
Documentation: &Documentation{
Xhtml: Xhtml{
Xmlns: XMLNS,
},
},
}
t.PouInstance = append(t.PouInstance, pI)
return pI
}