Indoor Propagation

Detailed Description

This is an example of how to use the WinProp API for indoor propagation. The full example is distributed with the installation.
#include <stdio.h>
#include <string>
#include <iostream>

#include "indoor_propagation.h"

#ifndef API_DATA_FOLDER
#define API_DATA_FOLDER "../../api/winprop/data/"
#endif // !API_DATA_FOLDER

int main(int argc, char** argv)
{
	int                 Error = 0, ProjectHandle = 0;
	WinProp_Scenario    WinPropScenario;
	WinProp_Callback    WinPropCallback;
	WinProp_Area        WinPropArea;
	WinProp_Antenna     WinPropAntenna;
	WinProp_Result      *PowerResult = NULL, *DelayResult = NULL, *LosResult = NULL;
	WinProp_RayMatrix   *RayMatrix = NULL;
	WinProp_Pattern     WinPropPattern;
	WinProp_Additional  WinPropMore;
	WinProp_Propagation_Results OutputResults;
	double              PredictionHeight = 1.5;
	

	/* ------------------------ Initialization of structures --------------------- */
    WinProp_Structure_Init_Scenario(&WinPropScenario);
    WinProp_Structure_Init_Callback(&WinPropCallback);
	WinProp_Structure_Init_Area(&WinPropArea);
	WinProp_Structure_Init_Antenna(&WinPropAntenna);
	WinProp_Structure_Init_Pattern(&WinPropPattern);
	WinProp_Structure_Init_Additional(&WinPropMore);
	WinProp_Structure_Init_Propagation_Results(&OutputResults);

	/* ---------- Load indoor vector database and initialise scenario ------------ */
	/* Assign database name. */
    WinPropScenario.Scenario = WINPROP_SCENARIO_INDOOR;
    char VectorDatabase[500];
    sprintf(VectorDatabase, "%s", API_DATA_FOLDER "../data/indoor/IndoorVectordatabase.idb");
    WinPropScenario.VectorDatabase = VectorDatabase;
	/* Define callback functions. */
	WinPropCallback.Percentage = CallbackProgress;
	WinPropCallback.Message = CallbackMessage;
	WinPropCallback.Error = CallbackError;


	/* Call the WinProp API to open a project and load the vector database. */
	Error = WinProp_Open(&ProjectHandle, &WinPropScenario, &WinPropCallback);
	/* ----------------------- Set up prediction --------------------------------- */
	if (Error == 0) {
		/* Definition of prediction area and resolution. */
		WinPropArea.LowerLeftX = -4.5;
		WinPropArea.LowerLeftY = -44.5;
		WinPropArea.UpperRightX = 101.5;
		WinPropArea.UpperRightY = 43.0;
		WinPropArea.Resolution = 1.0; // Resolution 1.0 meter
		WinPropArea.NrHeights = 1; // Number of prediction heights
		WinPropArea.Heights = &PredictionHeight; // Prediction height 1.5 meter

		/* Definition of antenna pattern. */
        WinPropPattern.Mode = PATTERN_MODE_FILE; // Load pattern from file
        char PatternFileName[500];
        sprintf(PatternFileName, "%s", API_DATA_FOLDER "antennas/Antenna.apb");
        WinPropPattern.Filename = PatternFileName; // Pattern file (including extension)

		/* Defintion of antenna properties. */
		WinPropAntenna.Enabled = 1;
		WinPropAntenna.Id = 1;
		WinPropAntenna.SiteId = 1;
		WinPropAntenna.Longitude_X = 60.25;
		WinPropAntenna.Latitude_Y = 6.25;
		WinPropAntenna.Height = 2.0; // Antenna height 2.0 meter
		WinPropAntenna.Model = WINPROP_MODEL_DPM; // Use the DPM
		WinPropAntenna.DataType = PROP_RESULT_POWER; // Compute received power
		WinPropAntenna.Power = 10.0; // Power in dBm
		WinPropAntenna.Frequency = 1800.0; // Frequency 1800 MHz
		WinPropAntenna.Pattern = &WinPropPattern; // Use pattern defined above
		WinPropAntenna.Azimuth = 270.0; // Antenna points in western direction
        WinPropAntenna.Downtilt = 1.0; // Downtilt of 1 degree

        char AntennaName[500];
        sprintf(AntennaName, "%s", "my_antenna_name");
        WinPropAntenna.Name = AntennaName; // name of the antenna

		/* Definition of outputs to be computed and written in WinProp format. */
        WinPropMore.OutputResults = &OutputResults;
        char ResultPath[500];
        sprintf(ResultPath, "%s", API_DATA_FOLDER "output/Indoor_Output");
        OutputResults.ResultPath = ResultPath; // Output data directory 
		OutputResults.FieldStrength = 1;
		OutputResults.PathLoss = 1;

		/* Further parameters: With filtering. */
		WinPropMore.ResultFiltering = 1;

		/* ----------------------- Start prediction ------------------------------ */
		Error = WinProp_Predict(
			ProjectHandle,
			&WinPropAntenna,
			&WinPropArea,
			nullptr,
			0,
			nullptr,
			&WinPropMore,
			&PowerResult,
			&DelayResult,
			&LosResult,
			&RayMatrix,
			nullptr,
			nullptr,
			nullptr);
	}
	WinProp_Close(ProjectHandle);
	
	return 0;
}

int _STD_CALL CallbackMessage(const char * Text)
{
	if (Text == nullptr)
		return 0;

	std::cout << "\n" << Text;

	return(0);
}

int _STD_CALL CallbackError(const char * Text, int Error)
{
	if (Text == nullptr)
		return 0;

	std::cout << "\n";

#ifdef __LINUX
	std::cout << "\033[31m" << "Error (" << Error << "): "; // highlight error in red color
#else
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hConsole, FOREGROUND_RED);
	std::cout << "Error (" << Error << "): ";
#endif // __LINUX
	std::cout << Text;

#ifdef __LINUX
	std::cout << "\033[0m"; // highlight error in red color
#else
	SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
#endif // __LINUX

	return 0;
}

int _STD_CALL CallbackProgress(int value, const char* text)
{
	char Line[200];

	sprintf(Line, "\n%d%% %s", value, text);
	std::cout << Line;

	return(0);
}