/*********************************************************************
 *
 *  $Id: YGps.cpp 53689 2023-03-22 11:17:15Z mvuilleu $
 *
 *  Implements commands to handle Gps functions
 *
 *  - - - - - - - - - License information: - - - - - - - - -
 *
 *  Copyright (C) 2011 and beyond by Yoctopuce Sarl, Switzerland.
 *
 *  Yoctopuce Sarl (hereafter Licensor) grants to you a perpetual
 *  non-exclusive license to use, modify, copy and integrate this
 *  file into your software for the sole purpose of interfacing
 *  with Yoctopuce products.
 *
 *  You may reproduce and distribute copies of this file in
 *  source or object form, as long as the sole purpose of this
 *  code is to interface with Yoctopuce products. You must retain
 *  this notice in the distributed source file.
 *
 *  You should refer to Yoctopuce General Terms and Conditions
 *  for additional information regarding your rights and
 *  obligations.
 *
 *  THE SOFTWARE AND DOCUMENTATION ARE PROVIDED 'AS IS' WITHOUT
 *  WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
 *  WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS
 *  FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO
 *  EVENT SHALL LICENSOR BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
 *  INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
 *  COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR
 *  SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT
 *  LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR
 *  CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON THE
 *  BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF
 *  WARRANTY, OR OTHERWISE.
 *
 *********************************************************************/


#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include "YGps.h"
#include "yocto_api.h"
#include "yocto_gps.h"

using namespace std;

//--- (YGps definitions)

static const char *enumBool[] = {
    "FALSE",
    "TRUE",
    NULL
};

static const char *enumGPSCoordinateSystem[] = {
    "GPS_DMS",
    "GPS_DM",
    "GPS_D",
    NULL
};

static const char *enumGPSConstellation[] = {
    "GNSS",
    "GPS",
    "GLONASS",
    "GALILEO",
    "GPS_GLONASS",
    "GPS_GALILEO",
    "GLONASS_GALILEO",
    NULL
};

//--- (end of YGps definitions)


//--- (YGps implementation)
bool   YGpsCmdLine::isModule(void)      { return false; }
string YGpsCmdLine::YFunctionName(void) { return "YGps"; }

// type of logicalName is string (Text)
// type of advertisedValue is string (PubText)
// type of isFixed is int (Bool)
// type of satCount is s64 (UInt)
// type of satPerConst is s64 (UInt)
// type of gpsRefreshRate is double (MeasureVal)
// type of coordSystem is int (GPSCoordinateSystem)
// type of constellation is int (GPSConstellation)
// type of latitude is string (Text)
// type of longitude is string (Text)
// type of dilution is double (MeasureVal)
// type of altitude is double (MeasureVal)
// type of groundSpeed is double (MeasureVal)
// type of direction is double (MeasureVal)
// type of unixTime is s64 (UTCTime)
// type of dateTime is string (Text)
// type of utcOffset is int (Int)
// type of command is string (Text)
/**
 * Returns the logical name of the geolocalization module.
 *
 * @return a string corresponding to the logical name of the geolocalization module
 *
 * On failure, throws an exception or returns YGps.LOGICALNAME_INVALID.
 */
class Gps_get_logicalName : public YapiCommand /* arguments: */
{
public:
  Gps_get_logicalName(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_logicalName";
  }

  string getDescription()
  {
    return "Returns the logical name of the geolocalization module.";
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches )
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        string attrval = (*list)[i]->get_logicalName();
        string strval =  attrval;
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), strval, true);
      }
  }
};

/**
 * Changes the logical name of the geolocalization module. You can use yCheckLogicalName()
 * prior to this call to make sure that your parameter is valid.
 * Remember to call the saveToFlash() method of the module if the
 * modification must be kept.
 *
 * @param newval : a string corresponding to the logical name of the geolocalization module
 *
 * @return YAPI.SUCCESS if the call succeeds.
 *
 * On failure, throws an exception or returns a negative error code.
 */
class Gps_set_logicalName : public YapiCommand /* arguments: newval */
{
public:
  Gps_set_logicalName(YFunctionCmdLine *function):YapiCommand(function){}
  string getName()
  {
    return "set_logicalName";
  }

  string getDescription()
  {
    return "Changes the logical name of the geolocalization module.";
  }

