[TeamTalk 12]: [549] TeamTalk/Agents/PrimitiveComm: The call to interpretBoeingPacket is now surrounded by a try block.
tk@edam.speech.cs.cmu.edu
tk at edam.speech.cs.cmu.edu
Thu Dec 7 16:49:06 EST 2006
An HTML attachment was scrubbed...
URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061207/3a7f2a18/attachment-0001.html
-------------- next part --------------
Modified: TeamTalk/Agents/PrimitiveComm/robot_client.cpp
===================================================================
--- TeamTalk/Agents/PrimitiveComm/robot_client.cpp 2006-12-07 21:47:20 UTC (rev 548)
+++ TeamTalk/Agents/PrimitiveComm/robot_client.cpp 2006-12-07 21:49:06 UTC (rev 549)
@@ -139,26 +139,33 @@
const Boeing::MsgRobot* mesg = i->getNextMessage();
if(mesg == NULL) continue;
gotAMessage = true;
- Msg* m = Msg::interpretBoeingPacket(string(mesg->buff, sizeof(Boeing::MsgRobot)), i->getName());
- if(m == NULL) continue;
- //report unless you get a monotonous location message
- if(dynamic_cast<MsgRobLocation*>(m))
- debug("client") << "robot " << i->getName() << ": " << m << endl;
- else
- info("client") << "robot " << i->getName() << ": " << m << endl;
- {
- //[2005-09-22] (tk): don't worry about pings for now
- //MsgPingPP* ping = dynamic_cast<MsgPingPP*>(m);
- //if(ping != NULL) {
- // if(me->addRobot(ping->handle(),
- // ping->content()->header.sender)) {
- // if(me->addRobot(ping->handle(), st_remote_addr))
- // //if this robot is new to us, reply to the ping
- // me->sendPacket(ping->handle(), MsgPingPP(me->handle_));
- //}
- }
- me->robotCallback_->processRobotMessage(m);
- delete m;
+ try {
+ Msg* m = Msg::interpretBoeingPacket(string(mesg->buff, sizeof(Boeing::MsgRobot)), i->getName());
+ if(m == NULL) {
+ error << "interpretation of message returned NULL" << endl;
+ continue;
+ }
+ //report unless you get a monotonous location message
+ if(dynamic_cast<MsgRobLocation*>(m))
+ debug("client") << "robot " << i->getName() << ": " << m << endl;
+ else
+ info("client") << "robot " << i->getName() << ": " << m << endl;
+ {
+ //[2005-09-22] (tk): don't worry about pings for now
+ //MsgPingPP* ping = dynamic_cast<MsgPingPP*>(m);
+ //if(ping != NULL) {
+ // if(me->addRobot(ping->handle(),
+ // ping->content()->header.sender)) {
+ // if(me->addRobot(ping->handle(), st_remote_addr))
+ // //if this robot is new to us, reply to the ping
+ // me->sendPacket(ping->handle(), MsgPingPP(me->handle_));
+ //}
+ }
+ me->robotCallback_->processRobotMessage(m);
+ delete m;
+ } catch(MalformedPacketException e) {
+ error << e.what();
+ }
}
if(!gotAMessage) Sleep(500);
}
Deleted: TeamTalk/Agents/PrimitiveComm/robot_packet.cpp
===================================================================
--- TeamTalk/Agents/PrimitiveComm/robot_packet.cpp 2006-12-07 21:47:20 UTC (rev 548)
+++ TeamTalk/Agents/PrimitiveComm/robot_packet.cpp 2006-12-07 21:49:06 UTC (rev 549)
@@ -1,589 +0,0 @@
-#include "robot_packet.hpp"
-
-#include <iostream>
-#include <sstream>
-#include <cmath>
-
-using namespace std;
-using namespace Boeing;
-
-ostream& operator<<(ostream& out, const RP_Polygon& p) {
- out << '{';
- for(int i=0; i<p.n; i++) {
- out << Vector(p.xpoint[i], p.ypoint[i]);
- if(i<p.n-1) out << ", ";
- }
- return out << '}';
-};
-
-ostream& operator<<(ostream& out, const Msg& m) {
- return out << m.render();
-};
-
-RP_Polygon makeRP(const geometry::Polygon& polygon) {
- RP_Polygon rpp;
- rpp.n = (int) polygon.size();
- for(int i=0; i<rpp.n; i++) {
- rpp.xpoint[i] = (float) polygon[i].x;
- rpp.ypoint[i] = (float) polygon[i].y;
- }
- return rpp;
-};
-
-int Msg::iTaskCounter = 0;
-
-Msg* Msg::interpretPlayAction(const MsgCmdAction& playaction) {
- Msg* retval = NULL;
- cerr << "about to interpret: '" << playaction.action << "'" << endl;
- istringstream i(playaction.action);
- string w1;
- i >> w1;
- if(w1 == "halt") retval = new MsgCmdHaltPP();
- else if(w1 == "goto") {
- string w2;
- i >> w2;
- if (w2 == "home") {
- retval = new MsgCmdHomePP();
- } else {
- geometry::Point p;
- i >> p;
- if (w2 == "abs") {
- retval = new MsgCmdGoToGlobalPP(p);
- } else if (w2 == "rel") {
- if(p.x == 0 && p.y == 0) {
- double a = 0;
- i >> a;
- retval = new MsgCmdTurnRelativePP(a);
- } else retval = new MsgCmdGoToRelativePP(p);
- }
- }
- } else if (w1 == "pause") retval = new MsgCmdPausePP();
- else if (w1 == "resume") retval = new MsgCmdResumePP();
- else if (w1 == "setpos") retval = new MsgCmdSetPos(playaction);
- return retval;
-}
-
-Msg* Msg::interpret(const char* c, string s) {
- Msg* retval = NULL;
- if(c == NULL) {
- cerr << "Msg::interpret: null string" << endl;
- return retval;
- }
- const MsgHeader* h = (const MsgHeader*)c;
- cerr << "got message type: " << h->type << endl;
- switch(h->type) {
- case CMD_HALT: retval = new MsgCmdHaltPP(*(const MsgCmdHalt*)c); break;
- case CMD_GOTO:
- switch(((const MsgCmdGoTo*)c)->attr) {
- case 0x0000: retval = new MsgCmdGoToGlobalPP(*(const MsgCmdGoTo*)c); break;
- case (MsgCmdGoTo::Relative):
- retval = new MsgCmdGoToRelativePP(*(const MsgCmdGoTo*)c); break;
- case (MsgCmdGoTo::Relative | MsgCmdGoTo::UseAngle):
- retval = new MsgCmdTurnRelativePP(*(const MsgCmdGoTo*)c); break;
- default:
- cerr << "got unexpected attr: " << hex << ((const MsgCmdGoTo*)c)->attr << endl;
- throw exception();
- }
- break;
- case CMD_HOME: retval = new MsgCmdHomePP(*(const MsgCmdHome*)c); break;
- case CMD_PAUSE: retval = new MsgCmdPausePP(*(const MsgCmdPause*)c); break;
- case CMD_RESUME: retval = new MsgCmdResumePP(*(const MsgCmdResume*)c); break;
- case CMD_FOLLOW: retval = new MsgCmdFollowPP(*(const MsgCmdFollow*)c); break;
- case REQ_LOCATION: retval = new MsgReqLocationPP(*(const MsgReqLocation*)c); break;
- case ROB_ACK: retval = new MsgRobAckPP(*(const MsgRobAck*)c); break;
- case ROB_DONE: retval = new MsgRobDonePP(*(const MsgRobDone*)c); break;
- case ROB_LOCATION: retval = new MsgRobLocationPP(*(const MsgRobLocation*)c); break;
- //case MsgIdPing: retval = new MsgPingPP(*(const MsgPing*)c); break;
- case ROB_ACTION_ACK: retval = new MsgActionAckPP(*(const MsgActionAck*)c); break;
- case ROB_ACTION_ECHO:
- case CMD_ACTION:
- retval = interpretPlayAction(*(const MsgCmdAction*)c);
- if (retval == NULL) {
- cerr << "didn't understand command action message" << endl;
- return NULL;
- }
- break;
- case REQ_IMAGE: retval = new MsgMapReqPP(*(const MsgMapReq*)c); break;
- case ROB_IMAGE: retval = new MsgMapPP(*(const MsgMap*)c); break;
- default: cerr << "unhandled type: " << h->type << endl; return NULL;
- }
- if (retval == NULL) {
- //shouldn't happen
- cerr << "weird error here" << endl;
- return NULL;
- }
- retval->sender = s;
- return retval;
-};
-
-Msg* Msg::clone() const {
- const MsgCmdHaltPP *halt = dynamic_cast<const MsgCmdHaltPP*>(this);
- if(halt != NULL) return halt->clone();
- const MsgCmdGoToGlobalPP *gtg = dynamic_cast<const MsgCmdGoToGlobalPP*>(this);
- if(gtg != NULL) return gtg->clone();
- const MsgCmdGoToRelativePP *gtr = dynamic_cast<const MsgCmdGoToRelativePP*>(this);
- if(gtr != NULL) return gtr->clone();
- const MsgCmdTurnRelativePP *turn = dynamic_cast<const MsgCmdTurnRelativePP*>(this);
- if(turn != NULL) return turn->clone();
- const MsgCmdPausePP *pause = dynamic_cast<const MsgCmdPausePP*>(this);
- if(pause != NULL) return pause->clone();
- const MsgCmdResumePP *resume = dynamic_cast<const MsgCmdResumePP*>(this);
- if(resume != NULL) return resume->clone();
- const MsgCmdFollowPP *follow = dynamic_cast<const MsgCmdFollowPP*>(this);
- if(follow != NULL) return follow->clone();
- const MsgReqLocationPP *rloc = dynamic_cast<const MsgReqLocationPP*>(this);
- if(rloc != NULL) return rloc->clone();
- const MsgRobAckPP *ack = dynamic_cast<const MsgRobAckPP*>(this);
- if(ack != NULL) return ack->clone();
- const MsgRobDonePP *done = dynamic_cast<const MsgRobDonePP*>(this);
- if(done != NULL) return done->clone();
- const MsgRobLocationPP *loc = dynamic_cast<const MsgRobLocationPP*>(this);
- if(loc != NULL) return loc->clone();
- //const MsgPingPP *ping = dynamic_cast<const MsgPingPP*>(this);
- //if(ping != NULL) return ping->clone();
- const MsgMapReqPP *req_map = dynamic_cast<const MsgMapReqPP*>(this);
- if(req_map != NULL) return req_map->clone();
- const MsgMapPP *map = dynamic_cast<const MsgMapPP*>(this);
- if(map != NULL) return map->clone();
- return NULL;
-};
-
-Msg::~Msg() {}
-
-uint16_t Msg::getType() const {
- if(dynamic_cast<const MsgCmdHaltPP*>(this) != NULL) return CMD_HALT;
- if(dynamic_cast<const MsgCmdGoToPP*>(this) != NULL) return CMD_GOTO;
- if(dynamic_cast<const MsgCmdHomePP*>(this) != NULL) return CMD_HOME;
- if(dynamic_cast<const MsgCmdPausePP*>(this) != NULL) return CMD_PAUSE;
- if(dynamic_cast<const MsgCmdResumePP*>(this) != NULL) return CMD_RESUME;
- if(dynamic_cast<const MsgCmdFollowPP*>(this) != NULL) return CMD_FOLLOW;
- if(dynamic_cast<const MsgCmdCoverPP*>(this) != NULL) return CMD_COVER;
- if(dynamic_cast<const MsgReqLocationPP*>(this) != NULL) return REQ_LOCATION;
- if(dynamic_cast<const MsgRobAckPP*>(this) != NULL) return ROB_ACK;
- if(dynamic_cast<const MsgRobDonePP*>(this) != NULL) return ROB_DONE;
- if(dynamic_cast<const MsgRobLocationPP*>(this) != NULL) return ROB_LOCATION;
- //if(dynamic_cast<const MsgPingPP*>(this) != NULL) return MsgIdPing;
- if(dynamic_cast<const MsgMapReqPP*>(this) != NULL) return REQ_IMAGE;
- if(dynamic_cast<const MsgMapPP*>(this) != NULL) return ROB_IMAGE;
- return 0;
-}
-
-string Msg::getSender() const {
- return sender;
-}
-
-MsgCmdActionPP::MsgCmdActionPP() {}
-MsgCmdActionPP::MsgCmdActionPP(const MsgCmdAction& c) : content_(c) {}
-MsgHeader* MsgCmdActionPP::header() {return (MsgHeader*)&content_;};
-string MsgCmdActionPP::render() const {
- return content_.action;
-}
-const MsgCmdAction* MsgCmdActionPP::content() const {
- return &content_;
-}
-
-MsgCmdHaltPP::MsgCmdHaltPP() {
- content_.type = CMD_HALT;
- content_.len = sizeof(content_);
- content_.taskid = iTaskCounter++;
- content_.priority = 1;
-};
-MsgCmdHaltPP::MsgCmdHaltPP(const MsgCmdHalt& x) : content_(x) {};
-MsgCmdHaltPP* MsgCmdHaltPP::clone() const {return new MsgCmdHaltPP(*this);};
-MsgHeader* MsgCmdHaltPP::header() {return (MsgHeader*)&content_;};
-const MsgCmdHalt* MsgCmdHaltPP::content() const {return &content_;}
-string MsgCmdHaltPP::action_string() const {return "halt";}
-string MsgCmdHaltPP::render() const {return "Halt";}
-
-MsgCmdGoToPP::MsgCmdGoToPP() {
- content_.type = CMD_GOTO;
- content_.len = sizeof(content_);
- content_.taskid = iTaskCounter++;
- content_.priority = 1;
-};
-MsgCmdGoToPP::MsgCmdGoToPP(const MsgCmdGoTo& x) : content_(x) {};
-MsgHeader* MsgCmdGoToPP::header() {return (MsgHeader*)&content_;};
-const MsgCmdGoTo* MsgCmdGoToPP::content() const {return &content_;}
-
-MsgCmdGoToGlobalPP::MsgCmdGoToGlobalPP(Point loc) {
- content_.x = (float) loc.x; content_.y = (float) loc.y; content_.attr = 0x0000;
-};
-MsgCmdGoToGlobalPP::MsgCmdGoToGlobalPP(const MsgCmdGoTo& x) :
- MsgCmdGoToPP(x) {};
-MsgCmdGoToGlobalPP* MsgCmdGoToGlobalPP::clone() const {return new MsgCmdGoToGlobalPP(*this);};
-string MsgCmdGoToGlobalPP::action_string() const {
- ostringstream s;
- s << "goto abs (" << content_.x << ' ' << content_.y << ')';
- return s.str();
-};
-string MsgCmdGoToGlobalPP::render() const {
- ostringstream out;
- out << "GoToGlobal: " << Point(content_.x, content_.y);
- return out.str();
-};
-
-MsgCmdGoToRelativePP::MsgCmdGoToRelativePP(Point vec) {
- content_.x = (float) vec.x; content_.y = (float) vec.y; content_.attr = 0x0001;
-};
-MsgCmdGoToRelativePP::MsgCmdGoToRelativePP(const MsgCmdGoTo& x) :
- MsgCmdGoToPP(x) {};
-MsgCmdGoToRelativePP* MsgCmdGoToRelativePP::clone() const {return new MsgCmdGoToRelativePP(*this);};
-string MsgCmdGoToRelativePP::action_string() const {
- ostringstream s;
- s << "goto rel (" << content_.x << ' ' << content_.y << ')';
- return s.str();
-};
-string MsgCmdGoToRelativePP::render() const {
- ostringstream out;
- out << "GoToRelative: " << Point(content_.x, content_.y);
- return out.str();
-};
-
-MsgCmdTurnRelativePP::MsgCmdTurnRelativePP(double a) {
- content_.x = 0; content_.y = 0;
- content_.angle = (float) a;
- content_.attr = 0x0101;
-};
-MsgCmdTurnRelativePP::MsgCmdTurnRelativePP(const MsgCmdGoTo& x) :
- MsgCmdGoToPP(x) {};
-MsgCmdTurnRelativePP* MsgCmdTurnRelativePP::clone() const {return new MsgCmdTurnRelativePP(*this);};
-string MsgCmdTurnRelativePP::action_string() const {
- ostringstream s;
- s << "goto rel (0 0) " << content_.angle;
- return s.str();
-};
-string MsgCmdTurnRelativePP::render() const {
- ostringstream out;
- out << "TurnRelative: " << content_.angle << " radians";
- return out.str();
-};
-
-MsgCmdHomePP::MsgCmdHomePP() {
- content_.type = CMD_HOME;
- content_.len = sizeof(content_);
- content_.taskid = iTaskCounter++;
- content_.priority = 1;
-};
-MsgCmdHomePP::MsgCmdHomePP(const MsgCmdHome& x) : content_(x) {}
-MsgCmdHomePP* MsgCmdHomePP::clone() const {return new MsgCmdHomePP(*this);}
-MsgHeader* MsgCmdHomePP::header() {return (MsgHeader*)&content_;}
-const MsgCmdHome* MsgCmdHomePP::content() const {return &content_;}
-string MsgCmdHomePP::action_string() const {return "goto home";}
-string MsgCmdHomePP::render() const {return "Home";}
-
-MsgCmdPausePP::MsgCmdPausePP() {
- content_.type = CMD_PAUSE;
- content_.len = sizeof(content_);
- content_.taskid = iTaskCounter++;
- content_.priority = 1;
-};
-MsgCmdPausePP::MsgCmdPausePP(const MsgCmdPause& x) : content_(x) {};
-MsgCmdPausePP* MsgCmdPausePP::clone() const {return new MsgCmdPausePP(*this);};
-MsgHeader* MsgCmdPausePP::header() {return (MsgHeader*)&content_;};
-const MsgCmdPause* MsgCmdPausePP::content() const {return &content_;}
-string MsgCmdPausePP::action_string() const {return "pause";}
-string MsgCmdPausePP::render() const {return "Pause";};
-
-MsgCmdResumePP::MsgCmdResumePP() {
- content_.type = CMD_RESUME;
- content_.len = sizeof(content_);
- content_.taskid = iTaskCounter++;
- content_.priority = 1;
-};
-MsgCmdResumePP::MsgCmdResumePP(const MsgCmdResume& x) : content_(x) {};
-MsgCmdResumePP* MsgCmdResumePP::clone() const {return new MsgCmdResumePP(*this);};
-MsgHeader* MsgCmdResumePP::header() {return (MsgHeader*)&content_;};
-const MsgCmdResume* MsgCmdResumePP::content() const {return &content_;}
-string MsgCmdResumePP::action_string() const {return "resume";}
-string MsgCmdResumePP::render() const {return "Resume";};
-
-MsgCmdFollowPP::MsgCmdFollowPP(const string& l) {
- content_.type = CMD_FOLLOW;
- content_.len = sizeof(content_);
- content_.taskid = iTaskCounter++;
- //strncpy(content_.leader, l.c_str(), SADDR_LENGTH);
- content_.priority = 1;
-};
-MsgCmdFollowPP::MsgCmdFollowPP(const MsgCmdFollow& x) : content_(x) {};
-MsgCmdFollowPP* MsgCmdFollowPP::clone() const {return new MsgCmdFollowPP(*this);};
-MsgHeader* MsgCmdFollowPP::header() {return (MsgHeader*)&content_;};
-const MsgCmdFollow* MsgCmdFollowPP::content() const {return &content_;}
-string MsgCmdFollowPP::action_string() const {
- ostringstream s;
- //s << "follow " << content_.leader;
- return s.str();
-}
-string MsgCmdFollowPP::render() const {
- ostringstream out;
- //out << "Follow: " << content_.leader;
- return out.str();
-};
-
-MsgCmdCoverPP::MsgCmdCoverPP(const Point& lower_left,
- const Point& upper_right) {
- content_.type = CMD_COVER;
- content_.len = sizeof(content_);
- content_.taskid = iTaskCounter++;
- content_.priority = 1;
- content_.cover_shape = makeRP((geometry::Polygon)Quadrilateral(lower_left, upper_right));
-};
-MsgCmdCoverPP::MsgCmdCoverPP(float x1, float x2, float y1, float y2) {
- content_.type = CMD_COVER;
- content_.len = sizeof(content_);
- content_.taskid = iTaskCounter++;
- content_.priority = 1;
- content_.cover_shape = makeRP((geometry::Polygon)Quadrilateral(x1, x2, y1, y2));
-};
-MsgCmdCoverPP::MsgCmdCoverPP(const geometry::Polygon& polygon) {
- content_.type = CMD_COVER;
- content_.len = sizeof(content_);
- content_.taskid = iTaskCounter++;
- content_.priority = 1;
- content_.cover_shape = makeRP(polygon);
-};
-MsgCmdCoverPP::MsgCmdCoverPP(const MsgCmdCover& x) : content_(x) {};
-MsgCmdCoverPP* MsgCmdCoverPP::clone() const {return new MsgCmdCoverPP(*this);};
-MsgHeader* MsgCmdCoverPP::header() {return (MsgHeader*)&content_;};
-const MsgCmdCover* MsgCmdCoverPP::content() const {return &content_;}
-string MsgCmdCoverPP::action_string() const {
- ostringstream s;
- s << "cover";
- for(int i=0; i < content_.cover_shape.n; i++) {
- s << " " << content_.cover_shape.xpoint[i] << ' ' << content_.cover_shape.ypoint[i] << ')';
- }
- return s.str();
-}
-string MsgCmdCoverPP::render() const {
- ostringstream out;
- out << "Cover: " << content_.cover_shape;
- return out.str();
-};
-
-MsgReqLocationPP::MsgReqLocationPP() {
- content_.type = REQ_LOCATION;
- content_.len = sizeof(content_);
- content_.priority = 1;
-};
-MsgReqLocationPP::MsgReqLocationPP(const MsgReqLocation& x) : content_(x) {};
-MsgReqLocationPP* MsgReqLocationPP::clone() const {return new MsgReqLocationPP(*this);};
-MsgHeader* MsgReqLocationPP::header() {return (MsgHeader*)&content_;};
-const MsgReqLocation* MsgReqLocationPP::content() const {
- return &content_;
-}
-string MsgReqLocationPP::render() const {return "ReqLocation";};
-
-MsgRobAckPP::MsgRobAckPP(uint16_t id) {
- content_.type = ROB_ACK;
- content_.len = sizeof(content_);
- content_.taskid = id;
-};
-MsgRobAckPP::MsgRobAckPP(const MsgRobAck& x) : content_(x) {};
-MsgRobAckPP* MsgRobAckPP::clone() const {return new MsgRobAckPP(*this);};
-MsgHeader* MsgRobAckPP::header() {return (MsgHeader*)&content_;};
-const MsgRobAck* MsgRobAckPP::content() const {
- return &content_;
-}
-string MsgRobAckPP::render() const {return "RobAck";};
-
-MsgRobDonePP::MsgRobDonePP(uint16_t id, bool success) {
- content_.type = ROB_DONE;
- content_.len = sizeof(content_);
- content_.taskid = id;
- content_.status = (success? 0x0001: 0x0002);
-};
-MsgRobDonePP::MsgRobDonePP(const MsgRobDone& x) : content_(x) {};
-MsgRobDonePP* MsgRobDonePP::clone() const {return new MsgRobDonePP(*this);};
-MsgHeader* MsgRobDonePP::header() {return (MsgHeader*)&content_;};
-const MsgRobDone* MsgRobDonePP::content() const {
- return &content_;
-}
-bool MsgRobDonePP::isSuccess() const {
- return content_.status == 0x0001;
-};
-string MsgRobDonePP::render() const {
- ostringstream out;
- out << "RobDone: "
- << (isSuccess()? "successful": "unsuccessful");
- return out.str();
-};
-
-MsgRobLocationPP::MsgRobLocationPP(Point loc, double a, bool m) {
- content_.type = ROB_LOCATION;
- content_.len = sizeof(content_);
- content_.x = (float) loc.x; content_.y = (float) loc.y;
- content_.angle = (float) a;
- content_.moving = (m? 1: 0);
-};
-MsgRobLocationPP::MsgRobLocationPP(const MsgRobLocation& x) : content_(x) {};
-MsgRobLocationPP* MsgRobLocationPP::clone() const {return new MsgRobLocationPP(*this);};
-MsgHeader* MsgRobLocationPP::header() {return (MsgHeader*)&content_;};
-const MsgRobLocation* MsgRobLocationPP::content() const {
- return &content_;
-}
-bool MsgRobLocationPP::isMoving() const {return content_.moving==1;};
-string MsgRobLocationPP::render() const {
- ostringstream out;
- out << "RobLocation: "
- << Point(content_.x, content_.y) << ' '
- << content_.angle << " radians "
- << (isMoving()? "Moving": "Not moving");
- return out.str();
-};
-
-/*
-MsgPingPP::MsgPingPP(const string& handle) {
- content_.type = MsgIdPing;
- content_.len = sizeof(content_);
- handle.copy(content_.handle, 0xff);
- content_.handle[handle.size()] = '\0';
-};
-MsgPingPP::MsgPingPP(const MsgPing& x) : content_(x) {};
-MsgPingPP* MsgPingPP::clone() const {return new MsgPingPP(*this);};
-MsgHeader* MsgPingPP::header() {return (MsgHeader*)&content_;};
-const MsgPing* MsgPingPP::content() const {return &content_;};
-string MsgPingPP::handle() const {return content_.handle;};
-string MsgPingPP::render() const {
- ostringstream out;
- out << "Ping: " << content_.handle;
- return out.str();
-};
-*/
-
-MsgActionAckPP::MsgActionAckPP() {
- content_.type = ROB_ACTION_ACK;
- content_.len = sizeof(content_);
-};
-MsgActionAckPP::MsgActionAckPP(const MsgActionAck& x) : content_(x) {};
-MsgActionAckPP* MsgActionAckPP::clone() const {return new MsgActionAckPP(*this);};
-MsgHeader* MsgActionAckPP::header() {return (MsgHeader*)&content_;};
-const MsgActionAck* MsgActionAckPP::content() const {return &content_;};
-string MsgActionAckPP::render() const {
- ostringstream out;
- out << "PlayActionAck: ";
- return out.str();
-};
-
-MsgMapReqPP::MsgMapReqPP() {
- content_.type = REQ_IMAGE;
- content_.len = sizeof(content_);
-};
-MsgMapReqPP::MsgMapReqPP(const MsgMapReq& x) : content_(x) {};
-MsgMapReqPP* MsgMapReqPP::clone() const {return new MsgMapReqPP(*this);};
-MsgHeader* MsgMapReqPP::header() {return (MsgHeader*)&content_;};
-const MsgMapReq* MsgMapReqPP::content() const {return &content_;};
-string MsgMapReqPP::render() const {
- ostringstream out;
- out << "MapReq: ";
- return out.str();
-};
-int MsgMapReqPP::getInvoice() const {
- return content_.invoice;
-}
-
-MsgMapPP::MsgMapPP() {
- content_ = (MsgMap *)malloc(sizeof(MsgMap));
- content_->type = ROB_IMAGE;
- content_->len = sizeof(content_);
- content_->array_length = 0;
-}
-MsgMapPP::MsgMapPP(const MsgMap& x) {
- content_ = (MsgMap *)malloc(x.getSize());
- memcpy(content_, &x, x.getSize());
-}
-MsgMapPP::~MsgMapPP() {free(content_);}
-MsgMapPP* MsgMapPP::clone() const {return new MsgMapPP(*(this->content_));}
-MsgHeader* MsgMapPP::header() {return (MsgHeader*)content_;}
-const MsgMap* MsgMapPP::content() const {return content_;}
-int MsgMapPP::getWidth() const {return content_->x;}
-int MsgMapPP::getHeight() const {return content_->y;}
-int MsgMapPP::getInvoice() const {return content_->invoice;}
-const char* MsgMapPP::getImageData() const {return (const char*)content_->map;}
-int MsgMapPP::getImageDataSize() const {return content_->array_length;}
-string MsgMapPP::render() const {
- ostringstream out;
- out << "Map: ";
- return out.str();
-}
-
-MsgHeader Msg::construct_MsgHeader(uint16_t _type) {
- MsgHeader retval;
- retval.type = _type;
-#ifdef WIN32
- struct __timeb64 timebuffer;
- _ftime64(&timebuffer);
-#else
- struct timeb timebuffer;
- ftime(&timebuffer);
-#endif
- retval.tstamp = timebuffer.time + (float)timebuffer.millitm/1000;
- return retval;
-}
-
-MsgCmdTask Msg::construct_MsgCmdTask(uint16_t _type) {
- MsgCmdTask retval;
- retval.type = _type;
-#ifdef WIN32
- struct __timeb64 timebuffer;
- _ftime64(&timebuffer);
-#else
- struct timeb timebuffer;
- ftime(&timebuffer);
-#endif
- retval.tstamp = timebuffer.time + (float)timebuffer.millitm/1000;
- retval.priority = 1;
- retval.taskid = iTaskCounter++;
- return retval;
-}
-
-MsgCmdAction Msg::construct_MsgCmdAction(const string& _action) {
- MsgCmdAction retval;
- retval.type = CMD_ACTION;
-#ifdef WIN32
- struct __timeb64 timebuffer;
- _ftime64(&timebuffer);
-#else
- struct timeb timebuffer;
- ftime(&timebuffer);
-#endif
- retval.tstamp = timebuffer.time + (float)timebuffer.millitm/1000;
- retval.priority = 1;
- retval.taskid = iTaskCounter++;
- _action.copy(retval.action, _action.size());
- retval.len = retval.getSize();
- return retval;
-}
-
-// **************** SetPos ****************************************************
-
-const char *const MsgCmdSetPos::scan_template = "setpos (%d %d) %d";
-
-bool MsgCmdSetPos::parse() {
- int numscanned = sscanf(content_.action, scan_template, x_, y_, angle_);
- if(numscanned != 3) {
- cerr << "problem parsing setpos: \"" << content_.action
- << "\" with scan template: " << scan_template << endl;
- cerr << "got only " << numscanned << " tokens" << endl;
- return false;
- }
- return true;
-}
-
-MsgCmdSetPos::MsgCmdSetPos(const Boeing::MsgCmdAction& x) : MsgCmdActionPP(x) {
- parse();
-}
-
-MsgCmdSetPos::MsgCmdSetPos(double x, double y, double a) : x_(x), y_(y), angle_(a) {
- ostringstream cmd_string;
- cmd_string << "setpos (" << x << ' ' << y << ") " << a;
- content_ = construct_MsgCmdAction(cmd_string.str());
-}
-
-double MsgCmdSetPos::getX() const {return x_;}
-double MsgCmdSetPos::getY() const {return y_;}
-double MsgCmdSetPos::getAngle() const {return angle_;}
-
-string MsgCmdSetPos::action_string() const {
- ostringstream out;
- out << "setpos (" << x_ << ' ' << y_ << ") " << angle_;
- return out.str();
-}
More information about the TeamTalk-developers
mailing list