-
Notifications
You must be signed in to change notification settings - Fork 0
/
pathfinder.c
1346 lines (1189 loc) · 42 KB
/
pathfinder.c
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
/* ****************PATH FINDER******************
This function sorts the request list attending to new requset and type
of the services that chosen by various parts of program.
********************************************* */
char pathfinder(char request, char sertype)
{
//Defining local variables
unsigned char pf1 = 0 , pf2 = 0 , pf3 = 0 , pf4 = 0 , pf5=0;
unsigned char temp_al[64] = {0};
if(sertype==32)
{
pf2=0;
beep_request=0;
while(AL[pf2]){AL[pf2]=0;
_al[pf2]=0;
pf2++;};
return 0;
}
if(Navistrategy=='d')
{
/////Down-Collective Movement Strategy
if(sertype==4)return 0;
else
if(sertype==2)
{
pf5=Undergroundno;
if(Groundexist!=0)pf5++;
if(request>pf5)sertype=4;
}
}
if(!floor)return 0;
if(opmode!='n')return 0;
if(request>Floorsno)return 0;
#ifndef BLOCK_DATE_DISABLE
if((Expired_date==0xFA)&&(Expired_date==0xFA))return 0;
#endif
switch(sertype)
{
//Sertype=0x01 means Car Request
case 1 :
if(!request)return 0;
if(OVLC||FTOC||FLTC)return 0;
if(firemf&&AL[0])return 0;
if(VIPmf&&AL[0])return 0;
// if(!floorvalidity(request))return 0;
break;
//Sertype=0x04 means Down-directed Hall Request
case 4 :
//Sertype=2 means Up-directed Hall Request
// or none-directed Hall Request
case 2 :
if(!request)return 0;
if(FTOC||OVLC||FULC||FLTC||firemf||VIPmf)return 0;
if(!floorvalidity(request))return 0;
break;
//Sertype=0x08 is for clearing the recent request
case 8 :
for(pf1=1;pf1<64;pf1++)
{AL[pf1-1]=AL[pf1];
_al[pf1-1]=_al[pf1];}
AL[63]=0;
_al[63]=0;
if(parkmf)parkmf=0;
if(!AL[0])
{direction=0;
return 0;}
if(AL[0]>floor)direction=1;
if(AL[0]<floor)direction=2;
return 0;
break;
//Sertype=0x10 means delete hall call
case 16:
for(pf1=0;AL[pf1]!=0;pf1++)
{pf3=_al[pf1];
if((pf3&0x01)&&((pf3&0x02)||(pf3&0x04)))_al[pf1]=1;}
pf2=0;
pf3=0;
while(AL[pf2])
{if(_al[pf2]==1){temp_al[pf3]=AL[pf2];
AL[pf2]=0;
pf3++;};
_al[pf2]=0;
pf2++;
};
pf2=0;
while(temp_al[pf2]){_al[pf2]=1;
AL[pf2]=temp_al[pf2];
pf2++;};
for(pf1=pf2;pf1<64;pf1++)
{AL[pf1]=0;
_al[pf1]=0;};
if(!AL[0])direction=0;
else if(AL[0]>floor)direction=1;
else if(AL[0]<floor)direction=2;
return 0;
break;
//Sertype=0x20 means delete the all of AL list
case 32:
break;
case 64 :
for(pf1=1;pf1<64;pf1++)
{
if(AL[pf1-1]==0){pf2=0;break;}
if(AL[pf1-1]==request && (_al[pf1-1]&0x01))
{
pf2=_al[pf1-1];
if(pf2&0xFE)
{
_al[pf1-1] &= 0xFE;
return 2; //no turn off leds
}
pf2=pf1;
break;
}
}
if(pf2==0)return 0;
for(pf1=pf2;pf1<64;pf1++)
{AL[pf1-1]=AL[pf1];
_al[pf1-1]=_al[pf1];}
AL[63]=0;
_al[63]=0;
//if(pf2!=1)return 1;
if(!AL[0]){direction=0;return 1;}
if(AL[0]>floor)direction=1;
if(AL[0]<floor)direction=2;
return 1;
break;
default :
return 0;
}; //switch end
if(standbymf)
{
standbymf=0;
if(request==floor)return 0; //for exit from standby mode
}
if(stayinstair&&(request==floor))
{
if(_hall_button_during_doorclose=='a')
_hall_button_during_doorclose=1;
return 0;
}
if(firemf)
{
if(AL[0])return 0; //just one request at time
else
{AL[0]=request;
_al[0]=sertype;
if(request>floor)direction=1;
if(request<floor)direction=2;
return 1;
};
}
else
if(VIPmf)
{
if(AL[0])return 0; //just one request at time
else
{AL[0]=request;
_al[0]=sertype;
if(request>floor)direction=1;
if(request<floor)direction=2;
return 1;
};
}
if(parkmf)
{
if(!AL[0]) //place request if list was empty
{AL[0]=request;
_al[0]=sertype;
if(request>floor)direction=1;
if(request<floor)direction=2;
return 1;};
if(request==Parkfloor)
{parkmf=0;
NNOD=0;
return 1;}; //request is same park floor
if((!I)&&stayinstair)
{
parkmf=0;
AL[0]=request;
_al[0]=sertype;
if(request>floor)direction=1;
if(request<floor)direction=2;
return 1;}; //not moving yet
if(AL[0]==floor)
{AL[1]=request;
_al[1]=sertype;
NNOD=1;
parkmf=0;
return 1;}; //being stop in stair
if(((request>floor)&&(direction==1))||((request<floor)&&(direction==2)))
{AL[0]=request;
_al[0]=sertype;
parkmf=0;
return 1;}; //request in same path
if((request<=floor)&&(direction==1))
{AL[0]=floor+1;
_al[0]=1;
AL[1]=request;
_al[1]=sertype;
NNOD=1;
parkmf=0;
return 1;};
if((request>=floor)&&(direction==2))
{AL[0]=floor-1;
_al[0]=1;
AL[1]=request;
_al[1]=sertype;
NNOD=1;
parkmf=0;
return 1;};
}; //end of park mode service
if(!AL[0])
{AL[0]=request;
_al[0]=sertype;
if(request<floor)direction=2;
if(request>floor)direction=1;
return 1;};
//if((Navistrategy=='f')||((Navistrategy=='d')&&(sertype==2)))
if(Navistrategy=='f')
{
pf1=0;
while(AL[pf1])
{
if(AL[pf1]==request)
{if(_al[pf1]==3)return 0;
if(sertype!=_al[pf1])
{_al[pf1]=3;
return 1;};
if(sertype==_al[pf1])return 0;
}
pf1++;
if(pf1==64)break;
}; //seeking for request in List
};
/*
if(Navistrategy=='d')
{
/////Down-Collective Movement Strategy
/////
if(direction==2)
{if(request<floor)
{pf1=0;
while(AL[pf1])
{if(request>=AL[pf1])break;
pf1++;
if(AL[pf1-1]<AL[pf1])break;
};
}
else if(request>=floor)
{pf1=0;
while(AL[pf1])
{pf1++;
if(AL[pf1]>AL[pf1-1])break;
};
if(sertype==1)
{
while(AL[pf1])
{pf2=_al[pf1];
if(!(pf2&0x01))break;
if(request<=AL[pf1])break;
pf1++;
};
}
else if(sertype==2)
{
do{pf2=_al[pf1];
if(!(pf2&0x01))break;
pf1++;
}while(AL[pf1]);
while(AL[pf1])
{if(request>=AL[pf1])break;
pf1++;};
};
};
};
if(direction==1)
{if((request>floor)&&(sertype==1))
{pf1=0;
if(AL[0]==floor)pf1=1;
while(AL[pf1])
{pf2=_al[pf1];
if(!(pf2&0x01))break; //if end of car call, break
if(request<=AL[pf1])break;
pf1++;
if(AL[pf1]<AL[pf1-1])break; //*******
};
}
else
{pf1=0;
if(AL[0]==floor)pf1=1;
pf2=_al[pf1];
while((pf2&0x01)&&AL[pf1]>floor)
{pf1++;
pf2=_al[pf1];
};
while(AL[pf1])
{if(request>=AL[pf1])break;
pf1++;
};
};
};
pf2=pf1;
while(AL[pf2])
{if(AL[pf2]==request)
{sertype|=_al[pf2];
while(AL[pf2]||_al[pf2])
{AL[pf2]=AL[pf2+1];
_al[pf2]=_al[pf2+1];
pf2++;
if(pf2==63)break;
};
AL[63]=0;
_al[63]=0;
break;
};
pf2++;
};
};
*/
if(Navistrategy=='f')
{
/////Full-Collective Movement Strategy
/////
if(direction==1) //upward
{if(request>floor)
{pf1=0;
while(request>AL[pf1])
{pf1++;
if(!AL[pf1])break;
if(AL[pf1]<AL[pf1-1])break;};
};
if(request<=floor)
{pf1=0;
while(AL[pf1])
{pf1++;
if(!AL[pf1])break;
if(AL[pf1]<AL[pf1-1])break;};
if(AL[pf1])
{while(AL[pf1])
{if(AL[pf1]<request)break;
pf1++;};
};
};
};
if(direction==2)
{if(request<floor)
{pf1=0;
while(request<AL[pf1])
{pf1++;
if(!AL[pf1])break;
if(AL[pf1]>AL[pf1-1])break;};
};
if(request>=floor)
{pf1=0;
while(AL[pf1])
{pf1++;if(!AL[pf1])break;
if(AL[pf1]>AL[pf1-1])break;};
if(AL[pf1])
{while(AL[pf1])
{if(AL[pf1]>request)break;
pf1++;};
};
};
};
pf2=0;
while(pf2<=pf1)
{if(AL[pf2]==request)
{_al[pf2]|=sertype;
return 1;
};
pf2++;
};
while(AL[pf2])
{if(AL[pf2]==request)
{sertype|=_al[pf2];
while(AL[pf2])
{AL[pf2]=AL[pf2+1];
_al[pf2]=_al[pf2+1];
pf2++;
if(pf2==63)break;
};
AL[63]=0;
_al[63]=0;
};
pf2++;
};
};
//if(Navistrategy=='s')
if((Navistrategy=='s')||(Navistrategy=='d'))
{
/////Collective-Selective Movement Strategy
/////
if(direction==1)
{
if(request>floor)
{
pf1=0;
if(AL[0]==floor)pf1=1; ////
if((sertype==1)||(sertype==2))
{
while(AL[pf1])
{
pf2=_al[pf1];
if(request<AL[pf1])break;
if(!((pf2&0x01)||(pf2&0x02)))break;
if((AL[pf1+1]<AL[pf1])&&AL[pf1+1])
{pf1++;
break;};
//*********
pf1++;
};
};
};
if(((request<=floor)&&(sertype==1))||(sertype==4))
{
pf1=0;
if(AL[0]==floor)pf1=1; ////
while(AL[pf1])
{
pf2=_al[pf1];
if(((pf2&0x01)||(pf2&0x02))&&(AL[pf1]>floor))
{pf1++;
continue;};
break;
};
while(AL[pf1])
{
pf2=_al[pf1];
if(request>AL[pf1])break;
if(!((pf2&0x01)||(pf2&0x04)))break;
pf1++;
};
};
if((request<=floor)&&(sertype==2))
{
pf1=0;
if(AL[0]==floor)pf1=1; ////
while(AL[pf1])
{
if(_al[pf1]==2)
if(AL[pf1]<=floor)break;
pf1++;
};
while(AL[pf1])
{
if(request<=AL[pf1])break;
pf1++;
};
};
};
if(direction==2)
{
if(request<floor)
{
pf1=0;
if(AL[0]==floor)pf1=1; ////
if((sertype==1)||(sertype==4))
{
while(AL[pf1])
{
pf2=_al[pf1];
if(request>AL[pf1])break;
if(!((pf2&0x01)||(pf2&0x04)))break;
if(AL[pf1+1]>AL[pf1])
{pf1++;
break;};
pf1++;
};
};
};
if(((request>=floor)&&(sertype==1))||(sertype==2))
{
pf1=0;
if(AL[0]==floor)pf1=1; ////
while(AL[pf1])
{
pf2=_al[pf1];
if(((pf2&0x01)||(pf2&0x04))&&(AL[pf1]<floor))
{pf1++;
continue;};
break;
};
while(AL[pf1])
{
pf2=_al[pf1];
if(request<AL[pf1])break;
if(!((pf2&0x01)||(pf2&0x02)))break;
pf1++;
};
};
if((request>=floor)&&(sertype==4))
{
pf1=0;
if(AL[0]==floor)pf1=1; ////
while(AL[pf1])
{
if(_al[pf1]==4)
if(AL[pf1]>=floor)break;
pf1++;
};
while(AL[pf1])
{
if(request>=AL[pf1])break;
pf1++;
};
};
};
pf2=0;
while(pf2<=pf1)
{
if(AL[pf2]==request)
{
_al[pf2]|=sertype;
return 1;
};
pf2++;
};
while(AL[pf2])
{
if(AL[pf2]==request)
{
sertype|=_al[pf2];
while(AL[pf2])
{
AL[pf2]=AL[pf2+1];
_al[pf2]=_al[pf2+1];
pf2++;
if(pf2==63)break;
};
AL[63]=0;
_al[63]=0;
};
pf2++;
};
};
//end of collective selective
//place request in the list at pf1-th row of it
pf2=62;
for(pf2=62;pf2>=pf1;pf2--)
{
if(pf2==255)break;
pf3=AL[pf2];
pf4=_al[pf2];
AL[pf2+1]=pf3;
_al[pf2+1]=pf4;
};
AL[pf1]=request;
_al[pf1]=sertype;
return 1;
}
/********************** Evaluation **************************
THIS PROGRAM SCORES A REQUEST FOR PLACEMENT IN
ANSWER LIST WITH ATTENTION TO ITS TYPE
IT IS FOLLOWING N.C. ALGORITHM
FOR SCORING REQUESTS
*******************************************************/
char Evaluation(unsigned char stair,unsigned char reqtype)
{
unsigned char diststraight,ev3,disttotal,stopsno,ev4=0;
unsigned char extremestair,extremestairL,extremestairH;
unsigned char requeststairs=0;
if(FTOC||OVLC||FULC||firemf||VIPmf)return 0; //Return 0 in special case
if(!floor)return 0;
if(!stair)return 0;
if((reqtype!=2)&&(reqtype!=4))return 0;
if(opmode!='n')return 0;
if(stair>Floorsno)return 0;
if(!floorvalidity(stair))return 0;
#ifndef BLOCK_DATE_DISABLE
if((Expired_date==0xFA)&&(Expired_date==0xFA))return 0;
#endif
if(floor>=stair)diststraight=floor-stair; //Calculate the straight distance
if(floor<stair)diststraight=stair-floor;
for(ev3=0;AL[ev3];ev3++)requeststairs++;
if(requeststairs>Floorsno)return 0;
requeststairs *= 2;
for(ev3=0;AL[ev3];ev3++)
if(AL[ev3]==stair)
{
ev4=2*(Floorsno);
if(ev4>=(ev3*3))ev4-=(ev3*3); //ev4 is evaluated when request is exist in list
break;
}
if(parkmf)
{
if((stair>floor)&&(direction==1)||(stair<floor)&&(direction==2)||(!direction))
{
return 2*(Floorsno)-diststraight;
}
else return 2*(Floorsno)-diststraight-1-1; //first for stop, second for redirection
}
if(!direction)return 2*(Floorsno)-diststraight;
//Calculating the Extreme-Stairs
extremestairH=floor;
extremestairL=floor;
for(ev3=0;AL[ev3];ev3++)
{
if(AL[ev3]>extremestairH)extremestairH=AL[ev3];
if(AL[ev3]<extremestairL)extremestairL=AL[ev3];
}
if(direction==1){extremestair=extremestairH;}
else if (direction==2)extremestair=extremestairL;
//Calculating un-straigt distance
if(extremestair>=stair)disttotal=extremestair-stair;
else if(extremestair<stair)disttotal=stair-extremestair; //disttotal is d'
// Collective-Selective Strategy
if(Navistrategy=='s')
{
if(!(reqtype==2||reqtype==4))return 0; //Only accept the hall call
//Car goes up toward request, in the same direction
if((direction==1)&&(reqtype==2)&&(stair>floor))
{
ev3 = 2*(Floorsno)-diststraight+1;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
};
//Car goes down toward request, in the same direction
if((direction==2)&&(reqtype==4)&&(stair<floor))
{
ev3 = 2*(Floorsno)-diststraight+1;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
};
//Car goes up toward request, but request is in other side
if((direction==1)&&(reqtype==4)&&(stair>floor))
{
if(stair<extremestair)
{
ev3 = 2*(Floorsno-disttotal)-diststraight+1;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
}
ev3 = 2*(Floorsno)-diststraight+1;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
}
//Car goes down toward request, but request is in other side
if((direction==2)&&(reqtype==2)&&(stair<floor))
{
if(stair>extremestair)
{
ev3 = 2*(Floorsno-disttotal)-diststraight+1;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
}
ev3 = 2*(Floorsno)-diststraight+1;
if(ev3>requeststairs)ev3 -= requeststairs;
return ev3;
}
//Car goes up backward request, and request is in other side
if((direction==1)&&(reqtype==4)&&(stair<=floor))
{
ev3 = 2*(Floorsno-disttotal)+diststraight;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
}
//Car goes down backward request, and request is in other side
if((direction==2)&&(reqtype==2)&&(stair>=floor))
{
ev3 = 2*(Floorsno-disttotal)+diststraight;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
}
//Car goes up backward request, in the same direction
if((direction==1)&&(reqtype==2)&&(stair<=floor))
{
if(extremestairL>floor)
{
ev3 = 2*(Floorsno-disttotal)-diststraight-1;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
}
ev3 = 2*(Floorsno-disttotal-extremestairL+floor)+diststraight-2;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
}
//Car goes down backward request,in the same direction
if((direction==2)&&(reqtype==4)&&(stair>=floor))
{
if(extremestairH<floor)
{
ev3 = 2*(Floorsno-disttotal)+diststraight-1;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
}
ev3 = 2*(Floorsno-disttotal-floor+extremestairH)+diststraight-2;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
}
}
// Collective-Down Strategy
else if(Navistrategy=='d')
{
//Car goes up toward request,existing a higher request in list.
if((direction==1)&&(stair>floor)&&(extremestair>stair))
{
ev3 = 2*(Floorsno-disttotal)-diststraight-1;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
}
//Car goes up toward request, not existing a higher request in list.
if((direction==1)&&(stair>floor)&&(extremestair<=stair))
{
ev3 = 2*Floorsno-diststraight;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
}
//Car goes up backward request.
if((direction==1)&&(stair<=floor))
{
ev3 = 2*(Floorsno-disttotal)+diststraight-1;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
}
//Car goes down toward request.
if((direction==2)&&(stair<floor))
{
ev3 = 2*Floorsno-diststraight;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
}
//Car goes down backward request,
if((direction==2)&&(stair>=floor))
{
//existing a higher request in list.
if(extremestairH>stair)
{
ev3 = 2*(Floorsno-extremestairH+extremestairL)+diststraight-2;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
}
//not existing a higher request in list
if(extremestairH<=stair)
{
ev3 = 2*(Floorsno-disttotal)+diststraight-1;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
}
}
}
//Full-Collective Strartegy
if(Navistrategy=='f')
{
//Car goes toward request.
if(((direction==1)&&(stair>floor))||((direction==2)&&(stair<floor)))
{
ev3 = 2*Floorsno-diststraight;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
}
//Car goes backward request.
if(((direction==1)&&(stair<=floor))||((direction==2)&&(stair>=floor)))
{
ev3 = 2*(Floorsno-disttotal)+diststraight-1;
if(ev3>requeststairs)ev3 -= requeststairs; else ev3=1;
if(ev4>ev3) return ev4;
return ev3;
}
}
else return 0;
}
unsigned char floorvalidity(unsigned char floorvalid)
{
unsigned char fv1=0,fv2=0,fv3,fv4;
fv1 = floorvalid % 8 ;
if(!fv1)fv1=8;
fv1--;
fv4= (floorvalid - 1) / 8;
fv2 = Maskfloor[fv4];
if(!((fv2>>fv1) & 0x01))return 0;
else return 1;
}
void setfloormask(unsigned char floormasked,unsigned char floorcond,unsigned char maskno)
{
unsigned char sfm1=0,sfm2=0,sfm3,sfm4;
if(!floormasked)return;
sfm4 = (floormasked-1)/8;
sfm1= floormasked % 8 ;
if(!sfm1)sfm1=8;
if(!floorcond)
{
sfm3=0xFE;
for(sfm2=1;sfm2<sfm1;sfm2++)
{
sfm3 <<= 1;
sfm3 |= 0x01;
}
switch(maskno)
{
case 0:
Maskfloor[sfm4] &= sfm3;
EE_Maskfloor[sfm4] = Maskfloor[sfm4];
break;
case 1:
FirstDoor[sfm4] &= sfm3;
EE_FirstDoor[sfm4] = FirstDoor[sfm4];
break;
case 2:
SecondDoor[sfm4] &= sfm3;
EE_SecondDoor[sfm4] = SecondDoor[sfm4];
break;
case 3:
HalfFloor[sfm4] &= sfm3;
EE_HalfFloor[sfm4] = HalfFloor[sfm4];
break;
}
delay_ms(1);
}
else
{
sfm3=0x01;
for(sfm2=1;sfm2<sfm1;sfm2++)
{
sfm3 <<= 1;
sfm3 &= 0xFE;
}
switch(maskno)
{
case 0:
Maskfloor[sfm4] |= sfm3;
EE_Maskfloor[sfm4] = Maskfloor[sfm4];
break;
case 1:
FirstDoor[sfm4] |= sfm3;
EE_FirstDoor[sfm4] = FirstDoor[sfm4];
break;
case 2:
SecondDoor[sfm4] |= sfm3;
EE_SecondDoor[sfm4] = SecondDoor[sfm4];
break;
case 3:
HalfFloor[sfm4] |= sfm3;
EE_HalfFloor[sfm4] = HalfFloor[sfm4];
break;
}
delay_ms(1);
}
}
unsigned char halffloorstatus(unsigned char floorvalid)
{
unsigned char hfs1=0,hfs2=0,hfs3,hfs4;
hfs1 = floorvalid % 8 ;
if(!hfs1)hfs1=8;
hfs1--;
hfs4= (floorvalid - 1) / 8;
hfs2 = HalfFloor[hfs4];
if(!((hfs2>>hfs1) & 0x01))return 0;
else return 1;
}
char Waiting_List_Manager(unsigned char Request_number,unsigned char Request_type
, unsigned char Evalue,unsigned char action
, unsigned char IPreceived,unsigned char UniqueIDreceived)
{
char i;
unsigned int wlm1;
unsigned char pc1,pc2;
//1 return the index of placed request in WL and 0xFF if was not succesful
//2 place the request in list and update nearestrequest
//3 compare the received request and update received Eval and IP in WL[]
//4 find the expired-time request related to nearestrequest
if(!Eth_number)return;
if(Grouptype=='s')return;
if(action=='w') //place in balank row
{
i=0;
while(WL[i].Req)
{i++;
if(i==4)return 0xFF;} // unsucessful