[TeamTalk 259]: [795] trunk/TeamTalk/Libraries/boeingLib: Importing updates from brett & co .
tk@edam.speech.cs.cmu.edu
tk at edam.speech.cs.cmu.edu
Mon Oct 1 11:57:06 EDT 2007
An HTML attachment was scrubbed...
URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20071001/5ea2800e/attachment.html
-------------- next part --------------
Modified: trunk/TeamTalk/Libraries/boeingLib/Makefile
===================================================================
--- trunk/TeamTalk/Libraries/boeingLib/Makefile 2007-09-28 23:00:09 UTC (rev 794)
+++ trunk/TeamTalk/Libraries/boeingLib/Makefile 2007-10-01 15:57:04 UTC (rev 795)
@@ -25,13 +25,13 @@
# Compilation options
#======================================================================#
-CC := g++-4.1
+CC := g++
# CFlags base
CFLAGS += -Wall -D_GNU_SOURCE
CFLAGS += $(CPU)
CFLAGS += -ffast-math
-CFLAGS += -g -O3
+CFLAGS += -g -O3 -fPIC
# uncomment to turn off asserts
# CFLAGS += -DNDEBUG
@@ -95,7 +95,7 @@
# start with empty libraries
-LIBS += $(MATH_LIBS) $(COMPRESS_LIBS) $(SCTP_LIBS)
+LIBS += $(MATH_LIBS) $(COMPRESS_LIBS) $(SCTP_LIBS) $(THREAD_LIBS)
# Each module will add to this
@@ -162,13 +162,13 @@
install: all_real
@echo "Installing to $(INSTALLDIR)"
@echo "Coping library files to $(INSTALLDIR_LIB)"
-
+
@if [ ! -d $(INSTALLDIR_LIB) ] ; then \
echo "Creating $(INSTALLDIR_LIB)"; \
mkdir $(INSTALLDIR_LIB) ; \
fi;
@cp $(LIB)/* $(INSTALLDIR_LIB)
-
+
@if [ ! -d $(INSTALLDIR_INCLUDE) ] ; then \
echo "Creating $(INSTALLDIR_INCLUDE)"; \
mkdir $(INSTALLDIR_INCLUDE) ; \
Modified: trunk/TeamTalk/Libraries/boeingLib/Makefile.config
===================================================================
--- trunk/TeamTalk/Libraries/boeingLib/Makefile.config 2007-09-28 23:00:09 UTC (rev 794)
+++ trunk/TeamTalk/Libraries/boeingLib/Makefile.config 2007-10-01 15:57:04 UTC (rev 795)
@@ -1,4 +1,4 @@
# Directory where lib and include directories will be placed
# For system wide usual use /usr/local/
-INSTALLDIR=~/rCommerce/software/external/boeingLib
+INSTALLDIR=~/software/external/boeingLib
Modified: trunk/TeamTalk/Libraries/boeingLib/boeing/boeing_map_packet.cc
===================================================================
--- trunk/TeamTalk/Libraries/boeingLib/boeing/boeing_map_packet.cc 2007-09-28 23:00:09 UTC (rev 794)
+++ trunk/TeamTalk/Libraries/boeingLib/boeing/boeing_map_packet.cc 2007-10-01 15:57:04 UTC (rev 795)
@@ -111,14 +111,14 @@
int new_major_dim,
unsigned char *raw_map) const {
bool changed = false;
- int j=0;
+ int j=0, k=0;
for(int i=0; i<array_length; i++) {
int run_length = (map[i]&0xFFFFFF00)>>8;
char run_value = (char) (map[i]&0x000000FF);
- int run_terminus = j+run_length;
- for(; j<run_terminus; j++)
+ for(; j<k+run_length; j++)
raw_map[j%old_major_dim*new_major_dim+j/old_major_dim] = run_value;
+ k=j;
changed |= (run_value != MAP_CELL_UNCHANGED);
}
return changed;
Modified: trunk/TeamTalk/Libraries/boeingLib/boeing/boeing_net.h
===================================================================
--- trunk/TeamTalk/Libraries/boeingLib/boeing/boeing_net.h 2007-09-28 23:00:09 UTC (rev 794)
+++ trunk/TeamTalk/Libraries/boeingLib/boeing/boeing_net.h 2007-10-01 15:57:04 UTC (rev 795)
@@ -14,6 +14,7 @@
#ifdef WIN32
#pragma pack(1)
#endif
+
#ifndef PACKED
#ifdef WIN32
#define PACKED
Modified: trunk/TeamTalk/Libraries/boeingLib/boeing/boeing_robot_client.cc
===================================================================
--- trunk/TeamTalk/Libraries/boeingLib/boeing/boeing_robot_client.cc 2007-09-28 23:00:09 UTC (rev 794)
+++ trunk/TeamTalk/Libraries/boeingLib/boeing/boeing_robot_client.cc 2007-10-01 15:57:04 UTC (rev 795)
@@ -57,7 +57,11 @@
int RobotClient::open(char const *h, int p)
{
printf("opening host %s:%d\n", h, p);
- if(p) port=p;
+ if (p>0) {
+ port=p;
+ } else {
+ port=ROBOT_PORT;
+ }
host=h;
// copy hostname
@@ -74,6 +78,7 @@
sock->set(-1,-1);
// open the socket
+
if (sock->connectClient(h,port) <= 0) {
fprintf(stderr, "ERROR: Cannot open client socket %s:%i\n", h, port);
return false;
@@ -327,11 +332,36 @@
return (NULL);
}
+MsgRobot const *RobotClient::waitForNextMessage(double timeout)
+{
+ if (!isConnected())
+ return NULL;
-int RobotClient::isConnected() const {
+ struct pollfd pfd;
+ pfd.fd=sock->getFD();
+ pfd.events=POLLIN;
+ pfd.revents=0;
+
+ int rv=poll(&pfd,1,(int)ceil(timeout*1e3));
+ if (rv<0) {
+ sock->disconnect();
+ printf("BoeingRobotClient::Connection error\n");
+ return NULL;
+ } else if (rv==0) {
+ // timeout
+ return NULL;
+ } else {
+ return getNextMessage();
+ }
+}
+
+
+int RobotClient::isConnected() const
+{
return sock->isConnected();
}
-int RobotClient::getFD(){
+int RobotClient::getFD() const
+{
return sock->getFD();
}
Modified: trunk/TeamTalk/Libraries/boeingLib/boeing/boeing_robot_client.h
===================================================================
--- trunk/TeamTalk/Libraries/boeingLib/boeing/boeing_robot_client.h 2007-09-28 23:00:09 UTC (rev 794)
+++ trunk/TeamTalk/Libraries/boeingLib/boeing/boeing_robot_client.h 2007-10-01 15:57:04 UTC (rev 795)
@@ -84,8 +84,12 @@
the id of the sending client */
MsgRobot const *getNextMessage();
+ /** waits for the next message and then returns it.
+ The timeout is in seconds */
+ MsgRobot const *waitForNextMessage(double timeout);
+
int isConnected() const;
- int getFD();
+ int getFD() const;
bool sendPacket(MsgHeader *msg);
Modified: trunk/TeamTalk/Libraries/boeingLib/boeing/boeing_robot_server.cc
===================================================================
--- trunk/TeamTalk/Libraries/boeingLib/boeing/boeing_robot_server.cc 2007-09-28 23:00:09 UTC (rev 794)
+++ trunk/TeamTalk/Libraries/boeingLib/boeing/boeing_robot_server.cc 2007-10-01 15:57:04 UTC (rev 795)
@@ -55,6 +55,10 @@
socket_s->set(-1,-1);
+ if (port<0) {
+ port=ROBOT_PORT;
+ }
+
// open the socket
if (socket_s->connectServer(port) <= 0) {
fprintf(stderr, "ERROR: Cannot open debug server socket %i\n", port);
Modified: trunk/TeamTalk/Libraries/boeingLib/coralshared/string_helper.cc
===================================================================
--- trunk/TeamTalk/Libraries/boeingLib/coralshared/string_helper.cc 2007-09-28 23:00:09 UTC (rev 794)
+++ trunk/TeamTalk/Libraries/boeingLib/coralshared/string_helper.cc 2007-10-01 15:57:04 UTC (rev 795)
@@ -219,48 +219,45 @@
//=== Pasring for filenames ===============================
-string removeExtension(char const *s)
+string removeExtension(string const &s)
{
- string str=s;
+ size_t i=s.rfind(".");
+ string str;
- int i=(int) str.rfind(".");
- if (i>=0)
- str.erase(i);
+ str.assign(s,0,i);
return str;
}
-string removePath(char const *s)
+string removePath(string const &s)
{
- string str=s;
-
- int i=(int) str.rfind("/");
- if (i>=0)
- str.erase(0,i+1);
+ size_t i=s.rfind("/");
+ string str;
+ if (i==string::npos) {
+ str=s;
+ } else {
+ str.assign(s,i+1,s.length()-i-1);
+ }
return str;
}
-string getExtension(char const *s)
+string getExtension(string const &s)
{
- string str=s,res;
-
- res.clear();
- int i=(int) str.rfind(".");
- if (i<=0)
- return res;
- res.assign(str,i+1,str.length()-1);
- return res;
+ string str;
+ size_t i=s.rfind(".");
+ if (i!=string::npos) {
+ str.assign(s,i+1,s.length()-i-1);
+ }
+ return str;
}
-string getPath(char const *s)
+string getPath(string const &s)
{
- string str=s;
- string res;
-
- res.clear();
- int i=(int) str.rfind("/");
- if (i>=0)
- res.assign(str,0,i);
- return res;
+ string str;
+ size_t i=s.rfind("/");
+ if (i!=string::npos) {
+ str.assign(s,0,i);
+ }
+ return str;
}
string replaceChar(char const *s,char c,char replace)
Modified: trunk/TeamTalk/Libraries/boeingLib/coralshared/string_helper.h
===================================================================
--- trunk/TeamTalk/Libraries/boeingLib/coralshared/string_helper.h 2007-09-28 23:00:09 UTC (rev 794)
+++ trunk/TeamTalk/Libraries/boeingLib/coralshared/string_helper.h 2007-10-01 15:57:04 UTC (rev 795)
@@ -68,11 +68,11 @@
//=== Pasring for filenames ===============================
-string removeExtension(char const *s);
-string removePath(char const *s);
+string removeExtension(string const &s);
+string removePath(string const &s);
-string getExtension(char const *s);
-string getPath(char const *s);
+string getExtension(string const &s);
+string getPath(string const &s);
string replaceChar(char const *s,char c,char replace);
Modified: trunk/TeamTalk/Libraries/boeingLib/coralshared/tcpsocket.cc
===================================================================
--- trunk/TeamTalk/Libraries/boeingLib/coralshared/tcpsocket.cc 2007-09-28 23:00:09 UTC (rev 794)
+++ trunk/TeamTalk/Libraries/boeingLib/coralshared/tcpsocket.cc 2007-10-01 15:57:04 UTC (rev 795)
@@ -352,6 +352,17 @@
return clients.size();
}
+void fillTimeout(double t,struct timeval &tv)
+{
+ if (t>0) {
+ double ts = floor(t);
+ tv.tv_sec = (long) ts;
+ tv.tv_usec = (long) ((t-ts)*1E6);
+ } else {
+ tv.tv_sec=tv.tv_usec=0;
+ }
+}
+
bool TCPSocket::readyForRecv(double timeout)
{
if (status <= 0)
@@ -359,14 +370,9 @@
// timeout field
struct timeval tv = {0, 0};
+ fillTimeout(timeout,tv);
- if (timeout>0) {
- double ts = floor(timeout);
- tv.tv_sec = (long) ts;
- tv.tv_usec = (long) ((ts-timeout)*1E6);
- }
-
if (status == Server) {
if (clients.empty())
return (false);
@@ -450,12 +456,14 @@
}
-bool TCPSocket::readyForSend()
+bool TCPSocket::readyForSend(double timeout)
{
if (status <= 0)
return 0;
struct timeval tv = {0, 0};
+ fillTimeout(timeout,tv);
+
fd_set fdvar;
int maxfd = 0;
FD_ZERO(&fdvar);
@@ -481,12 +489,14 @@
}
}
-bool TCPSocket::readyForAccept()
+bool TCPSocket::readyForAccept(double timeout)
{
Assert(status == Server, "not a server");
if (status == Server) {
struct timeval tv = {0, 0};
+ fillTimeout(timeout,tv);
+
fd_set fdvar;
FD_ZERO(&fdvar);
Modified: trunk/TeamTalk/Libraries/boeingLib/coralshared/tcpsocket.h
===================================================================
--- trunk/TeamTalk/Libraries/boeingLib/coralshared/tcpsocket.h 2007-09-28 23:00:09 UTC (rev 794)
+++ trunk/TeamTalk/Libraries/boeingLib/coralshared/tcpsocket.h 2007-10-01 15:57:04 UTC (rev 795)
@@ -140,8 +140,8 @@
// Returns if the socket can be written, read, or accepted without blocking.
bool readyForRecv(double timeout=0.0);
- bool readyForSend();
- bool readyForAccept();
+ bool readyForSend(double timeout=0.0);
+ bool readyForAccept(double timeout=0.0);
void print(sockaddr_in &a);
private:
Modified: trunk/TeamTalk/Libraries/boeingLib/coralshared/threadhelp.h
===================================================================
--- trunk/TeamTalk/Libraries/boeingLib/coralshared/threadhelp.h 2007-09-28 23:00:09 UTC (rev 794)
+++ trunk/TeamTalk/Libraries/boeingLib/coralshared/threadhelp.h 2007-10-01 15:57:04 UTC (rev 795)
@@ -12,13 +12,51 @@
public:
Thread() { thread_id=0; }
+ ~Thread() { cancel(); }
/// create the thread. True on success
int create(ThreadFn fn,void *params=NULL) {
return (pthread_create(&thread_id,NULL,fn,params)==0);
}
+ bool cancel() {
+ if (thread_id && pthread_cancel(thread_id)==0) {
+ thread_id=0;
+ return true;
+ }
+ return false;
+ }
+
+ void *join() {
+ void *rval=NULL;
+ if (thread_id && pthread_join(thread_id,&rval)==0) {
+ thread_id=0;
+ return rval;
+ }
+ return NULL;
+ }
+
+ // may not be posix compatible
+ void *tryJoin(bool &has_finished) {
+ void *rval=NULL;
+ has_finished=!(thread_id);
+ // if (thread_id && pthread_tryjoin_np(thread_id,&rval)==0) {
+ // thread_id=0;
+ // has_finished=true;
+ //}
+ return rval;
+ }
+
+ // does not return!!!
+ static void exit(void *v=NULL) {
+ pthread_exit(v);
+ }
+
+ static void checkCancel() { pthread_testcancel(); }
+
pthread_t getThreadID() const { return thread_id; }
+
+ bool isStarted() const { return thread_id>0; }
};
#endif
Modified: trunk/TeamTalk/Libraries/boeingLib/utils/Makefile.sub
===================================================================
--- trunk/TeamTalk/Libraries/boeingLib/utils/Makefile.sub 2007-09-28 23:00:09 UTC (rev 794)
+++ trunk/TeamTalk/Libraries/boeingLib/utils/Makefile.sub 2007-10-01 15:57:04 UTC (rev 795)
@@ -89,3 +89,38 @@
$(BIN)/$(TARGET): $(TEST_CONVERTER_OBJ) $(SRC_LIBS)
$(LINK_ECHO)
$(Q)$(CC) -o $@ $(TEST_CONVERTER_OBJ) $(SRC_LIBS) $(LIBS)
+
+
+#==== test_thread ======================================================#
+
+
+TARGET := test_thread
+SRC := utils/$(TARGET).cc
+
+TEST_THREAD_OBJ := $(SRC:.cc=.o)
+
+ALL_SRC += $(SRC)
+ALL_BIN_TARGETS += $(TARGET)
+
+$(TARGET): $(BIN)/$(TARGET)
+
+$(BIN)/$(TARGET): $(TEST_THREAD_OBJ) $(SRC_LIBS)
+ $(LINK_ECHO)
+ $(Q)$(CC) -o $@ $(TEST_THREAD_OBJ) $(SRC_LIBS) $(LIBS)
+
+#==== test_thread ======================================================#
+
+
+TARGET := test_zlib
+SRC := utils/$(TARGET).cc
+
+TEST_ZLIB_OBJ := $(SRC:.cc=.o)
+
+ALL_SRC += $(SRC)
+ALL_BIN_TARGETS += $(TARGET)
+
+$(TARGET): $(BIN)/$(TARGET)
+
+$(BIN)/$(TARGET): $(TEST_ZLIB_OBJ) $(SRC_LIBS)
+ $(LINK_ECHO)
+ $(Q)$(CC) -o $@ $(TEST_ZLIB_OBJ) $(SRC_LIBS) $(LIBS)
Modified: trunk/TeamTalk/Libraries/boeingLib/utils/test_robot_server.cc
===================================================================
--- trunk/TeamTalk/Libraries/boeingLib/utils/test_robot_server.cc 2007-09-28 23:00:09 UTC (rev 794)
+++ trunk/TeamTalk/Libraries/boeingLib/utils/test_robot_server.cc 2007-10-01 15:57:04 UTC (rev 795)
@@ -10,6 +10,7 @@
#include "boeing_robot_server.h"
#include "proghelp.h"
+#include "command_line_parser.h"
using namespace Boeing;
@@ -18,29 +19,20 @@
//=== Code ===============================================
-void PrintUsage(char const *pname)
-{
- printf("USAGE: %s [options]\n",pname);
- printf(" -h - this message\n");
-}
-
int main(int argc, char *argv[])
{
// Connect the stop signals
InitHandleStop();
- int c;
- while ((c=getopt(argc,argv,"h"))>0) {
- switch (c) {
- case 'h':
- default:
- PrintUsage(argv[0]);
- exit(1);
- }
- }
+ CommandLineParser parser;
+ parser.addUsage("n","Run with no delay in action");
+ parser.addUsage("f","Always fail action");
+ parser.addUsage("s","Always succeed action");
+ parser.parse(argc,argv);
+
RobotServer bserver;
// try to open the socket
@@ -50,7 +42,13 @@
exit(1);
}
+ bool always_fail=parser.hasOpt("f");
+ bool always_succeed=parser.hasOpt("s");
+ bool no_delay=parser.hasOpt("n");
+
printf("=== Running server stub ============\n");
+ printf("Running always_fail:%i always_succeed:%i no_delay:%i\n",
+ always_fail,always_succeed,no_delay);
// create the test image
static const size_t width=320;
@@ -74,78 +72,86 @@
while ((msg=bserver.getNextMessage())!=NULL) {
switch (msg->hdr.type) {
case CMD_ACTION:
- printf("(RE->ROBOT) action message\n");
- printf(" Action '%s'\n", msg->msg_action.action);
+ printf("(RE->ROBOT) action message\n");
+ printf(" Action '%s'\n", msg->msg_action.action);
- // sleep a random time
- sleep((rand()%10)+1);
-
- // send the response
- rv = ((rand()%10<1) ? FAILED : SUCCEEDED);
- printf(" Done with value %i, taskid %i\n",rv,msg->msg_action.taskid);
- bserver.sendActionAck(msg->msg_action.taskid,rv);
- break;
- case CMD_EVAL:
- printf("(RE->ROBOT) eval message\n");
- printf(" Eval '%s'\n", msg->msg_eval.eval);
-
- // sleep a random time
- sleep((rand()%10)+1);
-
- // send the response
- rv = ((rand()%10<1) ? FAILED : SUCCEEDED);
- printf(" Eval value %i\n",rv);
-
- bserver.sendEvalResult(msg->msg_eval.taskid,rv);
- break;
- case REQ_LOCATION:
- printf("Sending fake location: 1,2,0.1,false\n");
- bserver.sendLocation(1.0f,2.0f,0.1f,false);
- break;
- case REQ_IMAGE:
- printf("Sending fake image\n");
-
- printf("Opening JPEG writer with %i %i\n",(int)width,(int)height);
- jwriter.openMemGray(width,height);
- jwriter.writeData(image);
- bserver.sendJPEGImage((const unsigned char *)jwriter.getBuffer(),
- jwriter.getWrittenLength(),
- width,height,msg->msg_image.invoice);
- break;
- case CMD_HALT:
- printf("(RE->ROBOT) halt message\n");
- rv=SUCCEEDED;
- printf(" RobDone with value %i, taskid %i\n",rv,
- msg->msg_action.taskid);
- bserver.sendDone(msg->msg_action.taskid, rv);
- break;
- case CMD_GOTO:
- printf("(RE->ROBOT) cmd_goto message, nothing implemented\n");
- break;
- case CMD_HOME:
- printf("(RE->ROBOT) home message, nothing implemented\n");
- break;
- case CMD_FOLLOW:
- printf("(RE->ROBOT) follow message, nothing implemented\n");
- break;
- case CMD_COVER:
- printf("(RE->ROBOT) cover message, nothing implemented\n");
- break;
- case CMD_SETPOS:
- printf("(RE->ROBOT) setpos message, nothing implemented\n");
- break;
- case CMD_PAUSE:
- printf("(RE->ROBOT) pause message, nothing implemented\n");
- // bserver.sendPlayHalt();
- break;
- case CMD_RESUME:
- printf("(RE->ROBOT) resume message, nothing implemented\n");
- break;
- default:
- printf("(RE->ROBOT) Unknown mesasge %i\n", msg->hdr.type);
+ // sleep a random time
+ if (!no_delay) {
+ sleep((rand()%10)+1);
+ }
+
+ // send the response
+ if (always_succeed) {
+ rv=SUCCEEDED;
+ } else if (always_fail) {
+ rv=FAILED;
+ } else {
+ rv = ((rand()%10<1) ? FAILED : SUCCEEDED);
+ }
+ printf(" Done with value %i, taskid %i\n",rv,msg->msg_action.taskid);
+ bserver.sendActionAck(msg->msg_action.taskid,rv);
+ break;
+ case CMD_EVAL:
+ printf("(RE->ROBOT) eval message\n");
+ printf(" Eval '%s'\n", msg->msg_eval.eval);
+
+ // sleep a random time
+ //sleep((rand()%10)+1);
+
+ // send the response
+ rv = ((rand()%10<1) ? FAILED : SUCCEEDED);
+ printf(" Eval value %i\n",rv);
+
+ bserver.sendEvalResult(msg->msg_eval.taskid,rv);
+ break;
+ case REQ_LOCATION:
+ printf("Sending fake location: 1,2,0.1,false\n");
+ bserver.sendLocation(1.0f,2.0f,0.1f,false);
+ break;
+ case REQ_IMAGE:
+ printf("Sending fake image\n");
+
+ printf("Opening JPEG writer with %i %i\n",(int)width,(int)height);
+ jwriter.openMemGray(width,height);
+ jwriter.writeData(image);
+ bserver.sendJPEGImage((const unsigned char *)jwriter.getBuffer(),
+ jwriter.getWrittenLength(),
+ width,height,msg->msg_image.invoice);
+ break;
+ case CMD_HALT:
+ printf("(RE->ROBOT) halt message\n");
+ rv=SUCCEEDED;
+ printf(" RobDone with value %i, taskid %i\n",rv,
+ msg->msg_action.taskid);
+ bserver.sendDone(msg->msg_action.taskid, rv);
+ break;
+ case CMD_GOTO:
+ printf("(RE->ROBOT) cmd_goto message, nothing implemented\n");
+ break;
+ case CMD_HOME:
+ printf("(RE->ROBOT) home message, nothing implemented\n");
+ break;
+ case CMD_FOLLOW:
+ printf("(RE->ROBOT) follow message, nothing implemented\n");
+ break;
+ case CMD_COVER:
+ printf("(RE->ROBOT) cover message, nothing implemented\n");
+ break;
+ case CMD_SETPOS:
+ printf("(RE->ROBOT) setpos message, nothing implemented\n");
+ break;
+ case CMD_PAUSE:
+ printf("(RE->ROBOT) pause message, nothing implemented\n");
+ // bserver.sendPlayHalt();
+ break;
+ case CMD_RESUME:
+ printf("(RE->ROBOT) resume message, nothing implemented\n");
+ break;
+ default:
+ printf("(RE->ROBOT) Unknown mesasge %i\n", msg->hdr.type);
}
}
- usleep(500*1000);
+ usleep(150*1000);
}
bserver.close();
More information about the TeamTalk-developers
mailing list