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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# -*- coding: utf-8 -*-
#
# AWL simulator - IEC library - FC 12 "GE_DT"
#
# Copyright 2015 Christian Vitte <vitte.chris@gmail.com>
# Copyright 2015 Michael Buesch <m@bues.ch>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
from __future__ import division, absolute_import, print_function, unicode_literals
#from awlsim.common.cython_support cimport * #@cy
from awlsim.common.compat import *
from awlsim.library.libentry import *
class Lib__IEC__FC12_GE_DT(AwlLibFC):
libraryName = "IEC"
staticIndex = 12
symbolName = "GE_DT"
description = "Greater or equal DATE_AND_TIME"
interfaceFields = {
BlockInterfaceField.FTYPE_IN : (
BlockInterfaceField(name="DT1", dataType="DATE_AND_TIME"),
BlockInterfaceField(name="DT2", dataType="DATE_AND_TIME"),
),
BlockInterfaceField.FTYPE_OUT : (
BlockInterfaceField(name="RET_VAL", dataType="BOOL"),
),
BlockInterfaceField.FTYPE_TEMP : (
BlockInterfaceField(name="YEAR1", dataType="WORD"),
BlockInterfaceField(name="YEAR2", dataType="WORD"),
BlockInterfaceField(name="AR1_SAVE", dataType="DWORD"),
),
}
awlCodeCopyright = "Copyright (c) 2015 Christian Vitte <vitte.chris@gmail.com>\n"\
"Copyright (c) 2015 Michael Buesch <m@bues.ch>"
awlCodeLicense = "BSD-2-clause"
awlCodeIsStandard = True
awlCodeVersion = "0.1"
awlCode = """
TAR1 #AR1_SAVE // Save AR1 register
// Load a pointer to #DT1 into AR1 and open the DB
L P##DT1
LAR1
L W [AR1, P#0.0]
T #YEAR1 // DB number (abuse #YEAR1 temp field)
AUF DB [#YEAR1]
L D [AR1, P#2.0]
LAR1
// Load a pointer to #DT2 into AR2 and open the DB as DI
L P##DT2
LAR2
L W [AR2, P#0.0]
T #YEAR1 // DB number (abuse #YEAR1 temp field)
AUF DI [#YEAR1]
L D [AR2, P#2.0]
// If #DT2 points to DB (area 84) change it to DI (area 85).
// This also works, if #DT2 points to VL (area 87).
// Other areas are not possible.
OD DW#16#85000000
LAR2
//------------------------------------------------------
// Extract years from DT1 and DT2
L B [AR1, P#0.0]
T #YEAR1
L B [AR2, P#0.0]
T #YEAR2
// Check whether the year values from DT1 and DT2
// are valid BCD numbers.
L #YEAR1
UW W#16#000F
L W#16#0009
>I
SPB FAIL
L #YEAR1
UW W#16#00F0
L W#16#0090
>I
SPB FAIL
L #YEAR2
UW W#16#000F
L W#16#0009
>I
SPB FAIL
L #YEAR2
UW W#16#00F0
L W#16#0090
>I
SPB FAIL
//------------------------------------------------------
// Check whether specified year is 1990-1999 or 2000-2089
L B#16#89
L #YEAR1
>=I
SPB _2K1
// 1900 years correction (applicable for year 1990-1999)
OW W#16#1900
T #YEAR1
SPA Y2
// 2000 years correction (applicable for year 2000-2089)
_2K1: OW W#16#2000
T #YEAR1
// Check whether specified year is 1990-1999 or 2000-2089
Y2: L B#16#89
L #YEAR2
>=I
SPB _2K2
// 1900 years correction (applicable for year 1990-1999)
OW W#16#1900
T #YEAR2
SPA YRCK
// 2000 years correction (applicable for year 2000-2089)
_2K2: OW W#16#2000
T #YEAR2
//------------------------------------------------------
// Check if YEAR1 >= YEAR2.
// This check also works without BCD->INT conversion.
YRCK: L #YEAR1
L #YEAR2
<I
// year1 < year2 -> NOK
SPB NOK
// year1 > year2 -> OK
>I
SPB OK
//------------------------------------------------------
// Check if M:D:H DT1 >= M:D:H DT2 - Bytes 1 to 3
// Extract M:D:H from DT1 and DT2 (without year)
L D [AR1, P#0.0]
UD DW#16#00FFFFFF // Remove sign (and year)
L D [AR2, P#0.0]
UD DW#16#00FFFFFF // Remove sign (and year)
<D
// BCD-from-DT1 < BCD-from-DT2 -> NOK
// This check also works without BCD->INT conversion.
SPB NOK
>D
// BCD-from-DT1 > BCD-from-DT2 -> OK
SPB OK
//------------------------------------------------------
// Check if M:S:MS1 DT1 >= M:S:MS1 DT2 - Bytes 4 to 6
// Extract M:S:MS1 from DT1 and DT2
L D [AR1, P#3.0]
UD DW#16#00FFFFFF // Remove sign (and hour)
L D [AR2, P#3.0]
UD DW#16#00FFFFFF // Remove sign (and hour)
<D
// BCD-from-DT1 < BCD-from-DT2 -> NOK
// This check also works without BCD->INT conversion.
SPB NOK
>D
// BCD-from-DT1 > BCD-from-DT2 -> OK
SPB OK
//------------------------------------------------------
// Check if MS2:WD DT1 >= MS2:WD DT2 - Byte 7
// Extract MS2:WD from DT1 and DT2
L B [AR1, P#7.0]
L B [AR2, P#7.0]
<I
// BCD-from-DT1 < BCD-from-DT2 -> NOK
// This check also works without BCD->INT conversion.
SPB NOK
//------------------------------------------------------
// Everything is Ok.
// VKE is 1.
OK: = #RET_VAL // RET_VAL := 1
SAVE // BIE := 1
SPA END
// BCD failure. Set BIE := 0.
// Do not touch RET_VAL.
FAIL: CLR
SAVE // BIE := 0
SPA END
// BCD is Ok, but result is negative.
// VKE is 1.
NOK: SAVE // BIE := 1
CLR
= #RET_VAL // RET_VAL := 0
END: LAR1 #AR1_SAVE // Restore AR1 register
BE
"""
AwlLib.registerEntry(Lib__IEC__FC12_GE_DT)
|