Skip to content

Commit

Permalink
Server and client changes. (#37)
Browse files Browse the repository at this point in the history
Server :
* API files / modules renamed
* API constructor notation changed
* APIBase APIInfo not private anymore
* API unique ID is handed to API in constructor

Client :
* Main window didn't execute APIs after having used Range Testing
  • Loading branch information
jdahlblom authored Oct 22, 2023
1 parent 0d9b5f7 commit c099c6d
Show file tree
Hide file tree
Showing 43 changed files with 371 additions and 288 deletions.
2 changes: 1 addition & 1 deletion src/client/DCSInsight/DCSInsight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<UseWPF>true</UseWPF>
<AssemblyName>dcs-insight</AssemblyName>
<Version>1.0.0</Version>
<AssemblyVersion>1.7.7</AssemblyVersion>
<AssemblyVersion>1.7.8</AssemblyVersion>
<ApplicationIcon>Images\Magnifier_icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
Expand Down
19 changes: 13 additions & 6 deletions src/client/DCSInsight/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public partial class MainWindow : Window, IErrorListener, IConnectionListener, I
private bool _formLoaded;
private TCPClientHandler _tcpClientHandler;
private bool _isConnected;
private WindowRangeTest _windowRangeTest;
private bool _rangeTesting;

public MainWindow()
{
Expand All @@ -46,7 +46,6 @@ public MainWindow()
public void Dispose()
{
ItemsControlAPI.Items.Clear();
_windowRangeTest?.Close();
ICEventHandler.DetachErrorListener(this);
ICEventHandler.DetachConnectionListener(this);
ICEventHandler.DetachDataListener(this);
Expand Down Expand Up @@ -151,7 +150,7 @@ public void ErrorMessage(ErrorEventArgs args)
{
try
{
if (_windowRangeTest != null) return;
if (_rangeTesting) return;

Logger.Error(args.Ex);
Dispatcher?.BeginInvoke((Action)(() => TextBlockMessage.Text = $"{args.Message}. See log file."));
Expand All @@ -166,7 +165,7 @@ public void DataReceived(DataEventArgs args)
{
try
{
if (_windowRangeTest != null) return;
if (_rangeTesting) return;

if (args.DCSAPIS != null)
{
Expand Down Expand Up @@ -488,8 +487,16 @@ private void ButtonRangeTest_OnClick(object sender, RoutedEventArgs e)
{
try
{
_windowRangeTest = new WindowRangeTest(_dcsAPIList);
_windowRangeTest.Show();
try
{
_rangeTesting = true;
var windowRangeTest = new WindowRangeTest(_dcsAPIList);
windowRangeTest.ShowDialog();
}
finally
{
_rangeTesting = false;
}
}
catch (Exception ex)
{
Expand Down
5 changes: 2 additions & 3 deletions src/client/DCSInsight/Windows/WindowRangeTest.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void Dispose()
_doLoop = false;
AutoResetEvent1.Set();
AutoResetEvent1.Set();
_thread?.Join(10000000);
GC.SuppressFinalize(this);
}

Expand Down Expand Up @@ -605,9 +606,7 @@ private void WindowRangeTest_OnClosing(object sender, CancelEventArgs e)
{
try
{
_stopRunning = true;
_doLoop = false;
AutoResetEvent1.Set();
Dispose();
}
catch (Exception ex)
{
Expand Down
123 changes: 69 additions & 54 deletions src/server/Scripts/DCS-INSIGHT/lib/APIHandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ module("APIHandler", package.seeall)

local Log = require("Scripts.DCS-INSIGHT.lib.common.Log")

local GetArgumentValue = require("Scripts.DCS-INSIGHT.lib.commands.GetArgumentValue")
local SetArgumentValue = require("Scripts.DCS-INSIGHT.lib.commands.SetArgumentValue")
local SetCommand = require("Scripts.DCS-INSIGHT.lib.commands.SetCommand")
local SetFrequency = require("Scripts.DCS-INSIGHT.lib.commands.SetFrequency")
local GetFrequency = require("Scripts.DCS-INSIGHT.lib.commands.GetFrequency")
local PerformClickableAction = require("Scripts.DCS-INSIGHT.lib.commands.PerformClickableAction")
local GetArgumentValueAPI = require("Scripts.DCS-INSIGHT.lib.commands.GetArgumentValueAPI")
local SetArgumentValueAPI = require("Scripts.DCS-INSIGHT.lib.commands.SetArgumentValueAPI")
local SetCommandAPI = require("Scripts.DCS-INSIGHT.lib.commands.SetCommandAPI")
local SetFrequencyAPI = require("Scripts.DCS-INSIGHT.lib.commands.SetFrequencyAPI")
local GetFrequencyAPI = require("Scripts.DCS-INSIGHT.lib.commands.GetFrequencyAPI")
local UpdateArgumentsAPI = require("Scripts.DCS-INSIGHT.lib.commands.UpdateArgumentsAPI")
local PerformClickableActionAPI = require("Scripts.DCS-INSIGHT.lib.commands.PerformClickableActionAPI")
local LoGetAircraftDrawArgumentValueAPI = require("Scripts.DCS-INSIGHT.lib.commands.LoGetAircraftDrawArgumentValueAPI")
local LoGetSelfDataAPI = require("Scripts.DCS-INSIGHT.lib.commands.LoGetSelfDataAPI")
local LoGetModelTimeAPI = require("Scripts.DCS-INSIGHT.lib.commands.LoGetModelTimeAPI")
Expand Down Expand Up @@ -56,149 +57,163 @@ function APIHandler:new()
return o
end

local id = 0
local function counter()
id = id + 1
return id
end

--- @func Fills the commands and api table
function APIHandler:init()
local getArgumentValue = GetArgumentValue:new(nil)
self.commandsTable[#self.commandsTable + 1] = getArgumentValue
self.apiTable[#self.apiTable + 1] = getArgumentValue.apiInfo
local getArgumentValueAPI = GetArgumentValueAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = getArgumentValueAPI
self.apiTable[#self.apiTable + 1] = getArgumentValueAPI.apiInfo

local setArgumentValueAPI = SetArgumentValueAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = setArgumentValueAPI
self.apiTable[#self.apiTable + 1] = setArgumentValueAPI.apiInfo

local setArgumentValue = SetArgumentValue:new()
self.commandsTable[#self.commandsTable + 1] = setArgumentValue
self.apiTable[#self.apiTable + 1] = setArgumentValue.apiInfo
local performClickableActionAPI = PerformClickableActionAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = performClickableActionAPI
self.apiTable[#self.apiTable + 1] = performClickableActionAPI.apiInfo

local performClickableAction = PerformClickableAction:new()
self.commandsTable[#self.commandsTable + 1] = performClickableAction
self.apiTable[#self.apiTable + 1] = performClickableAction.apiInfo
local setCommandAPI = SetCommandAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = setCommandAPI
self.apiTable[#self.apiTable + 1] = setCommandAPI.apiInfo

local setCommand = SetCommand:new()
self.commandsTable[#self.commandsTable + 1] = setCommand
self.apiTable[#self.apiTable + 1] = setCommand.apiInfo
local getFrequencyAPI = GetFrequencyAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = getFrequencyAPI
self.apiTable[#self.apiTable + 1] = getFrequencyAPI.apiInfo

local getFrequency = GetFrequency:new()
self.commandsTable[#self.commandsTable + 1] = getFrequency
self.apiTable[#self.apiTable + 1] = getFrequency.apiInfo
local setFrequencyAPI = SetFrequencyAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = setFrequencyAPI
self.apiTable[#self.apiTable + 1] = setFrequencyAPI.apiInfo

local setFrequency = SetFrequency:new()
self.commandsTable[#self.commandsTable + 1] = setFrequency
self.apiTable[#self.apiTable + 1] = setFrequency.apiInfo
local updateArgumentsAPI = UpdateArgumentsAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = updateArgumentsAPI
self.apiTable[#self.apiTable + 1] = updateArgumentsAPI.apiInfo

local loGetAircraftDrawArgumentValue = LoGetAircraftDrawArgumentValueAPI:new()
--[[ APIs not requiring device parameter below ]]

local loGetAircraftDrawArgumentValue = LoGetAircraftDrawArgumentValueAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetAircraftDrawArgumentValue
self.apiTable[#self.apiTable + 1] = loGetAircraftDrawArgumentValue.apiInfo

local listIndicationAPI = ListIndicationAPI:new()
local listIndicationAPI = ListIndicationAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = listIndicationAPI
self.apiTable[#self.apiTable + 1] = listIndicationAPI.apiInfo

local listCockpitParamsAPI = ListCockpitParamsAPI:new(nil)
--[[ APIs not requiring parameters below ]]

local listCockpitParamsAPI = ListCockpitParamsAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = listCockpitParamsAPI
self.apiTable[#self.apiTable + 1] = listCockpitParamsAPI.apiInfo

local loGetSelfData = LoGetSelfDataAPI:new()
local loGetSelfData = LoGetSelfDataAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetSelfData
self.apiTable[#self.apiTable + 1] = loGetSelfData.apiInfo

local loGetModelTimeAPI = LoGetModelTimeAPI:new()
local loGetModelTimeAPI = LoGetModelTimeAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetModelTimeAPI
self.apiTable[#self.apiTable + 1] = loGetModelTimeAPI.apiInfo

local loGetMissionStartTimeAPI = LoGetMissionStartTimeAPI:new()
local loGetMissionStartTimeAPI = LoGetMissionStartTimeAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetMissionStartTimeAPI
self.apiTable[#self.apiTable + 1] = loGetMissionStartTimeAPI.apiInfo

local loIsOwnshipExportAllowedAPI = LoIsOwnshipExportAllowedAPI:new()
local loIsOwnshipExportAllowedAPI = LoIsOwnshipExportAllowedAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loIsOwnshipExportAllowedAPI
self.apiTable[#self.apiTable + 1] = loIsOwnshipExportAllowedAPI.apiInfo

local loGetPilotName = LoGetPilotNameAPI:new()
local loGetPilotName = LoGetPilotNameAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetPilotName
self.apiTable[#self.apiTable + 1] = loGetPilotName.apiInfo

local loGetIndicatedAirSpeedAPI = LoGetIndicatedAirSpeedAPI:new()
local loGetIndicatedAirSpeedAPI = LoGetIndicatedAirSpeedAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetIndicatedAirSpeedAPI
self.apiTable[#self.apiTable + 1] = loGetIndicatedAirSpeedAPI.apiInfo

local loGetAccelerationUnitsAPI = LoGetAccelerationUnitsAPI:new()
local loGetAccelerationUnitsAPI = LoGetAccelerationUnitsAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetAccelerationUnitsAPI
self.apiTable[#self.apiTable + 1] = loGetAccelerationUnitsAPI.apiInfo

local loGetADIPitchBankYawAPI = LoGetADIPitchBankYawAPI:new()
local loGetADIPitchBankYawAPI = LoGetADIPitchBankYawAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetADIPitchBankYawAPI
self.apiTable[#self.apiTable + 1] = loGetADIPitchBankYawAPI.apiInfo

local loGetSnaresAPI = LoGetSnaresAPI:new()
local loGetSnaresAPI = LoGetSnaresAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetSnaresAPI
self.apiTable[#self.apiTable + 1] = loGetSnaresAPI.apiInfo

local loGetAltitudeAboveSeaLevelAPI = LoGetAltitudeAboveSeaLevelAPI:new()
local loGetAltitudeAboveSeaLevelAPI = LoGetAltitudeAboveSeaLevelAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetAltitudeAboveSeaLevelAPI
self.apiTable[#self.apiTable + 1] = loGetAltitudeAboveSeaLevelAPI.apiInfo

local loGetAltitudeAboveGroundLevelAPI = LoGetAltitudeAboveGroundLevelAPI:new()
local loGetAltitudeAboveGroundLevelAPI = LoGetAltitudeAboveGroundLevelAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetAltitudeAboveGroundLevelAPI
self.apiTable[#self.apiTable + 1] = loGetAltitudeAboveGroundLevelAPI.apiInfo

local loGetVerticalVelocityAPI = LoGetVerticalVelocityAPI:new()
local loGetVerticalVelocityAPI = LoGetVerticalVelocityAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetVerticalVelocityAPI
self.apiTable[#self.apiTable + 1] = loGetVerticalVelocityAPI.apiInfo

local loGetTrueAirSpeedAPI = LoGetTrueAirSpeedAPI:new()
local loGetTrueAirSpeedAPI = LoGetTrueAirSpeedAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetTrueAirSpeedAPI
self.apiTable[#self.apiTable + 1] = loGetTrueAirSpeedAPI.apiInfo

local loGetMachNumberAPI = LoGetMachNumberAPI:new()
local loGetMachNumberAPI = LoGetMachNumberAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetMachNumberAPI
self.apiTable[#self.apiTable + 1] = loGetMachNumberAPI.apiInfo

local loGetAngleOfAttackAPI = LoGetAngleOfAttackAPI:new()
local loGetAngleOfAttackAPI = LoGetAngleOfAttackAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetAngleOfAttackAPI
self.apiTable[#self.apiTable + 1] = loGetAngleOfAttackAPI.apiInfo

local loGetGlideDeviationAPI = LoGetGlideDeviationAPI:new()
local loGetGlideDeviationAPI = LoGetGlideDeviationAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetGlideDeviationAPI
self.apiTable[#self.apiTable + 1] = loGetGlideDeviationAPI.apiInfo

local loGetSideDeviationAPI = LoGetSideDeviationAPI:new()
local loGetSideDeviationAPI = LoGetSideDeviationAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetSideDeviationAPI
self.apiTable[#self.apiTable + 1] = loGetSideDeviationAPI.apiInfo

local loGetSlipBallPositionAPI = LoGetSlipBallPositionAPI:new()
local loGetSlipBallPositionAPI = LoGetSlipBallPositionAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetSlipBallPositionAPI
self.apiTable[#self.apiTable + 1] = loGetSlipBallPositionAPI.apiInfo

local loGetEngineInfoAPI = LoGetEngineInfoAPI:new()
local loGetEngineInfoAPI = LoGetEngineInfoAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetEngineInfoAPI
self.apiTable[#self.apiTable + 1] = loGetEngineInfoAPI.apiInfo

local loGetMechInfoAPI = LoGetMechInfoAPI:new()
local loGetMechInfoAPI = LoGetMechInfoAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetMechInfoAPI
self.apiTable[#self.apiTable + 1] = loGetMechInfoAPI.apiInfo

local loGetControlPanel_HSI_API = LoGetControlPanel_HSI_API:new()
local loGetControlPanel_HSI_API = LoGetControlPanel_HSI_API:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetControlPanel_HSI_API
self.apiTable[#self.apiTable + 1] = loGetControlPanel_HSI_API.apiInfo

local loGetPayloadInfoAPI = LoGetPayloadInfoAPI:new()
local loGetPayloadInfoAPI = LoGetPayloadInfoAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetPayloadInfoAPI
self.apiTable[#self.apiTable + 1] = loGetPayloadInfoAPI.apiInfo

local loGetNavigationInfoAPI = LoGetNavigationInfoAPI:new()
local loGetNavigationInfoAPI = LoGetNavigationInfoAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetNavigationInfoAPI
self.apiTable[#self.apiTable + 1] = loGetNavigationInfoAPI.apiInfo

local loGetMagneticYawAPI = LoGetMagneticYawAPI:new()
local loGetMagneticYawAPI = LoGetMagneticYawAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetMagneticYawAPI
self.apiTable[#self.apiTable + 1] = loGetMagneticYawAPI.apiInfo

local loGetBasicAtmospherePressureAPI = LoGetBasicAtmospherePressureAPI:new()
local loGetBasicAtmospherePressureAPI = LoGetBasicAtmospherePressureAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetBasicAtmospherePressureAPI
self.apiTable[#self.apiTable + 1] = loGetBasicAtmospherePressureAPI.apiInfo

local loGetMCPStateAPI = LoGetMCPStateAPI:new()
local loGetMCPStateAPI = LoGetMCPStateAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetMCPStateAPI
self.apiTable[#self.apiTable + 1] = loGetMCPStateAPI.apiInfo

local loGetTWSInfoAPI = LoGetTWSInfoAPI:new()
local loGetTWSInfoAPI = LoGetTWSInfoAPI:new(nil, counter())
self.commandsTable[#self.commandsTable + 1] = loGetTWSInfoAPI
self.apiTable[#self.apiTable + 1] = loGetTWSInfoAPI.apiInfo

Expand Down
3 changes: 3 additions & 0 deletions src/server/Scripts/DCS-INSIGHT/lib/DCS_API_defines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ end
--- DCS Cockpit Device
CockpitDevice = {}

--- Updates device's arguments (mainpanel device 0)
function CockpitDevice:update_arguments() end

--- @func Sets command for a device
--- @param command_id integer
--- @param value integer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
module("GetArgumentValue", package.seeall)
module("GetArgumentValueAPI", package.seeall)

local APIBase = require("Scripts.DCS-INSIGHT.lib.commands.common.APIBase")
local ParamName = require("Scripts.DCS-INSIGHT.lib.commands.common.ParamName")
local ParamType = require("Scripts.DCS-INSIGHT.lib.commands.common.ParamType")

-- This is the unique ID for this particular API
local API_ID = 0

--- @class GetArgumentValue : APIBase
--- @class GetArgumentValueAPI : APIBase
--- @field id number API ID
--- @field apiInfo APIInfo
local GetArgumentValue = APIBase:new()
local GetArgumentValueAPI = APIBase:new()

--- @func Returns new GetArgumentValue
--- @return GetArgumentValue
function GetArgumentValue:new(o)
o = o or APIBase:new(o, API_ID, true, "GetDevice(device_id):get_argument_value(argument_id)", 2)
--- @func Returns new GetArgumentValueAPI
--- @param o table|nil Parent
--- @param apiId integer API ID, must be unique
--- @return APIBase
function GetArgumentValueAPI:new(o, apiId)
o = o or APIBase:new(o, apiId, true, "GetDevice(device_id):get_argument_value(argument_id)", 2)

o:add_param_def(0, ParamName.device_id, ParamType.number)
o:add_param_def(1, ParamName.argument_id, ParamType.number)
Expand All @@ -26,11 +25,11 @@ function GetArgumentValue:new(o)
end

--- @func Inits with internal data
function GetArgumentValue:init() end
function GetArgumentValueAPI:init() end

--- @func Executes sent api and returns the same api containing a result field
--- @param api APIInfo
function GetArgumentValue:execute(api)
function GetArgumentValueAPI:execute(api)
local result_code, message = self:verify_params()
if result_code == 1 then
api.error_thrown = true
Expand Down Expand Up @@ -61,4 +60,4 @@ function GetArgumentValue:execute(api)
return api
end

return GetArgumentValue
return GetArgumentValueAPI
Loading

0 comments on commit c099c6d

Please sign in to comment.