  string getMoreInfo()
  {
    return "You can use yCheckLogicalName() prior to this call to make sure that your parameter is valid. Remember to call \"YModule {target} saveToFlash\" if the modification must be kept.";
  }

  vector<ArgumentDesc*>* getArgumentDesc()
  {
    vector<ArgumentDesc*>* res = new vector<ArgumentDesc*>();
    res->push_back(new ArgumentDesc(STRING_ARG, "newval", "a string corresponding to the logical name of the geolocalization module", "_LOGICAL", false));
    return res;
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches)
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    string value = (*args)[0]->to_str();
    if (!YAPI::CheckLogicalName((*args)[0]->get_stringValue())) {
        throw std::string("Invalid name :" + (*args)[0]->get_stringValue());
    }
    for (i = 0; i < list->size(); i++) {
        (*list)[i]->set_logicalName(string((*args)[0]->get_stringValue()));
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), value, true);
    }
  }
};

/**
 * Returns a short string representing the current state of the geolocalization module.
 *
 * @return a string corresponding to a short string representing the current state of the geolocalization module
 *
 * On failure, throws an exception or returns YGps.ADVERTISEDVALUE_INVALID.
 */
class Gps_get_advertisedValue : public YapiCommand /* arguments: */
{
public:
  Gps_get_advertisedValue(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_advertisedValue";
  }

  string getDescription()
  {
    return "Returns a short string representing the current state of the geolocalization module.";
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches )
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        string attrval = (*list)[i]->get_advertisedValue();
        string strval =  attrval;
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), strval, true);
      }
  }
};

/**
 * Returns TRUE if the receiver has found enough satellites to work.
 *
 * @return either YGps.ISFIXED_FALSE or YGps.ISFIXED_TRUE, according to TRUE if the receiver has found
 * enough satellites to work
 *
 * On failure, throws an exception or returns YGps.ISFIXED_INVALID.
 */
class Gps_get_isFixed : public YapiCommand /* arguments: */
{
public:
  Gps_get_isFixed(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_isFixed";
  }

  string getDescription()
  {
    return "Returns TRUE if the receiver has found enough satellites to work.";
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches )
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        int attrval = (*list)[i]->get_isFixed();
        string strval =  enumString(attrval,enumBool);
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), strval, true);
      }
  }
};

/**
 * Returns the total count of satellites used to compute GPS position.
 *
 * @return an integer corresponding to the total count of satellites used to compute GPS position
 *
 * On failure, throws an exception or returns YGps.SATCOUNT_INVALID.
 */
class Gps_get_satCount : public YapiCommand /* arguments: */
{
public:
  Gps_get_satCount(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_satCount";
  }

  string getDescription()
  {
    return "Returns the total count of satellites used to compute GPS position.";
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches )
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        s64 attrval = (*list)[i]->get_satCount();
        char buf[32]; SAFE_SPRINTF(buf, 32, "%u", (u32)attrval); string strval =  string(buf);
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), strval, true);
      }
  }
};

/**
 * Returns the count of visible satellites per constellation encoded
 * on a 32 bit integer: bits 0..5: GPS satellites count,  bits 6..11 : Glonass, bits 12..17 : Galileo.
 * this value is refreshed every 5 seconds only.
 *
 * @return an integer corresponding to the count of visible satellites per constellation encoded
 *         on a 32 bit integer: bits 0.
 *
 * On failure, throws an exception or returns YGps.SATPERCONST_INVALID.
 */
class Gps_get_satPerConst : public YapiCommand /* arguments: */
{
public:
  Gps_get_satPerConst(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_satPerConst";
  }

  string getDescription()
  {
    return "Returns the count of visible satellites per constellation encodedon a 32 bit integer: bits 0.";
  }

  string getMoreInfo()
  {
    return ".5: GPS satellites count, bits 6..11 : Glonass, bits 12..17 : Galileo. this value is refreshed every 5 seconds only.";
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches )
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        s64 attrval = (*list)[i]->get_satPerConst();
        char buf[32]; SAFE_SPRINTF(buf, 32, "%u", (u32)attrval); string strval =  string(buf);
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), strval, true);
      }
  }
};

/**
 * Returns effective GPS data refresh frequency.
 * this value is refreshed every 5 seconds only.
 *
 * @return a floating point number corresponding to effective GPS data refresh frequency
 *
 * On failure, throws an exception or returns YGps.GPSREFRESHRATE_INVALID.
 */
class Gps_get_gpsRefreshRate : public YapiCommand /* arguments: */
{
public:
  Gps_get_gpsRefreshRate(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_gpsRefreshRate";
  }

  string getDescription()
  {
    return "Returns effective GPS data refresh frequency.";
  }

  string getMoreInfo()
  {
    return "this value is refreshed every 5 seconds only.";
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches )
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        double attrval = (*list)[i]->get_gpsRefreshRate();
        char buf[32]; SAFE_SPRINTF(buf,32,"%.3f",attrval); string strval =  string(buf);
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), strval, true);
      }
  }
};

/**
 * Returns the representation system used for positioning data.
 *
 * @return a value among YGps.COORDSYSTEM_GPS_DMS, YGps.COORDSYSTEM_GPS_DM and YGps.COORDSYSTEM_GPS_D
 * corresponding to the representation system used for positioning data
 *
 * On failure, throws an exception or returns YGps.COORDSYSTEM_INVALID.
 */
class Gps_get_coordSystem : public YapiCommand /* arguments: */
{
public:
  Gps_get_coordSystem(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_coordSystem";
  }

  string getDescription()
  {
    return "Returns the representation system used for positioning data.";
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches )
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        int attrval = (*list)[i]->get_coordSystem();
        string strval =  enumString(attrval,enumGPSCoordinateSystem);
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), strval, true);
      }
  }
};

/**
 * Changes the representation system used for positioning data.
 * Remember to call the saveToFlash() method of the module if the
 * modification must be kept.
 *
 * @param newval : a value among YGps.COORDSYSTEM_GPS_DMS, YGps.COORDSYSTEM_GPS_DM and
 * YGps.COORDSYSTEM_GPS_D corresponding to the representation system used for positioning data
 *
 * @return YAPI.SUCCESS if the call succeeds.
 *
 * On failure, throws an exception or returns a negative error code.
 */
class Gps_set_coordSystem : public YapiCommand /* arguments: newval */
{
public:
  Gps_set_coordSystem(YFunctionCmdLine *function):YapiCommand(function){}
  string getName()
  {
    return "set_coordSystem";
  }

  string getDescription()
  {
    return "Changes the representation system used for positioning data.";
  }

  string getMoreInfo()
  {
    return "Remember to call \"YModule {target} saveToFlash\" if the modification must be kept.";
  }

  vector<ArgumentDesc*>* getArgumentDesc()
  {
    vector<ArgumentDesc*>* res = new vector<ArgumentDesc*>();
    res->push_back(new ArgumentDesc(INT_ARG, "newval", "a value among GPS_DMS, GPS_DM and GPS_D corresponding to the representation system used for positioning data", "GPS_DMS=0,GPS_DM=1,GPS_D=2", false));
    return res;
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches)
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    string value = (*args)[0]->to_str();
    for (i = 0; i < list->size(); i++) {
        (*list)[i]->set_coordSystem(Y_COORDSYSTEM_enum((*args)[0]->get_intValue()));
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), value, true);
    }
  }
};

/**
 * Returns the the satellites constellation used to compute
 * positioning data.
 *
 * @return a value among YGps.CONSTELLATION_GNSS, YGps.CONSTELLATION_GPS, YGps.CONSTELLATION_GLONASS,
 * YGps.CONSTELLATION_GALILEO, YGps.CONSTELLATION_GPS_GLONASS, YGps.CONSTELLATION_GPS_GALILEO and
 * YGps.CONSTELLATION_GLONASS_GALILEO corresponding to the the satellites constellation used to compute
 *         positioning data
 *
 * On failure, throws an exception or returns YGps.CONSTELLATION_INVALID.
 */
class Gps_get_constellation : public YapiCommand /* arguments: */
{
public:
  Gps_get_constellation(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_constellation";
  }

  string getDescription()
  {
    return "Returns the the satellites constellation used to computepositioning data.";
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches )
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        int attrval = (*list)[i]->get_constellation();
        string strval =  enumString(attrval,enumGPSConstellation);
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), strval, true);
      }
  }
};

/**
 * Changes the satellites constellation used to compute
 * positioning data. Possible  constellations are GNSS ( = all supported constellations),
 * GPS, Glonass, Galileo , and the 3 possible pairs. This setting has  no effect on Yocto-GPS (V1).
 *
 * @param newval : a value among YGps.CONSTELLATION_GNSS, YGps.CONSTELLATION_GPS,
 * YGps.CONSTELLATION_GLONASS, YGps.CONSTELLATION_GALILEO, YGps.CONSTELLATION_GPS_GLONASS,
 * YGps.CONSTELLATION_GPS_GALILEO and YGps.CONSTELLATION_GLONASS_GALILEO corresponding to the
 * satellites constellation used to compute
 *         positioning data
 *
 * @return YAPI.SUCCESS if the call succeeds.
 *
 * On failure, throws an exception or returns a negative error code.
 */
class Gps_set_constellation : public YapiCommand /* arguments: newval */
{
public:
  Gps_set_constellation(YFunctionCmdLine *function):YapiCommand(function){}
  string getName()
  {
    return "set_constellation";
  }

  string getDescription()
  {
    return "Changes the satellites constellation used to computepositioning data.";
  }

  string getMoreInfo()
  {
    return "Possible constellations are GNSS ( = all supported constellations), GPS, Glonass, Galileo , and the 3 possible pairs. This setting has no effect on Yocto-GPS (V1).";
  }

  vector<ArgumentDesc*>* getArgumentDesc()
  {
    vector<ArgumentDesc*>* res = new vector<ArgumentDesc*>();
    res->push_back(new ArgumentDesc(INT_ARG, "newval", "a value among GNSS, GPS, GLONASS, GALILEO, GPS_GLONASS, GPS_GALILEO and GLONASS_GALILEO corresponding to the satellites constellation used to compute positioning data", "GNSS=0,GPS=1,GLONASS=2,GALILEO=3,GPS_GLONASS=4,GPS_GALILEO=5,GLONASS_GALILEO=6", false));
    return res;
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches)
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    string value = (*args)[0]->to_str();
    for (i = 0; i < list->size(); i++) {
        (*list)[i]->set_constellation(Y_CONSTELLATION_enum((*args)[0]->get_intValue()));
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), value, true);
    }
  }
};

/**
 * Returns the current latitude.
 *
 * @return a string corresponding to the current latitude
 *
 * On failure, throws an exception or returns YGps.LATITUDE_INVALID.
 */
class Gps_get_latitude : public YapiCommand /* arguments: */
{
public:
  Gps_get_latitude(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_latitude";
  }

  string getDescription()
  {
    return "Returns the current latitude.";
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches )
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        string attrval = (*list)[i]->get_latitude();
        string strval =  attrval;
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), strval, true);
      }
  }
};

/**
 * Returns the current longitude.
 *
 * @return a string corresponding to the current longitude
 *
 * On failure, throws an exception or returns YGps.LONGITUDE_INVALID.
 */
class Gps_get_longitude : public YapiCommand /* arguments: */
{
public:
  Gps_get_longitude(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_longitude";
  }

  string getDescription()
  {
    return "Returns the current longitude.";
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches )
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        string attrval = (*list)[i]->get_longitude();
        string strval =  attrval;
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), strval, true);
      }
  }
};

/**
 * Returns the current horizontal dilution of precision,
 * the smaller that number is, the better .
 *
 * @return a floating point number corresponding to the current horizontal dilution of precision,
 *         the smaller that number is, the better
 *
 * On failure, throws an exception or returns YGps.DILUTION_INVALID.
 */
class Gps_get_dilution : public YapiCommand /* arguments: */
{
public:
  Gps_get_dilution(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_dilution";
  }

  string getDescription()
  {
    return "Returns the current horizontal dilution of precision,the smaller that number is, the better .";
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches )
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        double attrval = (*list)[i]->get_dilution();
        char buf[32]; SAFE_SPRINTF(buf,32,"%.3f",attrval); string strval =  string(buf);
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), strval, true);
      }
  }
};

/**
 * Returns the current altitude. Beware:  GPS technology
 * is very inaccurate regarding altitude.
 *
 * @return a floating point number corresponding to the current altitude
 *
 * On failure, throws an exception or returns YGps.ALTITUDE_INVALID.
 */
class Gps_get_altitude : public YapiCommand /* arguments: */
{
public:
  Gps_get_altitude(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_altitude";
  }

  string getDescription()
  {
    return "Returns the current altitude.";
  }

  string getMoreInfo()
  {
    return "Beware: GPS technology is very inaccurate regarding altitude.";
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches )
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        double attrval = (*list)[i]->get_altitude();
        char buf[32]; SAFE_SPRINTF(buf,32,"%.3f",attrval); string strval =  string(buf);
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), strval, true);
      }
  }
};

/**
 * Returns the current ground speed in Km/h.
 *
 * @return a floating point number corresponding to the current ground speed in Km/h
 *
 * On failure, throws an exception or returns YGps.GROUNDSPEED_INVALID.
 */
class Gps_get_groundSpeed : public YapiCommand /* arguments: */
{
public:
  Gps_get_groundSpeed(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_groundSpeed";
  }

  string getDescription()
  {
    return "Returns the current ground speed in Km/h.";
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches )
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        double attrval = (*list)[i]->get_groundSpeed();
        char buf[32]; SAFE_SPRINTF(buf,32,"%.3f",attrval); string strval =  string(buf);
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), strval, true);
      }
  }
};

/**
 * Returns the current move bearing in degrees, zero
 * is the true (geographic) north.
 *
 * @return a floating point number corresponding to the current move bearing in degrees, zero
 *         is the true (geographic) north
 *
 * On failure, throws an exception or returns YGps.DIRECTION_INVALID.
 */
class Gps_get_direction : public YapiCommand /* arguments: */
{
public:
  Gps_get_direction(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_direction";
  }

  string getDescription()
  {
    return "Returns the current move bearing in degrees, zerois the true (geographic) north.";
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches )
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        double attrval = (*list)[i]->get_direction();
        char buf[32]; SAFE_SPRINTF(buf,32,"%.3f",attrval); string strval =  string(buf);
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), strval, true);
      }
  }
};

/**
 * Returns the current time in Unix format (number of
 * seconds elapsed since Jan 1st, 1970).
 *
 * @return an integer corresponding to the current time in Unix format (number of
 *         seconds elapsed since Jan 1st, 1970)
 *
 * On failure, throws an exception or returns YGps.UNIXTIME_INVALID.
 */
class Gps_get_unixTime : public YapiCommand /* arguments: */
{
public:
  Gps_get_unixTime(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_unixTime";
  }

  string getDescription()
  {
    return "Returns the current time in Unix format (number ofseconds elapsed since Jan 1st, 1970).";
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches )
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        s64 attrval = (*list)[i]->get_unixTime();
        char buf[64]; SAFE_SPRINTF(buf, 64, "%u [s] since Jan 1, 1970", (u32)attrval); string strval =  string(buf);
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), strval, true);
      }
  }
};

/**
 * Returns the current time in the form "YYYY/MM/DD hh:mm:ss".
 *
 * @return a string corresponding to the current time in the form "YYYY/MM/DD hh:mm:ss"
 *
 * On failure, throws an exception or returns YGps.DATETIME_INVALID.
 */
class Gps_get_dateTime : public YapiCommand /* arguments: */
{
public:
  Gps_get_dateTime(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_dateTime";
  }

  string getDescription()
  {
    return "Returns the current time in the form \"YYYY/MM/DD hh:mm:ss\".";
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches )
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        string attrval = (*list)[i]->get_dateTime();
        string strval =  attrval;
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), strval, true);
      }
  }
};

/**
 * Returns the number of seconds between current time and UTC time (time zone).
 *
 * @return an integer corresponding to the number of seconds between current time and UTC time (time zone)
 *
 * On failure, throws an exception or returns YGps.UTCOFFSET_INVALID.
 */
class Gps_get_utcOffset : public YapiCommand /* arguments: */
{
public:
  Gps_get_utcOffset(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_utcOffset";
  }

  string getDescription()
  {
    return "Returns the number of seconds between current time and UTC time (time zone).";
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches )
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        int attrval = (*list)[i]->get_utcOffset();
        char buf[32]; SAFE_SPRINTF(buf, 32, "%d", attrval); string strval =  string(buf);
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), strval, true);
      }
  }
};

/**
 * Changes the number of seconds between current time and UTC time (time zone).
 * The timezone is automatically rounded to the nearest multiple of 15 minutes.
 * If current UTC time is known, the current time is automatically be updated according to the selected time zone.
 * Remember to call the saveToFlash() method of the module if the
 * modification must be kept.
 *
 * @param newval : an integer corresponding to the number of seconds between current time and UTC time (time zone)
 *
 * @return YAPI.SUCCESS if the call succeeds.
 *
 * On failure, throws an exception or returns a negative error code.
 */
class Gps_set_utcOffset : public YapiCommand /* arguments: newval */
{
public:
  Gps_set_utcOffset(YFunctionCmdLine *function):YapiCommand(function){}
  string getName()
  {
    return "set_utcOffset";
  }

  string getDescription()
  {
    return "Changes the number of seconds between current time and UTC time (time zone).";
  }

  string getMoreInfo()
  {
    return "The timezone is automatically rounded to the nearest multiple of 15 minutes. If current UTC time is known, the current time is automatically be updated according to the selected time zone. Remember to call \"YModule {target} saveToFlash\" if the modification must be kept.";
  }

  vector<ArgumentDesc*>* getArgumentDesc()
  {
    vector<ArgumentDesc*>* res = new vector<ArgumentDesc*>();
    res->push_back(new ArgumentDesc(INT_ARG, "newval", "an integer corresponding to the number of seconds between current time and UTC time (time zone)", "_INT", false));
    return res;
  }

  void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches)
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    string value = (*args)[0]->to_str();
    for (i = 0; i < list->size(); i++) {
        (*list)[i]->set_utcOffset(int((*args)[0]->get_intValue()));
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), value, true);
    }
  }
};

// type of valueCallbackGps is YGpsValueCallback* (YGpsValueCallback)
/**
 * Disables the propagation of every new advertised value to the parent hub.
 * You can use this function to save bandwidth and CPU on computers with limited
 * resources, or to prevent unwanted invocations of the HTTP callback.
 * Remember to call the saveToFlash() method of the module if the
 * modification must be kept.
 *
 * @return YAPI.SUCCESS when the call succeeds.
 *
 * On failure, throws an exception or returns a negative error code.
 */
class apifun_Gps_muteValueCallbacks : public YapiCommand /* arguments: */
{
public:
  apifun_Gps_muteValueCallbacks(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "muteValueCallbacks";
  }

  string getDescription()
  {
    return "Disables the propagation of every new advertised value to the parent hub.";
  }

  string getMoreInfo()
  {
    return "You can use this function to save bandwidth and CPU on computers with limited resources, or to prevent unwanted invocations of the HTTP callback. Remember to call \"YModule {target} saveToFlash\" if the modification must be kept.";
  }

  vector<ArgumentDesc*>* getArgumentDesc()
  {
    vector<ArgumentDesc*>* res = new vector<ArgumentDesc*>();
    return res;
  }

  virtual void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches)
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    string value = "";
    for (i = 0; i < list->size(); i++)
      {
        (*list)[i]->muteValueCallbacks();
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), value, true);
      }
  }
};

/**
 * Re-enables the propagation of every new advertised value to the parent hub.
 * This function reverts the effect of a previous call to muteValueCallbacks().
 * Remember to call the saveToFlash() method of the module if the
 * modification must be kept.
 *
 * @return YAPI.SUCCESS when the call succeeds.
 *
 * On failure, throws an exception or returns a negative error code.
 */
class apifun_Gps_unmuteValueCallbacks : public YapiCommand /* arguments: */
{
public:
  apifun_Gps_unmuteValueCallbacks(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "unmuteValueCallbacks";
  }

  string getDescription()
  {
    return "Re-enables the propagation of every new advertised value to the parent hub.";
  }

  string getMoreInfo()
  {
    return "This function reverts the effect of a previous call to muteValueCallbacks(). Remember to call \"YModule {target} saveToFlash\" if the modification must be kept.";
  }

  vector<ArgumentDesc*>* getArgumentDesc()
  {
    vector<ArgumentDesc*>* res = new vector<ArgumentDesc*>();
    return res;
  }

  virtual void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches)
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    string value = "";
    for (i = 0; i < list->size(); i++)
      {
        (*list)[i]->unmuteValueCallbacks();
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), value, true);
      }
  }
};

/**
 * Indicates whether changes to the function are prohibited or allowed.
 * Returns true if the function is blocked by an admin password
 * or if the function is not available.
 *
 * @return true if the function is write-protected or not online.
 */
class apifun_Gps_isReadOnly : public YapiCommand /* arguments: */
{
public:
  apifun_Gps_isReadOnly(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "isReadOnly";
  }

