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

added var array and string

parent 06f3a09b
No related branches found
No related tags found
No related merge requests found
LCDIR=../..
LCCJAR=${LCDIR}/compiler/labComm.jar
LCLJAR=${LCDIR}/lib/java/labcomm.jar
LCCJAR=${LCDIR}/compiler/labComm.jar # the LabComm compiler
LCLJAR=${LCDIR}/lib/java/labcomm.jar # the LabComm library
JAVA_PKG=labcommTCPtest
.PHONY : clean run runserver runOSserver runclient
......@@ -26,7 +26,7 @@ ${LCLJAR} :
${JAVA_PKG}/gen/FooSample.java: test.lc ${LCCJAR}
${LCC} --javapackage=${JAVA_PKG}.gen --java=${JAVA_PKG}/gen $<
${JAVA_PKG}/gen/FooSample.class: ${JAVA_PKG}/gen/FooSample.java ${LCLJAR}
${JAVA_PKG}/gen/FooSample.class: ${JAVA_PKG}/gen/FooSample.java test.lc ${LCLJAR}
javac -cp ${CLASSPATH} $<
${JAVA_PKG}/Example.class: ${JAVA_PKG}/Example.java ${JAVA_PKG}/gen/FooSample.class ${LCLJAR}
......
......@@ -28,8 +28,15 @@ public class TestClient implements Handler {
LabCommEncoderChannel e = new LabCommEncoderChannel(out );
FooSample.register(e);
FooSample sample = new FooSample();
int a[] = new int[3];
a[0] = 1;
a[1] = 2;
a[2] = 3;
sample.s = "Some random values";
sample.x = 17;
sample.y = 42;
sample.a = a;
sample.t = 1717;
sample.d = 0.42;
printSample("Client sending", sample);
......@@ -57,8 +64,22 @@ public class TestClient implements Handler {
}
}
private String formatArray(int a[]) {
StringBuilder sb = new StringBuilder();
sb.append("[");
for(int i=0; i < a.length; i++) {
sb.append(a[i]);
if(i < a.length-1) {
sb.append(", ");
}
}
sb.append("]");
return sb.toString();
}
private void printSample(String header, FooSample sample2) throws Exception {
System.out.format("[TestClient] %s: (%d, %d, %d, %f)\n", header, sample2.x, sample2.y, sample2.t, sample2.d);
System.out.format("[TestClient] %s: (%s, %d, %d, %s, %d, %f )\n", header, sample2.s, sample2.x, sample2.y, formatArray(sample2.a), sample2.t, sample2.d);
}
public void handle_FooSample(FooSample sample2) throws Exception {
......
......@@ -49,9 +49,16 @@ public class TestServer implements Handler {
public void handle_FooSample(FooSample sample) throws Exception {
LabCommEncoderChannel e = new LabCommEncoderChannel(out );
FooSample.register(e);
System.out.println("TestServer.handle_FooSample...");
System.out.println("TestServer.handle_FooSample: "+sample.s);
int tmp[] = new int[2*sample.a.length];
for (int i = 0; i < sample.a.length;i++) {
tmp[2*i] = tmp[2*i+1] = sample.a[i];
}
sample.s = "double!";
sample.x *= 2;
sample.y *= 2;
sample.a = tmp;
sample.t *= 2;
sample.d *= 2;
FooSample.encode(e, sample);
......
sample struct {
string s;
int x;
int y;
int a[_];
long t;
double d;
} FooSample;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment