/*

ARIA header files for use with ARNL 1.7.1

Copyright(C) 2004, 2005 ActivMedia Robotics, LLC. 
Copyright(C) 2006, 2007, 2008, 2009 MobileRobots Inc.
All rights reserved.

This copy of Aria was relicensed for use with Arnl and the Arnl
license by MobileRobots Inc.  If you wish to download a seperate
distribution of Aria licensed under the GPL or a commercial license go to
http://www.mobilerobots.com/SOFTWARE/aria.html or contact MobileRobots
Inc, at robots@mobilerobots.com or MobileRobots Inc,
10 Columbia Drive, Amherst, NH 03031; 800-639-9481

MobileRobots Inc hereby grants to other individuals or
organizations permission to use this software with Arnl and in
compliance with the Arnl license.  This software may not be
distributed to others except by MobileRobots Inc.

MobileRobots Inc does not make any representations about the
suitability of this software for any purpose.  It is provided "as is"
without express or implied warranty.

*/
#ifndef ARSERVERROBOTINFO_H
#define ARSERVERROBOTINFO_H

#include "Aria.h"
#include "ArServerBase.h"

class ArServerClient;

/** Server component providing basic robot status information to clients.
 * This service accepts the following data requests: 
 * <ul>
 *  <li><code>update</code></li>
 *  <li><code>physicalInfo</code></li>
 *  <li><code>batteryInfo</code></li>
 *  <li><code>activityTimeInfo</code></li>
 * </ul>
 *
 *  For bandwidth savings you should use <code>updateNumbers</code>
 * and <code>updateStrings</code> instead of <code>update</code>.
 *
 * The <code>update</code> request returns data regarding the current
 * state of the robot. 
 * It replies with the following data packet:
 * <ol>
 *  <li>Status (Null-terminated string)</li>
 *  <li>Mode (Null-terminated string)</li>
 *  <li>Battery voltage (times 10) (2 Byte integer)</li>
 *  <li>X position (4 byte floating point number)</li>
 *  <li>Y position (4 byte floating point number)</li>
 *  <li>Theta (2-byte floating point number)</li>
 *  <li>Forward velocity (2-byte integer)</li>
 *  <li>Rotation velocity (2-byte integer)</li>
 * </ol>
 *
 * The <code>updateNumbers</code> request returns data regarding the current
 * state of the robot. 
 * It replies with the following data packet:
 * <ol>
 *  <li>Battery voltage (times 10) (2 Byte integer)</li>
 *  <li>X position (4 byte floating point number)</li>
 *  <li>Y position (4 byte floating point number)</li>
 *  <li>Theta (2-byte floating point number)</li>
 *  <li>Forward velocity (2-byte integer)</li>
 *  <li>Rotation velocity (2-byte integer)</li>
 * </ol>
 *
 * The <code>updateStrings</code> request broadcasts data regarding
 * the current state of the robot.  Request this at -1 to get the
 * broadcasts and an initial packet with the inital data.
 * It replies with the following data packet:
 * <ol>
 *  <li>Status (Null-terminated string)</li>
 *  <li>Mode (Null-terminated string)</li>
 *</ol>
 *
 * The <code>physicalInfo</code> request returns data regarding the physical characteristics of
 * the robot.  This information does not change during the robot execution.  It replies with the 
 * following data packet:
 * <ol>
 *  <li>Robot type (Null-terminated string)</li>
 *  <li>Robot sub-type (Null-terminated string)</li>
 *  <li>Robot width in mm (2 byte integer)</li>
 *  <li>Robot front length - mm from center of rotation to front of robot (2 byte integer)</li>
 *  <li>Robot rear length - mm from center of rotation to back of robot (2 byte integer)</li>
 * </ol>
 *
 * The <code>batteryInfo</code> request replies with the following data packet:
 * <ol>
 *  <li>Warning voltage (double)</li>
 *  <li>Shutdown voltage (double)</li>
 * </ol>
 *
 * The <code>activityTimeInfo</code> request replies with the following data packet:
 * <ol>
 *   <li>Sec since - the ArServerMode::getActiveModeActivityTimeSecSince value (4-byte int)</li>
 * </ol>
 *
 * These requests are in the <code>RobotInfo</code> command group.
 */

class ArServerInfoRobot
{
public:
  /// Constructor
  AREXPORT ArServerInfoRobot(ArServerBase *server, ArRobot *robot);
  /// Destructor
  AREXPORT virtual ~ArServerInfoRobot();
  /// The function that sends updates about the robot off to the client
  AREXPORT void update(ArServerClient *client, ArNetPacket *packet);
  /// The function that sends updates about the robot off to the client
  AREXPORT void updateNumbers(ArServerClient *client, ArNetPacket *packet);
  /// The function that sends updates about the robot off to the client
  AREXPORT void updateStrings(ArServerClient *client, ArNetPacket *packet);
  /// The function that sends battery info about the robot off to the client
  AREXPORT void batteryInfo(ArServerClient *client, ArNetPacket *packet);
  /// The function that sends information about the physical robot 
  AREXPORT void physicalInfo(ArServerClient *client, ArNetPacket *packet);
  /// The function that sends information about the time that the server mode was last active 
  AREXPORT void activityTimeInfo(ArServerClient *client, ArNetPacket *packet);
protected:
  ArServerBase *myServer;
  ArRobot *myRobot;
  void userTask(void);
  
  std::string myStatus;
  std::string myMode;
  std::string myOldStatus;
  std::string myOldMode;

  
  ArFunctor2C<ArServerInfoRobot, ArServerClient *, ArNetPacket *> myUpdateCB;
  ArFunctor2C<ArServerInfoRobot, ArServerClient *, ArNetPacket *> myUpdateNumbersCB;
  ArFunctor2C<ArServerInfoRobot, ArServerClient *, ArNetPacket *> myUpdateStringsCB;
  ArFunctor2C<ArServerInfoRobot, ArServerClient *, ArNetPacket *> myBatteryInfoCB;
  ArFunctor2C<ArServerInfoRobot, ArServerClient *, ArNetPacket *> myPhysicalInfoCB;
  ArFunctor2C<ArServerInfoRobot, ArServerClient *, ArNetPacket *> myActivityTimeInfoCB;
  ArFunctorC<ArServerInfoRobot> myUserTaskCB;
};

#endif