  string getDescription()
  {
    return "Indicates whether changes to the function are prohibited or allowed.";
  }

  string getMoreInfo()
  {
    return "Returns true if the function is blocked by an admin password or if the function is not available.";
  }

  vector<ArgumentDesc*>* getArgumentDesc()
  {
    vector<ArgumentDesc*>* res = new vector<ArgumentDesc*>();
    return res;
  }

  virtual void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches)
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        bool value = (*list)[i]->isReadOnly();
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), value, true);
      }
  }
};

/**
 * Returns the serial number of the module, as set by the factory.
 *
 * @return a string corresponding to the serial number of the module, as set by the factory.
 *
 * On failure, throws an exception or returns YFunction.SERIALNUMBER_INVALID.
 */
class apifun_Gps_get_serialNumber : public YapiCommand /* arguments: */
{
public:
  apifun_Gps_get_serialNumber(YFunctionCmdLine *function):YapiCommand(function){}

  string getName()
  {
    return "get_serialNumber";
  }

  string getDescription()
  {
    return "Returns the serial number of the module, as set by the factory.";
  }

  vector<ArgumentDesc*>* getArgumentDesc()
  {
    vector<ArgumentDesc*>* res = new vector<ArgumentDesc*>();
    return res;
  }

  virtual void execute(string target, vector<YModule*> *modulelist, string resultformat, vector<ArgumentDesc*>* args, vector<SwitchDesc*>* switches)
  {
    vector<YGps*>* list = enumerateTargets<YGps>(_function, target, modulelist);
    unsigned int i;
    for (i = 0; i < list->size(); i++)
      {
        string value = (*list)[i]->get_serialNumber();
        PrintResult(resultformat, this->getName(),YFunctionInfoCache((*list)[i]), value, true);
      }
  }
};

//--- (end of YGps implementation)

//--- (YGps functions)
void YGpsCmdLine::RegisterCommands(vector<YapiCommand*>* cmdList)
  {
    RegisterGenericFunctions<YGps>(this, cmdList);
    cmdList->push_back((YapiCommand*) (new Gps_get_logicalName(this)));
    cmdList->push_back((YapiCommand*) (new Gps_set_logicalName(this)));
    cmdList->push_back((YapiCommand*) (new Gps_get_advertisedValue(this)));
    cmdList->push_back((YapiCommand*) (new Gps_get_isFixed(this)));
    cmdList->push_back((YapiCommand*) (new Gps_get_satCount(this)));
    cmdList->push_back((YapiCommand*) (new Gps_get_satPerConst(this)));
    cmdList->push_back((YapiCommand*) (new Gps_get_gpsRefreshRate(this)));
    cmdList->push_back((YapiCommand*) (new Gps_get_coordSystem(this)));
    cmdList->push_back((YapiCommand*) (new Gps_set_coordSystem(this)));
    cmdList->push_back((YapiCommand*) (new Gps_get_constellation(this)));
    cmdList->push_back((YapiCommand*) (new Gps_set_constellation(this)));
    cmdList->push_back((YapiCommand*) (new Gps_get_latitude(this)));
    cmdList->push_back((YapiCommand*) (new Gps_get_longitude(this)));
    cmdList->push_back((YapiCommand*) (new Gps_get_dilution(this)));
    cmdList->push_back((YapiCommand*) (new Gps_get_altitude(this)));
    cmdList->push_back((YapiCommand*) (new Gps_get_groundSpeed(this)));
    cmdList->push_back((YapiCommand*) (new Gps_get_direction(this)));
    cmdList->push_back((YapiCommand*) (new Gps_get_unixTime(this)));
    cmdList->push_back((YapiCommand*) (new Gps_get_dateTime(this)));
    cmdList->push_back((YapiCommand*) (new Gps_get_utcOffset(this)));
    cmdList->push_back((YapiCommand*) (new Gps_set_utcOffset(this)));
    cmdList->push_back((YapiCommand*) (new apifun_Gps_muteValueCallbacks(this)));
    cmdList->push_back((YapiCommand*) (new apifun_Gps_unmuteValueCallbacks(this)));
    cmdList->push_back((YapiCommand*) (new apifun_Gps_isReadOnly(this)));
    cmdList->push_back((YapiCommand*) (new apifun_Gps_get_serialNumber(this)));
  }

//--- (end of YGps functions)
