From bb636c494944b0d7662377acbf69f14e40e75a06 Mon Sep 17 00:00:00 2001 From: Sven Robertz <sven@cs.lth.se> Date: Wed, 2 Nov 2011 16:55:13 +0100 Subject: [PATCH] added wiki_example and needed library files --- lib/c/labcomm_fd_reader_writer.c | 104 +++++++++++ lib/c/labcomm_fd_reader_writer.h | 9 + wiki_example/data.java | 62 +++++++ wiki_example/example.c | 214 ++++++++++++++++++++++ wiki_example/example.cs | 170 +++++++++++++++++ wiki_example/example.encoded | Bin 0 -> 203 bytes wiki_example/example.h | 68 +++++++ wiki_example/example.lc | 8 + wiki_example/example.py | 18 ++ wiki_example/example_decoder.py | 28 +++ wiki_example/example_decoder_encoder.java | 55 ++++++ wiki_example/example_encoder.c | 33 ++++ wiki_example/log_message.java | 119 ++++++++++++ wiki_example/run | 22 +++ 14 files changed, 910 insertions(+) create mode 100644 lib/c/labcomm_fd_reader_writer.c create mode 100644 lib/c/labcomm_fd_reader_writer.h create mode 100644 wiki_example/data.java create mode 100644 wiki_example/example.c create mode 100644 wiki_example/example.cs create mode 100644 wiki_example/example.encoded create mode 100644 wiki_example/example.h create mode 100644 wiki_example/example.lc create mode 100644 wiki_example/example.py create mode 100755 wiki_example/example_decoder.py create mode 100644 wiki_example/example_decoder_encoder.java create mode 100644 wiki_example/example_encoder.c create mode 100644 wiki_example/log_message.java create mode 100755 wiki_example/run diff --git a/lib/c/labcomm_fd_reader_writer.c b/lib/c/labcomm_fd_reader_writer.c new file mode 100644 index 0000000..2774b37 --- /dev/null +++ b/lib/c/labcomm_fd_reader_writer.c @@ -0,0 +1,104 @@ +#include <errno.h> +#include <unistd.h> +#include "labcomm.h" + +#define BUFFER_SIZE 2048 + +int labcomm_fd_reader( + labcomm_reader_t *r, + labcomm_reader_action_t action) +{ + int result = -EINVAL; + int *fd = r->context; + + switch (action) { + case labcomm_reader_alloc: { + r->data = malloc(BUFFER_SIZE); + if (r->data) { + r->data_size = BUFFER_SIZE; + result = r->data_size; + } else { + r->data_size = 0; + result = -ENOMEM; + } + r->count = 0; + r->pos = 0; + } break; + case labcomm_reader_start: + case labcomm_reader_continue: { + if (r->pos < r->count) { + result = r->count - r->pos; + } else { + int err; + + r->pos = 0; + err = read(*fd, r->data, r->data_size); + if (err <= 0) { + r->count = 0; + result = -1; + } else { + r->count = err; + result = r->count - r->pos; + } + } + } break; + case labcomm_reader_end: { + result = 0; + } break; + case labcomm_reader_free: { + free(r->data); + r->data = 0; + r->data_size = 0; + r->count = 0; + r->pos = 0; + result = 0; + } break; + } + return result; +} + +int labcomm_fd_writer( + labcomm_writer_t *w, + labcomm_writer_action_t action) +{ + int result = 0; + int *fd = w->context; + + switch (action) { + case labcomm_writer_alloc: { + w->data = malloc(BUFFER_SIZE); + if (! w->data) { + result = -ENOMEM; + w->data_size = 0; + w->count = 0; + w->pos = 0; + } else { + w->data_size = BUFFER_SIZE; + w->count = BUFFER_SIZE; + w->pos = 0; + } + } break; + case labcomm_writer_free: { + free(w->data); + w->data = 0; + w->data_size = 0; + w->count = 0; + w->pos = 0; + } break; + case labcomm_writer_start: { + w->pos = 0; + } break; + case labcomm_writer_continue: { + result = write(*fd, w->data, w->pos); + w->pos = 0; + } break; + case labcomm_writer_end: { + result = write(*fd, w->data, w->pos); + w->pos = 0; + } break; + case labcomm_writer_available: { + result = w->count - w->pos; + } break; + } + return result; +} diff --git a/lib/c/labcomm_fd_reader_writer.h b/lib/c/labcomm_fd_reader_writer.h new file mode 100644 index 0000000..538dccd --- /dev/null +++ b/lib/c/labcomm_fd_reader_writer.h @@ -0,0 +1,9 @@ +#include "labcomm.h" + +extern int labcomm_fd_reader( + labcomm_reader_t *r, + labcomm_reader_action_t action); + +extern int labcomm_fd_writer( + labcomm_writer_t *r, + labcomm_writer_action_t action); diff --git a/wiki_example/data.java b/wiki_example/data.java new file mode 100644 index 0000000..ce225ea --- /dev/null +++ b/wiki_example/data.java @@ -0,0 +1,62 @@ +/* +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[] { + 0, 0, 0, 37, + }; + +} diff --git a/wiki_example/example.c b/wiki_example/example.c new file mode 100644 index 0000000..4b6f639 --- /dev/null +++ b/wiki_example/example.c @@ -0,0 +1,214 @@ +#include "labcomm.h" +#include "labcomm_private.h" +#include "example.h" + +static unsigned char signature_bytes_log_message[] = { +// struct { 2 fields +0, 0, 0, 17, + 0, 0, 0, 2, + // int 'sequence' + 0, 0, 0, 8, + 115, 101, 113, 117, 101, 110, 99, 101, + 0, 0, 0, 35, + // array [_] 'line' + 0, 0, 0, 4, + 108, 105, 110, 101, + // array [_] + 0, 0, 0, 16, + 0, 0, 0, 1, + 0, 0, 0, 0, + // struct { 2 fields + 0, 0, 0, 17, + 0, 0, 0, 2, + // boolean 'last' + 0, 0, 0, 4, + 108, 97, 115, 116, + 0, 0, 0, 32, + // string 'data' + 0, 0, 0, 4, + 100, 97, 116, 97, + 0, 0, 0, 39, + // } + // } +// } +}; +labcomm_signature_t labcomm_signature_example_log_message = { + LABCOMM_SAMPLE, "log_message", + (int (*)(void *))labcomm_sizeof_example_log_message, + sizeof(signature_bytes_log_message), + signature_bytes_log_message + }; +static unsigned char signature_bytes_data[] = { +0, 0, 0, 37, +}; +labcomm_signature_t labcomm_signature_example_data = { + LABCOMM_SAMPLE, "data", + (int (*)(void *))labcomm_sizeof_example_data, + sizeof(signature_bytes_data), + signature_bytes_data + }; +static void decode_log_message( + labcomm_decoder_t *d, + void (*handle)( + example_log_message *v, + void *context + ), + void *context +) +{ + example_log_message v; + v.sequence = labcomm_decode_int(d); + v.line.n_0 = labcomm_decode_int(d); + v.line.a = malloc(sizeof(v.line.a[0]) * v.line.n_0); + { + int i_0_0; + for (i_0_0 = 0 ; i_0_0 < v.line.n_0 ; i_0_0++) { + int i_0 = i_0_0; + v.line.a[i_0].last = labcomm_decode_boolean(d); + v.line.a[i_0].data = labcomm_decode_string(d); + } + } + handle(&v, context); + { + { + int i_0_0; + for (i_0_0 = 0 ; i_0_0 < v.line.n_0 ; i_0_0++) { + int i_0 = i_0_0; + free(v.line.a[i_0].data); + } + } + free(v.line.a); + } +} +void labcomm_decoder_register_example_log_message( + struct labcomm_decoder *d, + void (*handler)( + example_log_message *v, + void *context + ), + void *context +) +{ + labcomm_internal_decoder_register( + d, + &labcomm_signature_example_log_message, + (labcomm_decoder_typecast_t)decode_log_message, + (labcomm_handler_typecast_t)handler, + context + ); +} +static void encode_log_message( + labcomm_encoder_t *e, + example_log_message *v +) +{ + e->writer.write(&e->writer, labcomm_writer_start); + labcomm_encode_type_index(e, &labcomm_signature_example_log_message); + { + labcomm_encode_int(e, (*v).sequence); + labcomm_encode_int(e, (*v).line.n_0); + { + int i_0_0; + for (i_0_0 = 0 ; i_0_0 < (*v).line.n_0 ; i_0_0++) { + int i_0 = i_0_0; + labcomm_encode_boolean(e, (*v).line.a[i_0].last); + labcomm_encode_string(e, (*v).line.a[i_0].data); + } + } + } + e->writer.write(&e->writer, labcomm_writer_end); +} +void labcomm_encode_example_log_message( +labcomm_encoder_t *e, +example_log_message *v +) +{ +labcomm_internal_encode(e, &labcomm_signature_example_log_message, v); +} +void labcomm_encoder_register_example_log_message( + struct labcomm_encoder *e +) +{ + labcomm_internal_encoder_register( + e, + &labcomm_signature_example_log_message, + (labcomm_encode_typecast_t)encode_log_message + ); +} +int labcomm_sizeof_example_log_message(example_log_message *v) +{ + int result = 4; + { + int i_0_0; + for (i_0_0 = 0 ; i_0_0 < (*v).line.n_0 ; i_0_0++) { + int i_0 = i_0_0; + result += 4 + strlen((*v).line.a[i_0].data); + result += 1; + } + } + result += 4; + return result; +} +static void decode_data( + labcomm_decoder_t *d, + void (*handle)( + example_data *v, + void *context + ), + void *context +) +{ + example_data v; + v = labcomm_decode_float(d); + handle(&v, context); +} +void labcomm_decoder_register_example_data( + struct labcomm_decoder *d, + void (*handler)( + example_data *v, + void *context + ), + void *context +) +{ + labcomm_internal_decoder_register( + d, + &labcomm_signature_example_data, + (labcomm_decoder_typecast_t)decode_data, + (labcomm_handler_typecast_t)handler, + context + ); +} +static void encode_data( + labcomm_encoder_t *e, + example_data *v +) +{ + e->writer.write(&e->writer, labcomm_writer_start); + labcomm_encode_type_index(e, &labcomm_signature_example_data); + { + labcomm_encode_float(e, (*v)); + } + e->writer.write(&e->writer, labcomm_writer_end); +} +void labcomm_encode_example_data( +labcomm_encoder_t *e, +example_data *v +) +{ +labcomm_internal_encode(e, &labcomm_signature_example_data, v); +} +void labcomm_encoder_register_example_data( + struct labcomm_encoder *e +) +{ + labcomm_internal_encoder_register( + e, + &labcomm_signature_example_data, + (labcomm_encode_typecast_t)encode_data + ); +} +int labcomm_sizeof_example_data(example_data *v) +{ + return 8; +} diff --git a/wiki_example/example.cs b/wiki_example/example.cs new file mode 100644 index 0000000..6599950 --- /dev/null +++ b/wiki_example/example.cs @@ -0,0 +1,170 @@ +using System; +using se.lth.control.labcomm; +/* +sample struct { + int sequence; + struct { + boolean last; + string data; + } line[_]; +} log_message; +*/ + +public class log_message : LabCommSample { + + public static class struct_line { + public boolean last; + public String data; + } + + public int sequence; + public struct_line[] line; + + public interface Handler : LabCommHandler { + void handle(log_message value); + } + + public static void register(LabCommDecoder d, Handler h) { + d.register(new Dispatcher(), h); + } + + public static void register(LabCommEncoder e) { + e.register(new Dispatcher()); + } + + private class Dispatcher : LabCommDispatcher { + + public Type getSampleClass() { + return typeof(log_message); + } + + public String getName() { + return "log_message"; + } + + public byte[] getSignature() { + return signature; + } + + public void decodeAndHandle(LabCommDecoder d, LabCommHandler h) { + ((Handler)h).handle(log_message.decode(d)); + } + + } + + public static void encode(LabCommEncoder e, log_message value) { + e.begin(typeof(log_message)); + e.encodeInt(value.sequence); + e.encodeInt(value.line.GetLength(0)); + int i_0_max = value.line.GetLength(0); + for (int i_0 = 0 ; i_0 < i_0_max ; i_0++) { + e.encodeBoolean(value.line[i_0].last); + e.encodeString(value.line[i_0].data); + } + e.end(typeof(log_message)); + } + + public static log_message decode(LabCommDecoder d) { + log_message result; + result = new log_message(); + result.sequence = d.decodeInt(); + { + int i_0_max = d.decodeInt(); + result.line = new struct_line[i_0_max] + ; + for (int i_0 = 0 ; i_0 < i_0_max ; i_0++) { + result.line[i_0] = new struct_line(); + result.line[i_0].last = d.decodeBoolean(); + result.line[i_0].data = d.decodeString(); + } + } + return result; + } + + private static byte[] signature = new byte[] { + // struct { 2 fields + 0, 0, 0, 17, + 0, 0, 0, 2, + // int 'sequence' + 0, 0, 0, 8, + 115, 101, 113, 117, 101, 110, 99, 101, + 0, 0, 0, 35, + // array [_] 'line' + 0, 0, 0, 4, + 108, 105, 110, 101, + // array [_] + 0, 0, 0, 16, + 0, 0, 0, 1, + 0, 0, 0, 0, + // struct { 2 fields + 0, 0, 0, 17, + 0, 0, 0, 2, + // boolean 'last' + 0, 0, 0, 4, + 108, 97, 115, 116, + 0, 0, 0, 32, + // string 'data' + 0, 0, 0, 4, + 100, 97, 116, 97, + 0, 0, 0, 39, + // } + // } + // } + }; + +} +/* +sample float data; +*/ + +public class data : LabCommSample { + + public interface Handler : LabCommHandler { + void handle(float value); + } + + public static void register(LabCommDecoder d, Handler h) { + d.register(new Dispatcher(), h); + } + + public static void register(LabCommEncoder e) { + e.register(new Dispatcher()); + } + + private class Dispatcher : LabCommDispatcher { + + public Type getSampleClass() { + return typeof(data); + } + + public String getName() { + return "data"; + } + + public byte[] getSignature() { + return signature; + } + + public void decodeAndHandle(LabCommDecoder d, LabCommHandler h) { + ((Handler)h).handle(data.decode(d)); + } + + } + + public static void encode(LabCommEncoder e, float value) { + e.begin(typeof(data)); + e.encodeFloat(value); + e.end(typeof(data)); + } + + public static float decode(LabCommDecoder d) { + float result; + result = d.decodeFloat(); + return result; + } + + private static byte[] signature = new byte[] { + 0, 0, 0, 37, + }; + +} diff --git a/wiki_example/example.encoded b/wiki_example/example.encoded new file mode 100644 index 0000000000000000000000000000000000000000..fe3d4eb2a5acba9e220ffd62cef467eb02850fdb GIT binary patch literal 203 zcmYj}Q3}H#5JWfCk3xTv8w5h>G1{9HNkjrBQnd6}Z{8V$kcG$W&hCzgTtp;;n-A{2 z*%*zp7ze=BHQLYD?lZj!Xut04d(Z(^yVc&rgn0ydG08w5fH~#l-O*>z{@L@UqoG30 Wr>6k@>eXHP1&qvMm1jQm1^EM?0vJ*N literal 0 HcmV?d00001 diff --git a/wiki_example/example.h b/wiki_example/example.h new file mode 100644 index 0000000..b84b36f --- /dev/null +++ b/wiki_example/example.h @@ -0,0 +1,68 @@ +/* LabComm declarations: +sample struct { + int sequence; + struct { + boolean last; + string data; + } line[_]; +} log_message; +sample float data; +*/ + + +#ifndef __LABCOMM_example_H__ +#define __LABCOMM_example_H__ + +#include "labcomm.h" + +#ifndef PREDEFINED_example_log_message +typedef struct { + int sequence; + struct { + int n_0; + struct { + unsigned char last; + char* data; + } *a; + } line; +} example_log_message; +#endif +void labcomm_decoder_register_example_log_message( + struct labcomm_decoder *d, + void (*handler)( + example_log_message *v, + void *context + ), + void *context +); +void labcomm_encoder_register_example_log_message( + struct labcomm_encoder *e); +void labcomm_encode_example_log_message( + struct labcomm_encoder *e, + example_log_message *v +); +extern int labcomm_sizeof_example_log_message(example_log_message *v); + +#ifndef PREDEFINED_example_data +typedef float example_data; +#endif +void labcomm_decoder_register_example_data( + struct labcomm_decoder *d, + void (*handler)( + example_data *v, + void *context + ), + void *context +); +void labcomm_encoder_register_example_data( + struct labcomm_encoder *e); +void labcomm_encode_example_data( + struct labcomm_encoder *e, + example_data *v +); +extern int labcomm_sizeof_example_data(example_data *v); + +#define LABCOMM_FORALL_SAMPLES_example(func, sep) \ + func(log_message, example_log_message) sep \ + func(data, example_data) +#endif diff --git a/wiki_example/example.lc b/wiki_example/example.lc new file mode 100644 index 0000000..ad58ecb --- /dev/null +++ b/wiki_example/example.lc @@ -0,0 +1,8 @@ +sample struct { + int sequence; + struct { + boolean last; + string data; + } line[_]; +} log_message; +sample float data; diff --git a/wiki_example/example.py b/wiki_example/example.py new file mode 100644 index 0000000..7ad6b6c --- /dev/null +++ b/wiki_example/example.py @@ -0,0 +1,18 @@ +#!/usr/bin/python +# Auto generated example + +import labcomm + +class log_message(object): + signature = labcomm.sample('log_message', + labcomm.struct([ + ('sequence', labcomm.INTEGER()), + ('line', labcomm.array([0], + labcomm.struct([ + ('last', labcomm.BOOLEAN()), + ('data', labcomm.STRING())])))])) + +class data(object): + signature = labcomm.sample('data', + labcomm.FLOAT()) + diff --git a/wiki_example/example_decoder.py b/wiki_example/example_decoder.py new file mode 100755 index 0000000..6c3828b --- /dev/null +++ b/wiki_example/example_decoder.py @@ -0,0 +1,28 @@ +#!/usr/bin/python + +import labcomm +import sys + +class FileReader: + def __init__(self, name): + self.f = open(name) + + def read(self, count): + s = self.f.read(count) + if len(s) == 0: + raise Exception("EOF") + return s + + def mark(self, value, decl): + pass + +if __name__ == "__main__": + d = labcomm.Decoder(FileReader(sys.argv[1])) + + while True: + try: + data,decl = d.decode() + if data: + print data + except: + break diff --git a/wiki_example/example_decoder_encoder.java b/wiki_example/example_decoder_encoder.java new file mode 100644 index 0000000..63f1d96 --- /dev/null +++ b/wiki_example/example_decoder_encoder.java @@ -0,0 +1,55 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; + +import se.lth.control.labcomm.LabCommDecoderChannel; +import se.lth.control.labcomm.LabCommEncoderChannel; + +public class example_decoder_encoder + implements data.Handler, log_message.Handler +{ + + LabCommDecoderChannel decoder; + LabCommEncoderChannel encoder; + + public example_decoder_encoder(InputStream in, OutputStream out) + throws Exception + { + decoder = new LabCommDecoderChannel(in); + log_message.register(decoder, this); + data.register(decoder, this); + + encoder = new LabCommEncoderChannel(out); + log_message.register(encoder); + data.register(encoder); + + try { + decoder.run(); + } catch (java.io.EOFException e) { + } + } + + public void handle_data(float v) throws java.io.IOException { + System.out.println("Got data"); + data.encode(encoder, v); + } + + public void handle_log_message(log_message v) throws java.io.IOException { + System.out.println("Got log_message"); + log_message.encode(encoder, v); + } + + + public static void main(String[] arg) throws Exception { + example_decoder_encoder example = new example_decoder_encoder( + new FileInputStream(new File(arg[0])), + new FileOutputStream(new File(arg[1]))); + + + + } + +} + diff --git a/wiki_example/example_encoder.c b/wiki_example/example_encoder.c new file mode 100644 index 0000000..c39ab9a --- /dev/null +++ b/wiki_example/example_encoder.c @@ -0,0 +1,33 @@ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <labcomm_fd_reader_writer.h> +#include "example.h" + +int main(int argc, char *argv[]) { + int fd; + struct labcomm_encoder *encoder; + int i, j; + + fd = open("example.encoded", O_WRONLY|O_CREAT|O_TRUNC, 0644); + encoder = labcomm_encoder_new(labcomm_fd_writer, &fd); + labcomm_encoder_register_example_log_message(encoder); + labcomm_encoder_register_example_data(encoder); + for (i = 0 ; i < argc ; i++) { + example_log_message message; + + message.sequence = i + 1; + message.line.n_0 = i; + message.line.a = malloc(message.line.n_0*sizeof(message.line)); + for (j = 0 ; j < i ; j++) { + 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); + free(message.line.a); + } + for (i = 0 ; i < argc ; i++) { + float f = i; + labcomm_encode_example_data(encoder, &f); + } +} diff --git a/wiki_example/log_message.java b/wiki_example/log_message.java new file mode 100644 index 0000000..c3731d7 --- /dev/null +++ b/wiki_example/log_message.java @@ -0,0 +1,119 @@ +/* +sample struct { + int sequence; + struct { + boolean last; + string data; + } line[_]; +} log_message; +*/ +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 log_message implements LabCommSample { + + public static class struct_line { + public boolean last; + public String data; + } + + public int sequence; + public struct_line[] line; + + public interface Handler extends LabCommHandler { + public void handle_log_message(log_message 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 log_message.class; + } + + public String getName() { + return "log_message"; + } + + public byte[] getSignature() { + return signature; + } + + public void decodeAndHandle(LabCommDecoder d, + LabCommHandler h) throws Exception { + ((Handler)h).handle_log_message(log_message.decode(d)); + } + + } + + public static void encode(LabCommEncoder e, log_message value) throws IOException { + e.begin(log_message.class); + e.encodeInt(value.sequence); + e.encodeInt(value.line.length); + int i_0_max = value.line.length; + for (int i_0 = 0 ; i_0 < i_0_max ; i_0++) { + e.encodeBoolean(value.line[i_0].last); + e.encodeString(value.line[i_0].data); + } + e.end(log_message.class); + } + + public static log_message decode(LabCommDecoder d) throws IOException { + log_message result; + result = new log_message(); + result.sequence = d.decodeInt(); + { + int i_0_max = d.decodeInt(); + result.line = new struct_line[i_0_max]; + for (int i_0 = 0 ; i_0 < i_0_max ; i_0++) { + result.line[i_0] = new struct_line(); + result.line[i_0].last = d.decodeBoolean(); + result.line[i_0].data = d.decodeString(); + } + } + return result; + } + + private static byte[] signature = new byte[] { + // struct { 2 fields + 0, 0, 0, 17, + 0, 0, 0, 2, + // int 'sequence' + 0, 0, 0, 8, + 115, 101, 113, 117, 101, 110, 99, 101, + 0, 0, 0, 35, + // array [_] 'line' + 0, 0, 0, 4, + 108, 105, 110, 101, + // array [_] + 0, 0, 0, 16, + 0, 0, 0, 1, + 0, 0, 0, 0, + // struct { 2 fields + 0, 0, 0, 17, + 0, 0, 0, 2, + // boolean 'last' + 0, 0, 0, 4, + 108, 97, 115, 116, + 0, 0, 0, 32, + // string 'data' + 0, 0, 0, 4, + 100, 97, 116, 97, + 0, 0, 0, 39, + // } + // } + // } + }; + +} diff --git a/wiki_example/run b/wiki_example/run new file mode 100755 index 0000000..93be4eb --- /dev/null +++ b/wiki_example/run @@ -0,0 +1,22 @@ +#!/bin/sh + +# Auto generate code from .lc file +java -jar /opt/robot/java/labComm.jar \ + --c=example.c --h=example.h \ + --java=. \ + --cs=example.cs \ + --python=example.py \ + example.lc + +# Compile executables +gcc -o example_encoder -I ../lib/c/ \ + example_encoder.c \ + example.c \ + ../lib/c/labcomm.c \ + ../lib/c//labcomm_fd_reader_writer.c +javac -cp ../lib/java:. *.java + +# 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 -- GitLab