//-------------------------------------------------------------------------------
// <copyright file="GPSSampleEvent.h" company="LiquidRobotics">
//
// Copyright (c) 2014 Liquid Robotics, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// This software is associated with a release.  Liquid Robotics makes no
// representation that the design, interfaces or component distribution will
// remain unchanged in future releases.
//
// </copyright>
//
// <summary>
//   Declaration of the GPSSampleEvent class, which models a GPS sample and which
//   can be used with the EventLib classes to forward events to subscribers.
// </summary>
//
// <owner>Mike Cookson</owner>
//-------------------------------------------------------------------------------

#ifndef __EVENTLIB_GPSSAMPLEEVENT_H__
#define __EVENTLIB_GPSSAMPLEEVENT_H__

#include "TelemetryEventBase.h"
#include "LqrSMACSharedLib.h"
#include <string>
#include <vector>
#include <sys/time.h>

namespace LiquidRobotics {
namespace EventLib {

class SHARED_LIB_PUBLIC GPSSampleEvent : public TelemetryEventBase
{
public:

	typedef TelemetryEventBase Base;
	typedef ::LiquidRobotics::EventLib::EventName EventName;
	typedef ::LiquidRobotics::EventLib::EventType EventType;
	typedef ::LiquidRobotics::EventLib::IOR IOR;
	typedef boost::shared_ptr<GPSSampleEvent> Ptr;
	typedef std::string string;
	typedef std::vector<string> StringArray;

	GPSSampleEvent(IObjectBroker& _broker);
	GPSSampleEvent(const EventSettings& _eventSettings, IObjectBroker& _broker);
	GPSSampleEvent(const EventName& _eventName, const EventType& _eventType, IObjectBroker& _broker);
	GPSSampleEvent(const EventName& _eventName, const EventType& _eventType, const IOR& _senderIOR, IObjectBroker& _broker);
	GPSSampleEvent(const GPSSampleEvent& other);

	virtual ostream& Describe(ostream& stm) const;
	virtual IEventBase::Ptr Duplicate() const;

	void ClearTime();
	timeval GetTime() const;					// timeval's time_t should always be relative to local time
	bool GetTime(timeval& outval) const;
	bool HasTime() const;
	void SetTime(const timeval& newValue);		// timeval's time_t should always be relative to local time

	void ClearGPS();
	void GetGPS(double& latitude, double& longitude) const;
	double GetLatitude() const;
	double GetLongitude() const;
	unsigned GetNumSatellites() const;
	bool HasGPS() const; // i.e. has position data
	void SetGPS(double latitude, double longitude, unsigned numSatellites);

	void ClearCourse();
	void GetCourse(double& degreesTrue, double& degreesMagnetic, double& speedKnots, double& speedKmh) const;
	bool HasCourse() const;
	void SetCourse(double degreesTrue, double degreesMagnetic, double speedKnots, double speedKmh);

	void ClearRMSAccuracy();
	double GetRMSAccuracy() const;
	bool GetRMSAccuracy(double& outval) const;
	bool HasRMSAccuracy() const;
	void SetRMSAccuracy(const double& newValue);

	void ClearElevation();
	double GetElevation() const;
	bool GetElevation(double& outval) const;
	bool HasElevation() const;
	void SetElevation(const double& newValue);

	void ClearMagneticDeclination();
	double GetMagneticDeclination() const;
	bool GetMagneticDeclination(double& outval) const;
	bool HasMagneticDeclination() const;
	void SetMagneticDeclination(const double& newValue);

	void ClearSentences();
	bool HasSentences() const;
	void GetSentences(StringArray& sentences) const;
	void SetSentences(const StringArray& sentences);

	bool GetSimulated() const;
	void SetSimulated(bool newValue);

	string GetSourceName() const;
	void SetSourceName(const string& sourceName);

private:

	static const PropertyNameType timeTagSeconds;
	static const PropertyNameType timeTagMicroseconds;
	static const PropertyNameType latitudeTag;
	static const PropertyNameType longitudeTag;
	static const PropertyNameType numSatellitesTag;
	static const PropertyNameType elevationTag;
	static const PropertyNameType degreesTrueTag;
	static const PropertyNameType degreesMagneticTag;
	static const PropertyNameType speedKnotsTag;
	static const PropertyNameType speedKmhTag;
	static const PropertyNameType sentencesTag;
	static const PropertyNameType rmsAccuracyTag;
	static const PropertyNameType magneticDeclinationTag;
	static const PropertyNameType simulatedTag;
	static const PropertyNameType sourceNameTag;
};

}
}

#endif
