forked from jordevorstenbosch/AMXMobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamx_mobile_comm.axs
3362 lines (2949 loc) · 107 KB
/
amx_mobile_comm.axs
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
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
MODULE_NAME='AMX_Mobile_Comm'(DEV vdvWeb,DEV dvWeb,INTEGER nWebPort,CHAR cWebURL_IP[],INTEGER nWebDeBug)
// Created by: Brian Cirrisi
// Last Modified: 03/25/2009
// Version: 1.0
// This code is provided to the AMX Forum community and is not to be sold commercially.
(*(VAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAV)*)
(*(VAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAV)*)
(*( MODIFIED BY VAV JULY 23, 2009 )*)
(*( Danile R. Vining )*)
(*( 30 Spring Street )*)
(*( Danbury, CT 06810 )*)
(*(VAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAV)*)
(*(VAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAV)*)
(*( As far as I'm concerned you can use it in jobs but )*)
(*( don't charge for it. If you do charge for it then )*)
(*( do something nice for someone else in return. )*)
(*(VAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAV)*)
(*(VAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAV)*)
(*( TAB STOPS BEFORE 8 BEFORE CHARACTERS )*)
(*( INDENT 5 BEFORE CHARACTERS )*)
(*(VAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAV)*)
(*(VAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAV)*)
(*( TO DEBUG DO A FIND AND REPLACE )*)
(*( FIND: //fnWebDeBug REPLACE W/ fnWebDeBug )*)
(*( since there's alot I don't like it running if )*)
(*( I'm not debugging. re-compile and then re-send!!!! )*)
(*(VAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAV)*)
(*(VAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAV)*)
DEFINE_CONSTANT //GENERAL VARS
CRLF[2] = {$0D,$0A}
DELETE_STORED_IP_20 = 200 ; //TIME TO WAIT BEFORE DELETING THE STORED IP AND REQUIRING USER TO LOGIN AGAIN.
DELETE_STORED_IP_40 = 400 ; //THIS TIME REFRESHES WHEN USED.
DELETE_STORED_IP_60 = 600 ;
DELETE_STORED_IP_120 = 1200 ;
WINGENERIC = 100 ;
BLACKBERRY = 101 ;
iPHONE = 102 ;
iPOD = 103 ;
WINSAFARI = 104 ;
PAGE_CLOSE_SERVER = 0 ;
PAGE_LOGIN = 1 ;
PAGE_RETRY = 2 ;
PAGE_BUTTONS = 3 ;
PAGE_SEND_FILES = 4 ;
PAGE_204_NOCONTENT = 5 ;
PAGE_404_FILENOFIND = 6 ;
PAGE_304_NOTMODIFIED = 7 ;
PAGE_SETCOOKIE = 8 ;
PAGE_202_ACCEPTED = 9 ;
PAGE_QUERY_RESPONSE = 10 ;
BUTTON_NO_SHOW = 0 ;
BUTTON_SHOW = 1 ;
BUTTON_MENU = 2 ;
SERVER_STOPPED = 0 ;
SERVER_READY = 1 ;
SERVER_CLIENT_CONNECTED = 2 ;
SERVER_RX_DATA = 3 ;
SERVER_DISABLED = 4 ;
MAX_MTU = 1500 ;
MAX_NUM_BTNs_ROW = 3 ;
MAX_NUM_ROWs = 8 ;
MAX_NUM_PAGEs = 10 ;
MAX_NUM_BTNs_PAGE = 24 ;
MAX_NUM_BUTTONs = MAX_NUM_PAGEs * MAX_NUM_BTNs_PAGE ;
MAX_NAME_LENGTH = 15 ;
MAX_LEN_STR_MSG = 20000 ;
WEB_PAGE_FB_REFRESH = 20 ; //delay in sending web page out to provide time feedback changes to occur ;
DEFINE_CONSTANT //GENERAL VARS * FILES * REFRESH * DATE TIMES * COOKIE
//CHAR BUTTON_IMG_ARRY [3][20] = {'button_off.jpg','button_on.jpg','button_on.jpg'}
NUM_FILES_TO_Q = 30 ;
MAXLEN_FILE_NAMES = 30 ;
EXPIRES_IN_SECONDS = 10 ; //10 seconds
//CSS_INCLUDE_REFRESH = 1 ;
CSS_EXCLUDE_REFRESH = 0 ;
MAX_READ_FILE_LENGTH = 40000 ; // Max buffer size for reading files.
CHAR AMX_MOBILE_COOKIE[]= 'amx00mobile00' ;
MIN_REFRESH_TIME = 5000 ; //in milli-seconds minimum number of second before the web page issues another get command for refresh.
MAX_REFRESH_TIME = 60000 ; //in milli-seconds maximum nuber of seconds for web page refersh
NUM_SECONDS_DAY = 86400 ;
CHAR WEB_MONTH[12][3] = {'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'} ;
LONG DAYS_MONTHs[12] = {31 ,28 ,31 ,30 ,31 ,30 ,31 ,31 ,30 ,31 ,30 ,31} ;
LONG DAYS_LEAPMONTHs[12] = {31 ,29 ,31 ,30 ,31 ,30 ,31 ,31 ,30 ,31 ,30 ,31} ;
CHAR WEB_DAYS[7][3] = {'SUN','MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'} ;
DEFINE_TYPE //STRUCTURE
STRUCTURE _sBUTTON
{
CHAR Name[MAX_NAME_LENGTH] ;
INTEGER Value ; //TYPE_CAST ALL FLOATS TO INTERGER. DON'T CARE ABOUT VALUES BEYOND THE DECIMAL POINT
INTEGER Show ; //USED TO DETERMINE IF A BUTTON SHOULD SHOW OR NOT EITHER 1 OR 0 SHOW OR NO SHOW
}
STRUCTURE _sWEB_PAGE
{//[MAX_NUM_BTNs_PAGE]
CHAR Pg_NAME[MAX_NAME_LENGTH] ;
_sBUTTON BTN[MAX_NUM_BTNs_PAGE] ;
}
DEFINE_VARIABLE //STRUCTURE VARIABLES
VOLATILE _sWEB_PAGE sWEB_PAGE[MAX_NUM_PAGEs] ;
DEFINE_VARIABLE //GENERAL VARS
//VOLATILE LONG nTestSecondsAdded ;
//VOLATILE INTEGER nTestTime ;
VOLATILE CHAR cWebURLPathReFresh[75] ;
VOLATILE CHAR cWebURLPathHome[75] ;
VOLATILE INTEGER nAutoRefresh ;
VOLATILE INTEGER nAutoRefreshTime ;
VOLATILE CHAR cRXCookie[48] ;
VOLATILE CHAR nRXNewValue = 0 ;
VOLATILE INTEGER nCurWebPage = 1 ;
VOLATILE INTEGER nBlockQueryResponse = 0 ;
VOLATILE CHAR cData1[20] ;
VOLATILE CHAR cData2[20] ;
VOLATILE INTEGER nTestBuff_Clear = 0 ;
VOLATILE CHAR cWeb_TestRXBuff[20000] ;
VOLATILE CHAR cWeb_TestTXBuff[20000] ;
VOLATILE CHAR cWeb_RXBuffer[20000] ; // The buffer for all incoming messages from the Mobile Web
VOLATILE CHAR cLogin_IPAddress[20] ; // Holds the IP address of the device communicating with the NI
VOLATILE CHAR cPassword[20] ; // Holds the Password for the Site
VOLATILE CHAR cTitle[20] ; // Holds the Title for the Site
VOLATILE SINTEGER nContentLength ; // Tracks how long the Content coming in is
VOLATILE INTEGER nWebAgent ; // What web user is the client using.
VOLATILE INTEGER nWebServerState ;
VOLATILE INTEGER nConnectAttempts = 0 ;
VOLATILE INTEGER nBtnCurLevel = 0 ;
VOLATILE INTEGER nWaitingToSend = 0 ;
NON_VOLATILE INTEGER nNumConfigBtns = 0 ;
VOLATILE INTEGER nFileInsertIndx = 1 ;
VOLATILE INTEGER nFileReadIndx = 1 ;
//VOLATILE SLONG nReadFResult ;
//VOLATILE INTEGER nReading = 0 ;
//VOLATILE CHAR cReadFileExt[3] = 'jpg' ;
//VOLATILE CHAR cReadFileBuf[MAX_READ_FILE_LENGTH] ;
VOLATILE CHAR cWebCurDateTime[29] ;
VOLATILE CHAR cWebExpDateTime[29] ;
DEFINE_VARIABLE //GET FILE QUEUE ARRAY
VOLATILE CHAR cFile_Q_Arry[NUM_FILES_TO_Q][MAXLEN_FILE_NAMES] ;
DEFINE_FUNCTION LONG fn24HourTimeTo_Seconds(CHAR iTime[])
{
RETURN ((((ATOI(REMOVE_STRING(iTime,"':'",1)) * 60) * 60) + ATOI(REMOVE_STRING(iTime,"':'",1)) * 60) + ATOI(iTime)) ;
}
DEFINE_FUNCTION CHAR[8] fnSecondsTo_24HourTime(LONG iTimeInSeconds)
{
RETURN "right_string("'0',ITOA(iTimeInSeconds / 3600)",2),':',
right_string("'0',ITOA((iTimeInSeconds % 3600) / 60)",2),':',
right_string("'0',ITOA((iTimeInSeconds % 3600) % 60)",2)" ;
}
DEFINE_FUNCTION fnUpdateDATE_TIME()
{
cWebCurDateTime = "fnDo24hrTimeAddition(LDate,TIME,0),' EST'" ;
cWebExpDateTime = "fnDo24hrTimeAddition(LDate,TIME,EXPIRES_IN_SECONDS),' EST'" ;
RETURN ;
}
DEFINE_FUNCTION CHAR[30] fnDo24hrTimeAddition(CHAR iLDate[],CHAR i24HourTime[],LONG iSecondsAdded)
{
STACK_VAR INTEGER nYear ; //change to all stack_var's
STACK_VAR INTEGER nMonth ;
STACK_VAR INTEGER nLeap ;
STACK_VAR CHAR c24HrTime[8] ;
STACK_VAR CHAR cNewDate[10] ;
STACK_VAR LONG nDay ;
STACK_VAR LONG nDaysOver ;
STACK_VAR LONG nSecondsRemain ;
STACK_VAR LONG nTotalTimeSeconds ;
nTotalTimeSeconds = fn24HourTimeTo_Seconds(i24HourTime) + iSecondsAdded ;
nMonth = atoi("REMOVE_STRING(iLDATE,"'/'",1)") ;
nDay = atoi("REMOVE_STRING(iLDATE,"'/'",1)") ;
nYear = atoi("iLDATE") ;
if(nTotalTimeSeconds > NUM_SECONDS_DAY)
{
STACK_VAR INTEGER i ;
nDaysOver = nTotalTimeSeconds / NUM_SECONDS_DAY ;
nSecondsRemain = nTotalTimeSeconds % NUM_SECONDS_DAY ;
if(!(nYear % 4))//http://en.wikipedia.org/wiki/Leap_year
{
nLeap = 1 ;
if(!(nYear % 100))//double check these rules??????
{
if(nYear % 400)
{
nLeap = 0 ;
}
}
}
if(nLeap)
{
if((nDaysOver + nDay) > DAYS_LEAPMONTHs[nMonth])
{
nDaysOver = nDaysOver - (DAYS_LEAPMONTHs[nMonth] - nDay) ;
nMonth++ ;
for(nMonth = nMonth ; nDaysOver > DAYS_LEAPMONTHs[nMonth] ; nMonth++)
{
nDaysOver = (nDaysOver - DAYS_LEAPMONTHs[nMonth]) ;
if(nMonth == 12)
{
nMonth = 1 ;
nYear ++ ;
}
}
nDay = nDaysOver ;
}
else
{
nDay = nDaysOver + nDay ;
}
}
else
{
if((nDaysOver + nDay) > DAYS_MONTHs[nMonth])
{
nDaysOver = nDaysOver - (DAYS_MONTHs[nMonth] - nDay) ;
nMonth++ ;
for(nMonth = nMonth ; nDaysOver > DAYS_MONTHs[nMonth] ; nMonth++)
{
nDaysOver = (nDaysOver - DAYS_MONTHs[nMonth]) ;
if(nMonth == 12)
{
nMonth = 1 ;
nYear ++ ;
}
}
nDay = nDaysOver ;
}
else
{
nDay = nDaysOver + nDay ;
}
}
c24HrTime = fnSecondsTo_24HourTime(nSecondsRemain) ;
}
else
{
c24HrTime = fnSecondsTo_24HourTime(nTotalTimeSeconds) ;
}
cNewDate = "right_string("'0',ITOA(nMonth)",2),'/',right_string("'0',ITOA(nDay)",2),'/',right_string("'0',ITOA(nYear)",2)" ;
RETURN "WEB_DAYS[TYPE_CAST(DAY_OF_WEEK(cNewDate))],', ',itoa(nDay),' ',WEB_MONTH[nMonth],' ',itoa(nYear),' ',c24HrTime" ;
}
DEFINE_FUNCTION fnWebDeBug(CHAR iStr[],INTEGER iPrefix)
{
if(nWebDebug)
{
if(iPrefix)
{
SEND_STRING 0,"'MOBILE WEB: ',iStr,CRLF" ;
}
else
{
SEND_STRING 0,"iStr,CRLF" ;
}
}
RETURN ;
}
DEFINE_FUNCTION fnOpenWebServer()
{
STACK_VAR SLONG nErrFlag ;
if(nWebServerState == SERVER_STOPPED)
{
nWebServerState = SERVER_DISABLED ;
//fnWebDeBug("'Opening Server. >-line-<',ITOA(__LINE__),'>'",1) ;
nErrFlag = IP_SERVER_OPEN (dvWeb.Port, nWebPort, 1) ;
{
if(nErrFlag)
{
//fnWebDeBug("'Server ERR: ',fnGET_IPServer_Error(nErrFlag),'. >-line-<',ITOA(__LINE__),'>'",1) ;
WAIT 300 'ERROR_DELAY_RESTART'
{
//fnWebDeBug("'Server Start ERR: Delayed Restart. >-line-<',ITOA(__LINE__),'>'",1) ;
nWebServerState = SERVER_STOPPED ;
}
}
else //if no error this means the online event didn't trigger setting the connection state.
{
CANCEL_WAIT 'WEB_CONNECT_TIMEOUT' ;
CANCEL_WAIT 'ERROR_DELAY_RESTART' ;
nWebServerState = SERVER_READY ; // WAIT FOR ONLINE EVENT ?
}
}
}
RETURN ;
}
DEFINE_FUNCTION fnCloseWebServer()
{
STACK_VAR SLONG nErrFlag ;
if(nWebServerState != SERVER_STOPPED && !nWaitingToSend)
{
nErrFlag = IP_SERVER_CLOSE(dvWeb.PORT) ;
if(nErrFlag == 0)
{
nWebServerState = SERVER_STOPPED ;
//fnWebDeBug("'Server Successfuly Closed. >-line-<',ITOA(__LINE__),'>'",1);
}
else if(nErrFlag == 9)
{
//fnWebDeBug("'Server Already Closed. >-line-<',ITOA(__LINE__),'>'",1);
WAIT 300 'ERROR_DELAY_RESTART'
{
//fnWebDeBug("'Server Stop ERR: Delayed Restart. >-line-<',ITOA(__LINE__),'>'",1) ;
nWebServerState = SERVER_STOPPED ;
}
}
else
{
//fnWebDeBug("'Server Shut Down Error. Returned Error: "',itoa(nErrFlag),'". >-line-<',ITOA(__LINE__),'>'",1);
WAIT 300 'ERROR_DELAY_RESTART'
{
//fnWebDeBug("'Server Stop ERR: Delayed Restart. >-line-<',ITOA(__LINE__),'>'",1) ;
nWebServerState = SERVER_STOPPED ;
}
}
}
RETURN ;
}
DEFINE_FUNCTION CHAR[2] fn2DHEX(INTEGER iInteger) //keep in case you ever need to change shadow colors
{
LOCAL_VAR CHAR cHexTemp[4] ;
LOCAL_VAR INTEGER nScaledInt ;
cHexTemp = '00' ;
nScaledInt = TYPE_CAST(iInteger * 2.55) ;
cHexTemp = right_string("cHexTemp,ITOHEX(nScaledInt)",2) ;
////fnWebDeBug("'fn2DHEX value in int = ',itoa(nScaledInt),', Hex of (int x 2.55) = ',cHexTemp,'. >-line-<',ITOA(__LINE__),'>'",1) ;
RETURN cHexTemp ;
}
DEFINE_FUNCTION CHAR[100] fnGET_IPServer_Error(SLONG iError)
{
STACK_VAR CHAR cErrMsg[100] ;
SELECT
{
ACTIVE(iError == 0): // this won't happen here
{
cErrMsg = "'Web Server: operation was successful'" ;
nWebServerState = SERVER_READY ;
nConnectAttempts = 0 ;
}
ACTIVE(iError == -1): // invalid server port
{
cErrMsg = "'Web Server: invalid server port'" ;
nWebServerState = SERVER_DISABLED ;
}
ACTIVE(iError == -2): // invalid value for Protocol
{
cErrMsg = "'Web Server: invalid protocol'" ;
nWebServerState = SERVER_DISABLED ;
}
ACTIVE(iError == -3): // unable to open communication port with server
{
cErrMsg = "'Web Server: unable to open port'" ;
nWebServerState = SERVER_DISABLED ;
}
/////////////////////////////////////////////////////////////////////////
ACTIVE(iError == 1): // invalid server address
{
cErrMsg = "'Web Server: invalid server address'" ;
nWebServerState = SERVER_DISABLED ;
}
ACTIVE(iError == 2): // invalid server port
{
cErrMsg = "'Web Server: invalid server port'" ;
nWebServerState = SERVER_DISABLED ;
}
ACTIVE(iError == 3): // invalid value for Protocol
{
cErrMsg = "'Web Server: invalid protocol'" ;
nWebServerState = SERVER_DISABLED ;
}
ACTIVE(iError == 4): // unable to open communication port with server
{
cErrMsg = "'Web Server: unable to open port'" ;
nWebServerState = SERVER_DISABLED ;
}
ACTIVE(iError == 6): // Connection refused
{
cErrMsg = "'Web Server: connection refused'" ;
nWebServerState = SERVER_DISABLED ;
}
ACTIVE(iError == 7): // Connection timed out
{
cErrMsg = "'Web Server: connection timed out'" ;
nWebServerState = SERVER_DISABLED ;
WAIT 300 'ERROR_DELAY_RESTART'
{
nWebServerState = SERVER_STOPPED ;
}
}
ACTIVE(iError == 8) : // WINGENERIC connection error
{
cErrMsg = "'Web Server: unknown connection error'" ;
nWebServerState = SERVER_DISABLED ;
}
ACTIVE(iError == 9): // Already closed
{
cErrMsg = "'Web Server: connection already closed'" ;
nWebServerState = SERVER_DISABLED ;
WAIT 300 'ERROR_DELAY_RESTART'
{
nWebServerState = SERVER_STOPPED ;
}
}
ACTIVE(iError == 10): // Binding error
{
cErrMsg = "'Web Server: binding error'" ;
nWebServerState = SERVER_DISABLED ;
WAIT 300 'ERROR_DELAY_RESTART'
{
nWebServerState = SERVER_STOPPED ;
}
}
ACTIVE(iError == 11): // Listening error
{
cErrMsg = "'Web Server: invalid server address'" ;
nWebServerState = SERVER_DISABLED ;
}
ACTIVE(iError == 14): // Local port already used
{
cErrMsg = "'Web Server: port in use'" ;
nWebServerState = SERVER_DISABLED ;
WAIT 300 'ERROR_DELAY_RESTART'
{
nWebServerState = SERVER_STOPPED ;
}
fnCloseWebServer() ;
}
ACTIVE(iError == 15): // UDP socket already listening
{
cErrMsg = "'Web Server: UDP socket already listening'" ;
nWebServerState = SERVER_DISABLED ;
}
ACTIVE(iError == 16): // Too many open sockets
{
cErrMsg = "'Web Server: Too many open sockets'" ;
nWebServerState = SERVER_DISABLED ;
WAIT 300 'ERROR_DELAY_RESTART'
{
nWebServerState = SERVER_STOPPED ;
}
}
ACTIVE(iError == 17): //Local port not open'
{
cErrMsg = "'Local port not open'" ;
nWebServerState = SERVER_DISABLED ;
WAIT 300 'ERROR_DELAY_RESTART'
{
nWebServerState = SERVER_STOPPED ;
}
}
ACTIVE(1): //
{
cErrMsg = "'ONERROR NO MATCH. ERROR# ',itoa(iError)" ;
nWebServerState = SERVER_DISABLED ;
WAIT 300 'ERROR_DELAY_RESTART'
{
nWebServerState = SERVER_STOPPED ;
}
}
}
RETURN cErrMsg ;
}
DEFINE_FUNCTION SLONG fnFileRead(CHAR icReadFile[],INTEGER inReadFStrLen) //body commented out
{(*
stack_var slong nReadFHandle ;
nReadFHandle = file_open(icReadFile,FILE_READ_ONLY) ;
if(nReadFHandle > 0)
{
//fnWebDeBug("'WebDeBug fnOpenFile. File_Open successful for *',
icReadFile,'*! line-<',ITOA(__LINE__),'>'",1) ;
nReadFResult = file_read(nReadFHandle,cReadFileBuf,inReadFStrLen) ;
if(nReadFResult > 0)
{
//fnWebDeBug("'WebDeBug fnReadFile. File_Read OK. Rcvd: a ',
itoa(nReadFResult),' CHAR String! line-<',ITOA(__LINE__),'>'",1) ;
}
else
{
stack_var char cErrorMsg [20] ;
switch (itoa(nReadFResult))
{
case '-9': {cErrorMsg = 'end-of-file reached'} ;
case '-6': {cErrorMsg = 'invalid parameter'} ;
case '-5': {cErrorMsg = 'disk I/O error'} ;
case '-1': {cErrorMsg = 'invalid file handle'} ;
case '-0': {cErrorMsg = 'zero bits returned?'} ;
}
//fnWebDeBug("'WebDeBug fnReadFile. Bad Read_File: ',cErrorMsg,
'! line-<',ITOA(__LINE__),'>'",1) ;
//fnWebDeBug("'WebDeBug fnReadFile. FilePath: ',icReadFile,
'! line-<',ITOA(__LINE__),'>'",1) ;
}
file_close(nReadFHandle) ;
}
else
{
stack_var char cErrorMsg [40] ;
switch (itoa(nReadFHandle))
{
case '-2': {cErrorMsg = 'invalid file path or name'} ;
case '-5': {cErrorMsg = 'disk I/O error'} ;
case '-3': {cErrorMsg = 'invalid value supplied for IOFlag'} ;
}
//fnWebDeBug("'WebDeBug fnOpenFile. Bad Open_File: ',cErrorMsg,
'! line-<',ITOA(__LINE__),'>'",1) ;
//fnWebDeBug("'WebDeBug fnOpenFile. FilePath: ',icReadFile,
'! line-<',ITOA(__LINE__),'>'",1) ;
}
file_close(nReadFHandle) ;
RETURN nReadFResult ;
*)
}
DEFINE_FUNCTION fnBeginReadingFiles() //body commented out
{
(*
nReading = 1 ;
WHILE(nFileReadIndx < nFileInsertIndx)
{
if(fnFileRead(cFile_Q_Arry[nFileReadIndx],MAX_READ_FILE_LENGTH))
{
fnWebPageOut(PAGE_SEND_FILES) ;
cFile_Q_Arry[nFileReadIndx] = '' ; //empty after it's sent!
nFileReadIndx ++ ;
}
else
{
cFile_Q_Arry[nFileReadIndx] = '' ; //invalid so clear and move on!
nFileReadIndx ++ ;
}
}
nReading = 0 ;
nFileInsertIndx = 1 ;//reset values when complete
nFileReadIndx = 1 ;
*)
}
DEFINE_FUNCTION CHAR[MAX_LEN_STR_MSG] fnHEADER_200OK(INTEGER iLengthContent)
{
STACK_VAR CHAR cWebHead[MAX_LEN_STR_MSG] ;
cWebHead = "'HTTP/1.1 200 OK',CRLF,
'Date: ',cWebCurDateTime,CRLF,
'Expires: ',cWebExpDateTime,CRLF,
'Connection: keep-alive',CRLF,
'Content-Type: text/html',CRLF,
'Server: AMX NetLinx',CRLF" ;
if(length_string(cRXCookie)) //// Set-Cookie: DLILPC= try to force our own cookie
{
cWebHead = "cWebHead,'Cookie: JSESSIONID=',cRXCookie,CRLF" ;
}
else
{
cWebHead = "cWebHead,'Cookie: JSESSIONID=""',CRLF" ;
}
cWebHead = "cWebHead,
'Content-Length: ',itoa(iLengthContent), //no cr or lf after content length?
CRLF,
CRLF" ;
RETURN cWebHead ;
}
//'Cache-Control: max-age=2592000',CRLF,
//'Expires: Mon, 22 Nov 2010 23:18:54 EST',CRLF,
//'Last-Modified: ',DAY,', ',cWebCurDateTime,' ',TIME,' EST',CRLF,
//'ETag: "1234a-56bc-78d70435"',CRLF" ;
DEFINE_FUNCTION CHAR[MAX_LEN_STR_MSG] fnHEADER_200OK_SetCookie(INTEGER iLengthContent)
{
STACK_VAR CHAR cWebHead[MAX_LEN_STR_MSG] ;
cWebHead = "'HTTP/1.1 200 OK',CRLF,
'Date: ',cWebCurDateTime,CRLF,
'Expires: ',cWebExpDateTime,CRLF,
'Connection: keep-alive',CRLF,
'Content-Type: text/html',CRLF,
'Server: AMX NetLinx',CRLF,
'Set-Cookie: JSESSIONID=',AMX_MOBILE_COOKIE,CRLF,
'Content-Length: ',itoa(iLengthContent), //no cr or lf after content length?
CRLF,
CRLF" ;
RETURN cWebHead ;
}
DEFINE_FUNCTION CHAR[MAX_LEN_STR_MSG] fnHEADER_200OK_Files(SLONG iLengthContent)
{
STACK_VAR CHAR cWebHead[MAX_LEN_STR_MSG] ;
cWebHead = "'HTTP/1.0 200 OK',CRLF,
'Date: ',cWebCurDateTime,CRLF,
'Server: AMX NetLinx',CRLF,
'Last-Modified: Wed, 11 Feb 2009 09:05:55 EST',CRLF,
'Cookie: JSESSIONID=',cRXCookie,CRLF,
'Connection: keep-alive',CRLF,
'Content-Type: image/jpeg',CRLF, //type="image/x-icon"
'Content-Length: ',itoa(iLengthContent), //no cr or lf after content length?
CRLF,
CRLF" ;
RETURN cWebHead ;
}
DEFINE_FUNCTION CHAR[MAX_LEN_STR_MSG] fnHEADER_202()
{
STACK_VAR CHAR cWebHead[MAX_LEN_STR_MSG] ;
cWebHead = "'HTTP/1.1 202 Accepted',CRLF,
'Date: ',cWebCurDateTime,CRLF,
'Server: AMX NetLinx',CRLF" ;
if(length_string(cRXCookie))
{
cWebHead = "cWebHead,'Cookie: JSESSIONID=',cRXCookie,CRLF" ;
}
else
{
cWebHead = "cWebHead,'Cookie: JSESSIONID=""',CRLF" ;
}
cWebHead = "cWebHead,'Connection: keep-alive',CRLF,
CRLF" ;
RETURN cWebHead ;
}
DEFINE_FUNCTION CHAR[MAX_LEN_STR_MSG] fnHEADER_204()
{
STACK_VAR CHAR cWebHead[MAX_LEN_STR_MSG] ;
cWebHead = "'HTTP/1.1 204 No Response',CRLF,
'Date: ',cWebCurDateTime,CRLF,
'Server: AMX NetLinx',CRLF,
'Cookie: JSESSIONID=',cRXCookie,CRLF,
'Connection: keep-alive',CRLF,
CRLF" ;
RETURN cWebHead ;
}
DEFINE_FUNCTION CHAR[MAX_LEN_STR_MSG] fnHEADER_304()
{
STACK_VAR CHAR cWebHead[MAX_LEN_STR_MSG] ;
cWebHead = "'HTTP/1.1 304 Not Modified',CRLF,
'Date: ',cWebCurDateTime,CRLF,
'Server: AMX NetLinx',CRLF,
'Cookie: JSESSIONID=',cRXCookie,CRLF,
'Connection: keep-alive',CRLF,
//'ETag: "681194-65b-4081e43c"',CRLF, need the tag to use
CRLF" ;
RETURN cWebHead ;
}
DEFINE_FUNCTION CHAR[MAX_LEN_STR_MSG] fnHEADER_404()
{
STACK_VAR CHAR cWebHead[MAX_LEN_STR_MSG] ;
cWebHead = "'HTTP/1.1 404 Not found',CRLF,
'Date: ',cWebCurDateTime,CRLF,
'Server: AMX NetLinx',CRLF,
'Cookie: JSESSIONID=',cRXCookie,CRLF,
'Connection: Keep-Alive',CRLF,
CRLF" ;
RETURN cWebHead ;
}
DEFINE_FUNCTION CHAR[MAX_LEN_STR_MSG] fnCSS_IncludeRefresh()
//http://www.w3schools.com/HTMLDOM/met_loc_replace.asp
//http://www.jibbering.com/2002/4/httprequest.html
//http://www.jibbering.com/2002/4/httprequest.html
//http://www.w3schools.com/XML/xml_http.asp
//http://www.w3.org/TR/XMLHttpRequest/
//http://msdn.microsoft.com/en-us/library/ms535157(VS.85).aspx
//http://blogs.telerik.com/files/AjaxPart1.pdf
//http://msdn.microsoft.com/en-us/library/ms757849(VS.85).aspx
{
STACK_VAR CHAR cCSS[MAX_LEN_STR_MSG] ;
cCSS = "cCSS,
'var obj = null;',$0A,
'function getURL(url, callBackFunc)
{
obj = new XMLHttpRequest();
obj.onreadystatechange = callBackFunc;
obj.open("GET", url, true);
obj.send(null);
obj.onreadystatechange = callBackFunc;
return obj;
}',$0A,
'function getResponse(obj)
{
var data = null;
if ( obj != null )
{
if (obj.readyState == 4)
{
if (obj.status == 200)
{
data = obj.responseText;
}
}
}
return data;
}',$0A,
'var changeReq = null;',$0A,
'function checkChange()
{
changeReq = getURL("',cWebURLPathRefresh,'", takeAction);
}',$0A,
'function takeAction()
{
if(changeReq)
{
var data = getResponse(changeReq);
if ( data != null)
{
reloadPage();
}
}
}',$0A,// ',cData2,' = data;
//'var updateReq = null;',$0A,
//
//'function updateContent()
//
// {
// updateReq = getURL("',cWebURLPathReFresh,'", doUpdate);
// }',$0A,
'function reloadPage()
{
window.location.replace("',cWebURLPathHome,'")
}',$0A, //window.location.reload()getURL("',cWebURLPathHome,'", DoNothing);
'function DoNothing()
{
var nothing = null;
}',$0A" ;//give it something to do?
//'function doUpdate()
//
// {
// if (updateReq)
// {
// var data = getResponse(updateReq);
// if ( data != null )
// {
// reloadPage();
// }
// }
// }',$0A,$0A,
cCSS = "cCSS,'setInterval("checkChange()", ',itoa(nAutoRefreshTime),');',$0A,$0A" ;
RETURN cCSS ;
}
DEFINE_FUNCTION CHAR[MAX_LEN_STR_MSG] fnCSS_BLACKBERRY(INTEGER iIncludeRefresh(*http://na.blackberry.com/eng/deliverables/6176/HTML_ref_meta_564143_11.jsp*))
{
STACK_VAR CHAR cCSS[MAX_LEN_STR_MSG] ;
cCSS = fnCSS_iPHONE(nAutoRefresh) ;//temp
RETURN cCSS ;
}
DEFINE_FUNCTION CHAR[MAX_LEN_STR_MSG] fnCSS_iPHONE(INTEGER iIncludeRefresh)
{
//STACK_VAR INTEGER i ; //needed to create new shadow colors list
STACK_VAR CHAR cCSS[MAX_LEN_STR_MSG] ;
STACK_VAR CHAR cBG_Color[6] ; //needed to make no show button invisible
STACK_VAR CHAR cBtn_Width[3] ;
STACK_VAR CHAR cBtn_Height[2] ;
STACK_VAR CHAR cBtn_Border_Type[6] ;
STACK_VAR CHAR cBtn_Border_Size[26] ;
STACK_VAR CHAR cBtn_Font_Size[2] ;
STACK_VAR CHAR cBtn_Font_Weight[6] ;
STACK_VAR CHAR cBtn_Border_Radius[2] ; //1234567890123456789012 n= posibble number n8 coulb be 18 for ex.
STACK_VAR CHAR cBtn_Shadow_x[2] ; // n8px n6px 40px #000000
STACK_VAR CHAR cBtn_Shadow_y[2] ; // n8px n6px 40px #000000
STACK_VAR CHAR cBtn_Shadow_Blur[2] ; // n8px n6px 40px #000000
cBG_Color = '080808' ;
cBtn_Width = '100' ;
cBtn_Height = '30' ;
cBtn_Border_Type = 'outset' ;
cBtn_Border_Size = '3' ;
cBtn_Font_Size = '9' ;
cBtn_Font_Weight = 'normal' ;
cBtn_Border_Radius = '15' ; // 1/2 OF THE BTN HEIGHT
cBtn_Shadow_x = '8' ;
cBtn_Shadow_y = '6' ;
cBtn_Shadow_Blur = '40' ;
//cBtn_Shadow_Str = '8px 6px 40px #000000' ; /x off , y off , shadow blur, color
cCSS = "'<style type="text/css">',$0A,
'body{
margin: 0;
font-family: "trebuchet ms",helvetica,sans-serif;
background: #505050 ;
color: #FFFFFF;
}
.container{
position: absolute;
width: 100%;
}
body[orient="profile"] .container{
height: 436px;
}
body[orient="landscape"] .container{
height: 258px;
}
.toolbar{
position: absolute;
width: 100%;
height: 60px;
font-size: 28pt;
}
body[orient="landscape"] .toolbar{
height: 30px;
font-size: 16pt;
}
.anchorTop{
top: 0;
}
.anchorBottom{
bottom: 0;
}
.center{
position: absolute;
top: 60px;
bottom: 60px;
}
body[orient="landscape"] .center{
top: 50px;
bottom: 30px;
}
body{
margin: 0;
padding: 0;
width: 320px;
height: 416px;
font-family: "trebuchet ms",helvetica,sans-serif;
-webkit-user-select: none;
cursor: default;
-webkit-text-size-adjust: none;
}
.main{
overflow: hidden;
position: relative;
}
.header{
position: relative;
height: 40px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
background-color: rgb(111, 135, 168);
border-top: 1px solid rgb(179, 186, 201);
border-bottom: 1px solid rgb(73, 95, 144);
color: white;
font-size: 20px;
text-shadow: rgba(0, 0, 0, 0.6) 0 -1px 0;
font-weight: bold;
text-align: center;
line-height: 42px;
}'" ;
//cCSS = "cCSS,'
//table.title{
// width: 100%;
// height: 50px;
// position: absolute;
// top: 0px;
// left: 0px;
// }
cCSS = "cCSS,'
table.curpage{
width: 100%;
height: 24px;
position: absolute;
top: 34px;
left: 0px;
}
table.btns{
width: 100%;
height: 240px;
position: absolute;
top: 68px;
left: 0px;
}'" ;
//tr{
// empty-cells: show;
// width: 100%;
// height: 40px;