00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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