-
Notifications
You must be signed in to change notification settings - Fork 0
/
main__.c
20621 lines (17943 loc) · 672 KB
/
main__.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
//#define debug 7
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <90can128.h>
#include <delay.h>
// I2C Bus functions
#asm
.equ __i2c_port=0x0E ;PORTE
.equ __sda_bit=3
.equ __scl_bit=2
#endasm
#include <i2c.h>
// DS1307 Real Time Clock functions
#include <ds1307.h>
#include <lm75.h>
// include avrlib basics
#include "global.h"
#include "debug.h"
#include "net.h"
#include "debug.h"
#include "arp.h"
#include "icmp.h"
#include "ip.h"
#include "nic.h"
#include "can.h"
#include "defines.h"
#include "misc.h"
////////////////////////////// global variables//////////////////////////
//static volatile unsigned long UptimeMs;
unsigned char RecData=0,side=0,vel=0,Door_Status=0x03;
unsigned char buffer[100];
unsigned char DataBuff[10];
bit ReadyFlag=0,ReadyFlag2=0;
int ElavNum=1;
unsigned int node_address=0x00; //Main Address
unsigned char hour,min,sec;
unsigned char floor,w1,w2,w3,w5,w6;
int ptimer_preopening;
struct can_message current_message;
struct message_serial_format
{
unsigned char source;
unsigned char address;
unsigned char length;
unsigned char data[8];
}serial_current_message;
struct can_message can_send_history[15 - TxStaMob];
extern unsigned int can_rxfull_mobs;
extern unsigned char cansrshow;
unsigned char rx_buffer1[RX_BUFFER_SIZE1],tx_buffer1[TX_BUFFER_SIZE1],rx_index=0,Ready=0,Ready2=0;
unsigned char rx_buffer2[RX_BUFFER_SIZE1];
unsigned char rx_buff[RX_BUFFER_SIZE1],SentTimeout=0;
unsigned char tx_wr_index1,tx_rd_index1,tx_counter1;
unsigned char End_Temp=0,Address=0,SerialSource=0 , rs485show=0;
struct can_long_message long_message_buff,long_message_send_buff;
unsigned long int ID;
struct protocol_id_structure_sep sep_id;
////////////////////////////// Ethernet functions///////////////////////
void netstackInit(uint32_t ipaddress, uint32_t netmask, uint32_t gatewayip,char EthAddrOffset);
void netstackUDPIPProcess(unsigned int len, udpip_hdr* packet);
//void netstackTCPIPProcess(unsigned int len, tcpip_hdr* packet);
void netstackIPProcess(unsigned int len, ip_hdr* packet);
void processCommand(u16 len, u08* data);
void serviceLocal(void);
void netstackService(void);
u08* netstackGetBuffer(void);
unsigned long int assemble_ipdot(unsigned char,unsigned char,unsigned char,unsigned char);
///////////////////////////// Can Functions/////////////////////////////////////////////
// External Interrupt 5 service routine
interrupt [EXT_INT5] void ext_int5_isr(void) //***\\
{
if(!dir_cal)return;
if(!floor_cal)return;
if(Fsflag==2)
{
M_INT3 = ((PINE & 0x10)>>4)&0x01 ;
if(!CF3)
{
if(floor)_int5_en=2;
else _int5_en=1;
EIMSK&=(~0x20);
return;
}
else
{ if(floor)_int4_en=2;
else _int4_en=1;
}
}
if(dir_cal!=dir_prev)
{
dir_prev=dir_cal;
}
else
{
if(dir_cal==1)
{floor_cal++;
if(floor_cal>=Floorsno)floor_cal=0;
}
if(dir_cal==2)
{floor_cal--;
if(floor_cal<=1)floor_cal=0;
}
}
EIMSK=0x00; //disble interrupt
if(floor)_int5_en=2;
else _int5_en=1;
}
// External Interrupt 4 service routine
interrupt [EXT_INT4] void ext_int4_isr(void) //***\\
{
if(!dir_cal)return;
if(!floor_cal)return;
if(Fsflag==2) //jahat dar
{
M_INT4 = ((PINE & 0x20)>>5)&0x01 ;
if(!CF1)
{
if(floor)_int4_en=2;
else _int4_en=1; //not in level state
EIMSK&=(~0x10); //disbale current interrupt
return;
}
else //in level state
{
if(floor)_int5_en=2;
else _int5_en=1;
}
}
else return;
if(dir_cal!=dir_prev)
{
dir_prev=dir_cal;
}
else
{
if(dir_cal==1)
{floor_cal++;
if(floor_cal>=Floorsno)floor_cal=0;
}
if(dir_cal==2)
{floor_cal--;
if(floor_cal<=1)floor_cal=0;
}
}
EIMSK=0x00; //disble interrupts
if(floor)_int4_en=2;
else _int4_en=1;
}
// Timer 1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
TIMSK1=0x00;
ptimer++;
if(ptimer==60000)ptimer=0;
if(ptimer_preopening)ptimer_preopening++;
if(Eth_number)
{
netstackService(); // service the network
}
if(I) traveltimer++;
else traveltimer=0;
if(!_inp_in_use)interpreter();
LED_indicator();
supervisor();
if(beep_request_on)
{BUZ=1;
beep_request_on=0;}
else
if(beep_request)
{beep_request=0;
BUZ=0;
beep_request_on=1;}
// Reinitialize Timer 1 value
TCNT1H = 0x9E ;
TCNT1L = 0x58 ;
TIMSK1=0x01;
}
interrupt [TIM3_OVF] void timer3_ovf_isr(void)
{
TCNT3H=0xE1;
TCNT3L=0x7B;
if(!WDRS)
{
#asm("cli")
TIMSK0=0;TIMSK1=0;
TIMSK2=0;TIMSK3=0;
}
if(WDRS==1)
{
#asm("wdr")
WDRS=0;
}
if(SentTimeout==1)SentTimeout=2; //To restore Serial variables
else if(SentTimeout==2) // in critical Mode
{
End_Temp=0;
rx_index=0;
SentTimeout=0;
}
if(_int5_en==1)_int5_en=2;
else
if(_int5_en==2)_int5_en=3;
else if(_int5_en==3)
{
if(dir_cal)
{EIFR|=0x20;
EIMSK|=0x20;
}
_int5_en=0;
}
if(_int4_en==1)_int4_en=2;
else
if(_int4_en==2)_int4_en=3;
else if(_int4_en==3)
{
if(dir_cal)
{EIFR|=0x10;
EIMSK|=0x10;
}
_int4_en=0;
}
//if(BUZ==0)BUZ=1;
if(beep_en)
{BUZ=0;
beep_en=0;}
else BUZ=1;
if(LED_blink)LED_blink=0;
else LED_blink=1;
if(!blink_en)
{
PORTC.0=0;PORTC.1=0;
PORTC.2=0;PORTC.3=0;
OE_7seg=0;
return;
}
if(!OE_7seg)
{
PORTC.1=1;PORTC.2=1;
PORTC.3=1;OE_7seg=1;
return;
}
else
if(OE_7seg)
{
PORTC.1=0;PORTC.2=0;
PORTC.3=0;OE_7seg=0;
return;
}
}
interrupt [USART0_RXC] void usart0_rx_isr(void)
{
RecData = UDR0;
ReadyFlag =1;
ReadyFlag2 =1;
}
interrupt [USART1_RXC] void usart1_rx_isr(void)
{
char status,data,jtemp,ktemp;
status=UCSR1A;
data=UDR1;
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
{
if(rx_index==0)SentTimeout=1;
if (rx_index < RX_BUFFER_SIZE1)
{
rx_buff[rx_index]=data;
rx_index++;
}
else rx_index=0;
if (data==0xFF)
{
if (End_Temp==0)
End_Temp=1;
else
{
if(rx_index>5) //validity in end and start of data frame
{
if(rx_buff[3]==node_address)
{
Ready = 1;
rs485show = 1;
Address = rx_buff[3];
SerialSource = rx_buff[2];
for(jtemp=0;jtemp<rx_index-5;jtemp++) rx_buffer1[jtemp]=rx_buff[jtemp+4];
for(ktemp=jtemp;ktemp<=RX_BUFFER_SIZE1;ktemp++)rx_buffer1[ktemp]=0;
}
}
End_Temp=0;
rx_index=0;
SentTimeout=0;
}
}
else
End_Temp=0;
}
}
interrupt [USART1_TXC] void usart1_tx_isr(void)
{
if (tx_counter1)
{
--tx_counter1;
UDR1=tx_buffer1[tx_rd_index1];
if (++tx_rd_index1 == TX_BUFFER_SIZE1) tx_rd_index1=0;
}
else
PORTD.7=0;
}
void transmit_data_422(unsigned int SendData)
{
if (tx_counter1 || ((UCSR1A & DATA_REGISTER_EMPTY)==0))
{
tx_buffer1[tx_wr_index1]=SendData;
if (++tx_wr_index1 == TX_BUFFER_SIZE1) tx_wr_index1=0;
++tx_counter1;
}
else
{
PORTD.4=1;
delay_us(10);
UDR1=SendData;
}
}
void transmit_data_485(unsigned int SendData)
{
if (tx_counter1 || ((UCSR1A & DATA_REGISTER_EMPTY)==0))
{
tx_buffer1[tx_wr_index1]=SendData;
if (++tx_wr_index1 == TX_BUFFER_SIZE1) tx_wr_index1=0;
++tx_counter1;
}
else
{
PORTD.7=1;
delay_us(10);
UDR1=SendData;
}
}
unsigned char RS422_send_message(struct message_serial_format current_message_422)
{
unsigned char j,waitforsend=0;
delay_ms(2);
while(rx_index)
{if(++waitforsend>50)return;
delay_ms(1);}
transmit_data_422(0xFE);
transmit_data_422(0xFE);
transmit_data_422(current_message_422.source);
transmit_data_422(current_message_422.address);
for(j=0;j<current_message_422.length;j++)
transmit_data_422(current_message_422.data[j]);
transmit_data_422(0xFF);
transmit_data_422(0xFF);
}
unsigned char RS485_send_message(struct message_serial_format current_message_485)
{
unsigned char j,waitforsend=0;
while(rx_index)
{if(++waitforsend>50) return;
delay_ms(1);}
transmit_data_485(0xFE);
transmit_data_485(0xFE);
transmit_data_485(current_message_485.source);
transmit_data_485(current_message_485.address);
for(j=0;j<current_message_485.length;j++)
transmit_data_485(current_message_485.data[j]);
transmit_data_485(0xFF);
transmit_data_485(0xFF);
delay_ms(5);
return 0;
}
void main(void)
{
struct netEthAddr myEthAddress;
WDRS=1; //for Watchdog reset
delay_ms(100); //for starting up
initialize();
errormsg(0);
Write_7Seg(0,0);
#ifdef debug
printf("\r\n Start...");
#endif
WDRS=1; //for Watchdog reset
//rescueviamain();
set_default_values();
WDRS=1; //for Watchdog reset
if(Eth_number)
{
netstackInit(IPADDRESS, NETMASK, GATEWAY,Eth_number); //Unremark for Using Ethernet
delay_ms(100); //Unremark for Using Ethernet
// nicGetMacAddress(&myEthAddress.addr[0]); //Unremark for Using Ethernet
myEthAddress.addr[0] =0x30;
myEthAddress.addr[1] =0x46;
myEthAddress.addr[2] =0x46;
myEthAddress.addr[3] =0x49;
myEthAddress.addr[4] =0x43;
myEthAddress.addr[5] =0x45+Eth_number;
WDRS=1;
}
delay_ms(100);
WDRS=1; //for Watchdog reset
if (MCUSR & 8) //Reset by watchdog
{
// Watchdog Reset
MCUSR&=0xE0;
errormsg(36);
ptimer=0;
while(ptimer<30)
{
WDRS=1; //for Watchdog reset
delay_ms(100);
ptimer++; //delay 4 seconds in start
LED_indicator();
interpreter();
if(Eth_number)netstackService(); // service the network
}
errormsg(0);
}
while(1)
{
//service local stuff
// serviceLocal();
WDRS=1; //for Watchdog reset
ClearAllMailbox();
WDRS=1; //for Watchdog reset
delay_ms(100);
sep_id.dest_address = 0x00;
sep_id.source_address = node_address;
sep_id.message_num = 0;
sep_id.priority = 0;
ID = assemble_id(sep_id);
current_message.datalen=8;
current_message.ide=1;
current_message.rb=0;
current_message.rtr=0;
current_message.id=ID;
current_message.data[0]=0;
current_message.data[1]=0;
current_message.data[2]=0;
current_message.data[3]=0;
current_message.data[4]=0;
current_message.data[5]=0;
current_message.data[6]=0;
current_message.data[7]=0;
set_mobs_for_receive(8);
serial_current_message.length = 8;
serial_current_message.source = node_address;
serial_current_message.address = 0x00;
serial_current_message.data[0] = 0x00;
serial_current_message.data[1] = 0x00;
serial_current_message.data[2] = 0x00;
serial_current_message.data[3] = 0x00;
serial_current_message.data[4] = 0x00;
serial_current_message.data[5] = 0x00;
serial_current_message.data[6] = 0x00;
serial_current_message.data[7] = 0x00;
opmode=0; //Not in any operation mode
standbymf=0;
parkmf=0;
firemf=0;
VIPmf=0;
_pf_reform=0;
_pf_park=0;
blink_en=0;
turnoffleds=0;
_set_numerator=0;
set_annunciator=0;
arrivedstair=0;
_delay_unload_door=0;
_delay_park_unload_door=0;
ptimer_preopening=0;
FTOC=0;
OVLC=0;
FLTC=0;
FULC=0;
TIMSK1=0x00;
//Set Timer1 for 100ms and STOP it
WDRS=1; //for Watchdog reset
delay_ms(50);
if(forcetoreset)
{
forcetoreset=0;
serial_current_message.length=4;
serial_current_message.address=0xD2;
serial_current_message.data[0]='S';
serial_current_message.data[1]='R';
serial_current_message.data[2]='s';
serial_current_message.data[3]='t';
serial_current_message.data[4]=0;
serial_current_message.data[5]=0;
serial_current_message.data[6]=0x00;
serial_current_message.data[7]=0x00;
RS485_send_message(serial_current_message);
delay_ms(10);
}
_volume_set_rs485=2;
sep_id.dest_address = 0xD1; //Annunciator Board on CAN-BUS
ID = assemble_id(sep_id);
current_message.id = ID;
current_message.datalen=2;
current_message.data[0]='G';
current_message.data[1]='V';
can_send_message(current_message);
delay_ms(50);
sep_id.dest_address = 0xC0; //Annunciator Board via CABIN BUS
ID = assemble_id(sep_id);
current_message.id = ID;
current_message.datalen=4;
current_message.data[0]='X';
current_message.data[1]=0xD1;
current_message.data[2]='G';
current_message.data[3]='V';
can_send_message(current_message);
delay_ms(50);
serial_current_message.address=0xD1;
serial_current_message.length=2;
serial_current_message.data[0]='G';
serial_current_message.data[1]='V';
RS485_send_message(serial_current_message);
delay_ms(10);
interpreter();
if(Numtype=='n') //Normal numerator
{
for(mb1=0;mb1<((Floorsno-1)/8+1);mb1++) //Reset Floor Boards outputs
{
WDRS=1; //for Watchdog reset
sep_id.dest_address = 0xF0+mb1;
ID = assemble_id(sep_id);
current_message.id = ID;
current_message.datalen=1;
current_message.data[0]='R'; //R
can_send_message(current_message);
delay_ms(50);
}
for(mb1=0;mb1<((Floorsno-1)/16+1);mb1++) //Reset Extension Board outputs
{
WDRS=1; //for Watchdog reset
sep_id.dest_address = 0xE0+mb1;
ID = assemble_id(sep_id);
current_message.id = ID;
current_message.datalen=1;
current_message.data[0]='R'; //R
can_send_message(current_message);
delay_ms(50);
}
WDRS=1; //for Watchdog reset
sep_id.dest_address = 0xD0; //Numerator Board
ID = assemble_id(sep_id);
current_message.id = ID;
current_message.datalen=1;
current_message.data[0]='R'; //R
can_send_message(current_message);
delay_ms(50);
}
else
if(Numtype=='d') //Decreased Numerator
{
WDRS=1; //for Watchdog reset
sep_id.dest_address = 0xB0; //Num-Floor Board
ID = assemble_id(sep_id);
current_message.id = ID;
current_message.datalen=1;
current_message.data[0]='R'; //R
can_send_message(current_message);
delay_ms(50);
WDRS=1; //for Watchdog reset
sep_id.dest_address = 0x10; //Num-Ext Board
ID = assemble_id(sep_id);
current_message.id = ID;
current_message.datalen=1;
current_message.data[0]='R'; //R
can_send_message(current_message);
delay_ms(50);
}
else
if(Numtype=='s')
{
serial_current_message.length=1;
serial_current_message.address=0xD3;
serial_current_message.data[0]='R';
RS485_send_message(serial_current_message);
sep_id.dest_address = 0xC0; //Cabin Board
ID = assemble_id(sep_id);
current_message.id = ID;
current_message.datalen=1;
current_message.data[0]='R'; //R
can_send_message(current_message);
delay_ms(50);
}
else
if(Numtype=='f')
{
for(mb1=0;mb1<((Floorsno-1)/8+1);mb1++) //Reset Floor Boards outputs
{
serial_current_message.length=1;
serial_current_message.address=0xF0+mb1;
serial_current_message.data[0]='R';
RS485_send_message(serial_current_message);
WDRS=1; //for Watchdog reset
delay_ms(50);
}
for(mb1=0;mb1<((Floorsno-1)/16+1);mb1++) //Reset Extension Board outputs
{
sep_id.dest_address = 0xC0; //Cabin Board
ID = assemble_id(sep_id);
current_message.id = ID;
current_message.datalen=3;
current_message.data[0]='X';
current_message.data[1]=0xE0+mb1;
current_message.data[2]='R'; //R
can_send_message(current_message);
delay_ms(50);
}
sep_id.dest_address = 0xC0; //Numerator
ID = assemble_id(sep_id);
current_message.id = ID;
current_message.datalen=3;
current_message.data[0]='X';
current_message.data[1]=0xD0;
current_message.data[2]='R'; //R
can_send_message(current_message);
delay_ms(50);
WDRS=1; //for Watchdog reset
serial_current_message.length=1;
serial_current_message.address=0xD0;
serial_current_message.data[0]='R';
RS485_send_message(serial_current_message);
delay_ms(50);
}
WDRS=1; //for Watchdog reset
interpreter();
if(IVA_comm=='c')
{
sep_id.dest_address = 0xD1; //Annunciator Board on CAN-BUS
ID = assemble_id(sep_id);
current_message.id = ID;
current_message.datalen=1;
current_message.data[0]='R';
can_send_message(current_message);
delay_ms(50);
}
else
if(IVA_comm=='s')
{
sep_id.dest_address = 0xC0; //Annunciator Board via CABIN BUS
ID = assemble_id(sep_id);
current_message.id = ID;
current_message.datalen=3;
current_message.data[0]='X';
current_message.data[1]=0xD1;
current_message.data[2]='R';
can_send_message(current_message);
delay_ms(50);
}
else
if(IVA_comm=='p') //ANnnunciatior Board on RS485
{
serial_current_message.address=0xD1;
serial_current_message.length=1;
serial_current_message.data[0]='R';
RS485_send_message(serial_current_message);
delay_ms(10);
}
_volume_set_rs485=0;
if(SMS_Level)
{
serial_current_message.address=0xD4;
serial_current_message.length=8;
sprintf(serial_current_message.data,SERIAL_NUMBER);
serial_current_message.data[0]='S';
RS485_send_message(serial_current_message);
delay_ms(10);
}
WDRS=1; //for Watchdog reset
if((Tunnel_Door_en=='s')||(Tunnel_Door_en=='2'))
{
sep_id.dest_address = 0xC0; //Cabin Board
ID = assemble_id(sep_id);
current_message.id = ID;
current_message.datalen=3;
current_message.data[0]='T'; //send parameter for tunnel door
current_message.data[1]='u';
current_message.data[2]=Tunnel_Door_en;
can_send_message(current_message);
delay_ms(50);
}
if(Numtype=='s')
{
mb1=1;
do
{
if(showfloor(mb1,2)=='-')
{
mb1=0;
break;
}
if(mb1>64)break;
WDRS=1;
mb1++;
}while(mb1<=Floorsno);
sep_id.dest_address = 0xC0; //Cabin Board
ID = assemble_id(sep_id);
current_message.id = ID;
current_message.datalen=3;
current_message.data[0]='M'; //send parameter for tunnel door
current_message.data[1]='e';
serial_current_message.length=3;
serial_current_message.address=0xD3;
serial_current_message.data[0]='M';
serial_current_message.data[1]='e';
if(mb1==0)
{
current_message.data[2]='y';
serial_current_message.data[2]='y';
}
else
{
current_message.data[2]='n';
serial_current_message.data[2]='n';
}
can_send_message(current_message);
RS485_send_message(serial_current_message);
delay_ms(20);
}
// if(!firstchk)RELAYSTBY=1; else RELAYSTBY=0; //***//
RELAYSTBY=1; //***//
RELAYO=0;
//if(!I)RELAYC=0;
if(!(CONTU||CONTD))RELAYC=0; //open door if not moving
URA=0;
CONTF=0; //First Stop!!
CONTU=0;
CONTD=0;
CONTS=0;
CONTM=0;
CONTL=0;
if(!firstchk)set_outputs_relay(1);
if(firstchk)set_outputs_relay(0); //don't send in first loop
WDRS=1; //for Watchdog reset
delay_ms(100);
if(Eth_number) //Reset ALL request packet
{
if(Monitoring == 'y')
{
DataBuff[0]=0xFF;
DataBuff[1]=0xFF;
DataBuff[2]=0x01; //Status Packet
DataBuff[3]=0xF6;
DataBuff[4]=0;
DataBuff[5]=0;
DataBuff[6]=0;
DataBuff[7]=IP; //IP address
for(mb1=0;mb1<=7;mb1++)
buffer[ETH_HEADER_LEN+IP_HEADER_LEN+UDP_HEADER_LEN+mb1]=DataBuff[mb1];
udpSend(GATEWAY, CONTROL_PORT, 8, &buffer[ETH_HEADER_LEN+IP_HEADER_LEN+UDP_HEADER_LEN]);
}
}
ptimer=10;
if(!firstchk)ptimer=0;
while(ptimer<20)
{
WDRS=1; //for Watchdog reset
delay_ms(100);
ptimer++; //delay 4 seconds in start
LED_indicator();
interpreter();
if(Eth_number)netstackService(); // service the network
}
read_inputs();
if((FEEDBF||FEEDBU||FEEDBD||FEEDBS)) //!FEEDB4BS||
{if(firstchk)
{errormsg(32); //Contcea
errormsg(88);}
do{
WDRS=1; //for Watchdog reset
delay_ms(100);
read_inputs();
}while(FEEDBS||FEEDBU||FEEDBF||FEEDBD);
//Waiting for Conts. to be freed
}
I=0; //Movement Flag "I" reset
LED_indicator();
WDRS=1; //for Watchdog reset
if((Eth_number)&&(firstchk))
{
netstackInit(IPADDRESS, NETMASK, GATEWAY,Eth_number); //Unremark for Using Ethernet
delay_ms(100); //Unremark for Using Ethernet
// nicGetMacAddress(&myEthAddress.addr[0]); //Unremark for Using Ethernet
myEthAddress.addr[0] =0x30;
myEthAddress.addr[1] =0x46;
myEthAddress.addr[2] =0x46;
myEthAddress.addr[3] =0x49;
myEthAddress.addr[4] =0x43;
myEthAddress.addr[5] =0x45+Eth_number;
WDRS=1;
}
sep_id.source_address = node_address;
sep_id.message_num = 0;
sep_id.priority = 0;
current_message.datalen=4;
current_message.data[0]='S';
current_message.data[1]='E';
current_message.data[2]='R';
current_message.data[3]='n';
if(Numtype=='n')
{
sep_id.dest_address = 0xD0;
ID = assemble_id(sep_id);
current_message.id = ID;
can_send_message(current_message);
delay_ms(10);
}
else
if(Numtype=='d')
{
sep_id.dest_address = 0xB0; //num-Floor
ID = assemble_id(sep_id);
current_message.id = ID;
can_send_message(current_message);
delay_ms(10);
sep_id.dest_address = 0x10; //num-Ext
ID = assemble_id(sep_id);
current_message.id = ID;
can_send_message(current_message);
delay_ms(10);
}
else