Skip to content

Commit

Permalink
Merge branch 'master' into feature/value-range-debug
Browse files Browse the repository at this point in the history
  • Loading branch information
charliefoxtwo authored Oct 9, 2023
2 parents 6053d1e + 8b5dc51 commit 1e363cd
Show file tree
Hide file tree
Showing 47 changed files with 3,650 additions and 2,313 deletions.
56 changes: 34 additions & 22 deletions Scripts/DCS-BIOS/BIOS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ package.path = lfs.writedir() .. [[Scripts/DCS-BIOS/lib/modules/documentation/?.
package.path = lfs.writedir() .. [[Scripts/DCS-BIOS/lib/modules/memory_map/?.lua;]] .. package.path

-- all requires must come after updates to package.path
local ProtocolIO = require("ProtocolIO")

local BIOSConfig = require("BIOSConfig")
local BIOSStateMachine = require("BIOSStateMachine")
local ConnectionManager= require("ConnectionManager")
local TCPServer = require("TCPServer")
local UDPServer = require("UDPServer")
local socket = require("socket") --[[@as Socket]]

local json = loadfile([[Scripts/JSON.lua]]) -- try to load json from dcs
BIOS.json = json and json() or require "JSON" -- if that fails, fall back to module that we can define
Expand Down Expand Up @@ -94,7 +98,9 @@ BIOS.protocol.writeNewModule(F_5E_3)
-- dofile(lfs.writedir()..[[Scripts/DCS-BIOS/lib/archive/old_format_planes/F-86F Sabre.lua]]) -- ID = 19, ProperName = F-86F Sabre
local F_86F_Sabre = require "F-86F Sabre"
BIOS.protocol.writeNewModule(F_86F_Sabre)
dofile(lfs.writedir()..[[Scripts/DCS-BIOS/lib/FA-18C_hornet.lua]]) -- ID = 20, ProperName = F/A-18C Hornet
-- dofile(lfs.writedir()..[[Scripts/DCS-BIOS/lib/archive/old_format_planes/FA-18C_hornet.lua]]) -- ID = 20, ProperName = F/A-18C Hornet
local FA_18C_hornet = require "FA-18C_hornet"
BIOS.protocol.writeNewModule(FA_18C_hornet)
-- dofile(lfs.writedir()..[[Scripts/DCS-BIOS/lib/archive/old_format_planes/FC3.lua]]) -- ID = 4, ProperName = Flaming Cliffs 3
local FC3 = require "FC3"
BIOS.protocol.writeNewModule(FC3)
Expand Down Expand Up @@ -173,8 +179,6 @@ BIOS.protocol.writeNewModule(VNAO_T_45)
local Yak_52 = require "Yak-52"
BIOS.protocol.writeNewModule(Yak_52)
----------------------------------------------------------------------------Modules End--------------------------------------
dofile(lfs.writedir()..[[Scripts/DCS-BIOS/BIOSConfig.lua]])

--Saves aliases for each aircraft for external programs
local function saveAliases()
local JSON = BIOS.json
Expand All @@ -186,6 +190,8 @@ local function saveAliases()
end
end
pcall(saveAliases)
-- save constants for arduino devs to a header file
pcall(BIOS.protocol.saveAddresses)

-- Prev Export functions.
local PrevExport = {}
Expand All @@ -194,36 +200,44 @@ PrevExport.LuaExportStop = LuaExportStop
PrevExport.LuaExportBeforeNextFrame = LuaExportBeforeNextFrame
PrevExport.LuaExportAfterNextFrame = LuaExportAfterNextFrame

local connection_manager = ConnectionManager:new({})

local state_machine = BIOSStateMachine:new(BIOS.dbg.aircraftNameToModules, MetadataStart, MetadataEnd, 11000, connection_manager)

local function process_input_line(line)
state_machine:processInputLine(line)
end

for _, udp in ipairs(BIOSConfig.udp_config) do
connection_manager:addConnection(UDPServer:new(udp.send_address, udp.send_port, udp.receive_address, udp.receive_port, socket, process_input_line))
end

for _, tcp in ipairs(BIOSConfig.tcp_config) do
connection_manager:addConnection(TCPServer:new(tcp.address, tcp.port, socket, process_input_line))
end

-- Lua Export Functions
LuaExportStart = function()

for _, v in pairs(ProtocolIO.connections) do v:init() end
BIOS.protocol.init()

state_machine:init()

-- Chain previously-included export as necessary
if PrevExport.LuaExportStart then
PrevExport.LuaExportStart()
end
end

LuaExportStop = function()

BIOS.protocol.shutdown()
ProtocolIO.flush()
for _, v in pairs(ProtocolIO.connections) do v:close() end

state_machine:shutdown()

-- Chain previously-included export as necessary
if PrevExport.LuaExportStop then
PrevExport.LuaExportStop()
end
end

function LuaExportBeforeNextFrame()

for _, v in pairs(ProtocolIO.connections) do
if v.step then v:step() end
end

state_machine:receive()

-- Chain previously-included export as necessary
if PrevExport.LuaExportBeforeNextFrame then
PrevExport.LuaExportBeforeNextFrame()
Expand All @@ -232,9 +246,7 @@ function LuaExportBeforeNextFrame()
end

function LuaExportAfterNextFrame()

BIOS.protocol.step()
ProtocolIO.flush()
state_machine:step()

-- Chain previously-included export as necessary
if PrevExport.LuaExportAfterNextFrame then
Expand Down
50 changes: 33 additions & 17 deletions Scripts/DCS-BIOS/BIOSConfig.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
local ProtocolIO = require("ProtocolIO")
local TCPServer = require("TCPServer")
local UDPServer = require("UDPServer")
local socket = require("socket") --[[@as Socket]]

local udp_send_address = "239.255.50.10"
local udp_send_port = 5010
local udp_receive_address = "*"
local udp_receive_port = 7778

local tcp_address = "*"
local tcp_port = 7778

ProtocolIO.connections = {
UDPServer:new(udp_send_address, udp_send_port, udp_receive_address, udp_receive_port, socket, BIOS.protocol.processInputLine),
TCPServer:new(tcp_address, tcp_port, socket, BIOS.protocol.processInputLine),
}
module("BIOSConfig", package.seeall)

--- @class TCPConnectionConfig
--- @field address string
--- @field port integer

--- @class UDPConnectionConfig
--- @field send_address string
--- @field send_port integer
--- @field receive_address string
--- @field receive_port integer

--- @class BIOSConfig
--- @field tcp_config TCPConnectionConfig[]
--- @field udp_config UDPConnectionConfig[]
local BIOSConfig = {
tcp_config = {
{
address = "*",
port = 7778
},
},
udp_config = {
{
send_address = "239.255.50.10",
send_port = 5010,
receive_address = "*",
receive_port = 7778
},
},
}

return BIOSConfig
16 changes: 4 additions & 12 deletions Scripts/DCS-BIOS/doc/Addresses.h
Original file line number Diff line number Diff line change
Expand Up @@ -7128,12 +7128,10 @@
#define FA_18C_hornet_CMSD_JET_SEL_L_AM 0x74D4, 0x8000
#define FA_18C_hornet_COCKKPIT_LIGHT_MODE_SW 0x74C8, 0x0600, 9
#define FA_18C_hornet_COMM1_ANT_SELECT_SW 0x74C0, 0x3000, 12
#define FA_18C_hornet_COMM1_CHANNEL_NUMERIC 0x7404, 0xFFFF, 0
#define FA_18C_hornet_COMM1_CHANNEL_NUMERIC_A 0x7404
#define FA_18C_hornet_COMM1_CHANNEL_NUMERIC 0x7404, 0x001F, 0
#define FA_18C_hornet_COMM1_FREQ 0x7400, 0xFFFF, 0
#define FA_18C_hornet_COMM1_FREQ_A 0x7400
#define FA_18C_hornet_COMM2_CHANNEL_NUMERIC 0x7406, 0xFFFF, 0
#define FA_18C_hornet_COMM2_CHANNEL_NUMERIC_A 0x7406
#define FA_18C_hornet_COMM2_CHANNEL_NUMERIC 0x7406, 0x001F, 0
#define FA_18C_hornet_COMM2_FREQ 0x7402, 0xFFFF, 0
#define FA_18C_hornet_COMM2_FREQ_A 0x7402
#define FA_18C_hornet_COM_AUX 0x7538, 0xFFFF, 0
Expand Down Expand Up @@ -20249,8 +20247,8 @@
#define MiG_15bis_TACTIC_RELEASE_L_AM 0x2468, 0x0100
#define MiG_15bis_TAS 0x24A4, 0xFFFF, 0
#define MiG_15bis_TAS_A 0x24A4
#define MiG_15bis_THROTTLE_FRICTION 0x2400, 0x1000, 12
#define MiG_15bis_THROTTLE_FRICTION_AM 0x2400, 0x1000
#define MiG_15bis_THROTTLE_FRICTION 0x24C8, 0xFFFF, 0
#define MiG_15bis_THROTTLE_FRICTION_A 0x24C8
#define MiG_15bis_TRANSFER_PUMP 0x2402, 0x0008, 3
#define MiG_15bis_TRANSFER_PUMP_AM 0x2402, 0x0008
#define MiG_15bis_TRIM 0x2402, 0x0400, 10
Expand Down Expand Up @@ -28162,14 +28160,8 @@
#define SpitfireLFMkIX_BUTTON_LINKED_AM 0x5400, 0x0010
#define SpitfireLFMkIX_BUTTON_MG 0x5400, 0x0004, 2
#define SpitfireLFMkIX_BUTTON_MG_AM 0x5400, 0x0004
#define SpitfireLFMkIX_CANOPY_CRANK 0x5428, 0xFFFF, 0
#define SpitfireLFMkIX_CANOPY_CRANK_A 0x5428
#define SpitfireLFMkIX_CANOPY_POS 0x545C, 0xFFFF, 0
#define SpitfireLFMkIX_CANOPY_POS_A 0x545C
#define SpitfireLFMkIX_CANOPY_TRUCKS 0x5424, 0xFFFF, 0
#define SpitfireLFMkIX_CANOPY_TRUCKS_A 0x5424
#define SpitfireLFMkIX_CANOPY_VISIBILITY 0x5426, 0xFFFF, 0
#define SpitfireLFMkIX_CANOPY_VISIBILITY_A 0x5426
#define SpitfireLFMkIX_CARB_AIR 0x541C, 0x2000, 13
#define SpitfireLFMkIX_CARB_AIR_AM 0x541C, 0x2000
#define SpitfireLFMkIX_CHARGER_SEC_GEAR_LIGHT 0x5422, 0x0800, 11
Expand Down
Loading

0 comments on commit 1e363cd

Please sign in to comment.