Skip to content
Snippets Groups Projects
Commit 86728095 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

migrated example from metadata branch. commented out broken python encoder

parent dbcb1907
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
(cd ../..; make all) (cd ../..; make all)
mkdir -p gen mkdir -p gen
java -jar ../../compiler/labComm.jar --java=gen --c=gen/simple.c --h=gen/simple.h --python=gen/simple.py simple.lc java -jar ../../compiler/labcomm_compiler.jar --java=gen --c=gen/simple.c --h=gen/simple.h --python=gen/simple.py simple.lc
javac -cp ../../lib/java/labcomm20141009.jar:. gen/*.java Encoder.java Decoder.java javac -cp ../../lib/java/labcomm20141009.jar:. gen/*.java Encoder.java Decoder.java
...@@ -20,7 +20,7 @@ gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \ ...@@ -20,7 +20,7 @@ gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \
# For version 2006 # For version 2006
mkdir -p gen06 mkdir -p gen06
java -jar ../../compiler/labComm.jar --ver=2006 --java=gen06 --c=gen06/simple.c --h=gen06/simple.h --python=gen06/simple.py simple.lc java -jar ../../compiler/labcomm_compiler.jar --ver=2006 --java=gen06 --c=gen06/simple.c --h=gen06/simple.h --python=gen06/simple.py simple.lc
javac -cp ../../lib/java/labcomm2006.jar:. gen06/*.java Encoder06.java Decoder06.java javac -cp ../../lib/java/labcomm2006.jar:. gen06/*.java Encoder06.java Decoder06.java
......
...@@ -5,7 +5,7 @@ import java.io.InputStream; ...@@ -5,7 +5,7 @@ import java.io.InputStream;
import se.lth.control.labcomm.DecoderChannel; import se.lth.control.labcomm.DecoderChannel;
public class Decoder public class Decoder
implements twoLines.Handler implements twoLines.Handler, theint.Handler, Comment.Handler//, Typedef.Handler
{ {
...@@ -16,6 +16,9 @@ public class Decoder ...@@ -16,6 +16,9 @@ public class Decoder
{ {
decoder = new DecoderChannel(in); decoder = new DecoderChannel(in);
twoLines.register(decoder, this); twoLines.register(decoder, this);
theint.register(decoder,this);
Comment.register(decoder, this);
//Typedef.register(decoder, this);
try { try {
System.out.println("Running decoder."); System.out.println("Running decoder.");
...@@ -39,6 +42,20 @@ public class Decoder ...@@ -39,6 +42,20 @@ public class Decoder
System.out.println(" Line l2: "+genLine(d.l2)); System.out.println(" Line l2: "+genLine(d.l2));
} }
public void handle_theint(int d) throws java.io.IOException {
System.out.println("Got theint: "+d);
}
public void handle_Comment(Comment c) throws java.io.IOException {
System.out.print("Decoder got Comment: ");
System.out.println("id: "+c.id);
System.out.println("comment: "+c.comment);
}
//public void handle_Typedef(Typedef t) throws java.io.IOException {
// System.out.print("Decoder got Typedef: ");
// t.dump();
//}
public static void main(String[] arg) throws Exception { public static void main(String[] arg) throws Exception {
Decoder example = new Decoder( Decoder example = new Decoder(
......
...@@ -17,6 +17,19 @@ public class Encoder ...@@ -17,6 +17,19 @@ public class Encoder
{ {
encoder = new EncoderChannel(out); encoder = new EncoderChannel(out);
twoLines.register(encoder); twoLines.register(encoder);
theint.register(encoder);
//LabCommEncoder.MetaDataTransaction t = encoder.beginMetaData(twoLines.class);
////LabCommEncoder.MetaDataTransaction t = encoder.beginMetaData();
//Comment.register(t, false);
//Comment c = new Comment();
//c.id = encoder.getTypeId(twoLines.class);
//c.comment = "Test comment";
//Comment.encode(t,c);
//t.commit();
//t = encoder.beginMetaData(null);
//afoo.register(t, false);
//afoo.encode(t, new foo());
//t.commit();
} }
public void doEncode() throws java.io.IOException { public void doEncode() throws java.io.IOException {
...@@ -74,6 +87,8 @@ public class Encoder ...@@ -74,6 +87,8 @@ public class Encoder
System.out.println("Encoding theTwoLines"); System.out.println("Encoding theTwoLines");
twoLines.encode(encoder, x); twoLines.encode(encoder, x);
theint.encode(encoder, 1337);
} }
......
all: LCDIR=../..
LCCJAR=${LCDIR}/compiler/labcomm_compiler.jar # the LabComm compiler
LCLJAR=${LCDIR}/lib/java/labcomm.jar # the LabComm library
EXECUTABLES=example_encoder example_decoder Encoder.class Decoder.class Encoder.exe Decoder.exe
include ${LCDIR}/lib/c/os_compat.mk
GENDIR=gen
.PHONY: all cleanbuild clean distclean build run allall buildcs runwcs
all: cleanbuild run
allall: clean build buildcs runwcs
###############################################
### dependencies and parts ####################
###############################################
LCC=java -jar ${LCCJAR}
CLASSPATH=.:${LCLJAR}
${LCCJAR} :
$MAKE -C ${LCDIR} make-compiler
${LCLJAR} :
$MAKE -C ${LCDIR} labcomm.jar
cleanbuild: clean build
labcomm.dll:
ln -sf ../../lib/csharp/labcomm.dll $@
Encoder.exe: Encoder.cs gen/test.cs labcomm.dll Makefile
mcs -out:$@ $(filter %.cs, $^) -lib:../../lib/csharp/ -r:labcomm
chmod a+x $@
Decoder.exe: Decoder.cs gen/test.cs labcomm.dll Makefile
mcs -out:$@ $(filter %.cs, $^) -lib:../../lib/csharp/ -r:labcomm
chmod a+x $@
build :
mkdir -p ${GENDIR}
java -jar ${LCDIR}/compiler/labcomm_compiler.jar --java=${GENDIR} --c=${GENDIR}/test.c --h=${GENDIR}/test.h --python=${GENDIR}/test.py --cs=${GENDIR}/test.cs test.lc
javac -cp ${LCDIR}/lib/java/labcomm.jar:. ${GENDIR}/*.java Encoder.java Decoder.java
${CC} ${CFLAGS} ${LDFLAGS} -Wall -Werror -Wno-unused-function \
-I. -I${LCDIR}/lib/c -L${LCDIR}/lib/c \
-o example_encoder example_encoder.c ${GENDIR}/test.c \
-llabcomm20141009
${CC} ${CFLAGS} ${LDFLAGS} -Wall -Werror -I . -I ${LCDIR}/lib/c -L${LCDIR}/lib/c \
-o example_decoder example_decoder.c ${GENDIR}/test.c \
-llabcomm20141009
buildcs: Encoder.exe Decoder.exe
run:
export LD_LIBRARY_PATH=${LCDIR}/lib/c/
@echo
@echo "********************************************"
@echo "*** ************ running example for version 2014 ***"
@echo "********************************************"
@echo
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Encoder encoded_data_j
@echo "************ running Java decoder: *****************"
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_j
@echo "************ running C decoder: *****************"
@./example_decoder encoded_data_j
@echo "************ running python decoder (from wiki_example):"
@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_j LabComm20141009
@echo "************ running C encoder: *****************"
@./example_encoder encoded_data_c
@echo "************ running Java decoder: *****************"
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_c
@echo "************ running C decoder: *****************"
@./example_decoder encoded_data_c
@echo "************ running python decoder (from wiki_example):"
@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_c LabComm20141009
# @echo "************ running python encoder: *****************"
# @PYTHONPATH=${LCDIR}/lib/python:${GENDIR} ./example_encoder.py encoded_data_p LabComm20141009
@echo "************ running Java decoder: *****************"
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_p
@echo "************ running C decoder: *****************"
@./example_decoder encoded_data_p
@echo "************ running python decoder (from wiki_example):"
PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_p LabComm20141009
runwcs: Encoder.exe Decoder.exe
export LD_LIBRARY_PATH=${LCDIR}/lib/c/
@echo
@echo "********************************************"
@echo "*** ************ running example for version 2014 ***"
@echo "********************************************"
@echo
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Encoder encoded_data_j
@echo "************ running Java decoder: *****************"
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_j
@echo "************ running C decoder: *****************"
@./example_decoder encoded_data_j
@echo "************ running python decoder (from wiki_example):"
@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_j LabComm2014
@echo "************ running C# decoder: *****************"
@./Decoder.exe encoded_data_j
@echo "************ running C encoder: *****************"
@./example_encoder encoded_data_c
@echo "************ running Java decoder: *****************"
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_c
@echo "************ running C decoder: *****************"
@./example_decoder encoded_data_c
@echo "************ running python decoder (from wiki_example):"
@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_c LabComm20141009
@echo "************ running C# decoder: *****************"
@./Decoder.exe encoded_data_c
# @echo "************ running python encoder: *****************"
# @PYTHONPATH=${LCDIR}/lib/python:${GENDIR} ./example_encoder.py encoded_data_p LabComm20141009
@echo "************ running Java decoder: *****************"
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_p
@echo "************ running C decoder: *****************"
@./example_decoder encoded_data_p
@echo "************ running python decoder (from wiki_example):"
PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_p LabComm20141009
@echo "************ running C# decoder: *****************"
@./Decoder.exe encoded_data_p
@echo "************ running C# encoder: *****************"
@./Encoder.exe encoded_data_cs
@echo "************ running Java decoder: *****************"
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_cs
@echo "************ running C decoder: *****************"
@./example_decoder encoded_data_cs
@echo "************ running python decoder (from wiki_example):"
@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_cs LabComm20141009
@echo "************ running C# decoder: *****************"
@./Decoder.exe encoded_data_cs
clean: clean:
rm -rf ${GENDIR}
distclean: distclean: clean
rm -rf gen rm -f ${EXECUTABLES}
rm -f encoded_data
### Example compile script, showing the steps required to build a labcomm application
### (including compiler and libs).
# For current version (2013)
(cd ../..; make all)
mkdir -p gen
java -jar ../../compiler/labComm.jar --java=gen --c=gen/test.c --h=gen/test.h --python=gen/test.py test.lc
javac -cp ../../lib/java/labcomm20141009.jar:. gen/*.java Encoder.java Decoder.java
# for macOS, add -DLABCOMM_COMPAT=\"labcomm_compat_osx.h\" \
gcc -Wall -Werror -Wno-unused-function \
-I. -I../../lib/c -L../../lib/c \
-o example_encoder example_encoder.c gen/test.c \
-llabcomm20141009
gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \
-o example_decoder example_decoder.c gen/test.c \
-llabcomm20141009
#-Tlabcomm.linkscript
...@@ -15,6 +15,14 @@ static void handle_test_twoLines(test_twoLines *v,void *context) { ...@@ -15,6 +15,14 @@ static void handle_test_twoLines(test_twoLines *v,void *context) {
v->l2.end.x.val, v->l2.end.y.val); v->l2.end.x.val, v->l2.end.y.val);
} }
static void handle_test_theint(test_theint *v,void *context) {
printf("Got theint. %d\n", *v);
}
static void handle_test_Comment(test_Comment *v,void *context) {
printf("Got comment (0x%x): %s\n", v->id, v->comment);
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
int fd; int fd;
struct labcomm_decoder *decoder; struct labcomm_decoder *decoder;
...@@ -34,6 +42,8 @@ int main(int argc, char *argv[]) { ...@@ -34,6 +42,8 @@ int main(int argc, char *argv[]) {
} }
labcomm_decoder_register_test_twoLines(decoder, handle_test_twoLines, context); labcomm_decoder_register_test_twoLines(decoder, handle_test_twoLines, context);
labcomm_decoder_register_test_theint(decoder, handle_test_theint, context);
labcomm_decoder_register_test_Comment(decoder, handle_test_Comment, context);
printf("Decoding:\n"); printf("Decoding:\n");
labcomm_decoder_run(decoder); labcomm_decoder_run(decoder);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "gen/test.h" #include "gen/test.h"
#include <stdio.h> #include <stdio.h>
extern struct labcomm_signature labcomm_signature_test_twoLines;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
int fd; int fd;
struct labcomm_encoder *encoder; struct labcomm_encoder *encoder;
...@@ -22,6 +23,16 @@ int main(int argc, char *argv[]) { ...@@ -22,6 +23,16 @@ int main(int argc, char *argv[]) {
labcomm_default_scheduler); labcomm_default_scheduler);
labcomm_encoder_register_test_twoLines(encoder); labcomm_encoder_register_test_twoLines(encoder);
#ifdef OLD_METADATA
struct labcomm_encoder *mdt = labcomm_metadata_begin(encoder,
&labcomm_signature_test_twoLines);
labcomm_encoder_register_test_Comment(mdt);
test_Comment comment;
comment.id = 17;
comment.comment = "This is a metadata comment...";
labcomm_encode_test_Comment(mdt, &comment);
labcomm_metadata_end(mdt);
#endif
test_twoLines tl; test_twoLines tl;
tl.l1.start.x.val = 11; tl.l1.start.x.val = 11;
......
export LD_LIBRARY_PATH=../../lib/c/
echo
echo "********************************************"
echo "*** Running example for version 2013 ***"
echo "********************************************"
echo
java -cp .:../../lib/java/labcomm20141009.jar:gen Encoder encoded_data
echo "running Java decoder:"
java -cp .:../../lib/java/labcomm20141009.jar:gen Decoder encoded_data
echo "running C decoder:"
./example_decoder encoded_data
echo "running python decoder (from wiki_example):"
PYTHONPATH=../../lib/python ../wiki_example/example_decoder.py encoded_data LabComm20141009
echo "running C encoder:"
./example_encoder encoded_data
echo "running Java decoder:"
java -cp .:../../lib/java/labcomm20141009.jar:gen Decoder encoded_data
echo "running C decoder:"
./example_decoder encoded_data
echo "running python decoder (from wiki_example):"
PYTHONPATH=../../lib/python ../wiki_example/example_decoder.py encoded_data LabComm20141009
echo "running python encoder:"
PYTHONPATH=../../lib/python:gen ./example_encoder.py encoded_data2
echo "running Java decoder:"
java -cp .:../../lib/java/labcomm20141009.jar:gen Decoder encoded_data2
echo "running C decoder:"
./example_decoder encoded_data2
...@@ -12,14 +12,34 @@ typedef struct { ...@@ -12,14 +12,34 @@ typedef struct {
point end; point end;
} line; } line;
typedef int anint;
typedef struct { typedef struct {
int a; anint a;
int b; anint b;
boolean c; boolean c;
} foo; } foo;
sample anint theint;
sample struct { sample struct {
line l1; line l1;
line l2; line l2;
foo f; foo f;
} twoLines; } twoLines;
sample line fixedLineArray[2];
sample line varLineArray[_];
sample struct {
int x;
int y;
} structArray[2];
sample struct {
int id;
string comment;
} Comment; // For use in metadata
sample foo afoo; // to test unregistered metadata
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment