-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathboot.tbs
More file actions
965 lines (784 loc) · 19.6 KB
/
boot.tbs
File metadata and controls
965 lines (784 loc) · 19.6 KB
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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
include "global.tbh"
#if SUPPORTS_DISPLAY
const IO_WIDTH=15
declare sub lcd_init()
declare sub kp_init()
declare sub print_main_screen()
declare sub print_main_icon()
#endif
#if WLN_AVAILABLE
dim wln_result as en_wln_status_codes
#endif
declare function get_TibbitType(tibbit as string(4)) as en_slot_type
#ifdef FIXEDCONFIG
declare function cfg_parse() as boolean
#endif
'====================================================================
public sub boot()
dim s as string
dim f as byte
io.num = RED_IO_NUM_1
io.enabled = YES
io.num = GREEN_IO_NUM_1
io.enabled = YES
reboot_flag = NO
reboot_timer = 0
agg_port_fallback_count = AGG_PORT_FALLBACK_MAX
'indicate that we are starting the boot
pat.channel = 0
pat.play(PAT_BOTH_LOOP, PL_PAT_CANINT)
#if SUPPORTS_DISPLAY
lcd_init()
lcd_clear(0, 0, lcd.width, lcd.height)
lan_network_state = 255
#endif
if fd.ready = NO then
if fd.mount <> PL_FD_STATUS_OK then
' Format Flash Disk
fd.format(fd.availableflashspace, 64)
end if
end if
if stg_start() <> EN_STG_STATUS_OK then
pat.play(PAT_BLINK_BOTH_TOGETHER_FAST, PL_PAT_NOINT)
exit sub
else
if stg_check_all(s) <> EN_STG_STATUS_OK then
device_setting_init(EN_STG_INIT_MODE_OVERRIDE)
sys.reboot
end if
end if
' Check configuration for FIXED mode
#ifdef FIXEDCONFIG
' Parce config file
cfg_parse()
#endif
error_mode = NO
if stg_check_all(s) <> EN_STG_STATUS_OK then
if device_setting_init(EN_STG_INIT_MODE_NORMAL) <> OK then
declare_error_mode()
end if
end if
'sntp
param_te = stg_get("TE",0)
if param_te = 1 then
last_sntp_date = 65535
s_sock = sock_get("SNTP")
sntp_init()
end if
'aggregate
param_ar = val(stg_get("AR",0))
if param_ar = 1 and param_te = 1 then
'disable time server if aggregate is enabled
param_te = 0
end if
#if SUPPORTS_GPRS
param_ge=stg_get("GE",0)
#endif
if net.linkstate <> PL_NET_LINKSTAT_NOLINK then
#if DEV_DEBUG_PRINT
dev_debugprint("Set current interface to Ethernet")
#endif
interface_ready(PL_SOCK_INTERFACE_NET) = YES
current_interface = PL_SOCK_INTERFACE_NET
end if
current_interface = PL_SOCK_INTERFACE_NET
'net. parameters and DHCP
'net_cmd
net_cmd_init()
init_x_flags()
param_dh = val(stg_get("DH",0))
set_net_ip(PL_SOCK_INTERFACE_NET)
if param_dh <> NO then
ip_configured(PL_SOCK_INTERFACE_NET) = NO
dhcp_start(PL_SOCK_INTERFACE_NET, net.ip, "")
else
declare_ip_set(PL_SOCK_INTERFACE_NET)
ip_configured(PL_SOCK_INTERFACE_NET) = YES
end if
#if WLN_AVAILABLE
'Wi-Fi parameters and DHCP
wln_error = NO
param_we = stg_get("WE", 0)
set_net_ip(PL_SOCK_INTERFACE_WLN)
#if SUPPORTS_DISPLAY
wln_network_state = 255
#endif
wln_dev_rescan_tmr = 0
rssi_update_timer=RSSI_UPDATE_TIMER_CTR
if param_we <> WE_DISABLED then
num_wln_failures = 0
param_wd = val(stg_get("WD", 0))
if param_wd <> NO then
ip_configured(PL_SOCK_INTERFACE_WLN) = NO
dhcp_start(PL_SOCK_INTERFACE_WLN, wln.ip, "")
else
ip_configured(PL_SOCK_INTERFACE_WLN) = YES
declare_ip_set(PL_SOCK_INTERFACE_WLN)
end if
param_wa=stg_get("WA", 0)
param_ws=val(stg_get("WS", 0))
select case param_ws
case WLN_SECURITY_MODE_DISABLED:
wln_password = ""
case WLN_SECURITY_MODE_WEP64, WLN_SECURITY_MODE_WEP128:
wln_password=stg_get("WP", 0)
#if WLN_WPA
case else:
if param_ws=stg_get("wS",0) and param_wa=stg_get("wA",0) and stg_get("WP",0)=stg_get("wP",0) and stg_sg("WK",0,wln_password,EN_STG_GET)=EN_STG_STATUS_OK and len(wln_password)=32 then
else
#if SUPPORTS_DISPLAY
'turn on backlight
io.num=PL_IO_NUM_54
io.state=LOW
lcd_clear(0,0,lcd.width,lcd.height)
romfile.open(LCD_STD_FONT)
lcd.setfont(romfile.offset)
lcd.textverticalspacing=2
lcd.texthorizontalspacing=2
lcd_print_msg(SYS_CALCULATE_WPA_KEY,0,0,lcd.width,lcd.height-lcd.fontheight*2,PL_LCD_TEXT_ALIGNMENT_MIDDLE_CENTER,no)
#endif
wln_password=wln_wpa_mkey_get(stg_get("WP",0),stg_get("WA",0))
stg_set("WK",0,wln_password)
stg_set("wS",0,str(param_ws))
stg_set("wA",0,param_wa)
stg_set("wP",0,stg_get("WP",0))
end if
#endif
end select
if param_we=WE_ENABLED_PERMANENT then
#if DEV_DEBUG_PRINT
dev_debugprint("Start Wi-Fi")
#endif
wln_result=wln_start(param_wa,param_ws,wln_password,PL_WLN_DOMAIN_FCC,no,PL_WLN_ASCAN_INFRASTRUCTURE)
if wln_result<>WLN_STATUS_OK then
#if DEV_DEBUG_PRINT
dev_debugprint("Wi-Fi MALFUNCTIONED (could not start)")
#endif
wln_error=YES
end if
wln_already_started=YES
#if SUPPORTS_DISPLAY
select case wln_result
case WLN_STATUS_OK:
wln_network_state=NETWORK_WLN_JOINING
case WLN_STATUS_INVALID_WEP_KEY:
wln_network_state=NETWORK_WLN_INVALID_WKEY
case else:
wln_network_state=NETWORK_WLN_FATAL_ERROR
end select
#endif
else
wln_stop()
wln_already_started=NO
#if SUPPORTS_DISPLAY
lcd_display_page(LCD_PAGE_WLN, LCD_PRINT_MODE_GENTLE, LCD_PRINT_ELEMENT_ALL)
#endif
end if
end if
'Set up Bluetooth. Only for WA2000 module
luis_start()
#if SIGNAL_STRENGTH_INDICATION
signal_strength_indication_init()
#endif
#else
wln_error=NO
#endif
'GPRS parameters
#if SUPPORTS_GPRS
gprs_error=NO
if param_ge<>GE_DISABLED then
param_ga=stg_get("GA",0)
param_gn=stg_get("GN",0)
param_gu=stg_get("GU",0)
param_gp=stg_get("GP",0)
if param_ge=GE_ENABLED_PERMANENT then
#if DEV_DEBUG_PRINT
dev_debugprint("Start GPRS")
#endif
if gprs_start(param_ga,param_gn,param_gu,param_gp)<>GPRS_STATUS_OK then
#if DEV_DEBUG_PRINT
dev_debugprint("GPRS MALFUNCTIONED (could not start)")
#endif
gprs_error=YES
end if
gprs_already_started=YES
else
gprs_already_started=NO
end if
end if
#endif
'HTTP sockets
for f = 0 to NUM_HTTP_SOCKETS - 1
sock_http(f) = sock_get("HTTP")
sock.num = sock_http(f)
sock.protocol = PL_SOCK_PROTOCOL_TCP
sock.httpportlist = "80"
sock.connectiontout = 600
sock.allowedinterfaces = "NET,WLN"
sock.inconmode = PL_SOCK_INCONMODE_ANY_IP_ANY_PORT
sock.reconmode = PL_SOCK_RECONMODE_0
next f
if http_buff_rq(HTTP_BUFF_ALLOCATE) <> OK then
'insufficient memory
end if
'===================================================
' HARDWARE INIT
'===================================================
for f = 0 to NUM_OF_SLOTS - 1
param_st(f) = get_TibbitType(stg_get("ST", f*2))
if param_st(f) = SLOT_IOD_2 then
' test #41
if get_TibbitType(stg_get("ST", f*2 + 1)) = SLOT_8BIT then
param_st(f) = SLOT_8BIT
end if
end if
next f
modbus_initialize()
' SNMP
if snmp_initialize() = true then
sock_snmp = sock_get("SNMP")
sock.num = sock_snmp
sock.protocol = PL_SOCK_PROTOCOL_UDP
sock.localportlist = "161"
sock.connectiontout = 600
sock.allowedinterfaces = "NET,WLN"
sock.inconmode = PL_SOCK_INCONMODE_ANY_IP_ANY_PORT
sock.reconmode = PL_SOCK_RECONMODE_3
sock.txbuffrq(1)
sock.rxbuffrq(1)
sys.buffalloc
if traps_enable = true then
sock_trap = sock_get("SNMT")
sock.num = sock_trap
sock.protocol = PL_SOCK_PROTOCOL_UDP
sock.targetport = "162"
sock.targetip = trap_receiver
sock.connectiontout = 600
sock.allowedinterfaces = "NET,WLN"
sock.reconmode = PL_SOCK_RECONMODE_3
sock.txbuffrq(1)
sock.rxbuffrq(1)
sys.buffalloc
end if
#if DEV_DEBUG_PRINT
dev_debugprint("SNMP initialized")
#endif
end if
' Get parameters for AGG events
param_aggEvents.agg_eventAnalog = val(stg_get("AA", 0))
param_aggEvents.agg_eventDigital = val(stg_get("AD", 0))
param_aggEvents.agg_eventCounter = val(stg_get("AC", 0))
param_aggEvents.agg_eventBP = val(stg_get("AB", 0))
bp_setup()
setup_io()
setup_serial()
analog_setup()
oneWire_Init()
'===================================================
#if USE_DNS
sock_dns=sock_get("DNS")
dns_start(sock_dns)
server_ip_obtain=NO
#endif
#if SUPPORTS_DISPLAY
lcd_error_mode = false
io_index = 0
kp_init()
lcd.forecolor = LCD_FORECOLOR
lcd.backcolor = LCD_BACKCOLOR
lcd_clear(0, 0, lcd.width, lcd.height)
' print_main_screen()
print_time()
' print_io_cursor(io_index)
' print_main_icon()
' print_wifi()
if param_dh = NO then
lcd_display_page(LCD_PAGE_NET, LCD_PRINT_MODE_GENTLE, LCD_PRINT_ELEMENT_ALL)
end if
#if WLN_AVAILABLE
if param_we = WE_DISABLED then
lcd_display_page(LCD_PAGE_WLN, LCD_PRINT_MODE_GENTLE, LCD_PRINT_ELEMENT_ALL)
end if
#endif
'turn on backlight
io.num = PL_IO_NUM_54
io.state = LOW
lcd_display_page(LCD_PAGE_NET, LCD_PRINT_MODE_GENTLE, LCD_PRINT_ELEMENT_ALL)
lcd_display_page(LCD_PAGE_WLN, LCD_PRINT_MODE_GENTLE, LCD_PRINT_ELEMENT_ALL)
lcd_display_page(LCD_PAGE_LOGO_WORK, LCD_PRINT_MODE_GENTLE, LCD_PRINT_ELEMENT_ALL)
lcd_display_channel(0)
lcd_display_channel(1)
lcd_display_channel(2)
lcd_display_channel(3)
lcd_display_channel(4)
lcd_display_channel(5)
#endif
'don't have established Ethernet link by now? Assume there is no link
if net.linkstate = PL_NET_LINKSTAT_NOLINK then
ethernet_link_state_change(PL_NET_LINKSTAT_NOLINK)
end if
' Sets 50ms Timer period
sys.onsystimerperiod = 5
'indicate that the boot is completed
pat.channel = 0
pat.play(PAT_THREE_BOTH, PL_PAT_CANINT)
beep.divider = BEEP_DIVIDER
beep.play(BEEP_SHORT, PL_BEEP_CANINT)
end sub
'------------------------------------------------------------------------------
#if SUPPORTS_DISPLAY
'------------------------------------------------------------------------------
sub lcd_init()
'----- INIT LCD -----
lcd.width=320
lcd.height=240
'RST
io.num=PL_IO_NUM_55
io.enabled=YES
'DC
io.num=PL_IO_NUM_43
io.enabled=YES
'WR
io.num=PL_IO_NUM_42
io.enabled=YES
'RD
io.num=PL_IO_NUM_41
io.enabled=YES
'CS
io.num=PL_IO_NUM_40
io.enabled=YES
lcd.iomapping="55,43,42,41,40,0" 'RST,DC,WR,RD,CS,data_bus
lcd.rotated=YES 'yes, the LCD is installed up side down
lcd.enabled=YES
'backlight OFF
io.num=PL_IO_NUM_54
io.enabled=YES
io.state=HIGH
end sub
'------------------------------------------------------------------------------
sub kp_init()
'----- KEYPAD -----
io.num=PL_IO_NUM_44
io.enabled=YES
io.state=LOW
kp.returnlinesmapping="36,37,38,39"
kp.enabled=YES
end sub
'------------------------------------------------------------------------------
public sub print_main_screen()
dim s as string
if enter_menu=YES then exit sub
lcd.textalignment=PL_LCD_TEXT_ALIGNMENT_MIDDLE_CENTER
romfile.open(LCD_STD_FONT)
lcd.setfont(romfile.offset)
lcd.textverticalspacing=2
lcd.texthorizontalspacing=2
lcd.forecolor=BG_BLUE
lcd.fill(0,63,lcd.width,lcd.height-150)
lcd.forecolor=LCD_FORECOLOR
lcd.backcolor=BG_BLUE
lcd_display_page(LCD_PAGE_NET, LCD_PRINT_MODE_GENTLE, LCD_PRINT_ELEMENT_ALL)
#if WLN_AVAILABLE
lcd_display_page(LCD_PAGE_WLN, LCD_PRINT_MODE_GENTLE, LCD_PRINT_ELEMENT_ALL)
#endif
s="Enter Menu >>"
lcd.textalignment=PL_LCD_TEXT_ALIGNMENT_BOTTOM_RIGHT
lcd.printaligned(s, 0,124,lcd.width,28)
' print_io_screen(0, yes)
end sub
'------------------------------------------------------------------------------
public sub print_io_screen(index as byte, refresh_all as no_yes)
dim i as byte
dim x,y,w,h,x1,y1 as word
dim print_ser_state as no_yes
dim s as string(4)
if enter_menu=YES then exit sub
lcd.textalignment=PL_LCD_TEXT_ALIGNMENT_MIDDLE_CENTER
romfile.open(SMALL_FONT)
lcd.setfont(romfile.offset)
lcd.textverticalspacing=1
lcd.texthorizontalspacing=1
if refresh_all=yes then
i=0
else
i=index
end if
do
print_ser_state=NO
io.num=index_to_io_num(i)
if i<8 then
if i>3 then
x=17+i*IO_WIDTH+15
else
x=17+i*IO_WIDTH
end if
y=lcd.height-54
x1=x+IO_WIDTH-1
if param_se(0)=1 then
select case i
case 0:
print_ser_state=YES
s="R/T"
case 1:
goto print_io_num
case 2:
if param_fc(0)=1 then
print_ser_state=YES
s="R/C"
end if
case 3:
if param_fc(0)=1 then
goto print_io_num
end if
end select
end if
if param_se(1)=1 then
select case i
case 4:
print_ser_state=YES
s="R/T"
case 5:
goto print_io_num
case 6:
if param_fc(1)=1 then
print_ser_state=YES
s="R/C"
end if
case 7:
if param_fc(1)=1 then
goto print_io_num
end if
end select
end if
end if
if i>7 and i<16 then
if i>11 then
x=17+(i+2)*IO_WIDTH+15
else
x=17+(i+2)*IO_WIDTH
end if
y=lcd.height-54
y1=y+IO_WIDTH
x1=x+IO_WIDTH-1
if param_se(2)=1 then
select case i
case 8:
print_ser_state=YES
s="R/T"
case 9:
goto print_io_num
case 10:
if param_fc(2)=1 then
print_ser_state=YES
s="R/C"
end if
case 11:
if param_fc(2)=1 then
goto print_io_num
end if
end select
end if
if param_se(3)=1 then
select case i
case 12:
print_ser_state=YES
s="R/T"
case 13:
goto print_io_num
case 14:
if param_fc(3)=1 then
print_ser_state=YES
s="R/C"
end if
case 15:
if param_fc(3)=1 then
goto print_io_num
end if
end select
end if
end if
if i>15 then
if i>19 then
x1=17+(34-i)*IO_WIDTH
else
x1=17+(34-i)*IO_WIDTH+15
end if
y=15
x=x1-IO_WIDTH+1
end if
h=IO_WIDTH-2
y1=y+IO_WIDTH
if print_ser_state=YES then
x1=x+IO_WIDTH*2-1
w=IO_WIDTH*2-4
lcd.forecolor=LCD_FORECOLOR
lcd.backcolor=BG_BLUE
goto print_io_state
else
w=IO_WIDTH-2
lcd.forecolor=LCD_FORECOLOR
if io.state=high then
lcd.backcolor=BG_GREEN
else
lcd.backcolor=BG_RED
end if
if param_io(i).io_enabled=YES then
s="O"
else
s="I"
end if
end if
print_io_state:
lcd.filledrectangle(x,y,x1,y1)
lcd.printaligned(s, x+1,y+1,w,h)
print_io_num:
if refresh_all=YES then
if i<16 then
y=y-IO_WIDTH
else
y=y+IO_WIDTH
end if
lcd.forecolor=LCD_FORECOLOR
lcd.backcolor=LCD_BACKCOLOR
lcd.printaligned(str(index_to_io_num(i)), x,y,IO_WIDTH,IO_WIDTH)
end if
if refresh_all=no then
exit do
else
i=i+1
end if
loop while i<NUM_OF_IO
end sub
'------------------------------------------------------------------------------
public sub print_io_cursor(index as byte)
dim x, y as word
if enter_menu=YES then exit sub
lcd.textalignment=PL_LCD_TEXT_ALIGNMENT_MIDDLE_CENTER
romfile.open("cursor.bmp")
lcd.forecolor=LCD_FORECOLOR
lcd.backcolor=LCD_BACKCOLOR
lcd_clear(0,lcd.height-54-IO_WIDTH*2,lcd.width,IO_WIDTH)
lcd_clear(0,15+IO_WIDTH*2,lcd.width,IO_WIDTH)
if index<8 then
if index>3 then
x=17+index*IO_WIDTH+15
else
x=17+index*IO_WIDTH
end if
y=lcd.height-54-IO_WIDTH
lcd.bmp(romfile.offset,x,y-IO_WIDTH,0,0,IO_WIDTH,IO_WIDTH)
end if
if index>7 and index<16 then
if index>11 then
x=17+(index+2)*IO_WIDTH+15
else
x=17+(index+2)*IO_WIDTH
end if
y=lcd.height-54-IO_WIDTH
lcd.bmp(romfile.offset,x,y-IO_WIDTH,0,0,IO_WIDTH,IO_WIDTH)
end if
if index>15 then
if index>19 then
x=17+(34-index)*IO_WIDTH
else
x=17+(34-index)*IO_WIDTH+15
end if
y=15+IO_WIDTH
lcd.bmp(romfile.offset,x-IO_WIDTH,y+IO_WIDTH,0,0,IO_WIDTH,IO_WIDTH)
end if
end sub
'------------------------------------------------------------------------------
public sub print_time()
dim s1,s2 as string(32)
dim b1 as byte
if enter_menu=YES then exit sub
lcd.textalignment=PL_LCD_TEXT_ALIGNMENT_TOP_LEFT
romfile.open(SMALL_FONT)
lcd.setfont(romfile.offset)
lcd.textverticalspacing=1
lcd.texthorizontalspacing=1
lcd.forecolor=LCD_FORECOLOR
lcd.backcolor=LCD_BACKCOLOR
device_settings_sg("TD",0,s1,b1,DEVICE_GET)
device_settings_sg("TT",0,s2,b1,DEVICE_GET)
lcd.printaligned(s1,1,1,60,10)
lcd.printaligned(s2,1,10,60,10)
end sub
'------------------------------------------------------------------------------
sub print_main_icon()
dim x,y,w as word
if enter_menu=YES then exit sub
x=6
y=lcd.height-32
w=90
romfile.open("io_icon.bmp")
lcd_clear(1,y-1,lcd.width-1,33)
lcd.bmp(romfile.offset,x,y,0,0,40,31)
lcd.bmp(romfile.offset,x+w,y,40,0,40,31)
lcd.bmp(romfile.offset,x+w*2,y,80,0,40,31)
lcd.bmp(romfile.offset,x+w*3,y,120,0,40,31)
end sub
#endif
function get_TibbitType(tibbit as string(4)) as en_slot_type
select case tibbit
case "00_0":
get_TibbitType = SLOT_EMPTY
case "00_1":
get_TibbitType = SLOT_IOD_4
case "00_2"
get_TibbitType = SLOT_IOD_3
case "00_3"
get_TibbitType = SLOT_IOD_2
case "01"
get_TibbitType = SLOT_SERIAL_01
case "02"
get_TibbitType = SLOT_SERIAL_02
case "03_1"
get_TibbitType = SLOT_OD_2
case "03_2"
get_TibbitType = SLOT_OD_2
case "04_1"
get_TibbitType = SLOT_ID_2
case "04_2"
get_TibbitType = SLOT_ID_3
case "04_3"
get_TibbitType = SLOT_ID_3
case "04_4"
get_TibbitType = SLOT_ID_4
case "04_5"
get_TibbitType = SLOT_ID_2
case "04_6"
get_TibbitType = SLOT_ID_3
case "04_7"
get_TibbitType = SLOT_ID_3
case "04_8"
get_TibbitType = SLOT_ID_4
case "05"
get_TibbitType = SLOT_SERIAL_05
case "06"
get_TibbitType = SLOT_OD_2
case "07"
get_TibbitType = SLOT_OD_2
case "11"
get_TibbitType = SLOT_OD_4
case "13"
get_TibbitType = SLOT_IA_4
case "14"
get_TibbitType = SLOT_OA_4
case "15"
get_TibbitType = SLOT_OD_1
case "16"
get_TibbitType = SLOT_OA_3
case "17"
get_TibbitType = SLOT_OA_3
case "22"
get_TibbitType = SLOT_IA_RTD
case "32"
get_TibbitType = SLOT_IA_4_32
case "40_1"
get_TibbitType = SLOT_DP
case "40_2"
get_TibbitType = SLOT_DP
case "40_3"
get_TibbitType = SLOT_DP
case "40_4"
get_TibbitType = SLOT_DP
case "52"
get_TibbitType = SLOT_IA_52
case "53"
get_TibbitType = SLOT_IA_53
case "54"
get_TibbitType = SLOT_ID_4
case "58"
get_TibbitType = SLOT_OD_2
case "59"
get_TibbitType = SLOT_OD_2
case "31"
get_TibbitType = SLOT_OW
case "41"
get_TibbitType = SLOT_8BIT
case "43-1"
get_TibbitType = SLOT_43_1
case "43-2"
get_TibbitType = SLOT_43_2
case "44-1"
get_TibbitType = SLOT_44_1
case "44-2"
get_TibbitType = SLOT_44_2
case else:
get_TibbitType = SLOT_EMPTY
end select
end function
#ifdef FIXEDCONFIG
function cfg_parse() as boolean
dim slot_type(NUM_OF_SLOTS_STG) as string(4)
dim resp as pl_fd_status_codes
dim buff as string
dim pos, pos1 as byte
dim posfile as dword
dim substr as string(6)
dim i as byte
dim endst as boolean
cfg_parse = false
substr = chr(34) + "ST" + chr(34) + ":["
posfile = 0
romfile.open(FILEFIXEDCONFIG)
if romfile.size > 0 then
'Find "ST":[
buff = romfile.getdata(250)
while len(buff) <> 0
pos = instr(1, buff, substr, 1)
if pos <> 0 then
romfile.pointer32 = posfile + pos + 1
buff = romfile.getdata(255)
exit while
else
buff = right(buff, 5)
buff = buff + romfile.getdata(250)
posfile = posfile + 250
end if
wend
'Parce ST fields
pos = 1
endst = false
for i = 0 to NUM_OF_SLOTS_STG - 1
if endst = false then
if mid(buff, pos, 1) = chr(34) then
pos1 = instr(pos + 1, buff, chr(34), 1)
if pos1 <> 0 then
slot_type(i) = mid(buff, pos + 1, pos1 - pos - 1)
if mid(buff, pos1 + 1, 1) <> "," then
endst = true
end if
pos = pos1 + 2
else
slot_type(i) = "00_0"
endst = true
end if
else
slot_type(i) = "00_0"
endst = true
end if
else
slot_type(i) = "00_0"
end if
next i
' Check match for current conf
endst = false
for i = 0 to NUM_OF_SLOTS_STG - 1
if stg_get("ST", i) <> slot_type(i) then
endst = true
exit for
end if
next i
if endst then
device_setting_init(EN_STG_INIT_MODE_OVERRIDE)
' Store fixed conf
for i = 0 to NUM_OF_SLOTS_STG - 1
stg_set("ST", i, slot_type(i))
next i
end if
cfg_parse = true
end if
end function
#endif