Commit 2bc1b87e authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

added c# user_types example

parent 59a49855
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using se.lth.control.labcomm;
namespace user_types
{
class Decoder : twoLines.Handler
{
DecoderChannel dec;
public Decoder(Stream stream)
{
dec = new DecoderChannel(stream);
twoLines.register(dec, this);
try
{
Console.WriteLine("Running decoder.");
dec.run();
}
catch (EndOfStreamException)
{
Console.WriteLine("EOF reached");
}
}
private string genPoint(point p)
{
return "(" + p.x.val + ", " + p.y.val + ")";
}
private String genLine(line l)
{
return "Line from " + genPoint(l.start) + " to " + genPoint(l.end);
}
public void handle(twoLines d)
{
Console.WriteLine("Got twoLines: ");
Console.WriteLine("Line l1: "+genLine(d.l1));
Console.WriteLine("Line l2: " + genLine(d.l2));
}
static void Main(string[] args)
{
new Decoder(new FileStream(args[0], FileMode.Open));
}
}
}
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using se.lth.control.labcomm;
namespace user_types
{
public class Encoder
{
private EncoderChannel enc;
public Encoder(Stream stream)
{
enc = new EncoderChannel(stream);
twoLines.register(enc);
}
public void doEncode()
{
twoLines x = new twoLines();
line l1 = new line();
point p11 = new point();
coord c11x = new coord();
coord c11y = new coord();
c11x.val = 11;
c11y.val = 99;
p11.x = c11x;
p11.y = c11y;
l1.start = p11;
point p12 = new point();
coord c12x = new coord();
coord c12y = new coord();
c12x.val = 22;
c12y.val = 88;
p12.x = c12x;
p12.y = c12y;
l1.end = p12;
line l2 = new line();
point p21 = new point();
coord c21x = new coord();
coord c21y = new coord();
c21x.val = 17;
c21y.val = 42;
p21.x = c21x;
p21.y = c21y;
l2.start = p21;
point p22 = new point();
coord c22x = new coord();
coord c22y = new coord();
c22x.val = 13;
c22y.val = 37;
p22.x = c22x;
p22.y = c22y;
l2.end = p22;
foo f = new foo();
f.a = 10;
f.b = 20;
f.c = false;
x.l1 = l1;
x.l2 = l2;
x.f = f;
Console.WriteLine("Encoding theTwoLines");
twoLines.encode(enc, x);
}
static void Main(string[] args)
{
FileStream stream = new FileStream(args[0],FileMode.Create);
Encoder example = new Encoder(stream);
example.doEncode();
stream.Close();
}
}
}
......@@ -32,11 +32,11 @@ cleanbuild: clean build
labcomm.dll:
ln -sf ../../lib/csharp/labcomm.dll $@
Encoder.exe: Encoder.cs gen/test.cs labcomm.dll Makefile
ExampleEncoder.exe: ExampleEncoder.cs gen/test.cs labcomm.dll Makefile
mcs -out:$@ $(filter %.cs, $^) -lib:../../lib/csharp/ -r:labcomm
chmod a+x $@
Decoder.exe: Decoder.cs gen/test.cs labcomm.dll Makefile
ExampleDecoder.exe: ExampleDecoder.cs gen/test.cs labcomm.dll Makefile
mcs -out:$@ $(filter %.cs, $^) -lib:../../lib/csharp/ -r:labcomm
chmod a+x $@
......@@ -100,7 +100,7 @@ run:
@echo "************ running python decoder (from wiki_example):"
PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_p LabComm2014
runwcs: Encoder.exe Decoder.exe
runwcs: ExampleEncoder.exe ExampleDecoder.exe
export LD_LIBRARY_PATH=${LCDIR}/lib/c/
@echo
@echo "********************************************"
......@@ -120,7 +120,7 @@ runwcs: Encoder.exe Decoder.exe
@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_j LabComm2014
@echo "************ running C# decoder: *****************"
@./Decoder.exe encoded_data_j
@./ExampleDecoder.exe encoded_data_j
@echo "************ running C encoder: *****************"
@./example_encoder encoded_data_c
......@@ -135,7 +135,7 @@ runwcs: Encoder.exe Decoder.exe
@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_c LabComm2014
@echo "************ running C# decoder: *****************"
@./Decoder.exe encoded_data_c
@./ExampleDecoder.exe encoded_data_c
@echo "************ running python encoder: *****************"
@PYTHONPATH=${LCDIR}/lib/python:${GENDIR} ./example_encoder.py encoded_data_p LabComm2014
......@@ -150,10 +150,10 @@ runwcs: Encoder.exe Decoder.exe
PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_p LabComm2014
@echo "************ running C# decoder: *****************"
@./Decoder.exe encoded_data_p
@./ExampleDecoder.exe encoded_data_p
@echo "************ running C# encoder: *****************"
@./Encoder.exe encoded_data_cs
@./ExampleEncoder.exe encoded_data_cs
@echo "************ running Java decoder: *****************"
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_cs
......@@ -165,7 +165,7 @@ runwcs: Encoder.exe Decoder.exe
@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_cs LabComm2014
@echo "************ running C# decoder: *****************"
@./Decoder.exe encoded_data_cs
@./ExampleDecoder.exe encoded_data_cs
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment