Commit eb88e395 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

tcp and jgrafchart examples tweaks

parent 2e0fa68f
......@@ -8,6 +8,8 @@ LCLIBDIR=${LCDIR}/lib/c
LCFILE=jg
AUX=enc.c dec.c
TLCFILE=turtle1
TAUX=turtle_enc.c turtle_dec.c
${JAVA_PKG}/gen/foo.java: ${LCFILE}.lc
${LCC} --javapackage=${JAVA_PKG}.gen --java=${JAVA_PKG}/gen $<
......@@ -35,14 +37,19 @@ client: client.c ${LCFILE}.c ${AUX} ${AUX:.c=.h}
testserver: testserver.c ${LCFILE}.c ${AUX} ${AUX:.c=.h}
${CC} -o $@ testserver.c ${AUX} ${LCFILE}.c -I${LCLIBDIR} -L${LCLIBDIR} -llabcomm
turtleclient: turtleclient.c ${TLCFILE}.c ${TAUX} ${TAUX:.c=.h}
${CC} -o $@ turtleclient.c ${TAUX} ${TLCFILE}.c -I${LCLIBDIR} -L${LCLIBDIR} -llabcomm
${LCFILE}.c : ${LCFILE}.lc
${LCC} -C ${LCFILE}.lc
all: client testserver ${JAVA_PKG}/server/TestServer.class ${JAVA_PKG}/client/TestClient.class
${TLCFILE}.c : ${TLCFILE}.lc
${LCC} -C ${TLCFILE}.lc
.PHONY: clean runclient runserver runjavaserver runjavaclient
all: client testserver ${JAVA_PKG}/server/TestServer.class ${JAVA_PKG}/client/TestClient.class turtleclient
.PHONY: clean runclient runserver runjavaserver runjavaclient turtleclient
clean :
rm ${LCFILE}.c ${LCFILE}.h client testserver
rm ${LCFILE}.c ${LCFILE}.h client testserver turtleclient
rm ${JAVA_PKG}/server/*.class ${JAVA_PKG}/client/*.class ${JAVA_PKG}/gen/*
runclient : client
......@@ -50,3 +57,6 @@ runclient : client
runserver : testserver
LD_LIBRARY_PATH=${LCLIBDIR} ./$< 9999
runtclient : turtleclient
LD_LIBRARY_PATH=${LCLIBDIR} ./$< localhost 8082
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <labcomm_fd_reader.h>
#include <labcomm_default_error_handler.h>
#include <labcomm_default_memory.h>
#include <labcomm_default_scheduler.h>
#include <stdio.h>
#include "turtle1.h"
static struct labcomm_encoder *encoder;
static void handle_pose(turtle1_pose *v, void *context) {
#if 1
printf("got pose\n");
#else
turtle1_velocity vel;
sleep(1);
labcomm_encode_turtle1_velocity(encoder, vel);
vel.angular = -1;
sleep(1);
labcomm_encode_turtle1_velocity(encoder, vel);
sleep(1);
vel.angular = -1;
labcomm_encode_turtle1_velocity(encoder, vel);
#endif
}
struct labcomm_decoder *turtle_dec_init(int fd, struct labcomm_encoder *e) {
struct labcomm_decoder *decoder;
encoder = e;
void *context = NULL;
decoder = labcomm_decoder_new(labcomm_fd_reader_new(
labcomm_default_memory, fd, 1),
labcomm_default_error_handler,
labcomm_default_memory,
labcomm_default_scheduler);
if (!decoder) {
printf("Failed to allocate decoder %s:%d\n", __FUNCTION__, __LINE__);
return (void *)0;
}
labcomm_decoder_register_turtle1_pose(decoder, handle_pose, context);
return decoder;
}
void turtle_dec_run(struct labcomm_decoder *decoder) {
printf("Decoding:\n");
labcomm_decoder_run(decoder);
printf("--- End Of File ---:\n");
}
void turtle_dec_cleanup(struct labcomm_decoder *decoder) {
labcomm_decoder_free(decoder);
}
#include <labcomm_fd_reader.h>
#include <labcomm_default_error_handler.h>
#include <labcomm_default_memory.h>
#include <labcomm_default_scheduler.h>
#include <stdio.h>
struct labcomm_decoder * turtle_dec_init(int fd, struct labcomm_encoder *e) ;
void turtle_dec_run(struct labcomm_decoder *decoder) ;
void turtle_dec_cleanup(struct labcomm_decoder *decoder) ;
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <labcomm_fd_writer.h>
#include <labcomm_default_error_handler.h>
#include <labcomm_default_memory.h>
#include <labcomm_default_scheduler.h>
#include "turtle1.h"
#include <stdio.h>
struct labcomm_encoder *turtle_enc_init( int fd) {
struct labcomm_encoder *encoder;
encoder = labcomm_encoder_new(labcomm_fd_writer_new(
labcomm_default_memory, fd, 1),
labcomm_default_error_handler,
labcomm_default_memory,
labcomm_default_scheduler);
labcomm_encoder_register_turtle1_velocity(encoder);
return encoder;
}
void turtle_enc_run(struct labcomm_encoder *encoder, turtle1_velocity *v) {
#if 0
jg_foo v;
v.b = 17.17;
v.c = 1742;
v.d = 4217;
v.e = "hello";
v.f = 17;
v.g = 42;
v.h = 2;
v.i = 42.42;
#endif
printf("Encoding for turtle1\n");
v->turtle_name="/turtlesim1/turtle1";
labcomm_encode_turtle1_velocity(encoder, v);
sleep(1);
printf("Encoding for turtle1\n");
v->angular *= -1;
labcomm_encode_turtle1_velocity(encoder, v);
sleep(1);
v->angular *= -1;
//v->h += 42000000;
labcomm_encode_turtle1_velocity(encoder, v);
}
void turtle_enc_cleanup(struct labcomm_encoder *encoder) {
labcomm_encoder_free(encoder);
}
#include <labcomm_fd_writer.h>
#include <labcomm_default_error_handler.h>
#include <labcomm_default_memory.h>
#include <labcomm_default_scheduler.h>
#include "turtle1.h"
struct labcomm_encoder *turtle_enc_init(int fd) ;
void turtle_enc_run(struct labcomm_encoder *encoder, turtle1_velocity *v) ;
void turtle_enc_cleanup(struct labcomm_encoder *encoder) ;
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include "turtle_dec.h"
#include "turtle_enc.h"
void error(const char *msg)
{
perror(msg);
exit(0);
}
void do_labcomm(int sockfd)
{
void *turtle_enc = turtle_enc_init(sockfd);
// void *turtle_dec = turtle_dec_init(sockfd, turtle_enc);
turtle1_velocity v;
v.linear=4;
v.angular=0.4;
turtle_enc_run(turtle_enc, &v);
// turtle_dec_run(turtle_dec);
// turtle_dec_cleanup(turtle_dec);
turtle_enc_cleanup(turtle_enc);
}
int main(int argc, char *argv[])
{
int sockfd, portno, n;
struct sockaddr_in serv_addr;
struct hostent *server;
char buffer[256];
if (argc < 3) {
fprintf(stderr,"usage %s hostname port\n", argv[0]);
exit(0);
}
portno = atoi(argv[2]);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
error("ERROR opening socket");
server = gethostbyname(argv[1]);
if (server == NULL) {
fprintf(stderr,"ERROR, no such host\n");
exit(0);
}
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
bcopy((char *)server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length);
serv_addr.sin_port = htons(portno);
if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
error("ERROR connecting");
do_labcomm(sockfd);
close(sockfd);
return 0;
}
......@@ -12,6 +12,9 @@ ${JAVA_PKG}/gen/FooSample.class: ${JAVA_PKG}/gen/FooSample.java
${JAVA_PKG}/server/TestServer.class: ${JAVA_PKG}/server/TestServer.java ${JAVA_PKG}/gen/FooSample.class
javac -cp ${CLASSPATH} $<
${JAVA_PKG}/server/OneShotServer.class: ${JAVA_PKG}/server/OneShotServer.java ${JAVA_PKG}/gen/FooSample.class
javac -cp ${CLASSPATH} $<
${JAVA_PKG}/client/TestClient.class: ${JAVA_PKG}/client/TestClient.java ${JAVA_PKG}/gen//FooSample.class
javac -cp ${CLASSPATH} $<
......@@ -20,6 +23,9 @@ ${JAVA_PKG}/client/TestClient.class: ${JAVA_PKG}/client/TestClient.java ${JAVA_P
runserver : ${JAVA_PKG}/server/TestServer.class
java -cp ${CLASSPATH} $(<:.class=)
runOSserver : ${JAVA_PKG}/server/OneShotServer.class
java -cp ${CLASSPATH} $(<:.class=)
runclient : ${JAVA_PKG}/client/TestClient.class
java -cp ${CLASSPATH} $(<:.class=)
......
......@@ -28,7 +28,6 @@ if __name__ == "__main__":
print data
except KeyError as e:
print 'KeyError : "%s"' % str(e)
break
except:
print 'exception...', sys.exc_info()[0]
break
all:
cd c ; make
cd csharp ; make
# cd csharp ; make
cd java ; make
test:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment