Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • anders_blomdell/labcomm
  • klaren/labcomm
  • tommyo/labcomm
  • erikj/labcomm
  • sven/labcomm
5 results
Show changes
Showing
with 352 additions and 109 deletions
typedef struct {
(foo:bar) int val;
} coord;
typedef int anInt;
typedef void avoid;
sample (function:"a trigger")(foo:bar) avoid doavoid;
sample (a:b) "A struct: an int and a ref." struct {
(e:f)(c:d) int x;
sample reference;
} intAndRef;
typedef struct {
coord x;
coord y;
} point;
typedef struct {
point start;
point end;
} line;
typedef struct {
int a;
int b;
boolean c;
} foo;
sample struct {
(name:l1)line l1;
(name:l2)line l2;
(b:"kalle anka")(c:hejdu)(a:"kalle anka")foo f;
} twoLines;
sample struct {
int a;
int b;
} twoInts;
sample anInt theFirstInt;
sample anInt theSecondInt;
sample struct {
struct {
int x;
int y;
} s1;
struct {
int a;
int b;
} s2;
int i;
double double_array[2,3,_][3][_];
} twoStructsAndInt;
data.java
example.c
example.cs
example.encoded
example.h
example.javaencoded
example.py
example_encoder
log_message.java
GENERATED=\
data.java \
example.c \
example.cs \
example.encoded \
example.h \
example.javaencoded \
example.py \
example_encoder \
log_message.java
all:
test:
./run
clean:
rm -f $(GENERATED) *.class
distclean: clean
/*
sample float data;
*/
import java.io.IOException;
import se.lth.control.labcomm.LabCommDecoder;
import se.lth.control.labcomm.LabCommDispatcher;
import se.lth.control.labcomm.LabCommEncoder;
import se.lth.control.labcomm.LabCommHandler;
import se.lth.control.labcomm.LabCommSample;
public class data implements LabCommSample {
public interface Handler extends LabCommHandler {
public void handle_data(float value) throws Exception;
}
public static void register(LabCommDecoder d, Handler h) throws IOException {
d.register(new Dispatcher(), h);
}
public static void register(LabCommEncoder e) throws IOException {
e.register(new Dispatcher());
}
private static class Dispatcher implements LabCommDispatcher {
public Class getSampleClass() {
return data.class;
}
public String getName() {
return "data";
}
public byte[] getSignature() {
return signature;
}
public void decodeAndHandle(LabCommDecoder d,
LabCommHandler h) throws Exception {
((Handler)h).handle_data(data.decode(d));
}
}
public static void encode(LabCommEncoder e, float value) throws IOException {
e.begin(data.class);
e.encodeFloat(value);
e.end(data.class);
}
public static float decode(LabCommDecoder d) throws IOException {
float result;
result = d.decodeFloat();
return result;
}
private static byte[] signature = new byte[] {
37,
};
}
#!/usr/bin/python
import labcomm
import labcomm2014
import sys
if __name__ == "__main__":
d = labcomm.Decoder(labcomm.StreamReader(open(sys.argv[1])))
version = sys.argv[2] if len(sys.argv) == 3 else "LabComm2014"
d = labcomm2014.Decoder(labcomm2014.StreamReader(open(sys.argv[1])), version)
while True:
try:
data,decl = d.decode()
if data:
print data
except:
except Exception, e:
print e
break
......@@ -4,24 +4,24 @@ import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm2014.DecoderChannel;
import se.lth.control.labcomm2014.EncoderChannel;
public class example_decoder_encoder
implements data.Handler, log_message.Handler
{
LabCommDecoderChannel decoder;
LabCommEncoderChannel encoder;
DecoderChannel decoder;
EncoderChannel encoder;
public example_decoder_encoder(InputStream in, OutputStream out)
throws Exception
{
decoder = new LabCommDecoderChannel(in);
decoder = new DecoderChannel(in);
log_message.register(decoder, this);
data.register(decoder, this);
encoder = new LabCommEncoderChannel(out);
encoder = new EncoderChannel(out);
log_message.register(encoder);
data.register(encoder);
......
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <labcomm_fd_reader.h>
#include <labcomm_fd_writer.h>
#include <labcomm2014.h>
#include <labcomm2014_default_memory.h>
#include <labcomm2014_fd_reader.h>
#include <labcomm2014_fd_writer.h>
#include "example.h"
int main(int argc, char *argv[]) {
int fd;
struct labcomm_encoder *encoder;
struct labcomm2014_encoder *encoder;
struct labcomm2014_writer *labcomm2014_fd_writer;
int i, j;
fd = open("example.encoded", O_WRONLY|O_CREAT|O_TRUNC, 0644);
encoder = labcomm_encoder_new(labcomm_fd_writer, &fd, NULL, NULL);
labcomm_encoder_register_example_log_message(encoder);
labcomm_encoder_register_example_data(encoder);
labcomm2014_fd_writer = labcomm2014_fd_writer_new(labcomm2014_default_memory, fd, 1);
encoder = labcomm2014_encoder_new(labcomm2014_fd_writer, NULL,
labcomm2014_default_memory, NULL);
labcomm2014_encoder_register_example_log_message(encoder);
labcomm2014_encoder_register_example_data(encoder);
for (i = 0 ; i < argc ; i++) {
example_log_message message;
......@@ -24,11 +29,12 @@ int main(int argc, char *argv[]) {
message.line.a[j].last = (j == message.line.n_0 - 1);
message.line.a[j].data = argv[j + 1];
}
labcomm_encode_example_log_message(encoder, &message);
labcomm2014_encode_example_log_message(encoder, &message);
free(message.line.a);
}
for (i = 0 ; i < argc ; i++) {
float f = i;
labcomm_encode_example_data(encoder, &f);
labcomm2014_encode_example_data(encoder, &f);
}
return 0;
}
#!/bin/sh
# Auto generate code from .lc file
java -jar ../../compiler/labComm.jar \
java -jar ../../compiler/labcomm2014_compiler.jar \
--c=example.c --h=example.h \
--java=. \
--cs=example.cs \
--python=example.py \
example.lc
example.lc || exit 1
# Compile executables
(cd ../../lib/c; make liblabcomm.a)
(cd ../../lib/c; make all || exit 1)
gcc -o example_encoder -I ../../lib/c/ \
example_encoder.c \
example.c \
../../lib/c/liblabcomm.a
gcc -Wall -Werror -o example_encoder -I../../lib/c/2014 \
example_encoder.c \
example.c \
../../lib/c/liblabcomm2014.a || exit 1
javac -cp ../../lib/java:. *.java
javac -cp ../../lib/java/labcomm2014.jar:. *.java || exit 1
# Run through all executables (c->java->Python)
./example_encoder one two
java -cp ../../lib/java:. example_decoder_encoder example.encoded example.javaencoded
PYTHONPATH=../../lib/python ./example_decoder.py example.javaencoded
./example_encoder one two || exit 1
java -cp ../../lib/java/labcomm2014.jar:. example_decoder_encoder example.encoded example.javaencoded || exit 1
PYTHONPATH=../../lib/python ./example_decoder.py example.javaencoded || exit 1
all:
cd c ; make
# cd csharp ; make
cd java ; make
test:
$(MAKE) -C c -e run-test
clean:
cd c ; make clean
cd csharp ; make clean
cd java ; make clean
distclean:
cd c ; make distclean
cd csharp ; make clean
cd java ; make clean
SUBDIRS=c csharp java python
.PHONY: all
all: $(SUBDIRS:%=make-%)
.PHONY: make-%
make-%:
$(MAKE) -C $*
.PHONY: test
test: $(SUBDIRS:%=test-%)
.PHONY: test-%
test-%:
$(MAKE) -C $* test
.PHONY: clean
clean: $(SUBDIRS:%=clean-%)
.PHONY: clean-%
clean-%:
$(MAKE) -C $* clean
.PHONY: distclean
distclean: clean $(SUBDIRS:%=distclean-%)
.PHONY: distclean-%
distclean-%:
$(MAKE) -C $* distclean
......@@ -314,4 +314,4 @@ MODULE LabComm(SYSMODULE)
RAISE ;
ENDPROC
ENDMODULE
\ No newline at end of file
ENDMODULE
......@@ -34,7 +34,7 @@ or
$ VAR Encoder e;
$ Init_Encoder e, st;
This will read/write the version of LabComm to ensure compatibility, current
version is "LabComm2013".
version is "LabComm2014".
# Initiate the labcomm samples:
LabComm trusts the application to manage each sample. It requests the samples,
......
liblabcomm.a
liblabcomm.so
liblabcomm.so.1
liblabcomm2006.so.1
liblabcomm2006.so
liblabcomm2006.a
liblabcomm2014.so.1
liblabcomm2014.so
liblabcomm2014.a
## Macros
VERSION=2014
LIBVERSION=2014
include ../os_compat.mk
ALL_DEPS=../liblabcomm$(LIBVERSION).a ../liblabcomm$(LIBVERSION).so
# TODO: Support for Codesourcery ARM toolchain.
OBJS=labcomm$(VERSION).o \
labcomm$(VERSION)_memory.o \
labcomm$(VERSION)_error.o \
labcomm$(VERSION)_default_error_handler.o \
labcomm$(VERSION)_default_memory.o \
labcomm$(VERSION)_default_scheduler.o \
labcomm$(VERSION)_time.o \
labcomm$(VERSION)_scheduler.o \
labcomm$(VERSION)_encoder.o \
labcomm$(VERSION)_decoder.o \
labcomm$(VERSION)_dynamic_buffer_writer.o \
labcomm$(VERSION)_fd_reader.o \
labcomm$(VERSION)_type_signature.o \
labcomm$(VERSION)_fd_writer.o \
labcomm$(VERSION)_pthread_scheduler.o \
labcomm$(VERSION)_renaming.o \
labcomm$(VERSION)_renaming_registry.o \
labcomm$(VERSION)_renaming_encoder.o \
labcomm$(VERSION)_renaming_decoder.o
# Enable experimental objects by `make LABCOMM_EXPERIMENTAL=true`
ifeq ($(LABCOMM_EXPERIMENTAL),true)
OBJS += experimental/udp_hack.o experimental/ethaddr.o \
experimental/labcomm_thr_reader_writer.o \
experimental/ThrottleDrv/ethernet_drv.o \
experimental/ThrottleDrv/throttle_drv.o \
experimental/labcomm_udp_reader_writer.o
endif
# Enable experimental objects by `make LABCOMM_SIG_PARSER=true`
ifeq ($(LABCOMM_SIG_PARSER),true)
OBJS += experimental/labcomm2014_sig_parser.o
endif
LABCOMM_JAR=../../../compiler/labcomm$(LIBVERSION)_compiler.jar
LABCOMM=java -jar $(LABCOMM_JAR)
TESTS=test_labcomm_basic_type_encoding \
test_labcomm_generated_encoding \
test_signature_numbers \
test_labcomm \
test_labcomm_pthread_scheduler \
test_labcomm_copy \
test_labcomm_renaming_registry \
test_labcomm_renaming_encoder \
test_labcomm_renaming_decoder
#FIXME: test_labcomm_errors
TEST_DIR=test
## Targets
.PHONY: all
all: $(ALL_DEPS)
.PHONY: test
test: all $(TESTS:%=run-test-%)
.PHONY: clean
clean:
$(RM) *.o
$(RM) experimental/*.o
$(RM) experimental/ThrottleDrv/*.o
$(RM) test/*.o
$(RM) test/*.gch
$(RM) test/test_labcomm_errors
$(RM) test/testdata/gen/*.[cho]
$(RM) test/gen/*.[cho]
$(RM) -rf test/gen
.PHONY: distclean
distclean: clean
$(RM) ../liblabcomm$(LIBVERSION).so.1
$(RM) ../liblabcomm$(LIBVERSION).a
# rules invoked by 'all'
../liblabcomm$(LIBVERSION).so: ../liblabcomm$(LIBVERSION).so.1
if [ -h $@ ] ; then rm $@ ; fi
ln -s $(<:../%=%) $@
../liblabcomm$(LIBVERSION).so.1: $(OBJS:%.o=%.pic.o)
$(call MAKESHARED,$@,$(@:../%=%),$^)
../liblabcomm$(LIBVERSION).a: $(OBJS)
ar -r $@ $^
# Enable sig parser objects by `make labcomm2014_sig_PARSER=true`
ifeq ($(LABCOMM_SIG_PARSER),true)
experimental/test_sig_parser : experimental/labcomm2014_sig_parser.o experimental/test_sig_parser.c
endif
# compilation rules
%.pic.o: %.c
$(CC) -fPIC $(CFLAGS) -c -o $@ $<
%.o: %.c %.h
$(CC) $(CFLAGS) -c -o $@ $<
# rules invoked by 'test'
.PHONY: run-test-%
run-test-%: $(TEST_DIR)/gen/% | $(TEST_DIR)/gen
$(VALGRIND) $<
.PRECIOUS: $(TEST_DIR)/gen/%
$(TEST_DIR)/gen/%: $(TEST_DIR)/gen/%.o | $(TEST_DIR)/gen
$(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
$(TEST_DIR)/gen/%.o: $(TEST_DIR)/%.c | $(TEST_DIR)/gen
$(CC) $(CFLAGS_TEST) -o $@ -c $<
.PRECIOUS: $(TEST_DIR)/gen/%.c
.PRECIOUS: $(TEST_DIR)/gen/%.h
$(TEST_DIR)/gen/%.c $(TEST_DIR)/gen/%.h: $(TEST_DIR)/%.lc | $(TEST_DIR)/gen
$(LABCOMM) \
--c=$(TEST_DIR)/gen/$*.c \
--h=$(TEST_DIR)/gen/$*.h \
$<
$(LABCOMM_JAR):
@echo "======Building LabComm compiler======"
cd $(shell dirname $(LABCOMM_JAR)); ant jar
@echo "======End building LabComm compiler======"
$(TEST_DIR)/gen:
mkdir -p $@
# Extra compilation dependencies
labcomm$(VERSION).o: \
labcomm$(VERSION).c \
labcomm$(VERSION).h \
labcomm$(VERSION)_private.h
labcomm$(VERSION)_fd_reader.o: \
labcomm$(VERSION)_private.h
labcomm$(VERSION)_fd_writer.o: \
labcomm$(VERSION)_private.h
labcomm$(VERSION)_dynamic_buffer_writer.o: \
labcomm$(VERSION)_private.h
$(TEST_DIR)/gen/test_labcomm_basic_type_encoding.o: \
labcomm$(VERSION)_private.h
$(TEST_DIR)/gen/test_labcomm_generated_encoding.o: \
labcomm$(VERSION)_private.h \
$(TEST_DIR)/gen/generated_encoding.h
$(TEST_DIR)/gen/test_labcomm_generated_encoding: \
$(TEST_DIR)/gen/generated_encoding.o
$(TEST_DIR)/gen/test_signature_numbers.c: \
$(TEST_DIR)/gen/another_encoding.h \
$(TEST_DIR)/gen/generated_encoding.h
$(TEST_DIR)/gen/test_signature_numbers: \
$(TEST_DIR)/gen/another_encoding.o \
$(TEST_DIR)/gen/generated_encoding.o
$(TEST_DIR)/gen/test_labcomm: \
$(TEST_DIR)/gen/test_sample.o
$(TEST_DIR)/gen/test_labcomm_copy: \
$(TEST_DIR)/gen/generated_encoding.o \
$(TEST_DIR)/gen/test_sample.o \
$(TEST_DIR)/gen/more_types.o
$(TEST_DIR)/gen/test_labcomm_renaming_registry: \
$(TEST_DIR)/gen/generated_encoding.o
$(TEST_DIR)/gen/test_labcomm_renaming_encoder: \
$(TEST_DIR)/gen/generated_encoding.o
$(TEST_DIR)/gen/test_labcomm_renaming_decoder: \
$(TEST_DIR)/gen/generated_encoding.o