clear
clc
wirelessnetworkSupportPackageCheck;
networkSimulator = wirelessNetworkSimulator.init;
rng(1,"combRecursive");
simulationTime = 0.05;
numNodes = 17;
accessPointCfg = wlanDeviceConfig(Mode="AP",MCS=2,TransmitPower=15);
stationCfg = wlanDeviceConfig(Mode="STA",MCS=2,TransmitPower=15);
apPositions=[2 2 3];
sta1Positions=[0.5 0.5 0];
sta2Positions=[1.5 0.5 0];
sta3Positions=[2.5 0.5 0];
sta4Positions=[3.5 0.5 0];
sta5Positions=[0.5 1.5 0];
sta6Positions=[1.5 1.5 0];
sta7Positions=[2.5 1.5 0];
sta8Positions=[3.5 1.5 0];
sta9Positions=[0.5 2.5 0];
sta10Positions=[1.5 2.5 0];
sta11Positions=[2.5 2.5 0];
sta12Positions=[3.5 2.5 0];
sta13Positions=[0.5 3.5 0];
sta14Positions=[1.5 3.5 0];
sta15Positions=[2.5 3.5 0];
sta16Positions=[3.5 3.5 0];
accessPoint = wlanNode(Name="AP",Position=apPositions,DeviceConfig=accessPointCfg);
sta1 = wlanNode(Name="STA1",Position=sta1Positions,DeviceConfig=stationCfg);
sta2 = wlanNode(Name="STA2",Position=sta2Positions,DeviceConfig=stationCfg);
sta3 = wlanNode(Name="STA3",Position=sta3Positions,DeviceConfig=stationCfg);
sta4 = wlanNode(Name="STA4",Position=sta4Positions,DeviceConfig=stationCfg);
sta5 = wlanNode(Name="STA5",Position=sta5Positions,DeviceConfig=stationCfg);
sta6 = wlanNode(Name="STA6",Position=sta6Positions,DeviceConfig=stationCfg);
sta7 = wlanNode(Name="STA7",Position=sta7Positions,DeviceConfig=stationCfg);
sta8 = wlanNode(Name="STA8",Position=sta8Positions,DeviceConfig=stationCfg);
sta9 = wlanNode(Name="STA9",Position=sta9Positions,DeviceConfig=stationCfg);
sta10 = wlanNode(Name="STA10",Position=sta10Positions,DeviceConfig=stationCfg);
sta11 = wlanNode(Name="STA11",Position=sta11Positions,DeviceConfig=stationCfg);
sta12 = wlanNode(Name="STA12",Position=sta12Positions,DeviceConfig=stationCfg);
sta13 = wlanNode(Name="STA13",Position=sta13Positions,DeviceConfig=stationCfg);
sta14 = wlanNode(Name="STA14",Position=sta14Positions,DeviceConfig=stationCfg);
sta15 = wlanNode(Name="STA15",Position=sta15Positions,DeviceConfig=stationCfg);
sta16 = wlanNode(Name="STA16",Position=sta16Positions,DeviceConfig=stationCfg);
associateStations(accessPoint,sta1);
associateStations(accessPoint,sta2);
associateStations(accessPoint,sta3);
associateStations(accessPoint,sta4);
associateStations(accessPoint,sta5);
associateStations(accessPoint,sta6);
associateStations(accessPoint,sta7);
associateStations(accessPoint,sta8);
associateStations(accessPoint,sta9);
associateStations(accessPoint,sta10);
associateStations(accessPoint,sta11);
associateStations(accessPoint,sta12);
associateStations(accessPoint,sta13);
associateStations(accessPoint,sta14);
associateStations(accessPoint,sta15);
associateStations(accessPoint,sta16);
nodes = [accessPoint sta1 sta2 sta3 sta4 sta5 sta6 sta7 sta8 sta9 sta10 sta11 sta12 sta13 sta14 sta15 sta16];
%trafficSourceUL = networkTrafficOnOff(DataRate=100000,PacketSize=1500);
%addTrafficSource(stations,trafficSourceUL,DestinationNode=accessPoint,AccessCategory=0);
%trafficSourceDL = networkTrafficOnOff(DataRate=100000,PacketSize=1500);
%addTrafficSource(accessPoint,trafficSourceDL,DestinationNode=stations,AccessCategory=0);
traffic = networkTrafficOnOff(DataRate=100,PacketSize=10,GeneratePacket=true);
addTrafficSource(accessPoint,traffic,DestinationNode=sta1);
addTrafficSource(accessPoint,traffic,DestinationNode=sta2);
addTrafficSource(accessPoint,traffic,DestinationNode=sta3);
addTrafficSource(accessPoint,traffic,DestinationNode=sta4);
addTrafficSource(accessPoint,traffic,DestinationNode=sta5);
addTrafficSource(accessPoint,traffic,DestinationNode=sta6);
addTrafficSource(accessPoint,traffic,DestinationNode=sta7);
addTrafficSource(accessPoint,traffic,DestinationNode=sta8);
addTrafficSource(accessPoint,traffic,DestinationNode=sta9);
addTrafficSource(accessPoint,traffic,DestinationNode=sta10);
addTrafficSource(accessPoint,traffic,DestinationNode=sta11);
addTrafficSource(accessPoint,traffic,DestinationNode=sta12);
addTrafficSource(accessPoint,traffic,DestinationNode=sta13);
addTrafficSource(accessPoint,traffic,DestinationNode=sta14);
addTrafficSource(accessPoint,traffic,DestinationNode=sta15);
addTrafficSource(accessPoint,traffic,DestinationNode=sta16);
addNodes(networkSimulator,nodes);
run(networkSimulator,simulationTime);
stats = statistics(nodes);
apStats = statistics(accessPoint);
sta1Stats = statistics(sta1);
sta2Stats = statistics(sta2);
sta3Stats = statistics(sta3);
sta4Stats = statistics(sta4);
sta5Stats = statistics(sta5);
sta6Stats = statistics(sta6);
sta7Stats = statistics(sta7);
sta8Stats = statistics(sta8);
sta9Stats = statistics(sta9);
sta10Stats = statistics(sta10);
sta11Stats = statistics(sta11);
sta12Stats = statistics(sta12);
sta13Stats = statistics(sta13);
sta14Stats = statistics(sta14);
sta15Stats = statistics(sta15);
sta16Stats = statistics(sta16);
disp(apStats.PHY)
disp(sta1Stats.PHY)
disp(sta2Stats.PHY)
disp(sta3Stats.PHY)
disp(sta4Stats.PHY)
disp(sta5Stats.PHY)
disp(sta6Stats.PHY)
disp(sta7Stats.PHY)
disp(sta8Stats.PHY)
disp(sta9Stats.PHY)
disp(sta10Stats.PHY)
disp(sta11Stats.PHY)
disp(sta12Stats.PHY)
disp(sta13Stats.PHY)
disp(sta14Stats.PHY)
disp(sta15Stats.PHY)
disp(sta16Stats.PHY)

figure;

% Plot AP positions
plot3(apPositions(:,1),apPositions(:,2),apPositions(:,3),"or",MarkerFaceColor="red"); 
hold on;
grid on;

% Label the APs
text(apPositions(:,1),apPositions(:,2),apPositions(:,3),'AP');

% Plot STA positions
plot3(sta1Positions(:,1),sta1Positions(:,2),sta1Positions(:,3),"^b",MarkerFaceColor="blue");
plot3(sta2Positions(:,1),sta2Positions(:,2),sta2Positions(:,3),"^b",MarkerFaceColor="blue");
plot3(sta3Positions(:,1),sta3Positions(:,2),sta3Positions(:,3),"^b",MarkerFaceColor="blue");
plot3(sta4Positions(:,1),sta4Positions(:,2),sta4Positions(:,3),"^b",MarkerFaceColor="blue");
plot3(sta5Positions(:,1),sta5Positions(:,2),sta5Positions(:,3),"^b",MarkerFaceColor="blue");
plot3(sta6Positions(:,1),sta6Positions(:,2),sta6Positions(:,3),"^b",MarkerFaceColor="blue");
plot3(sta7Positions(:,1),sta7Positions(:,2),sta7Positions(:,3),"^b",MarkerFaceColor="blue");
plot3(sta8Positions(:,1),sta8Positions(:,2),sta8Positions(:,3),"^b",MarkerFaceColor="blue");
plot3(sta9Positions(:,1),sta9Positions(:,2),sta9Positions(:,3),"^b",MarkerFaceColor="blue");
plot3(sta10Positions(:,1),sta10Positions(:,2),sta10Positions(:,3),"^b",MarkerFaceColor="blue");
plot3(sta11Positions(:,1),sta11Positions(:,2),sta11Positions(:,3),"^b",MarkerFaceColor="blue");
plot3(sta12Positions(:,1),sta12Positions(:,2),sta12Positions(:,3),"^b",MarkerFaceColor="blue");
plot3(sta13Positions(:,1),sta13Positions(:,2),sta13Positions(:,3),"^b",MarkerFaceColor="blue");
plot3(sta14Positions(:,1),sta14Positions(:,2),sta14Positions(:,3),"^b",MarkerFaceColor="blue");
plot3(sta15Positions(:,1),sta15Positions(:,2),sta15Positions(:,3),"^b",MarkerFaceColor="blue");
plot3(sta16Positions(:,1),sta16Positions(:,2),sta16Positions(:,3),"^b",MarkerFaceColor="blue");

% Label the STAs
text(sta1Positions(:,1),sta1Positions(:,2),sta1Positions(:,3),'sta1');
text(sta2Positions(:,1),sta2Positions(:,2),sta2Positions(:,3),'sta2');
text(sta3Positions(:,1),sta3Positions(:,2),sta3Positions(:,3),'sta3');
text(sta4Positions(:,1),sta4Positions(:,2),sta4Positions(:,3),'sta4');
text(sta5Positions(:,1),sta5Positions(:,2),sta5Positions(:,3),'sta5');
text(sta6Positions(:,1),sta6Positions(:,2),sta6Positions(:,3),'sta6');
text(sta7Positions(:,1),sta7Positions(:,2),sta7Positions(:,3),'sta7');
text(sta8Positions(:,1),sta8Positions(:,2),sta8Positions(:,3),'sta8');
text(sta9Positions(:,1),sta9Positions(:,2),sta9Positions(:,3),'sta9');
text(sta10Positions(:,1),sta10Positions(:,2),sta10Positions(:,3),'sta10');
text(sta11Positions(:,1),sta11Positions(:,2),sta11Positions(:,3),'sta11');
text(sta12Positions(:,1),sta12Positions(:,2),sta12Positions(:,3),'sta12');
text(sta13Positions(:,1),sta13Positions(:,2),sta13Positions(:,3),'sta13');
text(sta14Positions(:,1),sta14Positions(:,2),sta14Positions(:,3),'sta14');
text(sta15Positions(:,1),sta15Positions(:,2),sta15Positions(:,3),'sta15');
text(sta16Positions(:,1),sta16Positions(:,2),sta16Positions(:,3),'sta16');

axis([0 4 0 4 0 4]);
hold off;

% Label X, Y, and Z axes
xlabel("Position-X (meters)",Rotation=18);
ylabel("Position-Y (meters)",Rotation=-28);
zlabel("Position-Z (meters)");

% Title
title("Node Positions");

% Legend
legend(["AP" "STA"]);