Skip to content
Snippets Groups Projects
Commit 576f596c authored by Sven Robertz's avatar Sven Robertz
Browse files

extended simple example to use typedef

parent 75a92c86
Branches
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ import java.io.InputStream; ...@@ -5,7 +5,7 @@ import java.io.InputStream;
import se.lth.control.labcomm.LabCommDecoderChannel; import se.lth.control.labcomm.LabCommDecoderChannel;
public class Decoder public class Decoder
implements TwoInts.Handler, IntString.Handler, TwoArrays.Handler, TwoFixedArrays.Handler implements theTwoInts.Handler, anotherTwoInts.Handler, IntString.Handler, TwoArrays.Handler, TwoFixedArrays.Handler
{ {
...@@ -15,7 +15,8 @@ public class Decoder ...@@ -15,7 +15,8 @@ public class Decoder
throws Exception throws Exception
{ {
decoder = new LabCommDecoderChannel(in); decoder = new LabCommDecoderChannel(in);
TwoInts.register(decoder, this); theTwoInts.register(decoder, this);
anotherTwoInts.register(decoder, this);
IntString.register(decoder, this); IntString.register(decoder, this);
TwoArrays.register(decoder, this); TwoArrays.register(decoder, this);
TwoFixedArrays.register(decoder, this); TwoFixedArrays.register(decoder, this);
...@@ -28,8 +29,18 @@ public class Decoder ...@@ -28,8 +29,18 @@ public class Decoder
} }
} }
public void handle_TwoInts(TwoInts d) throws java.io.IOException { public void printTwoInts(TwoInts d) throws java.io.IOException {
System.out.println("Got TwoInts, a="+d.a+", b="+d.b); System.out.println("a="+d.a+", b="+d.b);
}
public void handle_theTwoInts(TwoInts d) throws java.io.IOException {
System.out.print("Got theTwoInts: ");
printTwoInts(d);
}
public void handle_anotherTwoInts(TwoInts d) throws java.io.IOException {
System.out.print("Got anotherheTwoInts: ");
printTwoInts(d);
} }
public void handle_IntString(IntString d) throws java.io.IOException { public void handle_IntString(IntString d) throws java.io.IOException {
......
...@@ -16,7 +16,7 @@ public class Encoder ...@@ -16,7 +16,7 @@ public class Encoder
throws Exception throws Exception
{ {
encoder = new LabCommEncoderChannel(out); encoder = new LabCommEncoderChannel(out);
TwoInts.register(encoder); theTwoInts.register(encoder);
IntString.register(encoder); IntString.register(encoder);
} }
...@@ -29,8 +29,8 @@ public class Encoder ...@@ -29,8 +29,8 @@ public class Encoder
y.x = 37; y.x = 37;
y.s = "Testing, testing"; y.s = "Testing, testing";
System.out.println("Encoding TwoInts, a="+x.a+", b="+x.b); System.out.println("Encoding theTwoInts, a="+x.a+", b="+x.b);
TwoInts.encode(encoder, x); theTwoInts.encode(encoder, x);
System.out.println("Encoding IntString, x="+y.x+", s="+y.s); System.out.println("Encoding IntString, x="+y.x+", s="+y.s);
IntString.encode(encoder, y); IntString.encode(encoder, y);
......
...@@ -4,8 +4,12 @@ ...@@ -4,8 +4,12 @@
#include <labcomm_fd_reader_writer.h> #include <labcomm_fd_reader_writer.h>
#include "gen/simple.h" #include "gen/simple.h"
static void handle_simple_TwoInts(simple_TwoInts *v,void *context) { static void handle_simple_theTwoInts(simple_TwoInts *v,void *context) {
printf("Got TwoInts. a=%d, b=%d\n", v->a, v->b); printf("Got theTwoInts. a=%d, b=%d\n", v->a, v->b);
}
static void handle_simple_anotherTwoInts(simple_TwoInts *v,void *context) {
printf("Got anotherTwoInts. a=%d, b=%d\n", v->a, v->b);
} }
static void handle_simple_IntString(simple_IntString *v,void *context) { static void handle_simple_IntString(simple_IntString *v,void *context) {
...@@ -55,7 +59,8 @@ int main(int argc, char *argv[]) { ...@@ -55,7 +59,8 @@ int main(int argc, char *argv[]) {
return 1; return 1;
} }
labcomm_decoder_register_simple_TwoInts(decoder, handle_simple_TwoInts, context); labcomm_decoder_register_simple_theTwoInts(decoder, handle_simple_theTwoInts, context);
labcomm_decoder_register_simple_anotherTwoInts(decoder, handle_simple_anotherTwoInts, context);
labcomm_decoder_register_simple_IntString(decoder, handle_simple_IntString, context); labcomm_decoder_register_simple_IntString(decoder, handle_simple_IntString, context);
labcomm_decoder_register_simple_TwoArrays(decoder, handle_simple_TwoArrays, context); labcomm_decoder_register_simple_TwoArrays(decoder, handle_simple_TwoArrays, context);
labcomm_decoder_register_simple_TwoFixedArrays(decoder, handle_simple_TwoFixedArrays, context); labcomm_decoder_register_simple_TwoFixedArrays(decoder, handle_simple_TwoFixedArrays, context);
......
...@@ -13,7 +13,8 @@ int main(int argc, char *argv[]) { ...@@ -13,7 +13,8 @@ int main(int argc, char *argv[]) {
printf("C encoder writing to %s\n", filename); printf("C encoder writing to %s\n", filename);
fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644); fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644);
encoder = labcomm_encoder_new(labcomm_fd_writer, &fd); encoder = labcomm_encoder_new(labcomm_fd_writer, &fd);
labcomm_encoder_register_simple_TwoInts(encoder); labcomm_encoder_register_simple_theTwoInts(encoder);
labcomm_encoder_register_simple_anotherTwoInts(encoder);
labcomm_encoder_register_simple_IntString(encoder); labcomm_encoder_register_simple_IntString(encoder);
simple_IntString is; simple_IntString is;
is.x = 24; is.x = 24;
...@@ -21,11 +22,17 @@ int main(int argc, char *argv[]) { ...@@ -21,11 +22,17 @@ int main(int argc, char *argv[]) {
printf("Encoding IntString, x=%d, s=%s\n", is.x, is.s); printf("Encoding IntString, x=%d, s=%s\n", is.x, is.s);
labcomm_encode_simple_IntString(encoder, &is); labcomm_encode_simple_IntString(encoder, &is);
simple_TwoInts ti; simple_theTwoInts ti;
ti.a = 13; ti.a = 13;
ti.b = 37; ti.b = 37;
printf("Encoding TwoInts, a=%d, b=%d\n", ti.a, ti.b); printf("Encoding theTwoInts, a=%d, b=%d\n", ti.a, ti.b);
labcomm_encode_simple_TwoInts(encoder, &ti); labcomm_encode_simple_theTwoInts(encoder, &ti);
simple_anotherTwoInts ati;
ati.a = 23;
ati.b = 47;
printf("Encoding anotherTwoInts, a=%d, b=%d\n", ati.a, ati.b);
labcomm_encode_simple_anotherTwoInts(encoder, &ati);
int foo[20]; int foo[20];
...@@ -47,8 +54,8 @@ int main(int argc, char *argv[]) { ...@@ -47,8 +54,8 @@ int main(int argc, char *argv[]) {
ti.a = 23; ti.a = 23;
ti.b = 47; ti.b = 47;
printf("Encoding TwoInts, a=%d, b=%d\n", ti.a, ti.b); printf("Encoding theTwoInts, a=%d, b=%d\n", ti.a, ti.b);
labcomm_encode_simple_TwoInts(encoder, &ti); labcomm_encode_simple_theTwoInts(encoder, &ti);
simple_TwoFixedArrays tfa; simple_TwoFixedArrays tfa;
......
sample struct { typedef struct {
int a; int a;
int b; int b;
} TwoInts; } TwoInts;
sample TwoInts theTwoInts;
sample TwoInts anotherTwoInts;
sample struct { sample struct {
int x; int x;
string s; string s;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment