mirror of
https://github.com/valmojr/armatak.git
synced 2026-06-13 15:53:28 +00:00
Added initial Laser Ranger Finder simulator on port 17211 (as default) emulate digital pointer for in game laser designators
This commit is contained in:
52
addons/client/functions/fnc_sendLaserRangeFinder.sqf
Normal file
52
addons/client/functions/fnc_sendLaserRangeFinder.sqf
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "..\script_component.hpp"
|
||||
|
||||
params ["_unit"];
|
||||
|
||||
private _lrfEnabled = player getVariable [QGVAR(lrfEnabled), false];
|
||||
|
||||
private _uid = format ["%1.LRF", _unit call armatak_fnc_extract_uuid];
|
||||
private _laserTarget = laserTarget _unit;
|
||||
|
||||
if (!isNull _laserTarget) exitWith {
|
||||
private _originASL = getPosASL _unit;
|
||||
private _targetASL = getPosASL _laserTarget;
|
||||
private _delta = _targetASL vectorDiff _originASL;
|
||||
|
||||
private _dx = _delta select 0;
|
||||
private _dy = _delta select 1;
|
||||
private _dz = _delta select 2;
|
||||
private _horizontalDistance = sqrt ((_dx * _dx) + (_dy * _dy));
|
||||
private _slantDistance = (_originASL vectorDistance _targetASL) max 1;
|
||||
private _azimuth = (((_dx atan2 _dy) + 360) mod 360);
|
||||
private _elevation = _dz atan2 (_horizontalDistance max 0.001);
|
||||
private _lastTargetASL = player getVariable [QGVAR(lrfLastTargetASL), []];
|
||||
private _lastSentAt = player getVariable [QGVAR(lrfLastSentAt), -1000];
|
||||
private _targetMoved = _lastTargetASL isEqualTo [] || {(_lastTargetASL vectorDistance _targetASL) > 5};
|
||||
private _sendCooldownElapsed = (time - _lastSentAt) >= 2.5;
|
||||
|
||||
player setVariable [QGVAR(lrfWasActive), true];
|
||||
player setVariable [QGVAR(lrfLostAt), -1];
|
||||
player setVariable [QGVAR(lrfClearSent), false];
|
||||
|
||||
if (_lrfEnabled && {_targetMoved} && {_sendCooldownElapsed}) then {
|
||||
"armatak" callExtension ["udp_socket:send_lrf", [[_uid, _slantDistance, _azimuth, _elevation]]];
|
||||
player setVariable [QGVAR(lrfLastTargetASL), _targetASL];
|
||||
player setVariable [QGVAR(lrfLastSentAt), time];
|
||||
};
|
||||
};
|
||||
|
||||
if !(player getVariable [QGVAR(lrfWasActive), false]) exitWith {};
|
||||
|
||||
private _lostAt = player getVariable [QGVAR(lrfLostAt), -1];
|
||||
if (_lostAt < 0) then {
|
||||
player setVariable [QGVAR(lrfLostAt), time];
|
||||
};
|
||||
|
||||
private _clearSent = player getVariable [QGVAR(lrfClearSent), false];
|
||||
if (_lrfEnabled && {!_clearSent} && {(time - (player getVariable [QGVAR(lrfLostAt), time])) >= 6}) then {
|
||||
"armatak" callExtension ["udp_socket:clear_lrf", [_uid]];
|
||||
player setVariable [QGVAR(lrfWasActive), false];
|
||||
player setVariable [QGVAR(lrfClearSent), true];
|
||||
player setVariable [QGVAR(lrfLastTargetASL), []];
|
||||
player setVariable [QGVAR(lrfLastSentAt), -1000];
|
||||
};
|
||||
@@ -14,24 +14,38 @@ disableSerialization;
|
||||
private _eud_address = ctrlText 16961;
|
||||
private _gnss_port = ctrlText 16962;
|
||||
private _mavlink_port = ctrlText 16967;
|
||||
private _lrf_port = ctrlText 16971;
|
||||
private _video_feed_url = ctrlText 16969;
|
||||
|
||||
private _udp_socket_fulladdress = _eud_address + ":" + _gnss_port;
|
||||
private _mavlink_address = _eud_address + ":" + _mavlink_port;
|
||||
private _lrf_port_trimmed = trim _lrf_port;
|
||||
private _lrf_enabled = _lrf_port_trimmed isNotEqualTo "";
|
||||
private _lrf_address = _eud_address + ":" + _lrf_port_trimmed;
|
||||
|
||||
player setVariable [QGVAR(udp_socket_address), _udp_socket_fulladdress];
|
||||
player setVariable [QGVAR(mavlink_address), _mavlink_address];
|
||||
player setVariable [QGVAR(lrf_address), _lrf_address];
|
||||
player setVariable [QGVAR(lrfEnabled), _lrf_enabled];
|
||||
player setVariable [QGVAR(lrfWasActive), false];
|
||||
player setVariable [QGVAR(lrfLostAt), -1];
|
||||
player setVariable [QGVAR(lrfClearSent), false];
|
||||
player setVariable [QGVAR(lrfLastTargetASL), []];
|
||||
player setVariable [QGVAR(lrfLastSentAt), -1000];
|
||||
player setVariable [QGVAR(video_feed_url), trim _video_feed_url];
|
||||
player setVariable [QGVAR(eudConnected), true];
|
||||
player setVariable [QGVAR(eudConnected), true, true];
|
||||
|
||||
private _advertised_video_uri = [objNull] call EFUNC(uav,resolveVideoUri);
|
||||
|
||||
"armatak" callExtension ["udp_socket:start", [_udp_socket_fulladdress]];
|
||||
"armatak" callExtension ["uas:start_endpoint", [parseNumber _mavlink_port]];
|
||||
if (_lrf_enabled) then {
|
||||
"armatak" callExtension ["udp_socket:start_lrf", [_lrf_address]];
|
||||
};
|
||||
|
||||
private _mdnsInstanceName = format ["ArmaTAK-%1", name player];
|
||||
"armatak" callExtension ["mdns:start_uas_advertisement", [_mdnsInstanceName, parseNumber _mavlink_port, _advertised_video_uri]];
|
||||
"armatak" callExtension ["log", [["info", format ["Client UDP socket started for %1, MAVLink target set to %2 and advertised video URI set to %3", _udp_socket_fulladdress, _mavlink_address, _advertised_video_uri]]]];
|
||||
"armatak" callExtension ["log", [["info", format ["Client UDP socket started for %1, MAVLink target set to %2, LRF target set to %3 and advertised video URI set to %4. Digital pointer uses ATAK LRF when enabled.", _udp_socket_fulladdress, _mavlink_address, _lrf_address, _advertised_video_uri]]]];
|
||||
|
||||
call EFUNC(uav,startMavlinkBroadcast);
|
||||
|
||||
@@ -41,5 +55,11 @@ call EFUNC(uav,startMavlinkBroadcast);
|
||||
"armatak" callExtension ["udp_socket:send_gps_cot", [player call FUNC(extractClientPosition)]];
|
||||
}, 0.5, []] call CBA_fnc_addPerFrameHandler;
|
||||
|
||||
[{
|
||||
if !(player getVariable [QGVAR(eudConnected), false]) exitWith {};
|
||||
|
||||
[player] call FUNC(sendLaserRangeFinder);
|
||||
}, 0.25, []] call CBA_fnc_addPerFrameHandler;
|
||||
|
||||
deleteVehicle _logic;
|
||||
closeDialog 1;
|
||||
|
||||
Reference in New Issue
Block a user