More fixes in binary data transmission

This commit is contained in:
Pax1601
2023-07-02 22:13:53 +02:00
parent 807cdfeb5b
commit ec91376da2
9 changed files with 89 additions and 83 deletions

View File

@@ -1,4 +1,5 @@
import { getUnitsManager } from ".."; import { getUnitsManager } from "..";
import { Ammo } from "../@types/unit";
import { ConvertDDToDMS, rad2deg } from "../other/utils"; import { ConvertDDToDMS, rad2deg } from "../other/utils";
import { aircraftDatabase } from "../units/aircraftdatabase"; import { aircraftDatabase } from "../units/aircraftdatabase";
import { Unit } from "../units/unit"; import { Unit } from "../units/unit";
@@ -77,10 +78,10 @@ export class UnitInfoPanel extends Panel {
const ammo = Object.values(unit.getData().ammo); const ammo = Object.values(unit.getData().ammo);
if (ammo.length > 0) { if (ammo.length > 0) {
items.replaceChildren(...Object.values(unit.getData().ammo).map( items.replaceChildren(...Object.values(unit.getData().ammo).map(
(ammo: any) => { (ammo: Ammo) => {
var el = document.createElement("div"); var el = document.createElement("div");
el.dataset.qty = ammo.count; el.dataset.qty = `${ammo.quantity}`;
el.dataset.item = ammo.desc.displayName; el.dataset.item = ammo.name;
return el; return el;
} }
)); ));

View File

@@ -109,7 +109,7 @@ export class DataExtractor {
for (let idx = 0; idx < size; idx++) { for (let idx = 0; idx < size; idx++) {
value.push({ value.push({
quantity: this.extractUInt16(), quantity: this.extractUInt16(),
name: this.extractString(32), name: this.extractString(33),
guidance: this.extractUInt8(), guidance: this.extractUInt8(),
category: this.extractUInt8(), category: this.extractUInt8(),
missileCategory: this.extractUInt8() missileCategory: this.extractUInt8()

View File

@@ -35,7 +35,7 @@ export class Unit extends CustomMarker {
#heading: number = 0; #heading: number = 0;
#isTanker: boolean = false; #isTanker: boolean = false;
#isAWACS: boolean = false; #isAWACS: boolean = false;
#onOff: boolean = false; #onOff: boolean = true;
#followRoads: boolean = false; #followRoads: boolean = false;
#fuel: number = 0; #fuel: number = 0;
#desiredSpeed: number = 0; #desiredSpeed: number = 0;
@@ -60,9 +60,9 @@ export class Unit extends CustomMarker {
channel: 0 channel: 0
}; };
#radio: Radio = { #radio: Radio = {
frequency: 0, frequency: 124000000,
callsign: 0, callsign: 1,
callsignNumber: 0 callsignNumber: 1
}; };
#generalSettings: GeneralSettings = { #generalSettings: GeneralSettings = {
prohibitAA: false, prohibitAA: false,
@@ -187,10 +187,10 @@ export class Unit extends CustomMarker {
this.#updateMarker(); this.#updateMarker();
// TODO dont delete the polylines of the detected units // TODO dont delete the polylines of the detected units
this.#clearDetectedUnits(); this.#clearContacts();
if (this.getSelected()) { if (this.getSelected()) {
this.#drawPath(); this.#drawPath();
this.#drawDetectedUnits(); this.#drawContacts();
this.#drawTarget(); this.#drawTarget();
} }
else { else {
@@ -284,7 +284,7 @@ export class Unit extends CustomMarker {
} }
else { else {
document.dispatchEvent(new CustomEvent("unitDeselection", { detail: this })); document.dispatchEvent(new CustomEvent("unitDeselection", { detail: this }));
this.#clearDetectedUnits(); this.#clearContacts();
this.#clearPath(); this.#clearPath();
this.#clearTarget(); this.#clearTarget();
} }
@@ -607,8 +607,7 @@ export class Unit extends CustomMarker {
onAdd(map: Map): this { onAdd(map: Map): this {
super.onAdd(map); super.onAdd(map);
/* If this is the first time adding this unit to the map, remove the temporary marker */ /* If this is the first time adding this unit to the map, remove the temporary marker */
if (getUnitsManager().getUnitByID(this.ID) == null) getMap().removeTemporaryMarker(new LatLng(this.#position.lat, this.#position.lng));
getMap().removeTemporaryMarker(new LatLng(this.#position.lat, this.#position.lng));
return this; return this;
} }
@@ -798,13 +797,13 @@ export class Unit extends CustomMarker {
var newHasFox2 = false; var newHasFox2 = false;
var newHasFox3 = false; var newHasFox3 = false;
var newHasOtherAmmo = false; var newHasOtherAmmo = false;
Object.values(this.#ammo).forEach((ammo: any) => { Object.values(this.#ammo).forEach((ammo: Ammo) => {
if (ammo.desc.category == 1 && ammo.desc.missileCategory == 1) { if (ammo.category == 1 && ammo.missileCategory == 1) {
if (ammo.desc.guidance == 4 || ammo.desc.guidance == 5) if (ammo.guidance == 4 || ammo.guidance == 5)
newHasFox1 = true; newHasFox1 = true;
else if (ammo.desc.guidance == 2) else if (ammo.guidance == 2)
newHasFox2 = true; newHasFox2 = true;
else if (ammo.desc.guidance == 3) else if (ammo.guidance == 3)
newHasFox3 = true; newHasFox3 = true;
} }
else else
@@ -870,31 +869,31 @@ export class Unit extends CustomMarker {
this.#pathPolyline.setLatLngs([]); this.#pathPolyline.setLatLngs([]);
} }
#drawDetectedUnits() { #drawContacts() {
for (let index in this.#contacts) { for (let index in this.#contacts) {
var targetData = this.#contacts[index]; var contactData = this.#contacts[index];
var target = getUnitsManager().getUnitByID(targetData.ID) var contact = getUnitsManager().getUnitByID(contactData.ID)
if (target != null) { if (contact != null) {
var startLatLng = new LatLng(this.#position.lat, this.#position.lng) var startLatLng = new LatLng(this.#position.lat, this.#position.lng)
var endLatLng = new LatLng(target.#position.lat, target.#position.lng) var endLatLng = new LatLng(contact.#position.lat, contact.#position.lng)
var color; var color;
if (targetData.detectionMethod === 1) if (contactData.detectionMethod === 1)
color = "#FF00FF"; color = "#FF00FF";
else if (targetData.detectionMethod === 4) else if (contactData.detectionMethod === 4)
color = "#FFFF00"; color = "#FFFF00";
else if (targetData.detectionMethod === 16) else if (contactData.detectionMethod === 16)
color = "#00FF00"; color = "#00FF00";
else else
color = "#FFFFFF"; color = "#FFFFFF";
var targetPolyline = new Polyline([startLatLng, endLatLng], { color: color, weight: 3, opacity: 0.4, smoothFactor: 1, dashArray: "4, 8" }); var contactPolyline = new Polyline([startLatLng, endLatLng], { color: color, weight: 3, opacity: 0.4, smoothFactor: 1, dashArray: "4, 8" });
targetPolyline.addTo(getMap()); contactPolyline.addTo(getMap());
this.#contactsPolylines.push(targetPolyline) this.#contactsPolylines.push(contactPolyline)
} }
} }
} }
#clearDetectedUnits() { #clearContacts() {
for (let index in this.#contactsPolylines) { for (let index in this.#contactsPolylines) {
getMap().removeLayer(this.#contactsPolylines[index]) getMap().removeLayer(this.#contactsPolylines[index])
} }

View File

@@ -234,7 +234,7 @@ private:
const bool explosion; const bool explosion;
}; };
/* Follow command */ /* SetTask command */
class SetTask : public Command class SetTask : public Command
{ {
public: public:

View File

@@ -162,43 +162,43 @@ public:
virtual void setActivePath(list<Coords> newValue); virtual void setActivePath(list<Coords> newValue);
/********** Getters **********/ /********** Getters **********/
virtual const string& getCategory() { return category; }; virtual string getCategory() { return category; };
virtual const bool& getAlive() { return alive; } virtual bool getAlive() { return alive; }
virtual const bool& getHuman() { return human; } virtual bool getHuman() { return human; }
virtual const bool& getControlled() { return controlled; } virtual bool getControlled() { return controlled; }
virtual const unsigned char& getCoalition() { return coalition; } virtual unsigned char getCoalition() { return coalition; }
virtual const unsigned char& getCountry() { return country; } virtual unsigned char getCountry() { return country; }
virtual const string& getName() { return name; } virtual string getName() { return name; }
virtual const string& getUnitName() { return unitName; } virtual string getUnitName() { return unitName; }
virtual const string& getGroupName() { return groupName; } virtual string getGroupName() { return groupName; }
virtual const unsigned char& getState() { return state; } virtual unsigned char getState() { return state; }
virtual const string& getTask() { return task; } virtual string getTask() { return task; }
virtual const bool& getHasTask() { return hasTask; } virtual bool getHasTask() { return hasTask; }
virtual const Coords& getPosition() { return position; } virtual Coords getPosition() { return position; }
virtual const double& getSpeed() { return speed; } virtual double getSpeed() { return speed; }
virtual const double& getHeading() { return heading; } virtual double getHeading() { return heading; }
virtual const bool& getIsTanker() { return isTanker; } virtual bool getIsTanker() { return isTanker; }
virtual const bool& getIsAWACS() { return isAWACS; } virtual bool getIsAWACS() { return isAWACS; }
virtual const bool& getOnOff() { return onOff; }; virtual bool getOnOff() { return onOff; };
virtual const bool& getFollowRoads() { return followRoads; }; virtual bool getFollowRoads() { return followRoads; };
virtual const unsigned short& getFuel() { return fuel; } virtual unsigned short getFuel() { return fuel; }
virtual const double& getDesiredSpeed() { return desiredSpeed; }; virtual double getDesiredSpeed() { return desiredSpeed; };
virtual const bool& getDesiredSpeedType() { return desiredSpeedType; }; virtual bool getDesiredSpeedType() { return desiredSpeedType; };
virtual const double& getDesiredAltitude() { return desiredAltitude; }; virtual double getDesiredAltitude() { return desiredAltitude; };
virtual const bool& getDesiredAltitudeType() { return desiredAltitudeType; }; virtual bool getDesiredAltitudeType() { return desiredAltitudeType; };
virtual const unsigned int& getLeaderID() { return leaderID; } virtual unsigned int getLeaderID() { return leaderID; }
virtual const Offset& getFormationoffset() { return formationOffset; } virtual Offset getFormationoffset() { return formationOffset; }
virtual const unsigned int& getTargetID() { return targetID; } virtual unsigned int getTargetID() { return targetID; }
virtual const Coords& getTargetPosition() { return targetPosition; } virtual Coords getTargetPosition() { return targetPosition; }
virtual const unsigned char& getROE() { return ROE; } virtual unsigned char getROE() { return ROE; }
virtual const unsigned char& getReactionToThreat() { return reactionToThreat; } virtual unsigned char getReactionToThreat() { return reactionToThreat; }
virtual const unsigned char& getEmissionsCountermeasures() { return emissionsCountermeasures; }; virtual unsigned char getEmissionsCountermeasures() { return emissionsCountermeasures; };
virtual const DataTypes::TACAN& getTACAN() { return TACAN; } virtual DataTypes::TACAN getTACAN() { return TACAN; }
virtual const DataTypes::Radio& getRadio() { return radio; } virtual DataTypes::Radio getRadio() { return radio; }
virtual const DataTypes::GeneralSettings& getGeneralSettings() { return generalSettings; } virtual DataTypes::GeneralSettings getGeneralSettings() { return generalSettings; }
virtual const vector<DataTypes::Ammo>& getAmmo() { return ammo; } virtual vector<DataTypes::Ammo> getAmmo() { return ammo; }
virtual const vector<DataTypes::Contact>& getTargets() { return contacts; } virtual vector<DataTypes::Contact> getTargets() { return contacts; }
virtual const list<Coords>& getActivePath() { return activePath; } virtual list<Coords> getActivePath() { return activePath; }
protected: protected:
unsigned int ID; unsigned int ID;
@@ -220,7 +220,7 @@ protected:
double heading = NULL; double heading = NULL;
bool isTanker = false; bool isTanker = false;
bool isAWACS = false; bool isAWACS = false;
bool onOff = false; bool onOff = true;
bool followRoads = false; bool followRoads = false;
unsigned short fuel = 0; unsigned short fuel = 0;
double desiredSpeed = 0; double desiredSpeed = 0;
@@ -265,7 +265,7 @@ protected:
if (newValue != value) if (newValue != value)
{ {
triggerUpdate(datumIndex); triggerUpdate(datumIndex);
*(&value) = newValue; value = newValue;
} }
} }
@@ -280,7 +280,9 @@ protected:
const unsigned short size = datumValue.size(); const unsigned short size = datumValue.size();
ss.write((const char*)&datumIndex, sizeof(unsigned char)); ss.write((const char*)&datumIndex, sizeof(unsigned char));
ss.write((const char*)&size, sizeof(unsigned short)); ss.write((const char*)&size, sizeof(unsigned short));
ss.write((const char*)&datumValue, size * sizeof(T));
for (auto& el : datumValue)
ss.write((const char*)&el, sizeof(T));
} }
template <typename T> template <typename T>

View File

@@ -113,6 +113,8 @@ void AirUnit::setState(unsigned char newState)
log(unitName + " setting state from " + to_string(state) + " to " + to_string(newState)); log(unitName + " setting state from " + to_string(state) + " to " + to_string(newState));
state = newState; state = newState;
triggerUpdate(DataIndex::state);
} }
void AirUnit::AIloop() void AirUnit::AIloop()

View File

@@ -65,6 +65,8 @@ void GroundUnit::setState(unsigned char newState)
log(unitName + " setting state from " + to_string(state) + " to " + to_string(newState)); log(unitName + " setting state from " + to_string(state) + " to " + to_string(newState));
state = newState; state = newState;
triggerUpdate(DataIndex::state);
} }
void GroundUnit::AIloop() void GroundUnit::AIloop()

View File

@@ -57,6 +57,7 @@ void Scheduler::handleRequest(string key, json::value value)
Command* command = nullptr; Command* command = nullptr;
log("Received request with ID: " + key); log("Received request with ID: " + key);
log(value.serialize());
if (key.compare("setPath") == 0) if (key.compare("setPath") == 0)
{ {
unsigned int ID = value[L"ID"].as_integer(); unsigned int ID = value[L"ID"].as_integer();
@@ -146,10 +147,10 @@ void Scheduler::handleRequest(string key, json::value value)
{ {
unsigned int ID = value[L"ID"].as_integer(); unsigned int ID = value[L"ID"].as_integer();
unitsManager->acquireControl(ID); unitsManager->acquireControl(ID);
unsigned int leaderID = value[L"targetID"].as_integer(); unsigned int leaderID = value[L"targetID"].as_double();
unsigned int offsetX = value[L"offsetX"].as_integer(); double offsetX = value[L"offsetX"].as_double();
unsigned int offsetY = value[L"offsetY"].as_integer(); double offsetY = value[L"offsetY"].as_double();
unsigned int offsetZ = value[L"offsetZ"].as_integer(); double offsetZ = value[L"offsetZ"].as_double();
Unit* unit = unitsManager->getGroupLeader(ID); Unit* unit = unitsManager->getGroupLeader(ID);
Unit* leader = unitsManager->getUnit(leaderID); Unit* leader = unitsManager->getUnit(leaderID);

View File

@@ -128,7 +128,6 @@ void Unit::updateMissionData(json::value json)
if (json.has_object_field(L"ammo")) { if (json.has_object_field(L"ammo")) {
vector<DataTypes::Ammo> ammo; vector<DataTypes::Ammo> ammo;
for (auto const& el : json[L"ammo"].as_object()) { for (auto const& el : json[L"ammo"].as_object()) {
log(el.second.serialize());
DataTypes::Ammo ammoItem; DataTypes::Ammo ammoItem;
auto ammoJson = el.second; auto ammoJson = el.second;
ammoItem.quantity = ammoJson[L"count"].as_number().to_uint32(); ammoItem.quantity = ammoJson[L"count"].as_number().to_uint32();
@@ -156,12 +155,12 @@ void Unit::updateMissionData(json::value json)
contactItem.ID = contactJson[L"object"][L"id_"].as_number().to_uint32(); contactItem.ID = contactJson[L"object"][L"id_"].as_number().to_uint32();
string detectionMethod = to_string(contactJson[L"detectionMethod"]); string detectionMethod = to_string(contactJson[L"detectionMethod"]);
if (detectionMethod.compare("VISUAL")) contactItem.detectionMethod = 1; if (detectionMethod.compare("VISUAL") == 0) contactItem.detectionMethod = 1;
else if (detectionMethod.compare("OPTIC")) contactItem.detectionMethod = 2; else if (detectionMethod.compare("OPTIC") == 0) contactItem.detectionMethod = 2;
else if (detectionMethod.compare("RADAR")) contactItem.detectionMethod = 4; else if (detectionMethod.compare("RADAR") == 0) contactItem.detectionMethod = 4;
else if (detectionMethod.compare("IRST")) contactItem.detectionMethod = 8; else if (detectionMethod.compare("IRST") == 0) contactItem.detectionMethod = 8;
else if (detectionMethod.compare("RWR")) contactItem.detectionMethod = 16; else if (detectionMethod.compare("RWR") == 0) contactItem.detectionMethod = 16;
else if (detectionMethod.compare("DLINK")) contactItem.detectionMethod = 32; else if (detectionMethod.compare("DLINK") == 0) contactItem.detectionMethod = 32;
contacts.push_back(contactItem); contacts.push_back(contactItem);
} }
setContacts(contacts); setContacts(contacts);
@@ -248,7 +247,7 @@ void Unit::setContacts(vector<DataTypes::Contact> newValue)
{ {
if (contacts.size() == newValue.size()) { if (contacts.size() == newValue.size()) {
bool equal = true; bool equal = true;
for (int i = 0; i < ammo.size(); i++) { for (int i = 0; i < contacts.size(); i++) {
if (contacts.at(i) != newValue.at(i)) if (contacts.at(i) != newValue.at(i))
{ {
equal = false; equal = false;