RadarFX API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
4 - RadarFX Developer Examples

Table of Contents

This chapter provides an overview of the simple client example and GUI client included with RadarFX.

4.1 Simple Example

The simple example shows a minimalistic application that connects to a server, issues a request and waits for a response. The entire program is shown below.

/*******************************************************************************
** Copyright (c) 2014 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#include <iostream>
using namespace makRadarFx;
//function to be called by the delegate when a SAR message is returned
void handleSarMessage(DtBaseMessage* msg)
{
//cast to the appropriate type
DtSarResponse* response=dynamic_cast<DtSarResponse*>(msg);
if(response!=NULL)
{
std::cout << "Received a SAR Response" << std::endl;
std::cout << "Image size: " << response->imageSize().x << " x " << response->imageSize().y << std::endl;
}
}
int main(int argc, char* argv[])
{
// Create a RadarFxConnector, and use it to connect to the server on
// the server running on the same machine as the client, with the default port
connector->connect("127.0.0.1", DtRadarFXPort /* 4567 */);
//note that this application does not wait for a connection callback before proceeding
//while not necessary, this application runs the risk of trying to send the message before
//being connected, causing the message to not arrive at the server. Actual applications should
//use the connection callback to be notified when the client succeeds in connecting
//to the server
// create a message delegate to handle responses from the server and register it
//with the connector for the response type message
//delegates can be either free functions, member functions of a class, or static functions of a class
DtMessageDelegate* sarMessageDelegate = new DtMessageDelegate(&handleSarMessage);
connector->messageHandler().addMessageCallback(DtSAR_RESPONSE_TYPE, *sarMessageDelegate);
// create a SAR request message
msg.setRadarSystemName("SAR");
msg.setOwnshipLocation(DtVector(/*Enter sensor lat, lon, alt in degrees/meters */));
msg.setTargetLocation(DtVector(/* Enter target lat, lon, alt in degrees/meters */));
msg.setCrossrange(400);
msg.setDownrange(400);
msg.setPower(100);
msg.setImageSize(DtImageSize(1280, 1024));
// send the message
if(connector->isOk()==true)
connector->sendMessage(msg);
//tick the connector
while (true)
{
connector->tick();
}
connector->messageHandler().removeMessageCallback(DtSAR_RESPONSE_TYPE, *sarMessageDelegate);
delete sarMessageDelegate;
}

This application creates a connector object, and then connects to the server.

Note
This example does not register any callbacks for notification on connection, but a real application should.

The example then creates a message handler and registers it for the message response, then sends a request. In this case it is a SAR message request. The application then calls tick on the connection object waiting for the server's response. When the server replies, the callback function handleSarMessage is called and prints out information about the message.

4.2 GUI Example

The GUI example is a more robust example and is the source code for the client application that ships with RadarFX. This example uses the Qt GUI library to present a user interface to the user for setting up the requests as well as presenting the responses from the server to the user.

/*******************************************************************************
** Copyright (c) 2014 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#include <QtCore/QCoreApplication>
#include "rfxSimpleClient.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
DtRadarFxSimpleClientWindow* mw = new DtRadarFxSimpleClientWindow();
if (!mw->init())
{
return 0;
}
mw->show();
mw->showConnectionDialog();
return app.exec();
delete mw;
}

[<< The Client API] [Home]


Document ID: 1.0
Copyright © 2015 VT MÄK Inc. All Rights Reserved (www.mak.com)