mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
ATIS v0.4.1
ATIS v0.4.1 - Fixed schedulers being deallocated by lua garbage collector. RADIOQUEUE - Added alias optional name. - Minor.
This commit is contained in:
parent
1cea10f03a
commit
f5f1c9043b
@ -17,33 +17,45 @@
|
|||||||
--
|
--
|
||||||
-- @type RADIOQUEUE
|
-- @type RADIOQUEUE
|
||||||
-- @field #string ClassName Name of the class "RADIOQUEUE".
|
-- @field #string ClassName Name of the class "RADIOQUEUE".
|
||||||
|
-- @field #boolean Debug Debug mode. More info.
|
||||||
-- @field #string lid ID for dcs.log.
|
-- @field #string lid ID for dcs.log.
|
||||||
-- @field #number frequency The radio frequency in Hz.
|
-- @field #number frequency The radio frequency in Hz.
|
||||||
-- @field #number modulation The radio modulation. Either radio.modulation.AM or radio.modulation.FM.
|
-- @field #number modulation The radio modulation. Either radio.modulation.AM or radio.modulation.FM.
|
||||||
-- @field Core.Scheduler#SCHEDULER scheduler The scheduler.
|
-- @field Core.Scheduler#SCHEDULER scheduler The scheduler.
|
||||||
-- @field #string RQid The radio queue scheduler ID.
|
-- @field #string RQid The radio queue scheduler ID.
|
||||||
-- @field #table queue The queue of transmissions.
|
-- @field #table queue The queue of transmissions.
|
||||||
|
-- @field #string alias Name of the radio.
|
||||||
|
-- @field #number dt Time interval in seconds for checking the radio queue.
|
||||||
|
-- @field #number delay Time delay before starting the radio queue.
|
||||||
-- @field #number Tlast Time (abs) when the last transmission finished.
|
-- @field #number Tlast Time (abs) when the last transmission finished.
|
||||||
-- @field Core.Point#COORDINATE sendercoord Coordinate from where transmissions are broadcasted.
|
-- @field Core.Point#COORDINATE sendercoord Coordinate from where transmissions are broadcasted.
|
||||||
-- @field #number sendername Name of the sending unit or static.
|
-- @field #number sendername Name of the sending unit or static.
|
||||||
-- @field Wrapper.Positionable#POSITIONABLE positionable The positionable to broadcast the message.
|
-- @field #boolean senderinit Set frequency was initialized.
|
||||||
-- @field #number power Power of radio station in Watts. Default 100 W.
|
-- @field #number power Power of radio station in Watts. Default 100 W.
|
||||||
-- @field #table numbers Table of number transmission parameters.
|
-- @field #table numbers Table of number transmission parameters.
|
||||||
|
-- @field #boolean checking Scheduler is checking the radio queue.
|
||||||
|
-- @field #boolean schedonce Call ScheduleOnce instead of normal scheduler.
|
||||||
-- @extends Core.Base#BASE
|
-- @extends Core.Base#BASE
|
||||||
RADIOQUEUE = {
|
RADIOQUEUE = {
|
||||||
ClassName = "RADIOQUEUE",
|
ClassName = "RADIOQUEUE",
|
||||||
lid=nil,
|
Debug = nil,
|
||||||
frequency=nil,
|
lid = nil,
|
||||||
modulation=nil,
|
frequency = nil,
|
||||||
scheduler=nil,
|
modulation = nil,
|
||||||
RQid=nil,
|
scheduler = nil,
|
||||||
queue={},
|
RQid = nil,
|
||||||
Tlast=nil,
|
queue = {},
|
||||||
sendercoord=nil,
|
alias = nil,
|
||||||
sendername=nil,
|
dt = nil,
|
||||||
positionable=nil,
|
delay = nil,
|
||||||
power=100,
|
Tlast = nil,
|
||||||
numbers={},
|
sendercoord = nil,
|
||||||
|
sendername = nil,
|
||||||
|
senderinit = nil,
|
||||||
|
power = 100,
|
||||||
|
numbers = {},
|
||||||
|
checking = nil,
|
||||||
|
schedonce = nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Radio queue transmission data.
|
--- Radio queue transmission data.
|
||||||
@ -63,13 +75,16 @@ RADIOQUEUE = {
|
|||||||
-- @param #RADIOQUEUE self
|
-- @param #RADIOQUEUE self
|
||||||
-- @param #number frequency The radio frequency in MHz.
|
-- @param #number frequency The radio frequency in MHz.
|
||||||
-- @param #number modulation (Optional) The radio modulation. Default radio.modulation.AM.
|
-- @param #number modulation (Optional) The radio modulation. Default radio.modulation.AM.
|
||||||
|
-- @param #string alias (Optional) Name of the radio queue.
|
||||||
-- @return #RADIOQUEUE self The RADIOQUEUE object.
|
-- @return #RADIOQUEUE self The RADIOQUEUE object.
|
||||||
function RADIOQUEUE:New(frequency, modulation)
|
function RADIOQUEUE:New(frequency, modulation, alias)
|
||||||
|
|
||||||
-- Inherit base
|
-- Inherit base
|
||||||
local self=BASE:Inherit(self, BASE:New()) -- #RADIOQUEUE
|
local self=BASE:Inherit(self, BASE:New()) -- #RADIOQUEUE
|
||||||
|
|
||||||
self.lid="RADIOQUEUE | "
|
self.alias=alias or "My Radio"
|
||||||
|
|
||||||
|
self.lid=string.format("RADIOQUEUE %s | ", self.alias)
|
||||||
|
|
||||||
if frequency==nil then
|
if frequency==nil then
|
||||||
self:E(self.lid.."ERROR: No frequency specified as first parameter!")
|
self:E(self.lid.."ERROR: No frequency specified as first parameter!")
|
||||||
@ -82,7 +97,7 @@ function RADIOQUEUE:New(frequency, modulation)
|
|||||||
-- Modulation.
|
-- Modulation.
|
||||||
self.modulation=modulation or radio.modulation.AM
|
self.modulation=modulation or radio.modulation.AM
|
||||||
|
|
||||||
-- Scheduler
|
-- Scheduler.
|
||||||
self.scheduler=SCHEDULER:New()
|
self.scheduler=SCHEDULER:New()
|
||||||
self.scheduler:NoTrace()
|
self.scheduler:NoTrace()
|
||||||
|
|
||||||
@ -96,13 +111,19 @@ end
|
|||||||
-- @return #RADIOQUEUE self The RADIOQUEUE object.
|
-- @return #RADIOQUEUE self The RADIOQUEUE object.
|
||||||
function RADIOQUEUE:Start(delay, dt)
|
function RADIOQUEUE:Start(delay, dt)
|
||||||
|
|
||||||
delay=delay or 1
|
self.delay=delay or 1
|
||||||
|
|
||||||
dt=dt or 0.01
|
self.dt=dt or 0.01
|
||||||
|
|
||||||
self:I(self.lid..string.format("Starting RADIOQUEUE on Frequency %.2f MHz [modulation=%d] in %.1f seconds (dt=%.3f sec)", self.frequency/1000000, self.modulation, delay, dt))
|
self:I(self.lid..string.format("Starting RADIOQUEUE %s on Frequency %.2f MHz [modulation=%d] in %.1f seconds (dt=%.3f sec)", self.alias, self.frequency/1000000, self.modulation, delay, dt))
|
||||||
|
|
||||||
self.RQid=self.scheduler:Schedule(self, self._CheckRadioQueue, {}, delay, dt)
|
|
||||||
|
if self.schedonce then
|
||||||
|
self:_CheckRadioQueueDelayed(self.delta)
|
||||||
|
else
|
||||||
|
--self.RQid=self.scheduler:Schedule(self, self._CheckRadioQueue, {}, delay, dt)
|
||||||
|
self.RQid=self.scheduler:Schedule(nil, RADIOQUEUE._CheckRadioQueue, {self}, delay, dt)
|
||||||
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@ -178,7 +199,10 @@ function RADIOQUEUE:AddTransmission(transmission)
|
|||||||
-- Add to queue.
|
-- Add to queue.
|
||||||
table.insert(self.queue, transmission)
|
table.insert(self.queue, transmission)
|
||||||
|
|
||||||
--TODO: Start scheduler.
|
-- Start checking.
|
||||||
|
if self.schedonce and not self.checking then
|
||||||
|
self:_CheckRadioQueueDelayed()
|
||||||
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@ -298,13 +322,22 @@ function RADIOQUEUE:Broadcast(transmission)
|
|||||||
-- Broadcasting from aircraft. Only players tuned in to the right frequency will see the message.
|
-- Broadcasting from aircraft. Only players tuned in to the right frequency will see the message.
|
||||||
self:T(self.lid..string.format("Broadcasting from aircraft %s", sender:GetName()))
|
self:T(self.lid..string.format("Broadcasting from aircraft %s", sender:GetName()))
|
||||||
|
|
||||||
-- Command to set the Frequency for the transmission.
|
|
||||||
local commandFrequency={
|
if not self.senderinit then
|
||||||
id="SetFrequency",
|
|
||||||
params={
|
-- Command to set the Frequency for the transmission.
|
||||||
frequency=self.frequency, -- Frequency in Hz.
|
local commandFrequency={
|
||||||
modulation=self.modulation,
|
id="SetFrequency",
|
||||||
}}
|
params={
|
||||||
|
frequency=self.frequency, -- Frequency in Hz.
|
||||||
|
modulation=self.modulation,
|
||||||
|
}}
|
||||||
|
|
||||||
|
-- Set commend for frequency
|
||||||
|
sender:SetCommand(commandFrequency)
|
||||||
|
|
||||||
|
self.senderinit=true
|
||||||
|
end
|
||||||
|
|
||||||
-- Command to tranmit the call.
|
-- Command to tranmit the call.
|
||||||
local commandTransmit={
|
local commandTransmit={
|
||||||
@ -316,13 +349,12 @@ function RADIOQUEUE:Broadcast(transmission)
|
|||||||
loop=false,
|
loop=false,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
-- Set commend for frequency
|
|
||||||
sender:SetCommand(commandFrequency)
|
|
||||||
|
|
||||||
-- Set command for radio transmission.
|
-- Set command for radio transmission.
|
||||||
sender:SetCommand(commandTransmit)
|
sender:SetCommand(commandTransmit)
|
||||||
|
|
||||||
--MESSAGE:New(string.format("transmissing file %s duration=%.2f sec, subtitle=%s", filename, transmission.duration, transmission.subtitle or ""), 5, "RADIOQUEUE"):ToAll()
|
-- Debug message.
|
||||||
|
local text=string.format("file=%s, freq=%.2f MHz, duration=%.2f sec, subtitle=%s", filename, self.frequency/1000000, transmission.duration, transmission.subtitle or "")
|
||||||
|
MESSAGE:New(text, 2, "RADIOQUEUE "..self.alias):ToAllIf(self.Debug)
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
@ -349,20 +381,35 @@ function RADIOQUEUE:Broadcast(transmission)
|
|||||||
if vec3 then
|
if vec3 then
|
||||||
self:T("Sending")
|
self:T("Sending")
|
||||||
self:T( { filename = filename, vec3 = vec3, modulation = self.modulation, frequency = self.frequency, power = self.power } )
|
self:T( { filename = filename, vec3 = vec3, modulation = self.modulation, frequency = self.frequency, power = self.power } )
|
||||||
--MESSAGE:New(string.format("transmissing file %s duration=%.2f sec, subtitle=%s", filename, transmission.duration, transmission.subtitle or ""), 5, "RADIOQUEUE (trigger)"):ToAll()
|
|
||||||
|
-- Trigger transmission.
|
||||||
trigger.action.radioTransmission(filename, vec3, self.modulation, false, self.frequency, self.power)
|
trigger.action.radioTransmission(filename, vec3, self.modulation, false, self.frequency, self.power)
|
||||||
|
|
||||||
|
-- Debug message.
|
||||||
|
local text=string.format("file=%s, freq=%.2f MHz, duration=%.2f sec, subtitle=%s", filename, self.frequency/1000000, transmission.duration, transmission.subtitle or "")
|
||||||
|
MESSAGE:New(string.format(text, filename, transmission.duration, transmission.subtitle or ""), 5, "RADIOQUEUE "..self.alias):ToAllIf(self.Debug)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Start checking the radio queue.
|
||||||
|
-- @param #RADIOQUEUE self
|
||||||
|
-- @param #number delay Delay in seconds before checking.
|
||||||
|
function RADIOQUEUE:_CheckRadioQueueDelayed(delay)
|
||||||
|
self.checking=true
|
||||||
|
self:ScheduleOnce(delay or self.dt, RADIOQUEUE._CheckRadioQueue, self)
|
||||||
|
end
|
||||||
|
|
||||||
--- Check radio queue for transmissions to be broadcasted.
|
--- Check radio queue for transmissions to be broadcasted.
|
||||||
-- @param #RADIOQUEUE self
|
-- @param #RADIOQUEUE self
|
||||||
function RADIOQUEUE:_CheckRadioQueue()
|
function RADIOQUEUE:_CheckRadioQueue()
|
||||||
|
--env.info("FF check radio queue "..self.alias)
|
||||||
|
|
||||||
-- Check if queue is empty.
|
-- Check if queue is empty.
|
||||||
if #self.queue==0 then
|
if #self.queue==0 then
|
||||||
--TODO: stop scheduler.
|
-- Queue is now empty. Nothing to else to do.
|
||||||
|
self.checking=false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -446,6 +493,11 @@ function RADIOQUEUE:_CheckRadioQueue()
|
|||||||
table.remove(self.queue, remove)
|
table.remove(self.queue, remove)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Check queue.
|
||||||
|
if self.schedonce then
|
||||||
|
self:_CheckRadioQueueDelayed()
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get unit from which we want to transmit a radio message. This has to be an aircraft for subtitles to work.
|
--- Get unit from which we want to transmit a radio message. This has to be an aircraft for subtitles to work.
|
||||||
|
|||||||
@ -80,7 +80,7 @@
|
|||||||
-- @field #boolean windtrue Report true (from) heading of wind. Default is magnetic.
|
-- @field #boolean windtrue Report true (from) heading of wind. Default is magnetic.
|
||||||
-- @extends Core.Fsm#FSM
|
-- @extends Core.Fsm#FSM
|
||||||
|
|
||||||
--- Be informed!
|
--- *It is a very sad thing that nowadays there is so little useless information.* - Oscar Wilde
|
||||||
--
|
--
|
||||||
-- ===
|
-- ===
|
||||||
--
|
--
|
||||||
@ -183,7 +183,7 @@
|
|||||||
-- * **Runways** *25* and *07* - automatic but can be set manually via @{#ATIS.SetRunwayHeadingsMagnetic}
|
-- * **Runways** *25* and *07* - automatic but can be set manually via @{#ATIS.SetRunwayHeadingsMagnetic}
|
||||||
-- * **ILS** *111.50* for runway *07* - set via @{#ATIS.AddILS}
|
-- * **ILS** *111.50* for runway *07* - set via @{#ATIS.AddILS}
|
||||||
-- * **PRMG** *N/A* - set via @{#ATIS.AddPRMG}
|
-- * **PRMG** *N/A* - set via @{#ATIS.AddPRMG}
|
||||||
-- * **OUTER NDB** *870.00* - set via @{#ATIS.AddNDBinner}
|
-- * **OUTER NDB** *870.00* - set via @{#ATIS.AddNDBouter}
|
||||||
-- * **INNER NDB** *490.00* - set via @{#ATIS.AddNDBinner}
|
-- * **INNER NDB** *490.00* - set via @{#ATIS.AddNDBinner}
|
||||||
--
|
--
|
||||||
-- 
|
-- 
|
||||||
@ -496,9 +496,14 @@ ATIS.Sound = {
|
|||||||
RSBNChannel={filename="RSBNChannel.ogg", duration=1.14},
|
RSBNChannel={filename="RSBNChannel.ogg", duration=1.14},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
--- ATIS table containing all defined ATISes.
|
||||||
|
-- @field #table _ATIS
|
||||||
|
_ATIS={}
|
||||||
|
|
||||||
--- ATIS class version.
|
--- ATIS class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
ATIS.version="0.4.0"
|
ATIS.version="0.4.1"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- TODO list
|
-- TODO list
|
||||||
@ -523,7 +528,7 @@ ATIS.version="0.4.0"
|
|||||||
-- @return #ATIS self
|
-- @return #ATIS self
|
||||||
function ATIS:New(airbasename, frequency, modulation)
|
function ATIS:New(airbasename, frequency, modulation)
|
||||||
|
|
||||||
-- Inherit everything from WAREHOUSE class.
|
-- Inherit everything from FSM class.
|
||||||
local self=BASE:Inherit(self, FSM:New()) -- #ATIS
|
local self=BASE:Inherit(self, FSM:New()) -- #ATIS
|
||||||
|
|
||||||
self.airbasename=airbasename
|
self.airbasename=airbasename
|
||||||
@ -543,6 +548,9 @@ function ATIS:New(airbasename, frequency, modulation)
|
|||||||
-- Set some string id for output to DCS.log file.
|
-- Set some string id for output to DCS.log file.
|
||||||
self.lid=string.format("ATIS %s | ", self.airbasename)
|
self.lid=string.format("ATIS %s | ", self.airbasename)
|
||||||
|
|
||||||
|
-- This is just to hinder the garbage collector deallocating the ATIS object.
|
||||||
|
_ATIS[#_ATIS+1]=self
|
||||||
|
|
||||||
-- Defaults:
|
-- Defaults:
|
||||||
self:SetSoundfilesPath()
|
self:SetSoundfilesPath()
|
||||||
self:SetSubtitleDuration()
|
self:SetSubtitleDuration()
|
||||||
@ -883,7 +891,7 @@ function ATIS:onafterStart(From, Event, To)
|
|||||||
self:I(self.lid..string.format("Starting ATIS v%s for airbase %s on %.3f MHz Modulation=%d", ATIS.version, self.airbasename, self.frequency, self.modulation))
|
self:I(self.lid..string.format("Starting ATIS v%s for airbase %s on %.3f MHz Modulation=%d", ATIS.version, self.airbasename, self.frequency, self.modulation))
|
||||||
|
|
||||||
-- Start radio queue.
|
-- Start radio queue.
|
||||||
self.radioqueue=RADIOQUEUE:New(self.frequency, self.modulation)
|
self.radioqueue=RADIOQUEUE:New(self.frequency, self.modulation, string.format("ATIS %s", self.airbasename))
|
||||||
|
|
||||||
-- Send coordinate is airbase coord.
|
-- Send coordinate is airbase coord.
|
||||||
self.radioqueue:SetSenderCoordinate(self.airbase:GetCoordinate())
|
self.radioqueue:SetSenderCoordinate(self.airbase:GetCoordinate())
|
||||||
@ -922,7 +930,7 @@ function ATIS:onafterStatus(From, Event, To)
|
|||||||
local text=string.format("State %s", fsmstate)
|
local text=string.format("State %s", fsmstate)
|
||||||
self:I(self.lid..text)
|
self:I(self.lid..text)
|
||||||
|
|
||||||
self:__Status(60)
|
self:__Status(-60)
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@ -941,7 +949,7 @@ function ATIS:onafterCheckQueue(From, Event, To)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Check back in 5 seconds.
|
-- Check back in 5 seconds.
|
||||||
self:__CheckQueue(5)
|
self:__CheckQueue(-5)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Broadcast ATIS radio message.
|
--- Broadcast ATIS radio message.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user