#!/usr/bin/gawk -f
#
#USAGE:
# paraFile station=xxx rtu=xxx yx.conf >yxstation
# paraFile [Help|help]
#
#NOTE:
# 脚本生成导入遥信、遥测参数的配置文件yxstation,只能通过gawk运行,
# 请检查gawk是否安装在系统/usr/local/bin目录下,配置文件名中请不要含
# <, >, {, }, [, ],.,=等特殊符号,脚本目前不支持特殊字符,也不能叫
# help的所有大小写的组合,配置文件名最好用字母,数字表示
#
#DESCRIPTION:
#yx.conf,该配置文件每行代表一个遥信的配置,其分五个域,每个的说明如下:
# PointName PointDesc DataCat DevName MeasName
# K3502jd 3502开关接地保护 PROTECT K3502 接地
#如果有些遥信不知道关联哪个设备,可以将DevName省略不填,不会影响遥信参数脚本的生成(遥测不行)
#
#配置文件每行代表一个遥测的配置,其分五个域,每个的说明如下:
# PointName PointDesc ConvFactA1/Max DevName MeasName savePeriod/MaxScope
# K1150P 1150有功 0.330000/20.48 K1150 有功 5/2048
#
#
#生成的参数脚本InRtuPointNo默认从0开始递增,若不想从0开始指定,请在脚本执行时命令行中加上count=num
#这样会按指定的num递增生成InRtuPointNo
#该生成遥信、遥测的配置文件,必须按照InRtuPointNo由从小到大的顺序来写配置文件,
#在不连续的InRtuPointNo时,请用"IGNORE"代替该行
#
#
#若要生成遥测,配置文件开头应有这样一行"#91yc"or"#91YC",如果指定用最大工程值生成,需在"#91yc"or"#91YC"
#加上" max"or" MAX "
#example:#91yc max
#
#以后若要生成其它非采集遥信等等的脚本,可以按照遥测的做法进行扩展
#
# lifei 2005.9.5 initial
#
BEGIN { MeasTypeCfg="/yh9100/.config/para_Meas.conf" MeasStatCfg="/yh9100/.config/MeasStat.conf" exitFlag=0 CheckArg() InitMeas() InitMeasStat(1) count=0 } { #判断是否生成遥测脚本
if($1~/^#91(yc|YC)/)
{ line++ if($2 ~/(^MAX)|(^max)/) maxFlag = 1 Flag = 1 } else if($1~/^#/||NF==0)
{ line++ next } else if($1~/^IGNORE/) ##跳过不用的yc、yx的点号
{ line++ count++ next } else if( Flag==0 ) ##遥信
{ checkPoint() printYx() } else if( Flag==1 ) ##遥测
{ if(maxFlag) { checkPoint() printYc(maxFlag) } else { checkPoint() printYc(maxFlag) } } }
END { if(exitFlag) exit(1) else { SaveMeasStat() if(numError==0&&numWarning==0) printf "paraFile execute sucessfully\n">"/dev/stderr" else { printf "\nparaFile execute unsucessfully:\n\tError number:%4d\n\tWarning number:%4d\n",numError,numWarning>"/dev/stderr" if(measError>0) LookMeasStatTable() } } } #
#支持函数 检查整个文件中点名是否重复
#
function checkPoint() { line++ if(++pointName[$1]>1) { printf "Error:\n\tPointName: %s in Line:%d相同Line:%d in File %s!\n",$1,line,nameOfline[$1],FILENAME>"/dev/stderr" numError++ } if(pointName[$1]==1) nameOfline[$1]=line }
#
#支持函数 检查设备名和点名及点描述是否一致
#
function checkDev(pointName,pointDesc,devName,temp) { if(match(devName,/[0-9]+/)) temp=substr($4,RSTART,RLENGTH) if(match(pointName,temp)&&match(pointDesc,temp)) return else { printf "Warning:\n\tDevname \"%s\" 不匹配 pointName \"%s\" or pointDesc \"%s\" in line %d\n",devName,pointName,pointDesc,line >"/dev/stderr" numWarning++ } } #
#支持函数 检查脚本配置文件是否存在
#
function CheckCfgFile(CfgFile,tmpCmd,tmpRes,retSts,idx,rep) { if(CfgFile~/[/][/]+/) { printf "ERROR: The path of \"%s\" is not true!\n",CfgFile>"/dev/stderr" printf "\tPlease check the path of \"%s\"\n" ,CfgFile>"/dev/stderr" retSts =1 return retSts } else if(CfgFile~/[^/]\/$/) { printf "ERROR: \"%s\" is not a ordinary file!\n",CfgFile>"/dev/stderr" printf "\tIt's maybe a directory file!\n" >"/dev/stderr" retSts =2 return retSts } idx=match(CfgFile,/[^/]+$/) #if(CfgFile!~/^\.\//)
if(idx&&index(CfgFile,"/")) { tmpCmd=sprintf("echo %s%s",substr(CfgFile,1,idx-1),"*") #printf "tmpCmd %s\n",tmpCmd
} else { tmpCmd=sprintf("echo %s","*") #printf "tmpCmd %s\n",tmpCmd
} #tmpCmd=sprintf("ls -ld %s ",CfgFile)
tmpCmd | getline tmpRes #printf "tmpRes %s\n",tmpRes
close(tmpCmd) #if(CfgFile~/^\.\//)
#{rep=sprintf("./%s\\>",substr(CfgFile,3));printf "rep %s\n",rep}
#else
#rep="\\<[ \t]*" CfgFile "\\>"
rep=sprintf("%s\\>",CfgFile) if(tmpRes!~rep) { printf "ERROR: \"%s\" is not exist!\n",CfgFile>"/dev/stderr" printf "\tPlease check it!\n" >"/dev/stderr" retSts =3 return retSts } tmpCmd=sprintf("ls -ld %s",CfgFile) tmpCmd | getline tmpRes close(tmpCmd) if(tmpRes !~/^-/) { printf "ERROR: \"%s\" is not a ordinary file!\n",CfgFile>"/dev/stderr" printf "\t\"%s\" maybe a directory file,Please check it!\n",CfgFile>"/dev/stderr" retSts =4 return retSts } return retSts } #
#支持函数 检查脚本参数表
#
function CheckArg(tmpCnt,tmpFlag,tmpCheck) { if(ARGC==1) tmpFlag=1 else { for(tmpCnt=1;tmpCnt<ARGC;tmpCnt++) { if(tolower(ARGV[tmpCnt])~/\<help\>/) { tmpFlag = 1 #break
} else if(index(ARGV[tmpCnt],"=")==0) tmpCheck=CheckCfgFile(ARGV[tmpCnt]) } } if(tmpCheck) { exitFlag=1 exit(1) } if(tmpFlag) { printf "\n">"/dev/stderr" while((getline info<"/yh9100/.script/paraFile")>0) { if(info !~/^#/)
{ close("/yh9100/.script/paraFile") break } else if(info ~/(^#!)|(^#+$)/)
; else { info = substr(info,2) printf "%s\n",info >"/dev/stderr" } } LookMeasStatTable() exitFlag=1 exit(1) } } #
#支持函数 查看量测类型统计表
#
function LookMeasStatTable(tmpFlag) { printf "\n你想查看常用的measType吗?[Yy]:">"/dev/stderr" getline tmpFlag<"-" if(tmpFlag~/[Yy]/) { printf "\n">"/dev/stderr" InitMeasStat(2) printf "\n如果想看更详细的量测类型信息,情参考%s\n",MeasTypeCfg>"/dev/stderr" #close("/dev/stderr")
} } #
#支持函数 初始化量测类型表
#
function InitMeas(tmpToken) { while(getline tmpToken < MeasTypeCfg >0) { if(tmpToken~/^#+/||tmpToken~/^$/)
continue else { #去除多余字符、赋值、添加进量测类型表
#match(tmpToken,/[ \t\n]+/)
#tmpToken=substr(tmpToken,1,RSTART-1)
Meas[tmpToken]=1 } } close(MeasTypeCfg) } #
#支持函数 核对量测类型
#
function CheckMeas( measIn ) { #去除多余字符
#match(measIn,/[ \t\n]+/)
#measIn=substr(measIn,1,RSTART-1)
#print MeasIn>"/dev/stderr"
if(Meas[measIn]>=1) { MeasStat[measIn]++ total++ return } else { printf "Error:\n\tMeastype \"%s\"不正确,在line %d,请参考%s文件\n",measIn,line,MeasTypeCfg>"/dev/stderr" numError++ measError++ } } #
#支持函数 初始化量测类型统计
#
function InitMeasStat(flag,tmpToken,tmpCnt) { while(getline <MeasStatCfg >0) { if(flag!=1) { if($0~/^#/)
printf ("\t%s\n", substr($0,2)) >"/dev/stderr" else if($0~/^$/) ; else printf "\t%s\n", $0 >"/dev/stderr" } else { if($0~/^#+/||$0~/^$/)
continue if($0~/^Total/) total=$2 else { #去除多余字符、赋值、添加进量测类型表
tmpToken=$1 MeasStatPre[tmpToken]=$2 } for(tmpCnt in MeasStatPre) { MeasStat[tmpCnt]=sprintf("%d",total*MeasStatPre[tmpCnt]/100) } } } close(MeasStatCfg) } #
#支持函数 保存量测类型统计
#
function SaveMeasStat(tmpToken,cnt) { printf "#下面显示常用量测类型统计表:\n\n"> MeasStatCfg printf "#Meas stat(%):\n">MeasStatCfg printf "#-------------------------------------\n">MeasStatCfg close(MeasStatCfg) for(cnt in MeasStat) { MeasStatPre[cnt]=sprintf("%.6f",MeasStat[cnt]*100/total) printf "%-18s %-.6f\n",cnt,MeasStatPre[cnt]|"sort -r -n +1 +0 -1 >>" MeasStatCfg } close("sort -r -n +1 +0 -1 >>" MeasStatCfg) printf "#-------------------------------------\n">>MeasStatCfg printf "\nTotal %d\n",total>>MeasStatCfg close(MeasStatCfg) } #
#支持函数 生成遥信
#
function printYx(Divalue,NormalState) { if($3~/(PROTECT)|(SGZ)/) { Divalue = 98 NomalState = 0 } else if($3~/STATUS/) { Divalue = 22 NomalState = 0 } else if($3=="SWITCH"||$3=="BREAK") { Divalue = 1 NomalState = 0 } else { #line++
#count++
printf "\tError:Check \"%s\" 3th filed in Line %d\n",$3,line>"/dev/stderr" numError++ } printf("PointDiTel\n"); printf("\tPointName = %s\n"),$1; printf("\tPointDesc = %s\n"),$2; printf("\tStationName = %s\n"),station; printf("\tAlmModPrn = 1\n"); printf("\tAlmModAud = 1\n"); printf("\tAlmModLog = 1\n"); printf("\tAlmModTel = 1\n"); printf("\tAlmModDis = 1\n"); printf("\tAlmModSav = 1\n"); printf("\tDataCat = %s\n"),$3; printf("\tPointClass = DI\n"); printf("\tManEntryFlag = 0\n"); printf("\tPmrFlag = 1\n"); printf("\tDisturbFlag = 0\n"); printf("\tAccidentJudgeName = 事故总或保护\n"); printf("\tDiValue = %d\n"),Divalue; printf("\tNormalState = %d\n"),NomalState; printf("\tDiAlarmDelay = 0\n"); printf("\tInGRtuName = %s\n"),rtu; printf("\tInRtuPointNo[1] = %s\n"),count++; if(NF>4) { printf("\tDevName = %s.%s\n"),station,$4; checkDev($1,$2,$4) } printf("\tMeasName = %s\n"),$NF; CheckMeas($NF) printf("\tPointPrior = 1\n"); printf("\tPointCtlLevel = 0\n"); printf("\tStatFlag = 1\n"); printf("\tAoPName = SCADA\n\n"); }
#
#支持函数 生成遥测
#
function printYc(tmpFlag) { if(tmpFlag) { printf"PointAiTel\n" printf" AnaValueConv = 1\n" printf" PointName = %s\n",$1 printf" PointDesc = %s\n",$2 printf" StationName = %s\n",station printf" AlmModPrn = 0\n" printf" AlmModAud = 1\n" printf" AlmModLog = 0\n" printf" AlmModTel = 0\n" printf" AlmModDis = 0\n" printf" AlmModSav = 1\n" printf" DataCat = ANALOG\n" printf" PointClass = AI\n" printf" ManEntryFlag = 0\n" printf" PmrFlag = 1\n" printf" DisturbFlag = 1\n" printf" IntervalFlag = 0\n" printf" HiReason = 999999.000000\n" printf" HiShortEmerg[1] = 0.000000\n" printf" HiShortEmerg[2] = 0.000000\n" printf" HiShortEmerg[3] = 0.000000\n" printf" HiShortEmerg[4] = 0.000000\n" printf" HiLongEmerg[1] = 0.000000\n" printf" HiLongEmerg[2] = 0.000000\n" printf" HiLongEmerg[3] = 0.000000\n" printf" HiLongEmerg[4] = 0.000000\n" printf" HiOper[1] = 0.000000\n" printf" HiOper[2] = 0.000000\n" printf" HiOper[3] = 0.000000\n" printf" HiOper[4] = 0.000000\n" printf" LoOper[1] = 0.000000\n" printf" LoOper[2] = 0.000000\n" printf" LoOper[3] = 0.000000\n" printf" LoOper[4] = 0.000000\n" printf" LoLongEmerg[1] = 0.000000\n" printf" LoLongEmerg[2] = 0.000000\n" printf" LoLongEmerg[3] = 0.000000\n" printf" LoLongEmerg[4] = 0.000000\n" printf" LoShortEmerg[1] = 0.000000\n" printf" LoShortEmerg[2] = 0.000000\n" printf" LoShortEmerg[3] = 0.000000\n" printf" LoShortEmerg[4] = 0.000000\n" printf" LoReason = -999999.000000\n" printf" AlarmDelay = 0\n" printf" SaveFlag = 1\n" #if($NF~/\<[0-9]+\>/)
#printf" SavePeriod = %d\n",$NF
#else
printf" SavePeriod = 5\n" printf" SaveMethod = 1\n" printf" SaveMaxFlag = 1\n" printf" SaveMinFlag = 1\n" if(NF>5) printf" MaxScope = %.6f\n",$NF else printf" MaxScope = 2048.000000\n" printf" MaxEngineerUnits = %.6f\n",$3 printf" InGRtuName = %s\n",rtu printf" InRtuPointNo = %d\n",count++ printf" DevName = %s.%s\n",station,$4 printf" MeasName = %s\n",$5 CheckMeas($5) printf" PointPrior = 1\n" printf" PointCtlLevel = 0\n" printf" StatFlag = 1\n" printf" AoPName = SCADA\n\n" checkDev($1,$2,$4) } else { printf"PointAiTel\n" printf" AnaValueConv = 1\n" printf" PointName = %s\n",$1 printf" PointDesc = %s\n",$2 printf" StationName = %s\n",station printf" AlmModPrn = 0\n" printf" AlmModAud = 1\n" printf" AlmModLog = 0\n" printf" AlmModTel = 0\n" printf" AlmModDis = 0\n" printf" AlmModSav = 1\n" printf" DataCat = ANALOG\n" printf" PointClass = AI\n" printf" ManEntryFlag = 0\n" printf" PmrFlag = 1\n" printf" DisturbFlag = 1\n" printf" IntervalFlag = 0\n" printf" HiReason = 999999.000000\n" printf" HiShortEmerg[1] = 0.000000\n" printf" HiShortEmerg[2] = 0.000000\n" printf" HiShortEmerg[3] = 0.000000\n" printf" HiShortEmerg[4] = 0.000000\n" printf" HiLongEmerg[1] = 0.000000\n" printf" HiLongEmerg[2] = 0.000000\n" printf" HiLongEmerg[3] = 0.000000\n" printf" HiLongEmerg[4] = 0.000000\n" printf" HiOper[1] = 0.000000\n" printf" HiOper[2] = 0.000000\n" printf" HiOper[3] = 0.000000\n" printf" HiOper[4] = 0.000000\n" printf" LoOper[1] = 0.000000\n" printf" LoOper[2] = 0.000000\n" printf" LoOper[3] = 0.000000\n" printf" LoOper[4] = 0.000000\n" printf" LoLongEmerg[1] = 0.000000\n" printf" LoLongEmerg[2] = 0.000000\n" printf" LoLongEmerg[3] = 0.000000\n" printf" LoLongEmerg[4] = 0.000000\n" printf" LoShortEmerg[1] = 0.000000\n" printf" LoShortEmerg[2] = 0.000000\n" printf" LoShortEmerg[3] = 0.000000\n" printf" LoShortEmerg[4] = 0.000000\n" printf" LoReason = -999999.000000\n" printf" AlarmDelay = 0\n" printf" SaveFlag = 1\n" if(NF>5) printf" SavePeriod = %d\n",$NF else printf" SavePeriod = 5\n" printf" SaveMethod = 1\n" printf" SaveMaxFlag = 1\n" printf" SaveMinFlag = 1\n" printf" ConvFactA1 = %.6f\n",$3 printf" InGRtuName = %s\n",rtu printf" InRtuPointNo = %d\n",count++ printf" DevName = %s.%s\n",station,$4 printf" MeasName = %s\n",$5 CheckMeas($5) printf" PointPrior = 1\n" printf" PointCtlLevel = 0\n" printf" StatFlag = 1\n" printf" AoPName = SCADA\n\n" checkDev($1,$2,$4) } }
|