Skip to content

Commit

Permalink
Server/fakepilot: Pick frequency after transmission finished; that wa…
Browse files Browse the repository at this point in the history
…y the next choosen frequency is preannounced on the net
  • Loading branch information
hbeni committed Mar 22, 2024
1 parent 2ffd32a commit d04ebcc
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions server/test/fgcom-fakepilot.bot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,37 +189,40 @@ updateAllChannelUsersforSend = function(cl)
end
end

-- pick a random frequency
pickRandomFrequency = function()
local f = testfrequencies[math.random(1,#testfrequencies)]
local ce = tonumber(math.random(0, 100)/100)
if ce < chance_echotest then
f = "910.00"
end
return f
end


--[[
Playback loop: we use a mumble timer for this. The timer loops in
the playback-rate and looks if there are samples buffered. If so,
he fetches them and plays them, one packet per timer tick.
]]
local playbackTimer = mumble.timer()
local freq = testfrequencies[1]
local freq = pickRandomFrequency()
fgcom.log("picked new frequency: "..freq)
playbackTimer_func = function(t)
--fgcom.dbg("playback timer: tick; ptt=",ptt)

-- So, a new timer tick started.
if ptt then
-- PTT is active: setup voice buffer and radio (if not done already)
if voiceBuffer:size() <= 0 then
fgcom.log(fgcom.callsign.." Starting new transmission...")
local freq_desc = "Normal"
if freq == "910.00" then freq_desc = "Echotest" end
fgcom.log(fgcom.callsign.." Starting new transmission... @"..freq.." ("..freq_desc..")")

-- fill temporary buffer
lastHeader, voiceBuffer = readFGCSSampleFile(sample)
if not lastHeader then fgcom.log("ERROR: '"..sample.."' not readable or no FGCS file") os.exit(1) else fgcom.dbg(sample..": successfully refreshed ("..voiceBuffer:size().." samples)") end

-- choose a random frequency
freq = testfrequencies[math.random(1,#testfrequencies)]
local ce = tonumber(math.random(0, 100)/100)
if ce < chance_echotest then
freq = "910.00"
fgcom.log(" (Echotest transmission @"..freq..")")
else
fgcom.log(" (Normal transmission @"..freq..")")
end

-- Broadcast radio
updateAllChannelUsersforSend(client)
if #playback_targets > 0 then
Expand Down Expand Up @@ -254,7 +257,10 @@ playbackTimer_func = function(t)
fgcom.dbg(fgcom.callsign.." no samples left, playback complete")

ptt = false;


freq = pickRandomFrequency() -- pick a new frequency for the next transmission
fgcom.log("picked new frequency: "..freq)

-- broadcast radio
updateAllChannelUsersforSend(client)
if #playback_targets > 0 then
Expand Down

0 comments on commit d04ebcc

Please sign in to comment.