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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
rem DeviceNumber.bas
rem
rem last revision on 05 Feb 2003
rem

rem Application:
rem      macro includes a password protected
rem      EDIT_MACRO area where a device ID
rem      can be entered for this particular meter

REG &PASSWD_NUMBER_1 = &USER_MEMORY_8
REG &PASSWD_NUMBER_2 = &USER_MEMORY_9
REG &USER_PASSWD_1 = &USER_MEMORY_10
REG &USER_PASSWD_2 = &USER_MEMORY_11

// initialize USER_MEMORY
MEM &PASSWD_NUMBER_1 = -1
MEM &PASSWD_NUMBER_2 = 1
MEM &USER_PASSWD_1 = 0
MEM &USER_PASSWD_2 = 0

DIM OffOn[] = [ "  off", "   on" ]
DIM NoYes[] = [ "   no", "  yes" ]
DIM letters[] = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", \
                  "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", \
                  "Y", "Z", "-", "0", \
                  "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", "_", " " ]
CONST L_LENGTH = 40

// &chars[] is used to store the indeces of letters[]
REG &chars = &USER_MEMORY_100
CONST MAX_INDEX = 16

// _MUST_ initialize USER_MEMORY !!!
// values are used as offsets in meter memory (pointers) and
// might crash the whole application otherwise !!!
MEM &chars[] = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]

/////////////////////////////////////////////////////////
// reset macro
/////////////////////////////////////////////////////////
RESET_MACRO:
        // used to start/stop display of Device ID
        |view_number = false

        // to omit constantly getting into edit mode after exiting it
        // needed because PROG button is used for enter AND exit
        CONST PROG_TIMEOUT = 10 // * 0.1 sec
        &TIMER2 = 0

        // used in EDIT_MACRO
        #state = 0
        #answer = 0

        // VARIABLE1-5 get display format from DISPLAY_FORMAT_DEFAULT
        // VARIABLE6-10 can be formatted with CURRENT_DISPLAY_FORMAT
        // user defined variables are numbered on first occurence in macro code
        #index = 0  // actually stored in VARIABLE4
END

view_number:
        write "      Device ID --- "
        for #index = 0 to MAX_INDEX - 1
                append letters[&chars[#index]]
        next #index
        append "      "
return

/////////////////////////////////////////////////////////
// f1 button macro
/////////////////////////////////////////////////////////
F1_Button_Macro:
if |view_number = false then
        |view_number = true
else
        write ""
        |view_number = false
endif
END

/////////////////////////////////////////////////////////
// customer id macro
/////////////////////////////////////////////////////////
CUSTOMER_ID_MACRO:
        write "     DeviceNumber.bas      "
END

/////////////////////////////////////////////////////////
// main macro
/////////////////////////////////////////////////////////
MAIN_MACRO:

if &STATE = 0 AND |PROG_BUTTON = on then
        if &TIMER2 > PROG_TIMEOUT then
                gosub enter_edit
        endif
else
        // reset program button timer
        &TIMER2 = 0
endif

if |view_number = true then
        gosub view_number
endif
END

/////////////////////////////////////////////////////////
// edit macro
/////////////////////////////////////////////////////////

// states different from these will be handled in default
// as default refers to entering the Device ID
// only these known cases should be used
CONST STATE_PASSWD_1 = 1
CONST STATE_PASSWD_2 = 2
CONST STATE_CHANGE_PASSWORD = 3
CONST STATE_SET_PASSWORD_1 = 4
CONST STATE_SET_PASSWORD_2 = 5

// cases higher than STATE_SET_NUMBER will be
// used by default handling (Device ID)
CONST STATE_SET_NUMBER = 20

enter_edit:
        EDIT &USER_PASSWD_1
        &CURRENT_DISPLAY_FORMAT = 0
        &EDIT_MIN = -32768
        &EDIT_MAX = 32767
        &EDIT_DEF = 0
        &EDIT_VALUE = 0
        write "PWD 1 "
        &STATE = STATE_PASSWD_1
return

EDIT_MACRO:
// copy STATE for increment in default case
#state = &STATE

write ""
select #state
case STATE_PASSWD_1:
        EXIT_EDIT &USER_PASSWD_1
        EDIT &USER_PASSWD_2
        &CURRENT_DISPLAY_FORMAT = 0
        &EDIT_VALUE = &USER_PASSWD_1
        &EDIT_MIN = -32768
        &EDIT_MAX = 32767
        &EDIT_DEF = 0
        write "PWD 2 "
        &STATE = STATE_PASSWD_2

case STATE_PASSWD_2:
        EXIT_EDIT &USER_PASSWD_2
        if &USER_PASSWD_1 = &PASSWD_NUMBER_1 AND \
           &USER_PASSWD_2 = &PASSWD_NUMBER_2 then
                EDIT #answer
                EDIT_TEXT NoYes[]
                &EDIT_MIN = 0
                &EDIT_MAX = 1
                &EDIT_VALUE = 0
                write "Set_PW"
                &STATE = STATE_CHANGE_PASSWORD
        else
                &STATE = 0
                write "      wrong password      "
        endif

case STATE_CHANGE_PASSWORD:
        EXIT_EDIT #answer
        if #answer = 0 then
                gosub set_number
        else
                EDIT &USER_PASSWD_1
                &CURRENT_DISPLAY_FORMAT = 0
                &EDIT_MIN = -32768
                &EDIT_MAX = 32767
                &EDIT_DEF = &USER_PASSWD_1
                write "PWD_1"
                &STATE = STATE_SET_PASSWORD_1
        endif

case STATE_SET_PASSWORD_1:
        EXIT_EDIT &PASSWD_NUMBER_1
        EDIT &USER_PASSWD_2
        &CURRENT_DISPLAY_FORMAT = 0
        &EDIT_MIN = -32768
        &EDIT_MAX = 32767
        &EDIT_DEF = &USER_PASSWD_2
        write "PWD_2"
        &STATE = STATE_SET_PASSWORD_2

case STATE_SET_PASSWORD_2:
        EXIT_EDIT &PASSWD_NUMBER_2
        gosub set_number

case STATE_SET_NUMBER:
        EXIT_EDIT #answer
        if #answer = 1 then
                EDIT &chars[0]
                EDIT_TEXT letters[]
                &EDIT_MIN = 0
                &EDIT_MAX = L_LENGTH -1
                &EDIT_DEF = 0
                write "Char 1"
                &STATE = #state + 1
        else
                &STATE = 0
        endif

default:
        // relies on
        // &STATE >= STATE_SET_NUMBER+1 AND
        // &STATE <= STATE_SET_NUMBER + MAX_INDEX
        if #state < STATE_SET_NUMBER + MAX_INDEX then
                #index = #state - STATE_SET_NUMBER
                EXIT_EDIT &chars[#index - 1]
                EDIT &chars[#index]
                &DISPLAY_FORMAT_DEFAULT = 0
                EDIT_TEXT letters[]
                &EDIT_MIN = 0
                &EDIT_MAX = L_LENGTH -1
                &EDIT_DEF = 0

                // add offset
                //   #index = [0; MAX_INDEX-1]
                //   but we want 'Char 1'  to 'Char<MAX_INDEX>'
                #index = #index + 1

                if #index < 10 then
                        write "Char " + #index
                else
                        write "Char" + #index
                endif
                &STATE = #state + 1
        else
                EXIT_EDIT &chars[#state - STATE_SET_NUMBER - 1]
                &STATE = 0
        endif
endsel
END

///////////////////////////////////////
// edit macro subroutine
///////////////////////////////////////

set_number:
        #answer = 0
        EDIT #answer
        EDIT_TEXT NoYes[]
        &EDIT_MIN = 0
        &EDIT_MAX = 1
        write "SET_NR"
        &STATE = STATE_SET_NUMBER
return

Download DeviceNumber.bas
(7.2 KB , Aug. 26, 2008)