Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages | Examples

ArPTZ.cpp

00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 #include "ArExport.h"
00027 #include "ariaOSDef.h"
00028 #include "ArPTZ.h"
00029 #include "ArRobot.h"
00030 #include "ArRobotPacket.h"
00031 #include "ArCommands.h"
00032 #include "ArDeviceConnection.h"
00033 
00037 AREXPORT ArPTZ::ArPTZ(ArRobot *robot) :
00038   myConnectCB(this, &ArPTZ::connectHandler),
00039   mySensorInterpCB(this, &ArPTZ::sensorInterpHandler),
00040   myRobotPacketHandlerCB(this, &ArPTZ::robotPacketHandler)
00041 {
00042   myRobot = robot;
00043   myConn = NULL;
00044   myAuxPort = 1;
00045   myAuxTxCmd = ArCommands::TTY2;
00046   myAuxRxCmd = ArCommands::GETAUX;
00047   myRobotPacketHandlerCB.setName("ArPTZ");
00048   if (myRobot != NULL)
00049   {
00050     myRobot->addConnectCB(&myConnectCB, ArListPos::LAST);
00051     myRobot->addPacketHandler(&myRobotPacketHandlerCB, ArListPos::FIRST);
00052   }
00053 }
00054 
00055 AREXPORT ArPTZ::~ArPTZ()
00056 {
00057   if (myRobot != NULL)
00058   {
00059     myRobot->remConnectCB(&myConnectCB);
00060     myRobot->remPacketHandler(&myRobotPacketHandlerCB);
00061     myRobot->remSensorInterpTask(&mySensorInterpCB);
00062   }
00063   
00064 }
00065 
00071 AREXPORT bool ArPTZ::sendPacket(ArBasePacket *packet)
00072 {
00073   packet->finalizePacket();
00074   if (myConn != NULL)
00075     return myConn->write(packet->getBuf(), packet->getLength());
00076   else if (myRobot != NULL)
00077     return myRobot->comStrN(myAuxTxCmd, packet->getBuf(), 
00078                 packet->getLength());
00079   else
00080     return false;
00081 }
00082 
00083 AREXPORT bool ArPTZ::robotPacketHandler(ArRobotPacket *packet)
00084 {
00085   //printf("%x\n", packet->getID());
00086   if ((packet->getID() == 0xb0 && myAuxPort == 1) ||
00087       (packet->getID() == 0xb8 && myAuxPort == 2))
00088     return packetHandler(packet);
00089   else
00090     return false;
00091 }
00092 
00093 AREXPORT void ArPTZ::connectHandler(void)
00094 {
00095   init();
00096 }
00097 
00098 AREXPORT void ArPTZ::sensorInterpHandler(void)
00099 {
00100   ArBasePacket *packet;
00101   while ((packet = readPacket()) != NULL)
00102     packetHandler(packet);
00103 }
00104 
00116 AREXPORT bool ArPTZ::setDeviceConnection(ArDeviceConnection *connection,
00117                      bool driveFromRobotLoop)
00118 {
00119   if (myRobot != NULL)
00120   {
00121     myRobot->remPacketHandler(&myRobotPacketHandlerCB);
00122     myRobot->remSensorInterpTask(&mySensorInterpCB);
00123   }
00124   if (myRobot == NULL)
00125     return false;
00126   myConn = connection;
00127   if (driveFromRobotLoop && myRobot != NULL && myConn != NULL)
00128     myRobot->addSensorInterpTask("ptz", 50, &mySensorInterpCB);
00129   if (myConn->getStatus() != ArDeviceConnection::STATUS_OPEN)
00130     return myConn->openSimple();
00131   else
00132     return true;
00133 }
00134 
00135 AREXPORT ArDeviceConnection *ArPTZ::getDeviceConnection(void)
00136 {
00137   return myConn;
00138 }
00139 
00140 
00148 AREXPORT bool ArPTZ::setAuxPort(int auxPort)
00149 {
00150   if (auxPort == 1)
00151   {
00152     myAuxTxCmd = ArCommands::TTY2;
00153     myAuxRxCmd = ArCommands::GETAUX;
00154     myAuxPort = 1;
00155     return true;
00156   }
00157   else if (auxPort == 2)
00158   {
00159     myAuxTxCmd = ArCommands::TTY3;
00160     myAuxRxCmd = ArCommands::GETAUX2;
00161     myAuxPort = 2;
00162     return true;
00163   }
00164   else
00165     return false;
00166 }
00167 

Generated on Tue Feb 20 10:51:40 2007 for Aria by  doxygen 1.4.0