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 e53fdd4
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions server/test/fgcom-fakepilot.bot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ local voiceBuffer = Queue:new() -- Queue voice buffer holding the cached samples
local lastHeader = nil -- holds last header data
local playback_targets = nil -- holds updated list of all channel users
local ptt = false -- signals if the bot is currently transmitting
local freq = "none" -- active frequency

local sleep = 30 -- time beween checks if to transmit
local chance_transmit = 0.25 -- chance that he will transmit
Expand Down Expand Up @@ -189,37 +190,38 @@ 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]
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 +256,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 Expand Up @@ -323,6 +328,18 @@ client:hook("OnServerSync", function(client, event)

end, 0.00, locs)

-- initiate radio stack
freq = pickRandomFrequency()
fgcom.log("picked new frequency: "..freq)
if #playback_targets > 0 then
local msg = "FRQ="..freq
..",CHN="..freq
..",PWR=10"
..",PTT=0"
fgcom.dbg(" Bot sets radio: "..msg)
client:sendPluginData("FGCOM:UPD_COM:0:0", msg, playback_targets)
end

-- let the pilot check every n seconds if he wants to do a transmission
checkTimer:start(function(t)
--fgcom.dbg("checkTimer: tick")
Expand Down

0 comments on commit e53fdd4

Please sign in to comment.