Commit 1a1224b4 authored by Bryan Godbolt's avatar Bryan Godbolt

Merge remote branch 'upstream/experimental' into experimental

parents 89ebecea 86eba06b
......@@ -19,6 +19,7 @@ var followEnabled = false;
var lastLat = 0;
var lastLon = 0;
var lastAlt = 0;
var currLat = 47.3769;
var currLon = 8.549444;
var currAlt = 470;
......@@ -44,6 +45,8 @@ var planeOrient;
var planeLoc;
var aircraft = [];
var aircraftLocations = [];
var aircraftLastLocations = [];
var attitudes = [];
var locations = [];
var trails = [];
......@@ -68,6 +71,11 @@ function init()
google.earth.createInstance("map3d", initCallback, failureCallback);
}
function setFollowEnabled(enable)
{
followEnabled = enable;
}
function setCurrAircraft(id)
......@@ -133,7 +141,8 @@ function createAircraft(id, type, color)
// Write into global structure
aircraft[id] = planePlacemark;
attitudes[id] = planeOrient;
locations[id] = planeLoc;
aircraftLocations[id] = planeLoc;
aircraftLastLocations[id] = ge.createLocation('');
//planeColor = color;
createTrail(id, color);
......@@ -168,7 +177,7 @@ trailsVisible[id] = false;
}
function hideTrail(id)
function clearTrail(id)
{
trailsVisible[id] = false;
ge.getFeatures().removeChild(trailPlacemarks[id]);
......@@ -188,65 +197,73 @@ function setViewRange(dist)
function addTrailPosition(id, lat, lon, alt)
{
trails[id].setExtrude(false);
trails[id].setAltitudeMode(ge.ALTITUDE_ABSOLUTE);
trails[id].setAltitudeMode(ge.ALTITUDE_ABSOLUTE);
// Add LineString points
trails[id].getCoordinates().pushLatLngAlt(lat, lon, alt);
// Add LineString points
trails[id].getCoordinates().pushLatLngAlt(lat, lon, alt);
// Create a style and set width and color of line
trailPlacemarks[id].setStyleSelector(ge.createStyle(''));
lineStyle = trailPlacemarks[id].getStyleSelector().getLineStyle();
lineStyle.setWidth(5);
lineStyle.getColor().set(trailColors[id]);  // aabbggrr format
//lineStyle.getColor().set(color);  // aabbggrr format
// Create a style and set width and color of line
trailPlacemarks[id].setStyleSelector(ge.createStyle(''));
lineStyle = trailPlacemarks[id].getStyleSelector().getLineStyle();
lineStyle.setWidth(5);
lineStyle.getColor().set(trailColors[id]);  // aabbggrr format
//lineStyle.getColor().set(color);  // aabbggrr format
// Add the feature to Earth
if (trailsVisible[id] == true) ge.getFeatures().replaceChild(trailPlacemarks[id], trailPlacemarks[id]);
// Add the feature to Earth
if (trailsVisible[id] == true) ge.getFeatures().replaceChild(trailPlacemarks[id], trailPlacemarks[id]);
}
function initCallback(object)
{
ge = object;
ge.getWindow().setVisibility(true);
ge.getOptions().setStatusBarVisibility(true);
ge.getOptions().setScaleLegendVisibility(true);
ge.getOptions().setFlyToSpeed(5.0);
//ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);
ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
ge = object;
ge.getWindow().setVisibility(true);
ge.getOptions().setStatusBarVisibility(true);
ge.getOptions().setScaleLegendVisibility(true);
//ge.getOptions().setFlyToSpeed(5.0);
ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);
ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN, true);
ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true);
ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
ge.getLayerRoot().enableLayerById(ge.LAYER_TREES, true);
ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN, true);
ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true);
ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
ge.getLayerRoot().enableLayerById(ge.LAYER_TREES, true);
initialized = true;
initialized = true;
}
function setAircraftPositionAttitude(id, lat, lon, alt, roll, pitch, yaw)
{
if (id == currAircraft)
{
lastLat = currLat;
lastLon = lastLon;
if (lastLat == 0)
{
lastLat = currLat;
lastLon = currLon;
}
currLat = lat;
currLon = lon;
currAlt = alt;
// Interpolate between t-1 and t and set new states
lastLat = lastLat*0.8+currLat*0.2;
lastLon = lastLon*0.8+currLon*0.2;
lastAlt = lastAlt*0.8+currAlt*0.2;
//currFollowHeading = ((yaw/M_PI)+1.0)*360.0;
}
// FIXME Currently invalid conversion from right-handed z-down to z-up frame
planeOrient.setRoll(((roll/M_PI)+1.0)*360.0);
planeOrient.setTilt(((pitch/M_PI)+1.0)*360.0);
planeOrient.setHeading(((yaw/M_PI)+1.0)*360.0);
planeLoc.setLatitude(lat);
planeLoc.setLongitude(lon);
planeLoc.setAltitude(alt);
planeOrient.setRoll(((roll/M_PI))*180.0+180.0);
planeOrient.setTilt(((pitch/M_PI))*180.0+180.0);
planeOrient.setHeading(((yaw/M_PI))*180.0-90.0);
currFollowHeading = ((yaw/M_PI))*180.0;
planeLoc.setLatitude(lastLat);
planeLoc.setLongitude(lastLon);
planeLoc.setAltitude(lastAlt);
planeModel.setLocation(planeLoc);
if (followEnabled) updateFollowAircraft();
}
}
function enableDaylight(enabled)
......@@ -280,13 +297,14 @@ function setCurrentAircraft(id)
function updateFollowAircraft()
{
currView = ge.getView().copyAsLookAt(ge.ALTITUDE_ABSOLUTE);
currView.setLatitude(currLat);
currView.setLongitude(currLon);
currView.setAltitude(currAlt);
currView.setLatitude(lastLat);
currView.setLongitude(lastLon);
currView.setAltitude(lastAlt);
currView.setRange(currViewRange);
currView.setTilt(currFollowTilt);
currFollowHeading = 0.9*currFollowHeading+0.1*((Math.atan2(lastLat-currLat, lastLon-currLon)/M_PI)+1.0)*360.0;
currView.setHeading(currFollowHeading-0.0);
currView.setHeading(currFollowHeading);
ge.getView().setAbstractView(currView);
}
......
......@@ -251,6 +251,21 @@ QSlider::groove:horizontal {
margin: -5px 0; /* handle is placed by default on the contents rect of the groove. Expand outside the groove */
border-radius: 3px;
}
QSlider::groove:vertical {
border: 1px solid #999999;
width: 4px; /* the groove expands to the size of the slider by default. by giving it a height, it has a fixed size */
background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 #4A4A4F, stop:1 #4A4A4F);
margin: 2px 0;
}
QSlider::handle:vertical {
background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #232228, stop: 1 #020208);
border: 2px solid #379AC3;
height: 18px;
margin: 0 -5px; /* handle is placed by default on the contents rect of the groove. Expand outside the groove */
border-radius: 3px;
}
QPushButton#forceLandButton {
font-weight: bold;
......
......@@ -119,7 +119,7 @@ namespace qmapcontrol
virtual bool hasClickedPoints() const;
virtual void setPen(QPen* pen);
virtual QList<Geometry*> clickedPoints();
virtual QList<Point*> points()=0;
virtual QList<Point*>& points()=0;
private:
Geometry* myparentGeometry;
......
......@@ -153,7 +153,7 @@ namespace qmapcontrol
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
tileData.save(&buffer, "PNG");
// FIXME This is weird - why first write in buffer and then in file?
file.write(bytes);
file.close();
return true;
......
......@@ -39,10 +39,10 @@ namespace qmapcontrol
delete mapAdapter;
}
void Layer::setSize(QSize size)
void Layer::setSize(QSize size, QPoint screenmiddle)
{
this->size = size;
screenmiddle = QPoint(size.width()/2, size.height()/2);
this->screenmiddle = screenmiddle;// QPoint(size.width()/2, size.height()/2);
//QMatrix mat;
//mat.translate(480/2, 640/2);
//mat.rotate(45);
......@@ -292,10 +292,12 @@ namespace qmapcontrol
// PREFETCHING
int upper = mapmiddle_tile_y-tiles_above-1;
int right = mapmiddle_tile_x+tiles_right+1;
int left = mapmiddle_tile_x-tiles_right-1;
int lower = mapmiddle_tile_y+tiles_bottom+1;
// FIXME Make prefetching a parameter
int upper = mapmiddle_tile_y-tiles_above-2;
int right = mapmiddle_tile_x+tiles_right+2;
int left = mapmiddle_tile_x-tiles_right-2;
int lower = mapmiddle_tile_y+tiles_bottom+2;
int j = upper;
for (int i=left; i<=right; i++)
......
......@@ -139,7 +139,7 @@ namespace qmapcontrol
void moveWidgets(const QPoint mapmiddle_px) const;
void drawYourImage(QPainter* painter, const QPoint mapmiddle_px) const;
void drawYourGeometries(QPainter* painter, const QPoint mapmiddle_px, QRect viewport) const;
void setSize(QSize size);
void setSize(QSize size, QPoint screenmiddle);
QRect offscreenViewport() const;
bool takesMouseEvents() const;
void mouseEvent(const QMouseEvent*, const QPoint mapmiddle_px);
......
......@@ -29,12 +29,9 @@ namespace qmapcontrol
LayerManager::LayerManager(MapControl* mapcontrol, QSize size)
:mapcontrol(mapcontrol), scroll(QPoint(0,0)), size(size), whilenewscroll(QPoint(0,0))
{
// genauer berechnen?
offSize = size *2;
composedOffscreenImage = QPixmap(offSize);
composedOffscreenImage2 = QPixmap(offSize);
setOffscreenImageFactor(2);
zoomImage = QPixmap(size);
zoomImage.fill(Qt::white);
zoomImage.fill(Qt::black);
screenmiddle = QPoint(size.width()/2, size.height()/2);
}
......@@ -44,6 +41,20 @@ namespace qmapcontrol
mylayers.clear();
}
void LayerManager::setOffscreenImageFactor(float factor)
{
offSize = size * factor;
offFactor = factor;
composedOffscreenImage = QPixmap(offSize);
composedOffscreenImage2 = QPixmap(offSize);
resize(size);
}
float LayerManager::offscreenImageFactor()
{
return offFactor;
}
QPointF LayerManager::currentCoordinate() const
{
return mapmiddle;
......@@ -209,7 +220,7 @@ namespace qmapcontrol
{
mylayers.append(layer);
layer->setSize(size);
layer->setSize(size, screenmiddle);
connect(layer, SIGNAL(updateRequest(QRectF)),
this, SLOT(updateRequest(QRectF)));
......@@ -229,7 +240,7 @@ namespace qmapcontrol
if (clearImage)
{
composedOffscreenImage2.fill(Qt::white);
composedOffscreenImage2.fill(Qt::black);
}
QPainter painter(&composedOffscreenImage2);
......@@ -264,7 +275,7 @@ namespace qmapcontrol
// layer rendern abbrechen?
zoomImageScroll = QPoint(0,0);
zoomImage.fill(Qt::white);
zoomImage.fill(Qt::black);
QPixmap tmpImg = composedOffscreenImage.copy(screenmiddle.x()+scroll.x(),screenmiddle.y()+scroll.y(), size.width(), size.height());
QPainter painter(&zoomImage);
......@@ -428,6 +439,20 @@ namespace qmapcontrol
forceRedraw();
}
void LayerManager::drawGeoms()
{
QPainter painter(&composedOffscreenImage);
QListIterator<Layer*> it(mylayers);
while (it.hasNext())
{
Layer* l = it.next();
if (l->layertype() == Layer::GeometryLayer && l->isVisible())
{
l->drawYourGeometries(&painter, mapmiddle_px, layer()->offscreenViewport());
}
}
}
void LayerManager::drawGeoms(QPainter* painter)
{
QListIterator<Layer*> it(mylayers);
......@@ -440,6 +465,8 @@ namespace qmapcontrol
}
}
}
void LayerManager::drawImage(QPainter* painter)
{
painter->drawPixmap(-scroll.x()-screenmiddle.x(),
......@@ -455,11 +482,11 @@ namespace qmapcontrol
void LayerManager::resize(QSize newSize)
{
size = newSize;
offSize = newSize *2;
offSize = newSize *offFactor;
composedOffscreenImage = QPixmap(offSize);
composedOffscreenImage2 = QPixmap(offSize);
zoomImage = QPixmap(newSize);
zoomImage.fill(Qt::white);
zoomImage.fill(Qt::black);
screenmiddle = QPoint(newSize.width()/2, newSize.height()/2);
......@@ -467,7 +494,7 @@ namespace qmapcontrol
while (it.hasNext())
{
Layer* l = it.next();
l->setSize(newSize);
l->setSize(newSize, screenmiddle);
}
newOffscreenImage();
......
......@@ -121,6 +121,11 @@ namespace qmapcontrol
*/
void setZoom(int zoomlevel);
//! Sets the factor the offscreen image should be larger than the visible area
void setOffscreenImageFactor(float factor);
//! Get the factor the offscreen image is larger than the screen
float offscreenImageFactor();
//! The Viewport of the display
/*!
* Returns the visible viewport in world coordinates
......@@ -166,13 +171,15 @@ namespace qmapcontrol
*/
int currentZoom() const;
void drawGeoms();
void drawGeoms(QPainter* painter);
void drawImage(QPainter* painter);
private:
LayerManager& operator=(const LayerManager& rhs);
LayerManager(const LayerManager& old);
//! This method have to be invoked to draw a new offscreen image
//! This method has to be invoked to draw a new offscreen image
/*!
* @param clearImage if the current offscreeen image should be cleared
* @param showZoomImage if a zoom image should be painted
......@@ -188,8 +195,9 @@ namespace qmapcontrol
QPoint scroll; // scrollvalue of the offscreen image
QPoint zoomImageScroll; // scrollvalue of the zoom image
QSize size; // widget size
QSize offSize; // size of the offscreen image
QSize size; ///< widget size
QSize offSize; ///< size of the offscreen image
float offFactor; ///< Size of the offscreen image
QPixmap composedOffscreenImage;
QPixmap composedOffscreenImage2;
......
......@@ -56,7 +56,12 @@ namespace qmapcontrol
vertices.append(point);
}
QList<Point*> LineString::points()
void LineString::clearPoints()
{
vertices.clear();
}
QList<Point*>& LineString::points()
{
return vertices;
}
......
......@@ -56,7 +56,7 @@ namespace qmapcontrol
/*!
* @return a list with the points of the LineString
*/
QList<Point*> points();
QList<Point*>& points();
//! adds a point at the end of the LineString
/*!
......@@ -64,6 +64,9 @@ namespace qmapcontrol
*/
void addPoint ( Point* point );
//! Remove all points from the LineString
void clearPoints();
//! sets the given list as points of the LineString
/*!
* @param points the points which should be set for the LineString
......
......@@ -23,6 +23,9 @@
*
*/
#include <QDialog>
#include <QDesktopServices>
#include "mapcontrol.h"
namespace qmapcontrol
{
......@@ -61,6 +64,29 @@ namespace qmapcontrol
return layermanager->layer(layername);
}
void MapControl::setOffscreenImageFactor(double factor)
{
layermanager->setOffscreenImageFactor(factor);
}
float MapControl::offscreenImageFactor()
{
return layermanager->offscreenImageFactor();
}
void MapControl::openImageSaveDialog()
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Image as"), QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), tr("Image file (*.jpg *.png);;"));
if (fileName != "")
{
if (!fileName.contains(".png") && !fileName.contains(".jpg"))
{
fileName.append(".png");
}
layermanager->getImage().save(fileName, fileName.split(".").last().toUpper().toAscii(), 95);
}
}
QList<QString> MapControl::layers() const
{
return layermanager->layers();
......@@ -324,6 +350,12 @@ namespace qmapcontrol
{
update(rect);
}
void MapControl::drawGeometries()
{
layermanager->drawGeoms();
}
void MapControl::updateRequestNew()
{
// qDebug() << "MapControl::updateRequestNew()";
......@@ -345,7 +377,7 @@ namespace qmapcontrol
{
layermanager->setZoom(zoomlevel);
qDebug() << "MAPCONTROL: Set zoomlevel to:" << zoomlevel << "at " << __FILE__ << __LINE__;
//qDebug() << "MAPCONTROL: Set zoomlevel to:" << zoomlevel << "at " << __FILE__ << __LINE__;
update();
}
......
......@@ -92,6 +92,9 @@ namespace qmapcontrol
*/
Layer* layer ( const QString& layername ) const;
//! The factor the offscreen image is larger than the current viewport
float offscreenImageFactor();
//! returns the names of all layers
/*!
* @return returns a QList with the names of all layers
......@@ -342,6 +345,8 @@ namespace qmapcontrol
*/
void updateRequest ( QRect rect );
void drawGeometries();
//! updates the hole map by creating a new offscreen image
/*!
*
......@@ -354,6 +359,12 @@ namespace qmapcontrol
*/
void resize(const QSize newSize);
//! Open a popup to save the current offscreen image to disk
void openImageSaveDialog();
//! Sets the factor the offscreen image should be larger than the visible area */
void setOffscreenImageFactor(double factor);
private slots:
void tick();
void loadingFinished();
......
......@@ -93,13 +93,19 @@ namespace qmapcontrol
// qDebug() << "Network loaded: " << (loaded);
parent->receivedImage(pm, url);
}
else if (pm.width() == 0 || pm.height() == 0)
{
// Silently ignore map request for a
// 0xn pixel map
}
else
{
// QGC FIXME Error is currently undetected
// TODO Error is currently undetected
//qDebug() << "NETWORK_PIXMAP_ERROR: " << ax;
qDebug() << "QMapControl external library: ERROR loading map:" << "width:" << pm.width() << "heigh:" << pm.height() << "at " << __FILE__ << __LINE__;
qDebug() << "HTML ERROR MESSAGE:" << ax << "at " << __FILE__ << __LINE__;
//qDebug() << "HTML ERROR MESSAGE:" << ax << "at " << __FILE__ << __LINE__;
}
}
......
......@@ -293,12 +293,11 @@ namespace qmapcontrol
emit(positionChanged(this));
}
QList<Point*> Point::points()
QList<Point*>& Point::points()
{
//TODO: assigning temp?!
QList<Point*> points;
points.append(this);
return points;
// FIXME TODO: THIS IS ABSOLUTELY WRONG IN THE ORIGINAL LIBRARY
// NEEDS AN INHERITANCE REWRITE!!!!
return m_points;
}
QWidget* Point::widget()
......
......@@ -139,7 +139,7 @@ namespace qmapcontrol
*/
QPointF coordinate() const;
virtual QList<Point*> points();
virtual QList<Point*>& points();
/*! \brief returns the widget of the point
@return the widget of the point
......@@ -191,6 +191,7 @@ namespace qmapcontrol
QSize displaysize;
QSize minsize;
QSize maxsize;
QList<Point*> m_points;
void drawWidget(const MapAdapter* mapadapter, const QPoint offset);
......
INCLUDE_DIRECTORIES(include)
SET_SOURCE_FILES(NMEALIB_SRC_FILES
context.c
time.c
generate.c
generator.c
gmath.c
info.c
parse.c
parser.c
sentence.c
tok.c
)
PIXHAWK_LIBRARY(nmea SHARED ${NMEALIB_SRC_FILES})
This diff is collapsed.
NMEA library
Disclaimer
The National Marine Electronics Association (NMEA) has developed a specification that defines the interface between various pieces of marine electronic equipment. The standard permits marine electronics to send information to computers and to other marine equipment.
Most computer programs that provide real time position information understand and expect data to be in NMEA format. This data includes the complete PVT (position, velocity, time) solution computed by the GPS receiver. The idea of NMEA is to send a line of data called a sentence that is totally self contained and independent from other sentences. All NMEA sentences is sequences of ACSII symbols begins with a '$' and ends with a carriage return/line feed sequence and can be no longer than 80 characters of visible text (plus the line terminators).
Introduction
We present library in 'C' programming language for work with NMEA protocol. Small and easy to use. The library build on different compilers under different platforms (see below). The code was tested in real projects. Just download and try...
Features
- Analysis NMEA sentences and granting GPS data in C structures
- Generate NMEA sentences
- Supported sentences: GPGGA, GPGSA, GPGSV, GPRMC, GPVTG
- Multilevel architecture of algorithms
- Additional functions of geographical mathematics and work with navigation data
Supported (tested) platforms
- Microsoft Windows (MS Visual Studio 8.0, GCC)
- Windows Mobile, Windows CE (MS Visual Studio 8.0)
- UNIX (GCC)
Licence: LGPL
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: context.c 17 2008-03-11 11:56:11Z xtimor $
*
*/
#include "nmea/context.h"
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
nmeaPROPERTY * nmea_property()
{
static nmeaPROPERTY prop = {
0, 0, NMEA_DEF_PARSEBUFF
};
return &prop;
}
void nmea_trace(const char *str, ...)
{
int size;
va_list arg_list;
char buff[NMEA_DEF_PARSEBUFF];
nmeaTraceFunc func = nmea_property()->trace_func;
if(func)
{
va_start(arg_list, str);
size = NMEA_POSIX(vsnprintf)(&buff[0], NMEA_DEF_PARSEBUFF - 1, str, arg_list);
va_end(arg_list);
if(size > 0)
(*func)(&buff[0], size);
}
}
void nmea_trace_buff(const char *buff, int buff_size)
{
nmeaTraceFunc func = nmea_property()->trace_func;
if(func && buff_size)
(*func)(buff, buff_size);
}
void nmea_error(const char *str, ...)
{
int size;
va_list arg_list;
char buff[NMEA_DEF_PARSEBUFF];
nmeaErrorFunc func = nmea_property()->error_func;
if(func)
{
va_start(arg_list, str);
size = NMEA_POSIX(vsnprintf)(&buff[0], NMEA_DEF_PARSEBUFF - 1, str, arg_list);
va_end(arg_list);
if(size > 0)
(*func)(&buff[0], size);
}
}
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: generate.c 17 2008-03-11 11:56:11Z xtimor $
*
*/
#include "nmea/tok.h"
#include "nmea/sentence.h"
#include "nmea/generate.h"
#include "nmea/units.h"
#include <string.h>
#include <stdlib.h>
#include <math.h>
int nmea_gen_GPGGA(char *buff, int buff_sz, nmeaGPGGA *pack)
{
return nmea_printf(buff, buff_sz,
"$GPGGA,%02d%02d%02d.%02d,%07.4f,%C,%07.4f,%C,%1d,%02d,%03.1f,%03.1f,%C,%03.1f,%C,%03.1f,%04d",
pack->utc.hour, pack->utc.min, pack->utc.sec, pack->utc.hsec,
pack->lat, pack->ns, pack->lon, pack->ew,
pack->sig, pack->satinuse, pack->HDOP, pack->elv, pack->elv_units,
pack->diff, pack->diff_units, pack->dgps_age, pack->dgps_sid);
}
int nmea_gen_GPGSA(char *buff, int buff_sz, nmeaGPGSA *pack)
{
return nmea_printf(buff, buff_sz,
"$GPGSA,%C,%1d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%03.1f,%03.1f,%03.1f",
pack->fix_mode, pack->fix_type,
pack->sat_prn[0], pack->sat_prn[1], pack->sat_prn[2], pack->sat_prn[3], pack->sat_prn[4], pack->sat_prn[5],
pack->sat_prn[6], pack->sat_prn[7], pack->sat_prn[8], pack->sat_prn[9], pack->sat_prn[10], pack->sat_prn[11],
pack->PDOP, pack->HDOP, pack->VDOP);
}
int nmea_gen_GPGSV(char *buff, int buff_sz, nmeaGPGSV *pack)
{
return nmea_printf(buff, buff_sz,
"$GPGSV,%1d,%1d,%02d,"
"%02d,%02d,%03d,%02d,"
"%02d,%02d,%03d,%02d,"
"%02d,%02d,%03d,%02d,"
"%02d,%02d,%03d,%02d",
pack->pack_count, pack->pack_index + 1, pack->sat_count,
pack->sat_data[0].id, pack->sat_data[0].elv, pack->sat_data[0].azimuth, pack->sat_data[0].sig,
pack->sat_data[1].id, pack->sat_data[1].elv, pack->sat_data[1].azimuth, pack->sat_data[1].sig,
pack->sat_data[2].id, pack->sat_data[2].elv, pack->sat_data[2].azimuth, pack->sat_data[2].sig,
pack->sat_data[3].id, pack->sat_data[3].elv, pack->sat_data[3].azimuth, pack->sat_data[3].sig);
}
int nmea_gen_GPRMC(char *buff, int buff_sz, nmeaGPRMC *pack)
{
return nmea_printf(buff, buff_sz,
"$GPRMC,%02d%02d%02d.%02d,%C,%07.4f,%C,%07.4f,%C,%03.1f,%03.1f,%02d%02d%02d,%03.1f,%C,%C",
pack->utc.hour, pack->utc.min, pack->utc.sec, pack->utc.hsec,
pack->status, pack->lat, pack->ns, pack->lon, pack->ew,
pack->speed, pack->direction,
pack->utc.day, pack->utc.mon + 1, pack->utc.year - 100,
pack->declination, pack->declin_ew, pack->mode);
}
int nmea_gen_GPVTG(char *buff, int buff_sz, nmeaGPVTG *pack)
{
return nmea_printf(buff, buff_sz,
"$GPVTG,%.1f,%C,%.1f,%C,%.1f,%C,%.1f,%C",
pack->dir, pack->dir_t,
pack->dec, pack->dec_m,
pack->spn, pack->spn_n,
pack->spk, pack->spk_k);
}
void nmea_info2GPGGA(const nmeaINFO *info, nmeaGPGGA *pack)
{
nmea_zero_GPGGA(pack);
pack->utc = info->utc;
pack->lat = fabs(info->lat);
pack->ns = ((info->lat > 0)?'N':'S');
pack->lon = fabs(info->lon);
pack->ew = ((info->lon > 0)?'E':'W');
pack->sig = info->sig;
pack->satinuse = info->satinfo.inuse;
pack->HDOP = info->HDOP;
pack->elv = info->elv;
}
void nmea_info2GPGSA(const nmeaINFO *info, nmeaGPGSA *pack)
{
int it;
nmea_zero_GPGSA(pack);
pack->fix_type = info->fix;
pack->PDOP = info->PDOP;
pack->HDOP = info->HDOP;
pack->VDOP = info->VDOP;
for(it = 0; it < NMEA_MAXSAT; ++it)
{
pack->sat_prn[it] =
((info->satinfo.sat[it].in_use)?info->satinfo.sat[it].id:0);
}
}
int nmea_gsv_npack(int sat_count)
{
int pack_count = (int)ceil(((double)sat_count) / NMEA_SATINPACK);
if(0 == pack_count)
pack_count = 1;
return pack_count;
}
void nmea_info2GPGSV(const nmeaINFO *info, nmeaGPGSV *pack, int pack_idx)
{
int sit, pit;
nmea_zero_GPGSV(pack);
pack->sat_count = (info->satinfo.inview <= NMEA_MAXSAT)?info->satinfo.inview:NMEA_MAXSAT;
pack->pack_count = nmea_gsv_npack(pack->sat_count);
if(pack->pack_count == 0)
pack->pack_count = 1;
if(pack_idx >= pack->pack_count)
pack->pack_index = pack_idx % pack->pack_count;
else
pack->pack_index = pack_idx;
for(pit = 0, sit = pack->pack_index * NMEA_SATINPACK; pit < NMEA_SATINPACK; ++pit, ++sit)
pack->sat_data[pit] = info->satinfo.sat[sit];
}
void nmea_info2GPRMC(const nmeaINFO *info, nmeaGPRMC *pack)
{
nmea_zero_GPRMC(pack);
pack->utc = info->utc;
pack->status = ((info->sig > 0)?'A':'V');
pack->lat = fabs(info->lat);
pack->ns = ((info->lat > 0)?'N':'S');
pack->lon = fabs(info->lon);
pack->ew = ((info->lon > 0)?'E':'W');
pack->speed = info->speed / NMEA_TUD_KNOTS;
pack->direction = info->direction;
pack->declination = info->declination;
pack->declin_ew = 'E';
pack->mode = ((info->sig > 0)?'A':'N');
}
void nmea_info2GPVTG(const nmeaINFO *info, nmeaGPVTG *pack)
{
nmea_zero_GPVTG(pack);
pack->dir = info->direction;
pack->dec = info->declination;
pack->spn = info->speed / NMEA_TUD_KNOTS;
pack->spk = info->speed;
}
int nmea_generate(
char *buff, int buff_sz,
const nmeaINFO *info,
int generate_mask
)
{
int gen_count = 0, gsv_it, gsv_count;
int pack_mask = generate_mask;
nmeaGPGGA gga;
nmeaGPGSA gsa;
nmeaGPGSV gsv;
nmeaGPRMC rmc;
nmeaGPVTG vtg;
if(!buff)
return 0;
while(pack_mask)
{
if(pack_mask & GPGGA)
{
nmea_info2GPGGA(info, &gga);
gen_count += nmea_gen_GPGGA(buff + gen_count, buff_sz - gen_count, &gga);
pack_mask &= ~GPGGA;
}
else if(pack_mask & GPGSA)
{
nmea_info2GPGSA(info, &gsa);
gen_count += nmea_gen_GPGSA(buff + gen_count, buff_sz - gen_count, &gsa);
pack_mask &= ~GPGSA;
}
else if(pack_mask & GPGSV)
{
gsv_count = nmea_gsv_npack(info->satinfo.inview);
for(gsv_it = 0; gsv_it < gsv_count && buff_sz - gen_count > 0; ++gsv_it)
{
nmea_info2GPGSV(info, &gsv, gsv_it);
gen_count += nmea_gen_GPGSV(buff + gen_count, buff_sz - gen_count, &gsv);
}
pack_mask &= ~GPGSV;
}
else if(pack_mask & GPRMC)
{
nmea_info2GPRMC(info, &rmc);
gen_count += nmea_gen_GPRMC(buff + gen_count, buff_sz - gen_count, &rmc);
pack_mask &= ~GPRMC;
}
else if(pack_mask & GPVTG)
{
nmea_info2GPVTG(info, &vtg);
gen_count += nmea_gen_GPVTG(buff + gen_count, buff_sz - gen_count, &vtg);
pack_mask &= ~GPVTG;
}
else
break;
if(buff_sz - gen_count <= 0)
break;
}
return gen_count;
}
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: generator.c 17 2008-03-11 11:56:11Z xtimor $
*
*/
#include "nmea/gmath.h"
#include "nmea/generate.h"
#include "nmea/generator.h"
#include "nmea/context.h"
#include <string.h>
#include <stdlib.h>
#if defined(NMEA_WIN) && defined(_MSC_VER)
# pragma warning(disable: 4100) /* unreferenced formal parameter */
#endif
double nmea_random(double min, double max)
{
static double rand_max = RAND_MAX;
double rand_val = rand();
double bounds = max - min;
return min + (rand_val * bounds) / rand_max;
}
/*
* low level
*/
int nmea_gen_init(nmeaGENERATOR *gen, nmeaINFO *info)
{
int RetVal = 1; int smask = info->smask;
nmeaGENERATOR *igen = gen;
nmea_zero_INFO(info);
info->smask = smask;
info->lat = NMEA_DEF_LAT;
info->lon = NMEA_DEF_LON;
while(RetVal && igen)
{
if(igen->init_call)
RetVal = (*igen->init_call)(igen, info);
igen = igen->next;
}
return RetVal;
}
int nmea_gen_loop(nmeaGENERATOR *gen, nmeaINFO *info)
{
int RetVal = 1;
if(gen->loop_call)
RetVal = (*gen->loop_call)(gen, info);
if(RetVal && gen->next)
RetVal = nmea_gen_loop(gen->next, info);
return RetVal;
}
int nmea_gen_reset(nmeaGENERATOR *gen, nmeaINFO *info)
{
int RetVal = 1;
if(gen->reset_call)
RetVal = (*gen->reset_call)(gen, info);
return RetVal;
}
void nmea_gen_destroy(nmeaGENERATOR *gen)
{
if(gen->next)
{
nmea_gen_destroy(gen->next);
gen->next = 0;
}
if(gen->destroy_call)
(*gen->destroy_call)(gen);
free(gen);
}
void nmea_gen_add(nmeaGENERATOR *to, nmeaGENERATOR *gen)
{
if(to->next)
nmea_gen_add(to->next, gen);
else
to->next = gen;
}
int nmea_generate_from(
char *buff, int buff_sz,
nmeaINFO *info,
nmeaGENERATOR *gen,
int generate_mask
)
{
int retval;
if(0 != (retval = nmea_gen_loop(gen, info)))
retval = nmea_generate(buff, buff_sz, info, generate_mask);
return retval;
}
/*
* NOISE generator
*/
int nmea_igen_noise_init(nmeaGENERATOR *gen, nmeaINFO *info)
{
Q_UNUSED(gen);
return 1;
}
int nmea_igen_noise_loop(nmeaGENERATOR *gen, nmeaINFO *info)
{
int it;
int in_use;
info->sig = (int)nmea_random(1, 3);
info->PDOP = nmea_random(0, 9);
info->HDOP = nmea_random(0, 9);
info->VDOP = nmea_random(0, 9);
info->fix = (int)nmea_random(2, 3);
info->lat = nmea_random(0, 100);
info->lon = nmea_random(0, 100);
info->speed = nmea_random(0, 100);
info->direction = nmea_random(0, 360);
info->declination = nmea_random(0, 360);
info->elv = (int)nmea_random(-100, 100);
info->satinfo.inuse = 0;
info->satinfo.inview = 0;
for(it = 0; it < 12; ++it)
{
info->satinfo.sat[it].id = it;
info->satinfo.sat[it].in_use = in_use = (int)nmea_random(0, 3);
info->satinfo.sat[it].elv = (int)nmea_random(0, 90);
info->satinfo.sat[it].azimuth = (int)nmea_random(0, 359);
info->satinfo.sat[it].sig = (int)(in_use?nmea_random(40, 99):nmea_random(0, 40));
if(in_use)
info->satinfo.inuse++;
if(info->satinfo.sat[it].sig > 0)
info->satinfo.inview++;
}
return 1;
}
int nmea_igen_noise_reset(nmeaGENERATOR *gen, nmeaINFO *info)
{
Q_UNUSED(gen);
return 1;
}
/*
* STATIC generator
*/
int nmea_igen_static_loop(nmeaGENERATOR *gen, nmeaINFO *info)
{
Q_UNUSED(gen);
nmea_time_now(&info->utc);
return 1;
};
int nmea_igen_static_reset(nmeaGENERATOR *gen, nmeaINFO *info)
{
Q_UNUSED(gen);
info->satinfo.inuse = 4;
info->satinfo.inview = 4;
info->satinfo.sat[0].id = 1;
info->satinfo.sat[0].in_use = 1;
info->satinfo.sat[0].elv = 50;
info->satinfo.sat[0].azimuth = 0;
info->satinfo.sat[0].sig = 99;
info->satinfo.sat[1].id = 2;
info->satinfo.sat[1].in_use = 1;
info->satinfo.sat[1].elv = 50;
info->satinfo.sat[1].azimuth = 90;
info->satinfo.sat[1].sig = 99;
info->satinfo.sat[2].id = 3;
info->satinfo.sat[2].in_use = 1;
info->satinfo.sat[2].elv = 50;
info->satinfo.sat[2].azimuth = 180;
info->satinfo.sat[2].sig = 99;
info->satinfo.sat[3].id = 4;
info->satinfo.sat[3].in_use = 1;
info->satinfo.sat[3].elv = 50;
info->satinfo.sat[3].azimuth = 270;
info->satinfo.sat[3].sig = 99;
return 1;
}
int nmea_igen_static_init(nmeaGENERATOR *gen, nmeaINFO *info)
{
info->sig = 3;
info->fix = 3;
nmea_igen_static_reset(gen, info);
return 1;
}
/*
* SAT_ROTATE generator
*/
int nmea_igen_rotate_loop(nmeaGENERATOR *gen, nmeaINFO *info)
{
int it;
int count = info->satinfo.inview;
double deg = 360 / (count?count:1);
double srt = (count?(info->satinfo.sat[0].azimuth):0) + 5;
nmea_time_now(&info->utc);
for(it = 0; it < count; ++it)
{
info->satinfo.sat[it].azimuth =
(int)((srt >= 360)?srt - 360:srt);
srt += deg;
}
return 1;
};
int nmea_igen_rotate_reset(nmeaGENERATOR *gen, nmeaINFO *info)
{
int it;
double deg = 360 / 8;
double srt = 0;
info->satinfo.inuse = 8;
info->satinfo.inview = 8;
for(it = 0; it < info->satinfo.inview; ++it)
{
info->satinfo.sat[it].id = it + 1;
info->satinfo.sat[it].in_use = 1;
info->satinfo.sat[it].elv = 5;
info->satinfo.sat[it].azimuth = (int)srt;
info->satinfo.sat[it].sig = 80;
srt += deg;
}
return 1;
}
int nmea_igen_rotate_init(nmeaGENERATOR *gen, nmeaINFO *info)
{
info->sig = 3;
info->fix = 3;
nmea_igen_rotate_reset(gen, info);
return 1;
}
/*
* POS_RANDMOVE generator
*/
int nmea_igen_pos_rmove_init(nmeaGENERATOR *gen, nmeaINFO *info)
{
info->sig = 3;
info->fix = 3;
info->direction = info->declination = 0;
info->speed = 20;
return 1;
}
int nmea_igen_pos_rmove_loop(nmeaGENERATOR *gen, nmeaINFO *info)
{
Q_UNUSED(gen);
nmeaPOS crd;
info->direction += nmea_random(-10, 10);
info->speed += nmea_random(-2, 3);
if(info->direction < 0)
info->direction = 359 + info->direction;
if(info->direction > 359)
info->direction -= 359;
if(info->speed > 40)
info->speed = 40;
if(info->speed < 1)
info->speed = 1;
nmea_info2pos(info, &crd);
nmea_move_horz(&crd, &crd, info->direction, info->speed / 3600);
nmea_pos2info(&crd, info);
info->declination = info->direction;
return 1;
};
int nmea_igen_pos_rmove_destroy(nmeaGENERATOR *gen)
{
return 1;
};
/*
* generator create
*/
nmeaGENERATOR * __nmea_create_generator(int type, nmeaINFO *info)
{
nmeaGENERATOR *gen = 0;
switch(type)
{
case NMEA_GEN_NOISE:
if(0 == (gen = malloc(sizeof(nmeaGENERATOR))))
nmea_error("Insufficient memory!");
else
{
memset(gen, 0, sizeof(nmeaGENERATOR));
gen->init_call = &nmea_igen_noise_init;
gen->loop_call = &nmea_igen_noise_loop;
gen->reset_call = &nmea_igen_noise_reset;
}
break;
case NMEA_GEN_STATIC:
case NMEA_GEN_SAT_STATIC:
if(0 == (gen = malloc(sizeof(nmeaGENERATOR))))
nmea_error("Insufficient memory!");
else
{
memset(gen, 0, sizeof(nmeaGENERATOR));
gen->init_call = &nmea_igen_static_init;
gen->loop_call = &nmea_igen_static_loop;
gen->reset_call = &nmea_igen_static_reset;
}
break;
case NMEA_GEN_SAT_ROTATE:
if(0 == (gen = malloc(sizeof(nmeaGENERATOR))))
nmea_error("Insufficient memory!");
else
{
memset(gen, 0, sizeof(nmeaGENERATOR));
gen->init_call = &nmea_igen_rotate_init;
gen->loop_call = &nmea_igen_rotate_loop;
gen->reset_call = &nmea_igen_rotate_reset;
}
break;
case NMEA_GEN_POS_RANDMOVE:
if(0 == (gen = malloc(sizeof(nmeaGENERATOR))))
nmea_error("Insufficient memory!");
else
{
memset(gen, 0, sizeof(nmeaGENERATOR));
gen->init_call = &nmea_igen_pos_rmove_init;
gen->loop_call = &nmea_igen_pos_rmove_loop;
gen->destroy_call = &nmea_igen_pos_rmove_destroy;
}
break;
case NMEA_GEN_ROTATE:
gen = __nmea_create_generator(NMEA_GEN_SAT_ROTATE, info);
nmea_gen_add(gen, __nmea_create_generator(NMEA_GEN_POS_RANDMOVE, info));
break;
};
return gen;
}
nmeaGENERATOR * nmea_create_generator(int type, nmeaINFO *info)
{
nmeaGENERATOR *gen = __nmea_create_generator(type, info);
if(gen)
nmea_gen_init(gen, info);
return gen;
}
void nmea_destroy_generator(nmeaGENERATOR *gen)
{
nmea_gen_destroy(gen);
}
#if defined(NMEA_WIN) && defined(_MSC_VER)
# pragma warning(default: 4100)
#endif
This diff is collapsed.
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: config.h 17 2008-03-11 11:56:11Z xtimor $
*
*/
#ifndef __NMEA_CONFIG_H__
#define __NMEA_CONFIG_H__
#define NMEA_VERSION ("0.5.3")
#define NMEA_VERSION_MAJOR (0)
#define NMEA_VERSION_MINOR (5)
#define NMEA_VERSION_PATCH (3)
#define NMEA_CONVSTR_BUF (256)
#define NMEA_TIMEPARSE_BUF (256)
#if defined(WINCE) || defined(UNDER_CE)
# define NMEA_CE
#endif
#if defined(WIN32) || defined(NMEA_CE)
# define NMEA_WIN
#else
# define NMEA_UNI
#endif
#if defined(NMEA_WIN) && (_MSC_VER >= 1400)
# pragma warning(disable: 4996) /* declared deprecated */
#endif
#if defined(_MSC_VER)
# define NMEA_POSIX(x) _##x
# define NMEA_INLINE __inline
#else
# define NMEA_POSIX(x) x
# define NMEA_INLINE inline
#endif
#if !defined(NDEBUG) && !defined(NMEA_CE)
# include <assert.h>
# define NMEA_ASSERT(x) assert(x)
#else
# define NMEA_ASSERT(x)
#endif
#endif /* __NMEA_CONFIG_H__ */
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: context.h 4 2007-08-27 13:11:03Z xtimor $
*
*/
#ifndef __NMEA_CONTEXT_H__
#define __NMEA_CONTEXT_H__
#include "config.h"
#define NMEA_DEF_PARSEBUFF (1024)
#define NMEA_MIN_PARSEBUFF (256)
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*nmeaTraceFunc)(const char *str, int str_size);
typedef void (*nmeaErrorFunc)(const char *str, int str_size);
typedef struct _nmeaPROPERTY
{
nmeaTraceFunc trace_func;
nmeaErrorFunc error_func;
int parse_buff_size;
} nmeaPROPERTY;
nmeaPROPERTY * nmea_property();
void nmea_trace(const char *str, ...);
void nmea_trace_buff(const char *buff, int buff_size);
void nmea_error(const char *str, ...);
#ifdef __cplusplus
}
#endif
#endif /* __NMEA_CONTEXT_H__ */
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: generate.h 4 2007-08-27 13:11:03Z xtimor $
*
*/
#ifndef __NMEA_GENERATE_H__
#define __NMEA_GENERATE_H__
#include "sentence.h"
#ifdef __cplusplus
extern "C" {
#endif
int nmea_generate(
char *buff, int buff_sz, /* buffer */
const nmeaINFO *info, /* source info */
int generate_mask /* mask of sentence`s (e.g. GPGGA | GPGSA) */
);
int nmea_gen_GPGGA(char *buff, int buff_sz, nmeaGPGGA *pack);
int nmea_gen_GPGSA(char *buff, int buff_sz, nmeaGPGSA *pack);
int nmea_gen_GPGSV(char *buff, int buff_sz, nmeaGPGSV *pack);
int nmea_gen_GPRMC(char *buff, int buff_sz, nmeaGPRMC *pack);
int nmea_gen_GPVTG(char *buff, int buff_sz, nmeaGPVTG *pack);
void nmea_info2GPGGA(const nmeaINFO *info, nmeaGPGGA *pack);
void nmea_info2GPGSA(const nmeaINFO *info, nmeaGPGSA *pack);
void nmea_info2GPRMC(const nmeaINFO *info, nmeaGPRMC *pack);
void nmea_info2GPVTG(const nmeaINFO *info, nmeaGPVTG *pack);
int nmea_gsv_npack(int sat_count);
void nmea_info2GPGSV(const nmeaINFO *info, nmeaGPGSV *pack, int pack_idx);
#ifdef __cplusplus
}
#endif
#endif /* __NMEA_GENERATE_H__ */
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: generator.h 4 2007-08-27 13:11:03Z xtimor $
*
*/
#ifndef __NMEA_GENERATOR_H__
#define __NMEA_GENERATOR_H__
#include "info.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* high level
*/
struct _nmeaGENERATOR;
enum nmeaGENTYPE
{
NMEA_GEN_NOISE = 0,
NMEA_GEN_STATIC,
NMEA_GEN_ROTATE,
NMEA_GEN_SAT_STATIC,
NMEA_GEN_SAT_ROTATE,
NMEA_GEN_POS_RANDMOVE,
NMEA_GEN_LAST
};
struct _nmeaGENERATOR * nmea_create_generator(int type, nmeaINFO *info);
void nmea_destroy_generator(struct _nmeaGENERATOR *gen);
int nmea_generate_from(
char *buff, int buff_sz, /* buffer */
nmeaINFO *info, /* source info */
struct _nmeaGENERATOR *gen, /* generator */
int generate_mask /* mask of sentence`s (e.g. GPGGA | GPGSA) */
);
/*
* low level
*/
typedef int (*nmeaNMEA_GEN_INIT)(struct _nmeaGENERATOR *gen, nmeaINFO *info);
typedef int (*nmeaNMEA_GEN_LOOP)(struct _nmeaGENERATOR *gen, nmeaINFO *info);
typedef int (*nmeaNMEA_GEN_RESET)(struct _nmeaGENERATOR *gen, nmeaINFO *info);
typedef int (*nmeaNMEA_GEN_DESTROY)(struct _nmeaGENERATOR *gen);
typedef struct _nmeaGENERATOR
{
void *gen_data;
nmeaNMEA_GEN_INIT init_call;
nmeaNMEA_GEN_LOOP loop_call;
nmeaNMEA_GEN_RESET reset_call;
nmeaNMEA_GEN_DESTROY destroy_call;
struct _nmeaGENERATOR *next;
} nmeaGENERATOR;
int nmea_gen_init(nmeaGENERATOR *gen, nmeaINFO *info);
int nmea_gen_loop(nmeaGENERATOR *gen, nmeaINFO *info);
int nmea_gen_reset(nmeaGENERATOR *gen, nmeaINFO *info);
void nmea_gen_destroy(nmeaGENERATOR *gen);
void nmea_gen_add(nmeaGENERATOR *to, nmeaGENERATOR *gen);
#ifdef __cplusplus
}
#endif
#endif /* __NMEA_GENERATOR_H__ */
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: gmath.h 17 2008-03-11 11:56:11Z xtimor $
*
*/
#ifndef __NMEA_GMATH_H__
#define __NMEA_GMATH_H__
#include "info.h"
#define NMEA_PI (3.141592653589793) /**< PI value */
#define NMEA_PI180 (NMEA_PI / 180) /**< PI division by 180 */
#define NMEA_EARTHRADIUS_KM (6378) /**< Earth's mean radius in km */
#define NMEA_EARTHRADIUS_M (NMEA_EARTHRADIUS_KM * 1000) /**< Earth's mean radius in m */
#define NMEA_EARTH_SEMIMAJORAXIS_M (6378137.0) /**< Earth's semi-major axis in m according WGS84 */
#define NMEA_EARTH_SEMIMAJORAXIS_KM (NMEA_EARTHMAJORAXIS_KM / 1000) /**< Earth's semi-major axis in km according WGS 84 */
#define NMEA_EARTH_FLATTENING (1 / 298.257223563) /**< Earth's flattening according WGS 84 */
#define NMEA_DOP_FACTOR (5) /**< Factor for translating DOP to meters */
#ifdef __cplusplus
extern "C" {
#endif
/*
* degree VS radian
*/
double nmea_degree2radian(double val);
double nmea_radian2degree(double val);
/*
* NDEG (NMEA degree)
*/
double nmea_ndeg2degree(double val);
double nmea_degree2ndeg(double val);
double nmea_ndeg2radian(double val);
double nmea_radian2ndeg(double val);
/*
* DOP
*/
double nmea_calc_pdop(double hdop, double vdop);
double nmea_dop2meters(double dop);
double nmea_meters2dop(double meters);
/*
* positions work
*/
void nmea_info2pos(const nmeaINFO *info, nmeaPOS *pos);
void nmea_pos2info(const nmeaPOS *pos, nmeaINFO *info);
double nmea_distance(
const nmeaPOS *from_pos,
const nmeaPOS *to_pos
);
double nmea_distance_ellipsoid(
const nmeaPOS *from_pos,
const nmeaPOS *to_pos,
double *from_azimuth,
double *to_azimuth
);
int nmea_move_horz(
const nmeaPOS *start_pos,
nmeaPOS *end_pos,
double azimuth,
double distance
);
int nmea_move_horz_ellipsoid(
const nmeaPOS *start_pos,
nmeaPOS *end_pos,
double azimuth,
double distance,
double *end_azimuth
);
#ifdef __cplusplus
}
#endif
#endif /* __NMEA_GMATH_H__ */
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: info.h 10 2007-11-15 14:50:15Z xtimor $
*
*/
/*! \file */
#ifndef __NMEA_INFO_H__
#define __NMEA_INFO_H__
#include "time.h"
#define NMEA_SIG_BAD (0)
#define NMEA_SIG_LOW (1)
#define NMEA_SIG_MID (2)
#define NMEA_SIG_HIGH (3)
#define NMEA_FIX_BAD (1)
#define NMEA_FIX_2D (2)
#define NMEA_FIX_3D (3)
#define NMEA_MAXSAT (12)
#define NMEA_SATINPACK (4)
#define NMEA_NSATPACKS (NMEA_MAXSAT / NMEA_SATINPACK)
#define NMEA_DEF_LAT (5001.2621)
#define NMEA_DEF_LON (3613.0595)
#ifdef __cplusplus
extern "C" {
#endif
/**
* Position data in fractional degrees or radians
*/
typedef struct _nmeaPOS
{
double lat; /**< Latitude */
double lon; /**< Longitude */
} nmeaPOS;
/**
* Information about satellite
* @see nmeaSATINFO
* @see nmeaGPGSV
*/
typedef struct _nmeaSATELLITE
{
int id; /**< Satellite PRN number */
int in_use; /**< Used in position fix */
int elv; /**< Elevation in degrees, 90 maximum */
int azimuth; /**< Azimuth, degrees from true north, 000 to 359 */
int sig; /**< Signal, 00-99 dB */
} nmeaSATELLITE;
/**
* Information about all satellites in view
* @see nmeaINFO
* @see nmeaGPGSV
*/
typedef struct _nmeaSATINFO
{
int inuse; /**< Number of satellites in use (not those in view) */
int inview; /**< Total number of satellites in view */
nmeaSATELLITE sat[NMEA_MAXSAT]; /**< Satellites information */
} nmeaSATINFO;
/**
* Summary GPS information from all parsed packets,
* used also for generating NMEA stream
* @see nmea_parse
* @see nmea_GPGGA2info, nmea_...2info
*/
typedef struct _nmeaINFO
{
int smask; /**< Mask specifying types of packages from which data have been obtained */
nmeaTIME utc; /**< UTC of position */
int sig; /**< GPS quality indicator (0 = Invalid; 1 = Fix; 2 = Differential, 3 = Sensitive) */
int fix; /**< Operating mode, used for navigation (1 = Fix not available; 2 = 2D; 3 = 3D) */
double PDOP; /**< Position Dilution Of Precision */
double HDOP; /**< Horizontal Dilution Of Precision */
double VDOP; /**< Vertical Dilution Of Precision */
double lat; /**< Latitude in NDEG - +/-[degree][min].[sec/60] */
double lon; /**< Longitude in NDEG - +/-[degree][min].[sec/60] */
double elv; /**< Antenna altitude above/below mean sea level (geoid) in meters */
double speed; /**< Speed over the ground in kilometers/hour */
double direction; /**< Track angle in degrees True */
double declination; /**< Magnetic variation degrees (Easterly var. subtracts from true course) */
nmeaSATINFO satinfo; /**< Satellites information */
} nmeaINFO;
void nmea_zero_INFO(nmeaINFO *info);
#ifdef __cplusplus
}
#endif
#endif /* __NMEA_INFO_H__ */
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: nmea.h 17 2008-03-11 11:56:11Z xtimor $
*
*/
#ifndef __NMEA_H__
#define __NMEA_H__
#include "./config.h"
#include "./units.h"
#include "./gmath.h"
#include "./info.h"
#include "./sentence.h"
#include "./generate.h"
#include "./generator.h"
#include "./parse.h"
#include "./parser.h"
#include "./context.h"
#endif /* __NMEA_H__ */
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: parse.h 4 2007-08-27 13:11:03Z xtimor $
*
*/
#ifndef __NMEA_PARSE_H__
#define __NMEA_PARSE_H__
#include "sentence.h"
#ifdef __cplusplus
extern "C" {
#endif
int nmea_pack_type(const char *buff, int buff_sz);
int nmea_find_tail(const char *buff, int buff_sz, int *res_crc);
int nmea_parse_GPGGA(const char *buff, int buff_sz, nmeaGPGGA *pack);
int nmea_parse_GPGSA(const char *buff, int buff_sz, nmeaGPGSA *pack);
int nmea_parse_GPGSV(const char *buff, int buff_sz, nmeaGPGSV *pack);
int nmea_parse_GPRMC(const char *buff, int buff_sz, nmeaGPRMC *pack);
int nmea_parse_GPVTG(const char *buff, int buff_sz, nmeaGPVTG *pack);
void nmea_GPGGA2info(nmeaGPGGA *pack, nmeaINFO *info);
void nmea_GPGSA2info(nmeaGPGSA *pack, nmeaINFO *info);
void nmea_GPGSV2info(nmeaGPGSV *pack, nmeaINFO *info);
void nmea_GPRMC2info(nmeaGPRMC *pack, nmeaINFO *info);
void nmea_GPVTG2info(nmeaGPVTG *pack, nmeaINFO *info);
#ifdef __cplusplus
}
#endif
#endif /* __NMEA_PARSE_H__ */
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: parser.h 4 2007-08-27 13:11:03Z xtimor $
*
*/
#ifndef __NMEA_PARSER_H__
#define __NMEA_PARSER_H__
#include "info.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* high level
*/
typedef struct _nmeaPARSER
{
void *top_node;
void *end_node;
unsigned char *buffer;
int buff_size;
int buff_use;
} nmeaPARSER;
int nmea_parser_init(nmeaPARSER *parser);
void nmea_parser_destroy(nmeaPARSER *parser);
int nmea_parse(
nmeaPARSER *parser,
const char *buff, int buff_sz,
nmeaINFO *info
);
/*
* low level
*/
int nmea_parser_push(nmeaPARSER *parser, const char *buff, int buff_sz);
int nmea_parser_top(nmeaPARSER *parser);
int nmea_parser_pop(nmeaPARSER *parser, void **pack_ptr);
int nmea_parser_peek(nmeaPARSER *parser, void **pack_ptr);
int nmea_parser_drop(nmeaPARSER *parser);
int nmea_parser_buff_clear(nmeaPARSER *parser);
int nmea_parser_queue_clear(nmeaPARSER *parser);
#ifdef __cplusplus
}
#endif
#endif /* __NMEA_PARSER_H__ */
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: sentence.h 17 2008-03-11 11:56:11Z xtimor $
*
*/
/*! \file */
#ifndef __NMEA_SENTENCE_H__
#define __NMEA_SENTENCE_H__
#include "info.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* NMEA packets type which parsed and generated by library
*/
enum nmeaPACKTYPE
{
GPNON = 0x0000, /**< Unknown packet type. */
GPGGA = 0x0001, /**< GGA - Essential fix data which provide 3D location and accuracy data. */
GPGSA = 0x0002, /**< GSA - GPS receiver operating mode, SVs used for navigation, and DOP values. */
GPGSV = 0x0004, /**< GSV - Number of SVs in view, PRN numbers, elevation, azimuth & SNR values. */
GPRMC = 0x0008, /**< RMC - Recommended Minimum Specific GPS/TRANSIT Data. */
GPVTG = 0x0010 /**< VTG - Actual track made good and speed over ground. */
};
/**
* GGA packet information structure (Global Positioning System Fix Data)
*/
typedef struct _nmeaGPGGA
{
nmeaTIME utc; /**< UTC of position (just time) */
double lat; /**< Latitude in NDEG - [degree][min].[sec/60] */
char ns; /**< [N]orth or [S]outh */
double lon; /**< Longitude in NDEG - [degree][min].[sec/60] */
char ew; /**< [E]ast or [W]est */
int sig; /**< GPS quality indicator (0 = Invalid; 1 = Fix; 2 = Differential, 3 = Sensitive) */
int satinuse; /**< Number of satellites in use (not those in view) */
double HDOP; /**< Horizontal dilution of precision */
double elv; /**< Antenna altitude above/below mean sea level (geoid) */
char elv_units; /**< [M]eters (Antenna height unit) */
double diff; /**< Geoidal separation (Diff. between WGS-84 earth ellipsoid and mean sea level. '-' = geoid is below WGS-84 ellipsoid) */
char diff_units; /**< [M]eters (Units of geoidal separation) */
double dgps_age; /**< Time in seconds since last DGPS update */
int dgps_sid; /**< DGPS station ID number */
} nmeaGPGGA;
/**
* GSA packet information structure (Satellite status)
*/
typedef struct _nmeaGPGSA
{
char fix_mode; /**< Mode (M = Manual, forced to operate in 2D or 3D; A = Automatic, 3D/2D) */
int fix_type; /**< Type, used for navigation (1 = Fix not available; 2 = 2D; 3 = 3D) */
int sat_prn[NMEA_MAXSAT]; /**< PRNs of satellites used in position fix (null for unused fields) */
double PDOP; /**< Dilution of precision */
double HDOP; /**< Horizontal dilution of precision */
double VDOP; /**< Vertical dilution of precision */
} nmeaGPGSA;
/**
* GSV packet information structure (Satellites in view)
*/
typedef struct _nmeaGPGSV
{
int pack_count; /**< Total number of messages of this type in this cycle */
int pack_index; /**< Message number */
int sat_count; /**< Total number of satellites in view */
nmeaSATELLITE sat_data[NMEA_SATINPACK];
} nmeaGPGSV;
/**
* RMC packet information structure (Recommended Minimum sentence C)
*/
typedef struct _nmeaGPRMC
{
nmeaTIME utc; /**< UTC of position */
char status; /**< Status (A = active or V = void) */
double lat; /**< Latitude in NDEG - [degree][min].[sec/60] */
char ns; /**< [N]orth or [S]outh */
double lon; /**< Longitude in NDEG - [degree][min].[sec/60] */
char ew; /**< [E]ast or [W]est */
double speed; /**< Speed over the ground in knots */
double direction; /**< Track angle in degrees True */
double declination; /**< Magnetic variation degrees (Easterly var. subtracts from true course) */
char declin_ew; /**< [E]ast or [W]est */
char mode; /**< Mode indicator of fix type (A = autonomous, D = differential, E = estimated, N = not valid, S = simulator) */
} nmeaGPRMC;
/**
* VTG packet information structure (Track made good and ground speed)
*/
typedef struct _nmeaGPVTG
{
double dir; /**< True track made good (degrees) */
char dir_t; /**< Fixed text 'T' indicates that track made good is relative to true north */
double dec; /**< Magnetic track made good */
char dec_m; /**< Fixed text 'M' */
double spn; /**< Ground speed, knots */
char spn_n; /**< Fixed text 'N' indicates that speed over ground is in knots */
double spk; /**< Ground speed, kilometers per hour */
char spk_k; /**< Fixed text 'K' indicates that speed over ground is in kilometers/hour */
} nmeaGPVTG;
void nmea_zero_GPGGA(nmeaGPGGA *pack);
void nmea_zero_GPGSA(nmeaGPGSA *pack);
void nmea_zero_GPGSV(nmeaGPGSV *pack);
void nmea_zero_GPRMC(nmeaGPRMC *pack);
void nmea_zero_GPVTG(nmeaGPVTG *pack);
#ifdef __cplusplus
}
#endif
#endif /* __NMEA_SENTENCE_H__ */
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: time.h 4 2007-08-27 13:11:03Z xtimor $
*
*/
/*! \file */
#ifndef __NMEA_TIME_H__
#define __NMEA_TIME_H__
#include "config.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Date and time data
* @see nmea_time_now
*/
typedef struct _nmeaTIME
{
int year; /**< Years since 1900 */
int mon; /**< Months since January - [0,11] */
int day; /**< Day of the month - [1,31] */
int hour; /**< Hours since midnight - [0,23] */
int min; /**< Minutes after the hour - [0,59] */
int sec; /**< Seconds after the minute - [0,59] */
int hsec; /**< Hundredth part of second - [0,99] */
} nmeaTIME;
/**
* \brief Get time now to nmeaTIME structure
*/
void nmea_time_now(nmeaTIME *t);
#ifdef __cplusplus
}
#endif
#endif /* __NMEA_TIME_H__ */
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: tok.h 4 2007-08-27 13:11:03Z xtimor $
*
*/
#ifndef __NMEA_TOK_H__
#define __NMEA_TOK_H__
#include "config.h"
#ifdef __cplusplus
extern "C" {
#endif
int nmea_calc_crc(const char *buff, int buff_sz);
int nmea_atoi(const char *str, int str_sz, int radix);
double nmea_atof(const char *str, int str_sz);
int nmea_printf(char *buff, int buff_sz, const char *format, ...);
int nmea_scanf(const char *buff, int buff_sz, const char *format, ...);
#ifdef __cplusplus
}
#endif
#endif /* __NMEA_TOK_H__ */
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: units.h 4 2007-08-27 13:11:03Z xtimor $
*
*/
#ifndef __NMEA_UNITS_H__
#define __NMEA_UNITS_H__
#include "config.h"
/*
* Distance units
*/
#define NMEA_TUD_YARDS (1.0936) /**< Yeards, meter * NMEA_TUD_YARDS = yard */
#define NMEA_TUD_KNOTS (1.852) /**< Knots, kilometer / NMEA_TUD_KNOTS = knot */
#define NMEA_TUD_MILES (1.609) /**< Miles, kilometer / NMEA_TUD_MILES = mile */
/*
* Speed units
*/
#define NMEA_TUS_MS (3.6) /**< Meters per seconds, (k/h) / NMEA_TUS_MS= (m/s) */
#endif /* __NMEA_UNITS_H__ */
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: info.c 17 2008-03-11 11:56:11Z xtimor $
*
*/
#include <string.h>
#include "nmea/info.h"
void nmea_zero_INFO(nmeaINFO *info)
{
memset(info, 0, sizeof(nmeaINFO));
nmea_time_now(&info->utc);
info->sig = NMEA_SIG_BAD;
info->fix = NMEA_FIX_BAD;
}
DEPENDPATH += lib/nmea lib/nmea/include
INCLUDEPATH += lib/nmea/include
# Input
HEADERS += include/nmea/config.h \
include/nmea/context.h \
include/nmea/gmath.h \
include/nmea/info.h \
include/nmea/nmea.h \
include/nmea/parse.h \
include/nmea/parser.h \
include/nmea/sentence.h \
include/nmea/time.h \
include/nmea/tok.h \
include/nmea/units.h
SOURCES += context.c \
gmath.c \
info.c \
parse.c \
parser.c \
sentence.c \
time.c \
tok.c
This diff is collapsed.
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: parser.c 17 2008-03-11 11:56:11Z xtimor $
*
*/
/**
* \file parser.h
*/
#include "nmea/tok.h"
#include "nmea/parse.h"
#include "nmea/parser.h"
#include "nmea/context.h"
#include <string.h>
#include <stdlib.h>
typedef struct _nmeaParserNODE
{
int packType;
void *pack;
struct _nmeaParserNODE *next_node;
} nmeaParserNODE;
/*
* high level
*/
/**
* \brief Initialization of parser object
* @return true (1) - success or false (0) - fail
*/
int nmea_parser_init(nmeaPARSER *parser)
{
int resv = 0;
int buff_size = nmea_property()->parse_buff_size;
NMEA_ASSERT(parser);
if(buff_size < NMEA_MIN_PARSEBUFF)
buff_size = NMEA_MIN_PARSEBUFF;
memset(parser, 0, sizeof(nmeaPARSER));
if(0 == (parser->buffer = malloc(buff_size)))
nmea_error("Insufficient memory!");
else
{
parser->buff_size = buff_size;
resv = 1;
}
return resv;
}
/**
* \brief Destroy parser object
*/
void nmea_parser_destroy(nmeaPARSER *parser)
{
NMEA_ASSERT(parser && parser->buffer);
free(parser->buffer);
nmea_parser_queue_clear(parser);
memset(parser, 0, sizeof(nmeaPARSER));
}
/**
* \brief Analysis of buffer and put results to information structure
* @return Number of packets wos parsed
*/
int nmea_parse(
nmeaPARSER *parser,
const char *buff, int buff_sz,
nmeaINFO *info
)
{
int ptype, nread = 0;
void *pack = 0;
NMEA_ASSERT(parser && parser->buffer);
nmea_parser_push(parser, buff, buff_sz);
while(GPNON != (ptype = nmea_parser_pop(parser, &pack)))
{
nread++;
switch(ptype)
{
case GPGGA:
nmea_GPGGA2info((nmeaGPGGA *)pack, info);
break;
case GPGSA:
nmea_GPGSA2info((nmeaGPGSA *)pack, info);
break;
case GPGSV:
nmea_GPGSV2info((nmeaGPGSV *)pack, info);
break;
case GPRMC:
nmea_GPRMC2info((nmeaGPRMC *)pack, info);
break;
case GPVTG:
nmea_GPVTG2info((nmeaGPVTG *)pack, info);
break;
};
free(pack);
}
return nread;
}
/*
* low level
*/
int nmea_parser_real_push(nmeaPARSER *parser, const char *buff, int buff_sz)
{
int nparsed = 0, crc, sen_sz, ptype;
nmeaParserNODE *node = 0;
NMEA_ASSERT(parser && parser->buffer);
/* clear unuse buffer (for debug) */
/*
memset(
parser->buffer + parser->buff_use, 0,
parser->buff_size - parser->buff_use
);
*/
/* add */
if(parser->buff_use + buff_sz >= parser->buff_size)
nmea_parser_buff_clear(parser);
memcpy(parser->buffer + parser->buff_use, buff, buff_sz);
parser->buff_use += buff_sz;
/* parse */
for(;;node = 0)
{
sen_sz = nmea_find_tail(
(const char *)parser->buffer + nparsed,
(int)parser->buff_use - nparsed, &crc);
if(!sen_sz)
{
if(nparsed)
memcpy(
parser->buffer,
parser->buffer + nparsed,
parser->buff_use -= nparsed);
break;
}
else if(crc >= 0)
{
ptype = nmea_pack_type(
(const char *)parser->buffer + nparsed + 1,
parser->buff_use - nparsed - 1);
if(0 == (node = malloc(sizeof(nmeaParserNODE))))
goto mem_fail;
node->pack = 0;
switch(ptype)
{
case GPGGA:
if(0 == (node->pack = malloc(sizeof(nmeaGPGGA))))
goto mem_fail;
node->packType = GPGGA;
if(!nmea_parse_GPGGA(
(const char *)parser->buffer + nparsed,
sen_sz, (nmeaGPGGA *)node->pack))
{
free(node);
node = 0;
}
break;
case GPGSA:
if(0 == (node->pack = malloc(sizeof(nmeaGPGSA))))
goto mem_fail;
node->packType = GPGSA;
if(!nmea_parse_GPGSA(
(const char *)parser->buffer + nparsed,
sen_sz, (nmeaGPGSA *)node->pack))
{
free(node);
node = 0;
}
break;
case GPGSV:
if(0 == (node->pack = malloc(sizeof(nmeaGPGSV))))
goto mem_fail;
node->packType = GPGSV;
if(!nmea_parse_GPGSV(
(const char *)parser->buffer + nparsed,
sen_sz, (nmeaGPGSV *)node->pack))
{
free(node);
node = 0;
}
break;
case GPRMC:
if(0 == (node->pack = malloc(sizeof(nmeaGPRMC))))
goto mem_fail;
node->packType = GPRMC;
if(!nmea_parse_GPRMC(
(const char *)parser->buffer + nparsed,
sen_sz, (nmeaGPRMC *)node->pack))
{
free(node);
node = 0;
}
break;
case GPVTG:
if(0 == (node->pack = malloc(sizeof(nmeaGPVTG))))
goto mem_fail;
node->packType = GPVTG;
if(!nmea_parse_GPVTG(
(const char *)parser->buffer + nparsed,
sen_sz, (nmeaGPVTG *)node->pack))
{
free(node);
node = 0;
}
break;
default:
free(node);
node = 0;
break;
};
if(node)
{
if(parser->end_node)
((nmeaParserNODE *)parser->end_node)->next_node = node;
parser->end_node = node;
if(!parser->top_node)
parser->top_node = node;
node->next_node = 0;
}
}
nparsed += sen_sz;
}
return nparsed;
mem_fail:
if(node)
free(node);
nmea_error("Insufficient memory!");
return -1;
}
/**
* \brief Analysis of buffer and keep results into parser
* @return Number of bytes wos parsed from buffer
*/
int nmea_parser_push(nmeaPARSER *parser, const char *buff, int buff_sz)
{
int nparse, nparsed = 0;
do
{
if(buff_sz > parser->buff_size)
nparse = parser->buff_size;
else
nparse = buff_sz;
nparsed += nmea_parser_real_push(
parser, buff, nparse);
buff_sz -= nparse;
} while(buff_sz);
return nparsed;
}
/**
* \brief Get type of top packet keeped into parser
* @return Type of packet
* @see nmeaPACKTYPE
*/
int nmea_parser_top(nmeaPARSER *parser)
{
int retval = GPNON;
nmeaParserNODE *node = (nmeaParserNODE *)parser->top_node;
NMEA_ASSERT(parser && parser->buffer);
if(node)
retval = node->packType;
return retval;
}
/**
* \brief Withdraw top packet from parser
* @return Received packet type
* @see nmeaPACKTYPE
*/
int nmea_parser_pop(nmeaPARSER *parser, void **pack_ptr)
{
int retval = GPNON;
nmeaParserNODE *node = (nmeaParserNODE *)parser->top_node;
NMEA_ASSERT(parser && parser->buffer);
if(node)
{
*pack_ptr = node->pack;
retval = node->packType;
parser->top_node = node->next_node;
if(!parser->top_node)
parser->end_node = 0;
free(node);
}
return retval;
}
/**
* \brief Get top packet from parser without withdraw
* @return Received packet type
* @see nmeaPACKTYPE
*/
int nmea_parser_peek(nmeaPARSER *parser, void **pack_ptr)
{
int retval = GPNON;
nmeaParserNODE *node = (nmeaParserNODE *)parser->top_node;
NMEA_ASSERT(parser && parser->buffer);
if(node)
{
*pack_ptr = node->pack;
retval = node->packType;
}
return retval;
}
/**
* \brief Delete top packet from parser
* @return Deleted packet type
* @see nmeaPACKTYPE
*/
int nmea_parser_drop(nmeaPARSER *parser)
{
int retval = GPNON;
nmeaParserNODE *node = (nmeaParserNODE *)parser->top_node;
NMEA_ASSERT(parser && parser->buffer);
if(node)
{
if(node->pack)
free(node->pack);
retval = node->packType;
parser->top_node = node->next_node;
if(!parser->top_node)
parser->end_node = 0;
free(node);
}
return retval;
}
/**
* \brief Clear cache of parser
* @return true (1) - success
*/
int nmea_parser_buff_clear(nmeaPARSER *parser)
{
NMEA_ASSERT(parser && parser->buffer);
parser->buff_use = 0;
return 1;
}
/**
* \brief Clear packets queue into parser
* @return true (1) - success
*/
int nmea_parser_queue_clear(nmeaPARSER *parser)
{
NMEA_ASSERT(parser);
while(parser->top_node)
nmea_parser_drop(parser);
return 1;
}
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: sentence.c 17 2008-03-11 11:56:11Z xtimor $
*
*/
#include "nmea/sentence.h"
#include <string.h>
void nmea_zero_GPGGA(nmeaGPGGA *pack)
{
memset(pack, 0, sizeof(nmeaGPGGA));
nmea_time_now(&pack->utc);
pack->ns = 'N';
pack->ew = 'E';
pack->elv_units = 'M';
pack->diff_units = 'M';
}
void nmea_zero_GPGSA(nmeaGPGSA *pack)
{
memset(pack, 0, sizeof(nmeaGPGSA));
pack->fix_mode = 'A';
pack->fix_type = NMEA_FIX_BAD;
}
void nmea_zero_GPGSV(nmeaGPGSV *pack)
{
memset(pack, 0, sizeof(nmeaGPGSV));
}
void nmea_zero_GPRMC(nmeaGPRMC *pack)
{
memset(pack, 0, sizeof(nmeaGPRMC));
nmea_time_now(&pack->utc);
pack->status = 'V';
pack->ns = 'N';
pack->ew = 'E';
pack->declin_ew = 'E';
}
void nmea_zero_GPVTG(nmeaGPVTG *pack)
{
memset(pack, 0, sizeof(nmeaGPVTG));
pack->dir_t = 'T';
pack->dec_m = 'M';
pack->spn_n = 'N';
pack->spk_k = 'K';
}
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: time.c 4 2007-08-27 13:11:03Z xtimor $
*
*/
/*! \file time.h */
#include "nmea/time.h"
#ifdef NMEA_WIN
# pragma warning(disable: 4201)
# pragma warning(disable: 4214)
# pragma warning(disable: 4115)
# include <windows.h>
# pragma warning(default: 4201)
# pragma warning(default: 4214)
# pragma warning(default: 4115)
#else
# include <time.h>
#endif
#ifdef NMEA_WIN
void nmea_time_now(nmeaTIME *stm)
{
SYSTEMTIME st;
GetSystemTime(&st);
stm->year = st.wYear - 1900;
stm->mon = st.wMonth - 1;
stm->day = st.wDay;
stm->hour = st.wHour;
stm->min = st.wMinute;
stm->sec = st.wSecond;
stm->hsec = st.wMilliseconds / 10;
}
#else /* NMEA_WIN */
void nmea_time_now(nmeaTIME *stm)
{
time_t lt;
struct tm *tt;
time(&lt);
tt = gmtime(&lt);
stm->year = tt->tm_year;
stm->mon = tt->tm_mon;
stm->day = tt->tm_mday;
stm->hour = tt->tm_hour;
stm->min = tt->tm_min;
stm->sec = tt->tm_sec;
stm->hsec = 0;
}
#endif
/*
*
* NMEA library
* URL: http://nmea.sourceforge.net
* Author: Tim (xtimor@gmail.com)
* Licence: http://www.gnu.org/licenses/lgpl.html
* $Id: tok.c 17 2008-03-11 11:56:11Z xtimor $
*
*/
/*! \file tok.h */
#include "nmea/tok.h"
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#define NMEA_TOKS_COMPARE (1)
#define NMEA_TOKS_PERCENT (2)
#define NMEA_TOKS_WIDTH (3)
#define NMEA_TOKS_TYPE (4)
/**
* \brief Calculate control sum of binary buffer
*/
int nmea_calc_crc(const char *buff, int buff_sz)
{
int chsum = 0,
it;
for(it = 0; it < buff_sz; ++it)
chsum ^= (int)buff[it];
return chsum;
}
/**
* \brief Convert string to number
*/
int nmea_atoi(const char *str, int str_sz, int radix)
{
char *tmp_ptr;
char buff[NMEA_CONVSTR_BUF];
int res = 0;
if(str_sz < NMEA_CONVSTR_BUF)
{
memcpy(&buff[0], str, str_sz);
buff[str_sz] = '\0';
res = strtol(&buff[0], &tmp_ptr, radix);
}
return res;
}
/**
* \brief Convert string to fraction number
*/
double nmea_atof(const char *str, int str_sz)
{
char *tmp_ptr;
char buff[NMEA_CONVSTR_BUF];
double res = 0;
if(str_sz < NMEA_CONVSTR_BUF)
{
memcpy(&buff[0], str, str_sz);
buff[str_sz] = '\0';
res = strtod(&buff[0], &tmp_ptr);
}
return res;
}
/**
* \brief Formating string (like standart printf) with CRC tail (*CRC)
*/
int nmea_printf(char *buff, int buff_sz, const char *format, ...)
{
int retval, add = 0;
va_list arg_ptr;
if(buff_sz <= 0)
return 0;
va_start(arg_ptr, format);
retval = NMEA_POSIX(vsnprintf)(buff, buff_sz, format, arg_ptr);
if(retval > 0)
{
add = NMEA_POSIX(snprintf)(
buff + retval, buff_sz - retval, "*%02x\r\n",
nmea_calc_crc(buff + 1, retval - 1));
}
retval += add;
if(retval < 0 || retval > buff_sz)
{
memset(buff, ' ', buff_sz);
retval = buff_sz;
}
va_end(arg_ptr);
return retval;
}
/**
* \brief Analyse string (specificate for NMEA sentences)
*/
int nmea_scanf(const char *buff, int buff_sz, const char *format, ...)
{
const char *beg_tok;
const char *end_buf = buff + buff_sz;
va_list arg_ptr;
int tok_type = NMEA_TOKS_COMPARE;
int width = 0;
const char *beg_fmt = 0;
int snum = 0, unum = 0;
int tok_count = 0;
void *parg_target;
va_start(arg_ptr, format);
for(; *format && buff < end_buf; ++format)
{
switch(tok_type)
{
case NMEA_TOKS_COMPARE:
if('%' == *format)
tok_type = NMEA_TOKS_PERCENT;
else if(*buff++ != *format)
goto fail;
break;
case NMEA_TOKS_PERCENT:
width = 0;
beg_fmt = format;
tok_type = NMEA_TOKS_WIDTH;
case NMEA_TOKS_WIDTH:
if(isdigit(*format))
break;
{
tok_type = NMEA_TOKS_TYPE;
if(format > beg_fmt)
width = nmea_atoi(beg_fmt, (int)(format - beg_fmt), 10);
}
case NMEA_TOKS_TYPE:
beg_tok = buff;
if(!width && ('c' == *format || 'C' == *format) && *buff != format[1])
width = 1;
if(width)
{
if(buff + width <= end_buf)
buff += width;
else
goto fail;
}
else
{
if(!format[1] || (0 == (buff = (char *)memchr(buff, format[1], end_buf - buff))))
buff = end_buf;
}
if(buff > end_buf)
goto fail;
tok_type = NMEA_TOKS_COMPARE;
tok_count++;
parg_target = 0; width = (int)(buff - beg_tok);
switch(*format)
{
case 'c':
case 'C':
parg_target = (void *)va_arg(arg_ptr, char *);
if(width && 0 != (parg_target))
*((char *)parg_target) = *beg_tok;
break;
case 's':
case 'S':
parg_target = (void *)va_arg(arg_ptr, char *);
if(width && 0 != (parg_target))
{
memcpy(parg_target, beg_tok, width);
((char *)parg_target)[width] = '\0';
}
break;
case 'f':
case 'g':
case 'G':
case 'e':
case 'E':
parg_target = (void *)va_arg(arg_ptr, double *);
if(width && 0 != (parg_target))
*((double *)parg_target) = nmea_atof(beg_tok, width);
break;
};
if(parg_target)
break;
if(0 == (parg_target = (void *)va_arg(arg_ptr, int *)))
break;
if(!width)
break;
switch(*format)
{
case 'd':
case 'i':
snum = nmea_atoi(beg_tok, width, 10);
memcpy(parg_target, &snum, sizeof(int));
break;
case 'u':
unum = nmea_atoi(beg_tok, width, 10);
memcpy(parg_target, &unum, sizeof(unsigned int));
break;
case 'x':
case 'X':
unum = nmea_atoi(beg_tok, width, 16);
memcpy(parg_target, &unum, sizeof(unsigned int));
break;
case 'o':
unum = nmea_atoi(beg_tok, width, 8);
memcpy(parg_target, &unum, sizeof(unsigned int));
break;
default:
goto fail;
};
break;
};
}
fail:
va_end(arg_ptr);
return tok_count;
}
#-------------------------------------------------
#
# Project created by QtCreator 2011-01-11T08:54:37
#
#-------------------------------------------------
QT += network \
phonon \
testlib \
svg
TEMPLATE = app
TARGET = qgcunittest
BASEDIR = $$IN_PWD
TESTDIR = $$BASEDIR/qgcunittest
TARGETDIR = $$OUT_PWD
BUILDDIR = $$TARGETDIR/build
LANGUAGE = C++
CONFIG += console
CONFIG -= app_bundle
OBJECTS_DIR = $$BUILDDIR/obj
MOC_DIR = $$BUILDDIR/moc
UI_HEADERS_DIR = src/ui/generated
MAVLINK_CONF = ""
# If the user config file exists, it will be included.
# if the variable MAVLINK_CONF contains the name of an
# additional project, QGroundControl includes the support
# of custom MAVLink messages of this project
exists(user_config.pri) {
include(user_config.pri)
message("----- USING CUSTOM USER QGROUNDCONTROL CONFIG FROM user_config.pri -----")
message("Adding support for additional MAVLink messages for: " $$MAVLINK_CONF)
message("------------------------------------------------------------------------")
}
INCLUDEPATH += $$BASEDIR/../mavlink/include/common
contains(MAVLINK_CONF, pixhawk) {
# Remove the default set - it is included anyway
INCLUDEPATH -= $$BASEDIR/../mavlink/include/common
# PIXHAWK SPECIAL MESSAGES
INCLUDEPATH += $$BASEDIR/../mavlink/include/pixhawk
DEFINES += QGC_USE_PIXHAWK_MESSAGES
}
contains(MAVLINK_CONF, slugs) {
# Remove the default set - it is included anyway
INCLUDEPATH -= $$BASEDIR/../mavlink/include/common
# SLUGS SPECIAL MESSAGES
INCLUDEPATH += $$BASEDIR/../mavlink/include/slugs
DEFINES += QGC_USE_SLUGS_MESSAGES
}
contains(MAVLINK_CONF, ualberta) {
# Remove the default set - it is included anyway
INCLUDEPATH -= $$BASEDIR/../mavlink/include/common
# UALBERTA SPECIAL MESSAGES
INCLUDEPATH += $$BASEDIR/../mavlink/include/ualberta
DEFINES += QGC_USE_UALBERTA_MESSAGES
}
contains(MAVLINK_CONF, ardupilotmega) {
# Remove the default set - it is included anyway
INCLUDEPATH -= $$BASEDIR/../mavlink/include/common
# UALBERTA SPECIAL MESSAGES
INCLUDEPATH += $$BASEDIR/../mavlink/include/ardupilotmega
DEFINES += QGC_USE_ARDUPILOTMEGA_MESSAGES
}
# Include general settings for QGroundControl
# necessary as last include to override any non-acceptable settings
# done by the plugins above
include(qgroundcontrol.pri)
# Reset QMAKE_POST_LINK to prevent file copy operations
QMAKE_POST_LINK = ""
# QWT plot and QExtSerial depend on paths set by qgroundcontrol.pri
# Include serial port library
include(src/lib/qextserialport/qextserialport.pri)
# Include QWT plotting library
include(src/lib/qwt/qwt.pri)
DEPENDPATH += . \
lib/QMapControl \
lib/QMapControl/src \
plugins
INCLUDEPATH += . \
lib/QMapControl \
$$BASEDIR/../mavlink/include \
$$BASEDIR/src/uas \
$$BASEDIR/src/comm \
$$BASEDIR/src/ \
$$BASEDIR/src/ui/RadioCalibration \
$$BASEDIR/src/ui/ \
SOURCES += src/uas/UAS.cc \
src/comm/MAVLinkProtocol.cc \
src/uas/UASWaypointManager.cc \
src/Waypoint.cc \
src/ui/RadioCalibration/RadioCalibrationData.cc \
src/uas/SlugsMAV.cc \
src/uas/PxQuadMAV.cc \
src/uas/ArduPilotMegaMAV.cc \
src/GAudioOutput.cc \
src/uas/UASManager.cc \
src/comm/LinkManager.cc \
src/QGC.cc \
src/comm/SerialLink.cc \
$$TESTDIR/SlugsMavUnitTest.cc \
$$TESTDIR/testSuite.cc \
$$TESTDIR/UASUnitTest.cc \
src/uas/QGCMAVLinkUASFactory.cc
HEADERS += src/uas/UASInterface.h \
src/uas/UAS.h \
src/comm/MAVLinkProtocol.h \
src/comm/ProtocolInterface.h \
src/uas/UASWaypointManager.h \
src/Waypoint.h \
src/ui/RadioCalibration/RadioCalibrationData.h \
src/uas/SlugsMAV.h \
src/uas/PxQuadMAV.h \
src/uas/ArduPilotMegaMAV.h \
src/GAudioOutput.h \
src/uas/UASManager.h \
src/comm/LinkManager.h \
src/comm/LinkInterface.h \
src/QGC.h \
src/comm/SerialLinkInterface.h \
src/comm/SerialLink.h \
$$TESTDIR//SlugsMavUnitTest.h \
$$TESTDIR/AutoTest.h \
$$TESTDIR/UASUnitTest.h \
src/uas/QGCMAVLinkUASFactory.h
DEFINES += SRCDIR=\\\"$$PWD/\\\"
/**
* @author Rob Caldecott
* @note This was obtained from http://qtcreator.blogspot.com/2010/04/sample-multiple-unit-test-project.html
*
*/
#ifndef AUTOTEST_H
#define AUTOTEST_H
#include <QTest>
#include <QList>
#include <QString>
#include <QSharedPointer>
namespace AutoTest
{
typedef QList<QObject*> TestList;
inline TestList& testList()
{
static TestList list;
return list;
}
inline bool findObject(QObject* object)
{
TestList& list = testList();
if (list.contains(object))
{
return true;
}
foreach (QObject* test, list)
{
if (test->objectName() == object->objectName())
{
return true;
}
}
return false;
}
inline void addTest(QObject* object)
{
TestList& list = testList();
if (!findObject(object))
{
list.append(object);
}
}
inline int run(int argc, char *argv[])
{
int ret = 0;
foreach (QObject* test, testList())
{
ret += QTest::qExec(test, argc, argv);
}
return ret;
}
}
template <class T>
class Test
{
public:
QSharedPointer<T> child;
Test(const QString& name) : child(new T)
{
child->setObjectName(name);
AutoTest::addTest(child.data());
}
};
#define DECLARE_TEST(className) static Test<className> t(#className);
#define TEST_MAIN \
int main(int argc, char *argv[]) \
{ \
return AutoTest::run(argc, argv); \
}
#endif // AUTOTEST_H
#include "SlugsMavUnitTest.h"
SlugsMavUnitTest::SlugsMavUnitTest()
{
}
void SlugsMavUnitTest::initTestCase()
{
}
void SlugsMavUnitTest::cleanupTestCase()
{
}
void SlugsMavUnitTest::first_test()
{
QCOMPARE(1,2);
}
#ifndef SLUGSMAVUNITTEST_H
#define SLUGSMAVUNITTEST_H
#include <QObject>
#include <QtCore/QString>
#include <QtTest/QtTest>
#include "UAS.h"
#include "MAVLinkProtocol.h"
#include "UASInterface.h"
#include "AutoTest.h"
class SlugsMavUnitTest : public QObject
{
Q_OBJECT
public:
SlugsMavUnitTest();
signals:
private slots:
void initTestCase();
void cleanupTestCase();
void first_test();
};
DECLARE_TEST(SlugsMavUnitTest)
#endif // SLUGSMAVUNITTEST_H
#include "UASUnitTest.h"
UASUnitTest::UASUnitTest()
{
}
void UASUnitTest::initTestCase()
{
mav= new MAVLinkProtocol();
link = new SerialLink();
uas=new UAS(mav,UASID);
}
void UASUnitTest::cleanupTestCase()
{
delete uas;
delete mav;
}
void UASUnitTest::getUASID_test()
{
// Test a default ID of zero is assigned
UAS* uas2 = new UAS(mav);
QCOMPARE(uas2->getUASID(), 0);
delete uas2;
// Test that the chosen ID was assigned at construction
QCOMPARE(uas->getUASID(), UASID);
// Make sure that no other ID was sert
QEXPECT_FAIL("", "When you set an ID it does not use the default ID of 0", Continue);
QCOMPARE(uas->getUASID(), 0);
}
void UASUnitTest::getUASName_test()
{
// Test that the name is build as MAV + ID
QCOMPARE(uas->getUASName(), "MAV 0" + QString::number(UASID));
}
void UASUnitTest::getUpTime_test()
{
UAS* uas2 = new UAS(mav);
// Test that the uptime starts at zero to a
// precision of seconds
QCOMPARE(floor(uas2->getUptime()/1000.0), 0.0);
// Sleep for three seconds
QTest::qSleep(3000);
// Test that the up time is computed correctly to a
// precision of seconds
QCOMPARE(floor(uas2->getUptime()/1000.0), 3.0);
delete uas2;
}
void UASUnitTest::getCommunicationStatus_test()
{
// Verify that upon construction the Comm status is disconnected
QCOMPARE(uas->getCommunicationStatus(), static_cast<int>(UASInterface::COMM_DISCONNECTED));
}
void UASUnitTest::filterVoltage_test()
{
float verificar=uas->filterVoltage(0.4f);
// Verify that upon construction the Comm status is disconnected
QCOMPARE(verificar, 8.52f);
}
void UASUnitTest:: getAutopilotType_test()
{
int type = uas->getAutopilotType();
// Verify that upon construction the autopilot is set to -1
QCOMPARE(type, -1);
}
void UASUnitTest::setAutopilotType_test()
{
uas->setAutopilotType(2);
// Verify that the autopilot is set
QCOMPARE(uas->getAutopilotType(), 2);
}
void UASUnitTest::getStatusForCode_test()
{
QString state, desc;
state = "";
desc = "";
uas->getStatusForCode(MAV_STATE_UNINIT, state, desc);
QVERIFY(state == "UNINIT");
uas->getStatusForCode(MAV_STATE_UNINIT, state, desc);
QVERIFY(state == "UNINIT");
uas->getStatusForCode(MAV_STATE_BOOT, state, desc);
QVERIFY(state == "BOOT");
uas->getStatusForCode(MAV_STATE_CALIBRATING, state, desc);
QVERIFY(state == "CALIBRATING");
uas->getStatusForCode(MAV_STATE_ACTIVE, state, desc);
QVERIFY(state == "ACTIVE");
uas->getStatusForCode(MAV_STATE_STANDBY, state, desc);
QVERIFY(state == "STANDBY");
uas->getStatusForCode(MAV_STATE_CRITICAL, state, desc);
QVERIFY(state == "CRITICAL");
uas->getStatusForCode(MAV_STATE_EMERGENCY, state, desc);
QVERIFY(state == "EMERGENCY");
uas->getStatusForCode(MAV_STATE_POWEROFF, state, desc);
QVERIFY(state == "SHUTDOWN");
uas->getStatusForCode(5325, state, desc);
QVERIFY(state == "UNKNOWN");
}
void UASUnitTest::getLocalX_test()
{
QCOMPARE(uas->getLocalX(), 0.0);
}
void UASUnitTest::getLocalY_test()
{
QCOMPARE(uas->getLocalY(), 0.0);
}
void UASUnitTest::getLocalZ_test()
{
QCOMPARE(uas->getLocalZ(), 0.0);
}
void UASUnitTest::getLatitude_test()
{ QCOMPARE(uas->getLatitude(), 0.0);
}
void UASUnitTest::getLongitude_test()
{
QCOMPARE(uas->getLongitude(), 0.0);
}
void UASUnitTest::getAltitude_test()
{
QCOMPARE(uas->getAltitude(), 0.0);
}
void UASUnitTest::getRoll_test()
{
QCOMPARE(uas->getRoll(), 0.0);
}
void UASUnitTest::getPitch_test()
{
QCOMPARE(uas->getPitch(), 0.0);
}
void UASUnitTest::getYaw_test()
{
QCOMPARE(uas->getYaw(), 0.0);
}
void UASUnitTest::attitudeLimitsZero_test()
{
mavlink_message_t msg;
mavlink_attitude_t att;
// Set zero values and encode them
att.roll = 0.0f;
att.pitch = 0.0f;
att.yaw = 0.0f;
mavlink_msg_attitude_encode(uas->getUASID(), MAV_COMP_ID_IMU, &msg, &att);
// Let UAS decode message
uas->receiveMessage(link, msg);
// Check result
QCOMPARE(uas->getRoll(), 0.0);
QCOMPARE(uas->getPitch(), 0.0);
QCOMPARE(uas->getYaw(), 0.0);
}
void UASUnitTest::attitudeLimitsPi_test()
{
mavlink_message_t msg;
mavlink_attitude_t att;
// Set PI values and encode them
att.roll = M_PI;
att.pitch = M_PI;
att.yaw = M_PI;
mavlink_msg_attitude_encode(uas->getUASID(), MAV_COMP_ID_IMU, &msg, &att);
// Let UAS decode message
uas->receiveMessage(link, msg);
// Check result
QVERIFY((uas->getRoll() < M_PI+0.000001) && (uas->getRoll() > M_PI+-0.000001));
QVERIFY((uas->getPitch() < M_PI+0.000001) && (uas->getPitch() > M_PI+-0.000001));
QVERIFY((uas->getYaw() < M_PI+0.000001) && (uas->getYaw() > M_PI+-0.000001));
}
void UASUnitTest::attitudeLimitsMinusPi_test()
{
mavlink_message_t msg;
mavlink_attitude_t att;
// Set -PI values and encode them
att.roll = -M_PI;
att.pitch = -M_PI;
att.yaw = -M_PI;
mavlink_msg_attitude_encode(uas->getUASID(), MAV_COMP_ID_IMU, &msg, &att);
// Let UAS decode message
uas->receiveMessage(link, msg);
// Check result
QVERIFY((uas->getRoll() > -M_PI-0.000001) && (uas->getRoll() < -M_PI+0.000001));
QVERIFY((uas->getPitch() > -M_PI-0.000001) && (uas->getPitch() < -M_PI+0.000001));
QVERIFY((uas->getYaw() > -M_PI-0.000001) && (uas->getYaw() < -M_PI+0.000001));
}
void UASUnitTest::attitudeLimitsTwoPi_test()
{
mavlink_message_t msg;
mavlink_attitude_t att;
// Set off-limit values and check
// correct wrapping
// Set 2PI values and encode them
att.roll = 2*M_PI;
att.pitch = 2*M_PI;
att.yaw = 2*M_PI;
mavlink_msg_attitude_encode(uas->getUASID(), MAV_COMP_ID_IMU, &msg, &att);
// Let UAS decode message
uas->receiveMessage(link, msg);
// Check result
QVERIFY((uas->getRoll() < 0.000001) && (uas->getRoll() > -0.000001));
QVERIFY((uas->getPitch() < 0.000001) && (uas->getPitch() > -0.000001));
QVERIFY((uas->getYaw() < 0.000001) && (uas->getYaw() > -0.000001));
}
void UASUnitTest::attitudeLimitsMinusTwoPi_test()
{
mavlink_message_t msg;
mavlink_attitude_t att;
// Set -2PI values and encode them
att.roll = -2*M_PI;
att.pitch = -2*M_PI;
att.yaw = -2*M_PI;
mavlink_msg_attitude_encode(uas->getUASID(), MAV_COMP_ID_IMU, &msg, &att);
// Let UAS decode message
uas->receiveMessage(link, msg);
// Check result
QVERIFY((uas->getRoll() < 0.000001) && (uas->getRoll() > -0.000001));
QVERIFY((uas->getPitch() < 0.000001) && (uas->getPitch() > -0.000001));
QVERIFY((uas->getYaw() < 0.000001) && (uas->getYaw() > -0.000001));
}
void UASUnitTest::attitudeLimitsTwoPiOne_test()
{
mavlink_message_t msg;
mavlink_attitude_t att;
// Set over 2 PI values and encode them
att.roll = 2*M_PI+1.0f;
att.pitch = 2*M_PI+1.0f;
att.yaw = 2*M_PI+1.0f;
mavlink_msg_attitude_encode(uas->getUASID(), MAV_COMP_ID_IMU, &msg, &att);
// Let UAS decode message
uas->receiveMessage(link, msg);
// Check result
QVERIFY((uas->getRoll() < 1.000001) && (uas->getRoll() > 0.999999));
QVERIFY((uas->getPitch() < 1.000001) && (uas->getPitch() > 0.999999));
QVERIFY((uas->getYaw() < 1.000001) && (uas->getYaw() > 0.999999));
}
void UASUnitTest::attitudeLimitsMinusTwoPiOne_test()
{
mavlink_message_t msg;
mavlink_attitude_t att;
// Set 3PI values and encode them
att.roll = -2*M_PI-1.0f;
att.pitch = -2*M_PI-1.0f;
att.yaw = -2*M_PI-1.0f;
mavlink_msg_attitude_encode(uas->getUASID(), MAV_COMP_ID_IMU, &msg, &att);
// Let UAS decode message
uas->receiveMessage(link, msg);
// Check result
QVERIFY((uas->getRoll() > -1.000001) && (uas->getRoll() < -0.999999));
QVERIFY((uas->getPitch() > -1.000001) && (uas->getPitch() < -0.999999));
QVERIFY((uas->getYaw() > -1.000001) && (uas->getYaw() < -0.999999));
}
#ifndef UASUNITTEST_H
#define UASUNITTEST_H
#include <QObject>
#include <QtCore/QString>
#include <QtTest/QtTest>
#include "UAS.h"
#include "MAVLinkProtocol.h"
#include "SerialLink.h"
#include "UASInterface.h"
#include "AutoTest.h"
class UASUnitTest : public QObject
{
Q_OBJECT
public:
#define UASID 50
MAVLinkProtocol* mav;
UAS* uas;
SerialLink* link;
UASUnitTest();
signals:
private slots:
void initTestCase();
void cleanupTestCase();
void getUASID_test();
void getUASName_test();
void getUpTime_test();
void getCommunicationStatus_test();
void filterVoltage_test();
void getAutopilotType_test();
void setAutopilotType_test();
void getStatusForCode_test();
void getLocalX_test();
void getLocalY_test();
void getLocalZ_test();
void getLatitude_test();
void getLongitude_test();
void getAltitude_test();
void getRoll_test();
void getPitch_test();
void getYaw_test();
void attitudeLimitsZero_test();
void attitudeLimitsPi_test();
void attitudeLimitsMinusPi_test();
void attitudeLimitsTwoPi_test();
void attitudeLimitsMinusTwoPi_test();
void attitudeLimitsTwoPiOne_test();
void attitudeLimitsMinusTwoPiOne_test();
protected:
UAS *prueba;
};
DECLARE_TEST(UASUnitTest)
#endif // UASUNITTEST_H
/**
* @author Rob Caldecott
* @note This was obtained from http://qtcreator.blogspot.com/2010/04/sample-multiple-unit-test-project.html
*
*/
#include "AutoTest.h"
#include <QDebug>
#if 1
// This is all you need to run all the tests
TEST_MAIN
#else
// Or supply your own main function
int main(int argc, char *argv[])
{
int failures = AutoTest::run(argc, argv);
if (failures == 0)
{
qDebug() << "ALL TESTS PASSED";
}
else
{
qDebug() << failures << " TESTS FAILED!";
}
return failures;
}
#endif
This diff is collapsed.
# -------------------------------------------------
# QGroundControl - Micro Air Vehicle Groundstation
# Please see our website at <http://qgroundcontrol.org>
# Author:
# Lorenz Meier <mavteam@student.ethz.ch>
# (c) 2009-2010 PIXHAWK Team
# This file is part of the mav groundstation project
# QGroundControl is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# QGroundControl is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with QGroundControl. If not, see <http://www.gnu.org/licenses/>.
# -------------------------------------------------
# Include QMapControl map library
# prefer version from external directory /
# from http://github.com/pixhawk/qmapcontrol/
# over bundled version in lib directory
# Version from GIT repository is preferred
# include ( "../qmapcontrol/QMapControl/QMapControl.pri" ) #{
# Include bundled version if necessary
CONFIG += designer plugin
TARGET = $$qtLibraryTarget($$TARGET)
TEMPLATE = lib
QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/designer
FORMS = src/ui/designer/QGCParamSlider.ui
HEADERS = src/ui/designer/QGCParamSlider.h \
src/ui/designer/QGCParamSliderPlugin.h
SOURCES = src/ui/designer/QGCParamSlider.cc \
src/ui/designer/QGCParamSliderPlugin.cc
# install
target.path = $$[QT_INSTALL_PLUGINS]/designer
sources.files = $$SOURCES $$HEADERS *.pro
sources.path = $$[QT_INSTALL_EXAMPLES]/designer/worldtimeclockplugin
INSTALLS += target
symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
This diff is collapsed.
This diff is collapsed.
......@@ -189,6 +189,15 @@ Core::Core(int &argc, char* argv[]) : QApplication(argc, argv)
QTimer::singleShot(200, mainWindow, SLOT(close()));
}
}
// forever
// {
// QGC::SLEEP::msleep(5000);
// }
// mainWindow->close();
// mainWindow->deleteLater();
// QGC::SLEEP::msleep(200);
}
/**
......
......@@ -153,7 +153,7 @@ void GAudioOutput::mute(bool mute)
{
this->muted = mute;
QSettings settings;
settings.setValue(QGC_GAUDIOOUTPUT_KEY+"muted", muted);
settings.setValue(QGC_GAUDIOOUTPUT_KEY+"muted", this->muted);
settings.sync();
}
......
......@@ -41,7 +41,7 @@ This file is part of the PIXHAWK project
namespace MG
{
const static int MAX_FLIGHT_TIME = 60 * 60 * 24 * 365 * 2;
const static int MAX_FLIGHT_TIME = 60 * 60 * 24 * 21;
class VERSION
{
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment