diff --git a/MATLAB/+XPlaneConnect/closeUDP.m b/MATLAB/+XPlaneConnect/closeUDP.m index 404cef8..0575ddb 100644 --- a/MATLAB/+XPlaneConnect/closeUDP.m +++ b/MATLAB/+XPlaneConnect/closeUDP.m @@ -23,4 +23,6 @@ function [socket] = closeUDP(socket) socket.close; +assert(isequal(socket.isClosed(),1),'closeUDP: Error- Could not close socket'); + end \ No newline at end of file diff --git a/MATLAB/+XPlaneConnect/openUDP.m b/MATLAB/+XPlaneConnect/openUDP.m index fba3a71..77aa43f 100644 --- a/MATLAB/+XPlaneConnect/openUDP.m +++ b/MATLAB/+XPlaneConnect/openUDP.m @@ -36,4 +36,6 @@ if ~isempty(varargin) end end +assert(isequal(socket.isClosed(),0),'openUDP: Error- Could not open port'); + end diff --git a/MATLAB/+XPlaneConnect/readDATA.m b/MATLAB/+XPlaneConnect/readDATA.m index bede1ee..f0492a5 100644 --- a/MATLAB/+XPlaneConnect/readDATA.m +++ b/MATLAB/+XPlaneConnect/readDATA.m @@ -67,7 +67,7 @@ function [ sensor ] = readDATA( socket ) dim1 = sensor.raw(a); dim2 = sensor.raw(a+1); if dim1 == 0 %String - value = char(sensor.raw(a+2:a+1+dim2)); + value = char(sensor.raw(a+2:a+1+dim2))'; a = a + dim2 + 2; else value = []; diff --git a/MATLAB/+XPlaneConnect/readUDP.m b/MATLAB/+XPlaneConnect/readUDP.m index cae4f2f..32a8b0c 100644 --- a/MATLAB/+XPlaneConnect/readUDP.m +++ b/MATLAB/+XPlaneConnect/readUDP.m @@ -50,7 +50,7 @@ function [ data ] = readUDP( input ) data = int16(data); data(data(:)<0) = uint8(data(data(:)<0) + 256); %fix signed issue size = int16(data(5)); %size of data stream - + %% trim trailing data for i=1:floor(length(data)/256)+1 if data(size+1:end)==0 diff --git a/MATLAB/+XPlaneConnect/sendCTRL.m b/MATLAB/+XPlaneConnect/sendCTRL.m index 15dfb10..722fdca 100644 --- a/MATLAB/+XPlaneConnect/sendCTRL.m +++ b/MATLAB/+XPlaneConnect/sendCTRL.m @@ -36,7 +36,7 @@ import XPlaneConnect.* %% Handle Input % Optional parameters - if ~exist('IP','var'), IP = "127.0.0.1"; end + if ~exist('IP','var'), IP = '127.0.0.1'; end if ~exist('port','var'), port = 49009; end if ~exist('acft','var'), acft = 0; end @@ -44,7 +44,7 @@ import XPlaneConnect.* %%BODY header = ['CTRL'-0,0]; - dataStream = [header, acft]; + dataStream = header; %TODO-ADD ACFT % Deal with position update control = [0, 0, 0, 0.8, 0, 1]; @@ -55,7 +55,7 @@ import XPlaneConnect.* dataStream = [dataStream, typecast(single(control),'uint8')]; % Send DATA - status = sendUDP(IP, port, dataStream); - + status = sendUDP(dataStream, IP, port); + end diff --git a/MATLAB/+XPlaneConnect/sendUDP.m b/MATLAB/+XPlaneConnect/sendUDP.m index bdb1989..6b0b112 100644 --- a/MATLAB/+XPlaneConnect/sendUDP.m +++ b/MATLAB/+XPlaneConnect/sendUDP.m @@ -42,16 +42,8 @@ function [ status ] = sendUDP( data, IP, port ) end end - try - IP = InetAddress.getByName(IP); - packet = DatagramPacket(data, length(data), IP, port); %create packet - socket.send(packet); - catch err - status = 1; - disp(err) - end - - - + IP = InetAddress.getByName(IP); + packet = DatagramPacket(data, length(data), IP, port); %create packet + socket.send(packet); end diff --git a/TestScripts/C Tests.xcodeproj/project.xcworkspace/xcuserdata/cteubert.xcuserdatad/UserInterfaceState.xcuserstate b/TestScripts/C Tests.xcodeproj/project.xcworkspace/xcuserdata/cteubert.xcuserdatad/UserInterfaceState.xcuserstate index 92637e3..c90ffe9 100644 Binary files a/TestScripts/C Tests.xcodeproj/project.xcworkspace/xcuserdata/cteubert.xcuserdatad/UserInterfaceState.xcuserstate and b/TestScripts/C Tests.xcodeproj/project.xcworkspace/xcuserdata/cteubert.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/TestScripts/CPP Tests/XPC_Tests.1 b/TestScripts/CPP Tests/Cpp_Tests.1 similarity index 100% rename from TestScripts/CPP Tests/XPC_Tests.1 rename to TestScripts/CPP Tests/Cpp_Tests.1 diff --git a/TestScripts/Cpp Tests.xcodeproj/project.pbxproj b/TestScripts/Cpp Tests.xcodeproj/project.pbxproj index 02d3e37..b22b04d 100644 --- a/TestScripts/Cpp Tests.xcodeproj/project.pbxproj +++ b/TestScripts/Cpp Tests.xcodeproj/project.pbxproj @@ -26,7 +26,7 @@ /* Begin PBXFileReference section */ BE7C5C001A28F72F00F246B9 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main.cpp; path = "CPP Tests/main.cpp"; sourceTree = SOURCE_ROOT; }; - BE7C5C011A28F72F00F246B9 /* XPC_Tests.1 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.man; name = XPC_Tests.1; path = "CPP Tests/XPC_Tests.1"; sourceTree = SOURCE_ROOT; }; + BE7C5C011A28F72F00F246B9 /* Cpp_Tests.1 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.man; name = Cpp_Tests.1; path = "CPP Tests/Cpp_Tests.1"; sourceTree = SOURCE_ROOT; }; BE9C6BAB1A253FA100EBE08A /* Cpp Tests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "Cpp Tests"; sourceTree = BUILT_PRODUCTS_DIR; }; BEB0F4F61A28F7B0001975A6 /* xplaneConnect.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = xplaneConnect.c; path = ../C/src/xplaneConnect.c; sourceTree = ""; }; BEB0F4F71A28F7B0001975A6 /* xplaneConnect.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = xplaneConnect.h; path = ../C/src/xplaneConnect.h; sourceTree = ""; }; @@ -65,7 +65,7 @@ isa = PBXGroup; children = ( BE7C5C001A28F72F00F246B9 /* main.cpp */, - BE7C5C011A28F72F00F246B9 /* XPC_Tests.1 */, + BE7C5C011A28F72F00F246B9 /* Cpp_Tests.1 */, ); name = "Cpp Tests"; path = "XPC Tests"; diff --git a/TestScripts/Cpp Tests.xcodeproj/project.xcworkspace/xcuserdata/cteubert.xcuserdatad/UserInterfaceState.xcuserstate b/TestScripts/Cpp Tests.xcodeproj/project.xcworkspace/xcuserdata/cteubert.xcuserdatad/UserInterfaceState.xcuserstate index 89a6cd4..73c5526 100644 Binary files a/TestScripts/Cpp Tests.xcodeproj/project.xcworkspace/xcuserdata/cteubert.xcuserdatad/UserInterfaceState.xcuserstate and b/TestScripts/Cpp Tests.xcodeproj/project.xcworkspace/xcuserdata/cteubert.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/TestScripts/MATLAB Tests/CTRLTest.m b/TestScripts/MATLAB Tests/CTRLTest.m new file mode 100644 index 0000000..9bacf13 --- /dev/null +++ b/TestScripts/MATLAB Tests/CTRLTest.m @@ -0,0 +1,26 @@ +function CTRLTest( ) +%CTRLTest Summary of this function goes here +% Detailed explanation goes here +addpath('../../MATLAB') +import XPlaneConnect.* + +DREFS = {'sim/cockpit2/controls/yoke_pitch_ratio',... + 'sim/cockpit2/controls/yoke_roll_ratio',... + 'sim/cockpit2/controls/yoke_heading_ratio',... + 'sim/flightmodel/engine/ENGN_thro',... + 'sim/cockpit/switches/gear_handle_status',... + 'sim/flightmodel/controls/flaprqst'}; +THROT = rand(); +CTRL = [0.0, 0.0, 1.0, THROT, 0.0, 1.0]; + +sendCTRL(CTRL); +result = requestDREF(DREFS); + +assert(isequal(length(result),6),'CTRLTest: requestDREF unsucessful-wrong number of elements returned'); +assert(isequal(length(result{4}),8),'CTRLTest: requestDREF unsucessful- element 1 incorrect size (should be size 8)'); +for i=1:length(CTRL)-1 + assert(abs(result{i}(1)-CTRL(i))<1e-4,['CTRLTest: DATA set unsucessful-',num2str(i)]); +end + +end + diff --git a/TestScripts/MATLAB Tests/DATATest.m b/TestScripts/MATLAB Tests/DATATest.m new file mode 100644 index 0000000..4c69a5d --- /dev/null +++ b/TestScripts/MATLAB Tests/DATATest.m @@ -0,0 +1,20 @@ +function DATATest( ) +%DATATest Summary of this function goes here +% Detailed explanation goes here +addpath('../../MATLAB') +import XPlaneConnect.* + +DREFS = {'sim/flightmodel/engine/ENGN_thro'}; + +value = rand(); +data = struct('h',25,'d',[value,-998,-998,-998,-998,-998,-998,-998]); + +sendDATA(data); +result = requestDREF(DREFS); + +assert(isequal(length(result),1),'DATATest: requestDREF unsucessful-wrong number of elements returned'); +assert(isequal(length(result{1}),8),'DATATest: requestDREF unsucessful- element 1 incorrect size (should be size 8)'); +assert(abs(result{1}(1)-value)<1e-4,'DATATest: DATA set unsucessful'); + +end + diff --git a/TestScripts/MATLAB Tests/POSITest.m b/TestScripts/MATLAB Tests/POSITest.m new file mode 100644 index 0000000..110d769 --- /dev/null +++ b/TestScripts/MATLAB Tests/POSITest.m @@ -0,0 +1,28 @@ +function POSITest( ) +%POSITest Summary of this function goes here +% Detailed explanation goes here +addpath('../../MATLAB') +import XPlaneConnect.* + +DREFS = {'sim/flightmodel/position/latitude', ... + 'sim/flightmodel/position/longitude', ... + 'sim/flightmodel/position/y_agl', ... + 'sim/flightmodel/position/phi', ... + 'sim/flightmodel/position/theta', ... + 'sim/flightmodel/position/psi', ... + 'sim/cockpit/switches/gear_handle_status'}; +POSI = [37.524, -122.06899, 2500, 0, 0, 0, 1]; % Gear + +sendPOSI(POSI); +result = requestDREF(DREFS); + +assert(isequal(length(result),7),'POSITest: requestDREF unsucessful-wrong number of elements returned'); +for i=1:length(POSI) + if i==3 + continue + end + assert(abs(result{i}(1)-POSI(i))<1e-4,['POSITest: DATA set unsucessful-',num2str(i)]); +end + +end + diff --git a/TestScripts/MATLAB Tests/openCloseTest.m b/TestScripts/MATLAB Tests/openCloseTest.m new file mode 100644 index 0000000..b05a497 --- /dev/null +++ b/TestScripts/MATLAB Tests/openCloseTest.m @@ -0,0 +1,12 @@ +function openCloseTest() +%OPENCLOSETEST Summary of this function goes here +% Detailed explanation goes here +addpath('../../MATLAB') +import XPlaneConnect.* + +socket = openUDP( 49007 ); + +closeUDP( socket ); + +end + diff --git a/TestScripts/MATLAB Tests/pauseTest.m b/TestScripts/MATLAB Tests/pauseTest.m new file mode 100644 index 0000000..c7979a6 --- /dev/null +++ b/TestScripts/MATLAB Tests/pauseTest.m @@ -0,0 +1,25 @@ +function pauseTest( ) +%PauseTest Summary of this function goes here +% Detailed explanation goes here +addpath('../../MATLAB') +import XPlaneConnect.* + +DREFS = {'sim/operation/override/override_planepath'}; +value = 0; % Resume + +pauseSim(value); +result = requestDREF(DREFS); + +assert(isequal(length(result),1),'pauseTest: requestDREF unsucessful-wrong number of elements returned'); +assert(abs(result{1}(1)-value)<1e-4,'pauseTest: Pause Unsuccessful'); + +value = 1; % Pause + +pauseSim(value); +result = requestDREF(DREFS); + +assert(isequal(length(result),1),'pauseTest: requestDREF unsucessful-wrong number of elements returned'); +assert(abs(result{1}(1)-value)<1e-4,'pauseTest: Pause Unsuccessful'); + +end + diff --git a/TestScripts/MATLAB Tests/requestDREFTest.m b/TestScripts/MATLAB Tests/requestDREFTest.m new file mode 100644 index 0000000..e9ce4d3 --- /dev/null +++ b/TestScripts/MATLAB Tests/requestDREFTest.m @@ -0,0 +1,17 @@ +function requestDREFTest( ) +%SENDREADTEST Summary of this function goes here +% Detailed explanation goes here +addpath('../../MATLAB') +import XPlaneConnect.* + +DREFS = {'sim/cockpit/switches/gear_handle_status',... + 'cockpit2/switches/panel_brightness_ratio'}; + +result = requestDREF(DREFS); + +assert(isequal(length(result),2)); +assert(isequal(length(result{1}),1)); +assert(isequal(length(result{2}),4)); + +end + diff --git a/TestScripts/MATLAB Tests/sendDREFTest.m b/TestScripts/MATLAB Tests/sendDREFTest.m new file mode 100644 index 0000000..e688d08 --- /dev/null +++ b/TestScripts/MATLAB Tests/sendDREFTest.m @@ -0,0 +1,19 @@ +function sendDREFTest( ) +%SENDREADTEST Summary of this function goes here +% Detailed explanation goes here +addpath('../../MATLAB') +import XPlaneConnect.* + +DREFS = {'sim/cockpit/switches/gear_handle_status'}; +value = randi([0 10]); + +sendDREF(DREFS{1},value); +result = requestDREF(DREFS); + +assert(isequal(length(result),1),'sendDREFTest: requestDREF unsucessful-wrong number of elements returned'); +assert(isequal(length(result{1}),1),'sendDREFTest: requestDREF unsucessful- element 1 incorrect size (should be size 1)'); + +assert(isequal(result{1},value),'sendDREFTest: DREF set unsucessful'); + +end + diff --git a/TestScripts/MATLAB Tests/sendReadTest.m b/TestScripts/MATLAB Tests/sendReadTest.m new file mode 100644 index 0000000..62bca30 --- /dev/null +++ b/TestScripts/MATLAB Tests/sendReadTest.m @@ -0,0 +1,18 @@ +function sendReadTest( ) +%SENDREADTEST Summary of this function goes here +% Detailed explanation goes here +addpath('../../MATLAB') +import XPlaneConnect.* + +recvPortNum = 49074; +recvPort = openUDP(49074); + +sendUDP('test2'-0,'127.0.0.1',49074); +result = readUDP(recvPort); +closeUDP(recvPort); + +assert(~isequal(result,-998), 'no data received'); +assert(all(result(1:4)'=='test'-0)); + +end + diff --git a/TestScripts/MATLAB Tests/setConnTest.m b/TestScripts/MATLAB Tests/setConnTest.m new file mode 100644 index 0000000..e0f8c30 --- /dev/null +++ b/TestScripts/MATLAB Tests/setConnTest.m @@ -0,0 +1,18 @@ +function setConnTest( ) + +disp('Not Functional Yet!') +%setConnTest Summary of this function goes here +% Detailed explanation goes here +addpath('../../MATLAB') +import XPlaneConnect.* + +DREFS = {'sim/operation/override/override_planepath'}; +value = 0; % Resume + +setConn(value); +result = requestDREF(DREFS); + +assert(isequal(length(result),1),'setConnTest: requestDREF unsucessful-wrong number of elements returned'); + +end + diff --git a/TestScripts/MATLAB Tests/struTest.m b/TestScripts/MATLAB Tests/struTest.m new file mode 100644 index 0000000..028e9bd --- /dev/null +++ b/TestScripts/MATLAB Tests/struTest.m @@ -0,0 +1,19 @@ +function struTest( ) +%STRUTEST Summary of this function goes here +% Detailed explanation goes here +addpath('../../MATLAB') +import XPlaneConnect.* + +recvNum = 49076; +recvPort = openUDP(recvNum); + +testSTRU = struct('h',15,'d',[12, 34, 55, 99, 1, 0],'test','theTest'); + +sendSTRU(testSTRU,'127.0.0.1',recvNum); +resultSTRU = readDATA(recvPort); +closeUDP(recvPort); +resultSTRU = rmfield(resultSTRU,'raw'); +assert(isequal(testSTRU,resultSTRU),'struTest: Error-structs are not equal'); + +end + diff --git a/TestScripts/MATLAB Tests/tests.m b/TestScripts/MATLAB Tests/tests.m new file mode 100644 index 0000000..4a8faae --- /dev/null +++ b/TestScripts/MATLAB Tests/tests.m @@ -0,0 +1,39 @@ +testsPassed=0; +testsFailed=0; +if ismac() + os = 'Mac'; +elseif ispc() + os = 'Win'; +else + os = 'Linux'; +end + +disp(['XPC Tests-MATLAB (', os, ')']); + +theTests = {{@openCloseTest, 'Open/Close Test', 0},... + {@sendReadTest,'Send/Read Test', 0},... + {@requestDREFTest,'Request DREF Test', 0},... + {@sendDREFTest,'Send DREF Test', 0},... + {@DATATest,'DATA Test', 0},... + {@CTRLTest,'CTRL Test', 0},... + {@POSITest,'POSI Test', 0},... + {@pauseTest,'Pause Test', 0},... + {@struTest,'Struct Test', 0}}; + +for i=1:length(theTests) + fprintf(['Test ',num2str(i),': ',theTests{i}{2},' - ']); + try + theTests{i}{1}(); + disp('SUCCESS'); + theTests{i}{3} = 1; + testsPassed = testsPassed+1; + catch err + disp('FAILURE'); + fprintf('\t%s\n',err.message); + theTests{i}{3} = -1; + testsFailed = testsFailed + 1; + end +end + +disp('Results Summary:'); +fprintf('Passed: %i\tFailed: %i\n',testsPassed, testsFailed); \ No newline at end of file