//--------------------------------------------------------------------------------
// <copyright file="AlarmSubsystem.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 AlarmSubsystem, which factors out the alarm reporting and
//  status methods for PayloadInterfaceController and SV3RemoteController
// </summary>
//
// <owner>Mike Cookson</owner>
//--------------------------------------------------------------------------------

#ifndef ALARMSUBSYSTEM_H_
#define ALARMSUBSYSTEM_H_

#include <string>
#include "EventTransceiver.h"
#include "LqrSMACScopedConnection.h"
#include "PayloadManagerClient.h"
#include "PayloadInterfaceController_Config.h"

namespace LiquidRobotics {
namespace PayloadInterface {

class PayloadInterfaceController_Config;

class SHARED_LIB_PUBLIC AlarmSubsystem
{
public:


	AlarmSubsystem(
			LiquidRobotics::EventLib::EventTransceiver& _evtTrans,
			LiquidRobotics::SMACFramework::Logger& _logger,
			const PayloadInterfaceController_Config& _config,
			LiquidRobotics::SMACFramework::IObjectBroker& _broker,
			LiquidRobotics::EventLib::PayloadManagerClient& _pmClient);

	void Initialize();
	void Shutdown();
	void SavePosition(double _lat, double _lon);

protected:

	void FormatLevel1(uint16_t senderAddress,
		uint32_t reportTypeID, uint8_t alarmType, uint32_t enumerationType, uint32_t notificationID,
		const std::string& freeText, const LiquidRobotics::SMACFramework::ByteArray& freeData,
		LiquidRobotics::SMACFramework::ByteArray& level1SysInfo);
	void FormatLevel1(uint16_t senderAddress, const timeval& timestamp, double latitude, double longitude,
		uint32_t reportTypeID, uint8_t alarmType, uint32_t enumerationType, uint32_t notificationID,
		const std::string& freeText, const LiquidRobotics::SMACFramework::ByteArray& freeData,
		LiquidRobotics::SMACFramework::ByteArray& level1SysInfo);
	void HandleAlarmReport(LiquidRobotics::EventLib::EventTransceiver& sender, const LiquidRobotics::EventLib::IEventBase& receivedEvent);
	virtual void ReportAlarm(uint16_t senderAddress, const LiquidRobotics::SMACFramework::ByteArray& level1SysInfo) = 0;

private:

	LiquidRobotics::EventLib::EventTransceiver& evtTrans;
	LiquidRobotics::SMACFramework::Logger& logger;
	const PayloadInterfaceController_Config& config;
	LiquidRobotics::SMACFramework::IObjectBroker& broker;
	LiquidRobotics::EventLib::PayloadManagerClient& pmClient;
	LiquidRobotics::SMACFramework::ScopedConnectionPtr connectionToAlarmReport;
	double lat;
	double lon;
};

}
}

#endif /* TELEMETRYSUBSYSTEM_H_ */
