/
trainOrder.go
62 lines (54 loc) · 1.88 KB
/
trainOrder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package darwind3
import (
"encoding/xml"
"github.com/peter-mount/nre-feeds/util"
"time"
)
// Defines the expected Train order at a platform
type TrainOrder struct {
Order int `json:"order" xml:"order,attr"`
// The platform number where the train order applies
Platform string `json:"plat,omitempty" xml:"plat,attr,omitempty"`
// This is the TS time from Darwin so we keep a copy of when this struct
// was sent to us
Date time.Time `json:"date,omitempty"`
}
// The trainOrder as received from darwin
type trainOrderWrapper struct {
// The tiploc where the train order applies
Tiploc string `xml:"tiploc,attr"`
// The CRS code of the station where the train order applies
CRS string `xml:"crs,attr"`
// The platform number where the train order applies
Platform string `xml:"platform,attr"`
// The Train orders to set
Set *trainOrderData `xml:"set"`
// Clear the current train order
Clear bool `xml:"clear"`
}
// Defines the sequence of trains making up the train order
type trainOrderData struct {
// The first train in the train order.
First *trainOrderItem `xml:"first"`
// The second train in the train order.
Second *trainOrderItem `xml:"second"`
// The third train in the train order.
Third *trainOrderItem `xml:"third"`
}
// Describes the identifier of a train in the train order
type trainOrderItem struct {
// For trains in the train order where the train is the Darwin timetable,
// it will be identified by its RID
RID TrainOrderRID `xml:"rid"`
// Where a train in the train order is not in the Darwin timetable,
// a Train ID (headcode) will be supplied
TrainId string `xml:"trainID"`
}
type TrainOrderRID struct {
RID string `json:"rid"`
Times util.CircularTimes `json:"times"`
}
func (t *TrainOrderRID) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error {
t.Times.UnmarshalXMLAttributes(start)
return decoder.DecodeElement(&t.RID, &start)
}