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

added typedefs of primitive types to examples/user_types

parent 7df66f2d
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,9 @@ import se.lth.control.labcomm.DecoderChannel; ...@@ -6,7 +6,9 @@ import se.lth.control.labcomm.DecoderChannel;
public class Decoder public class Decoder
implements twoLines.Handler, implements twoLines.Handler,
twoInts.Handler twoInts.Handler,
theFirstInt.Handler,
theSecondInt.Handler
{ {
...@@ -18,6 +20,8 @@ public class Decoder ...@@ -18,6 +20,8 @@ public class Decoder
decoder = new DecoderChannel(in); decoder = new DecoderChannel(in);
twoInts.register(decoder, this); twoInts.register(decoder, this);
twoLines.register(decoder, this); twoLines.register(decoder, this);
theFirstInt.register(decoder, this);
theSecondInt.register(decoder, this);
try { try {
System.out.println("Running decoder."); System.out.println("Running decoder.");
...@@ -40,6 +44,14 @@ public class Decoder ...@@ -40,6 +44,14 @@ public class Decoder
System.out.println(d.a +", "+d.b); System.out.println(d.a +", "+d.b);
} }
public void handle_theFirstInt(int d) throws java.io.IOException {
System.out.println("Got theFirstInt: "+d);
}
public void handle_theSecondInt(int d) throws java.io.IOException {
System.out.println("Got theSecondInt: "+d);
}
public void handle_twoLines(twoLines d) throws java.io.IOException { public void handle_twoLines(twoLines d) throws java.io.IOException {
System.out.print("Got twoLines: "); System.out.print("Got twoLines: ");
System.out.println("Line l1: "+genLine(d.l1)); System.out.println("Line l1: "+genLine(d.l1));
......
...@@ -18,6 +18,8 @@ public class Encoder ...@@ -18,6 +18,8 @@ public class Encoder
encoder = new EncoderChannel(out); encoder = new EncoderChannel(out);
twoInts.register(encoder); twoInts.register(encoder);
twoLines.register(encoder); twoLines.register(encoder);
theFirstInt.register(encoder);
theSecondInt.register(encoder);
} }
public void doEncode() throws java.io.IOException { public void doEncode() throws java.io.IOException {
...@@ -28,6 +30,10 @@ public class Encoder ...@@ -28,6 +30,10 @@ public class Encoder
System.out.println("Encoding twoInts"); System.out.println("Encoding twoInts");
twoInts.encode(encoder, ti); twoInts.encode(encoder, ti);
System.out.println("Encoding the Ints");
theFirstInt.encode(encoder, 71);
theSecondInt.encode(encoder, 24);
twoLines x = new twoLines(); twoLines x = new twoLines();
line l1 = new line(); line l1 = new line();
point p11 = new point(); point p11 = new point();
......
...@@ -12,6 +12,14 @@ static void handle_test_twoInts(test_twoInts *v,void *context) { ...@@ -12,6 +12,14 @@ static void handle_test_twoInts(test_twoInts *v,void *context) {
printf("Got twoInts. (%d,%d) \n", v->a, v->b); printf("Got twoInts. (%d,%d) \n", v->a, v->b);
} }
static void handle_test_theFirstInt(int *v,void *context) {
printf("Got theFirstInt. (%d) \n", *v);
}
static void handle_test_theSecondInt(int *v,void *context) {
printf("Got theSecondInt. (%d) \n", *v);
}
static void handle_test_twoLines(test_twoLines *v,void *context) { static void handle_test_twoLines(test_twoLines *v,void *context) {
printf("Got twoLines. (%d,%d) -> (%d,%d), (%d,%d) -> (%d,%d)\n", v->l1.start.x.val, v->l1.start.y.val, printf("Got twoLines. (%d,%d) -> (%d,%d), (%d,%d) -> (%d,%d)\n", v->l1.start.x.val, v->l1.start.y.val,
v->l1.end.x.val, v->l1.end.y.val, v->l1.end.x.val, v->l1.end.y.val,
...@@ -38,6 +46,8 @@ int main(int argc, char *argv[]) { ...@@ -38,6 +46,8 @@ int main(int argc, char *argv[]) {
} }
labcomm_decoder_register_test_twoInts(decoder, handle_test_twoInts, context); labcomm_decoder_register_test_twoInts(decoder, handle_test_twoInts, context);
labcomm_decoder_register_test_theFirstInt(decoder, handle_test_theFirstInt, context);
labcomm_decoder_register_test_theSecondInt(decoder, handle_test_theSecondInt, context);
labcomm_decoder_register_test_twoLines(decoder, handle_test_twoLines, context); labcomm_decoder_register_test_twoLines(decoder, handle_test_twoLines, context);
printf("Decoding:\n"); printf("Decoding:\n");
......
...@@ -2,6 +2,8 @@ typedef struct { ...@@ -2,6 +2,8 @@ typedef struct {
int val; int val;
} coord; } coord;
typedef int anInt;
typedef struct { typedef struct {
coord x; coord x;
coord y; coord y;
...@@ -28,3 +30,6 @@ sample struct { ...@@ -28,3 +30,6 @@ sample struct {
int a; int a;
int b; int b;
} twoInts; } twoInts;
sample anInt theFirstInt;
sample anInt theSecondInt;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment