-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevice.tbh
431 lines (388 loc) · 17.7 KB
/
device.tbh
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
#define BEEP_DIVIDER 21600
'------------------------------------------------------------------------------
#if PLATFORM_ID=TPP2W or PLATFORM_ID=TPP3W
const NUM_HTTP_SOCKETS=3
const SOCK_HTTP_TXBUFF_SIZE=4
#else
const NUM_HTTP_SOCKETS=5
const SOCK_HTTP_TXBUFF_SIZE=10
#endif
const HTML_CONFIRM_LOG_OFF = "Would you like to log out?"
const HTML_CONFIRM_INITIALIZE = "Would you like to initialize the device? \\nSome of the settings will only be effective after reboot!"
const HTML_CONFIRM_REBOOT = "Would you like to reboot the device? \\nIP address of the device might change after reboot!"
const HTML_REBOOT_REQUIRED = "The changes you made might only take effects after device reboot. \\n Would you like to reboot the device now?"
const HTML_LOWER_PRIO_INPROC = "Another session with lower priority is in progress. Proceed and interupt the low-priority session?"
const HTML_LOGGED_OUT = "<b>Logged out.</b>"
const HTML_INVALID_LOGIN = "<b>Invalid password. Please try again.</b>"
const HTML_INVALID_SESSION = "<b>Invalid session ID, or other user is currently logged in, please log in again.</b>"
const HTML_NO_PRIORITY = "<b>Another user is currently logged in from a client with higher priority.</b>"
const HTML_NOT_LOGGED_IN = "<b>You are not logged in. This could be because your login session has expired OR because another session with higher priority has started</b>"
const BUTTON_CONST_QUICK_INIT=5 'in 0.5 intervals -- how long you need to press button for quick init
const AGG_PORT_FALLBACK_MAX=2
'------------------------------------------------------------------------------
const PAT_GAP= "-**" 'a special empty pattern used to cause on_pat event
const PAT_BOTH_LOOP= "B~" 'boot in progress
const PAT_BLINK_BOTH_TOGETHER_FAST= "B-B-B-B-**~" 'boot failed
const PAT_THREE_BOTH= "---------B-B-B--" 'boot completed
const PAT_BOTH_OFF= "-" 'starting setting initialization
const PAT_LONG_GREEN= "GGGGGGGG-" 'settings initialized successfully
const PAT_LONG_RED= "RRRRRRRR-" 'settings failed to initialize
const PAT_TWO_SHORT_RED= "-----RRRRRR--R-R~" 'network interface error
const PAT_BLINK_RED_SLOW= "--RR" 'setting error (error_mode)
const PAT_ONE_SHORT_GREEN= "---------------G~" 'IP not configured (configuration in progress)
const PAT_TWO_SHORT_GREEN= "-------------G-G~" 'AggreGate connection idle
const PAT_THREE_SHORT_GREEN= "-----------G-G-G~" 'opening TCP link to AggreGate server
const PAT_BLINK_GREEN= "-G~" 'synching with AggreGate
const PAT_GREEN_ON= "G~" 'AggreGate link configured, sync completed
const PAT_THREE_SHORT_RED= "-----------R-R-R~" 'AggreGate link failed
const PAT_BLINK_BOTH_IN_TURNS= "RG~" 'Html login
const BEEP_SHORT= "BB" 'OK of some kind
const BEEP_LONG= "BBBBBB" 'ERROR of some kind
const BEEP_VERY_SHORT="-B**"
'----------------------------------------------------------------------------
#if SUPPORTS_DISPLAY
const BG_BLUE=41736
const BG_GREEN=17704
const BG_RED=31
const TXT_GRAY=46486
const SETTING_VAL_X=MENU_X
const SETTING_VAL_Y=MENU_H+MENU_Y-7
const SETTING_VAL_W=MENU_W
const SETTING_VAL_H=23
const KEY_F1=0
const KEY_F2=1
const KEY_F3=2
const KEY_F4=3
const EXIT_MENU = "Device will exit the programming mode now.`Continue?"
const INVALID_INPUT = "INTERNAL ERROR (invalid input type)"
const EMPTY_FOLDER = "This folder is empty"
const SYS_ERROR_REBOOT = "INTERNAL ERROR. Device will now reboot."
const COMMAND_SETTING_FAILURE="FATAL SYSTEM FAILURE:`Setting error.`The system is not function properly. Device initialization may help."
const SYS_SETTING_VALUE_INVALID="Setting value is invalid."
const SYS_CALCULATE_WPA_KEY="The device is calculating the Wi-Fi security key. This is done in WPA-PSK and WPA2-PSK modes after the change of the access point name or password."
const ICON_FILE = "icon.bmp"
enum en_mb_keys
MBK_COMMAND_CONFIRM,
MBK_COMMAND_CANCEL,
MBK_YES,
MBK_NO,
MBK_OK,
MBK_F1,
MBK_F2,
MBK_F4
end enum
enum en_ib_mode
INPUT_BOX_ALPH_LOWER,
INPUT_BOX_ALPH_UPPER,
INPUT_BOX_NUMERIC
end enum
#endif
enum en_param_we
WE_DISABLED,
WE_ENABLED_ONDEMAND,
WE_ENABLED_PERMANENT
end enum
enum en_param_ge
GE_DISABLED,
GE_ENABLED_ONDEMAND,
GE_ENABLED_PERMANENT
end enum
enum en_http_buff_allocate
HTTP_BUFF_ALLOCATE,
HTTP_BUFF_DISALLOCATE
end enum
enum bb_modes
BB_7,
BB_8
end enum
enum br_modes
BR_1200,
BR_2400,
BR_4800,
BR_9600,
BR_19200,
BR_38400,
BR_57600,
BR_115200,
BR_150,
BR_300,
BR_600,
BR_28800,
BR_230400,
BR_460800
end enum
enum pr_modes
PR_NONE,
PR_EVEN,
PR_ODD,
PR_MARK,
PR_SPACE
end enum
enum fc_modes
FC_DIS,
FC_RTSCTS,
FC_XONXOFF
end enum
enum en_device_rdwr
DEVICE_GET,
DEVICE_SET
end enum
enum en_network_states
NETWORK_INIT,
NETWORK_WLN_DISABLED,
NETWORK_WLN_JOINING,
NETWORK_WLN_JOINED,
NETWORK_WLN_FATAL_ERROR,
NETWORK_WLN_INVALID_WKEY,
NETWORK_WLN_SCANNING_FAIL,
NETWORK_WLN_ASSOCIATION_FAIL,
NETWORK_WLN_DISASSOCIATE,
NETWORK_DHCP_FIXED_IP,
NETWORK_DHCP_OBTAINING_IP,
NETWORK_DHCP_FAIL_OBTAINING_IP,
NETWORK_DHCP_IP_OBTAINED,
NETWORK_REPRINT_PREVIOUS_STATE 'this is not a state, it instructs device_print_network_info() to print previous state
end enum
type io_type
io_enabled as no_yes
io_output as no_yes
io_prev_state as low_high
io_prev_enabled as no_yes
io_state as low_high
end type
enum en_slot_type
SLOT_EMPTY,
SLOT_SERIAL_01,
SLOT_SERIAL_02,
SLOT_SERIAL_05,
SLOT_IOD_4,
SLOT_IOD_3,
SLOT_IOD_2,
SLOT_ID_4,
SLOT_ID_3,
SLOT_ID_2,
SLOT_OD_4,
SLOT_OD_2,
SLOT_OD_1,
SLOT_IA_4,
SLOT_IA_RTD,
SLOT_IA_52,
SLOT_IA_53,
SLOT_OA_4,
SLOT_OA_3,
SLOT_DP,
SLOT_OW,
SLOT_8BIT,
SLOT_IA_4_32,
SLOT_43_1,
SLOT_43_2,
SLOT_44_1,
SLOT_44_2
end enum
#if SUPPORTS_DISPLAY
declare lan_network_state as en_network_states
declare agg_cmd_received as no_yes
declare sub print_wifi()
#endif
'---------------------------------------------------------------------------------------------------
#if WLN_AVAILABLE
const WLN_RESCAN_TMR_CTR=120 'when have TCP connection
const WLN_RESCAN_TMR_CTR2=240 'when no TCP connecion
const RSSI_UPDATE_TIMER_CTR=10
const WLN_RSSI_1=170
const WLN_RSSI_2=175
const WLN_RSSI_3=180
const WLN_RSSI_4=190
declare wln_want_to_change_ap as no_yes
declare wln_rescanning as no_yes
declare rssi_update_timer as byte
declare wln_dev_rescan_tmr as byte
declare sub device_check_for_better_ap()
declare sub device_update_rssi()
#if SUPPORTS_DISPLAY
declare wln_network_state as en_network_states
#endif
#endif
type agg_events
agg_eventAnalog as boolean
agg_eventDigital as boolean
agg_eventCounter as boolean
agg_eventBP as boolean
end type
'------------------------------------------------------------------------------
declare led_pat_to_play,led_pat_to_play_prev as string(18)
declare reboot_timer as byte
declare agg_retry_counter as byte
declare param_st(NUM_OF_SLOTS) as en_slot_type
declare param_io(NUM_OF_IO) as io_type
declare param_sp(4) as byte
declare param_se(4) as byte
declare param_fc(4) as byte
declare param_br(4) as byte
declare param_pr(4) as byte
declare param_bb(4) as byte
declare param_bp(4) as boolean
declare param_te as byte
declare last_sntp_date as word
declare s_sock as byte
declare param_aggEvents as agg_events
'------------------------------------------------------------------------------
declare sub boot()
declare function proc_device_op(byref param1 as string, byref param2 as string) as string(1)
declare sub device_setting_set(sname as string(STG_MAX_SETTING_NAME_LEN), index as byte, byref s as string)
declare function device_setting_check(byref setting_name as string,byref setting_val as string) as ok_ng
declare function validate_ip(byref ip as string) as string
declare function http_buff_rq(op as en_http_buff_allocate) as ok_ng
declare sub device_process_esc_seq(byref s as string)
declare function device_setting_init(init_mode as en_stg_init_modes) as ok_ng
declare sub ethernet_link_state_change(new_state as pl_net_linkstate)
declare sub close_interface_sockets(interface as pl_sock_interfaces)
declare sub change_current_interface(new_interface as pl_sock_interfaces)
declare sub html_pre_login()
declare function index_to_io_num(index as byte) as pl_io_num
declare function io_num_to_index(io_num as pl_io_num) as byte
declare sub set_net_ip(interface as pl_sock_interfaces)
declare function device_settings_sg(setting_name as string(5),index as byte, byref setting_val as string, byref stg_num as byte, rw as en_device_rdwr) as en_stg_status_codes
#if SIGNAL_STRENGTH_INDICATION=1
declare sub signal_strength_indication_init()
declare sub signal_strength_set(strength as byte)
#endif
#if DEV_DEBUG_PRINT
declare sub dev_debugprint(byref print_data as string)
#endif
#if SUPPORTS_DISPLAY
enum enum_lcd_pages
LCD_PAGE_NET
LCD_PAGE_WLN
LCD_PAGE_CH1
LCD_PAGE_CH2
LCD_PAGE_CH3
LCD_PAGE_CH4
LCD_PAGE_SER_PROG_MODE
LCD_PAGE_ERROR
LCD_PAGE_LOGO
LCD_PAGE_LOGO_WORK
LCD_PAGE_INIT_START
LCD_PAGE_INIT_DONE
LCD_ADVANCE_PAGE 'this is not a state
end enum
enum enum_lcd_print_modes
LCD_PRINT_MODE_GENTLE 'do not print if display is OFF, do not print if we are on a different page
LCD_PRINT_MODE_STANDARD 'do not print if we are on a different page
LCD_PRINT_MODE_AGGRESSIVE 'print under any contitions
end enum
enum enum_lcd_print_elements
LCD_PRINT_ELEMENT_ALL,
LCD_PRINT_ELEMENT_CH_OTF
end enum
declare lcd_error_mode as boolean
declare function device_mb_get_key(mk as en_mb_keys) as string
declare sub device_mb_interrupt()
declare sub device_ib_interrupt()
declare sub device_lb_interrupt()
declare sub device_tb_interrupt()
declare sub device_menu_interrupt()
declare sub device_move_cursor(menu_item as menu_display_item,desc_file as string(30))
declare sub device_menu_pre(
x_coord as word, 'x coordination
y_coord as word, 'y coordination
width as word, 'width of the menu in pixel
height as word, 'height of the menu in pixel
byref menu_states as string(MENU_MAX_LVL), 'allows user to start up the menu inside of selected sub-folders instead of root. example: if menu_state = "23" then the menu will started at 2nd folder of menu lvl 1, 3rd folder of menu lvl 2. if menu_state = "" then menu started at root.
byref menu_descriptor_file as string(20), 'the descriptor file
access_level as byte, 'access level of the user, only the menu item that is small or equal to access_level will show.
timeout as byte 'if no respond from the keypad within the time defined by "timeout", exit the menu and return to the previous screen. If timeout = 0, no time out applies
)
declare sub device_input_box_pre(
byref mask_str as string(IB_MAX_LEN), 'uneditable part of the input string
byref edit_str as string(IB_MAX_LEN), 'input string
char_range as input_box_char_ranges, 'the input range. INPUT_BOX_CHAR_RANGE_09 only allows numeric input, INPUT_BOX_CHAR_RANGE_AZ allows alphabetic, INPUT_BOX_CHAR_RANGE_09AZ allows both numeric and alphabetic input.
secret_mode as no_yes, 'if secret_mode = yes, all editable part of the input string will be display on the LCD as "*", this are mostly used for password.
insert_mode as no_yes, 'if insert_mode = yes, the new character is insert before the cursor, if insert_mode = no, the character replaces the character at the cursor position.
byref initial_pos as byte, 'initial cursor position
timeout as byte, 'if no keypad activity for the amount of time defined by timeout, input box is automatically closed and return to previous screen.
input_length as byte 'the maximum number of characters
)
declare sub device_list_box_pre(
x_coord as word, 'x coordination
y_coord as word, 'y coordination
list_width as word, 'list box width
list_height as word, 'list box height
byref listbox_data as string, 'values and display strings of all list box items
byref listbox_state as string(10), 'the value of selected list box item
timeout as byte 'if no respond from the keypad within the time defined by "timeout", exit the list box and return to the previous screen. If timeout = 0, no time out applies
)
declare sub device_msg_box_pre(
byref msg as string(160), 'message to be displayed in the Message Box
x as word, 'x coordination
y as word, 'y coordination
w as word, 'width of the msgbox
h as word, 'height of the msgbox
align as pl_lcd_text_alignment, 'alignment of the text in the msgbox
byref keycode_str as string(20), 'this string contains the characters which ASCII is correspond to the keycode of keys on the keypad that msgbox responds to
bolder as no_yes, 'if the msgbox is wrap with a visible bolder line
timeout as byte 'if no respond from the keypad within the time defined by "timeout", exit the msgbox and return to the previous screen. If timeout = 0, no time out applies
)
declare sub device_menu_post(
x_coord as word, 'x coordination
y_coord as word, 'y coordination
width as word, 'width of the menu in pixel
height as word, 'height of the menu in pixel
byref menu_states as string(MENU_MAX_LVL), 'allows user to start up the menu inside of selected sub-folders instead of root. example: if menu_state = "23" then the menu will started at 2nd folder of menu lvl 1, 3rd folder of menu lvl 2. if menu_state = "" then menu started at root.
byref menu_descriptor_file as string(20), 'the descriptor file
access_level as byte, 'access level of the user, only the menu item that is small or equal to access_level will show.
timeout as byte 'if no respond from the keypad within the time defined by "timeout", exit the menu and return to the previous screen. If timeout = 0, no time out applies
)
declare sub device_input_box_post(
byref mask_str as string(IB_MAX_LEN), 'uneditable part of the input string
byref edit_str as string(IB_MAX_LEN), 'input string
char_range as input_box_char_ranges, 'the input range. INPUT_BOX_CHAR_RANGE_09 only allows numeric input, INPUT_BOX_CHAR_RANGE_AZ allows alphabetic, INPUT_BOX_CHAR_RANGE_09AZ allows both numeric and alphabetic input.
secret_mode as no_yes, 'if secret_mode = yes, all editable part of the input string will be display on the LCD as "*", this are mostly used for password.
insert_mode as no_yes, 'if insert_mode = yes, the new character is insert before the cursor, if insert_mode = no, the character replaces the character at the cursor position.
byref initial_pos as byte, 'initial cursor position
timeout as byte, 'if no keypad activity for the amount of time defined by timeout, input box is automatically closed and return to previous screen.
input_length as byte 'the maximum number of characters
)
declare sub device_list_box_post(
x_coord as word, 'x coordination
y_coord as word, 'y coordination
list_width as word, 'list box width
list_height as word, 'list box height
byref listbox_data as string, 'values and display strings of all list box items
byref listbox_state as string(10), 'the value of selected list box item
byref disable_print as no_yes,
timeout as byte 'if no respond from the keypad within the time defined by "timeout", exit the list box and return to the previous screen. If timeout = 0, no time out applies
)
declare sub device_msg_box_post(
byref msg as string(60), 'message to be displayed in the Message Box
x as word, 'x coordination
y as word, 'y coordination
w as word, 'width of the msgbox
h as word, 'height of the msgbox
align as pl_lcd_text_alignment, 'alignment of the text in the msgbox
byref keycode_str as string(20), 'this string contains the characters which ASCII is correspond to the keycode of keys on the keypad that msgbox responds to
bolder as no_yes, 'if the msgbox is wrap with a visible bolder line
timeout as byte 'if no respond from the keypad within the time defined by "timeout", exit the msgbox and return to the previous screen. If timeout = 0, no time out applies
)
declare sub device_ib_timer_event(byref current_state as input_box_key_actions,byref key_asc as byte,byref insert_mode as no_yes)
declare sub lcd_clear(x as word, y as word, width as word, height as word)
declare sub lcd_print_msg(byref msg as string,x as word, y as word, w as word, h as word,al as pl_lcd_text_alignment, bolder as no_yes)
declare sub reset_keypad()
declare sub device_menu_key_proc(key_event as pl_kp_event_codes, key_code as byte, byref current_state as menu_key_actions)
declare sub device_number_key_action(led_key as word,upper_asc as byte,lower_asc as byte, number_asc as byte, byref current_state as input_box_key_actions, byref key_asc as byte, byref insert_mode as no_yes)
declare sub device_ib_key_proc(key_event as pl_kp_event_codes, key_code as byte, byref current_state as input_box_key_actions, byref key_asc as byte, byref insert_mode as no_yes)
declare sub device_lb_key_proc(key_event as pl_kp_event_codes, key_code as byte, byref current_state as list_box_key_action)
declare sub device_mb_key_proc(key_event as pl_kp_event_codes, key_code as byte)
declare sub set_stg_modified()
declare sub lcd_print_dhcp(interface as pl_sock_interfaces, x as word, y as word)
declare sub lcd_print_ip(byref ip as string, x as word, y as word)
declare sub lcd_print_top_text(byref text as string, x as word, y as word, width as word, height as word)
declare sub lcd_print_bottom_text(byref text as string, x as word, y as word, width as word, height as word)
declare sub lcd_print_icon(byref name as string, x as word, y as word)
declare sub lcd_display_tibbo(byref text as string)
declare sub lcd_display_channel(channel as byte)
declare sub lcd_display_page(page as enum_lcd_pages, mode as enum_lcd_print_modes, element as enum_lcd_print_elements)
declare sub lcd_print_io_pin(s as string(1), pin as byte, inverse as boolean, base_x as word, base_y as word, color as word)
declare sub lcd_serial_print(sernum as byte, corn_x as byte, corn_y as byte)
declare sub lcd_channel_fault(channel as byte)
#endif