/* RLS device emulation. Generates alarms periodicaly on a specified sector.*/ var r1_chanel; /*0 - 0-80 m, 1 - 80-160 m, 2 - 160-240 m, 3 - 240-320 m*/ var r1_far_near;/*1 - near target detected, 2 - far target detected*/ var r1_barrier_address; /* RLS device alarm sector */ set_alarm_sector() { r1_chanel = 0; r1_far_near = 1; } /* RLS device address */ set_radar_address() { r1_barrier_address = 1; } /* this entry point is not used*/ main() { } /* this entry point is called on data receive*/ on_read() { var type; set_radar_address(); while(get_in_que_count()>0) { type = get_poll_type(); if(type==1) { process_type1(); } if(type==2) { process_type2(); } } } process_type1() { putx(0x84); return 0; } process_type2() { var result; var cntr; var cntr2; set_alarm_sector(); cntr = get_global(1); cntr = cntr + 1; if(cntr==16) { cntr = 0; } set_global(1,cntr); if(cntr/4 == r1_chanel) { if(cntr%4 == 0) { if(get_global(2)>1) { set_global(2,0); } else { set_global(2,1+get_global(2)); } } if(get_global(2)>0) {/*normal*/ result = 0x80 | shl(cntr/4,5); } else {/*alarm*/ result = 0x80 | shl(cntr/4,5) | r1_far_near; } } else {/*normal*/ result = 0x80 | shl(cntr/4,5); } putx(result); return 0; } /*returns 0-error, 1-type1, 2-type2*/ get_poll_type() { var ch; var addr; var type; ch = getx(); if(ch & 0x80 > 0) { if(ch & 0x20 > 0) { putx(0x80 | get_global(0));/* 0x80 | address */ putx(ch); } return 0; } type = ch & 0x03; addr = shr(ch,2); set_global(0,addr);/* store address */ if(addr != r1_barrier_address) { return 0; } if(type == 0) { return 1; } if(type == 0x02) { return 2; } return 0; }