;P75/P175/P275 automated FM monitoring script (C) Pira.cz 2018 ;FM Scope version required: 1.5 rev. 20 or later Again: reset ;************************************************************* ;*** User configurable parameters: *** ;************************************************************* set (DataPath,c:\monitor) set (BandscanSize,800x288) ;bandscan image size in pixels set (GraphSize,529x260) ;graph image size in pixels set (DelayMeasuring,900) set (DelayRDS,60) set (DevPercentOverAllowed,3) set (PmPercentOverAllowed,10) set (PmAbsoluteLimit,1.5) set (AMLimit,18) set (SkipAntPolH,08790 09140 09430 09630 09670 09540 10710) set (SkipAntPolV,08970 09390 09740 10010 10270 10600) frequencydeviation.histogram (1) setproperty (OnlineUpdate,0) setproperty (Encoding,UTF-8) ;************************************************************* ;*** Main program: *** ;************************************************************* setproperty (ExecutionSpeed,4) textwindow.clear textwindow.addline([Batch script file v. 1.4 starting at %date %time]) mpx.doubletimebase(0) rfmaxhold(1) rfmask(1) rfhistogram(1) com_ini: set (tcpconfailed,0) if (%connected=0) connect textwindow.addline({%time} -[ Script reconnection attempt (A)) sleep(10) goto (com_ini) endif set (antpol,H) send (ARK:GH*X) setmode (0) set (tempfreq,102.7) tune (%tempfreq) call (CheckStation) if (%Result!=0) imf.setasnormal textwindow.addline({%time} Getting carrier frequency normal from %frequency) endif if (%tcpconfailed=1) textwindow.addline({%time} WiFi link failure detected - trying again) goto (com_ini) endif location.load (monitor) location.unlock set (antpol,H) send (ARK:GH*X) set (BandscanName,bs0.svg) call (ProcessBand) set (antpol,V) send (ARK:GD*X) set (BandscanName,bs1.svg) call (ProcessBand) textwindow.addline([END %date %time]) textwindow.savedata(%DataPath\log.txt) ftp.connect ftp.put(log.txt) ftp.disconnect ;email.to (mail@pira.cz) ;email.body (Monitoring log %date %time) ;email.attachfile (%DataPath\log.txt) ;email.send modulationpower.stop sleep(5) disconnect stop ;************************************************************* ;*** Band processing: *** ;************************************************************* ProcessBand: set (tcpconfailed,0) if (%connected=0) connect textwindow.addline({%time} -[ Script reconnection attempt (B)) sleep(10) goto (ProcessBand) endif textwindow.addline({%time} Getting bandscan) bandscan.acquire if (%tcpconfailed=1) textwindow.addline({%time} WiFi link failure detected - trying again) goto (ProcessBand) endif bandscan.savegraph (%DataPath\%BandscanName,%BandscanSize) ftp.connect ftp.put(%BandscanName) ftp.disconnect set (stationindex,1) Loop1: ;loop through stations from bandscan if (%stationindex>%stationcount) RETURN endif if (%station.noise>80) goto (Next1) endif if (%antpol$=H) if (%station.freq@%SkipAntPolH) goto (Next1) endif endif if (%antpol$=V) if (%station.freq@%SkipAntPolV) goto (Next1) endif endif call (ProcessStation) Next1: inc (stationindex) goto (Loop1) ;************************************************************* ;*** Station measuring: *** ;************************************************************* ProcessStation: set (tcpconfailed,0) if (%connected=0) connect textwindow.addline({%time} -[ Script reconnection attempt (C)) sleep(10) goto (ProcessStation) endif call (ResetWarnings) setmode (0) tune (%station.frequency) send (*1) send (*0) set (tempfreq,%station.frequency) call (CheckStation) ;check the station's reception quality if (%Result=0) RETURN ;poor quality, return endif ;------------------------------------------------------------- textwindow.addline({%time} Monitoring station %station.frequency) imf.get mpx.run modulationpower.run set(LowestQuality,5) set (EndTime,%timestamp) inc (EndTime,%DelayMeasuring) call (WaitAndProcessWarnings) modulationpower.stop mpx.stop getquality send (?U) modulationpower.savegraph (%DataPath\pm.svg,%GraphSize) frequencydeviation.acquire frequencydeviation.savegraph (%DataPath\hi.svg,%GraphSize) mpx.savegraph (%DataPath\mx.svg,%GraphSize) rf.savegraph (%DataPath\rf.svg,%GraphSize) setmode (1) send (*6) send (*0) rawdata.run sleep (%DelayRDS) rawdata.stop rawdata.save (%DataPath\rw.spy) rds.getdata rds.getstatistics call (EvaluateWarnings) if (%tcpconfailed=1) textwindow.addline({%time} WiFi link failure detected - trying again) goto (ProcessStation) endif savetext (%DataPath\rd.txt,PS: %rdsps, PI: %rdspi, PTY: %rdspty, TP: %rdstp, TA: %rdsta, MS: %rdsms, DI: %rdsdi, CT: %rdsct, EON: %rdseon
RT: %rdsrt, ECC: %rdsecc, PTYN: %rdsptyn) appendtext (%DataPath\rd.txt,
AF: %rdsaf) appendtext (%DataPath\rd.txt,%cr%rdsstat1
%rdsstat2
%rdsstat3
%rdsstat4) savetext (%DataPath\dt.txt,%station.frequency%station.rdsps%date %time%quality/5, %level%WarningMsgPilot%WarningMsgBalance%WarningMsgPhase%WarningMsgOverdev%WarningMsgPm%WarningMsgSilence%WarningMsgRDS%rdserr) createreport (%DataPath\rp.txt) savetext (%DataPath\nm.stn,%station.frequency - %station.rdsps) set(OutputFile,%DataPath\rp.htm) call(CompleteReport) ;mysql.connect ;mysql.query(INSERT INTO monitor VALUES('%date %time', %station.frequency_, '', '%WarningMsgPilot%WarningMsgBalance%WarningMsgPhase%WarningMsgOverdev%WarningMsgPm%WarningMsgSilence%WarningMsgRDS%rdserr');) ;mysql.disconnect if (%quality>2) textwindow.addline({%time} Uploading data for station %station.frequency) ftp.connect ftp.put (hi.svg,hi%station.freq.svg) ftp.put (mx.svg,mx%station.freq.svg) ftp.put (rf.svg,rf%station.freq.svg) ftp.put (pm.svg,pm%station.freq.svg) ftp.put (rp.txt,rp%station.freq.txt) ftp.put (rp.htm,rp%station.freq.htm) ftp.put (rd.txt,rd%station.freq.txt) ftp.put (rw.spy,rw%station.freq.spy) ftp.put (dt.txt,dt%station.freq.txt) ftp.put (rp.htm,history/rp%station.freq - %date %time.htm) ftp.put (nm.stn,%station.freq.stn) ftp.disconnect endif RETURN ;************************************************************* ;*** Additional routines: *** ;************************************************************* WaitAndProcessWarnings: sleep(5) if (%timestamp>=%EndTime) RETURN endif ;------------------------------------------------------------- getquality if (%quality<%LowestQuality) set(LowestQuality,%quality) endif getpilot if (%pilot<5.8) if (%pilot>1) goto (PilotFailed) endif endif if (%pilot>7.7) goto (PilotFailed) endif if (%WarningCntPilot<9999) set (WarningCntPilot,O) endif goto (WarningSilence) PilotFailed: inc (WarningCntPilot,1) if (%WarningCntPilot>3) if (%WarningCntPilot<9999) set (WarningCntPilot,9999) set (WarningMsgPilot,Pilot level failed {%pilot, %time}! ) textwindow.addline({%time} Warning: Pilot failed {%station.frequency}) endif endif ;------------------------------------------------------------- WarningSilence: if (%pmlast<-6) goto (SilenceDetected) endif if (%WarningCntSilence<9999) set (WarningCntSilence,O) endif goto (WaitAndProcessWarnings) SilenceDetected: if (%WarningCntSilence<9999) inc (WarningCntSilence,1) if (%WarningCntSilence>5) set (WarningCntSilence,9999) set (WarningMsgSilence,Silence detected! {%time}) textwindow.addline({%time} Warning: Silence detected {%station.frequency}! ) endif endif goto (WaitAndProcessWarnings) ;************************************************************* EvaluateWarnings: if (%pmmax>%PmAbsoluteLimit) goto (PmFailed) endif if (%pmabovelimit>%PmPercentOverAllowed) goto (PmFailed) endif goto (EvaluateWarnings2) PmFailed: if (%LowestQuality>2) set (WarningMsgPm,Modulation power failed! ) textwindow.addline({%time} Warning: Modulation power failed {%station.frequency}) endif EvaluateWarnings2: if (%abovelimit>%DevPercentOverAllowed) set (WarningMsgOverdev,Overmodulation! ) textwindow.addline({%time} Warning: Overmodulation {%station.frequency}) endif if (%rds>0) if (%pilot>0) if (No@%phase) if (%quality>4) set (WarningMsgPhase,Pilot+RDS: no phase relation found! ) textwindow.addline({%time} Warning: Pilot+RDS: no phase relation found {%station.frequency}) endif endif endif endif if (%rds=0) if (%rdspi=0) set (WarningMsgRDS,No RDS. ) endif endif if (%rds>8) set (WarningMsgRDS,RDS level failed! ) textwindow.addline({%time} Warning: RDS level failed {%station.frequency}) endif if (%pilot=0) set (WarningMsgPilot,No pilot. ) RETURN endif set (ltor,-%lmaxdb) inc (ltor,%rmaxdb) if (%ltor>6) goto (BalanceFailed) endif if (%ltor<-6) goto (BalanceFailed) endif goto (EvaluateWarnings3) BalanceFailed: textwindow.addline({%time} Warning: Channel balance failed {%station.frequency}) set (WarningMsgBalance,Channel balance failed {%lmaxdbdB/%rmaxdbdB}! ) EvaluateWarnings3: RETURN ;************************************************************* ResetWarnings: set (WarningMsgPilot,) set (WarningCntPilot,0) set (WarningMsgBalance,) set (WarningMsgSilence,) set (WarningCntSilence,0) set (WarningMsgPm,) set (WarningMsgOverdev,) set (WarningMsgPhase,) set (WarningMsgRDS,) RETURN ;************************************************************* CheckStation: textwindow.addline({%time} Checking station %tempfreq) set (Result,0) set (WaitCnt,22) set (AModCnt,0) getfrequency Loop2: sleep (2) inc (WaitCnt,-1) if (%WaitCnt<0) goto (ContinueStation) endif getamod if (%amod>%AMLimit) goto (AMFailed) endif goto (Loop2) AMFailed: inc (AModCnt,1) if (%AModCnt>3) textwindow.addline({%time} Station %tempfreq skipped {AM modulation}) RETURN endif goto (Loop2) ContinueStation: getfrequency if (%tempfreq!=%frequency) textwindow.addline({%time} Error: Device connection failed, station skipped) RETURN endif frequencydeviation.acquire if (%totalsamples<120) textwindow.addline({%time} Station %tempfreq skipped {noisy reception}) RETURN endif if (%totalsamples<600) if (%abovelimit>1) textwindow.addline({%time} Station %tempfreq skipped {noisy reception}) RETURN endif endif set (Result,1) RETURN include(report_svg.fms)