//--------------------------------------------------------------------------------
// <copyright file="SSQCommunicatorSettings.cpp" 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>
// Implementation of the SSQCommunicatorSettings class, a serializable entity that
// contains the settings for SSQCommunicator.
// </summary>
//
// <owner>Mike Cookson</owner>
//--------------------------------------------------------------------------------

#include "SSQCommunicatorSettings.h"
#include "LqrSMACLoadSaveBoostXml.h"

using namespace std;
using namespace LiquidRobotics::SMACFramework;

namespace LiquidRobotics {
namespace SimpleSBDQueue {

const unsigned OneSecond = 1000;
const unsigned OneMinute = 60*OneSecond;

SSQCommunicatorSettings::SSQCommunicatorSettings()
: minOffTimeMS(OneMinute/2)
, maxOnTimeMS(0)
, dutyCycleModem(true)
, networkAvailableTimeoutMS(OneMinute)
, mailboxCheckIntervalMS(5*OneMinute)
, networkFailDelayMS(8*OneMinute)
, commFailureDelayMS(15*OneMinute)
, useRingIndicator(false)
, powerOnVerb("sudo SetPowerSwitch 4 1")
, powerOffVerb("sudo SetPowerSwitch 4 0")
, modemOnDelayMS(25*OneSecond)
, waitForNetworkRegistration(true)
{
}

SSQCommunicatorSettings::SSQCommunicatorSettings(const SSQCommunicatorSettings& orig)
: sbdModemSettings(orig.GetSBDModemSettings())
, minOffTimeMS(orig.GetMinOffTimeMS())
, maxOnTimeMS(orig.GetMaxOnTimeMS())
, dutyCycleModem(orig.GetDutyCycleModem())
, networkAvailableTimeoutMS(orig.GetNetworkAvailableTimeoutMS())
, mailboxCheckIntervalMS(orig.GetMailboxCheckIntervalMS())
, networkFailDelayMS(orig.GetNetworkFailDelayMS())
, commFailureDelayMS(orig.GetCommFailureDelayMS())
, useRingIndicator(orig.GetUseRingIndicator())
, powerOnVerb(orig.GetPowerOnVerb())
, powerOffVerb(orig.GetPowerOffVerb())
, modemOnDelayMS(orig.GetModemPowerOnDelayMS())
, waitForNetworkRegistration(orig.GetWaitForNetworkRegistration())
{
}

SSQCommunicatorSettings::~SSQCommunicatorSettings()
{
}

const SSQCommunicatorSettings::SBDModemSettings& SSQCommunicatorSettings::GetSBDModemSettings() const
{
    return sbdModemSettings;
}

void SSQCommunicatorSettings::SetSBDModemSettings(const SBDModemSettings& newValue)
{
    sbdModemSettings = newValue;
}

unsigned SSQCommunicatorSettings::GetMinOffTimeMS() const
{
    return minOffTimeMS;
}

void SSQCommunicatorSettings::SetMinOffTimeMS(unsigned newValue)
{
    minOffTimeMS = newValue;
}

unsigned SSQCommunicatorSettings::GetMaxOnTimeMS() const
{
    return maxOnTimeMS;
}

void SSQCommunicatorSettings::SetMaxOnTimeMS(unsigned newValue)
{
    maxOnTimeMS = newValue;
}

bool SSQCommunicatorSettings::GetDutyCycleModem() const
{
    return dutyCycleModem;
}

void SSQCommunicatorSettings::SetDutyCycleModem(bool newValue)
{
    dutyCycleModem = newValue;
}

unsigned SSQCommunicatorSettings::GetNetworkAvailableTimeoutMS() const
{
    return networkAvailableTimeoutMS;
}

void SSQCommunicatorSettings::SetNetworkAvailableTimeoutMS(unsigned newValue)
{
    networkAvailableTimeoutMS = newValue;
}

unsigned SSQCommunicatorSettings::GetMailboxCheckIntervalMS() const
{
    return mailboxCheckIntervalMS;
}

void SSQCommunicatorSettings::SetMailboxCheckIntervalMS(unsigned newValue)
{
    mailboxCheckIntervalMS = newValue;
}

unsigned SSQCommunicatorSettings::GetNetworkFailDelayMS() const
{
    return networkFailDelayMS;
}

void SSQCommunicatorSettings::SetNetworkFailDelayMS(unsigned newValue)
{
    networkFailDelayMS = newValue;
}

unsigned SSQCommunicatorSettings::GetCommFailureDelayMS() const
{
    return commFailureDelayMS;
}

void SSQCommunicatorSettings::SetCommFailureDelayMS(unsigned newValue)
{
    commFailureDelayMS = newValue;
}

bool SSQCommunicatorSettings::GetUseRingIndicator() const
{
    return useRingIndicator;
}

void SSQCommunicatorSettings::SetUseRingIndicator(bool newValue)
{
    useRingIndicator = newValue;
}

string SSQCommunicatorSettings::GetPowerOnVerb() const
{
    string temp = powerOnVerb;
    return temp;
}

void SSQCommunicatorSettings::SetPowerOnVerb(const string& newValue)
{
    powerOnVerb = newValue;
}

string SSQCommunicatorSettings::GetPowerOffVerb() const
{
    string temp = powerOffVerb;
    return temp;
}

void SSQCommunicatorSettings::SetPowerOffVerb(const string& newValue)
{
    powerOffVerb = newValue;
}

bool SSQCommunicatorSettings::GetWaitForNetworkRegistration() const
{
	return waitForNetworkRegistration;
}

void SSQCommunicatorSettings::SetWaitForNetworkRegistration(bool newValue)
{
	waitForNetworkRegistration = newValue;
}

unsigned SSQCommunicatorSettings::GetModemPowerOnDelayMS() const
{
	return modemOnDelayMS;
}

void SSQCommunicatorSettings::SetModemPowerOnDelayMS(unsigned newValue)
{
	modemOnDelayMS = newValue;
}

unsigned SSQCommunicatorSettings::GetNetworkTimeoutSeconds() const
{
    return networkTimeoutSeconds;
}

void SSQCommunicatorSettings::SetNetworkTimeoutSeconds(unsigned newValue)
{
    networkTimeoutSeconds = newValue;
}

void SSQCommunicatorSettings::Load(const string& fileName)
{
    LoadBoostXml(fileName, *this);
}

void SSQCommunicatorSettings::Save(const string& fileName)
{
    SaveBoostXml(fileName, *this);
}

}
}
