Skip to content

Commit

Permalink
- Fix CtrlMeasures not read correctly
Browse files Browse the repository at this point in the history
- Use new OptionEnabled display data check function for point reading
- Use new display text reading function on OSB from display data for point reading
- Refactor GetTextLinesForOsbForDisplayData to return all lines (no lines if empty)
  • Loading branch information
FalcoGer committed Jan 7, 2025
1 parent 73a70e5 commit 26477e4
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 87 deletions.
85 changes: 55 additions & 30 deletions CoordinateConverter/DCS/Aircraft/AH64/AH64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ public List<CoordinateDataEntry> ReadPointsFromAC(EPointType pointType)
{
case EPointType.Waypoint:
case EPointType.Hazard:
if (!displayData.ContainsKey("PB1_1_b")) // we are not on the WPT/HZ page
if (!CheckOsbOptionEnabledForDisplayData(EKeyCode.MFD_T1, displayData, "WPTHZ")) // we are not on the WPT/HZ page
{
// go to the WPT/HZ page
commands = new List<DCSCommand>()
Expand All @@ -745,7 +745,7 @@ public List<CoordinateDataEntry> ReadPointsFromAC(EPointType pointType)
}
break;
case EPointType.ControlMeasure:
if (!displayData.ContainsKey("PB2_3_b")) // we are not on the CTRLM page
if (!CheckOsbOptionEnabledForDisplayData(EKeyCode.MFD_T2, displayData, "CTRLM")) // we are not on the CTRLM page
{
// go to the CTRLM page
commands = new List<DCSCommand>()
Expand All @@ -755,7 +755,7 @@ public List<CoordinateDataEntry> ReadPointsFromAC(EPointType pointType)
}
break;
case EPointType.Target:
if (!displayData.ContainsKey("PB5_9_b")) // we are not on the COORD (TGT/THRT) page
if (!CheckOsbOptionEnabledForDisplayData(EKeyCode.MFD_T5, displayData, "COORD")) // we are not on the COORD (TGT/THRT) page
{
// go to the COORD (TGT/THRT) page
commands = new List<DCSCommand>()
Expand Down Expand Up @@ -814,23 +814,51 @@ public List<CoordinateDataEntry> ReadPointsFromAC(EPointType pointType)

Dictionary<int, List<string>> displayDataKeysForLine = new Dictionary<int, List<string>>()
{
{ 1, new List<string>() { "PB24_21", "LABEL 1", "LABEL 2", "LABEL 5", "LABEL 6" } },
{ 2, new List<string>() { "PB23_23", "LABEL 21", "LABEL 22", "LABEL 25", "LABEL 26" } },
{ 3, new List<string>() { "PB22_25", "LABEL 41", "LABEL 42", "LABEL 45", "LABEL 46" } },
{ 4, new List<string>() { "PB21_27", "LABEL 61", "LABEL 62", "LABEL 65", "LABEL 66" } },
{ 5, new List<string>() { "PB20_29", "LABEL 81", "LABEL 82", "LABEL 85", "LABEL 86" } },
{ 6, new List<string>() { "PB19_31", "LABEL 101", "LABEL 102", "LABEL 105", "LABEL 106" } }
{ 1, new List<string>() { "LABEL 1", "LABEL 2", "LABEL 5", "LABEL 6" } },
{ 2, new List<string>() { "LABEL 21", "LABEL 22", "LABEL 25", "LABEL 26" } },
{ 3, new List<string>() { "LABEL 41", "LABEL 42", "LABEL 45", "LABEL 46" } },
{ 4, new List<string>() { "LABEL 61", "LABEL 62", "LABEL 65", "LABEL 66" } },
{ 5, new List<string>() { "LABEL 81", "LABEL 82", "LABEL 85", "LABEL 86" } },
{ 6, new List<string>() { "LABEL 101", "LABEL 102", "LABEL 105", "LABEL 106" } }
};

for (int line = 1; line <= 6; line++)
{
var keys = displayDataKeysForLine[line];
if (!displayData.ContainsKey(keys[0]))
var labelIds = displayDataKeysForLine[line];

EKeyCode keyCode;
switch (line)
{
case 1:
keyCode = EKeyCode.MFD_L1;
break;
case 2:
keyCode = EKeyCode.MFD_L2;
break;
case 3:
keyCode = EKeyCode.MFD_L3;
break;
case 4:
keyCode = EKeyCode.MFD_L4;
break;
case 5:
keyCode = EKeyCode.MFD_L5;
break;
case 6:
keyCode = EKeyCode.MFD_L6;
break;
default:
throw new Exception("Unknown line number");
}

List<string> lines = GetTextLinesForOsbForDisplayData(keyCode, displayData);

if (lines.Count == 0)
{
break; // page done
}

string pointIdStr = displayData[keys[0]]; // "W18", "H04", "T49", "C52"
string pointIdStr = lines.First(); // "W18", "H04", "T49", "C52"

string pointIdentStr;

Expand Down Expand Up @@ -860,10 +888,10 @@ public List<CoordinateDataEntry> ReadPointsFromAC(EPointType pointType)
throw new Exception("Unknown point type");
}

pointIdentStr += displayData[keys[1]]; // "LZ", "TU", "ZU", "AE"
string pointFreetextStr = displayData[keys[2]]; // "W18", "TWR", "Z23", "T90"
string pointMGRSStr = displayData[keys[3]]; // "37T DL 0192 5672"
string pointElevationStr = displayData[keys[4]]; // "17 FT"
pointIdentStr += displayData[labelIds[0]]; // "LZ", "TU", "ZU", "AE"
string pointFreetextStr = displayData[labelIds[1]]; // "W18", "TWR", "Z23", "T90"
string pointMGRSStr = displayData[labelIds[2]]; // "37T DL 0192 5672"
string pointElevationStr = displayData[labelIds[3]]; // "17 FT"

// parse the data
EPointIdent pointIdent = (EPointIdent)Enum.Parse(typeof(EPointIdent), pointIdentStr);
Expand Down Expand Up @@ -1026,7 +1054,7 @@ public int ClearPoints(EPointType pointType, int startIdx, int endIdx)
/// <param name="displayData">The display data for the display at the time</param>
/// <returns>A directory of the internal dcs push button names and it's associated text.</returns>
/// <exception cref="System.ArgumentException">Invalid key - key</exception>
static public Dictionary<string, string> GetDictionaryForDisplayDataOnPB(AH64.EKeyCode key, Dictionary<string, string> displayData)
static public Dictionary<string, string> GetDictionaryOnOsbForDisplayData(AH64.EKeyCode key, Dictionary<string, string> displayData)
{
string dcsInternalKeyName = "PB";
switch (key)
Expand Down Expand Up @@ -1118,23 +1146,20 @@ static public Dictionary<string, string> GetDictionaryForDisplayDataOnPB(AH64.EK
/// <param name="line">The line number to get, 0 indexed.</param>
/// <returns>The text for the line on that push button</returns>
/// <exception cref=">System.ArgumentException">Not enough lines, or no text at all.</exception>
static public string GetLineForDisplayDataOnPB(AH64.EKeyCode key, Dictionary<string, string> displayData, uint line)
static public List<string> GetTextLinesForOsbForDisplayData(AH64.EKeyCode key, Dictionary<string, string> displayData)
{
var dictForPB = GetDictionaryForDisplayDataOnPB(key, displayData);
// we need to discard the box key (ending with _b)
// order keys by ID (as int)
dictForPB = dictForPB.Where(kvp => !kvp.Key.EndsWith("_b")).OrderBy(kvp => int.Parse(kvp.Key.Substring(kvp.Key.LastIndexOf('_') + 1))).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

var dictForPB = GetDictionaryOnOsbForDisplayData(key, displayData);
// Keys for the lines on the displays are in the form of PB<key>_<id>
// where key is the pushbuton internal name in DCS (starting with T1, going clockwise around the OSBs)
// and id is a seemingly arbitrary number, but they are strictly ordered by line number
// and then return the line-th entry in the dictionary
// when sorted by the id.
if (dictForPB.Count < line)
{
throw new System.ArgumentException("No text at that line. number of lines: " + dictForPB.Count.ToString() + " but wanted line: " + line.ToString(), nameof(line));
}
return dictForPB.ElementAt((int)line).Value;

// we need to discard the box key (ending with _b)
// order keys by ID (as int)
dictForPB = dictForPB.Where(kvp => !kvp.Key.EndsWith("_b")).OrderBy(kvp => int.Parse(kvp.Key.Substring(kvp.Key.LastIndexOf('_') + 1))).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

return dictForPB.Select(kvp => kvp.Value).ToList();
}

/// <summary>
Expand All @@ -1146,9 +1171,9 @@ static public string GetLineForDisplayDataOnPB(AH64.EKeyCode key, Dictionary<str
/// <returns>
/// <c>true</c> if the option in display data is enabled on the push button; otherwise, <c>false</c>.
/// </returns>
static public bool IsOptionInDisplayDataEnabledOnPB(AH64.EKeyCode key, Dictionary<string, string> displayData, string checkAgainst = null)
static public bool CheckOsbOptionEnabledForDisplayData(AH64.EKeyCode key, Dictionary<string, string> displayData, string checkAgainst = null)
{
var displayDataForPB = GetDictionaryForDisplayDataOnPB(key, displayData);
var displayDataForPB = GetDictionaryOnOsbForDisplayData(key, displayData);

// check all values if any contains the checkAgainst string
if (!string.IsNullOrEmpty(checkAgainst))
Expand Down
6 changes: 3 additions & 3 deletions CoordinateConverter/DCS/Aircraft/AH64/AH64DTCData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1645,9 +1645,9 @@ public ELaserCodeProgrammSelector CurrentLaserCodeProgrammSelector
get
{
// read the current selected laser code for programming from the weapons page
List<DCSCommand> commands= new List<DCSCommand>();
List<DCSCommand> commands = new List<DCSCommand>();
int device = (int)(IsPilot ? AH64.EDeviceCode.PLT_LMFD : AH64.EDeviceCode.CPG_LMFD);

// go to weapons page
commands.Add(new DCSCommand(device, (int)AH64.EKeyCode.MFD_WPN));
// go to code page
Expand Down Expand Up @@ -1686,7 +1686,7 @@ public ELaserCodeProgrammSelector CurrentLaserCodeProgrammSelector
return ELaserCodeProgrammSelector.Lrfd;
}

string setString = AH64.GetLineForDisplayDataOnPB(AH64.EKeyCode.MFD_T2, message.CockpitDisplayData[displayToRead], 1);
string setString = AH64.GetTextLinesForOsbForDisplayData(AH64.EKeyCode.MFD_T2, message.CockpitDisplayData[displayToRead]).ElementAt(1);
switch (setString)
{
case "LST":
Expand Down
Loading

0 comments on commit 26477e4

Please sign in to comment.