From 4a9019342698d1b55a9026d74a20161b46fff0fa Mon Sep 17 00:00:00 2001 From: Pax1601 Date: Thu, 13 Apr 2023 08:09:15 +0200 Subject: [PATCH] Added functions to set TACAN and radio frequencies --- client/src/panels/unitcontrolpanel.ts | 3 +- client/src/server/server.ts | 5 +- client/src/units/unit.ts | 4 +- scripts/OlympusCommand.lua | 2 +- src/core/include/unit.h | 40 +++++++----- src/core/src/scheduler.cpp | 15 ++++- src/core/src/unit.cpp | 88 ++++++++++++++++++++++++++- src/dcstools/include/dcstools.h | 1 + src/dcstools/src/dcstools.cpp | 7 ++- 9 files changed, 138 insertions(+), 27 deletions(-) diff --git a/client/src/panels/unitcontrolpanel.ts b/client/src/panels/unitcontrolpanel.ts index 8c71b386..d2f010e7 100644 --- a/client/src/panels/unitcontrolpanel.ts +++ b/client/src/panels/unitcontrolpanel.ts @@ -248,11 +248,12 @@ export class UnitControlPanel extends Panel { const radioMHz = Number(this.#advancedSettingsDialog.querySelector("#radio-mhz")?.querySelector("input")?.value); const radioDecimals = this.#radioDecimalsDropdown.getValue(); const radioCallsign = this.#radioCallsignDropdown.getIndex(); + const radioCallsignNumber = Number(this.#advancedSettingsDialog.querySelector("#radio-callsign-number")?.querySelector("input")?.value); var radioFrequency = (radioMHz * 1000 + Number(radioDecimals.substring(1))) * 1000; var units = getUnitsManager().getSelectedUnits(); if (units.length > 0) - units[0].setAdvancedOptions(isTanker, isAWACS, TACANChannel, TACANXY, TACANCallsign, radioFrequency, radioCallsign); + units[0].setAdvancedOptions(isTanker, isAWACS, TACANChannel, TACANXY, TACANCallsign, radioFrequency, radioCallsign, radioCallsignNumber); } } \ No newline at end of file diff --git a/client/src/server/server.ts b/client/src/server/server.ts index b6ee81d2..48e89148 100644 --- a/client/src/server/server.ts +++ b/client/src/server/server.ts @@ -183,7 +183,7 @@ export function refuel(ID: number) { POST(data, () => { }); } -export function setAdvacedOptions(ID: number, isTanker: boolean, isAWACS: boolean, TACANChannel: number, TACANXY: string, TACANCallsign: string, radioFrequency: number, radioCallsign: number) +export function setAdvacedOptions(ID: number, isTanker: boolean, isAWACS: boolean, TACANChannel: number, TACANXY: string, TACANCallsign: string, radioFrequency: number, radioCallsign: number, radioCallsignNumber: number) { var command = { "ID": ID, "isTanker": isTanker, @@ -192,7 +192,8 @@ export function setAdvacedOptions(ID: number, isTanker: boolean, isAWACS: boolea "TACANXY": TACANXY, "TACANCallsign": TACANCallsign, "radioFrequency": radioFrequency, - "radioCallsign": radioCallsign + "radioCallsign": radioCallsign, + "radioCallsignNumber": radioCallsignNumber }; var data = { "setAdvancedOptions": command }; diff --git a/client/src/units/unit.ts b/client/src/units/unit.ts index 24f40250..35836b16 100644 --- a/client/src/units/unit.ts +++ b/client/src/units/unit.ts @@ -376,8 +376,8 @@ export class Unit extends Marker { refuel(this.ID); } - setAdvancedOptions(isTanker: boolean, isAWACS: boolean, TACANChannel: number, TACANXY: string, TACANcallsign: string, radioFrequency: number, radioCallsign: number) { - setAdvacedOptions(this.ID, isTanker, isAWACS, TACANChannel, TACANXY, TACANcallsign, radioFrequency, radioCallsign); + setAdvancedOptions(isTanker: boolean, isAWACS: boolean, TACANChannel: number, TACANXY: string, TACANcallsign: string, radioFrequency: number, radioCallsign: number, radioCallsignNumber: number) { + setAdvacedOptions(this.ID, isTanker, isAWACS, TACANChannel, TACANXY, TACANcallsign, radioFrequency, radioCallsign, radioCallsignNumber); } #onClick(e: any) { diff --git a/scripts/OlympusCommand.lua b/scripts/OlympusCommand.lua index 1563ebfb..0c087c0a 100644 --- a/scripts/OlympusCommand.lua +++ b/scripts/OlympusCommand.lua @@ -399,7 +399,7 @@ function Olympus.setCommand(ID, command) end function Olympus.setOption(ID, optionID, optionValue) - Olympus.debug("Olympus.setCommand " .. ID .. " " .. optionID .. " " .. optionValue, 2) + Olympus.debug("Olympus.setOption " .. ID .. " " .. optionID .. " " .. optionValue, 2) local unit = Olympus.getUnitByID(ID) if unit then unit:getGroup():getController():setOption(optionID, optionValue) diff --git a/src/core/include/unit.h b/src/core/include/unit.h index 2c3c15d4..92b50083 100644 --- a/src/core/include/unit.h +++ b/src/core/include/unit.h @@ -105,12 +105,16 @@ public: void setTargetID(int newTargetID) { targetID = newTargetID; addMeasure(L"targetID", json::value(newTargetID));} void setIsTanker(bool newIsTanker) { isTanker = newIsTanker; addMeasure(L"isTanker", json::value(newIsTanker));} void setIsAWACS(bool newIsAWACS) { isAWACS = newIsAWACS; addMeasure(L"isAWACS", json::value(newIsAWACS));} - void setRadioOn(bool newRadioOn) { radioOn = newRadioOn; addMeasure(L"radioOn", json::value(newRadioOn)); } - void setTACANOn(bool newTACANOn) { TACANOn = newTACANOn; addMeasure(L"TACANOn", json::value(newTACANOn)); } - void setRadioFrequency(int newRadioFrequency) { radioFrequency = newRadioFrequency; addMeasure(L"radioFrequency", json::value(newRadioFrequency)); } - void setTACANChannel(int newTACANChannel) { TACANChannel = newTACANChannel; addMeasure(L"TACANChannel", json::value(newTACANChannel)); } - void setTACANXY(wstring newTACANXY) { TACANXY = newTACANXY; addMeasure(L"TACANXY", json::value(newTACANXY)); } - void setTACANCallsign(wstring newTACANCallsign) { TACANCallsign = newTACANCallsign; addMeasure(L"TACANCallsign", json::value(newTACANCallsign)); } + void setTACANOn(bool newTACANOn); + void setTACANChannel(int newTACANChannel); + void setTACANXY(wstring newTACANXY); + void setTACANCallsign(wstring newTACANCallsign); + void setTACAN(); + void setRadioOn(bool newRadioOn); + void setRadioFrequency(int newRadioFrequency); + void setRadioCallsign(int newRadioCallsign); + void setRadioCallsignNumber(int newRadioCallsignNumber); + void setRadio(); wstring getCurrentTask() { return currentTask; } virtual double getTargetSpeed() { return targetSpeed; }; virtual double getTargetAltitude() { return targetAltitude; }; @@ -119,12 +123,14 @@ public: int getTargetID() { return targetID; } bool getIsTanker() { return isTanker; } bool getIsAWACS() { return isAWACS; } - bool setRadioOn() { return radioOn; } - bool setTACANOn() { return TACANOn; } - int setRadioFrequency() { return radioFrequency; } - int setTACANChannel() { return TACANChannel; } - wstring setTACANXY() { return TACANXY; } - wstring setTACANCallsign() { return TACANCallsign; } + bool getTACANOn() { return TACANOn; } + int getTACANChannel() { return TACANChannel; } + wstring getTACANXY() { return TACANXY; } + wstring getTACANCallsign() { return TACANCallsign; } + bool getRadioOn() { return radioOn; } + int getRadioFrequency() { return radioFrequency; } + int getRadioCallsign() { return radioCallsign; } + int getRadioCallsignNumber() { return radioCallsignNumber; } /********** Options data **********/ void setROE(wstring newROE); @@ -186,12 +192,14 @@ protected: int targetID = NULL; bool isTanker = false; bool isAWACS = false; - bool radioOn = false; bool TACANOn = false; - int radioFrequency = 0; int TACANChannel = 0; - wstring TACANXY = "X"; - wstring TACANCallsign = "TKR"; + wstring TACANXY = L"X"; + wstring TACANCallsign = L"TKR"; + bool radioOn = false; + int radioFrequency = 0; + int radioCallsign = 0; + int radioCallsignNumber = 1; /********** Options data **********/ wstring ROE = L""; diff --git a/src/core/src/scheduler.cpp b/src/core/src/scheduler.cpp index aa5a5475..61dc7507 100644 --- a/src/core/src/scheduler.cpp +++ b/src/core/src/scheduler.cpp @@ -264,11 +264,20 @@ void Scheduler::handleRequest(wstring key, json::value value) { unit->setIsTanker(value[L"isTanker"].as_bool()); unit->setIsAWACS(value[L"isAWACS"].as_bool()); - unit->setRadioOn(value[L"radioOn"].as_bool()); - unit->setTACANOn(value[L"TACANOn"].as_bool()); - unit->setTACANCallsign(value[L"TACANCallsign"].as_string()); + + unit->setTACANOn(true); // TODO Remove unit->setTACANChannel(value[L"TACANChannel"].as_number().to_int32()); unit->setTACANXY(value[L"TACANXY"].as_string()); + unit->setTACANCallsign(value[L"TACANCallsign"].as_string()); + unit->setTACAN(); + + unit->setRadioOn(true); // TODO Remove + unit->setRadioFrequency(value[L"radioFrequency"].as_number().to_int32()); + unit->setRadioCallsign(value[L"radioCallsign"].as_number().to_int32()); + unit->setRadioCallsignNumber(value[L"radioCallsignNumber"].as_number().to_int32()); + unit->setRadio(); + + unit->resetActiveDestination(); } } else diff --git a/src/core/src/unit.cpp b/src/core/src/unit.cpp index 5c14c6bd..7d77aa1e 100644 --- a/src/core/src/unit.cpp +++ b/src/core/src/unit.cpp @@ -346,4 +346,90 @@ void Unit::landAt(Coords loc) { clearActivePath(); pushActivePathBack(loc); setState(State::LAND); -} \ No newline at end of file +} + +void Unit::setTACANOn(bool newTACANOn) { + TACANOn = newTACANOn; + addMeasure(L"TACANOn", json::value(newTACANOn)); +} + +void Unit::setTACANChannel(int newTACANChannel) { + TACANChannel = newTACANChannel; + addMeasure(L"TACANChannel", json::value(newTACANChannel)); +} + +void Unit::setTACANXY(wstring newTACANXY) { + TACANXY = newTACANXY; + addMeasure(L"TACANXY", json::value(newTACANXY)); +} +void Unit::setTACANCallsign(wstring newTACANCallsign) { + TACANCallsign = newTACANCallsign; + addMeasure(L"TACANCallsign", json::value(newTACANCallsign)); +} + +void Unit::setRadioOn(bool newRadioOn) { + radioOn = newRadioOn; + addMeasure(L"radioOn", json::value(newRadioOn)); +} + +void Unit::setRadioFrequency(int newRadioFrequency) { + radioFrequency = newRadioFrequency; + addMeasure(L"radioFrequency", json::value(newRadioFrequency)); +} + +void Unit::setRadioCallsign(int newRadioCallsign) { + radioCallsign = newRadioCallsign; + addMeasure(L"radioCallsign", json::value(newRadioCallsign)); +} + +void Unit::setRadioCallsignNumber(int newRadioCallsignNumber) { + radioCallsignNumber = newRadioCallsignNumber; + addMeasure(L"radioCallsignNumber", json::value(newRadioCallsignNumber)); +} + +void Unit::setTACAN() +{ + std::wostringstream commandSS; + commandSS << "{" + << "id = 'ActivateBeacon'," + << "params = {" + << "type = 4," + << "system = 4," + << "name = Olympus_TACAN," + << "callsign = " << TACANCallsign << ", " + << "frequency = " << TACANChannelToFrequency(TACANChannel, TACANXY) << "," + << "}" + << "}"; + Command* command = dynamic_cast(new SetCommand(ID, commandSS.str())); + scheduler->appendCommand(command); +} + +void Unit::setRadio() +{ + { + std::wostringstream commandSS; + commandSS << "{" + << "id = 'SetFrequency'," + << "params = {" + << "modulation = 0," // TODO Allow selection + << "frequency = " << TACANChannelToFrequency(TACANChannel, TACANXY) << "," + << "}" + << "}"; + Command* command = dynamic_cast(new SetCommand(ID, commandSS.str())); + scheduler->appendCommand(command); + } + + { + std::wostringstream commandSS; + commandSS << "{" + << "id = 'SetCallsign'," + << "params = {" + << "callname = " << radioCallsign << "," + << "number = " << radioCallsignNumber << "," + << "}" + << "}"; + Command* command = dynamic_cast(new SetCommand(ID, commandSS.str())); + scheduler->appendCommand(command); + } +} + diff --git a/src/dcstools/include/dcstools.h b/src/dcstools/include/dcstools.h index b4866db4..db8ff519 100644 --- a/src/dcstools/include/dcstools.h +++ b/src/dcstools/include/dcstools.h @@ -8,4 +8,5 @@ void DllExport LogError(lua_State* L, string message); void DllExport Log(lua_State* L, string message, int level); int DllExport dostring_in(lua_State* L, string target, string command); map DllExport getAllUnits(lua_State* L); +int DllExport TACANChannelToFrequency(int channel, wstring XY); diff --git a/src/dcstools/src/dcstools.cpp b/src/dcstools/src/dcstools.cpp index 3995f9b5..1af8ebf2 100644 --- a/src/dcstools/src/dcstools.cpp +++ b/src/dcstools/src/dcstools.cpp @@ -94,7 +94,6 @@ exit: return units; } - int dostring_in(lua_State* L, string target, string command) { lua_getglobal(L, "net"); @@ -102,4 +101,10 @@ int dostring_in(lua_State* L, string target, string command) lua_pushstring(L, target.c_str()); lua_pushstring(L, command.c_str()); return lua_pcall(L, 2, 0, 0); +} + +int TACANChannelToFrequency(int channel, wstring XY) +{ + int basef = (XY == L"X" && channel > 63) || (XY == L"Y" && channel < 64) ? 1087000000 : 961000000; + return basef + 1000000 * channel; } \ No newline at end of file