Отчёт - Имитационная модель воздушно-космической обороны, страница 2
Описание файла
Документ из архива "Отчёт - Имитационная модель воздушно-космической обороны", который расположен в категории "". Всё это находится в предмете "военная кафедра" из 10 семестр (2 семестр магистратуры), которые можно найти в файловом архиве МГТУ им. Н.Э.Баумана. Не смотря на прямую связь этого архива с МГТУ им. Н.Э.Баумана, его также можно найти и в других разделах. Архив можно найти в разделе "курсовые/домашние работы", в предмете "военная кафедра" в общих файлах.
Онлайн просмотр документа "Отчёт - Имитационная модель воздушно-космической обороны"
Текст 2 страницы из документа "Отчёт - Имитационная модель воздушно-космической обороны"
r1=${r1_/\.*}
if (( typeofvko == 1 )); then
if [ "$r1" -le "${SPRO[2+3*$i]}" ]
then
#echo "R is OK!"
return 1
fi
else
if [ "$r1" -le "${ZRDN[2+3*$i]}" ]
then
#echo "R is OK!"
return 1
fi
fi
return 0
}
function checkinAreaByType
{
local type="$1"
local no=$2
local Xm=$3
local Ym=$4
((X=$Xm/1000));X=${X/\.*}
((Y=$Ym/1000));Y=${Y/\.*}
case $type in
"РЛС" )
checkinSector $no $X $Y
spotted=$?
return $spotted
;;
"СПРО" )
checkinCircle $no $X $Y 1
spotted=$?
return $spotted
;;
"зрдн" )
checkinCircle $no $X $Y 2
spotted=$?
return $spotted
esac
}
function checkSPRODir
{
local X=$1
local Y=$2
local spX=$3
local spY=$4
fi=$(echo | awk " { x=atan2($spY,$spX)*180/3.14; print x}"); fi=(${fi/\.*});
if [ "$fi" -lt "0" ]
then
((fi=360+$fi))
fi
#secho "fi = $fi"
let X3=${SPRO[0+3*0]}-$X; let Y3=${SPRO[1+3*0]}-$Y;
betta=$(echo | awk " { x=atan2($Y3,$X3)*180/3.14; print x}"); betta=(${betta/\.*});
if [ "$betta" -lt "0" ]
then
((betta=360+$betta))
fi
#echo "betta = $betta"
r1_=$(echo "sqrt ( (($X3*$X3+$Y3*$Y3)) )" | bc -l);
gamma=$(echo | awk " { x=atan2(${SPRO[2+3*0]},$r1_)*180/3.14; print x}"); gamma=(${gamma/\.*});
if [ "$gamma" -lt "0" ]
then
((gamma=360+$gamma))
fi
#echo "gamma = $gamma"
((fimax=$betta+$gamma));
((fimin=$betta-$gamma));
if (( $fi <= $fimax )) && (( $fi >= $fimin ))
then
#echo " SPRO DIRECTION!!! "
return 1
fi
return 0;
}
-
Файл VKO.sh
#!/bin/bash
args=$#
if (( args != 1 ))
then
echo "Параметры запуска системы заданы неверно(1)!"
exit 1
fi
currentVKOType=$1
if (( currentVKOType > 2 )) || (( currentVKOType < 0 ))
then
echo "Параметры запуска системы заданы неверно(2)!"
exit 2
fi
# ------------------------------------------
# Vars and consts
# ------------------------------------------
declare -a TargetsId # ID Xcurr Ycurr SpeedX SpeedY SpottedFlag IdentifiedFlag
NoTarget=0
# ------------------------------------------
# Common includes
# ------------------------------------------
source "params.sh"
source "CommonFuncs.sh"
# ------------------------------------------
# Specific
# ------------------------------------------
TYPE="unk"
TYPELOG="unk"
MAXOFTYPE=0
CANDESTROY=(0 0 0) #0-br 1-plan 2-cmiss
SetParamsBySystemID $currentVKOType # Setting all specific params
# ------------------------------------------
# Program
# ------------------------------------------
CheckConditions
trap sigint_handler 2
commfile="$DirectoryCommLog/$TYPELOG.log"
mkdir $DirectoryComm >/dev/null 2>/dev/null
mkdir $DirectoryCommLog >/dev/null 2>/dev/null
rm -rf $DirectoryComm/$TYPELOG* 2>/dev/null
rm -rf $DirectoryCommLog/$TYPELOG* 2>/dev/null
echo "Система $TYPE успешно инициализирована!" | base64 >>$commfile
HeartBeatInit $TYPELOG
while :
do
GetTargetsList # Result in $Targets
for target in $Targets
do
if [ "$target" ]
then
IDTarget=`expr substr $target 11 6`;
readedfile=`tail $DirectoryTargets/$target 2>/dev/null`;result=$?;
if (( $result == 0 ))
then
XYTarget=($readedfile);
isNewIDinList "7" "$IDTarget"; idx=$returnIdx;
if (( $idx == -1 ))
then
# New element
TargetsId[0+7*$NoTarget]=$IDTarget
TargetsId[1+7*$NoTarget]=${XYTarget[0]}
TargetsId[2+7*$NoTarget]=${XYTarget[1]}
TargetsId[3+7*$NoTarget]=0
TargetsId[4+7*$NoTarget]=0
TargetsId[5+7*$NoTarget]=0
TargetsId[6+7*$NoTarget]=-1
cIdx=$NoTarget
let NoTarget+=1
else
# Old element
if (( ${TargetsId[3+7*$idx]} == 0 )) && (( ${TargetsId[1+7*$idx]} != ${XYTarget[0]} ))
# if speed was not calculated and coord are differs
then
checkDetection $TYPE $MAXOFTYPE ${TargetsId[1+7*$idx]} ${TargetsId[2+7*$idx]}; det1=$?
checkDetection $TYPE $MAXOFTYPE ${XYTarget[0]} ${XYTarget[1]}; det2=$?
if (($det1 == 1)) && (( $det2 == 1 ))
then
let TargetsId[3+7*$idx]=(${XYTarget[0]}-${TargetsId[1+7*$idx]})
let TargetsId[4+7*$idx]=(${XYTarget[1]}-${TargetsId[2+7*$idx]})
fi
fi
TargetsId[1+7*$idx]=${XYTarget[0]}
TargetsId[2+7*$idx]=${XYTarget[1]}
cIdx=$idx
fi
# Detection
if (( ${TargetsId[5+7*$cIdx]} == 0 ))
then
i=0
while [[ "$i" < "$MAXOFTYPE" ]]
do
checkinAreaByType $TYPE $i ${TargetsId[1+7*$cIdx]} ${TargetsId[2+7*$cIdx]}; spotted=$?
let i+=1
if [[ "$spotted" == "1" ]]
then
TargetsId[5+7*$cIdx]=1
echo $TYPE" $i: Цель ID:${TargetsId[0+7*$cIdx]} обнаружена" \
"${TargetsId[1+7*$cIdx]} ${TargetsId[2+7*$cIdx]}" | base64 >>$commfile
fi
done
fi
# Identification
if (( ${TargetsId[6+7*$cIdx]} == -1 )) && (( ${TargetsId[3+7*$cIdx]} != 0 ))
then
TargetTypeBySpeed ${TargetsId[3+7*$cIdx]}
TargetsId[6+7*$cIdx]=$?
i=0
while [[ "$i" < "$MAXOFTYPE" ]]
do
checkinAreaByType $TYPE $i ${TargetsId[1+7*$cIdx]} ${TargetsId[2+7*$cIdx]}; spotted=$?
let i+=1
if (( $spotted == 1 ))
then
case ${TargetsId[6+7*$cIdx]} in
0 )
echo "$TYPE $i: Цель ID:${TargetsId[0+7*$cIdx]} идентифицирована как Бал.блок" \
" (${TargetsId[3+7*$idx]} ${TargetsId[4+7*$idx]})" | base64 >>$commfile
;;
1 )
echo "$TYPE $i: Цель ID:${TargetsId[0+7*$cIdx]} идентифицирована как Самолет" \
" (${TargetsId[3+7*$idx]} ${TargetsId[4+7*$idx]})" | base64 >>$commfile
;;
2 )
echo "$TYPE $i: Цель ID:${TargetsId[0+7*$cIdx]} идентифицирована как К.ракета" \
" (${TargetsId[3+7*$idx]} ${TargetsId[4+7*$idx]})" | base64 >>$commfile
esac
if [[ $TYPE == "РЛС" ]]
then
checkSPRODir ${TargetsId[1+7*$cIdx]} ${TargetsId[2+7*$cIdx]} \
${TargetsId[3+7*$cIdx]} ${TargetsId[4+7*$cIdx]}
direction=$?
if (( $direction == 1 ))
then
echo $TYPE" $i: Цель ID:${TargetsId[0+7*$cIdx]} движется в направлении СПРО" | base64 >>$commfile
fi
fi
fi
done
fi
# Destroy
if (( ${TargetsId[6+7*$cIdx]} != -1 ))
then
if (( "${CANDESTROY[${TargetsId[6+7*$cIdx]}]}" == "1" ))
then
touch "$DestroyDirectory/${TargetsId[0+7*$cIdx]}"
fi
fi
fi
fi
done
#echo "END OF CYCLE"
#stime=`date +%s`
#etime=`date +%s`;((time=$etime-$stime));if (($time > 0));then echo "Cycle time = $time s."; fi
HeartBeat $TYPELOG
RandomSleep
done
-
Файл KP.sh
#!/bin/bash
# ------------------------------------------
# Vars and consts
# ------------------------------------------
SYSPID=(0 0 0)
args=$#
if (( args == 3 )); then
SYSPID[0]=$1
SYSPID[1]=$2
SYSPID[2]=$3
fi
SYSTEMS=("rls" "zrdn" "spro" "kp")
SYSTEMSDESCR=("РЛС" "зрдн" "СПРО")
HBVARS=("-1" "-1" "-1")
LOGLINES=("0" "0" "0")
STRTODEL=20
STRMAXCOUNT=100
# ------------------------------------------
# Common includes
# ------------------------------------------
source "params.sh"
source "CommonFuncs.sh"
# ------------------------------------------
# Specific
# ------------------------------------------
TYPE="КП"
TYPELOG="KP"
MAXOFTYPE=0
CANDESTROY=(0 0 0) #0-br 1-plan 2-cmiss
# ------------------------------------------
# Program
# ------------------------------------------
commfile="$DirectoryCommLog/kp.log"
CheckConditions
trap sigint_handler 2
echo "Система $TYPE успешно инициализирована!"
echo "Система $TYPE успешно инициализирована!" >>$commfile
sltime=0;
while :
do
sleep 1
let sltime+=1
# display new log lines
if (( sltime%2 == 0))
then
i=0
while (( $i < 3 ))
do
lines=`wc -l "$DirectoryCommLog/${SYSTEMS[$i]}.log" 2>/dev/null`; res=$?
if (( res == 0 )); then
count=($lines); count=${count[0]}
((LinesToDisplay=$count-${LOGLINES[$i]})); LOGLINES[$i]=$count;
if (( $LinesToDisplay > 0)); then
readedfile=`tail -n $LinesToDisplay $DirectoryCommLog/${SYSTEMS[$i]}.log 2>/dev/null`;result=$?;
if (( $result == 0 )); then
echo "$readedfile" | base64 -d
fi
fi
fi
let i+=1
done
fi
# maintain all systems state
if (( sltime%30 == 0))
then
echo "Запуск проверки всех систем"
echo "Запуск проверки всех систем" >>$commfile
i=0
while (( $i < 3 ))
do
readedfile=`tail $DirectoryComm/${SYSTEMS[$i]} 2>/dev/null`;result=$?;
if (( $result == 0 )); then
if (( ${HBVARS[$i]} == $readedfile)); then
echo " Система ${SYSTEMSDESCR[$i]} зависла или остановлена."
echo " Система ${SYSTEMSDESCR[$i]} зависла или остановлена." >>$commfile
else
if (( ${HBVARS[$i]} == -1 )); then
echo " Получено начальное состояние системы ${SYSTEMSDESCR[$i]}."
echo " Получено начальное состояние системы ${SYSTEMSDESCR[$i]}." >>$commfile
else
echo " Система ${SYSTEMSDESCR[$i]} работает в штатном режиме."
echo " Система ${SYSTEMSDESCR[$i]} работает в штатном режиме." >>$commfile
fi
fi
HBVARS[$i]=$readedfile
else
echo " Ошибка доступа к системе ${SYSTEMSDESCR[$i]}. Система неинициализирована или недоступна."
echo " Ошибка доступа к системе ${SYSTEMSDESCR[$i]}. Система неинициализирована или недоступна." >>$commfile
fi
let i+=1
done
fi
# delete old log entries
if (( sltime%10 == 0))
then
i=0
while (( $i < 4 ))
do
lines=`wc -l "$DirectoryCommLog/${SYSTEMS[$i]}.log" 2>/dev/null`; res=$?
if (( res == 0 )); then
count=($lines); count=${count[0]}
if (( $count >= $STRMAXCOUNT )); then
echo "Файл ${SYSTEMS[$i]}.log. Строк $count. Допустимо $STRMAXCOUNT. Удаление первых $STRTODEL строк."
echo "Файл ${SYSTEMS[$i]}.log. Строк $count. Допустимо $STRMAXCOUNT. Удаление первых $STRTODEL строк." >>$commfile
deleted=`sed "1,$STRTODEL d" /tmp/GenTargets/CommLog/${SYSTEMS[$i]}.log`
echo "$deleted" >/tmp/GenTargets/CommLog/${SYSTEMS[$i]}.log
((LOGLINES[$i]=${LOGLINES[$i]}-$STRTODEL))
fi
fi
let i+=1